Forgot to remove an import I added temporarily
[adiumx.git] / Source / AITabStatusIconsPlugin.m
blob67494e95c77170e752ee955b86519dbf5176bb9e
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 <Adium/AIContactControllerProtocol.h>
19 #import <Adium/AIChatControllerProtocol.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 chatController] 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 chatController] 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 chatController] 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:KEY_IS_BLOCKED] ||
90            [inModifiedKeys containsObject:@"IsMobile"]) {
91                 
92                 //Tab
93                 NSImage *icon = [AIStatusIcons statusIconForListObject:inObject
94                                                                                                                   type:AIStatusIconTab
95                                                                                                          direction:AIIconNormal];
96                 [[inObject displayArrayForKey:@"Tab Status Icon"] setObject:icon withOwner:self];
97                 
98                 //List
99                 icon = [AIStatusIcons statusIconForListObject:inObject
100                                                                                                  type:AIStatusIconList
101                                                                                         direction:AIIconNormal];
102                 [[inObject displayArrayForKey:@"List Status Icon"] setObject:icon withOwner:self];
103                 
104                 modifiedAttributes = [NSSet setWithObjects:@"Tab Status Icon", @"List Status Icon", nil];
105         }
106         
107         return modifiedAttributes;
111  * @brief Update a chat for typing and unviewed content icons
112  */
113 - (NSSet *)updateChat:(AIChat *)inChat keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
115         NSSet           *modifiedAttributes = nil;
116         
117         if (inModifiedKeys == nil ||
118                 [inModifiedKeys containsObject:KEY_TYPING] ||
119                 [inModifiedKeys containsObject:KEY_UNVIEWED_CONTENT]) {
120                 AIListContact   *listContact;
121                 NSImage                 *tabStateIcon;
122                 
123                 //Apply the state icon to our chat
124                 tabStateIcon = [AIStatusIcons statusIconForChat:inChat
125                                                                                                    type:AIStatusIconTab
126                                                                                           direction:AIIconNormal];
127                 [[inChat displayArrayForKey:@"Tab State Icon"] setObject:tabStateIcon withOwner:self];
128                 modifiedAttributes = [NSSet setWithObject:@"Tab State Icon"];
130                 //Also apply the state icon to our contact if this is a one-on-one chat
131                 if ((listContact = [[inChat listObject] parentContact])) {
132                         NSImage *listStateIcon;
133                         
134                         listStateIcon = [AIStatusIcons statusIconForChat:inChat
135                                                                                                                 type:AIStatusIconList
136                                                                                                    direction:AIIconNormal];
137                         [[listContact displayArrayForKey:@"List State Icon"] setObject:listStateIcon withOwner:self];
138                         [[adium contactController] listObjectAttributesChanged:listContact
139                                                                                                           modifiedKeys:[NSSet setWithObject:@"List State Icon"]];
140                 }               
141         }
142         
143         return modifiedAttributes;
146 @end