Unescape the HREF attribute's text before passing it to NSURL which does not expect...
[adiumx.git] / Source / GBQuestionHandlerPlugin.m
blobb60fc27e56933d2ce3e3732c269190dab947ff89
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
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.
8  * 
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.
12  * 
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.
15  */
17 #import "GBQuestionHandlerPlugin.h"
18 #import <Adium/AIInterfaceControllerProtocol.h>
19 #import "ESTextAndButtonsWindowController.h"
21 typedef enum
23         ALERT_TYPE_ERROR,
24         ALERT_TYPE_QUESTION
25 } AlertType;
27 @interface GBQuestionHandlerPlugin (privateFunctions)
28 - (BOOL)displayNextAlert;
29 @end
31 @implementation GBQuestionHandlerPlugin
33 - (id)init
35         if( (self = [super init]) != nil)
36         {
37                 questionQueue = [[NSMutableArray alloc] init];
38                 errorQueue = [[NSMutableArray alloc] init];
39         }
40         
41         return self;
44 - (void)dealloc
46         [questionQueue release];
47         [errorQueue release];
48         [currentAlert release];
49         [super dealloc];
52 - (void)installPlugin
54     //Install our observers
55     [[adium notificationCenter] addObserver:self
56                                                                    selector:@selector(handleQuestion:)
57                                                                            name:Interface_ShouldDisplayQuestion 
58                                                                          object:nil];
61 - (void)uninstallPlugin
65 - (void)handleType:(AlertType)type userInfo:(NSDictionary *)userInfo
67         NSDictionary *infoCopy = [userInfo copy];
68         
69         switch(type)
70         {
71                 case ALERT_TYPE_QUESTION:
72                         [questionQueue addObject:infoCopy];
73                         break;
74                 case ALERT_TYPE_ERROR:
75                         [errorQueue addObject:infoCopy];
76                         break;
77         }
78         [infoCopy release];
79         if(currentAlert == nil)
80                 [self displayNextAlert];
83 - (void)handleQuestion:(NSNotification *)notification
85         NSDictionary    *userInfo;
86     
87     //Get the error info
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"];
96         BOOL    ret = YES;
97         
98         if(target != nil || selectorString != nil)
99         {
100                 SEL selector = NSSelectorFromString(selectorString);
101                 if([target respondsToSelector:selector])
102                 {
103                         [target performSelector:selector withObject:[NSNumber numberWithInt:returnCode] withObject:[userInfo objectForKey:@"Userinfo"]];
104                 }
105         }
106         if([self displayNextAlert])
107                 //More alerts so don't hide window
108                 ret = NO;
109         else
110         {
111                 [currentAlert release];
112                 currentAlert = nil;
113         }
114         return ret;
117 - (BOOL)displayNextAlert
119         BOOL ret = NO;
120         if([errorQueue count] != 0)
121         {
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")
128                                                           otherButton:nil
129                                                 withMessageHeader:[info objectForKey:@"Title"]
130                                                            andMessage:[info objectForKey:@"Description"]
131                                                                         image:nil
132                                                                    target:self
133                                                                  userInfo:info];
134                 [currentAlert show];
135                 [errorQueue removeObjectAtIndex:0];
136                 ret = YES;
137         }
138         else if ([questionQueue count] != 0)
139         {
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"]
149                                                                         image:nil
150                                                                    target:self
151                                                                  userInfo:info];
152                 [currentAlert show];
153                 [questionQueue removeObjectAtIndex:0];
154                 ret = YES;
155         }
156         return ret;
159 @end