2 // ESAwayStatusWindowPlugin.m
5 // Created by Evan Schoenberg on 4/12/05.
6 // Copyright 2005 The Adium Team. All rights reserved.
9 #import "ESAwayStatusWindowPlugin.h"
10 #import "ESAwayStatusWindowController.h"
11 #import "AIContactController.h"
12 #import "AIPreferenceController.h"
13 #import "AISoundController.h"
14 #import "AIStatusController.h"
15 #import <Adium/AIAccount.h>
16 #import <Adium/AIListObject.h>
19 * @class ESAwayStatusWindowPlugin
20 * @brief Component to manage the status window optionally displayed when one or more accounts are away
22 * XXX - This comopnent should move to being an external, included, disabled by default plugin, with more
23 * options added when it is enabled.
25 @implementation ESAwayStatusWindowPlugin
32 showStatusWindow = FALSE;
33 awayAccounts = [[NSMutableSet alloc] init];
35 //Remove any mute-while-stauts-window-is-open mute from the sound controller's preferences
36 [[adium preferenceController] setPreference:nil
37 forKey:KEY_SOUND_STATUS_MUTE
38 group:PREF_GROUP_SOUNDS];
40 //Observe preference changes for updating if we should show the status window
41 [[adium preferenceController] registerPreferenceObserver:self
42 forGroup:PREF_GROUP_STATUS_PREFERENCES];
45 - (void)uninstallPlugin
47 [[adium preferenceController] unregisterPreferenceObserver:self];
48 [[adium contactController] unregisterListObjectObserver:self];
56 [awayAccounts release];
62 * @brief Preferences changed
64 * Note whether we are supposed to should show the status window, and toggle it if necessary
66 - (void)preferencesChangedForGroup:(NSString *)group key:(NSString *)key
67 object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime
69 BOOL oldShowStatusWindow = showStatusWindow;
71 showStatusWindow = [[prefDict objectForKey:KEY_STATUS_SHOW_STATUS_WINDOW] boolValue];
73 if(showStatusWindow != oldShowStatusWindow){
75 /* Register as a list object observer, which will update all objects for us immediately leading to the proper
76 * status window toggling. */
77 [[adium contactController] registerListObjectObserver:self];
79 //Hide the status window if it is currently visible
80 [ESAwayStatusWindowController updateStatusWindowWithVisibility:NO];
82 //Clear our away account tracking
83 [awayAccounts removeAllObjects];
85 //Stop observing list objects
86 [[adium contactController] unregisterListObjectObserver:self];
92 * @brief Account status changed.
94 * Show or hide our status window as appropriate
96 - (NSSet *)updateListObject:(AIListObject *)inObject keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
98 if([inObject isKindOfClass:[AIAccount class]] &&
99 (!inModifiedKeys || [inModifiedKeys containsObject:@"StatusState"] || [inModifiedKeys containsObject:@"Online"])){
100 if([inObject online] && ([inObject statusType] != AIAvailableStatusType)){
101 [awayAccounts addObject:inObject];
103 [awayAccounts removeObject:inObject];
106 /* We wait until the next run loop so we can have processed multiple changing accounts at once before updating
107 * our display, preventing flickering through changes as the global state changes and thereby modifies multiple
108 * account states in a single invocation.
110 [NSObject cancelPreviousPerformRequestsWithTarget:self
111 selector:@selector(processStatusUpdate)
113 [self performSelector:@selector(processStatusUpdate)
118 //We don't modify any keys
122 - (void)processStatusUpdate
124 //Tell the window to update, showing/hiding as necessary
125 [ESAwayStatusWindowController updateStatusWindowWithVisibility:([awayAccounts count] > 0)];