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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | /*
* Adium is the legal property of its developers, whose names are listed in the copyright file included
* with this source distribution.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "ESAddressBookIntegrationAdvancedPreferences.h"
#import <Adium/AIAddressBookController.h>
#import <Adium/AIContactControllerProtocol.h>
#import <Adium/AILocalizationTextField.h>
#import <AIUtilities/AIDictionaryAdditions.h>
#import <AIUtilities/AIImageAdditions.h>
#import <AIUtilities/AIMenuAdditions.h>
#define ADDRESS_BOOK_FIRST_OPTION AILocalizedString(@"First","Address Book Name display style, e.g. Evan")
#define ADDRESS_BOOK_FIRST_LAST_OPTION AILocalizedString(@"First Last","Address Book Name display style, e.g. Evan Schoenberg")
#define ADDRESS_BOOK_LAST_FIRST_OPTION AILocalizedString(@"Last, First","Address Book Name display style, e.g. Schoenberg, Evan")
#define ADDRESS_BOOK_LAST_FIRST_NO_COMMA_OPTION AILocalizedString(@"Last First", "Address Book Name display style, e.g. Schoenberg Evan")
#define ADDRESS_BOOK_FIRST_MIDDLE_OPTION AILocalizedString(@"First Middle", "Address Book Name display style, e.g. Evan Dreskin")
#define ADDRESS_BOOK_FIRST_MIDDLE_LAST_OPTION AILocalizedString(@"First Middle Last", "Address Book Name display style, e.g. Evan Dreskin Schoenberg")
#define ADDRESS_BOOK_LAST_FIRST_MIDDLE_OPTION AILocalizedString(@"Last, First Middle", "Address Book Name display style, e.g. Schoenberg, Evan Dreskin")
#define ADDRESS_BOOK_LAST_FIRST_MIDDLE_NO_COMMA_OPTION AILocalizedString(@"Last First Middle", "Address Book Name display style, e.g. Schoenberg Evan Dreskin")
#define ADDRESS_BOOK_FIRST_LAST_INITIAL AILocalizedString(@"First Last-Initial", "Address Book Name display style, e.g. Evan S")
#define ADDRESS_BOOK_FIRST_MIDDLE_LAST_INITIAL AILocalizedString(@"First Middle Last-Initial", "Address Book Name display style, e.g. Evan Dreskin S")
@interface ESAddressBookIntegrationAdvancedPreferences ()
- (void)configureFormatMenu;
- (IBAction)changeFormat:(id)sender;
@end
/*!
* @class ESAddressBookIntegrationAdvancedPreferences
* @brief Provide advanced preferences for the address book integration
*/
@implementation ESAddressBookIntegrationAdvancedPreferences
/*!
* @brief Label
*/
- (NSString *)label{
return AILocalizedString(@"Address Book",nil);
}
/*!
* @brief Nib name
*/
- (NSString *)nibName{
return @"AddressBookPrefs";
}
/*!
* @brief Image for advanced preferences
*/
- (NSImage *)image{
return [NSImage imageNamed:@"AddressBook" forClass:[self class]];
}
/*!
* @brief Configure the preference view
*/
- (void)viewDidLoad
{
[self configureFormatMenu];
[label_formatNamesAs setLocalizedString:AILocalizedString(@"Format name as:", "Format name as: [popup menu of choices like 'First, Last']")];
[label_names setLocalizedString:AILocalizedString(@"Names",nil)];
[label_images setLocalizedString:AILocalizedString(@"Images",nil)];
[label_contacts setLocalizedString:AILocalizedString(@"Contacts",nil)];
[checkBox_enableImport setLocalizedString:AILocalizedString(@"Import my contacts' names from the Address Book",nil)];
[checkBox_useNickName setLocalizedString:AILocalizedString(@"Use nickname if available",nil)];
[checkBox_useMiddleName setLocalizedString:AILocalizedString(@"Use middle name if available",nil)];
[checkBox_useABImages setLocalizedString:AILocalizedString(@"Use Address Book images as contacts' icons",nil)];
[checkBox_preferABImages setLocalizedString:AILocalizedString(@"Even if the contact already has a contact icon",nil)];
[checkBox_syncAutomatic setLocalizedString:AILocalizedString(@"Overwrite Address Book images with contacts' icons",nil)];
[checkBox_metaContacts setLocalizedString:AILocalizedString(@"Combine contacts listed on a single card",nil)];
[checkBox_enableImport setState:[[adium.preferenceController preferenceForKey:KEY_AB_ENABLE_IMPORT
group:PREF_GROUP_ADDRESSBOOK] boolValue]];
[popUp_formatMenu selectItemAtIndex:[popUp_formatMenu indexOfItemWithTag:[[adium.preferenceController preferenceForKey:KEY_AB_DISPLAYFORMAT
group:PREF_GROUP_ADDRESSBOOK] integerValue]]];
[checkBox_useNickName setState:[[adium.preferenceController preferenceForKey:KEY_AB_USE_NICKNAME
group:PREF_GROUP_ADDRESSBOOK] boolValue]];
[checkBox_useMiddleName setState:[[adium.preferenceController preferenceForKey:KEY_AB_USE_MIDDLE
group:PREF_GROUP_ADDRESSBOOK] boolValue]];
[checkBox_syncAutomatic setState:[[adium.preferenceController preferenceForKey:KEY_AB_IMAGE_SYNC
group:PREF_GROUP_ADDRESSBOOK] boolValue]];
[checkBox_useABImages setState:[[adium.preferenceController preferenceForKey:KEY_AB_USE_IMAGES
group:PREF_GROUP_ADDRESSBOOK] boolValue]];
[checkBox_enableNoteSync setState:[[adium.preferenceController preferenceForKey:KEY_AB_NOTE_SYNC
group:PREF_GROUP_ADDRESSBOOK] boolValue]];
[checkBox_preferABImages setState:[[adium.preferenceController preferenceForKey:KEY_AB_PREFER_ADDRESS_BOOK_IMAGES
group:PREF_GROUP_ADDRESSBOOK] boolValue]];
[checkBox_metaContacts setState:[[adium.preferenceController preferenceForKey:KEY_AB_CREATE_METACONTACTS
group:PREF_GROUP_ADDRESSBOOK] boolValue]];
[self configureControlDimming];
}
/*!
* @brief Deallocate
*/
- (void)dealloc
{
[super dealloc];
}
/*!
* @brief Configure control dimming
*/
- (void)configureControlDimming
{
BOOL enableImport = [[adium.preferenceController preferenceForKey:KEY_AB_ENABLE_IMPORT
group:PREF_GROUP_ADDRESSBOOK] boolValue];
BOOL useImages = [[adium.preferenceController preferenceForKey:KEY_AB_USE_IMAGES
group:PREF_GROUP_ADDRESSBOOK] boolValue];
//Use Nick Name and the format menu are irrelevent if importing of names is not enabled
[checkBox_useNickName setEnabled:enableImport];
[popUp_formatMenu setEnabled:enableImport];
[checkBox_useMiddleName setEnabled:enableImport];
//We will not allow image syncing if AB images are preferred
//so disable the control and uncheck the box to indicate this to the user
//dchoby98: why are image import and export linked?
//[checkBox_syncAutomatic setEnabled:!preferABImages];
//if (preferABImages)
// [checkBox_syncAutomatic setState:NSOffState];
//Disable the image priority checkbox if we aren't using images
[checkBox_preferABImages setEnabled:useImages];
}
/*!
* @brief Configure the menu of name formats
*/
- (void)configureFormatMenu
{
NSMenu *choicesMenu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init] autorelease];
NSMenuItem *menuItem;
NSString *firstTitle, *firstLastTitle, *lastFirstTitle, *lastFirstNoCommaTitle, *firstLastInitial;
BOOL useMiddleName = [[adium.preferenceController preferenceForKey:KEY_AB_USE_MIDDLE
group:PREF_GROUP_ADDRESSBOOK] boolValue];
//If the use middle name preference is set, we use the menu titles that include a middle name
if (useMiddleName) {
firstTitle = ADDRESS_BOOK_FIRST_MIDDLE_OPTION;
firstLastTitle = ADDRESS_BOOK_FIRST_MIDDLE_LAST_OPTION;
lastFirstTitle = ADDRESS_BOOK_LAST_FIRST_MIDDLE_OPTION;
lastFirstNoCommaTitle = ADDRESS_BOOK_LAST_FIRST_MIDDLE_NO_COMMA_OPTION;
firstLastInitial = ADDRESS_BOOK_FIRST_MIDDLE_LAST_INITIAL;
//Otherwise we use the standard menu titles
} else {
firstTitle = ADDRESS_BOOK_FIRST_OPTION;
firstLastTitle = ADDRESS_BOOK_FIRST_LAST_OPTION;
lastFirstTitle = ADDRESS_BOOK_LAST_FIRST_OPTION;
lastFirstNoCommaTitle = ADDRESS_BOOK_LAST_FIRST_NO_COMMA_OPTION;
firstLastInitial = ADDRESS_BOOK_FIRST_LAST_INITIAL;
}
menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:firstTitle
target:self
action:@selector(changeFormat:)
keyEquivalent:@""] autorelease];
[menuItem setTag:First];
[choicesMenu addItem:menuItem];
menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:firstLastTitle
target:self
action:@selector(changeFormat:)
keyEquivalent:@""] autorelease];
[menuItem setTag:FirstLast];
[choicesMenu addItem:menuItem];
menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:lastFirstTitle
target:self
action:@selector(changeFormat:)
keyEquivalent:@""] autorelease];
[menuItem setTag:LastFirst];
[choicesMenu addItem:menuItem];
menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:lastFirstNoCommaTitle
target:self
action:@selector(changeFormat:)
keyEquivalent:@""] autorelease];
[menuItem setTag:LastFirstNoComma];
[choicesMenu addItem:menuItem];
menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:firstLastInitial
target:self
action:@selector(changeFormat:)
keyEquivalent:@""] autorelease];
[menuItem setTag:FirstLastInitial];
[choicesMenu addItem:menuItem];
[popUp_formatMenu setMenu:choicesMenu];
NSRect oldFrame = [popUp_formatMenu frame];
[popUp_formatMenu setFrameOrigin:oldFrame.origin];
[[self view] setNeedsDisplay:YES];
}
/*!
* @brief Save changed name format preference
*/
- (IBAction)changeFormat:(id)sender
{
[adium.preferenceController setPreference:[NSNumber numberWithInteger:[sender tag]]
forKey:KEY_AB_DISPLAYFORMAT
group:PREF_GROUP_ADDRESSBOOK];
}
/*!
* @brief Save changed preference
*/
- (IBAction)changePreference:(id)sender
{
if (sender == checkBox_syncAutomatic) {
[adium.preferenceController setPreference:[NSNumber numberWithBool:([sender state]==NSOnState)]
forKey:KEY_AB_IMAGE_SYNC
group:PREF_GROUP_ADDRESSBOOK];
} else if (sender == checkBox_useABImages) {
[adium.preferenceController setPreference:[NSNumber numberWithBool:([sender state]==NSOnState)]
forKey:KEY_AB_USE_IMAGES
group:PREF_GROUP_ADDRESSBOOK];
} else if (sender == checkBox_useNickName) {
[adium.preferenceController setPreference:[NSNumber numberWithBool:([sender state]==NSOnState)]
forKey:KEY_AB_USE_NICKNAME
group:PREF_GROUP_ADDRESSBOOK];
} else if (sender == checkBox_useMiddleName) {
[adium.preferenceController setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
forKey:KEY_AB_USE_MIDDLE
group:PREF_GROUP_ADDRESSBOOK];
//Update the format menu to reflect the use of middle names
[self configureFormatMenu];
} else if (sender == checkBox_enableImport) {
[adium.preferenceController setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
forKey:KEY_AB_ENABLE_IMPORT
group:PREF_GROUP_ADDRESSBOOK];
} else if (sender == checkBox_preferABImages) {
[adium.preferenceController setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
forKey:KEY_AB_PREFER_ADDRESS_BOOK_IMAGES
group:PREF_GROUP_ADDRESSBOOK];
} else if (sender == checkBox_enableNoteSync) {
[adium.preferenceController setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
forKey:KEY_AB_NOTE_SYNC
group:PREF_GROUP_ADDRESSBOOK];
} else if (sender == checkBox_metaContacts) {
BOOL shouldCreateMetaContacts = ([sender state] == NSOnState);
if (shouldCreateMetaContacts) {
[adium.preferenceController setPreference:[NSNumber numberWithBool:YES]
forKey:KEY_AB_CREATE_METACONTACTS
group:PREF_GROUP_ADDRESSBOOK];
} else {
NSBeginAlertSheet(nil,
AILocalizedString(@"Unconsolidate all metacontacts",nil),
AILocalizedString(@"Cancel",nil), nil,
[[self view] window], self,
@selector(sheetDidEnd:returnCode:contextInfo:), NULL,
NULL,
AILocalizedString(@"Disabling automatic contact consolidation will also unconsolidate all existing metacontacts, including any created manually. You will need to recreate any manually-created metacontacts if you proceed.",nil));
}
}
[self configureControlDimming];
}
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
if (returnCode == NSAlertDefaultReturn) {
//If we now shouldn't create metaContacts, clear 'em all... not pretty, but effective.
//Delay to the next run loop to give better UI responsiveness
[adium.contactController performSelector:@selector(clearAllMetaContactData)
withObject:nil
afterDelay:0];
[adium.preferenceController setPreference:[NSNumber numberWithBool:NO]
forKey:KEY_AB_CREATE_METACONTACTS
group:PREF_GROUP_ADDRESSBOOK];
} else {
//Put the checkbox back
[checkBox_metaContacts setState:![checkBox_metaContacts state]];
}
}
@end
|