William Bowling is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this again1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | /*
* Adium is the legal property of its developers, whose names are listed in the copyright file included
* with this source distribution.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import <Adium/AIAccountControllerProtocol.h>
#import "AIAccountProxySettings.h"
#import <AIUtilities/AIMenuAdditions.h>
#import <AIUtilities/AIPopUpButtonAdditions.h>
#import <Adium/AIAccount.h>
@interface AIAccountProxySettings ()
- (void)configureControlDimming;
- (void)updatePasswordField;
- (NSMenu *)_proxyMenu;
- (NSMenuItem *)_proxyMenuItemWithTitle:(NSString *)title tag:(NSInteger)tag;
@end
@implementation AIAccountProxySettings
+ (void)initialize
{
if (self == [AIAccountProxySettings class]) {
[self exposeBinding:@"showProxyDetailsControls"];
}
}
/*!
* @brief Init our account proxy settings
*
* Loads AccountProxy.nib and sets up menus
*/
- (id)init
{
if ((self = [super init])) {
//Load our view
[NSBundle loadNibNamed:@"AccountProxy" owner:self];
//Setup our menu
[popUpButton_proxy setMenu:[self _proxyMenu]];
}
return self;
}
/*!
* @brief Our view
*/
- (NSView *)view
{
return view_accountProxy;
}
/*!
* @brief Deallocate
*/
- (void)dealloc
{
[view_accountProxy release];
[super dealloc];
}
/*!
* @brief Toggle proxy
*
* Called when proxy usage is turned on or off
*/
- (IBAction)toggleProxy:(id)sender
{
[self configureControlDimming];
}
/*!
* @brief Change proxy type
*
* Called when the proxy type is changed
*/
- (void)changeProxyType:(id)sender
{
[self configureControlDimming];
}
/*!
* @brief Configure the proxy view for the passed account
*
* @param inAccount The account for which to configure
*/
- (void)configureForAccount:(AIAccount *)inAccount
{
if (account != inAccount) {
[account release];
account = [inAccount retain];
//Enabled & Type
[checkBox_useProxy setState:[[account preferenceForKey:KEY_ACCOUNT_PROXY_ENABLED
group:GROUP_ACCOUNT_STATUS] boolValue]];
[popUpButton_proxy selectItemWithTag:[[account preferenceForKey:KEY_ACCOUNT_PROXY_TYPE
group:GROUP_ACCOUNT_STATUS] integerValue]];
//Host & Port
NSString *proxyHost = [account preferenceForKey:KEY_ACCOUNT_PROXY_HOST group:GROUP_ACCOUNT_STATUS];
[textField_proxyHostName setStringValue:(proxyHost ? proxyHost : @"")];
NSString *proxyPort = [account preferenceForKey:KEY_ACCOUNT_PROXY_PORT group:GROUP_ACCOUNT_STATUS];
[textField_proxyPortNumber setStringValue:(proxyPort ? proxyPort : @"")];
//Username
NSString *proxyUser = [account preferenceForKey:KEY_ACCOUNT_PROXY_USERNAME group:GROUP_ACCOUNT_STATUS];
[textField_proxyUserName setStringValue:(proxyUser ? proxyUser : @"")];
[self updatePasswordField];
[self configureControlDimming];
}
}
/*!
* @brief Save current control values
*/
- (void)saveConfiguration
{
NSString *proxyHostName = [textField_proxyHostName stringValue];
NSString *proxyUserName = [textField_proxyUserName stringValue];
//Password
if (![proxyUserName isEqualToString:[account preferenceForKey:KEY_ACCOUNT_PROXY_USERNAME group:GROUP_ACCOUNT_STATUS]] ||
![proxyHostName isEqualToString:[account preferenceForKey:KEY_ACCOUNT_PROXY_HOST group:GROUP_ACCOUNT_STATUS]]) {
[adium.accountController setPassword:[textField_proxyPassword stringValue]
forProxyServer:proxyHostName
userName:proxyUserName];
}
//Enabled & Type
[account setPreference:[NSNumber numberWithInteger:[checkBox_useProxy state]]
forKey:KEY_ACCOUNT_PROXY_ENABLED group:GROUP_ACCOUNT_STATUS];
[account setPreference:[NSNumber numberWithInteger:[[popUpButton_proxy selectedItem] tag]]
forKey:KEY_ACCOUNT_PROXY_TYPE group:GROUP_ACCOUNT_STATUS];
//Host & Port
[account setPreference:[textField_proxyHostName stringValue]
forKey:KEY_ACCOUNT_PROXY_HOST group:GROUP_ACCOUNT_STATUS];
[account setPreference:[textField_proxyPortNumber stringValue]
forKey:KEY_ACCOUNT_PROXY_PORT group:GROUP_ACCOUNT_STATUS];
//Username
[account setPreference:[textField_proxyUserName stringValue]
forKey:KEY_ACCOUNT_PROXY_USERNAME group:GROUP_ACCOUNT_STATUS];
}
/*!
* @brief Update password field
*/
- (void)updatePasswordField
{
NSString *proxyHostName = [textField_proxyHostName stringValue];
NSString *proxyUserName = [textField_proxyUserName stringValue];
if (proxyHostName && proxyUserName) {
NSString *proxyPassword = [adium.accountController passwordForProxyServer:proxyHostName
userName:proxyUserName];
[textField_proxyPassword setStringValue:(proxyPassword ? proxyPassword : @"")];
}
}
/*!
* @brief User changed proxy preference
*
* We set to nil instead of the @"" a stringValue would return because we want to return to the global (default) value
* if the user clears the field.
*/
- (void)controlTextDidChange:(NSNotification *)aNotification
{
NSTextField *sender = [aNotification object];
if (sender == textField_proxyHostName) {
} else if (sender == textField_proxyPortNumber) {
[account setPreference:[NSNumber numberWithInteger:[textField_proxyPortNumber integerValue]]
forKey:KEY_ACCOUNT_PROXY_PORT
group:GROUP_ACCOUNT_STATUS];
} else if (sender == textField_proxyUserName) {
NSString *userName = [textField_proxyUserName stringValue];
//If the username changed, save the new username and clear the password field
if (![userName isEqualToString:[account preferenceForKey:KEY_ACCOUNT_PROXY_USERNAME
group:GROUP_ACCOUNT_STATUS]]) {
[account setPreference:userName
forKey:KEY_ACCOUNT_PROXY_USERNAME
group:GROUP_ACCOUNT_STATUS];
//Update the password field
[textField_proxyPassword setStringValue:@""];
[textField_proxyPassword setEnabled:(userName && [userName length])];
}
}
}
- (BOOL)showProxyDetailsControls
{
AdiumProxyType proxyType = [[popUpButton_proxy selectedItem] tag];
BOOL usingSystemwide = (proxyType == Adium_Proxy_Default_SOCKS5 ||
proxyType == Adium_Proxy_Default_HTTP ||
proxyType == Adium_Proxy_Default_SOCKS4);
return !usingSystemwide;
}
/*!
* @brief Configure dimming of proxy controls
*/
- (void)configureControlDimming
{
AdiumProxyType proxyType = [[popUpButton_proxy selectedItem] tag];
BOOL proxyEnabled = [checkBox_useProxy state];
BOOL usingSystemwide = (proxyType == Adium_Proxy_Default_SOCKS5 ||
proxyType == Adium_Proxy_Default_HTTP ||
proxyType == Adium_Proxy_Default_SOCKS4);
[popUpButton_proxy setEnabled:proxyEnabled];
[textField_proxyHostName setEnabled:(proxyEnabled && !usingSystemwide)];
[textField_proxyPortNumber setEnabled:(proxyEnabled && !usingSystemwide)];
[textField_proxyUserName setEnabled:(proxyEnabled && !usingSystemwide)];
[textField_proxyPassword setEnabled:(proxyEnabled && !usingSystemwide)];
[self willChangeValueForKey:@"showProxyDetailsControls"];
[self didChangeValueForKey:@"showProxyDetailsControls"];
}
//Proxy type menu ------------------------------------------------------------------------------------------------------
#pragma mark Proxy type menu
/*!
* @brief Build the proxy type menu
*
* @result An NSMenu of supported proxy settings
*/
- (NSMenu *)_proxyMenu
{
NSMenu *proxyMenu = [[NSMenu alloc] init];
[proxyMenu addItem:[self _proxyMenuItemWithTitle:AILocalizedString(@"Systemwide SOCKS4 Settings",nil) tag:Adium_Proxy_Default_SOCKS4]];
[proxyMenu addItem:[self _proxyMenuItemWithTitle:AILocalizedString(@"Systemwide SOCKS5 Settings",nil) tag:Adium_Proxy_Default_SOCKS5]];
[proxyMenu addItem:[self _proxyMenuItemWithTitle:AILocalizedString(@"Systemwide HTTP Settings",nil) tag:Adium_Proxy_Default_HTTP]];
[proxyMenu addItem:[self _proxyMenuItemWithTitle:@"SOCKS4" tag:Adium_Proxy_SOCKS4]];
[proxyMenu addItem:[self _proxyMenuItemWithTitle:@"SOCKS5" tag:Adium_Proxy_SOCKS5]];
[proxyMenu addItem:[self _proxyMenuItemWithTitle:@"HTTP" tag:Adium_Proxy_HTTP]];
return [proxyMenu autorelease];
}
/*!
* @brief Create a proxy menu menuItem
*
* Convenience method for _proxyMenu
*/
- (NSMenuItem *)_proxyMenuItemWithTitle:(NSString *)title tag:(NSInteger)tag
{
NSMenuItem *menuItem;
menuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
target:self
action:@selector(changeProxyType:)
keyEquivalent:@""];
[menuItem setTag:tag];
return [menuItem autorelease];
}
@end
|