2 // ESAuthorizationRequestWindowController.m
5 // Created by Evan Schoenberg on 5/18/05.
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;
18 @implementation ESAuthorizationRequestWindowController
20 + (ESAuthorizationRequestWindowController *)showAuthorizationRequestWithDict:(NSDictionary *)inInfoDict forAccount:(AIAccount *)inAccount
22 ESAuthorizationRequestWindowController *controller;
24 if ((controller = [[self alloc] initWithWindowNibName:@"AuthorizationRequestWindow"
26 forAccount:inAccount])) {
27 [controller showWindow:nil];
28 [[controller window] orderFront:nil];
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];
47 [infoDict release]; infoDict = nil;
48 [account release]; account = nil;
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];
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"]];
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]];
86 NSScrollView *scrollView_message = [textView_message enclosingScrollView];
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];
94 [textView_message setString:(message ? message : @"")];
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];
105 [[self window] center];
108 - (void)windowWillClose:(id)sender
110 windowIsClosing = YES;
112 [super windowWillClose:sender];
117 - (void)closeWindow:(id)sender
119 if (!windowIsClosing)
120 [super closeWindow:sender];
125 - (IBAction)authorize:(id)sender
127 //Do the authorization serverside
128 [account authorizationWindowController:self
129 authorizationWithDict:infoDict
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]
141 [infoDict release]; infoDict = nil;
143 [self closeWindow:nil];
146 - (IBAction)deny:(id)sender
148 [account authorizationWindowController:self
149 authorizationWithDict:infoDict
152 [infoDict release]; infoDict = nil;
154 [self closeWindow:nil];