Feature #6: Application Sharing (server part)
[siplcs.git] / src / adium / ESSIPEAccountViewController.m
blobbd1c4aead4edfc0240c85ee9a52661533f161180
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 <Adium/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              checkbox_allowWebPhoto,     KEY_SIPE_ALLOW_WEB_PHOTO,
45              nil
46              ];
47     }
48     
49     return self;
52 - (void)dealloc
54     [sipe_key_to_gui release];
55     [super dealloc];
58 - (NSString *)nibName{
59     return @"ESSIPEAccountView";
62 #pragma mark Configuration methods
63 - (void)configureForAccount:(AIAccount *)inAccount
65     [super configureForAccount:inAccount];
67     // BEAST mitigation for Mavericks and 10.8.5 users (with Security Update 2014-001)
68     if (NSAppKitVersionNumber < NSAppKitVersionNumber10_8_5) {
69         // We are not running on an OS with BEAST mitigations - Don't display this as a configuration option
70         [checkbox_beastDisable setHidden:YES];
71     }
72     
73     // Only need 1 hash for both connection & auth since there are no overlapping keys
74     NSDictionary *conn_auth_dict =
75     [NSDictionary dictionaryWithObjectsAndKeys:
76      @"NTLM",@"ntlm",
77      @"Kerberos",@"krb5",
78      @"TLS-DSK",@"tls-dsk",
79      @"Auto",@"auto",
80      @"SSL/TLS",@"tls",
81      @"TCP",@"tcp",
82      nil];
83     
84     for (NSString* key in sipe_key_to_gui) {
85         id value = [sipe_key_to_gui objectForKey:key];
86         
87         if ([value isKindOfClass:[NSTextField class]]) {
88             NSString *tmp = [account preferenceForKey:key group:GROUP_ACCOUNT_STATUS];
89             [value setStringValue:(tmp ? tmp : @"")];
90         } else if ([value isKindOfClass:[NSPopUpButton class]]) {
91             // NSPopUpButton *MUST* appear before NSButton in the if/else
92             //   because  NSPopUpButton is a NSButton...
93             NSString *tmp_key = [account preferenceForKey:key group:GROUP_ACCOUNT_STATUS];
94             NSString *tmp = @"auto";
95             
96             if ([conn_auth_dict objectForKey:tmp_key])
97                 tmp = [conn_auth_dict objectForKey:tmp_key];
98             
99             [value selectItemWithTitle:tmp];
100         } else if ([value isKindOfClass:[NSButton class]]) {
101             [value setState:[[account preferenceForKey:key group:GROUP_ACCOUNT_STATUS] boolValue]];
102         } else {
103             AILog(@"(ESSIPEAccountViewController) Unknown class %@ for key %@", [value class], key);
104         }
105     }
108 - (void)saveConfiguration
110     [super saveConfiguration];
111     
112     // Only need 1 hash for both connection & auth since there are no overlapping keys
113     NSDictionary *conn_auth_dict =
114     [NSDictionary dictionaryWithObjectsAndKeys:
115      @"ntlm",@"NTLM",
116      @"krb5",@"Kerberos",
117      @"tls-dsk",@"TLS-DSK",
118      @"auto",@"Auto",
119      @"tls",@"SSL/TLS",
120      @"tcp",@"TCP",
121      nil];
122     
123     for (NSString* key in sipe_key_to_gui) {
124         id value = [sipe_key_to_gui objectForKey:key];
125         
126         if ([value isKindOfClass:[NSTextField class]]) {
127             [account
128              setPreference:[[value stringValue] length] ? [value stringValue] : @""
129              forKey:key
130              group:GROUP_ACCOUNT_STATUS];
131         } else if ([value isKindOfClass:[NSPopUpButton class]]) {
132             // NSPopUpButton *MUST* appear before NSButton in the if/else
133             //   because  NSPopUpButton is a NSButton...
134             NSString *tmp = [conn_auth_dict objectForKey:[[value selectedItem] title]];
135             [account
136              setPreference:tmp
137              forKey:key
138              group:GROUP_ACCOUNT_STATUS];
139         } else if ([value isKindOfClass:[NSButton class]]) {
140             [account
141              setPreference:[NSNumber numberWithBool:[value state]]
142              forKey:key
143              group:GROUP_ACCOUNT_STATUS];
144         } else {
145             AILog(@"(ESSIPEAccountViewController) Unknown class %@ for key %@", [value class], key);
146         }
147     }
150 @end