libpurple.framework 2.3.1 as before but with HAVE_OPENSSL defined, which enables...
[adiumx.git] / Source / ESAuthorizationRequestWindowController.m
bloba3b53f1bea2acb9a23f9ef231092f04e4a5d27ca
1 //
2 //  ESAuthorizationRequestWindowController.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 5/18/05.
6 //
8 #import "ESAuthorizationRequestWindowController.h"
9 #import <Adium/AIAccountControllerProtocol.h>
10 #import <Adium/AIContactControllerProtocol.h>
11 #import <Adium/AIAccount.h>
12 #import <AIUtilities/AIStringAdditions.h>
14 @interface ESAuthorizationRequestWindowController (PRIVATE)
15 - (id)initWithWindowNibName:(NSString *)windowNibName withDict:(NSDictionary *)inInfoDict forAccount:(AIAccount *)inAccount;
16 @end
18 @implementation ESAuthorizationRequestWindowController
20 + (ESAuthorizationRequestWindowController *)showAuthorizationRequestWithDict:(NSDictionary *)inInfoDict  forAccount:(AIAccount *)inAccount
22         ESAuthorizationRequestWindowController  *controller;
23         
24         if ((controller = [[self alloc] initWithWindowNibName:@"AuthorizationRequestWindow"
25                                                                                                  withDict:inInfoDict
26                                                                                            forAccount:inAccount])) {
27                 [controller showWindow:nil];
28                 [[controller window] orderFront:nil];
29         }
30         
31         return controller;
34 //Init
35 - (id)initWithWindowNibName:(NSString *)windowNibName withDict:(NSDictionary *)inInfoDict forAccount:(AIAccount *)inAccount
37     if ((self = [super initWithWindowNibName:windowNibName])) {
38                 infoDict = [inInfoDict retain];
39                 account = [inAccount retain];
40         }
41         
42     return self;
45 - (void)dealloc
47         [infoDict release]; infoDict = nil;
48         [account release]; account = nil;
50         [super dealloc];
53 - (void)windowDidLoad
54 {       
55         NSString        *message;
57         [super windowDidLoad];
59         [textField_header setStringValue:AILocalizedString(@"Authorization Requested",nil)];
60         [checkBox_addToList setLocalizedString:AILocalizedString(@"Add to my Contact List", "Checkbox in the Authorizatoin Request window to add the contact to the contact list if authorization is granted")]; 
61         [button_authorize setLocalizedString:AILocalizedString(@"Authorize", nil)];
62         [button_deny setLocalizedString:AILocalizedString(@"Deny", nil)];
64         // Hide the "Add to my Contact List" checkbox if the contact already exists in the list
65         AIListContact *contact = [[adium contactController] existingContactWithService:[account service] account:account UID:[infoDict objectForKey:@"Remote Name"]];
66         if (contact && [contact isIntentionallyNotAStranger]) {
67                 [checkBox_addToList setState:NSOffState];
68                 [checkBox_addToList setEnabled:NO];
69                 [checkBox_addToList setHidden:YES];
70         }
72         if ([infoDict objectForKey:@"Reason"]) {
73                 message = [NSString stringWithFormat:
74                         AILocalizedString(@"The contact %@ wants to add %@ to his or her contact list for the following reason:\n%@",nil),
75                         [infoDict objectForKey:@"Remote Name"],
76                         [account formattedUID],
77                         [infoDict objectForKey:@"Reason"]];
79         } else {
80                 message = [NSString stringWithFormat:
81                         AILocalizedString(@"The contact %@ wants to add %@ to his or her contact list.",nil),
82                         [infoDict objectForKey:@"Remote Name"],
83                         [account formattedUID]];
84         }
86         NSScrollView *scrollView_message = [textView_message enclosingScrollView];
87         
88         [textView_message setVerticallyResizable:YES];
89         [textView_message setHorizontallyResizable:NO];
90         [textView_message setDrawsBackground:NO];
91         [textView_message setTextContainerInset:NSZeroSize];
92         [scrollView_message setDrawsBackground:NO];
93         
94         [textView_message setString:(message ? message : @"")];
95         
96         //Resize the window frame to fit the error title
97         [textView_message sizeToFit];
98         float heightChange = [textView_message frame].size.height - [scrollView_message documentVisibleRect].size.height;
100         NSRect windowFrame = [[self window] frame];
101         windowFrame.size.height += heightChange;
102         windowFrame.origin.y -= heightChange;
103         [[self window] setFrame:windowFrame display:YES animate:NO];
104         
105         [[self window] center];
108 - (void)windowWillClose:(id)sender
110         windowIsClosing = YES;
112         [super windowWillClose:sender];
114         [self autorelease];
117 - (void)closeWindow:(id)sender
119         if (!windowIsClosing)
120                 [super closeWindow:sender];
122         
125 - (IBAction)authorize:(id)sender
127         //Do the authorization serverside
128         [account authorizationWindowController:self
129                                          authorizationWithDict:infoDict
130                                                           didAuthorize:YES];
131         
132         //Now handle the Add To Contact List checkbox
133         AILog(@"Authorize: (%i) %@",[checkBox_addToList state],infoDict);
135         if ([checkBox_addToList state] == NSOnState) {
136                 [[adium contactController] requestAddContactWithUID:[infoDict objectForKey:@"Remote Name"]
137                                                                                                         service:[account service]
138                                                                                                         account:account];
139         }
140         
141         [infoDict release]; infoDict = nil;
142         
143         [self closeWindow:nil];
146 - (IBAction)deny:(id)sender
148         [account authorizationWindowController:self
149                                          authorizationWithDict:infoDict
150                                                           didAuthorize:NO];     
152         [infoDict release]; infoDict = nil;
154         [self closeWindow:nil];
157 @end