Plugins/Purple Service/AIXMPPOAuthAccountViewController.m
branchGTalkOAuth2Support
changeset 5089 a761745f82a1
equal deleted inserted replaced
5086:816c7d80c0e5 5089:a761745f82a1
       
     1 //
       
     2 //  AIFacebookXMPPAccountViewController.m
       
     3 //  Adium
       
     4 //
       
     5 //  Created by Colin Barrett on 11/18/10.
       
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
       
     7 //
       
     8 
       
     9 #import "AIPurpleOAuthJabberAccount.h"
       
    10 #import "AIXMPPOAuthAccountViewController.h"
       
    11 #import <Adium/AIAccount.h>
       
    12 #import <Adium/AIAccountControllerProtocol.h>
       
    13 #import <AIUtilities/AIStringAdditions.h>
       
    14 
       
    15 @interface AIXMPPOAuthAccountViewController ()
       
    16 - (void)authProgressDidChange:(NSNotification *)notification;
       
    17 @end
       
    18 
       
    19 @implementation AIXMPPOAuthAccountViewController
       
    20 
       
    21 @synthesize spinner, textField_OAuthStatus, button_OAuthStart, button_help;
       
    22 
       
    23 - (void)dealloc
       
    24 {
       
    25 	[[NSNotificationCenter defaultCenter] removeObserver:self];
       
    26     [super dealloc];
       
    27 }
       
    28 
       
    29 - (NSView *)optionsView
       
    30 {
       
    31     return nil;
       
    32 }
       
    33 
       
    34 - (NSView *)privacyView
       
    35 {
       
    36     return nil;
       
    37 }
       
    38 
       
    39 - (NSView *)setupView
       
    40 {	
       
    41 	return view_setup;
       
    42 }
       
    43 
       
    44 - (NSString *)nibName
       
    45 {
       
    46     return @"AIXMPPOAuthAccountView";
       
    47 }
       
    48 
       
    49 /*!
       
    50  * @brief Configure controls
       
    51  */
       
    52 - (void)configureForAccount:(AIAccount *)inAccount
       
    53 {
       
    54 	[super configureForAccount:inAccount];
       
    55 	
       
    56 	if ([[AIPurpleOAuthJabberAccount class] uidIsValid:account.UID] &&
       
    57 		[adium.accountController passwordForAccount:account].length) {
       
    58 		[textField_OAuthStatus setStringValue:AILocalizedString(@"Adium is authorized for Facebook Chat.", nil)];
       
    59 		[button_OAuthStart setEnabled:NO];
       
    60 	} else {
       
    61 		[textField_OAuthStatus setStringValue:@""];
       
    62 		[button_OAuthStart setEnabled:YES]; 
       
    63 	}
       
    64 	
       
    65 	[[NSNotificationCenter defaultCenter] addObserver:self
       
    66 											 selector:@selector(authProgressDidChange:)
       
    67 												 name: AIXMPPAuthProgressNotification
       
    68 											   object:inAccount];
       
    69 }
       
    70 
       
    71 - (void) authProgressDidChange:(NSNotification *)notification
       
    72 {
       
    73 	AIXMPPOAuthProgressStep step = [[notification.userInfo objectForKey:KEY_XMPP_OAUTH_STEP] intValue];
       
    74 	
       
    75 	switch (step) {
       
    76 		case AIXMPPOAuthProgressPromptingUser:
       
    77 			[textField_OAuthStatus setStringValue:[AILocalizedString(@"Requesting authorization", nil) stringByAppendingEllipsis]];
       
    78 			break;
       
    79 			
       
    80 		case AIXMPPOAuthProgressContactingServer:
       
    81 			[textField_OAuthStatus setStringValue:[AILocalizedString(@"Contacting authorization server", nil) stringByAppendingEllipsis]];
       
    82 			break;
       
    83 
       
    84 		case AIXMPPOAuthProgressPromotingForChat:
       
    85 			[textField_OAuthStatus setStringValue:[AILocalizedString(@"Promoting authorization for chat", nil) stringByAppendingEllipsis]];
       
    86 			break;
       
    87 
       
    88 		case AIXMPPOAuthProgressSuccess:
       
    89 			[textField_OAuthStatus setStringValue:AILocalizedString(@"Adium is authorized for Facebook Chat.", nil)];
       
    90 			break;
       
    91 			
       
    92 		case AIXMPPOAuthProgressFailure:
       
    93 			[textField_OAuthStatus setStringValue:AILocalizedString(@"Could not complete authorization.", nil)];
       
    94 			[button_OAuthStart setEnabled:YES];
       
    95 			break;
       
    96 	}
       
    97 }
       
    98 
       
    99 /*!
       
   100  * @brief A preference was changed
       
   101  *
       
   102  * Don't save here; merely update controls as necessary.
       
   103  */
       
   104 - (IBAction)changedPreference:(id)sender
       
   105 {
       
   106 	if (sender == button_OAuthStart) {
       
   107 		[(AIPurpleOAuthJabberAccount *)account requestAuthorization];
       
   108 		[button_OAuthStart setEnabled:NO];
       
   109 
       
   110 	} else 
       
   111 		[super changedPreference:sender];
       
   112 }
       
   113 
       
   114 /* xxx it'd be better to link to an entry in our docs */
       
   115 - (IBAction)showHelp:(id)sender
       
   116 {
       
   117 	[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://trac.adium.im/wiki/FacebookChat"]];
       
   118 }
       
   119 
       
   120 @end