2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import <Adium/AIContactControllerProtocol.h>
18 #import "ESAddressBookIntegrationAdvancedPreferences.h"
19 #import "ESAddressBookIntegrationPlugin.h"
20 #import <AIUtilities/AIDictionaryAdditions.h>
21 #import <AIUtilities/AIMenuAdditions.h>
22 #import <AIUtilities/AIImageAdditions.h>
23 #import <Adium/AILocalizationTextField.h>
25 #define ADDRESS_BOOK_FIRST_OPTION AILocalizedString(@"First","Address Book Name display style, e.g. Evan")
26 #define ADDRESS_BOOK_FIRST_LAST_OPTION AILocalizedString(@"First Last","Address Book Name display style, e.g. Evan Schoenberg")
27 #define ADDRESS_BOOK_LAST_FIRST_OPTION AILocalizedString(@"Last, First","Address Book Name display style, e.g. Schoenberg, Evan")
28 #define ADDRESS_BOOK_LAST_FIRST_NO_COMMA_OPTION AILocalizedString(@"Last First", "Address Book Name display style, e.g. Schoenberg Evan")
29 #define ADDRESS_BOOK_FIRST_MIDDLE_OPTION AILocalizedString(@"First Middle", "Address Book Name display style, e.g. Evan Dreskin")
30 #define ADDRESS_BOOK_FIRST_MIDDLE_LAST_OPTION AILocalizedString(@"First Middle Last", "Address Book Name display style, e.g. Evan Dreskin Schoenberg")
31 #define ADDRESS_BOOK_LAST_FIRST_MIDDLE_OPTION AILocalizedString(@"Last, First Middle", "Address Book Name display style, e.g. Schoenberg, Evan Dreskin")
32 #define ADDRESS_BOOK_LAST_FIRST_MIDDLE_NO_COMMA_OPTION AILocalizedString(@"Last First Middle", "Address Book Name display style, e.g. Schoenberg Evan Dreskin")
34 @interface ESAddressBookIntegrationAdvancedPreferences (PRIVATE)
35 - (void)preferencesChanged:(NSNotification *)notification;
36 - (void)configureFormatMenu;
37 - (IBAction)changeFormat:(id)sender;
41 * @class ESAddressBookIntegrationAdvancedPreferences
42 * @brief Provide advanced preferences for the address book integration
44 @implementation ESAddressBookIntegrationAdvancedPreferences
49 - (AIPreferenceCategory)category{
50 return AIPref_Advanced;
56 return AILocalizedString(@"Address Book",nil);
61 - (NSString *)nibName{
62 return @"AddressBookPrefs";
65 * @brief Image for advanced preferences
68 return [NSImage imageNamed:@"AddressBook" forClass:[self class]];
72 * @brief Configure the preference view
76 [self configureFormatMenu];
78 [label_formatNamesAs setLocalizedString:AILocalizedString(@"Format name as:", "Format name as: [popup menu of choices like 'First, Last']")];
79 [label_names setLocalizedString:AILocalizedString(@"Names",nil)];
80 [label_images setLocalizedString:AILocalizedString(@"Images",nil)];
81 [label_contacts setLocalizedString:AILocalizedString(@"Contacts",nil)];
83 [checkBox_enableImport setLocalizedString:AILocalizedString(@"Import my contacts' names from the Address Book",nil)];
84 [checkBox_useNickName setLocalizedString:AILocalizedString(@"Use nickname if available",nil)];
85 [checkBox_useMiddleName setLocalizedString:AILocalizedString(@"Use middle name if available",nil)];
86 [checkBox_useABImages setLocalizedString:AILocalizedString(@"Use Address Book images as contacts' icons",nil)];
87 [checkBox_preferABImages setLocalizedString:AILocalizedString(@"Even if the contact already has a contact icon",nil)];
88 [checkBox_syncAutomatic setLocalizedString:AILocalizedString(@"Overwrite Address Book images with contacts' icons",nil)];
89 [checkBox_metaContacts setLocalizedString:AILocalizedString(@"Combine contacts listed on a single card",nil)];
91 [checkBox_enableImport setState:[[[adium preferenceController] preferenceForKey:KEY_AB_ENABLE_IMPORT
92 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
93 [popUp_formatMenu selectItemAtIndex:[popUp_formatMenu indexOfItemWithTag:[[[adium preferenceController] preferenceForKey:KEY_AB_DISPLAYFORMAT
94 group:PREF_GROUP_ADDRESSBOOK] intValue]]];
95 [checkBox_useNickName setState:[[[adium preferenceController] preferenceForKey:KEY_AB_USE_NICKNAME
96 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
97 [checkBox_useMiddleName setState:[[[adium preferenceController] preferenceForKey:KEY_AB_USE_MIDDLE
98 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
99 [checkBox_syncAutomatic setState:[[[adium preferenceController] preferenceForKey:KEY_AB_IMAGE_SYNC
100 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
101 [checkBox_useABImages setState:[[[adium preferenceController] preferenceForKey:KEY_AB_USE_IMAGES
102 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
103 [checkBox_enableNoteSync setState:[[[adium preferenceController] preferenceForKey:KEY_AB_NOTE_SYNC
104 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
105 [checkBox_preferABImages setState:[[[adium preferenceController] preferenceForKey:KEY_AB_PREFER_ADDRESS_BOOK_IMAGES
106 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
107 [checkBox_metaContacts setState:[[[adium preferenceController] preferenceForKey:KEY_AB_CREATE_METACONTACTS
108 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
110 [self configureControlDimming];
122 * @brief Configure control dimming
124 - (void)configureControlDimming
126 BOOL enableImport = [[[adium preferenceController] preferenceForKey:KEY_AB_ENABLE_IMPORT
127 group:PREF_GROUP_ADDRESSBOOK] boolValue];
128 BOOL useImages = [[[adium preferenceController] preferenceForKey:KEY_AB_USE_IMAGES
129 group:PREF_GROUP_ADDRESSBOOK] boolValue];
131 //Use Nick Name and the format menu are irrelevent if importing of names is not enabled
132 [checkBox_useNickName setEnabled:enableImport];
133 [popUp_formatMenu setEnabled:enableImport];
134 [checkBox_useMiddleName setEnabled:enableImport];
136 //We will not allow image syncing if AB images are preferred
137 //so disable the control and uncheck the box to indicate this to the user
138 //dchoby98: why are image import and export linked?
139 //[checkBox_syncAutomatic setEnabled:!preferABImages];
140 //if (preferABImages)
141 // [checkBox_syncAutomatic setState:NSOffState];
143 //Disable the image priority checkbox if we aren't using images
144 [checkBox_preferABImages setEnabled:useImages];
148 * @brief Configure the menu of name formats
150 - (void)configureFormatMenu
152 NSMenu *choicesMenu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init] autorelease];
153 NSMenuItem *menuItem;
154 NSString *firstTitle, *firstLastTitle, *lastFirstTitle, *lastFirstNoCommaTitle;
156 BOOL useMiddleName = [[[adium preferenceController] preferenceForKey:KEY_AB_USE_MIDDLE
157 group:PREF_GROUP_ADDRESSBOOK] boolValue];
159 //If the use middle name preference is set, we use the menu titles that include a middle name
161 firstTitle = ADDRESS_BOOK_FIRST_MIDDLE_OPTION;
162 firstLastTitle = ADDRESS_BOOK_FIRST_MIDDLE_LAST_OPTION;
163 lastFirstTitle = ADDRESS_BOOK_LAST_FIRST_MIDDLE_OPTION;
164 lastFirstNoCommaTitle = ADDRESS_BOOK_LAST_FIRST_MIDDLE_NO_COMMA_OPTION;
166 //Otherwise we use the standard menu titles
168 firstTitle = ADDRESS_BOOK_FIRST_OPTION;
169 firstLastTitle = ADDRESS_BOOK_FIRST_LAST_OPTION;
170 lastFirstTitle = ADDRESS_BOOK_LAST_FIRST_OPTION;
171 lastFirstNoCommaTitle = ADDRESS_BOOK_LAST_FIRST_NO_COMMA_OPTION;
175 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:firstTitle
177 action:@selector(changeFormat:)
178 keyEquivalent:@""] autorelease];
179 [menuItem setTag:First];
180 [choicesMenu addItem:menuItem];
182 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:firstLastTitle
184 action:@selector(changeFormat:)
185 keyEquivalent:@""] autorelease];
186 [menuItem setTag:FirstLast];
187 [choicesMenu addItem:menuItem];
189 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:lastFirstTitle
191 action:@selector(changeFormat:)
192 keyEquivalent:@""] autorelease];
193 [menuItem setTag:LastFirst];
194 [choicesMenu addItem:menuItem];
196 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:lastFirstNoCommaTitle
198 action:@selector(changeFormat:)
199 keyEquivalent:@""] autorelease];
200 [menuItem setTag:LastFirstNoComma];
201 [choicesMenu addItem:menuItem];
203 [popUp_formatMenu setMenu:choicesMenu];
205 NSRect oldFrame = [popUp_formatMenu frame];
206 [popUp_formatMenu setFrameOrigin:oldFrame.origin];
207 [[self view] setNeedsDisplay:YES];
211 * @brief Save changed name format preference
213 - (IBAction)changeFormat:(id)sender
215 [[adium preferenceController] setPreference:[NSNumber numberWithInt:[sender tag]]
216 forKey:KEY_AB_DISPLAYFORMAT
217 group:PREF_GROUP_ADDRESSBOOK];
221 * @brief Save changed preference
223 - (IBAction)changePreference:(id)sender
225 if (sender == checkBox_syncAutomatic) {
226 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state]==NSOnState)]
227 forKey:KEY_AB_IMAGE_SYNC
228 group:PREF_GROUP_ADDRESSBOOK];
230 } else if (sender == checkBox_useABImages) {
231 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state]==NSOnState)]
232 forKey:KEY_AB_USE_IMAGES
233 group:PREF_GROUP_ADDRESSBOOK];
235 } else if (sender == checkBox_useNickName) {
236 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state]==NSOnState)]
237 forKey:KEY_AB_USE_NICKNAME
238 group:PREF_GROUP_ADDRESSBOOK];
240 } else if (sender == checkBox_useMiddleName) {
241 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
242 forKey:KEY_AB_USE_MIDDLE
243 group:PREF_GROUP_ADDRESSBOOK];
244 //Update the format menu to reflect the use of middle names
245 [self configureFormatMenu];
247 } else if (sender == checkBox_enableImport) {
248 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
249 forKey:KEY_AB_ENABLE_IMPORT
250 group:PREF_GROUP_ADDRESSBOOK];
252 } else if (sender == checkBox_preferABImages) {
253 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
254 forKey:KEY_AB_PREFER_ADDRESS_BOOK_IMAGES
255 group:PREF_GROUP_ADDRESSBOOK];
257 } else if (sender == checkBox_enableNoteSync) {
258 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
259 forKey:KEY_AB_NOTE_SYNC
260 group:PREF_GROUP_ADDRESSBOOK];
262 } else if (sender == checkBox_metaContacts) {
263 BOOL shouldCreateMetaContacts = ([sender state] == NSOnState);
265 if (shouldCreateMetaContacts) {
266 [[adium preferenceController] setPreference:[NSNumber numberWithBool:YES]
267 forKey:KEY_AB_CREATE_METACONTACTS
268 group:PREF_GROUP_ADDRESSBOOK];
271 NSBeginAlertSheet(nil,
272 AILocalizedString(@"Unconsolidate all metacontacts",nil),
273 AILocalizedString(@"Cancel",nil), nil,
274 [[self view] window], self,
275 @selector(sheetDidEnd:returnCode:contextInfo:), NULL,
277 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));
281 [self configureControlDimming];
284 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
286 if (returnCode == NSAlertDefaultReturn) {
287 //If we now shouldn't create metaContacts, clear 'em all... not pretty, but effective.
289 //Delay to the next run loop to give better UI responsiveness
290 [[adium contactController] performSelector:@selector(clearAllMetaContactData)
295 [[adium preferenceController] setPreference:[NSNumber numberWithBool:NO]
296 forKey:KEY_AB_CREATE_METACONTACTS
297 group:PREF_GROUP_ADDRESSBOOK];
299 //Put the checkbox back
300 [checkBox_metaContacts setState:![checkBox_metaContacts state]];