French updates
[adiumx.git] / Source / AITabStatusIconsPlugin.m
blobbae5ced692a80b43824c19753808dda6a51a081a
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 "AITabStatusIconsPlugin.h"
18 #import "AIContactController.h"
19 #import "AIContentController.h"
20 #import <AIUtilities/AIMutableOwnerArray.h>
21 #import <Adium/AIChat.h>
22 #import <Adium/AIListObject.h>
23 #import <Adium/AIListContact.h>
24 #import <Adium/AIStatusIcons.h>
26 @interface AITabStatusIconsPlugin (PRIVATE)
27 - (NSString *)_stateIDForChat:(AIChat *)inChat;
28 - (NSString *)_statusIDForListObject:(AIListObject *)listObject;
29 @end
31 /*!
32  * @class AITabStatusIconsPlugin
33  * @brief Tab status icons component
34  *
35  * This component is effectively glue to AIStatusIcons to provide status and typing/unviewed content icons
36  * for chats.
37  */
38 @implementation AITabStatusIconsPlugin
40 /*!
41  * @brief Install
42  */
43 - (void)installPlugin
45         //Observe list object changes
46         [[adium contactController] registerListObjectObserver:self];
47         
48         //Observe chat changes
49         [[adium contentController] registerChatObserver:self];
50         
51         [[adium notificationCenter] addObserver:self
52                                                                    selector:@selector(statusIconSetDidChange:)
53                                                                            name:AIStatusIconSetDidChangeNotification
54                                                                          object:nil];
57 /*!
58  * @brief Uninstall
59  */
60 - (void)uninstallPlugin
62         [[adium contactController] unregisterListObjectObserver:self];
63         [[adium contentController] unregisterChatObserver:self];
64         [[adium notificationCenter] removeObserver:self];
67 /*!
68  * @brief The status icon set changed; update our objects and chats.
69  */
70 - (void)statusIconSetDidChange:(NSNotification *)aNotification
72         [[adium contactController] updateAllListObjectsForObserver:self];
73         [[adium contentController] updateAllChatsForObserver:self];
76 /*!
77  * @brief Apply the correct tab icon according to status
78  */
79 - (NSSet *)updateListObject:(AIListObject *)inObject keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
81     NSSet               *modifiedAttributes = nil;
82         
83         if(inModifiedKeys == nil ||
84            [inModifiedKeys containsObject:@"Online"] ||
85            [inModifiedKeys containsObject:@"StatusName"] ||
86            [inModifiedKeys containsObject:@"StatusType"] ||
87            [inModifiedKeys containsObject:@"IsIdle"] ||
88            [inModifiedKeys containsObject:@"NotAStranger"] ||
89            [inModifiedKeys containsObject:@"IsMobile"]){
90                 
91                 //Tab
92                 NSImage *icon = [AIStatusIcons statusIconForListObject:inObject
93                                                                                                                   type:AIStatusIconTab
94                                                                                                          direction:AIIconNormal];
95                 [[inObject displayArrayForKey:@"Tab Status Icon"] setObject:icon withOwner:self];
96                 
97                 //List
98                 icon = [AIStatusIcons statusIconForListObject:inObject
99                                                                                                  type:AIStatusIconList
100                                                                                         direction:AIIconNormal];
101                 [[inObject displayArrayForKey:@"List Status Icon"] setObject:icon withOwner:self];
102                 
103                 modifiedAttributes = [NSSet setWithObjects:@"Tab Status Icon", @"List Status Icon", nil];
104         }
105         
106         return(modifiedAttributes);
110  * @brief Update a chat for typing and unviewed content icons
111  */
112 - (NSSet *)updateChat:(AIChat *)inChat keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
114         NSSet           *modifiedAttributes = nil;
115         
116         if (inModifiedKeys == nil ||
117                 [inModifiedKeys containsObject:KEY_TYPING] ||
118                 [inModifiedKeys containsObject:KEY_UNVIEWED_CONTENT]){
119                 
120                 //Apply the state icon to our chat
121                 NSImage *icon = [AIStatusIcons statusIconForChat:inChat
122                                                                                                                 type:AIStatusIconTab
123                                                                                                    direction:AIIconNormal];
124                 [[inChat displayArrayForKey:@"Tab State Icon"] setObject:icon withOwner:self];
125                 modifiedAttributes = [NSSet setWithObject:@"Tab State Icon"];
127                 //Also apply the state icon to our contact if this is a one-on-one chat
128                 if([inChat listObject]){
129                         AIListObject *contact = [[adium contactController] parentContactForListObject:[inChat listObject]];
130                         
131                         NSImage *icon = [AIStatusIcons statusIconForChat:inChat
132                                                                                                                 type:AIStatusIconList
133                                                                                                    direction:AIIconNormal];
134                         [[contact displayArrayForKey:@"List State Icon"] setObject:icon withOwner:self];
135                         [[adium contactController] listObjectAttributesChanged:contact
136                                                                                                           modifiedKeys:[NSSet setWithObject:@"List State Icon"]];
137                 }               
138         }
139         
140         return(modifiedAttributes);
143 @end