We need a b8 before we can release since we've had some significant changes since...
[adiumx.git] / Source / AIAdvancedPreferences.m
bloba7a14ef4182c84e6c0fabd98d6aacd96695befe2
1 //
2 //  AIAdvancedPreferences.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 4/7/07.
6 //
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;
22 @end
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];
30         
31         return [super preferencePane];
34 - (NSString *)paneIdentifier
36         return @"Advanced";
38 - (NSString *)paneName{
39         return AILocalizedString(@"Advanced", "Title of the messages preferences");
41 - (NSString *)nibName{
42     return @"AdvancedPreferences";
44 - (NSImage *)paneIcon
46         return [NSImage imageNamed:@"pref-advanced"];
49 /*!
50  * @brief Configure the preference view
51  */
52 - (void)viewDidLoad
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];
61 - (void)viewWillClose
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];
71         
72         //Close open panes
73         [loadedAdvancedPanes makeObjectsPerformSelector:@selector(closeView)];
74         [modularPane removeAllSubviews];
75         [loadedAdvancedPanes release]; loadedAdvancedPanes = nil;
76         [_advancedCategoryArray release]; _advancedCategoryArray = nil;
79 /*!
80 * @brief Returns an array containing all the available advanced preference views
81  */
82 - (NSArray *)advancedCategoryArray
84     if (!_advancedCategoryArray) {
85         _advancedCategoryArray = [[[[adium preferenceController] advancedPaneArray] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] retain];
86     }
87     
88     return _advancedCategoryArray;
91 /*!
92  * @brief Displays the passed AIPreferencePane in the advanced preferences tab of our window
93  */
94 - (void)configureAdvancedPreferencesForPane:(AIAdvancedPreferencePane *)preferencePane
96         //Close open panes
97         [loadedAdvancedPanes makeObjectsPerformSelector:@selector(closeView)];
98         [modularPane removeAllSubviews];
99         [loadedAdvancedPanes release]; loadedAdvancedPanes = nil;
100         
101         //Load new panes
102         if (preferencePane) {
103                 loadedAdvancedPanes = [[NSArray arrayWithObject:preferencePane] retain];
104                 [modularPane setPanes:loadedAdvancedPanes];
105         }
109 * @brief Configure the advanced preference category table view
110  */
111 - (void)_configureAdvancedPreferencesTable
113     AIImageTextCell                     *cell;
114         
115     //Configure our tableView
116     cell = [[AIImageTextCell alloc] init];
117     [cell setFont:[NSFont systemFontOfSize:12]];
118     [[tableView_categories tableColumnWithIdentifier:@"description"] setDataCell:cell];
119         [cell release];
120         
121     [[tableView_categories enclosingScrollView] setAutohidesScrollers:YES];
122         [tableView_categories setDrawsGradientSelection:YES];
123         
124         //This is the Mail.app source list background color... which differs from the iTunes one.
125         [tableView_categories setBackgroundColor:[NSColor colorWithCalibratedRed:.9059
126                                                                                                                                            green:.9294
127                                                                                                                                                 blue:.9647
128                                                                                                                                            alpha:1.0]];
129         
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;
134         
135         if ([self tableView:tableView_categories shouldSelectRow:row]) {
136                 [tableView_categories selectRow:row byExtendingSelection:NO];
137         }
141 * @brief Return the number of accounts
142  */
143 - (int)numberOfRowsInTableView:(NSTableView *)tableView
145         return [[self advancedCategoryArray] count];
149 * @brief Return the account description or image
150  */
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
158  */
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
167  */
168 - (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(int)row
170         if (row >= 0 && row < [[self advancedCategoryArray] count]) {           
171                 [self configureAdvancedPreferencesForPane:[[self advancedCategoryArray] objectAtIndex:row]];
172                 return YES;
173     } else {
174                 return NO;
175         }
178 @end