1 #import "PreferencesController.h"
2 #import "MainController.h"
3 #import "StatusWindow.h"
4 #import "StatusWindowController.h"
5 #import "CustomMenuTableView.h"
7 #import <ITKit/ITHotKeyCenter.h>
8 #import <ITKit/ITKeyCombo.h>
9 #import <ITKit/ITWindowPositioning.h>
10 #import <ITKit/ITKeyBroadcaster.h>
12 #import <ITKit/ITCutWindowEffect.h>
13 #import <ITKit/ITDissolveWindowEffect.h>
14 #import <ITKit/ITSlideHorizontallyWindowEffect.h>
15 #import <ITKit/ITSlideVerticallyWindowEffect.h>
16 #import <ITKit/ITPivotWindowEffect.h>
19 #define SENDER_STATE (([sender state] == NSOnState) ? YES : NO)
21 /*************************************************************************/
23 #pragma mark PRIVATE INTERFACE
24 /*************************************************************************/
26 @interface PreferencesController (Private)
28 - (void)setupCustomizationTables;
29 - (void)setupMenuItems;
31 - (IBAction)changeMenus:(id)sender;
32 - (void)setLaunchesAtLogin:(BOOL)flag;
36 @implementation PreferencesController
39 /*************************************************************************/
41 #pragma mark STATIC VARIABLES
42 /*************************************************************************/
44 static PreferencesController *prefs = nil;
47 /*************************************************************************/
49 #pragma mark INITIALIZATION METHODS
50 /*************************************************************************/
52 + (PreferencesController *)sharedPrefs;
55 prefs = [[self alloc] init];
62 if ( (self = [super init]) ) {
63 ITDebugLog(@"Preferences initialized.");
64 df = [[NSUserDefaults standardUserDefaults] retain];
65 hotKeysDictionary = [[NSMutableDictionary alloc] init];
72 /*************************************************************************/
74 #pragma mark ACCESSOR METHODS
75 /*************************************************************************/
82 - (void)setController:(id)object
84 [controller autorelease];
85 controller = [object retain];
89 /*************************************************************************/
91 #pragma mark INSTANCE METHODS
92 /*************************************************************************/
94 - (IBAction)showPrefsWindow:(id)sender
96 ITDebugLog(@"Showing preferences window.");
97 if (! window) { // If window does not exist yet, then the nib hasn't been loaded.
98 ITDebugLog(@"Window doesn't exist, initial setup.");
99 [self setupWindow]; // Load in the nib, and perform any initial setup.
100 [self setupCustomizationTables]; // Setup the DnD manu config tables.
101 [self setupMenuItems]; // Setup the arrays of menu items
102 [self setupUI]; // Sets up additional UI
103 [window setDelegate:self];
104 [menuTableView reloadData];
106 //Change the launch player checkbox to the proper name
107 [launchPlayerAtLaunchCheckbox setTitle:[NSString stringWithFormat:@"Launch %@ when MenuTunes launches", [[controller currentRemote] playerSimpleName]]]; //This isn't localized...
111 [NSApp activateIgnoringOtherApps:YES];
112 [window performSelector:@selector(makeKeyAndOrderFront:) withObject:self afterDelay:0.0];
115 - (IBAction)changeGeneralSetting:(id)sender
117 ITDebugLog(@"Changing general setting of tag %i.", [sender tag]);
118 if ( [sender tag] == 1010) {
119 [self setLaunchesAtLogin:SENDER_STATE];
120 } else if ( [sender tag] == 1020) {
121 [df setBool:SENDER_STATE forKey:@"LaunchPlayerWithMT"];
122 } else if ( [sender tag] == 1030) {
123 [df setInteger:[sender intValue] forKey:@"SongsInAdvance"];
125 } else if ( [sender tag] == 1040) {
126 // This will not be executed. Song info always shows the title of the song.
127 // [df setBool:SENDER_STATE forKey:@"showName"];
128 } else if ( [sender tag] == 1050) {
129 [df setBool:SENDER_STATE forKey:@"showArtist"];
130 } else if ( [sender tag] == 1060) {
131 [df setBool:SENDER_STATE forKey:@"showAlbum"];
132 } else if ( [sender tag] == 1070) {
133 [df setBool:SENDER_STATE forKey:@"showTime"];
134 } else if ( [sender tag] == 1080) {
135 [df setBool:SENDER_STATE forKey:@"showTrackNumber"];
136 } else if ( [sender tag] == 1090) {
137 [df setBool:SENDER_STATE forKey:@"showTrackRating"];
142 - (IBAction)changeStatusWindowSetting:(id)sender
144 StatusWindow *sw = [StatusWindow sharedWindow];
145 ITDebugLog(@"Changing status window setting of tag %i", [sender tag]);
146 if ( [sender tag] == 2010) {
147 [df setInteger:[sender selectedRow] forKey:@"statusWindowVerticalPosition"];
148 [df setInteger:[sender selectedColumn] forKey:@"statusWindowHorizontalPosition"];
149 // update the window's position here
150 } else if ( [sender tag] == 2020) {
151 // update screen selection
152 } else if ( [sender tag] == 2030) {
153 int effectTag = [[sender selectedItem] tag];
154 float time = ([df floatForKey:@"statusWindowAppearanceSpeed"] ? [df floatForKey:@"statusWindowAppearanceSpeed"] : 0.8);
155 [df setInteger:effectTag forKey:@"statusWindowAppearanceEffect"];
157 if ( effectTag == 2100 ) {
158 [sw setEntryEffect:[[[ITCutWindowEffect alloc] initWithWindow:sw] autorelease]];
159 } else if ( effectTag == 2101 ) {
160 [sw setEntryEffect:[[[ITDissolveWindowEffect alloc] initWithWindow:sw] autorelease]];
161 } else if ( effectTag == 2102 ) {
162 [sw setEntryEffect:[[[ITSlideVerticallyWindowEffect alloc] initWithWindow:sw] autorelease]];
163 } else if ( effectTag == 2103 ) {
164 [sw setEntryEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:sw] autorelease]];
165 } else if ( effectTag == 2104 ) {
167 [sw setEntryEffect:[[[ITPivotWindowEffect alloc] initWithWindow:sw] autorelease]];
170 [[sw entryEffect] setEffectTime:time];
172 } else if ( [sender tag] == 2040) {
173 int effectTag = [[sender selectedItem] tag];
174 float time = ([df floatForKey:@"statusWindowVanishSpeed"] ? [df floatForKey:@"statusWindowVanishSpeed"] : 0.8);
176 [df setInteger:[[sender selectedItem] tag] forKey:@"statusWindowVanishEffect"];
178 if ( effectTag == 2100 ) {
179 [sw setExitEffect:[[[ITCutWindowEffect alloc] initWithWindow:sw] autorelease]];
180 } else if ( effectTag == 2101 ) {
181 [sw setExitEffect:[[[ITDissolveWindowEffect alloc] initWithWindow:sw] autorelease]];
182 } else if ( effectTag == 2102 ) {
183 [sw setExitEffect:[[[ITSlideVerticallyWindowEffect alloc] initWithWindow:sw] autorelease]];
184 } else if ( effectTag == 2103 ) {
185 [sw setExitEffect:[[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:sw] autorelease]];
186 } else if ( effectTag == 2104 ) {
187 [sw setExitEffect:[[[ITPivotWindowEffect alloc] initWithWindow:sw] autorelease]];
190 [[sw exitEffect] setEffectTime:time];
192 } else if ( [sender tag] == 2050) {
193 float newTime = (-([sender floatValue]));
194 [df setFloat:newTime forKey:@"statusWindowAppearanceSpeed"];
195 [[sw entryEffect] setEffectTime:newTime];
196 } else if ( [sender tag] == 2060) {
197 float newTime = (-([sender floatValue]));
198 [df setFloat:newTime forKey:@"statusWindowVanishSpeed"];
199 [[sw exitEffect] setEffectTime:newTime];
200 } else if ( [sender tag] == 2070) {
201 [df setFloat:[sender floatValue] forKey:@"statusWindowVanishDelay"];
202 [sw setExitDelay:[sender floatValue]];
203 } else if ( [sender tag] == 2080) {
204 [df setBool:SENDER_STATE forKey:@"showSongInfoOnChange"];
209 - (IBAction)changeHotKey:(id)sender
211 ITDebugLog(@"Changing hot keys.");
212 [controller clearHotKeys];
213 switch ([sender tag])
216 [self setKeyCombo:[hotKeysDictionary objectForKey:@"PlayPause"]];
217 [self setCurrentHotKey:@"PlayPause"];
220 [self setKeyCombo:[hotKeysDictionary objectForKey:@"NextTrack"]];
221 [self setCurrentHotKey:@"NextTrack"];
224 [self setKeyCombo:[hotKeysDictionary objectForKey:@"PrevTrack"]];
225 [self setCurrentHotKey:@"PrevTrack"];
228 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ShowPlayer"]];
229 [self setCurrentHotKey:@"ShowPlayer"];
232 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleLoop"]];
233 [self setCurrentHotKey:@"ToggleLoop"];
236 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleShuffle"]];
237 [self setCurrentHotKey:@"ToggleShuffle"];
240 [self setKeyCombo:[hotKeysDictionary objectForKey:@"TrackInfo"]];
241 [self setCurrentHotKey:@"TrackInfo"];
244 [self setKeyCombo:[hotKeysDictionary objectForKey:@"UpcomingSongs"]];
245 [self setCurrentHotKey:@"UpcomingSongs"];
248 [self setKeyCombo:[hotKeysDictionary objectForKey:@"IncrementVolume"]];
249 [self setCurrentHotKey:@"IncrementVolume"];
252 [self setKeyCombo:[hotKeysDictionary objectForKey:@"DecrementVolume"]];
253 [self setCurrentHotKey:@"DecrementVolume"];
256 [self setKeyCombo:[hotKeysDictionary objectForKey:@"IncrementRating"]];
257 [self setCurrentHotKey:@"IncrementRating"];
260 [self setKeyCombo:[hotKeysDictionary objectForKey:@"DecrementRating"]];
261 [self setCurrentHotKey:@"DecrementRating"];
266 - (void)registerDefaults
269 NSMutableDictionary *loginWindow;
270 NSMutableArray *loginArray;
271 NSEnumerator *loginEnum;
273 ITDebugLog(@"Registering defaults.");
274 [df setObject:[NSArray arrayWithObjects:
286 nil] forKey:@"menu"];
288 [df setInteger:5 forKey:@"SongsInAdvance"];
289 // [df setBool:YES forKey:@"showName"]; // Song info will always show song title.
290 [df setBool:YES forKey:@"showArtist"];
291 [df setBool:NO forKey:@"showAlbum"];
292 [df setBool:NO forKey:@"showTime"];
294 [df setInteger:2100 forKey:@"statusWindowAppearanceEffect"];
295 [df setInteger:2101 forKey:@"statusWindowVanishEffect"];
296 [df setFloat:0.8 forKey:@"statusWindowAppearanceSpeed"];
297 [df setFloat:0.8 forKey:@"statusWindowVanishSpeed"];
298 [df setFloat:4.0 forKey:@"statusWindowVanishDelay"];
299 [df setBool:YES forKey:@"showSongInfoOnChange"];
303 loginWindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
304 loginArray = [loginWindow objectForKey:@"AutoLaunchedApplicationDictionary"];
305 loginEnum = [loginArray objectEnumerator];
307 while ( (anItem = [loginEnum nextObject]) ) {
308 if ( [[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]] ) {
312 [loginWindow release];
315 [[StatusWindowController sharedController] showSetupQueryWindow];
321 [[StatusWindow sharedWindow] setLocked:NO];
322 [[StatusWindow sharedWindow] vanish:self];
323 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
325 [self setLaunchesAtLogin:YES];
328 - (void)autoLaunchCancel
330 [[StatusWindow sharedWindow] setLocked:NO];
331 [[StatusWindow sharedWindow] vanish:self];
332 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
335 - (IBAction)cancelHotKey:(id)sender
337 ITDebugLog(@"Hot key canceled.");
338 [[NSNotificationCenter defaultCenter] removeObserver:self];
339 [NSApp endSheet:keyComboPanel];
340 [keyComboPanel orderOut:nil];
343 - (IBAction)clearHotKey:(id)sender
345 ITDebugLog(@"Hot key cleared.");
346 [self setKeyCombo:[ITKeyCombo clearKeyCombo]];
349 - (IBAction)okHotKey:(id)sender
351 NSString *string = [combo description];
352 NSEnumerator *enumerator = [hotKeysDictionary keyEnumerator];
355 ITDebugLog(@"Hot key ok'd, saving.");
361 ITDebugLog(@"Checking for duplicate hot keys.");
362 while ( (enumKey = [enumerator nextObject]) ) {
363 if (![enumKey isEqualToString:currentHotKey]) {
364 if (![combo isEqual:[ITKeyCombo clearKeyCombo]] &&
365 [combo isEqual:[hotKeysDictionary objectForKey:enumKey]]) {
366 [window setLevel:NSNormalWindowLevel];
367 ITDebugLog(@"Duplicate hot key found: %@", enumKey);
368 if ( NSRunAlertPanel(NSLocalizedString(@"duplicateCombo", @"Duplicate Key Combo") , NSLocalizedString(@"duplicateCombo_msg", @"The specified key combo is already in use..."), NSLocalizedString(@"replace", @"Replace"), NSLocalizedString(@"cancel", @"Cancel"), nil) ) {
369 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:currentHotKey];
370 if ([enumKey isEqualToString:@"PlayPause"]) {
371 [playPauseButton setTitle:@"(None)"];
372 } else if ([enumKey isEqualToString:@"NextTrack"]) {
373 [nextTrackButton setTitle:@"(None)"];
374 } else if ([enumKey isEqualToString:@"PrevTrack"]) {
375 [previousTrackButton setTitle:@"(None)"];
376 } else if ([enumKey isEqualToString:@"ShowPlayer"]) {
377 [showPlayerButton setTitle:@"(None)"];
378 } else if ([enumKey isEqualToString:@"TrackInfo"]) {
379 [trackInfoButton setTitle:@"(None)"];
380 } else if ([enumKey isEqualToString:@"UpcomingSongs"]) {
381 [upcomingSongsButton setTitle:@"(None)"];
382 } else if ([enumKey isEqualToString:@"IncrementVolume"]) {
383 [volumeIncrementButton setTitle:@"(None)"];
384 } else if ([enumKey isEqualToString:@"DecrementVolume"]) {
385 [volumeDecrementButton setTitle:@"(None)"];
386 } else if ([enumKey isEqualToString:@"IncrementRating"]) {
387 [ratingIncrementButton setTitle:@"(None)"];
388 } else if ([enumKey isEqualToString:@"DecrementRating"]) {
389 [ratingDecrementButton setTitle:@"(None)"];
390 } else if ([enumKey isEqualToString:@"ToggleShuffle"]) {
391 [toggleShuffleButton setTitle:@"(None)"];
392 } else if ([enumKey isEqualToString:@"ToggleLoop"]) {
393 [toggleLoopButton setTitle:@"(None)"];
395 ITDebugLog(@"Saved hot key named %@.", enumKey);
396 [df setObject:[[ITKeyCombo clearKeyCombo] plistRepresentation] forKey:enumKey];
397 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:enumKey];
401 [window setLevel:NSStatusWindowLevel];
406 ITDebugLog(@"Saved hot key named %@.", currentHotKey);
407 [hotKeysDictionary setObject:combo forKey:currentHotKey];
408 [df setObject:[combo plistRepresentation] forKey:currentHotKey];
410 ITDebugLog(@"Setting button name.");
411 if ([currentHotKey isEqualToString:@"PlayPause"]) {
412 [playPauseButton setTitle:string];
413 } else if ([currentHotKey isEqualToString:@"NextTrack"]) {
414 [nextTrackButton setTitle:string];
415 } else if ([currentHotKey isEqualToString:@"PrevTrack"]) {
416 [previousTrackButton setTitle:string];
417 } else if ([currentHotKey isEqualToString:@"ShowPlayer"]) {
418 [showPlayerButton setTitle:string];
419 } else if ([currentHotKey isEqualToString:@"TrackInfo"]) {
420 [trackInfoButton setTitle:string];
421 } else if ([currentHotKey isEqualToString:@"UpcomingSongs"]) {
422 [upcomingSongsButton setTitle:string];
423 } else if ([currentHotKey isEqualToString:@"IncrementVolume"]) {
424 [volumeIncrementButton setTitle:string];
425 } else if ([currentHotKey isEqualToString:@"DecrementVolume"]) {
426 [volumeDecrementButton setTitle:string];
427 } else if ([currentHotKey isEqualToString:@"IncrementRating"]) {
428 [ratingIncrementButton setTitle:string];
429 } else if ([currentHotKey isEqualToString:@"DecrementRating"]) {
430 [ratingDecrementButton setTitle:string];
431 } else if ([currentHotKey isEqualToString:@"ToggleShuffle"]) {
432 [toggleShuffleButton setTitle:string];
433 } else if ([currentHotKey isEqualToString:@"ToggleLoop"]) {
434 [toggleLoopButton setTitle:string];
436 [controller setupHotKeys];
437 [self cancelHotKey:sender];
440 - (void)deletePressedInTableView:(NSTableView *)tableView
442 if (tableView == menuTableView) {
443 int selRow = [tableView selectedRow];
444 ITDebugLog(@"Delete pressed in menu table view.");
446 NSString *object = [myItems objectAtIndex:selRow];
448 if ([object isEqualToString:@"preferences"]) {
453 if (![object isEqualToString:@"separator"])
454 [availableItems addObject:object];
455 ITDebugLog(@"Removing object named %@", object);
456 [myItems removeObjectAtIndex:selRow];
457 [menuTableView reloadData];
458 [allTableView reloadData];
460 [self changeMenus:self];
465 /*************************************************************************/
467 #pragma mark HOTKEY SUPPORT METHODS
468 /*************************************************************************/
470 - (void)setCurrentHotKey:(NSString *)key
472 ITDebugLog(@"Setting current hot key to %@", key);
473 [currentHotKey autorelease];
474 currentHotKey = [key copy];
475 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyEvent:) name:ITKeyBroadcasterKeyEvent object:nil];
476 [NSApp beginSheet:keyComboPanel modalForWindow:window modalDelegate:self didEndSelector:nil contextInfo:nil];
479 - (void)keyEvent:(NSNotification *)note
481 [self setKeyCombo:[[[note userInfo] objectForKey:@"keyCombo"] copy]];
484 - (void)setKeyCombo:(ITKeyCombo *)newCombo
488 combo = [newCombo copy];
489 ITDebugLog(@"Setting key combo to %@", newCombo);
490 string = [combo description];
494 [keyComboField setStringValue:string];
498 /*************************************************************************/
500 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
501 /*************************************************************************/
505 ITDebugLog(@"Loading Preferences.nib.");
506 if (![NSBundle loadNibNamed:@"Preferences" owner:self]) {
507 ITDebugLog(@"Failed to load Preferences.nib.");
513 - (void)setupCustomizationTables
515 NSImageCell *imgCell = [[[NSImageCell alloc] initImageCell:nil] autorelease];
516 ITDebugLog(@"Setting up table views.");
517 // Set the table view cells up
518 [imgCell setImageScaling:NSScaleNone];
519 [[menuTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
520 [[allTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
522 // Register for drag and drop
523 [menuTableView registerForDraggedTypes:[NSArray arrayWithObjects:
524 @"MenuTableViewPboardType",
525 @"AllTableViewPboardType",
527 [allTableView registerForDraggedTypes:[NSArray arrayWithObjects:
528 @"MenuTableViewPboardType",
529 @"AllTableViewPboardType",
533 - (void)setupMenuItems
535 NSEnumerator *itemEnum;
537 ITDebugLog(@"Setting up table view arrays.");
538 // Set the list of items you can have.
539 availableItems = [[NSMutableArray alloc] initWithObjects:
555 // Get our preferred menu
556 myItems = [[df arrayForKey:@"menu"] mutableCopy];
558 // Delete items in the availableItems array that are already part of the menu
559 itemEnum = [myItems objectEnumerator];
560 while ( (anItem = [itemEnum nextObject]) ) {
561 if (![anItem isEqualToString:@"separator"]) {
562 [availableItems removeObject:anItem];
566 // Items that show should a submenu image
567 submenuItems = [[NSArray alloc] initWithObjects:
577 NSMutableDictionary *loginwindow;
578 NSMutableArray *loginarray;
579 NSEnumerator *loginEnum;
581 ITDebugLog(@"Setting up preferences UI.");
582 // Fill in the number of songs in advance to show field
583 [songsInAdvance setIntValue:[df integerForKey:@"SongsInAdvance"]];
585 // Fill in hot key buttons
586 if ([df objectForKey:@"PlayPause"]) {
587 ITDebugLog(@"Setting up \"PlayPause\" hot key.");
588 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PlayPause"]];
589 [hotKeysDictionary setObject:anItem forKey:@"PlayPause"];
590 [playPauseButton setTitle:[anItem description]];
592 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"PlayPause"];
593 [playPauseButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
596 if ([df objectForKey:@"NextTrack"]) {
597 ITDebugLog(@"Setting up \"NextTrack\" hot key.");
598 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"NextTrack"]];
599 [hotKeysDictionary setObject:anItem forKey:@"NextTrack"];
600 [nextTrackButton setTitle:[anItem description]];
602 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"NextTrack"];
603 [nextTrackButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
606 if ([df objectForKey:@"PrevTrack"]) {
607 ITDebugLog(@"Setting up \"PrevTrack\" hot key.");
608 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PrevTrack"]];
609 [hotKeysDictionary setObject:anItem forKey:@"PrevTrack"];
610 [previousTrackButton setTitle:[anItem description]];
612 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"PrevTrack"];
613 [previousTrackButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
616 if ([df objectForKey:@"ShowPlayer"]) {
617 ITDebugLog(@"Setting up \"ShowPlayer\" hot key.");
618 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]];
619 [hotKeysDictionary setObject:anItem forKey:@"ShowPlayer"];
620 [showPlayerButton setTitle:[anItem description]];
622 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"ShowPlayer"];
623 [showPlayerButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
626 if ([df objectForKey:@"TrackInfo"]) {
627 ITDebugLog(@"Setting up \"TrackInfo\" hot key.");
628 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"TrackInfo"]];
629 [hotKeysDictionary setObject:anItem forKey:@"TrackInfo"];
630 [trackInfoButton setTitle:[anItem description]];
632 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"TrackInfo"];
633 [trackInfoButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
636 if ([df objectForKey:@"UpcomingSongs"]) {
637 ITDebugLog(@"Setting up \"UpcomingSongs\" hot key.");
638 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"UpcomingSongs"]];
639 [hotKeysDictionary setObject:anItem forKey:@"UpcomingSongs"];
640 [upcomingSongsButton setTitle:[anItem description]];
642 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"UpcomingSongs"];
643 [upcomingSongsButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
646 if ([df objectForKey:@"IncrementVolume"]) {
647 ITDebugLog(@"Setting up \"IncrementVolume\" hot key.");
648 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementVolume"]];
649 [hotKeysDictionary setObject:anItem forKey:@"IncrementVolume"];
650 [volumeIncrementButton setTitle:[anItem description]];
652 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"IncrementVolume"];
653 [volumeIncrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
656 if ([df objectForKey:@"DecrementVolume"]) {
657 ITDebugLog(@"Setting up \"DecrementVolume\" hot key.");
658 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementVolume"]];
659 [hotKeysDictionary setObject:anItem forKey:@"DecrementVolume"];
660 [volumeDecrementButton setTitle:[anItem description]];
662 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"DecrementVolume"];
663 [volumeDecrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
666 if ([df objectForKey:@"IncrementRating"]) {
667 ITDebugLog(@"Setting up \"IncrementRating\" hot key.");
668 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementRating"]];
669 [hotKeysDictionary setObject:anItem forKey:@"IncrementRating"];
670 [ratingIncrementButton setTitle:[anItem description]];
672 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"IncrementRating"];
673 [ratingIncrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
676 if ([df objectForKey:@"DecrementRating"]) {
677 ITDebugLog(@"Setting up \"DecrementRating\" hot key.");
678 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementRating"]];
679 [hotKeysDictionary setObject:anItem forKey:@"DecrementRating"];
680 [ratingDecrementButton setTitle:[anItem description]];
682 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"DecrementRating"];
683 [ratingDecrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
686 if ([df objectForKey:@"ToggleLoop"]) {
687 ITDebugLog(@"Setting up \"ToggleLoop\" hot key.");
688 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleLoop"]];
689 [hotKeysDictionary setObject:anItem forKey:@"ToggleLoop"];
690 [toggleLoopButton setTitle:[anItem description]];
692 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"ToggleLoop"];
693 [toggleLoopButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
696 if ([df objectForKey:@"ToggleShuffle"]) {
697 ITDebugLog(@"Setting up \"ToggleShuffle\" hot key.");
698 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleShuffle"]];
699 [hotKeysDictionary setObject:anItem forKey:@"ToggleShuffle"];
700 [toggleShuffleButton setTitle:[anItem description]];
702 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"ToggleShuffle"];
703 [toggleShuffleButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
706 ITDebugLog(@"Setting up track info checkboxes.");
707 // Check current track info buttons
708 [albumCheckbox setState:[df boolForKey:@"showAlbum"] ? NSOnState : NSOffState];
709 [nameCheckbox setState:NSOnState]; // Song info will ALWAYS show song title.
710 [nameCheckbox setEnabled:NO]; // Song info will ALWAYS show song title.
711 [artistCheckbox setState:[df boolForKey:@"showArtist"] ? NSOnState : NSOffState];
712 [trackTimeCheckbox setState:[df boolForKey:@"showTime"] ? NSOnState : NSOffState];
713 [trackNumberCheckbox setState:[df boolForKey:@"showTrackNumber"] ? NSOnState : NSOffState];
714 [ratingCheckbox setState:[df boolForKey:@"showTrackRating"] ? NSOnState : NSOffState];
716 // Set the launch at login checkbox state
717 ITDebugLog(@"Setting launch at login state.");
719 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
720 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
722 loginEnum = [loginarray objectEnumerator];
723 while ( (anItem = [loginEnum nextObject]) ) {
724 if ([[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
725 [launchAtLoginCheckbox setState:NSOnState];
729 // Setup the positioning controls
731 // Setup effects controls
732 [appearanceEffectPopup selectItem:[appearanceEffectPopup itemAtIndex:[appearanceEffectPopup indexOfItemWithTag:[df integerForKey:@"statusWindowAppearanceEffect"]]]];
733 [vanishEffectPopup selectItem:[vanishEffectPopup itemAtIndex:[vanishEffectPopup indexOfItemWithTag:[df integerForKey:@"statusWindowVanishEffect"]]]];
734 [appearanceSpeedSlider setFloatValue:-([df floatForKey:@"statusWindowAppearanceSpeed"])];
735 [vanishSpeedSlider setFloatValue:-([df floatForKey:@"statusWindowVanishSpeed"])];
736 [vanishDelaySlider setFloatValue:[df floatForKey:@"statusWindowVanishDelay"]];
737 [showOnChangeCheckbox setState:([df boolForKey:@"showSongInfoOnChange"] ? NSOnState : NSOffState)];
740 - (IBAction)changeMenus:(id)sender
742 ITDebugLog(@"Synchronizing menus");
743 [df setObject:myItems forKey:@"menu"];
747 - (void)setLaunchesAtLogin:(BOOL)flag
749 NSMutableDictionary *loginwindow;
750 NSMutableArray *loginarray;
751 ITDebugLog(@"Setting launches at login: %i", flag);
753 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
754 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
757 NSDictionary *itemDict = [NSDictionary dictionaryWithObjectsAndKeys:
758 [[NSBundle mainBundle] bundlePath], @"Path",
759 [NSNumber numberWithInt:0], @"Hide", nil];
760 [loginarray addObject:itemDict];
763 for (i = 0; i < [loginarray count]; i++) {
764 NSDictionary *tempDict = [loginarray objectAtIndex:i];
765 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
766 [loginarray removeObjectAtIndex:i];
771 [df setPersistentDomain:loginwindow forName:@"loginwindow"];
773 [loginwindow release];
774 ITDebugLog(@"Finished setting launches at login.");
778 /*************************************************************************/
780 #pragma mark NSWindow DELEGATE METHODS
781 /*************************************************************************/
783 - (void)windowWillClose:(NSNotification *)note
785 [(MainController *)controller closePreferences];
789 /*************************************************************************/
791 #pragma mark NSTableView DATASOURCE METHODS
792 /*************************************************************************/
794 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
796 if (aTableView == menuTableView) {
797 return [myItems count];
799 return [availableItems count];
803 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
805 if (aTableView == menuTableView) {
806 NSString *object = [myItems objectAtIndex:rowIndex];
807 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
808 if ([object isEqualToString:@"showPlayer"]) {
809 return [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), [[controller currentRemote] playerSimpleName]];
811 return NSLocalizedString(object, @"ERROR");
813 if ([submenuItems containsObject:object])
815 return [NSImage imageNamed:@"submenu"];
821 NSString *object = [availableItems objectAtIndex:rowIndex];
822 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
823 if ([object isEqualToString:@"showPlayer"]) {
824 return [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), [[controller currentRemote] playerSimpleName]];
826 return NSLocalizedString(object, @"ERROR");
828 if ([submenuItems containsObject:object]) {
829 return [NSImage imageNamed:@"submenu"];
837 - (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard
839 if (tableView == menuTableView) {
840 [pboard declareTypes:[NSArray arrayWithObjects:@"MenuTableViewPboardType", nil] owner:self];
841 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"MenuTableViewPboardType"];
845 if (tableView == allTableView) {
846 [pboard declareTypes:[NSArray arrayWithObjects:@"AllTableViewPboardType", nil] owner:self];
847 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"AllTableViewPboardType"];
853 - (BOOL)tableView:(NSTableView*)tableView acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)operation
857 NSString *dragData, *temp;
859 pb = [info draggingPasteboard];
861 if ([[pb types] containsObject:@"MenuTableViewPboardType"]) {
862 dragData = [pb stringForType:@"MenuTableViewPboardType"];
863 dragRow = [dragData intValue];
864 temp = [myItems objectAtIndex:dragRow];
866 if (tableView == menuTableView) {
867 [myItems insertObject:temp atIndex:row];
869 [myItems removeObjectAtIndex:dragRow];
871 [myItems removeObjectAtIndex:dragRow + 1];
874 if (![temp isEqualToString:@"separator"]) {
875 [availableItems addObject:temp];
877 [myItems removeObjectAtIndex:dragRow];
879 } else if ([[pb types] containsObject:@"AllTableViewPboardType"]) {
880 dragData = [pb stringForType:@"AllTableViewPboardType"];
881 dragRow = [dragData intValue];
882 temp = [availableItems objectAtIndex:dragRow];
884 [myItems insertObject:temp atIndex:row];
886 if (![temp isEqualToString:@"separator"]) {
887 [availableItems removeObjectAtIndex:dragRow];
891 [menuTableView reloadData];
892 [allTableView reloadData];
893 [self changeMenus:self];
897 - (NSDragOperation)tableView:(NSTableView*)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)operation
899 if (tableView == allTableView) {
900 if ([[[info draggingPasteboard] types] containsObject:@"AllTableViewPboardType"]) {
901 return NSDragOperationNone;
904 if ([[[info draggingPasteboard] types] containsObject:@"MenuTableViewPboardType"]) {
905 NSString *item = [myItems objectAtIndex:[[[info draggingPasteboard] stringForType:@"MenuTableViewPboardType"] intValue]];
906 if ([item isEqualToString:@"preferences"] || [item isEqualToString:@"quit"]) {
907 return NSDragOperationNone;
911 [tableView setDropRow:-1 dropOperation:NSTableViewDropOn];
912 return NSDragOperationGeneric;
915 if (operation == NSTableViewDropOn || row == -1)
917 return NSDragOperationNone;
920 return NSDragOperationGeneric;
924 /*************************************************************************/
926 #pragma mark DEALLOCATION METHODS
927 /*************************************************************************/
931 [self setKeyCombo:nil];
932 [hotKeysDictionary release];
933 [keyComboPanel release];
934 [menuTableView setDataSource:nil];
935 [allTableView setDataSource:nil];
936 [controller release];
937 [availableItems release];
938 [submenuItems release];