Automatically disable the Delete button in the Xtras Manager if no item is selected...
[adiumx.git] / Source / ESPersonalPreferences.m
blob5e1faaaf1ae8856925dfbb0f946161e87dd1f26c
1 //
2 //  ESPersonalPreferences.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 12/18/05.
6 //
8 #import "ESPersonalPreferences.h"
9 #import "AIPreferenceController.h"
10 #import "AIContactController.h"
11 #import <Adium/AIAccount.h>
12 #import <AIUtilities/AIAttributedStringAdditions.h>
13 #import <AIUtilities/AIImageViewWithImagePicker.h>
14 #import <AIUtilities/AIAutoScrollView.h>
15 #import <AIUtilities/AIImageViewWithImagePicker.h>
16 #import <AIUtilities/AIDelayedTextField.h>
17 #import <Adium/AIMessageEntryTextView.h>
19 @interface ESPersonalPreferences (PRIVATE)
20 - (void)fireProfileChangesImmediately;
21 - (void)configureProfile;
22 - (void)configureImageView;
23 - (void)configureTooltips;
24 @end
26 @implementation ESPersonalPreferences
28 /*!
29  * @brief Preference pane properties
30  */
31 - (PREFERENCE_CATEGORY)category{
32     return AIPref_Personal;
34 - (NSString *)label{
35     return AILocalizedString(@"Personal","Personal preferences label");
37 - (NSString *)nibName{
38     return @"PersonalPreferences";
41 /*!
42  * @brief Configure the view initially
43  */
44 - (void)viewDidLoad
46         NSString *displayName = [[[[adium preferenceController] preferenceForKey:KEY_ACCOUNT_DISPLAY_NAME
47                                                                                                                                            group:GROUP_ACCOUNT_STATUS] attributedString] string];
48         [textField_displayName setStringValue:(displayName ? displayName : @"")];
49         
50         //Set the default local alias (address book name) as the placeholder for the local alias
51         NSString *defaultAlias = [[[[adium preferenceController] defaultPreferenceForKey:KEY_ACCOUNT_DISPLAY_NAME
52                                                                                                                                                            group:GROUP_ACCOUNT_STATUS
53                                                                                                                                                           object:nil] attributedString] string];
54         [[textField_displayName cell] setPlaceholderString:(defaultAlias ? defaultAlias : @"")];
56         [self configureProfile];
57         [self configureImageView];
58         [self configureTooltips];
59         
60         if ([[[adium preferenceController] preferenceForKey:KEY_USE_USER_ICON
61                                                                                                   group:GROUP_ACCOUNT_STATUS] boolValue]) {
62                 [matrix_userIcon selectCellWithTag:1];
63         } else {
64                 [matrix_userIcon selectCellWithTag:0];          
65         }
67         [self configureControlDimming];
69         [super viewDidLoad];
72 - (void)viewWillClose
74         [self fireProfileChangesImmediately];
76         [[NSFontPanel sharedFontPanel] setDelegate:nil];
78         [super viewWillClose];
81 - (void)changePreference:(id)sender
82 {       
83         if (sender == textField_displayName) {
84                 NSString *displayName = [textField_displayName stringValue];
85                 
86                 [[adium preferenceController] setPreference:((displayName && [displayName length]) ?
87                                                                                                          [[NSAttributedString stringWithString:displayName] dataRepresentation] :
88                                                                                                          nil)
89                                                                                          forKey:KEY_ACCOUNT_DISPLAY_NAME
90                                                                                           group:GROUP_ACCOUNT_STATUS];
92         } else if (sender == textView_profile) {
93                 [[adium preferenceController] setPreference:[[textView_profile textStorage] dataRepresentation] 
94                                                                                          forKey:@"TextProfile"
95                                                                                           group:GROUP_ACCOUNT_STATUS];
97         } else if (sender == matrix_userIcon) {
98                 BOOL enableUserIcon = ([[matrix_userIcon selectedCell] tag] == 1);
100                 [[adium preferenceController] setPreference:[NSNumber numberWithBool:enableUserIcon]
101                                                                                          forKey:KEY_USE_USER_ICON
102                                                                                           group:GROUP_ACCOUNT_STATUS];  
103         }else if (sender == button_enableMusicProfile) {
104                 BOOL enableUserIcon = ([button_enableMusicProfile state] == NSOnState);
105                 
106                 [[adium preferenceController] setPreference:[NSNumber numberWithBool:enableUserIcon]
107                                                                                          forKey:KEY_USE_USER_ICON
108                                                                                           group:GROUP_ACCOUNT_STATUS];  
109         }
110         
111         
112         [super changePreference:nil];
115 - (void)configureControlDimming
117         BOOL enableUserIcon = ([[matrix_userIcon selectedCell] tag] == 1);
119         [button_chooseIcon setEnabled:enableUserIcon];
120         [imageView_userIcon setEnabled:enableUserIcon]; 
123 #pragma mark Profile
124 - (void)configureProfile
126         NSScrollView    *scrollView = [textView_profile enclosingScrollView];
127         if (scrollView && [scrollView isKindOfClass:[AIAutoScrollView class]]) {
128                 [(AIAutoScrollView *)scrollView setAlwaysDrawFocusRingIfFocused:YES];
129         }
130         
131         if ([textView_profile isKindOfClass:[AIMessageEntryTextView class]]) {
132                 /* We use the AIMessageEntryTextView to get nifty features for our text view, but we don't want to attempt
133                 * to 'send' to a target on Enter or Return.
134                 */
135                 [(AIMessageEntryTextView *)textView_profile setSendingEnabled:NO];
136         }
138         [[NSFontPanel sharedFontPanel] setDelegate:textView_profile];
140         NSData                          *profileData = [[adium preferenceController] preferenceForKey:@"TextProfile"
141                                                                                                                                                                 group:GROUP_ACCOUNT_STATUS];
142         NSAttributedString      *profile = (profileData ? [NSAttributedString stringWithData:profileData] : nil);
143         
144         if (profile && [profile length]) {
145                 [[textView_profile textStorage] setAttributedString:profile];
146         } else {
147                 [textView_profile setString:@""];
148         }       
151 - (void)fireProfileChangesImmediately
153         [NSObject cancelPreviousPerformRequestsWithTarget:self
154                                                                                          selector:@selector(changePreference:)
155                                                                                            object:textView_profile];    
156         [self changePreference:textView_profile];
159 - (void)textDidChange:(NSNotification *)aNotification
161         if ([aNotification object] == textView_profile) {               
162                 [NSObject cancelPreviousPerformRequestsWithTarget:self
163                                                                                                  selector:@selector(changePreference:)
164                                                                                                    object:textView_profile];
165                 [self performSelector:@selector(changePreference:)
166                                    withObject:textView_profile
167                                    afterDelay:1.0];
168         }
171 // AIImageViewWithImagePicker Delegate ---------------------------------------------------------------------
172 #pragma mark AIImageViewWithImagePicker Delegate
173 - (void)imageViewWithImagePicker:(AIImageViewWithImagePicker *)sender didChangeToImageData:(NSData *)imageData
175         [[adium preferenceController] setPreference:imageData
176                                                                                  forKey:KEY_USER_ICON
177                                                                                   group:GROUP_ACCOUNT_STATUS];
180 - (void)deleteInImageViewWithImagePicker:(AIImageViewWithImagePicker *)sender
182         [[adium preferenceController] setPreference:nil
183                                                                                  forKey:KEY_USER_ICON
184                                                                                   group:GROUP_ACCOUNT_STATUS];
186         //User icon - restore to the default icon
187         [self configureImageView];
190 - (NSString *)fileNameForImageInImagePicker:(AIImageViewWithImagePicker *)picker
192         return AILocalizedString(@"Adium Icon", nil);
195 - (void)configureImageView
197         NSData *imageData = [[adium preferenceController] preferenceForKey:KEY_USER_ICON
198                                                                                                                                  group:GROUP_ACCOUNT_STATUS];
199         if (!imageData) {
200                 imageData = [[adium preferenceController] preferenceForKey:KEY_DEFAULT_USER_ICON
201                                                                                                                          group:GROUP_ACCOUNT_STATUS];
202         }
204         [imageView_userIcon setImage:(imageData ? [[[NSImage alloc] initWithData:imageData] autorelease] : nil)];
207 - (void)configureTooltips
209         [matrix_userIcon setToolTip:AILocalizedString(@"Do not use an icon to represent you.", nil)
210                                                 forCell:[matrix_userIcon cellWithTag:0]];
211         [matrix_userIcon setToolTip:AILocalizedString(@"Use the icon below to represent you.", nil)
212                                                 forCell:[matrix_userIcon cellWithTag:1]];
214 #define DISPLAY_NAME_TOOLTIP AILocalizedString(@"Your name, which on supported services will be sent to remote contacts. Substitutions from the Edit->Scripts and Edit->iTunes menus may be used here.", nil)
215         [label_remoteAlias  setToolTip:DISPLAY_NAME_TOOLTIP];
216         [textField_displayName setToolTip:DISPLAY_NAME_TOOLTIP];
218 #define PROFILE_TOOLTIP AILocalizedString(@"Profile to display when contacts request information about you (not supported by all services). Text may be formatted using the Edit and Format menus.", nil)
219         [label_profile setToolTip:PROFILE_TOOLTIP];
220         [textView_profile setToolTip:PROFILE_TOOLTIP];
223 @end