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 "AIDockUnviewedContentPlugin.h"
18 #import <Adium/AIChatControllerProtocol.h>
19 #import <Adium/AIContentControllerProtocol.h>
20 #import "AIDockController.h"
21 #import <Adium/AIPreferenceControllerProtocol.h>
22 #import <AIUtilities/AIArrayAdditions.h>
23 #import <AIUtilities/AIDictionaryAdditions.h>
24 #import <Adium/AIChat.h>
26 @interface AIDockUnviewedContentPlugin (PRIVATE)
31 * @class AIDockUnviewedContentPlugin
32 * @brief Component responsible for triggering and removing the Alert dock icon state for unviewed content
34 @implementation AIDockUnviewedContentPlugin
42 unviewedObjectsArray = [[NSMutableArray alloc] init];
45 //Register our default preferences
46 [[adium preferenceController] registerDefaults:[NSDictionary dictionaryNamed:@"DockUnviewedContentDefaults"
47 forClass:[self class]]
48 forGroup:PREF_GROUP_APPEARANCE];
50 //Observe pref changes
51 [[adium preferenceController] registerPreferenceObserver:self forGroup:PREF_GROUP_APPEARANCE];
57 - (void)uninstallPlugin
59 [[adium chatController] unregisterChatObserver:self];
60 [[adium notificationCenter] removeObserver:self];
63 #pragma mark Preference observing
64 - (void)preferencesChangedForGroup:(NSString *)group key:(NSString *)key
65 object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime
67 if (!key || [key isEqualToString:KEY_ANIMATE_DOCK_ICON]) {
68 BOOL newAnimateDockIcon = [[prefDict objectForKey:KEY_ANIMATE_DOCK_ICON] boolValue];
70 if (newAnimateDockIcon != animateDockIcon) {
71 animateDockIcon = newAnimateDockIcon;
73 if (animateDockIcon) {
74 //Register as a chat observer (So we can catch the unviewed content status flag)
75 [[adium chatController] registerChatObserver:self];
77 [[adium notificationCenter] addObserver:self
78 selector:@selector(chatWillClose:)
79 name:Chat_WillClose object:nil];
84 [[adium chatController] unregisterChatObserver:self];
85 [[adium notificationCenter] removeObserver:self];
91 * @brief Chat was updated
93 * Check for whether inModifiedKeys contains a change to unviewed content. If so, put the dock in the Alert state
94 * if it isn't already and there is unviewed content, or take it out of the Alert state if it is and there is none.
96 * The alert state, in the default dock icon set, is the Adium duck flapping its wings.
98 - (NSSet *)updateChat:(AIChat *)inChat keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
100 if ([inModifiedKeys containsObject:KEY_UNVIEWED_CONTENT]) {
102 if ([inChat unviewedContentCount]) {
103 //If this is the first contact with unviewed content, animate the dock
104 if (!unviewedState) {
105 [[adium dockController] setIconStateNamed:@"Alert"];
109 [unviewedObjectsArray addObject:inChat];
112 if ([unviewedObjectsArray containsObjectIdenticalTo:inChat]) {
113 [unviewedObjectsArray removeObject:inChat];
115 //If there are no more contacts with unviewed content, stop animating the dock
116 if ([unviewedObjectsArray count] == 0 && unviewedState) {
127 * @brief Remove any existing alert state
131 [[adium dockController] removeIconStateNamed:@"Alert"];
136 * @brief Respond to a chat closing
138 * Ensure that when a chat closes we remove the Alert state if necessary.
140 - (void)chatWillClose:(NSNotification *)notification
142 AIChat *inChat = [notification object];
144 if ([unviewedObjectsArray containsObjectIdenticalTo:inChat]) {
145 [unviewedObjectsArray removeObject:inChat];
147 //If there are no more contacts with unviewed content, stop animating the dock
148 if ([unviewedObjectsArray count] == 0 && unviewedState) {