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 <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;
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 chatController] registerChatObserver:self];
51 [[adium notificationCenter] addObserver:self
52 selector:@selector(statusIconSetDidChange:)
53 name:AIStatusIconSetDidChangeNotification
60 - (void)uninstallPlugin
62 [[adium contactController] unregisterListObjectObserver:self];
63 [[adium chatController] 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 chatController] 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:KEY_IS_BLOCKED] ||
90 [inModifiedKeys containsObject:@"IsMobile"]) {
93 NSImage *icon = [AIStatusIcons statusIconForListObject:inObject
95 direction:AIIconNormal];
96 [[inObject displayArrayForKey:@"Tab Status Icon"] setObject:icon withOwner:self];
99 icon = [AIStatusIcons statusIconForListObject:inObject
100 type:AIStatusIconList
101 direction:AIIconNormal];
102 [[inObject displayArrayForKey:@"List Status Icon"] setObject:icon withOwner:self];
104 modifiedAttributes = [NSSet setWithObjects:@"Tab Status Icon", @"List Status Icon", nil];
107 return modifiedAttributes;
111 * @brief Update a chat for typing and unviewed content icons
113 - (NSSet *)updateChat:(AIChat *)inChat keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
115 NSSet *modifiedAttributes = nil;
117 if (inModifiedKeys == nil ||
118 [inModifiedKeys containsObject:KEY_TYPING] ||
119 [inModifiedKeys containsObject:KEY_UNVIEWED_CONTENT]) {
120 AIListContact *listContact;
121 NSImage *tabStateIcon;
123 //Apply the state icon to our chat
124 tabStateIcon = [AIStatusIcons statusIconForChat:inChat
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;
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"]];
143 return modifiedAttributes;