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 "GBQuestionHandlerPlugin.h"
18 #import <Adium/AIInterfaceControllerProtocol.h>
19 #import "ESTextAndButtonsWindowController.h"
27 @interface GBQuestionHandlerPlugin (privateFunctions)
28 - (BOOL)displayNextAlert;
31 @implementation GBQuestionHandlerPlugin
35 if( (self = [super init]) != nil)
37 questionQueue = [[NSMutableArray alloc] init];
38 errorQueue = [[NSMutableArray alloc] init];
46 [questionQueue release];
48 [currentAlert release];
54 //Install our observers
55 [[adium notificationCenter] addObserver:self
56 selector:@selector(handleQuestion:)
57 name:Interface_ShouldDisplayQuestion
61 - (void)uninstallPlugin
65 - (void)handleType:(AlertType)type userInfo:(NSDictionary *)userInfo
67 NSDictionary *infoCopy = [userInfo copy];
71 case ALERT_TYPE_QUESTION:
72 [questionQueue addObject:infoCopy];
74 case ALERT_TYPE_ERROR:
75 [errorQueue addObject:infoCopy];
79 if(currentAlert == nil)
80 [self displayNextAlert];
83 - (void)handleQuestion:(NSNotification *)notification
85 NSDictionary *userInfo;
88 userInfo = [notification userInfo];
89 [self handleType:ALERT_TYPE_QUESTION userInfo:userInfo];
92 - (BOOL)textAndButtonsWindowDidEnd:(NSWindow *)window returnCode:(AITextAndButtonsReturnCode)returnCode userInfo:(id)userInfo
94 NSString *selectorString = [userInfo objectForKey:@"Selector"];
95 id target = [userInfo objectForKey:@"Target"];
98 if(target != nil || selectorString != nil)
100 SEL selector = NSSelectorFromString(selectorString);
101 if([target respondsToSelector:selector])
103 [target performSelector:selector withObject:[NSNumber numberWithInt:returnCode] withObject:[userInfo objectForKey:@"Userinfo"]];
106 if([self displayNextAlert])
107 //More alerts so don't hide window
111 [currentAlert release];
117 - (BOOL)displayNextAlert
120 if([errorQueue count] != 0)
122 NSDictionary *info = [errorQueue objectAtIndex:0];
123 if(currentAlert == nil)
124 currentAlert = [[ESTextAndButtonsWindowController controller] retain];
125 [currentAlert changeWindowToTitle:[info objectForKey:@"Window Title"]
126 defaultButton:AILocalizedString(@"Next", @"Next Button")
127 alternateButton:AILocalizedString(@"Dismiss All", @"Dismiss All Button")
129 withMessageHeader:[info objectForKey:@"Title"]
130 andMessage:[info objectForKey:@"Description"]
135 [errorQueue removeObjectAtIndex:0];
138 else if ([questionQueue count] != 0)
140 NSDictionary *info = [questionQueue objectAtIndex:0];
141 if(currentAlert == nil)
142 currentAlert = [[ESTextAndButtonsWindowController controller] retain];
143 [currentAlert changeWindowToTitle:[info objectForKey:@"Window Title"]
144 defaultButton:[info objectForKey:@"Default Button"]
145 alternateButton:[info objectForKey:@"Alternate Button"]
146 otherButton:[info objectForKey:@"Other Button"]
147 withMessageHeader:[info objectForKey:@"Title"]
148 andMessage:[info objectForKey:@"Description"]
153 [questionQueue removeObjectAtIndex:0];