adium: condense code
[siplcs.git] / src / adium / ESSIPEAccountViewController.m
blobdc941c33f399c05df8db0c2814e1c6f7a6c95e15
1 //
2 //  ESSIPEAccountViewController.m
3 //  SIPEAdiumPlugin
4 //
5 //  Created by Matt Meissner on 10/30/09.
6 //  Modified by Michael Lamb on 2/27/13
7 //  Copyright 2013 Michael Lamb/Harris Kauffman. All rights reserved.
8 //
10 #import <AdiumLibpurple/CBPurpleAccount.h>
11 #import <ESDebugAILog.h>
12 #import "ESSIPEAccountViewController.h"
14 #include "prpl.h"
15 #include "ESPurpleSIPEAccount.h"
17 // Gotta define these here, because they're not yet in the 10.9 SDK.  :(
18 #define NSAppKitVersionNumber10_8 1187
19 #define NSAppKitVersionNumber10_8_5 1187.4
20 #define NSAppKitVersionNumber10_9 1265
22 @implementation ESSIPEAccountViewController
24 - (id)init {
25     [super init];
26     
27     sipe_key_to_gui =
28     [[NSDictionary alloc] initWithObjectsAndKeys:
29      textField_password,         KEY_SIPE_PASSWORD,
30      textField_windowsLogin,     KEY_SIPE_WINDOWS_LOGIN,
31      checkBox_singleSignOn,      KEY_SIPE_SINGLE_SIGN_ON,
32      checkbox_dontPublish,       KEY_SIPE_DONT_PUBLISH,
33      textField_userAgent,        KEY_SIPE_USER_AGENT,
34      textField_emailURL,         KEY_SIPE_EMAIL_URL,
35      textField_email,            KEY_SIPE_EMAIL,
36      textField_emailLogin,       KEY_SIPE_EMAIL_LOGIN,
37      textField_emailPassword,    KEY_SIPE_EMAIL_PASSWORD,
38      textField_groupchatUser,    KEY_SIPE_GROUP_CHAT_PROXY,
39      popup_connectionType,       KEY_SIPE_CONNECTION_TYPE,
40      popup_authenticationScheme, KEY_SIPE_AUTH_SCHEME,
41      checkbox_beastDisable,      KEY_SIPE_BEAST_DISABLE,
42      nil
43      ];
44     
45     return self;
48 - (void)dealloc
50     [sipe_key_to_gui release];
51     [super dealloc];
54 - (NSString *)nibName{
55     return @"ESSIPEAccountView";
58 #pragma mark Configuration methods
59 - (void)configureForAccount:(AIAccount *)inAccount
61     [super configureForAccount:inAccount];
63     // BEAST mitigation for Mavericks users
64     if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_8) {
65         // We are not running on Mavericks - Don't display BEAST mitigation configuration option
66         [checkbox_beastDisable setHidden:YES];
67     }
68     
69     // Only need 1 hash for both connection & auth since there are no overlapping keys
70     NSDictionary *conn_auth_dict =
71     [NSDictionary dictionaryWithObjectsAndKeys:
72      @"NTLM",@"ntlm",
73      @"Kerberos",@"krb5",
74      @"TLS-DSK",@"tls-dsk",
75      @"Auto",@"auto",
76      @"SSL/TLS",@"tls",
77      @"TCP",@"tcp",
78      nil];
79     
80     for (NSString* key in sipe_key_to_gui) {
81         id value = [sipe_key_to_gui objectForKey:key];
82         
83         if ([value isKindOfClass:[NSTextField class]]) {
84             NSString *tmp = [account preferenceForKey:key group:GROUP_ACCOUNT_STATUS];
85             [value setStringValue:(tmp ? tmp : @"")];
86         } else if ([value isKindOfClass:[NSPopUpButton class]]) {
87             // NSPopUpButton *MUST* appear before NSButton in the if/else
88             //   because  NSPopUpButton is a NSButton...
89             NSString *tmp_key = [account preferenceForKey:key group:GROUP_ACCOUNT_STATUS];
90             NSString *tmp = [key isEqualToString:KEY_SIPE_CONNECTION_TYPE] ? @"auto" : @"ntlm";
91             
92             if (conn_auth_dict[tmp_key])
93                 tmp = conn_auth_dict[tmp_key];
94             
95             [value selectItemWithTitle:tmp];
96         } else if ([value isKindOfClass:[NSButton class]]) {
97             [value setState:[[account preferenceForKey:key group:GROUP_ACCOUNT_STATUS] boolValue]];
98         } else {
99             AILog(@"(ESSIPEAccountViewController) Unknown class %@ for key %@", [value class], key);
100         }
101     }
104 - (void)saveConfiguration
106     [super saveConfiguration];
107     
108     // Only need 1 hash for both connection & auth since there are no overlapping keys
109     NSDictionary *conn_auth_dict =
110     [NSDictionary dictionaryWithObjectsAndKeys:
111      @"ntlm",@"NTLM",
112      @"krb5",@"Kerberos",
113      @"tls-dsk",@"TLS-DSK",
114      @"auto",@"Auto",
115      @"tls",@"SSL/TLS",
116      @"tcp",@"TCP",
117      nil];
118     
119     for (NSString* key in sipe_key_to_gui) {
120         id value = [sipe_key_to_gui objectForKey:key];
121         
122         if ([value isKindOfClass:[NSTextField class]]) {
123             [account
124              setPreference:[[value stringValue] length] ? [value stringValue] : @""
125              forKey:key
126              group:GROUP_ACCOUNT_STATUS];
127         } else if ([value isKindOfClass:[NSPopUpButton class]]) {
128             // NSPopUpButton *MUST* appear before NSButton in the if/else
129             //   because  NSPopUpButton is a NSButton...
130             NSString *tmp = conn_auth_dict[[[value selectedItem] title]];
131             [account
132              setPreference:tmp
133              forKey:key
134              group:GROUP_ACCOUNT_STATUS];
135         } else if ([value isKindOfClass:[NSButton class]]) {
136             [account
137              setPreference:[NSNumber numberWithBool:[value state]]
138              forKey:key
139              group:GROUP_ACCOUNT_STATUS];
140         } else {
141             AILog(@"(ESSIPEAccountViewController) Unknown class %@ for key %@", [value class], key);
142         }
143     }
146 @end