Plugins/General Preferences/ESGeneralPreferences.m
author Zachary West <zacw@adium.im>
Wed Nov 25 22:28:47 2009 -0500 (2009-11-25)
changeset 2820 37f86ef91f64
parent 2392 955aecf2b34c
child 3326 030035dabb86
permissions -rw-r--r--
Code simplification; remove the old preferences, and don't use a static variable to count the lines. Refs #13362.

I can't imagine using a static variable like this wouldn't cause problems, especially with "save chats" enabled; we'd be messing with the same static variable like crazy. I'm betting this explains some weird context problems, so let's see if this helps #13362.
David@0
     1
/* 
David@0
     2
 * Adium is the legal property of its developers, whose names are listed in the copyright file included
David@0
     3
 * with this source distribution.
David@0
     4
 * 
David@0
     5
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
David@0
     6
 * General Public License as published by the Free Software Foundation; either version 2 of the License,
David@0
     7
 * or (at your option) any later version.
David@0
     8
 * 
David@0
     9
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
David@0
    10
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
David@0
    11
 * Public License for more details.
David@0
    12
 * 
David@0
    13
 * You should have received a copy of the GNU General Public License along with this program; if not,
David@0
    14
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
David@0
    15
 */
David@0
    16
David@0
    17
#import <Adium/AIContentControllerProtocol.h>
David@0
    18
#import <Adium/AIInterfaceControllerProtocol.h>
David@0
    19
#import "AISoundController.h"
David@0
    20
#import "ESGeneralPreferences.h"
David@0
    21
#import "ESGeneralPreferencesPlugin.h"
David@0
    22
#import "PTHotKeyCenter.h"
David@0
    23
#import "PTHotKey.h"
David@0
    24
#import "SRRecorderControl.h"
David@0
    25
#import "PTHotKey.h"
David@0
    26
#import "AIMessageHistoryPreferencesWindowController.h"
David@0
    27
#import "AIMessageWindowController.h"
David@0
    28
#import <Adium/AIServiceIcons.h>
David@0
    29
#import <Adium/AIStatusIcons.h>
David@0
    30
#import <AIUtilities/AIColorAdditions.h>
David@0
    31
#import <AIUtilities/AIFontAdditions.h>
David@0
    32
#import <AIUtilities/AIImageAdditions.h>
David@0
    33
#import <AIUtilities/AIMenuAdditions.h>
David@0
    34
#import <AIUtilities/AIPopUpButtonAdditions.h>
David@0
    35
David@0
    36
#define	PREF_GROUP_DUAL_WINDOW_INTERFACE	@"Dual Window Interface"
David@0
    37
#define KEY_TABBAR_POSITION					@"Tab Bar Position"
David@0
    38
David@84
    39
@interface ESGeneralPreferences ()
David@0
    40
- (NSMenu *)tabChangeKeysMenu;
David@0
    41
- (NSMenu *)sendKeysMenu;
David@0
    42
- (NSMenu *)tabPositionMenu;
David@0
    43
@end
David@0
    44
David@0
    45
@implementation ESGeneralPreferences
David@0
    46
David@0
    47
// XXX in order to edit the nib, you need the ShortcutReporter palette
David@0
    48
// You can download it at http://evands.penguinmilitia.net/ShortcutRecorder.palette.zip
David@0
    49
// This comes from http://wafflesoftware.net/shortcut/
David@0
    50
Evan@541
    51
+ (NSSet *)keyPathsForValuesAffectingChatHistoryDisplayActive
Evan@541
    52
{
Evan@542
    53
	return [NSSet setWithObjects:@"adium.preferenceController.Logging.Enable Logging",
Evan@542
    54
			@"adium.preferenceController.Message Context Display.Display Message Context",
Evan@542
    55
			nil];
Evan@541
    56
}
Evan@541
    57
David@0
    58
//Preference pane properties
David@0
    59
- (NSString *)paneIdentifier
David@0
    60
{
David@0
    61
	return @"General";
David@0
    62
}
David@0
    63
- (NSString *)paneName{	
David@0
    64
    return AILocalizedString(@"General","General preferences label");
David@0
    65
}
David@0
    66
- (NSString *)nibName{
David@0
    67
    return @"GeneralPreferences";
David@0
    68
}
David@0
    69
- (NSImage *)paneIcon
David@0
    70
{
David@0
    71
	return [NSImage imageNamed:@"pref-general" forClass:[self class]];
David@0
    72
}
David@0
    73
David@0
    74
//Configure the preference view
David@0
    75
- (void)viewDidLoad
David@0
    76
{
David@0
    77
	BOOL			sendOnEnter, sendOnReturn;
Evan@541
    78
David@0
    79
	//Interface
David@95
    80
    [checkBox_messagesInTabs setState:[[adium.preferenceController preferenceForKey:KEY_TABBED_CHATTING
David@0
    81
																				group:PREF_GROUP_INTERFACE] boolValue]];
David@95
    82
	[checkBox_arrangeByGroup setState:[[adium.preferenceController preferenceForKey:KEY_GROUP_CHATS_BY_GROUP
David@0
    83
																				group:PREF_GROUP_INTERFACE] boolValue]];
David@0
    84
	
David@0
    85
	// Update Checking
Peter@197
    86
	[checkBox_updatesAutomatic setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"SUEnableAutomaticChecks"]];
David@421
    87
	[checkBox_updatesProfileInfo setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"SUSendProfileInfo"]];
David@0
    88
	[checkBox_updatesIncludeBetas setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"AIAlwaysUpdateToBetas"]];
David@0
    89
David@0
    90
	//Chat Cycling
David@0
    91
	[popUp_tabKeys setMenu:[self tabChangeKeysMenu]];
David@413
    92
	[popUp_tabKeys selectItemWithTag:[[adium.preferenceController preferenceForKey:KEY_TAB_SWITCH_KEYS
David@0
    93
																						 group:PREF_GROUP_CHAT_CYCLING] intValue]];
David@0
    94
David@0
    95
	//General
David@95
    96
	sendOnEnter = [[adium.preferenceController preferenceForKey:SEND_ON_ENTER
David@0
    97
															group:PREF_GROUP_GENERAL] boolValue];
David@95
    98
	sendOnReturn = [[adium.preferenceController preferenceForKey:SEND_ON_RETURN
David@0
    99
															group:PREF_GROUP_GENERAL] boolValue];
David@0
   100
	[popUp_sendKeys setMenu:[self sendKeysMenu]];
David@0
   101
	
David@0
   102
	if (sendOnEnter && sendOnReturn) {
David@413
   103
		[popUp_sendKeys selectItemWithTag:AISendOnBoth];
David@0
   104
	} else if (sendOnEnter) {
David@413
   105
		[popUp_sendKeys selectItemWithTag:AISendOnEnter];			
David@0
   106
	} else if (sendOnReturn) {
David@413
   107
		[popUp_sendKeys selectItemWithTag:AISendOnReturn];
David@0
   108
	}
David@0
   109
David@0
   110
	[popUp_tabPositionMenu setMenu:[self tabPositionMenu]];
David@413
   111
	[popUp_tabPositionMenu selectItemWithTag:[[adium.preferenceController preferenceForKey:KEY_TABBAR_POSITION
David@0
   112
																								 group:PREF_GROUP_DUAL_WINDOW_INTERFACE] intValue]];
zacw@2820
   113
David@0
   114
	//Global hotkey
zacw@2391
   115
	TISInputSourceRef currentLayout = TISCopyCurrentKeyboardLayoutInputSource();
zacw@2391
   116
	
zacw@2391
   117
	if (TISGetInputSourceProperty(currentLayout, kTISPropertyUnicodeKeyLayoutData)) {
zacw@2391
   118
		PTKeyCombo *keyCombo = [[[PTKeyCombo alloc] initWithPlistRepresentation:[adium.preferenceController preferenceForKey:KEY_GENERAL_HOTKEY
zacw@2391
   119
																														 group:PREF_GROUP_GENERAL]] autorelease];
zacw@2391
   120
		[shortcutRecorder setKeyCombo:SRMakeKeyCombo([keyCombo keyCode], [shortcutRecorder carbonToCocoaFlags:[keyCombo modifiers]])];
zacw@2391
   121
		[shortcutRecorder setAnimates:YES];
zacw@2391
   122
		[shortcutRecorder setStyle:SRGreyStyle];
zacw@2391
   123
		
zacw@2391
   124
		[label_shortcutRecorder setLocalizedString:AILocalizedString(@"When pressed, this key combination will bring Adium to the front", nil)];
zacw@2391
   125
	} else {
zacw@2391
   126
		[shortcutRecorder setEnabled:NO];
zacw@2392
   127
		
zacw@2391
   128
		[label_shortcutRecorder setLocalizedString:AILocalizedString(@"You are using an old-style (rsrc) keyboard layout which Adium does not support.", nil)];
zacw@2391
   129
	}
zacw@2392
   130
	
zacw@2392
   131
	CFRelease(currentLayout);
David@0
   132
David@0
   133
    [self configureControlDimming];
David@0
   134
}
David@0
   135
David@0
   136
//Called in response to all preference controls, applies new settings
David@0
   137
- (IBAction)changePreference:(id)sender
David@0
   138
{
David@0
   139
    if (sender == popUp_tabKeys) {
David@0
   140
		AITabKeys keySelection = [[sender selectedItem] tag];
David@0
   141
David@95
   142
		[adium.preferenceController setPreference:[NSNumber numberWithInt:keySelection]
David@0
   143
											 forKey:KEY_TAB_SWITCH_KEYS
David@0
   144
											  group:PREF_GROUP_CHAT_CYCLING];
David@0
   145
		
David@0
   146
	} else if (sender == popUp_sendKeys) {
David@0
   147
		AISendKeys 	keySelection = [[sender selectedItem] tag];
David@0
   148
		BOOL		sendOnEnter = (keySelection == AISendOnEnter || keySelection == AISendOnBoth);
David@0
   149
		BOOL		sendOnReturn = (keySelection == AISendOnReturn || keySelection == AISendOnBoth);
David@0
   150
		
David@95
   151
		[adium.preferenceController setPreference:[NSNumber numberWithInt:sendOnEnter]
David@0
   152
											 forKey:SEND_ON_ENTER
David@0
   153
											  group:PREF_GROUP_GENERAL];
David@95
   154
		[adium.preferenceController setPreference:[NSNumber numberWithInt:sendOnReturn]
David@0
   155
											 forKey:SEND_ON_RETURN
David@0
   156
                                              group:PREF_GROUP_GENERAL];
David@0
   157
	} else if (sender == checkBox_updatesAutomatic) {
Peter@198
   158
		[[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:@"SUEnableAutomaticChecks"];
David@0
   159
		[self configureControlDimming];
David@0
   160
	} else if (sender == checkBox_updatesProfileInfo) {
David@421
   161
		[[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:@"SUSendProfileInfo"];
David@0
   162
	} else if (sender == checkBox_updatesIncludeBetas) {
David@0
   163
		[[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:@"AIAlwaysUpdateToBetas"];
David@0
   164
	}
David@0
   165
}
David@0
   166
David@0
   167
//Dim controls as needed
David@0
   168
- (void)configureControlDimming
David@0
   169
{
David@0
   170
	[checkBox_arrangeByGroup setEnabled:[checkBox_messagesInTabs state]];
David@0
   171
	[checkBox_updatesProfileInfo setEnabled:[checkBox_updatesAutomatic state]];
zacw@422
   172
#ifdef BETA_RELEASE
zacw@422
   173
	[checkBox_updatesIncludeBetas setEnabled:NO];
zacw@2383
   174
	[checkBox_updatesIncludeBetas setState:NSOnState];
zacw@422
   175
#else
David@0
   176
	[checkBox_updatesIncludeBetas setEnabled:[checkBox_updatesAutomatic state]];
zacw@422
   177
#endif
David@0
   178
}
David@0
   179
David@0
   180
/*!
David@0
   181
 * @brief Construct our menu by hand for easy localization
David@0
   182
 */
David@0
   183
- (NSMenu *)tabChangeKeysMenu
David@0
   184
{
David@0
   185
	NSMenu		*menu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
David@0
   186
#define PLACE_OF_INTEREST_SIGN	"\u2318"
David@0
   187
#define LEFTWARDS_ARROW			"\u2190"
David@0
   188
#define RIGHTWARDS_ARROW		"\u2192"
David@0
   189
#define SHIFT_ARROW				"\u21E7"
David@0
   190
#define OPTION_KEY				"\u2325"
David@0
   191
David@0
   192
	[menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Arrows (%@ and %@)","Directional arrow keys word"), [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN LEFTWARDS_ARROW], [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN RIGHTWARDS_ARROW]]
David@0
   193
					target:nil
David@0
   194
					action:nil
David@0
   195
			 keyEquivalent:@""
David@0
   196
					   tag:AISwitchArrows];
David@0
   197
	
David@0
   198
	[menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Shift + Arrows (%@ and %@)","Shift key word + Directional arrow keys word"), [NSString stringWithUTF8String:SHIFT_ARROW PLACE_OF_INTEREST_SIGN LEFTWARDS_ARROW], [NSString stringWithUTF8String:SHIFT_ARROW PLACE_OF_INTEREST_SIGN RIGHTWARDS_ARROW]]
David@0
   199
					target:nil
David@0
   200
					action:nil
David@0
   201
			 keyEquivalent:@""
David@0
   202
					   tag:AISwitchShiftArrows];
David@0
   203
	
David@0
   204
	[menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Option + Arrows (%@ and %@)","Option key word + Directional arrow keys word"), [NSString stringWithUTF8String:OPTION_KEY PLACE_OF_INTEREST_SIGN LEFTWARDS_ARROW], [NSString stringWithUTF8String:OPTION_KEY PLACE_OF_INTEREST_SIGN RIGHTWARDS_ARROW]]
David@0
   205
					target:nil
David@0
   206
					action:nil
David@0
   207
			 keyEquivalent:@""
David@0
   208
					   tag:AIOptArrows];	
David@0
   209
	
David@0
   210
	[menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Brackets (%@ and %@)","Word for [ and ] keys"), [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "["], [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "]"]]
David@0
   211
					target:nil
David@0
   212
					action:nil
David@0
   213
			 keyEquivalent:@""
David@0
   214
					   tag:AIBrackets];
David@0
   215
	
David@0
   216
	[menu addItemWithTitle:[NSString stringWithFormat:AILocalizedString(@"Curly braces (%@ and %@)","Word for { and } keys"), [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "{"], [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN "}"]]
David@0
   217
					target:nil
David@0
   218
					action:nil
David@0
   219
			 keyEquivalent:@""
David@0
   220
					   tag:AIBraces];
David@0
   221
	
David@0
   222
	
David@0
   223
	return [menu autorelease];		
David@0
   224
}
David@0
   225
David@0
   226
- (BOOL)shortcutRecorder:(SRRecorderControl *)aRecorder isKeyCode:(signed short)keyCode andFlagsTaken:(unsigned int)flags reason:(NSString **)aReason
David@0
   227
{
David@0
   228
	return NO;
David@0
   229
}
David@0
   230
David@0
   231
- (void)shortcutRecorder:(SRRecorderControl *)aRecorder keyComboDidChange:(KeyCombo)newKeyCombo
David@0
   232
{
David@0
   233
	if (aRecorder == shortcutRecorder) {
David@0
   234
		PTKeyCombo *keyCombo = [PTKeyCombo keyComboWithKeyCode:[shortcutRecorder keyCombo].code
David@0
   235
													 modifiers:[shortcutRecorder cocoaToCarbonFlags:[shortcutRecorder keyCombo].flags]];
David@95
   236
		[adium.preferenceController setPreference:[keyCombo plistRepresentation]
David@0
   237
											 forKey:KEY_GENERAL_HOTKEY
David@0
   238
											  group:PREF_GROUP_GENERAL];
David@0
   239
	}
David@0
   240
}
David@0
   241
David@0
   242
/*!
David@0
   243
 * @brief Construct our menu by hand for easy localization
David@0
   244
 */
David@0
   245
- (NSMenu *)sendKeysMenu
David@0
   246
{
David@0
   247
	NSMenu		*menu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
David@0
   248
David@0
   249
	[menu addItemWithTitle:AILocalizedString(@"Enter","Enter key for sending messages")
David@0
   250
					target:nil
David@0
   251
					action:nil
David@0
   252
			 keyEquivalent:@""
David@0
   253
					   tag:AISendOnEnter];
David@0
   254
David@0
   255
	[menu addItemWithTitle:AILocalizedString(@"Return","Return key for sending messages")
David@0
   256
					target:nil
David@0
   257
					action:nil
David@0
   258
			 keyEquivalent:@""
David@0
   259
					   tag:AISendOnReturn];
David@0
   260
David@0
   261
	[menu addItemWithTitle:AILocalizedString(@"Enter and Return","Enter and return key for sending messages")
David@0
   262
					target:nil
David@0
   263
					action:nil
David@0
   264
			 keyEquivalent:@""
David@0
   265
					   tag:AISendOnBoth];
David@0
   266
David@0
   267
	return [menu autorelease];		
David@0
   268
}
David@0
   269
David@0
   270
- (NSMenu *)tabPositionMenu
David@0
   271
{
David@0
   272
	NSMenu		*menu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
David@0
   273
	
David@0
   274
	[menu addItemWithTitle:AILocalizedString(@"Top","Position menu item for tabs at the top of the message window")
David@0
   275
					target:nil
David@0
   276
					action:nil
David@0
   277
			 keyEquivalent:@""
David@0
   278
					   tag:AdiumTabPositionTop];
David@0
   279
	
David@0
   280
	[menu addItemWithTitle:AILocalizedString(@"Bottom","Position menu item for tabs at the bottom of the message window")
David@0
   281
					target:nil
David@0
   282
					action:nil
David@0
   283
			 keyEquivalent:@""
David@0
   284
					   tag:AdiumTabPositionBottom];
David@0
   285
	
David@0
   286
	[menu addItemWithTitle:AILocalizedString(@"Left","Position menu item for tabs at the left of the message window")
David@0
   287
					target:nil
David@0
   288
					action:nil
David@0
   289
			 keyEquivalent:@""
David@0
   290
					   tag:AdiumTabPositionLeft];
David@0
   291
David@0
   292
	[menu addItemWithTitle:AILocalizedString(@"Right","Position menu item for tabs at the right of the message window")
David@0
   293
					target:nil
David@0
   294
					action:nil
David@0
   295
			 keyEquivalent:@""
David@0
   296
					   tag:AdiumTabPositionRight];
David@0
   297
	
Evan@541
   298
	return [menu autorelease];
Evan@541
   299
}
Evan@541
   300
Evan@541
   301
- (BOOL)chatHistoryDisplayActive
Evan@541
   302
{
Evan@541
   303
	return ([[adium.preferenceController preferenceForKey:@"Display Message Context" group:@"Message Context Display"] boolValue] &&
Evan@541
   304
			[[adium.preferenceController preferenceForKey:@"Enable Logging" group:@"Logging"] boolValue]);
Evan@541
   305
}
Evan@541
   306
- (void)setChatHistoryDisplayActive:(BOOL)flag
Evan@541
   307
{
Evan@541
   308
	[adium.preferenceController setPreference:[NSNumber	numberWithBool:flag]
Evan@541
   309
	 forKey:@"Display Message Context"
Evan@541
   310
	 group:@"Message Context Display"];
David@0
   311
}
David@0
   312
David@0
   313
#pragma mark Message history
David@0
   314
- (IBAction)configureMessageHistory:(id)sender
David@0
   315
{
David@0
   316
	[AIMessageHistoryPreferencesWindowController configureMessageHistoryPreferencesOnWindow:[[self view] window]];
David@0
   317
}
David@0
   318
David@0
   319
@end