Release 1.19.1 -- Bug Fixes I
[siplcs.git] / src / adium / ESSIPEAccountViewController.m
blob2d7cfa843e1ab11d5be83bdbba3b028d91acab6d
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     self = [super init];
26     
27     if (self) {
28         sipe_key_to_gui =
29             [[NSDictionary alloc] initWithObjectsAndKeys:
30              textField_windowsLogin,     KEY_SIPE_WINDOWS_LOGIN,
31              textField_password,         KEY_SIPE_PASSWORD,
32              textField_server,           KEY_SIPE_CONNECT_HOST,
33              popup_connectionType,       KEY_SIPE_CONNECTION_TYPE,
34              popup_authenticationScheme, KEY_SIPE_AUTH_SCHEME,
35              textField_userAgent,        KEY_SIPE_USER_AGENT,
36              checkBox_singleSignOn,      KEY_SIPE_SINGLE_SIGN_ON,
37              checkbox_beastDisable,      KEY_SIPE_BEAST_DISABLE,
38              textField_groupchatUser,    KEY_SIPE_GROUP_CHAT_PROXY,
39              textField_emailURL,         KEY_SIPE_EMAIL_URL,
40              textField_email,            KEY_SIPE_EMAIL,
41              textField_emailLogin,       KEY_SIPE_EMAIL_LOGIN,
42              textField_emailPassword,    KEY_SIPE_EMAIL_PASSWORD,
43              checkbox_dontPublish,       KEY_SIPE_DONT_PUBLISH,
44              nil
45              ];
46     }
47     
48     return self;
51 - (void)dealloc
53     [sipe_key_to_gui release];
54     [super dealloc];
57 - (NSString *)nibName{
58     return @"ESSIPEAccountView";
61 #pragma mark Configuration methods
62 - (void)configureForAccount:(AIAccount *)inAccount
64     [super configureForAccount:inAccount];
66     // BEAST mitigation for Mavericks and 10.8.5 users (with Security Update 2014-001)
67     if (NSAppKitVersionNumber < NSAppKitVersionNumber10_8_5) {
68         // We are not running on an OS with BEAST mitigations - Don't display this as a configuration option
69         [checkbox_beastDisable setHidden:YES];
70     }
71     
72     // Only need 1 hash for both connection & auth since there are no overlapping keys
73     NSDictionary *conn_auth_dict =
74     [NSDictionary dictionaryWithObjectsAndKeys:
75      @"NTLM",@"ntlm",
76      @"Kerberos",@"krb5",
77      @"TLS-DSK",@"tls-dsk",
78      @"Auto",@"auto",
79      @"SSL/TLS",@"tls",
80      @"TCP",@"tcp",
81      nil];
82     
83     for (NSString* key in sipe_key_to_gui) {
84         id value = [sipe_key_to_gui objectForKey:key];
85         
86         if ([value isKindOfClass:[NSTextField class]]) {
87             NSString *tmp = [account preferenceForKey:key group:GROUP_ACCOUNT_STATUS];
88             [value setStringValue:(tmp ? tmp : @"")];
89         } else if ([value isKindOfClass:[NSPopUpButton class]]) {
90             // NSPopUpButton *MUST* appear before NSButton in the if/else
91             //   because  NSPopUpButton is a NSButton...
92             NSString *tmp_key = [account preferenceForKey:key group:GROUP_ACCOUNT_STATUS];
93             NSString *tmp = @"auto";
94             
95             if ([conn_auth_dict objectForKey:tmp_key])
96                 tmp = [conn_auth_dict objectForKey:tmp_key];
97             
98             [value selectItemWithTitle:tmp];
99         } else if ([value isKindOfClass:[NSButton class]]) {
100             [value setState:[[account preferenceForKey:key group:GROUP_ACCOUNT_STATUS] boolValue]];
101         } else {
102             AILog(@"(ESSIPEAccountViewController) Unknown class %@ for key %@", [value class], key);
103         }
104     }
107 - (void)saveConfiguration
109     [super saveConfiguration];
110     
111     // Only need 1 hash for both connection & auth since there are no overlapping keys
112     NSDictionary *conn_auth_dict =
113     [NSDictionary dictionaryWithObjectsAndKeys:
114      @"ntlm",@"NTLM",
115      @"krb5",@"Kerberos",
116      @"tls-dsk",@"TLS-DSK",
117      @"auto",@"Auto",
118      @"tls",@"SSL/TLS",
119      @"tcp",@"TCP",
120      nil];
121     
122     for (NSString* key in sipe_key_to_gui) {
123         id value = [sipe_key_to_gui objectForKey:key];
124         
125         if ([value isKindOfClass:[NSTextField class]]) {
126             [account
127              setPreference:[[value stringValue] length] ? [value stringValue] : @""
128              forKey:key
129              group:GROUP_ACCOUNT_STATUS];
130         } else if ([value isKindOfClass:[NSPopUpButton class]]) {
131             // NSPopUpButton *MUST* appear before NSButton in the if/else
132             //   because  NSPopUpButton is a NSButton...
133             NSString *tmp = [conn_auth_dict objectForKey:[[value selectedItem] title]];
134             [account
135              setPreference:tmp
136              forKey:key
137              group:GROUP_ACCOUNT_STATUS];
138         } else if ([value isKindOfClass:[NSButton class]]) {
139             [account
140              setPreference:[NSNumber numberWithBool:[value state]]
141              forKey:key
142              group:GROUP_ACCOUNT_STATUS];
143         } else {
144             AILog(@"(ESSIPEAccountViewController) Unknown class %@ for key %@", [value class], key);
145         }
146     }
149 @end