2 // ESPersonalPreferences.m
5 // Created by Evan Schoenberg on 12/18/05.
8 #import "ESPersonalPreferences.h"
9 #import <Adium/AIPreferenceControllerProtocol.h>
10 #import <Adium/AIContactControllerProtocol.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;
26 @implementation ESPersonalPreferences
29 * @brief Preference pane properties
31 - (AIPreferenceCategory)category{
32 return AIPref_Personal;
35 return AILocalizedString(@"Personal","Personal preferences label");
37 - (NSString *)nibName{
38 return @"PersonalPreferences";
42 * @brief Configure the view initially
46 NSString *displayName = [[[[adium preferenceController] preferenceForKey:KEY_ACCOUNT_DISPLAY_NAME
47 group:GROUP_ACCOUNT_STATUS] attributedString] string];
48 [textField_displayName setStringValue:(displayName ? displayName : @"")];
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];
60 if ([[[adium preferenceController] preferenceForKey:KEY_USE_USER_ICON
61 group:GROUP_ACCOUNT_STATUS] boolValue]) {
62 [matrix_userIcon selectCellWithTag:1];
64 [matrix_userIcon selectCellWithTag:0];
67 [self configureControlDimming];
69 [[adium preferenceController] registerPreferenceObserver:self forGroup:GROUP_ACCOUNT_STATUS];
76 [[adium preferenceController] unregisterPreferenceObserver:self];
77 [self fireProfileChangesImmediately];
79 [[NSFontPanel sharedFontPanel] setDelegate:nil];
81 [super viewWillClose];
84 - (void)changePreference:(id)sender
86 if (sender == textField_displayName) {
87 NSString *displayName = [textField_displayName stringValue];
89 [[adium preferenceController] setPreference:((displayName && [displayName length]) ?
90 [[NSAttributedString stringWithString:displayName] dataRepresentation] :
92 forKey:KEY_ACCOUNT_DISPLAY_NAME
93 group:GROUP_ACCOUNT_STATUS];
95 } else if (sender == textView_profile) {
96 [[adium preferenceController] setPreference:[[textView_profile textStorage] dataRepresentation]
98 group:GROUP_ACCOUNT_STATUS];
100 } else if (sender == matrix_userIcon) {
101 BOOL enableUserIcon = ([[matrix_userIcon selectedCell] tag] == 1);
103 [[adium preferenceController] setPreference:[NSNumber numberWithBool:enableUserIcon]
104 forKey:KEY_USE_USER_ICON
105 group:GROUP_ACCOUNT_STATUS];
106 }else if (sender == button_enableMusicProfile) {
107 BOOL enableUserIcon = ([button_enableMusicProfile state] == NSOnState);
109 [[adium preferenceController] setPreference:[NSNumber numberWithBool:enableUserIcon]
110 forKey:KEY_USE_USER_ICON
111 group:GROUP_ACCOUNT_STATUS];
115 [super changePreference:nil];
118 - (void)configureControlDimming
120 BOOL enableUserIcon = ([[matrix_userIcon selectedCell] tag] == 1);
122 [button_chooseIcon setEnabled:enableUserIcon];
123 [imageView_userIcon setEnabled:enableUserIcon];
126 - (void)preferencesChangedForGroup:(NSString *)group key:(NSString *)key
127 object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime
131 if ([key isEqualToString:KEY_ACCOUNT_DISPLAY_NAME]) {
132 NSString *displayName = [textField_displayName stringValue];
133 NSString *newDisplayName = [[[prefDict objectForKey:KEY_ACCOUNT_DISPLAY_NAME] attributedString] string];
134 if (![displayName isEqualToString:newDisplayName]) {
135 [textField_displayName setStringValue:newDisplayName];
141 - (void)configureProfile
143 NSScrollView *scrollView = [textView_profile enclosingScrollView];
144 if (scrollView && [scrollView isKindOfClass:[AIAutoScrollView class]]) {
145 [(AIAutoScrollView *)scrollView setAlwaysDrawFocusRingIfFocused:YES];
148 if ([textView_profile isKindOfClass:[AIMessageEntryTextView class]]) {
149 /* We use the AIMessageEntryTextView to get nifty features for our text view, but we don't want to attempt
150 * to 'send' to a target on Enter or Return.
152 [(AIMessageEntryTextView *)textView_profile setSendingEnabled:NO];
155 [[NSFontPanel sharedFontPanel] setDelegate:textView_profile];
157 NSData *profileData = [[adium preferenceController] preferenceForKey:@"TextProfile"
158 group:GROUP_ACCOUNT_STATUS];
159 NSAttributedString *profile = (profileData ? [NSAttributedString stringWithData:profileData] : nil);
161 if (profile && [profile length]) {
162 [[textView_profile textStorage] setAttributedString:profile];
164 [textView_profile setString:@""];
168 - (void)fireProfileChangesImmediately
170 [NSObject cancelPreviousPerformRequestsWithTarget:self
171 selector:@selector(changePreference:)
172 object:textView_profile];
173 [self changePreference:textView_profile];
176 - (void)textDidChange:(NSNotification *)aNotification
178 if ([aNotification object] == textView_profile) {
179 [NSObject cancelPreviousPerformRequestsWithTarget:self
180 selector:@selector(changePreference:)
181 object:textView_profile];
182 [self performSelector:@selector(changePreference:)
183 withObject:textView_profile
188 // AIImageViewWithImagePicker Delegate ---------------------------------------------------------------------
189 #pragma mark AIImageViewWithImagePicker Delegate
190 - (void)imageViewWithImagePicker:(AIImageViewWithImagePicker *)sender didChangeToImageData:(NSData *)imageData
192 [[adium preferenceController] setPreference:imageData
194 group:GROUP_ACCOUNT_STATUS];
197 - (void)deleteInImageViewWithImagePicker:(AIImageViewWithImagePicker *)sender
199 [[adium preferenceController] setPreference:nil
201 group:GROUP_ACCOUNT_STATUS];
203 //User icon - restore to the default icon
204 [self configureImageView];
207 - (NSString *)fileNameForImageInImagePicker:(AIImageViewWithImagePicker *)picker
209 return AILocalizedString(@"Adium Icon", nil);
212 - (void)configureImageView
214 NSData *imageData = [[adium preferenceController] preferenceForKey:KEY_USER_ICON
215 group:GROUP_ACCOUNT_STATUS];
217 imageData = [[adium preferenceController] preferenceForKey:KEY_DEFAULT_USER_ICON
218 group:GROUP_ACCOUNT_STATUS];
221 [imageView_userIcon setImage:(imageData ? [[[NSImage alloc] initWithData:imageData] autorelease] : nil)];
224 - (void)configureTooltips
226 [matrix_userIcon setToolTip:AILocalizedString(@"Do not use an icon to represent you.", nil)
227 forCell:[matrix_userIcon cellWithTag:0]];
228 [matrix_userIcon setToolTip:AILocalizedString(@"Use the icon below to represent you.", nil)
229 forCell:[matrix_userIcon cellWithTag:1]];
231 #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)
232 [label_remoteAlias setToolTip:DISPLAY_NAME_TOOLTIP];
233 [textField_displayName setToolTip:DISPLAY_NAME_TOOLTIP];
235 #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)
236 [label_profile setToolTip:PROFILE_TOOLTIP];
237 [textView_profile setToolTip:PROFILE_TOOLTIP];