Fixed the accessibility hierarchy of the message view to allow the accessibility...
[adiumx.git] / Source / ESMetaContactContentsPlugin.m
blob3e929b8b0c41fa54be61881bc71d2af0f32d6ec4
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 <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)
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                         BOOL                    shouldAppendServiceIcon = ![(AIMetaContact *)inObject containsOnlyOneService];
76                         entry = [[NSMutableAttributedString alloc] init];
77                         entryString = [entry mutableString];
78                         
79                         enumerator = [listContacts objectEnumerator];
80                         while ((contact = [enumerator nextObject])) {
81                                 NSImage *statusIcon, *serviceIcon;
82                                 
83                                 if (shouldAppendString) {
84                                         [entryString appendString:@"\r"];
85                                 } else {
86                                         shouldAppendString = YES;
87                                 }
88                                 
89                                 statusIcon = [[contact displayArrayObjectForKey:@"Tab Status Icon"] imageByScalingToSize:META_TOOLTIP_ICON_SIZE];
90                                 
91                                 if (statusIcon) {
92                                         NSTextAttachment                *attachment;
93                                         NSTextAttachmentCell    *cell;
94                                                 
95                                         cell = [[NSTextAttachmentCell alloc] init];
96                                         [cell setImage:statusIcon];
97                                         
98                                         attachment = [[NSTextAttachment alloc] init];
99                                         [attachment setAttachmentCell:cell];
100                                         [cell release];
102                                         [entry appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
103                                         [attachment release];
104                                 }
105                                 
106                                 [entryString appendString:[contact formattedUID]];
107                                 
108                                 if (shouldAppendServiceIcon) {
109                                         serviceIcon = [[AIServiceIcons serviceIconForObject:contact type:AIServiceIconSmall direction:AIIconNormal]
110                                                                         imageByScalingToSize:META_TOOLTIP_ICON_SIZE];
111                                         if (serviceIcon) {
112                                                 NSTextAttachment                *attachment;
113                                                 NSTextAttachmentCell    *cell;
114                                                 
115                                                 cell = [[NSTextAttachmentCell alloc] init];
116                                                 [cell setImage:serviceIcon];
117                                                 
118                                                 attachment = [[NSTextAttachment alloc] init];
119                                                 [attachment setAttachmentCell:cell];
120                                                 [cell release];
122                                                 [entryString appendString:@" "];
123                                                 [entry appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];
124                                                 [attachment release];
125                                         }
126                                 }
127                         }
128                 }
129         }
130     
131     return [entry autorelease];
134 @end