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 "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;
32 * @class AITabStatusIconsPlugin
33 * @brief Tab status icons component
35 * This component is effectively glue to AIStatusIcons to provide status and typing/unviewed content icons
38 @implementation AITabStatusIconsPlugin
45 //Observe list object changes
46 [[adium contactController] registerListObjectObserver:self];
48 //Observe chat changes
49 [[adium contentController] registerChatObserver:self];
51 [[adium notificationCenter] addObserver:self
52 selector:@selector(statusIconSetDidChange:)
53 name:AIStatusIconSetDidChangeNotification
60 - (void)uninstallPlugin
62 [[adium contactController] unregisterListObjectObserver:self];
63 [[adium contentController] unregisterChatObserver:self];
64 [[adium notificationCenter] removeObserver:self];
68 * @brief The status icon set changed; update our objects and chats.
70 - (void)statusIconSetDidChange:(NSNotification *)aNotification
72 [[adium contactController] updateAllListObjectsForObserver:self];
73 [[adium contentController] updateAllChatsForObserver:self];
77 * @brief Apply the correct tab icon according to status
79 - (NSSet *)updateListObject:(AIListObject *)inObject keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
81 NSSet *modifiedAttributes = nil;
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"]){
92 NSImage *icon = [AIStatusIcons statusIconForListObject:inObject
94 direction:AIIconNormal];
95 [[inObject displayArrayForKey:@"Tab Status Icon"] setObject:icon withOwner:self];
98 icon = [AIStatusIcons statusIconForListObject:inObject
100 direction:AIIconNormal];
101 [[inObject displayArrayForKey:@"List Status Icon"] setObject:icon withOwner:self];
103 modifiedAttributes = [NSSet setWithObjects:@"Tab Status Icon", @"List Status Icon", nil];
106 return(modifiedAttributes);
110 * @brief Update a chat for typing and unviewed content icons
112 - (NSSet *)updateChat:(AIChat *)inChat keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
114 NSSet *modifiedAttributes = nil;
116 if (inModifiedKeys == nil ||
117 [inModifiedKeys containsObject:KEY_TYPING] ||
118 [inModifiedKeys containsObject:KEY_UNVIEWED_CONTENT]){
120 //Apply the state icon to our chat
121 NSImage *icon = [AIStatusIcons statusIconForChat:inChat
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]];
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"]];
140 return(modifiedAttributes);