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