Source/AIConfirmationsAdvancedPreferences.m
author Zachary West <zacw@adium.im>
Fri Oct 16 11:21:50 2009 -0400 (2009-10-16)
changeset 2724 347930af493c
parent 2450 08aa9c3a346c
child 2837 f7162bff4baf
permissions -rw-r--r--
Properly invert the BOOLs for the quit confirmations. Fixes #12817.
     1 //
     2 //  AIConfirmationsAdvancedPreferences.m
     3 //  Adium
     4 //
     5 //  Created by Zachary West on 2009-06-02.
     6 //  Copyright 2009 Adium. All rights reserved.
     7 //
     8 
     9 #import "AIConfirmationsAdvancedPreferences.h"
    10 #import "AIPreferenceWindowController.h"
    11 
    12 #import <Adium/AIPreferenceControllerProtocol.h>
    13 #import <Adium/AIInterfaceControllerProtocol.h>
    14 
    15 #import <AIUtilities/AIStringAdditions.h>
    16 #import <AIUtilities/AIImageAdditions.h>
    17 
    18 @implementation AIConfirmationsAdvancedPreferences
    19 #pragma mark Preference pane settings
    20 - (AIPreferenceCategory)category
    21 {
    22     return AIPref_Advanced;
    23 }
    24 - (NSString *)label{
    25     return AILocalizedString(@"Confirmations",nil);
    26 }
    27 - (NSString *)nibName{
    28     return @"AIConfirmationsAdvancedPreferences";
    29 }
    30 - (NSImage *)image{
    31 	return [NSImage imageNamed:@"pref-events" forClass:[AIPreferenceWindowController class]];
    32 }
    33 
    34 /*!
    35  * @brief The view loaded
    36  */
    37 - (void)viewDidLoad
    38 {
    39 	[label_quitConfirmation setLocalizedString:AILocalizedString(@"Quit Confirmation", "Preference")];
    40 	[checkBox_confirmBeforeQuitting setLocalizedString:AILocalizedString(@"Confirm before quitting Adium", "Quit Confirmation preference")];
    41 	[checkBox_quitConfirmFT setLocalizedString:AILocalizedString(@"File transfers are in progress", "Quit Confirmation preference")];
    42 	[checkBox_quitConfirmUnread setLocalizedString:AILocalizedString(@"There are unread messages", "Quit Confirmation preference")];
    43 	[checkBox_quitConfirmOpenChats setLocalizedString:AILocalizedString(@"There are open chat windows", "Quit Confirmation preference")];
    44 	[[matrix_quitConfirmType cellWithTag:AIQuitConfirmAlways] setTitle:AILocalizedString(@"Always","Confirmation preference")];
    45 	[[matrix_quitConfirmType cellWithTag:AIQuitConfirmSelective] setTitle:[AILocalizedString(@"Only when","Quit Confirmation preference") stringByAppendingEllipsis]];
    46 	
    47 	[label_messageCloseConfirmation setLocalizedString:AILocalizedString(@"Window Close Confirmation", "Preference")];
    48 	[checkBox_confirmBeforeClosing setLocalizedString:AILocalizedString(@"Confirm before closing multiple chat windows", "Message close confirmation preference")];
    49 	[[matrix_closeConfirmType cellWithTag:AIMessageCloseAlways] setTitle:AILocalizedString(@"Always", "Confirmation preference")];
    50 	[[matrix_closeConfirmType cellWithTag:AIMessageCloseUnread] setTitle:AILocalizedString(@"Only when there are unread messages", "Message close confirmation preference")];
    51 	
    52 	NSDictionary *confirmationDict = [adium.preferenceController preferencesForGroup:PREF_GROUP_CONFIRMATIONS];
    53 
    54 	[checkBox_confirmBeforeQuitting setState:[[confirmationDict objectForKey:KEY_CONFIRM_QUIT] boolValue]];
    55 	[matrix_quitConfirmType selectCellWithTag:[[confirmationDict objectForKey:KEY_CONFIRM_QUIT_TYPE] integerValue]];
    56 	[checkBox_quitConfirmFT setState:![[confirmationDict objectForKey:KEY_CONFIRM_QUIT_FT] boolValue]];
    57 	[checkBox_quitConfirmOpenChats setState:![[confirmationDict objectForKey:KEY_CONFIRM_QUIT_OPEN] boolValue]];
    58 	[checkBox_quitConfirmUnread setState:![[confirmationDict objectForKey:KEY_CONFIRM_QUIT_UNREAD] boolValue]];
    59 	
    60 	[checkBox_confirmBeforeClosing setState:[[confirmationDict objectForKey:KEY_CONFIRM_MSG_CLOSE] boolValue]];
    61 	[matrix_closeConfirmType selectCellWithTag:[[confirmationDict objectForKey:KEY_CONFIRM_MSG_CLOSE_TYPE] integerValue]];
    62 	
    63 	[self configureControlDimming];
    64 	
    65 	[super viewDidLoad];
    66 }
    67 
    68 - (void)viewWillClose
    69 {	
    70 	[super viewWillClose];
    71 }
    72 
    73 - (IBAction)changePreference:(id)sender
    74 {
    75 	if (sender == checkBox_confirmBeforeQuitting) {
    76 		[adium.preferenceController setPreference:[NSNumber numberWithBool:[sender state]]
    77 										   forKey:KEY_CONFIRM_QUIT
    78 											group:PREF_GROUP_CONFIRMATIONS];
    79 		
    80 		[self configureControlDimming];
    81 	}
    82 	
    83 	if (sender == checkBox_quitConfirmFT) {
    84 		[adium.preferenceController setPreference:[NSNumber numberWithBool:![sender state]]
    85 										   forKey:KEY_CONFIRM_QUIT_FT
    86 											group:PREF_GROUP_CONFIRMATIONS];
    87 	}
    88 	
    89 	if (sender == checkBox_quitConfirmUnread) {
    90 		[adium.preferenceController setPreference:[NSNumber numberWithBool:![sender state]]
    91 										   forKey:KEY_CONFIRM_QUIT_UNREAD
    92 											group:PREF_GROUP_CONFIRMATIONS];		
    93 	}
    94 	
    95 	if (sender == checkBox_quitConfirmOpenChats) {
    96 		[adium.preferenceController setPreference:[NSNumber numberWithBool:![sender state]]
    97 										   forKey:KEY_CONFIRM_QUIT_OPEN
    98 											group:PREF_GROUP_CONFIRMATIONS];
    99 	}
   100 	
   101 	if (sender == matrix_quitConfirmType) {
   102 		[adium.preferenceController setPreference:[NSNumber numberWithInteger:[[sender selectedCell] tag]]
   103 								   forKey:KEY_CONFIRM_QUIT_TYPE
   104 									group:PREF_GROUP_CONFIRMATIONS];
   105 		
   106 		[self configureControlDimming];
   107 	}
   108 	
   109 	if (sender == checkBox_confirmBeforeClosing) {
   110 		[adium.preferenceController setPreference:[NSNumber numberWithBool:[sender state]]
   111 										   forKey:KEY_CONFIRM_MSG_CLOSE
   112 											group:PREF_GROUP_CONFIRMATIONS];		
   113 		
   114 		[self configureControlDimming];		
   115 	}
   116 	
   117 	if (sender == matrix_closeConfirmType) {
   118 		[adium.preferenceController setPreference:[NSNumber numberWithInteger:[[sender selectedCell] tag]]
   119 								   forKey:KEY_CONFIRM_MSG_CLOSE_TYPE
   120 									group:PREF_GROUP_CONFIRMATIONS];		
   121 	}
   122 	
   123 	[self viewDidLoad];
   124 }
   125 
   126 - (void)configureControlDimming
   127 {
   128 	BOOL		confirmQuitEnabled			= (checkBox_confirmBeforeQuitting.state == NSOnState);
   129 	BOOL		enableSpecificConfirmations = (confirmQuitEnabled && [[matrix_quitConfirmType selectedCell] tag] == AIQuitConfirmSelective);
   130 	
   131 	[matrix_quitConfirmType	setEnabled:confirmQuitEnabled];
   132 	[checkBox_quitConfirmFT	setEnabled:enableSpecificConfirmations];
   133 	[checkBox_quitConfirmUnread	setEnabled:enableSpecificConfirmations];
   134 	[checkBox_quitConfirmOpenChats setEnabled:enableSpecificConfirmations];
   135 	
   136 	BOOL		confirmCloseEnabled			= (checkBox_confirmBeforeClosing.state == NSOnState);
   137 	[matrix_closeConfirmType setEnabled:confirmCloseEnabled];
   138 }
   139 
   140 @end