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 "ESAddressBookIntegrationAdvancedPreferences.h"
18 #import "ESAddressBookIntegrationPlugin.h"
19 #import <Adium/AIContactControllerProtocol.h>
20 #import <Adium/AIPreferenceControllerProtocol.h>
21 #import <Adium/AILocalizationTextField.h>
22 #import <AIUtilities/AIDictionaryAdditions.h>
23 #import <AIUtilities/AIImageAdditions.h>
24 #import <AIUtilities/AIMenuAdditions.h>
26 #define ADDRESS_BOOK_FIRST_OPTION AILocalizedString(@"First","Address Book Name display style, e.g. Evan")
27 #define ADDRESS_BOOK_FIRST_LAST_OPTION AILocalizedString(@"First Last","Address Book Name display style, e.g. Evan Schoenberg")
28 #define ADDRESS_BOOK_LAST_FIRST_OPTION AILocalizedString(@"Last, First","Address Book Name display style, e.g. Schoenberg, Evan")
29 #define ADDRESS_BOOK_LAST_FIRST_NO_COMMA_OPTION AILocalizedString(@"Last First", "Address Book Name display style, e.g. Schoenberg Evan")
30 #define ADDRESS_BOOK_FIRST_MIDDLE_OPTION AILocalizedString(@"First Middle", "Address Book Name display style, e.g. Evan Dreskin")
31 #define ADDRESS_BOOK_FIRST_MIDDLE_LAST_OPTION AILocalizedString(@"First Middle Last", "Address Book Name display style, e.g. Evan Dreskin Schoenberg")
32 #define ADDRESS_BOOK_LAST_FIRST_MIDDLE_OPTION AILocalizedString(@"Last, First Middle", "Address Book Name display style, e.g. Schoenberg, Evan Dreskin")
33 #define ADDRESS_BOOK_LAST_FIRST_MIDDLE_NO_COMMA_OPTION AILocalizedString(@"Last First Middle", "Address Book Name display style, e.g. Schoenberg Evan Dreskin")
35 @interface ESAddressBookIntegrationAdvancedPreferences (PRIVATE)
36 - (void)preferencesChanged:(NSNotification *)notification;
37 - (void)configureFormatMenu;
38 - (IBAction)changeFormat:(id)sender;
42 * @class ESAddressBookIntegrationAdvancedPreferences
43 * @brief Provide advanced preferences for the address book integration
45 @implementation ESAddressBookIntegrationAdvancedPreferences
51 return AILocalizedString(@"Address Book",nil);
56 - (NSString *)nibName{
57 return @"AddressBookPrefs";
60 * @brief Image for advanced preferences
63 return [NSImage imageNamed:@"AddressBook" forClass:[self class]];
67 * @brief Configure the preference view
71 [self configureFormatMenu];
73 [label_formatNamesAs setLocalizedString:AILocalizedString(@"Format name as:", "Format name as: [popup menu of choices like 'First, Last']")];
74 [label_names setLocalizedString:AILocalizedString(@"Names",nil)];
75 [label_images setLocalizedString:AILocalizedString(@"Images",nil)];
76 [label_contacts setLocalizedString:AILocalizedString(@"Contacts",nil)];
78 [checkBox_enableImport setLocalizedString:AILocalizedString(@"Import my contacts' names from the Address Book",nil)];
79 [checkBox_useNickName setLocalizedString:AILocalizedString(@"Use nickname if available",nil)];
80 [checkBox_useMiddleName setLocalizedString:AILocalizedString(@"Use middle name if available",nil)];
81 [checkBox_useABImages setLocalizedString:AILocalizedString(@"Use Address Book images as contacts' icons",nil)];
82 [checkBox_preferABImages setLocalizedString:AILocalizedString(@"Even if the contact already has a contact icon",nil)];
83 [checkBox_syncAutomatic setLocalizedString:AILocalizedString(@"Overwrite Address Book images with contacts' icons",nil)];
84 [checkBox_metaContacts setLocalizedString:AILocalizedString(@"Combine contacts listed on a single card",nil)];
86 [checkBox_enableImport setState:[[[adium preferenceController] preferenceForKey:KEY_AB_ENABLE_IMPORT
87 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
88 [popUp_formatMenu selectItemAtIndex:[popUp_formatMenu indexOfItemWithTag:[[[adium preferenceController] preferenceForKey:KEY_AB_DISPLAYFORMAT
89 group:PREF_GROUP_ADDRESSBOOK] intValue]]];
90 [checkBox_useNickName setState:[[[adium preferenceController] preferenceForKey:KEY_AB_USE_NICKNAME
91 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
92 [checkBox_useMiddleName setState:[[[adium preferenceController] preferenceForKey:KEY_AB_USE_MIDDLE
93 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
94 [checkBox_syncAutomatic setState:[[[adium preferenceController] preferenceForKey:KEY_AB_IMAGE_SYNC
95 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
96 [checkBox_useABImages setState:[[[adium preferenceController] preferenceForKey:KEY_AB_USE_IMAGES
97 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
98 [checkBox_enableNoteSync setState:[[[adium preferenceController] preferenceForKey:KEY_AB_NOTE_SYNC
99 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
100 [checkBox_preferABImages setState:[[[adium preferenceController] preferenceForKey:KEY_AB_PREFER_ADDRESS_BOOK_IMAGES
101 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
102 [checkBox_metaContacts setState:[[[adium preferenceController] preferenceForKey:KEY_AB_CREATE_METACONTACTS
103 group:PREF_GROUP_ADDRESSBOOK] boolValue]];
105 [self configureControlDimming];
117 * @brief Configure control dimming
119 - (void)configureControlDimming
121 BOOL enableImport = [[[adium preferenceController] preferenceForKey:KEY_AB_ENABLE_IMPORT
122 group:PREF_GROUP_ADDRESSBOOK] boolValue];
123 BOOL useImages = [[[adium preferenceController] preferenceForKey:KEY_AB_USE_IMAGES
124 group:PREF_GROUP_ADDRESSBOOK] boolValue];
126 //Use Nick Name and the format menu are irrelevent if importing of names is not enabled
127 [checkBox_useNickName setEnabled:enableImport];
128 [popUp_formatMenu setEnabled:enableImport];
129 [checkBox_useMiddleName setEnabled:enableImport];
131 //We will not allow image syncing if AB images are preferred
132 //so disable the control and uncheck the box to indicate this to the user
133 //dchoby98: why are image import and export linked?
134 //[checkBox_syncAutomatic setEnabled:!preferABImages];
135 //if (preferABImages)
136 // [checkBox_syncAutomatic setState:NSOffState];
138 //Disable the image priority checkbox if we aren't using images
139 [checkBox_preferABImages setEnabled:useImages];
143 * @brief Configure the menu of name formats
145 - (void)configureFormatMenu
147 NSMenu *choicesMenu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init] autorelease];
148 NSMenuItem *menuItem;
149 NSString *firstTitle, *firstLastTitle, *lastFirstTitle, *lastFirstNoCommaTitle;
151 BOOL useMiddleName = [[[adium preferenceController] preferenceForKey:KEY_AB_USE_MIDDLE
152 group:PREF_GROUP_ADDRESSBOOK] boolValue];
154 //If the use middle name preference is set, we use the menu titles that include a middle name
156 firstTitle = ADDRESS_BOOK_FIRST_MIDDLE_OPTION;
157 firstLastTitle = ADDRESS_BOOK_FIRST_MIDDLE_LAST_OPTION;
158 lastFirstTitle = ADDRESS_BOOK_LAST_FIRST_MIDDLE_OPTION;
159 lastFirstNoCommaTitle = ADDRESS_BOOK_LAST_FIRST_MIDDLE_NO_COMMA_OPTION;
161 //Otherwise we use the standard menu titles
163 firstTitle = ADDRESS_BOOK_FIRST_OPTION;
164 firstLastTitle = ADDRESS_BOOK_FIRST_LAST_OPTION;
165 lastFirstTitle = ADDRESS_BOOK_LAST_FIRST_OPTION;
166 lastFirstNoCommaTitle = ADDRESS_BOOK_LAST_FIRST_NO_COMMA_OPTION;
170 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:firstTitle
172 action:@selector(changeFormat:)
173 keyEquivalent:@""] autorelease];
174 [menuItem setTag:First];
175 [choicesMenu addItem:menuItem];
177 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:firstLastTitle
179 action:@selector(changeFormat:)
180 keyEquivalent:@""] autorelease];
181 [menuItem setTag:FirstLast];
182 [choicesMenu addItem:menuItem];
184 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:lastFirstTitle
186 action:@selector(changeFormat:)
187 keyEquivalent:@""] autorelease];
188 [menuItem setTag:LastFirst];
189 [choicesMenu addItem:menuItem];
191 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:lastFirstNoCommaTitle
193 action:@selector(changeFormat:)
194 keyEquivalent:@""] autorelease];
195 [menuItem setTag:LastFirstNoComma];
196 [choicesMenu addItem:menuItem];
198 [popUp_formatMenu setMenu:choicesMenu];
200 NSRect oldFrame = [popUp_formatMenu frame];
201 [popUp_formatMenu setFrameOrigin:oldFrame.origin];
202 [[self view] setNeedsDisplay:YES];
206 * @brief Save changed name format preference
208 - (IBAction)changeFormat:(id)sender
210 [[adium preferenceController] setPreference:[NSNumber numberWithInt:[sender tag]]
211 forKey:KEY_AB_DISPLAYFORMAT
212 group:PREF_GROUP_ADDRESSBOOK];
216 * @brief Save changed preference
218 - (IBAction)changePreference:(id)sender
220 if (sender == checkBox_syncAutomatic) {
221 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state]==NSOnState)]
222 forKey:KEY_AB_IMAGE_SYNC
223 group:PREF_GROUP_ADDRESSBOOK];
225 } else if (sender == checkBox_useABImages) {
226 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state]==NSOnState)]
227 forKey:KEY_AB_USE_IMAGES
228 group:PREF_GROUP_ADDRESSBOOK];
230 } else if (sender == checkBox_useNickName) {
231 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state]==NSOnState)]
232 forKey:KEY_AB_USE_NICKNAME
233 group:PREF_GROUP_ADDRESSBOOK];
235 } else if (sender == checkBox_useMiddleName) {
236 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
237 forKey:KEY_AB_USE_MIDDLE
238 group:PREF_GROUP_ADDRESSBOOK];
239 //Update the format menu to reflect the use of middle names
240 [self configureFormatMenu];
242 } else if (sender == checkBox_enableImport) {
243 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
244 forKey:KEY_AB_ENABLE_IMPORT
245 group:PREF_GROUP_ADDRESSBOOK];
247 } else if (sender == checkBox_preferABImages) {
248 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
249 forKey:KEY_AB_PREFER_ADDRESS_BOOK_IMAGES
250 group:PREF_GROUP_ADDRESSBOOK];
252 } else if (sender == checkBox_enableNoteSync) {
253 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
254 forKey:KEY_AB_NOTE_SYNC
255 group:PREF_GROUP_ADDRESSBOOK];
257 } else if (sender == checkBox_metaContacts) {
258 BOOL shouldCreateMetaContacts = ([sender state] == NSOnState);
260 if (shouldCreateMetaContacts) {
261 [[adium preferenceController] setPreference:[NSNumber numberWithBool:YES]
262 forKey:KEY_AB_CREATE_METACONTACTS
263 group:PREF_GROUP_ADDRESSBOOK];
266 NSBeginAlertSheet(nil,
267 AILocalizedString(@"Unconsolidate all metacontacts",nil),
268 AILocalizedString(@"Cancel",nil), nil,
269 [[self view] window], self,
270 @selector(sheetDidEnd:returnCode:contextInfo:), NULL,
272 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));
276 [self configureControlDimming];
279 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
281 if (returnCode == NSAlertDefaultReturn) {
282 //If we now shouldn't create metaContacts, clear 'em all... not pretty, but effective.
284 //Delay to the next run loop to give better UI responsiveness
285 [[adium contactController] performSelector:@selector(clearAllMetaContactData)
290 [[adium preferenceController] setPreference:[NSNumber numberWithBool:NO]
291 forKey:KEY_AB_CREATE_METACONTACTS
292 group:PREF_GROUP_ADDRESSBOOK];
294 //Put the checkbox back
295 [checkBox_metaContacts setState:![checkBox_metaContacts state]];