William Bowling is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this again1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | /*
* Adium is the legal property of its developers, whose names are listed in the copyright file included
* with this source distribution.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "AICLPreferences.h"
#import "AIListLayoutWindowController.h"
#import "AIListThemePreviewCell.h"
#import "AIListThemeWindowController.h"
#import "AISCLViewPlugin.h"
#import <AIUtilities/AIFileManagerAdditions.h>
#import <AIUtilities/AIImageTextCell.h>
#import <AIUtilities/ESImageAdditions.h>
#import <Adium/AIAbstractListController.h>
//Handles the interface interaction, and sets preference values
//The outline view plugin is responsible for reading & setting the preferences, as well as observing changes in them
@interface AICLPreferences (PRIVATE)
- (void)configureView;
- (void)changeFont:(id)sender;
- (void)showFont:(NSFont *)inFont inField:(NSTextField *)inTextField;
- (void)configureControlDimming;
- (void)updateLayouts;
- (void)updateThemes;
- (void)updateSelectedLayoutAndTheme;
- (void)applySet:(NSDictionary *)setDictionary toPreferenceGroup:(NSString *)preferenceGroup;
- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row;
@end
@implementation AICLPreferences
//Preference pane properties
- (PREFERENCE_CATEGORY)category{
return AIPref_Advanced;
}
- (NSString *)label{
return @"General Appearance";
}
- (NSString *)nibName{
return @"AICLPrefView";
}
//Configures our view for the current preferences
- (void)viewDidLoad
{
AIImageTextCell *dataCell;
currentLayoutName = [@"Default" retain];
currentThemeName = [@"Default" retain];
[self updateLayouts];
[self updateThemes];
//Observe for installation of new themes/layouts
[[adium notificationCenter] addObserver:self
selector:@selector(xtrasChanged:)
name:Adium_Xtras_Changed
object:nil];
[adium.preferenceController registerPreferenceObserver:self forGroup:PREF_GROUP_CONTACT_LIST];
//Images
layoutStandard = [[NSImage imageNamed:@"style-standard" forClass:[self class]] retain];
layoutBorderless = [[NSImage imageNamed:@"style-borderless" forClass:[self class]] retain];
layoutMockie = [[NSImage imageNamed:@"style-mockie" forClass:[self class]] retain];
layoutPillows = [[NSImage imageNamed:@"style-pillows" forClass:[self class]] retain];
//
[button_themeEdit setTitle:@"Edit"];
[button_layoutEdit setTitle:@"Edit"];
//
dataCell = [[[AIImageTextCell alloc] init] autorelease];
[dataCell setFont:[NSFont systemFontOfSize:12]];
[dataCell setIgnoresFocus:YES];
[dataCell setDrawsGradientHighlight:YES];
[[tableView_layout tableColumnWithIdentifier:@"name"] setDataCell:dataCell];
dataCell = [[[AIGradientCell alloc] init] autorelease];
[dataCell setFont:[NSFont systemFontOfSize:12]];
[dataCell setIgnoresFocus:YES];
[dataCell setDrawsGradientHighlight:YES];
[[tableView_layout tableColumnWithIdentifier:@"preview"] setDataCell:dataCell];
dataCell = [[[AIImageTextCell alloc] init] autorelease];
[dataCell setFont:[NSFont systemFontOfSize:12]];
[dataCell setIgnoresFocus:YES];
[dataCell setDrawsGradientHighlight:YES];
[[tableView_theme tableColumnWithIdentifier:@"name"] setDataCell:dataCell];
//
[tableView_layout setTarget:self];
[tableView_layout setDoubleAction:@selector(editLayout:)];
[tableView_theme setTarget:self];
[tableView_theme setDoubleAction:@selector(editTheme:)];
}
//Preference view is closing
- (void)viewWillClose
{
[layoutStandard release]; layoutStandard = nil;
[layoutBorderless release]; layoutBorderless = nil;
[layoutMockie release]; layoutMockie = nil;
[layoutPillows release]; layoutPillows = nil;
[[adium notificationCenter] removeObserver:self];
[adium.preferenceController unregisterPreferenceObserver:self];
[AISCLViewPlugin resetXtrasCache];
}
//Installed xtras have changed
- (void)xtrasChanged:(NSNotification *)notification
{
if(notification == nil || [[notification object] caseInsensitiveCompare:LIST_LAYOUT_EXTENSION] == 0){
[AISCLViewPlugin resetXtrasCache];
[self updateLayouts];
}else if(notification == nil || [[notification object] caseInsensitiveCompare:LIST_THEME_EXTENSION] == 0){
[AISCLViewPlugin resetXtrasCache];
[self updateThemes];
}
}
//Selected theme/layout changed
- (void)preferencesChangedForGroup:(NSString *)group key:(NSString *)key
object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime
{
[self updateSelectedLayoutAndTheme];
}
//Update our list of available layouts
- (void)updateLayouts
{
[layoutArray release];
layoutArray = [[AISCLViewPlugin availableLayoutSets] retain];
[tableView_layout reloadData];
[self updateSelectedLayoutAndTheme];
}
//Update our list of available themes
- (void)updateThemes
{
[themeArray release];
themeArray = [[AISCLViewPlugin availableThemeSets] retain];
[tableView_theme reloadData];
[self updateSelectedLayoutAndTheme];
}
//Update the selected table rows to match our preferences
- (void)updateSelectedLayoutAndTheme
{
NSEnumerator *enumerator;
NSDictionary *dict;
[currentLayoutName release];
[currentThemeName release];
currentLayoutName = [[adium.preferenceController preferenceForKey:KEY_LIST_LAYOUT_NAME group:PREF_GROUP_CONTACT_LIST] retain];
currentThemeName = [[adium.preferenceController preferenceForKey:KEY_LIST_THEME_NAME group:PREF_GROUP_CONTACT_LIST] retain];
enumerator = [layoutArray objectEnumerator];
while((dict = [enumerator nextObject])){
if([[dict objectForKey:@"name"] isEqualToString:currentLayoutName]){
[tableView_layout selectRow:[layoutArray indexOfObject:dict] byExtendingSelection:NO];
}
}
enumerator = [themeArray objectEnumerator];
while((dict = [enumerator nextObject])){
if([[dict objectForKey:@"name"] isEqualToString:currentThemeName]){
[tableView_theme selectRow:[themeArray indexOfObject:dict] byExtendingSelection:NO];
}
}
[self configureControlDimming];
}
- (void)configureControlDimming
{
[button_layoutEdit setEnabled:([layoutArray count] > 0)];
[button_layoutDelete setEnabled:([layoutArray count] > 1)];
[button_themeEdit setEnabled:([themeArray count] > 0)];
[button_themeDelete setEnabled:([themeArray count] > 1)];
}
//Editing --------------------------------------------------------------------------------------------------------------
#pragma mark Editing
//Create new layout or theme
- (IBAction)spawnLayout:(id)sender
{
[AIListLayoutWindowController listLayoutOnWindow:[[self view] window]
withName:[NSString stringWithFormat:@"%@ Copy",currentLayoutName]];
}
- (IBAction)spawnTheme:(id)sender
{
[AIListThemeWindowController listThemeOnWindow:[[self view] window]
withName:[NSString stringWithFormat:@"%@ Copy",currentThemeName]];
}
//Edit a layout or theme
- (IBAction)editTheme:(id)sender
{
[AIListThemeWindowController listThemeOnWindow:[[self view] window] withName:currentThemeName];
}
- (IBAction)editLayout:(id)sender
{
[AIListLayoutWindowController listLayoutOnWindow:[[self view] window] withName:currentLayoutName];
}
//Delete a layout
- (IBAction)deleteLayout:(id)sender
{
if([layoutArray count] > 1){
NSDictionary *selected = [layoutArray objectAtIndex:[tableView_layout selectedRow]];
NSBeginAlertSheet(AILocalizedString(@"Delete Layout",nil),
AILocalizedString(@"Delete",nil),
AILocalizedString(@"Cancel",nil),
@"",
[[self view] window],
self,
@selector(deleteLayoutSheetDidEnd:returnCode:contextInfo:),
nil,
selected,
AILocalizedString(@"Delete the layout \"%@\" from %@?",nil),
[selected objectForKey:@"name"],
[selected objectForKey:@"path"]);
}
}
- (void)deleteLayoutSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(NSDictionary *)contextInfo
{
if(returnCode == NSAlertDefaultReturn && contextInfo){
NSString *path = [contextInfo objectForKey:@"path"];
if(path){
[[NSFileManager defaultManager] trashFileAtPath:path];
[[adium notificationCenter] postNotificationName:Adium_Xtras_Changed object:LIST_LAYOUT_EXTENSION];
[self tableView:tableView_layout shouldSelectRow:[tableView_layout selectedRow]];
}
}
}
//Delete a theme
- (IBAction)deleteTheme:(id)sender
{
if([themeArray count] > 1){
NSDictionary *selected = [themeArray objectAtIndex:[tableView_theme selectedRow]];
NSBeginAlertSheet(AILocalizedString(@"Delete Theme",nil),
AILocalizedString(@"Delete",nil),
AILocalizedString(@"Cancel",nil),
@"",
[[self view] window],
self,
@selector(deleteThemeSheetDidEnd:returnCode:contextInfo:),
nil,
selected,
AILocalizedString(@"Delete the theme \"%@\" from %@?",nil),
[selected objectForKey:@"name"],
[selected objectForKey:@"path"]);
}
}
- (void)deleteThemeSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(NSDictionary *)contextInfo
{
if(returnCode == NSAlertDefaultReturn && contextInfo){
NSString *path = [contextInfo objectForKey:@"path"];
if(path){
[[NSFileManager defaultManager] trashFileAtPath:path];
[[adium notificationCenter] postNotificationName:Adium_Xtras_Changed object:LIST_THEME_EXTENSION];
[self tableView:tableView_theme shouldSelectRow:[tableView_theme selectedRow]];
}
}
}
//Table Delegate -------------------------------------------------------------------------------------------------------
#pragma mark Table Delegate
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
if(tableView == tableView_layout){
return [layoutArray count];
}else{
return [themeArray count];
}
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSString *column = [tableColumn identifier];
if(tableView == tableView_layout){
NSDictionary *layoutDict = [layoutArray objectAtIndex:row];
if([column isEqualToString:@"name"]){
return [layoutDict objectForKey:@"name"];
}else if([column isEqualToString:@"preview"]){
return @"-";
}
}else if(tableView == tableView_theme){
NSDictionary *themeDict = [themeArray objectAtIndex:row];
if([column isEqualToString:@"type"]){
return @"-";
}else if([column isEqualToString:@"name"]){
return [themeDict objectForKey:@"name"];
}else if([column isEqualToString:@"preview"]){
return @"-";
}
}
return @"-";
}
- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row
{
if(tableView == tableView_layout){
NSDictionary *layoutDict = [layoutArray objectAtIndex:row];
[adium.preferenceController setPreference:[layoutDict objectForKey:@"name"]
forKey:KEY_LIST_LAYOUT_NAME
group:PREF_GROUP_CONTACT_LIST];
}else if(tableView == tableView_theme){
NSDictionary *themeDict = [themeArray objectAtIndex:row];
[adium.preferenceController setPreference:[themeDict objectForKey:@"name"]
forKey:KEY_LIST_THEME_NAME
group:PREF_GROUP_CONTACT_LIST];
}
[self updateSelectedLayoutAndTheme];
return YES;
}
- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
// NSString *column = [tableColumn identifier];
//
// if(tableView == tableView_layout){
// if([column isEqualToString:@"name"]){
// NSImage *image = nil;
// switch([[[[layoutArray objectAtIndex:row] objectForKey:@"preferences"] objectForKey:KEY_LIST_LAYOUT_WINDOW_STYLE] intValue]){
// case WINDOW_STYLE_STANDARD: image = layoutStandard; break;
// case WINDOW_STYLE_BORDERLESS: image = layoutBorderless; break;
// case WINDOW_STYLE_MOCKIE: image = layoutMockie; break;
// case WINDOW_STYLE_PILLOWS: image = layoutPillows; break;
// case WINDOW_STYLE_PILLOWS_FITTED: image = layoutPillows; break;
// }
// [cell setImage:image];
// }else{
// [cell setImage:nil];
// }
// }else if(tableView == tableView_theme){
// if([column isEqualToString:@"preview"]){
// [cell setThemeDict:[[themeArray objectAtIndex:row] objectForKey:@"preferences"]];
// }
// }
}
@end
|