2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import "AIInterfaceController.h"
18 #import "ESMetaContactContentsPlugin.h"
19 #import <AIUtilities/ESImageAdditions.h>
20 #import <Adium/AIListContact.h>
21 #import <Adium/AIListObject.h>
22 #import <Adium/AIMetaContact.h>
23 #import <Adium/AIServiceIcons.h>
25 #define META_TOOLTIP_ICON_SIZE NSMakeSize(10,10)
28 * @class ESMetaContactContentsPlugin
29 * @brief Tooltip component: Show the contacts contained by metaContacts, with service and status state.
31 @implementation ESMetaContactContentsPlugin
38 //Install our tooltip entry
39 [[adium interfaceController] registerContactListTooltipEntry:self secondaryEntry:YES];
43 * @brief Tooltip label
45 * @result A label, or nil if no tooltip entry should be shown
47 - (NSString *)labelForObject:(AIListObject *)inObject
49 if ([inObject isKindOfClass:[AIMetaContact class]]){
50 return(AILocalizedString(@"Contacts",nil));
57 * @brief Tooltip entry
59 * @result The tooltip entry, or nil if no tooltip should be shown
61 - (NSAttributedString *)entryForObject:(AIListObject *)inObject
63 NSMutableAttributedString *entry = nil;
65 if([inObject isKindOfClass:[AIMetaContact class]]){
66 NSArray *listContacts = [(AIMetaContact *)inObject listContacts];
68 //Only display the contents if it has more than one contact within it.
69 if ([listContacts count] > 1){
70 NSMutableString *entryString;
71 AIListContact *contact;
72 NSEnumerator *enumerator;
73 BOOL shouldAppendString = NO;
75 entry = [[NSMutableAttributedString alloc] init];
76 entryString = [entry mutableString];
78 enumerator = [listContacts objectEnumerator];
79 while(contact = [enumerator nextObject]){
80 NSImage *statusIcon, *serviceIcon;
82 if (shouldAppendString){
83 [entryString appendString:@"\r"];
85 shouldAppendString = YES;
88 statusIcon = [[contact displayArrayObjectForKey:@"Tab Status Icon"] imageByScalingToSize:META_TOOLTIP_ICON_SIZE];
91 NSTextAttachment *attachment;
92 NSTextAttachmentCell *cell;
94 cell = [[[NSTextAttachmentCell alloc] init] autorelease];
95 [cell setImage:statusIcon];
97 attachment = [[[NSTextAttachment alloc] init] autorelease];
98 [attachment setAttachmentCell:cell];
100 [entry appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
103 [entryString appendString:[contact formattedUID]];
105 serviceIcon = [[AIServiceIcons serviceIconForObject:contact type:AIServiceIconSmall direction:AIIconNormal]
106 imageByScalingToSize:META_TOOLTIP_ICON_SIZE];
108 NSTextAttachment *attachment;
109 NSTextAttachmentCell *cell;
111 cell = [[[NSTextAttachmentCell alloc] init] autorelease];
112 [cell setImage:serviceIcon];
114 attachment = [[[NSTextAttachment alloc] init] autorelease];
115 [attachment setAttachmentCell:cell];
117 [entryString appendString:@" "];
118 [entry appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
124 return([entry autorelease]);