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 "AIContactController.h"
18 #import "ESAddressBookIntegrationAdvancedPreferences.h"
19 #import "ESAddressBookIntegrationPlugin.h"
20 #import <AIUtilities/AIDictionaryAdditions.h>
21 #import <AIUtilities/AIMenuAdditions.h>
22 #import <AIUtilities/ESImageAdditions.h>
23 #import <Adium/AILocalizationTextField.h>
25 #define ADDRESS_BOOK_FIRST_OPTION AILocalizedString(@"First","Name display style, e.g. Evan")
26 #define ADDRESS_BOOK_FIRST_LAST_OPTION AILocalizedString(@"First Last","Name display style, e.g. Evan Schoenberg")
27 #define ADDRESS_BOOK_LAST_FIRST_OPTION AILocalizedString(@"Last, First","Name display style, e.g. Schoenberg, Evan")
28 #define ADDRESS_BOOK_LAST_FIRST_NO_COMMA_OPTION AILocalizedString(@"Last First", "Name display style, e.g. Schoenberg Evan")
29 #define ADDRESS_BOOK_FIRST_MIDDLE_OPTION AILocalizedString(@"First Middle", "Name display style, e.g. Evan Dreskin")
30 #define ADDRESS_BOOK_FIRST_MIDDLE_LAST_OPTION AILocalizedString(@"First Middle Last", "Name display style, e.g. Evan Dreskin Schoenberg")
31 #define ADDRESS_BOOK_LAST_FIRST_MIDDLE_OPTION AILocalizedString(@"Last, First Middle", "Name display style, e.g. Schoenberg, Evan Dreskin")
32 #define ADDRESS_BOOK_LAST_FIRST_MIDDLE_NO_COMMA_OPTION AILocalizedString(@"Last First Middle", "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 - (PREFERENCE_CATEGORY)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 Restorable preferences
74 - (NSDictionary *)restorablePreferences
76 NSDictionary *defaultPrefs = [NSDictionary dictionaryNamed:AB_DISPLAYFORMAT_DEFAULT_PREFS forClass:[self class]];
77 NSDictionary *defaultsDict = [NSDictionary dictionaryWithObject:defaultPrefs forKey:PREF_GROUP_ADDRESSBOOK];
82 * @brief Configure the preference view
86 [self configureFormatMenu];
88 [label_formatNamesAs setLocalizedString:AILocalizedString(@"Format name as:", "Format name as: [popup menu of choices like 'First, Last']")];
89 [label_names setLocalizedString:AILocalizedString(@"Names",nil)];
90 [label_images setLocalizedString:AILocalizedString(@"Images",nil)];
91 [label_contacts setLocalizedString:AILocalizedString(@"Contacts",nil)];
93 [checkBox_enableImport setLocalizedString:AILocalizedString(@"Import my contacts' names from the Address Book",nil)];
94 [checkBox_useNickName setLocalizedString:AILocalizedString(@"Use nickname if available",nil)];
95 [checkBox_useMiddleName setLocalizedString:AILocalizedString(@"Use middle name if available",nil)];
96 [checkBox_useABImages setLocalizedString:AILocalizedString(@"Use Address Book images as contacts' icons",nil)];
97 [checkBox_preferABImages setLocalizedString:AILocalizedString(@"Even if the contact already has a contact icon",nil)];
98 [checkBox_syncAutomatic setLocalizedString:AILocalizedString(@"Overwrite Address Book images with contacts' icons",nil)];
99 [checkBox_metaContacts setLocalizedString:AILocalizedString(@"Consolidate contacts listed in the card",nil)];
101 NSDictionary *prefDict = [[adium preferenceController] preferencesForGroup:PREF_GROUP_ADDRESSBOOK];
103 [checkBox_enableImport setState:[[prefDict objectForKey:KEY_AB_ENABLE_IMPORT] boolValue]];
104 [popUp_formatMenu selectItemAtIndex:[popUp_formatMenu indexOfItemWithTag:[[prefDict objectForKey:KEY_AB_DISPLAYFORMAT] intValue]]];
105 [checkBox_useNickName setState:[[prefDict objectForKey:KEY_AB_USE_NICKNAME] boolValue]];
106 [checkBox_useMiddleName setState:[[prefDict objectForKey:KEY_AB_USE_MIDDLE] boolValue]];
107 [checkBox_syncAutomatic setState:[[prefDict objectForKey:KEY_AB_IMAGE_SYNC] boolValue]];
108 [checkBox_useABImages setState:[[prefDict objectForKey:KEY_AB_USE_IMAGES] boolValue]];
109 [checkBox_enableNoteSync setState:[[prefDict objectForKey:KEY_AB_NOTE_SYNC] boolValue]];
110 [checkBox_preferABImages setState:[[prefDict objectForKey:KEY_AB_PREFER_ADDRESS_BOOK_IMAGES] boolValue]];
111 [checkBox_metaContacts setState:[[prefDict objectForKey:KEY_AB_CREATE_METACONTACTS] boolValue]];
113 [self configureControlDimming];
125 * @brief Configure control dimming
127 - (void)configureControlDimming
129 NSDictionary *prefDict = [[adium preferenceController] preferencesForGroup:PREF_GROUP_ADDRESSBOOK];
131 BOOL enableImport = [[prefDict objectForKey:KEY_AB_ENABLE_IMPORT] boolValue];
132 BOOL useImages = [[prefDict objectForKey:KEY_AB_USE_IMAGES] boolValue];
134 //Use Nick Name and the format menu are irrelevent if importing of names is not enabled
135 [checkBox_useNickName setEnabled:enableImport];
136 [popUp_formatMenu setEnabled:enableImport];
137 [checkBox_useMiddleName setEnabled:enableImport];
139 //We will not allow image syncing if AB images are preferred
140 //so disable the control and uncheck the box to indicate this to the user
141 //dchoby98: why are image import and export linked?
142 //[checkBox_syncAutomatic setEnabled:!preferABImages];
143 //if (preferABImages)
144 // [checkBox_syncAutomatic setState:NSOffState];
146 //Disable the image priority checkbox if we aren't using images
147 [checkBox_preferABImages setEnabled:useImages];
151 * @brief Configure the menu of name formats
153 - (void)configureFormatMenu
155 NSMenu *choicesMenu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init] autorelease];
156 NSMenuItem *menuItem;
157 NSDictionary *prefDict = [[adium preferenceController] preferencesForGroup:PREF_GROUP_ADDRESSBOOK];
158 NSString *firstTitle, *firstLastTitle, *lastFirstTitle, *lastFirstNoCommaTitle;
160 BOOL useMiddleName = [[prefDict objectForKey:KEY_AB_USE_MIDDLE] boolValue];
162 //If the use middle name preference is set, we use the menu titles that include a middle name
164 firstTitle = ADDRESS_BOOK_FIRST_MIDDLE_OPTION;
165 firstLastTitle = ADDRESS_BOOK_FIRST_MIDDLE_LAST_OPTION;
166 lastFirstTitle = ADDRESS_BOOK_LAST_FIRST_MIDDLE_OPTION;
167 lastFirstNoCommaTitle = ADDRESS_BOOK_LAST_FIRST_MIDDLE_NO_COMMA_OPTION;
169 //Otherwise we use the standard menu titles
171 firstTitle = ADDRESS_BOOK_FIRST_OPTION;
172 firstLastTitle = ADDRESS_BOOK_FIRST_LAST_OPTION;
173 lastFirstTitle = ADDRESS_BOOK_LAST_FIRST_OPTION;
174 lastFirstNoCommaTitle = ADDRESS_BOOK_LAST_FIRST_NO_COMMA_OPTION;
178 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:firstTitle
180 action:@selector(changeFormat:)
181 keyEquivalent:@""] autorelease];
182 [menuItem setTag:First];
183 [choicesMenu addItem:menuItem];
185 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:firstLastTitle
187 action:@selector(changeFormat:)
188 keyEquivalent:@""] autorelease];
189 [menuItem setTag:FirstLast];
190 [choicesMenu addItem:menuItem];
192 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:lastFirstTitle
194 action:@selector(changeFormat:)
195 keyEquivalent:@""] autorelease];
196 [menuItem setTag:LastFirst];
197 [choicesMenu addItem:menuItem];
199 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:lastFirstNoCommaTitle
201 action:@selector(changeFormat:)
202 keyEquivalent:@""] autorelease];
203 [menuItem setTag:LastFirstNoComma];
204 [choicesMenu addItem:menuItem];
206 [popUp_formatMenu setMenu:choicesMenu];
208 NSRect oldFrame = [popUp_formatMenu frame];
209 [popUp_formatMenu setFrameOrigin:oldFrame.origin];
210 [[self view] setNeedsDisplay:YES];
214 * @brief Save changed name format preference
216 - (IBAction)changeFormat:(id)sender
218 [[adium preferenceController] setPreference:[NSNumber numberWithInt:[sender tag]]
219 forKey:KEY_AB_DISPLAYFORMAT
220 group:PREF_GROUP_ADDRESSBOOK];
224 * @brief Save changed preference
226 - (IBAction)changePreference:(id)sender
228 if (sender == checkBox_syncAutomatic){
229 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state]==NSOnState)]
230 forKey:KEY_AB_IMAGE_SYNC
231 group:PREF_GROUP_ADDRESSBOOK];
233 }else if (sender == checkBox_useABImages){
234 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state]==NSOnState)]
235 forKey:KEY_AB_USE_IMAGES
236 group:PREF_GROUP_ADDRESSBOOK];
238 }else if (sender == checkBox_useNickName){
239 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state]==NSOnState)]
240 forKey:KEY_AB_USE_NICKNAME
241 group:PREF_GROUP_ADDRESSBOOK];
243 } else if (sender == checkBox_useMiddleName) {
244 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
245 forKey:KEY_AB_USE_MIDDLE
246 group:PREF_GROUP_ADDRESSBOOK];
247 //Update the format menu to reflect the use of middle names
248 [self configureFormatMenu];
250 } else if (sender == checkBox_enableImport) {
251 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
252 forKey:KEY_AB_ENABLE_IMPORT
253 group:PREF_GROUP_ADDRESSBOOK];
255 }else if (sender == checkBox_preferABImages){
256 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
257 forKey:KEY_AB_PREFER_ADDRESS_BOOK_IMAGES
258 group:PREF_GROUP_ADDRESSBOOK];
260 }else if (sender == checkBox_enableNoteSync){
261 [[adium preferenceController] setPreference:[NSNumber numberWithBool:([sender state] == NSOnState)]
262 forKey:KEY_AB_NOTE_SYNC
263 group:PREF_GROUP_ADDRESSBOOK];
265 }else if (sender == checkBox_metaContacts){
266 BOOL shouldCreateMetaContacts = ([sender state] == NSOnState);
268 //If we now shouldn't create metaContacts, clear 'em all... not pretty, but effective.
269 if (!shouldCreateMetaContacts){
270 //Delay to the next run loop to give better UI responsiveness
271 [[adium contactController] performSelector:@selector(clearAllMetaContactData)
276 [[adium preferenceController] setPreference:[NSNumber numberWithBool:shouldCreateMetaContacts]
277 forKey:KEY_AB_CREATE_METACONTACTS
278 group:PREF_GROUP_ADDRESSBOOK];
281 [self configureControlDimming];