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 <Adium/AIInterfaceControllerProtocol.h>
18 #import "ESMetaContactContentsPlugin.h"
19 #import <AIUtilities/AIImageAdditions.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(11,11)
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;
74 BOOL shouldAppendServiceIcon = ![(AIMetaContact *)inObject containsOnlyOneService];
76 entry = [[NSMutableAttributedString alloc] init];
77 entryString = [entry mutableString];
79 enumerator = [listContacts objectEnumerator];
80 while ((contact = [enumerator nextObject])) {
81 NSImage *statusIcon, *serviceIcon;
83 if (shouldAppendString) {
84 [entryString appendString:@"\r"];
86 shouldAppendString = YES;
89 statusIcon = [[contact displayArrayObjectForKey:@"Tab Status Icon"] imageByScalingToSize:META_TOOLTIP_ICON_SIZE];
92 NSTextAttachment *attachment;
93 NSTextAttachmentCell *cell;
95 cell = [[NSTextAttachmentCell alloc] init];
96 [cell setImage:statusIcon];
98 attachment = [[NSTextAttachment alloc] init];
99 [attachment setAttachmentCell:cell];
102 [entry appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
103 [attachment release];
106 [entryString appendString:[contact formattedUID]];
108 if (shouldAppendServiceIcon) {
109 serviceIcon = [[AIServiceIcons serviceIconForObject:contact type:AIServiceIconSmall direction:AIIconNormal]
110 imageByScalingToSize:META_TOOLTIP_ICON_SIZE];
112 NSTextAttachment *attachment;
113 NSTextAttachmentCell *cell;
115 cell = [[NSTextAttachmentCell alloc] init];
116 [cell setImage:serviceIcon];
118 attachment = [[NSTextAttachment alloc] init];
119 [attachment setAttachmentCell:cell];
122 [entryString appendString:@" "];
123 [entry appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
124 [attachment release];
131 return [entry autorelease];