ca, fr, fr_CA, and it updates
[adiumx.git] / Source / ESPersonalPreferences.m
blob76da09910e3df76e3df515c46cb4825135d8c0ab
1 //
2 //  ESPersonalPreferences.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 12/18/05.
6 //
8 #import "ESPersonalPreferences.h"
9 #import <Adium/AIAccount.h>
10 #import <Adium/AIContactControllerProtocol.h>
11 #import <Adium/AIMessageEntryTextView.h>
12 #import <Adium/AIPreferenceControllerProtocol.h>
13 #import <AIUtilities/AIAttributedStringAdditions.h>
14 #import <AIUtilities/AIAutoScrollView.h>
15 #import <AIUtilities/AIDelayedTextField.h>
16 #import <AIUtilities/AIImageViewWithImagePicker.h>
17 #import <AIUtilities/AIImageAdditions.h>
18 #import <AIUtilities/AIImageViewWithImagePicker.h>
20 @interface ESPersonalPreferences (PRIVATE)
21 - (void)fireProfileChangesImmediately;
22 - (void)configureProfile;
23 - (void)configureImageView;
24 - (void)configureTooltips;
25 @end
27 @implementation ESPersonalPreferences
29 /*!
30  * @brief Preference pane properties
31  */
32 - (NSString *)paneIdentifier
34         return @"Personal";
36 - (NSString *)paneName{
37     return AILocalizedString(@"Personal","Personal preferences label");
39 - (NSString *)nibName{
40     return @"PersonalPreferences";
42 - (NSImage *)paneIcon
44         return [NSImage imageNamed:@"pref-personal" forClass:[self class]];
47 /*!
48  * @brief Configure the view initially
49  */
50 - (void)viewDidLoad
52         NSString *displayName = [[[[adium preferenceController] preferenceForKey:KEY_ACCOUNT_DISPLAY_NAME
53                                                                                                                                            group:GROUP_ACCOUNT_STATUS] attributedString] string];
54         [textField_displayName setStringValue:(displayName ? displayName : @"")];
55         
56         //Set the default local alias (address book name) as the placeholder for the local alias
57         NSString *defaultAlias = [[[[adium preferenceController] defaultPreferenceForKey:KEY_ACCOUNT_DISPLAY_NAME
58                                                                                                                                                            group:GROUP_ACCOUNT_STATUS
59                                                                                                                                                           object:nil] attributedString] string];
60         [[textField_displayName cell] setPlaceholderString:(defaultAlias ? defaultAlias : @"")];
62         [self configureProfile];
63         [self configureTooltips];
64         
65         if ([[[adium preferenceController] preferenceForKey:KEY_USE_USER_ICON
66                                                                                                   group:GROUP_ACCOUNT_STATUS] boolValue]) {
67                 [matrix_userIcon selectCellWithTag:1];
68         } else {
69                 [matrix_userIcon selectCellWithTag:0];          
70         }
72         [self configureControlDimming];
74         [[adium preferenceController] registerPreferenceObserver:self forGroup:GROUP_ACCOUNT_STATUS];
76         [imageView_userIcon setMaxSize:NSMakeSize(256, 256)];
78         [super viewDidLoad];
81 - (void)viewWillClose
83         [[adium preferenceController] unregisterPreferenceObserver:self];
84         [self fireProfileChangesImmediately];
86         [[NSFontPanel sharedFontPanel] setDelegate:nil];
88         [super viewWillClose];
91 - (void)changePreference:(id)sender
92 {       
93         if (sender == textField_displayName) {
94                 NSString *displayName = [textField_displayName stringValue];
95                 
96                 [[adium preferenceController] setPreference:((displayName && [displayName length]) ?
97                                                                                                          [[NSAttributedString stringWithString:displayName] dataRepresentation] :
98                                                                                                          nil)
99                                                                                          forKey:KEY_ACCOUNT_DISPLAY_NAME
100                                                                                           group:GROUP_ACCOUNT_STATUS];
102         } else if (sender == textView_profile) {
103                 [[adium preferenceController] setPreference:[[textView_profile textStorage] dataRepresentation] 
104                                                                                          forKey:@"TextProfile"
105                                                                                           group:GROUP_ACCOUNT_STATUS];
107         } else if (sender == matrix_userIcon) {
108                 BOOL enableUserIcon = ([[matrix_userIcon selectedCell] tag] == 1);
110                 [[adium preferenceController] setPreference:[NSNumber numberWithBool:enableUserIcon]
111                                                                                          forKey:KEY_USE_USER_ICON
112                                                                                           group:GROUP_ACCOUNT_STATUS];  
113         }else if (sender == button_enableMusicProfile) {
114                 BOOL enableUserIcon = ([button_enableMusicProfile state] == NSOnState);
115                 
116                 [[adium preferenceController] setPreference:[NSNumber numberWithBool:enableUserIcon]
117                                                                                          forKey:KEY_USE_USER_ICON
118                                                                                           group:GROUP_ACCOUNT_STATUS];  
119         }
120         
121         
122         [super changePreference:nil];
125 - (void)configureControlDimming
127         BOOL enableUserIcon = ([[matrix_userIcon selectedCell] tag] == 1);
129         [button_chooseIcon setEnabled:enableUserIcon];
130         [imageView_userIcon setEnabled:enableUserIcon]; 
133 - (void)preferencesChangedForGroup:(NSString *)group key:(NSString *)key
134                                                         object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime
136         if (object) return;
138         if ([key isEqualToString:KEY_ACCOUNT_DISPLAY_NAME]) {
139                 NSString *displayName = [textField_displayName stringValue];
140                 NSString *newDisplayName = [[[prefDict objectForKey:KEY_ACCOUNT_DISPLAY_NAME] attributedString] string];
141                 if (![displayName isEqualToString:newDisplayName]) {
142                         [textField_displayName setStringValue:newDisplayName];
143                 }
144         }
146         if (firstTime || [key isEqualToString:KEY_USER_ICON] || [key isEqualToString:KEY_DEFAULT_USER_ICON]) {
147                 [self configureImageView];
148         }
151 #pragma mark Profile
152 - (void)configureProfile
154         NSScrollView    *scrollView = [textView_profile enclosingScrollView];
155         if (scrollView && [scrollView isKindOfClass:[AIAutoScrollView class]]) {
156                 [(AIAutoScrollView *)scrollView setAlwaysDrawFocusRingIfFocused:YES];
157         }
158         
159         if ([textView_profile isKindOfClass:[AIMessageEntryTextView class]]) {
160                 /* We use the AIMessageEntryTextView to get nifty features for our text view, but we don't want to attempt
161                 * to 'send' to a target on Enter or Return.
162                 */
163                 [(AIMessageEntryTextView *)textView_profile setSendingEnabled:NO];
164         }
166         [[NSFontPanel sharedFontPanel] setDelegate:textView_profile];
168         NSData                          *profileData = [[adium preferenceController] preferenceForKey:@"TextProfile"
169                                                                                                                                                                 group:GROUP_ACCOUNT_STATUS];
170         NSAttributedString      *profile = (profileData ? [NSAttributedString stringWithData:profileData] : nil);
171         
172         if (profile && [profile length]) {
173                 [[textView_profile textStorage] setAttributedString:profile];
174         } else {
175                 [textView_profile setString:@""];
176         }       
179 - (void)fireProfileChangesImmediately
181         [NSObject cancelPreviousPerformRequestsWithTarget:self
182                                                                                          selector:@selector(changePreference:)
183                                                                                            object:textView_profile];    
184         [self changePreference:textView_profile];
187 - (void)textDidChange:(NSNotification *)aNotification
189         if ([aNotification object] == textView_profile) {               
190                 [NSObject cancelPreviousPerformRequestsWithTarget:self
191                                                                                                  selector:@selector(changePreference:)
192                                                                                                    object:textView_profile];
193                 [self performSelector:@selector(changePreference:)
194                                    withObject:textView_profile
195                                    afterDelay:1.0];
196         }
199 // AIImageViewWithImagePicker Delegate ---------------------------------------------------------------------
200 #pragma mark AIImageViewWithImagePicker Delegate
201 - (void)imageViewWithImagePicker:(AIImageViewWithImagePicker *)sender didChangeToImageData:(NSData *)imageData
203         [[adium preferenceController] setPreference:imageData
204                                                                                  forKey:KEY_USER_ICON
205                                                                                   group:GROUP_ACCOUNT_STATUS];
208 - (void)deleteInImageViewWithImagePicker:(AIImageViewWithImagePicker *)sender
210         [[adium preferenceController] setPreference:nil
211                                                                                  forKey:KEY_USER_ICON
212                                                                                   group:GROUP_ACCOUNT_STATUS];
214         //User icon - restore to the default icon
215         [self configureImageView];
218 - (NSString *)fileNameForImageInImagePicker:(AIImageViewWithImagePicker *)picker
220         return AILocalizedString(@"Adium Icon", nil);
223 - (void)configureImageView
225         NSData *imageData = [[adium preferenceController] preferenceForKey:KEY_USER_ICON
226                                                                                                                                  group:GROUP_ACCOUNT_STATUS];
227         if (!imageData) {
228                 imageData = [[adium preferenceController] preferenceForKey:KEY_DEFAULT_USER_ICON
229                                                                                                                          group:GROUP_ACCOUNT_STATUS];
230         }
232         [imageView_userIcon setImage:(imageData ? [[[NSImage alloc] initWithData:imageData] autorelease] : nil)];
235 - (void)configureTooltips
237         [matrix_userIcon setToolTip:AILocalizedString(@"Do not use an icon to represent you.", nil)
238                                                 forCell:[matrix_userIcon cellWithTag:0]];
239         [matrix_userIcon setToolTip:AILocalizedString(@"Use the icon below to represent you.", nil)
240                                                 forCell:[matrix_userIcon cellWithTag:1]];
242 #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)
243         [label_remoteAlias  setToolTip:DISPLAY_NAME_TOOLTIP];
244         [textField_displayName setToolTip:DISPLAY_NAME_TOOLTIP];
246 #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)
247         [label_profile setToolTip:PROFILE_TOOLTIP];
248         [textView_profile setToolTip:PROFILE_TOOLTIP];
251 @end