French updates
[adiumx.git] / Source / ESMetaContactContentsPlugin.m
blob5d4be59c3a340515a7d1a860016f537b29c14e1b
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
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.
8  * 
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.
12  * 
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.
15  */
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)
27 /*!
28  * @class ESMetaContactContentsPlugin
29  * @brief Tooltip component: Show the contacts contained by metaContacts, with service and status state.
30  */
31 @implementation ESMetaContactContentsPlugin
33 /*!
34  * @brief Install
35  */
36 - (void)installPlugin
38     //Install our tooltip entry
39     [[adium interfaceController] registerContactListTooltipEntry:self secondaryEntry:YES];      
42 /*!
43  * @brief Tooltip label
44  *
45  * @result A label, or nil if no tooltip entry should be shown
46  */
47 - (NSString *)labelForObject:(AIListObject *)inObject
49         if ([inObject isKindOfClass:[AIMetaContact class]]){
50                 return(AILocalizedString(@"Contacts",nil));
51         }
52         
53         return nil;
56 /*!
57  * @brief Tooltip entry
58  *
59  * @result The tooltip entry, or nil if no tooltip should be shown
60  */
61 - (NSAttributedString *)entryForObject:(AIListObject *)inObject
63     NSMutableAttributedString   *entry = nil;
64         
65         if([inObject isKindOfClass:[AIMetaContact class]]){
66                 NSArray                         *listContacts = [(AIMetaContact *)inObject listContacts];
67                 
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                         
75                         entry = [[NSMutableAttributedString alloc] init];
76                         entryString = [entry mutableString];
77                         
78                         enumerator = [listContacts objectEnumerator];
79                         while(contact = [enumerator nextObject]){
80                                 NSImage *statusIcon, *serviceIcon;
81                                 
82                                 if (shouldAppendString){
83                                         [entryString appendString:@"\r"];
84                                 }else{
85                                         shouldAppendString = YES;
86                                 }
87                                 
88                                 statusIcon = [[contact displayArrayObjectForKey:@"Tab Status Icon"] imageByScalingToSize:META_TOOLTIP_ICON_SIZE];
89                                 
90                                 if(statusIcon){
91                                         NSTextAttachment                *attachment;
92                                         NSTextAttachmentCell    *cell;
93                                                 
94                                         cell = [[[NSTextAttachmentCell alloc] init] autorelease];
95                                         [cell setImage:statusIcon];
96                                         
97                                         attachment = [[[NSTextAttachment alloc] init] autorelease];
98                                         [attachment setAttachmentCell:cell];
99                                         
100                                         [entry appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
101                                 }
102                                 
103                                 [entryString appendString:[contact formattedUID]];
104                                 
105                                 serviceIcon = [[AIServiceIcons serviceIconForObject:contact type:AIServiceIconSmall direction:AIIconNormal]
106                                                                         imageByScalingToSize:META_TOOLTIP_ICON_SIZE];
107                                 if (serviceIcon){
108                                         NSTextAttachment                *attachment;
109                                         NSTextAttachmentCell    *cell;
110                                         
111                                         cell = [[[NSTextAttachmentCell alloc] init] autorelease];
112                                         [cell setImage:serviceIcon];
113                                         
114                                         attachment = [[[NSTextAttachment alloc] init] autorelease];
115                                         [attachment setAttachmentCell:cell];
116                                         
117                                         [entryString appendString:@" "];
118                                         [entry appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
119                                 }
120                         }
121                 }
122         }
123     
124     return([entry autorelease]);
127 @end