2 // AIAdvancedPreferences.m
5 // Created by Evan Schoenberg on 4/7/07.
8 #import "AIAdvancedPreferences.h"
9 #import <Adium/AIAdvancedPreferencePane.h>
10 #import <Adium/KNShelfSplitView.h>
11 #import <Adium/AIModularPaneCategoryView.h>
12 #import <Adium/AIPreferenceControllerProtocol.h>
13 #import <AIUtilities/AIImageTextCell.h>
14 #import <AIUtilities/AIViewAdditions.h>
15 #import <AIUtilities/AIAlternatingRowTableView.h>
17 #define KEY_ADVANCED_PREFERENCE_SELECTED_ROW @"Preference Advanced Selected Row"
18 #define KEY_ADVANCED_PREFERENCE_SHELF_WIDTH @"AdvancedPrefs:ShelfWidth"
20 @interface AIAdvancedPreferences (PRIVATE)
21 - (void)_configureAdvancedPreferencesTable;
24 @implementation AIAdvancedPreferences
25 + (AIPreferencePane *)preferencePane
27 [[[AIObject sharedAdiumInstance] preferenceController] registerDefaults:[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:150]
28 forKey:KEY_ADVANCED_PREFERENCE_SHELF_WIDTH]
29 forGroup:PREF_GROUP_WINDOW_POSITIONS];
31 return [super preferencePane];
34 - (NSString *)paneIdentifier
38 - (NSString *)paneName{
39 return AILocalizedString(@"Advanced", "Title of the messages preferences");
41 - (NSString *)nibName{
42 return @"AdvancedPreferences";
46 return [NSImage imageNamed:@"pref-advanced"];
50 * @brief Configure the preference view
54 [shelf_splitView setFrame:[[shelf_splitView superview] frame]];
55 [shelf_splitView setShelfWidth:[[[adium preferenceController] preferenceForKey:KEY_ADVANCED_PREFERENCE_SHELF_WIDTH
56 group:PREF_GROUP_WINDOW_POSITIONS] floatValue]];
58 [self _configureAdvancedPreferencesTable];
63 //Select the previously selected row
64 [[adium preferenceController] setPreference:[NSNumber numberWithInt:[tableView_categories selectedRow]]
65 forKey:KEY_ADVANCED_PREFERENCE_SELECTED_ROW
66 group:PREF_GROUP_WINDOW_POSITIONS];
68 [[adium preferenceController] setPreference:[NSNumber numberWithFloat:[shelf_splitView shelfWidth]]
69 forKey:KEY_ADVANCED_PREFERENCE_SHELF_WIDTH
70 group:PREF_GROUP_WINDOW_POSITIONS];
73 [loadedAdvancedPanes makeObjectsPerformSelector:@selector(closeView)];
74 [modularPane removeAllSubviews];
75 [loadedAdvancedPanes release]; loadedAdvancedPanes = nil;
76 [_advancedCategoryArray release]; _advancedCategoryArray = nil;
80 * @brief Returns an array containing all the available advanced preference views
82 - (NSArray *)advancedCategoryArray
84 if (!_advancedCategoryArray) {
85 _advancedCategoryArray = [[[[adium preferenceController] advancedPaneArray] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] retain];
88 return _advancedCategoryArray;
92 * @brief Displays the passed AIPreferencePane in the advanced preferences tab of our window
94 - (void)configureAdvancedPreferencesForPane:(AIAdvancedPreferencePane *)preferencePane
97 [loadedAdvancedPanes makeObjectsPerformSelector:@selector(closeView)];
98 [modularPane removeAllSubviews];
99 [loadedAdvancedPanes release]; loadedAdvancedPanes = nil;
102 if (preferencePane) {
103 loadedAdvancedPanes = [[NSArray arrayWithObject:preferencePane] retain];
104 [modularPane setPanes:loadedAdvancedPanes];
109 * @brief Configure the advanced preference category table view
111 - (void)_configureAdvancedPreferencesTable
113 AIImageTextCell *cell;
115 //Configure our tableView
116 cell = [[AIImageTextCell alloc] init];
117 [cell setFont:[NSFont systemFontOfSize:12]];
118 [[tableView_categories tableColumnWithIdentifier:@"description"] setDataCell:cell];
121 [[tableView_categories enclosingScrollView] setAutohidesScrollers:YES];
122 [tableView_categories setDrawsGradientSelection:YES];
124 //This is the Mail.app source list background color... which differs from the iTunes one.
125 [tableView_categories setBackgroundColor:[NSColor colorWithCalibratedRed:.9059
130 //Select the previously selected row
131 int row = [[[adium preferenceController] preferenceForKey:KEY_ADVANCED_PREFERENCE_SELECTED_ROW
132 group:PREF_GROUP_WINDOW_POSITIONS] intValue];
133 if (row < 0 || row >= [tableView_categories numberOfRows]) row = 1;
135 if ([self tableView:tableView_categories shouldSelectRow:row]) {
136 [tableView_categories selectRow:row byExtendingSelection:NO];
141 * @brief Return the number of accounts
143 - (int)numberOfRowsInTableView:(NSTableView *)tableView
145 return [[self advancedCategoryArray] count];
149 * @brief Return the account description or image
151 - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
153 return [[[self advancedCategoryArray] objectAtIndex:row] label];
157 * @brief Set the category image before the cell is displayed
159 - (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(int)row
161 [cell setImage:[[[self advancedCategoryArray] objectAtIndex:row] image]];
162 [cell setSubString:nil];
166 * @brief Update our advanced preferences for the selected pane
168 - (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(int)row
170 if (row >= 0 && row < [[self advancedCategoryArray] count]) {
171 [self configureAdvancedPreferencesForPane:[[self advancedCategoryArray] objectAtIndex:row]];