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:
291 nil] forKey:@"menu"];
293 [df setInteger:5 forKey:@"SongsInAdvance"];
294 // [df setBool:YES forKey:@"showName"]; // Song info will always show song title.
295 [df setBool:YES forKey:@"showArtist"];
296 [df setBool:NO forKey:@"showAlbum"];
297 [df setBool:NO forKey:@"showTime"];
301 loginWindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
302 loginArray = [loginWindow objectForKey:@"AutoLaunchedApplicationDictionary"];
303 loginEnum = [loginArray objectEnumerator];
305 while ( (anItem = [loginEnum nextObject]) ) {
306 if ( [[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]] ) {
310 [loginWindow release];
313 [[StatusWindowController sharedController] showSetupQueryWindow];
319 [[StatusWindow sharedWindow] setLocked:NO];
320 [[StatusWindow sharedWindow] vanish:self];
321 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
323 [self setLaunchesAtLogin:YES];
326 - (void)autoLaunchCancel
328 [[StatusWindow sharedWindow] setLocked:NO];
329 [[StatusWindow sharedWindow] vanish:self];
330 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
333 - (IBAction)cancelHotKey:(id)sender
335 ITDebugLog(@"Hot key canceled.");
336 [[NSNotificationCenter defaultCenter] removeObserver:self];
337 [NSApp endSheet:keyComboPanel];
338 [keyComboPanel orderOut:nil];
341 - (IBAction)clearHotKey:(id)sender
343 ITDebugLog(@"Hot key cleared.");
344 [self setKeyCombo:[ITKeyCombo clearKeyCombo]];
347 - (IBAction)okHotKey:(id)sender
349 NSString *string = [combo description];
350 NSEnumerator *enumerator = [hotKeysDictionary keyEnumerator];
353 ITDebugLog(@"Hot key ok'd, saving.");
359 ITDebugLog(@"Checking for duplicate hot keys.");
360 while ( (enumKey = [enumerator nextObject]) ) {
361 if (![enumKey isEqualToString:currentHotKey]) {
362 if (![combo isEqual:[ITKeyCombo clearKeyCombo]] &&
363 [combo isEqual:[hotKeysDictionary objectForKey:enumKey]]) {
364 [window setLevel:NSNormalWindowLevel];
365 ITDebugLog(@"Duplicate hot key found: %@", enumKey);
366 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) ) {
367 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:currentHotKey];
368 if ([enumKey isEqualToString:@"PlayPause"]) {
369 [playPauseButton setTitle:@"(None)"];
370 } else if ([enumKey isEqualToString:@"NextTrack"]) {
371 [nextTrackButton setTitle:@"(None)"];
372 } else if ([enumKey isEqualToString:@"PrevTrack"]) {
373 [previousTrackButton setTitle:@"(None)"];
374 } else if ([enumKey isEqualToString:@"ShowPlayer"]) {
375 [showPlayerButton setTitle:@"(None)"];
376 } else if ([enumKey isEqualToString:@"TrackInfo"]) {
377 [trackInfoButton setTitle:@"(None)"];
378 } else if ([enumKey isEqualToString:@"UpcomingSongs"]) {
379 [upcomingSongsButton setTitle:@"(None)"];
380 } else if ([enumKey isEqualToString:@"IncrementVolume"]) {
381 [volumeIncrementButton setTitle:@"(None)"];
382 } else if ([enumKey isEqualToString:@"DecrementVolume"]) {
383 [volumeDecrementButton setTitle:@"(None)"];
384 } else if ([enumKey isEqualToString:@"IncrementRating"]) {
385 [ratingIncrementButton setTitle:@"(None)"];
386 } else if ([enumKey isEqualToString:@"DecrementRating"]) {
387 [ratingDecrementButton setTitle:@"(None)"];
388 } else if ([enumKey isEqualToString:@"ToggleShuffle"]) {
389 [toggleShuffleButton setTitle:@"(None)"];
390 } else if ([enumKey isEqualToString:@"ToggleLoop"]) {
391 [toggleLoopButton setTitle:@"(None)"];
393 ITDebugLog(@"Saved hot key named %@.", enumKey);
394 [df setObject:[[ITKeyCombo clearKeyCombo] plistRepresentation] forKey:enumKey];
395 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:enumKey];
399 [window setLevel:NSStatusWindowLevel];
404 ITDebugLog(@"Saved hot key named %@.", currentHotKey);
405 [hotKeysDictionary setObject:combo forKey:currentHotKey];
406 [df setObject:[combo plistRepresentation] forKey:currentHotKey];
408 ITDebugLog(@"Setting button name.");
409 if ([currentHotKey isEqualToString:@"PlayPause"]) {
410 [playPauseButton setTitle:string];
411 } else if ([currentHotKey isEqualToString:@"NextTrack"]) {
412 [nextTrackButton setTitle:string];
413 } else if ([currentHotKey isEqualToString:@"PrevTrack"]) {
414 [previousTrackButton setTitle:string];
415 } else if ([currentHotKey isEqualToString:@"ShowPlayer"]) {
416 [showPlayerButton setTitle:string];
417 } else if ([currentHotKey isEqualToString:@"TrackInfo"]) {
418 [trackInfoButton setTitle:string];
419 } else if ([currentHotKey isEqualToString:@"UpcomingSongs"]) {
420 [upcomingSongsButton setTitle:string];
421 } else if ([currentHotKey isEqualToString:@"IncrementVolume"]) {
422 [volumeIncrementButton setTitle:string];
423 } else if ([currentHotKey isEqualToString:@"DecrementVolume"]) {
424 [volumeDecrementButton setTitle:string];
425 } else if ([currentHotKey isEqualToString:@"IncrementRating"]) {
426 [ratingIncrementButton setTitle:string];
427 } else if ([currentHotKey isEqualToString:@"DecrementRating"]) {
428 [ratingDecrementButton setTitle:string];
429 } else if ([currentHotKey isEqualToString:@"ToggleShuffle"]) {
430 [toggleShuffleButton setTitle:string];
431 } else if ([currentHotKey isEqualToString:@"ToggleLoop"]) {
432 [toggleLoopButton setTitle:string];
434 [controller setupHotKeys];
435 [self cancelHotKey:sender];
438 - (void)deletePressedInTableView:(NSTableView *)tableView
440 if (tableView == menuTableView) {
441 int selRow = [tableView selectedRow];
442 ITDebugLog(@"Delete pressed in menu table view.");
444 NSString *object = [myItems objectAtIndex:selRow];
446 if ([object isEqualToString:@"preferences"]) {
451 if (![object isEqualToString:@"separator"])
452 [availableItems addObject:object];
453 ITDebugLog(@"Removing object named %@", object);
454 [myItems removeObjectAtIndex:selRow];
455 [menuTableView reloadData];
456 [allTableView reloadData];
458 [self changeMenus:self];
463 /*************************************************************************/
465 #pragma mark HOTKEY SUPPORT METHODS
466 /*************************************************************************/
468 - (void)setCurrentHotKey:(NSString *)key
470 ITDebugLog(@"Setting current hot key to %@", key);
471 [currentHotKey autorelease];
472 currentHotKey = [key copy];
473 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyEvent:) name:ITKeyBroadcasterKeyEvent object:nil];
474 [NSApp beginSheet:keyComboPanel modalForWindow:window modalDelegate:self didEndSelector:nil contextInfo:nil];
477 - (void)keyEvent:(NSNotification *)note
479 [self setKeyCombo:[[[note userInfo] objectForKey:@"keyCombo"] copy]];
482 - (void)setKeyCombo:(ITKeyCombo *)newCombo
486 combo = [newCombo copy];
487 ITDebugLog(@"Setting key combo to %@", newCombo);
488 string = [combo description];
492 [keyComboField setStringValue:string];
496 /*************************************************************************/
498 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
499 /*************************************************************************/
503 ITDebugLog(@"Loading Preferences.nib.");
504 if (![NSBundle loadNibNamed:@"Preferences" owner:self]) {
505 ITDebugLog(@"Failed to load Preferences.nib.");
511 - (void)setupCustomizationTables
513 NSImageCell *imgCell = [[[NSImageCell alloc] initImageCell:nil] autorelease];
514 ITDebugLog(@"Setting up table views.");
515 // Set the table view cells up
516 [imgCell setImageScaling:NSScaleNone];
517 [[menuTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
518 [[allTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
520 // Register for drag and drop
521 [menuTableView registerForDraggedTypes:[NSArray arrayWithObjects:
522 @"MenuTableViewPboardType",
523 @"AllTableViewPboardType",
525 [allTableView registerForDraggedTypes:[NSArray arrayWithObjects:
526 @"MenuTableViewPboardType",
527 @"AllTableViewPboardType",
531 - (void)setupMenuItems
533 NSEnumerator *itemEnum;
535 ITDebugLog(@"Setting up table view arrays.");
536 // Set the list of items you can have.
537 availableItems = [[NSMutableArray alloc] initWithObjects:
553 // Get our preferred menu
554 myItems = [[df arrayForKey:@"menu"] mutableCopy];
556 // Delete items in the availableItems array that are already part of the menu
557 itemEnum = [myItems objectEnumerator];
558 while ( (anItem = [itemEnum nextObject]) ) {
559 if (![anItem isEqualToString:@"separator"]) {
560 [availableItems removeObject:anItem];
564 // Items that show should a submenu image
565 submenuItems = [[NSArray alloc] initWithObjects:
575 NSMutableDictionary *loginwindow;
576 NSMutableArray *loginarray;
577 NSEnumerator *loginEnum;
579 ITDebugLog(@"Setting up preferences UI.");
580 // Fill in the number of songs in advance to show field
581 [songsInAdvance setIntValue:[df integerForKey:@"SongsInAdvance"]];
583 // Fill in hot key buttons
584 if ([df objectForKey:@"PlayPause"]) {
585 ITDebugLog(@"Setting up \"PlayPause\" hot key.");
586 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PlayPause"]];
587 [hotKeysDictionary setObject:anItem forKey:@"PlayPause"];
588 [playPauseButton setTitle:[anItem description]];
590 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"PlayPause"];
591 [playPauseButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
594 if ([df objectForKey:@"NextTrack"]) {
595 ITDebugLog(@"Setting up \"NextTrack\" hot key.");
596 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"NextTrack"]];
597 [hotKeysDictionary setObject:anItem forKey:@"NextTrack"];
598 [nextTrackButton setTitle:[anItem description]];
600 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"NextTrack"];
601 [nextTrackButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
604 if ([df objectForKey:@"PrevTrack"]) {
605 ITDebugLog(@"Setting up \"PrevTrack\" hot key.");
606 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PrevTrack"]];
607 [hotKeysDictionary setObject:anItem forKey:@"PrevTrack"];
608 [previousTrackButton setTitle:[anItem description]];
610 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"PrevTrack"];
611 [previousTrackButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
614 if ([df objectForKey:@"ShowPlayer"]) {
615 ITDebugLog(@"Setting up \"ShowPlayer\" hot key.");
616 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]];
617 [hotKeysDictionary setObject:anItem forKey:@"ShowPlayer"];
618 [showPlayerButton setTitle:[anItem description]];
620 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"ShowPlayer"];
621 [showPlayerButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
624 if ([df objectForKey:@"TrackInfo"]) {
625 ITDebugLog(@"Setting up \"TrackInfo\" hot key.");
626 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"TrackInfo"]];
627 [hotKeysDictionary setObject:anItem forKey:@"TrackInfo"];
628 [trackInfoButton setTitle:[anItem description]];
630 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"TrackInfo"];
631 [trackInfoButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
634 if ([df objectForKey:@"UpcomingSongs"]) {
635 ITDebugLog(@"Setting up \"UpcomingSongs\" hot key.");
636 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"UpcomingSongs"]];
637 [hotKeysDictionary setObject:anItem forKey:@"UpcomingSongs"];
638 [upcomingSongsButton setTitle:[anItem description]];
640 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"UpcomingSongs"];
641 [upcomingSongsButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
644 if ([df objectForKey:@"IncrementVolume"]) {
645 ITDebugLog(@"Setting up \"IncrementVolume\" hot key.");
646 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementVolume"]];
647 [hotKeysDictionary setObject:anItem forKey:@"IncrementVolume"];
648 [volumeIncrementButton setTitle:[anItem description]];
650 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"IncrementVolume"];
651 [volumeIncrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
654 if ([df objectForKey:@"DecrementVolume"]) {
655 ITDebugLog(@"Setting up \"DecrementVolume\" hot key.");
656 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementVolume"]];
657 [hotKeysDictionary setObject:anItem forKey:@"DecrementVolume"];
658 [volumeDecrementButton setTitle:[anItem description]];
660 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"DecrementVolume"];
661 [volumeDecrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
664 if ([df objectForKey:@"IncrementRating"]) {
665 ITDebugLog(@"Setting up \"IncrementRating\" hot key.");
666 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementRating"]];
667 [hotKeysDictionary setObject:anItem forKey:@"IncrementRating"];
668 [ratingIncrementButton setTitle:[anItem description]];
670 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"IncrementRating"];
671 [ratingIncrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
674 if ([df objectForKey:@"DecrementRating"]) {
675 ITDebugLog(@"Setting up \"DecrementRating\" hot key.");
676 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementRating"]];
677 [hotKeysDictionary setObject:anItem forKey:@"DecrementRating"];
678 [ratingDecrementButton setTitle:[anItem description]];
680 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"DecrementRating"];
681 [ratingDecrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
684 if ([df objectForKey:@"ToggleLoop"]) {
685 ITDebugLog(@"Setting up \"ToggleLoop\" hot key.");
686 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleLoop"]];
687 [hotKeysDictionary setObject:anItem forKey:@"ToggleLoop"];
688 [toggleLoopButton setTitle:[anItem description]];
690 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"ToggleLoop"];
691 [toggleLoopButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
694 if ([df objectForKey:@"ToggleShuffle"]) {
695 ITDebugLog(@"Setting up \"ToggleShuffle\" hot key.");
696 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleShuffle"]];
697 [hotKeysDictionary setObject:anItem forKey:@"ToggleShuffle"];
698 [toggleShuffleButton setTitle:[anItem description]];
700 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"ToggleShuffle"];
701 [toggleShuffleButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
704 ITDebugLog(@"Setting up track info checkboxes.");
705 // Check current track info buttons
706 [albumCheckbox setState:[df boolForKey:@"showAlbum"] ? NSOnState : NSOffState];
707 [nameCheckbox setState:NSOnState]; // Song info will ALWAYS show song title.
708 [nameCheckbox setEnabled:NO]; // Song info will ALWAYS show song title.
709 [artistCheckbox setState:[df boolForKey:@"showArtist"] ? NSOnState : NSOffState];
710 [trackTimeCheckbox setState:[df boolForKey:@"showTime"] ? NSOnState : NSOffState];
711 [trackNumberCheckbox setState:[df boolForKey:@"showTrackNumber"] ? NSOnState : NSOffState];
712 [ratingCheckbox setState:[df boolForKey:@"showTrackRating"] ? NSOnState : NSOffState];
714 // Set the launch at login checkbox state
715 ITDebugLog(@"Setting launch at login state.");
717 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
718 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
720 loginEnum = [loginarray objectEnumerator];
721 while ( (anItem = [loginEnum nextObject]) ) {
722 if ([[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
723 [launchAtLoginCheckbox setState:NSOnState];
728 - (IBAction)changeMenus:(id)sender
730 ITDebugLog(@"Synchronizing menus");
731 [df setObject:myItems forKey:@"menu"];
735 - (void)setLaunchesAtLogin:(BOOL)flag
737 NSMutableDictionary *loginwindow;
738 NSMutableArray *loginarray;
739 ITDebugLog(@"Setting launches at login: %i", flag);
741 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
742 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
745 NSDictionary *itemDict = [NSDictionary dictionaryWithObjectsAndKeys:
746 [[NSBundle mainBundle] bundlePath], @"Path",
747 [NSNumber numberWithInt:0], @"Hide", nil];
748 [loginarray addObject:itemDict];
751 for (i = 0; i < [loginarray count]; i++) {
752 NSDictionary *tempDict = [loginarray objectAtIndex:i];
753 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
754 [loginarray removeObjectAtIndex:i];
759 [df setPersistentDomain:loginwindow forName:@"loginwindow"];
761 [loginwindow release];
762 ITDebugLog(@"Finished setting launches at login.");
766 /*************************************************************************/
768 #pragma mark NSWindow DELEGATE METHODS
769 /*************************************************************************/
771 - (void)windowWillClose:(NSNotification *)note
773 [(MainController *)controller closePreferences];
777 /*************************************************************************/
779 #pragma mark NSTableView DATASOURCE METHODS
780 /*************************************************************************/
782 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
784 if (aTableView == menuTableView) {
785 return [myItems count];
787 return [availableItems count];
791 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
793 if (aTableView == menuTableView) {
794 NSString *object = [myItems objectAtIndex:rowIndex];
795 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
796 if ([object isEqualToString:@"showPlayer"]) {
797 return [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), [[controller currentRemote] playerSimpleName]];
799 return NSLocalizedString(object, @"ERROR");
801 if ([submenuItems containsObject:object])
803 return [NSImage imageNamed:@"submenu"];
809 NSString *object = [availableItems objectAtIndex:rowIndex];
810 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
811 if ([object isEqualToString:@"showPlayer"]) {
812 return [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), [[controller currentRemote] playerSimpleName]];
814 return NSLocalizedString(object, @"ERROR");
816 if ([submenuItems containsObject:object]) {
817 return [NSImage imageNamed:@"submenu"];
825 - (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard
827 if (tableView == menuTableView) {
828 [pboard declareTypes:[NSArray arrayWithObjects:@"MenuTableViewPboardType", nil] owner:self];
829 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"MenuTableViewPboardType"];
833 if (tableView == allTableView) {
834 [pboard declareTypes:[NSArray arrayWithObjects:@"AllTableViewPboardType", nil] owner:self];
835 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"AllTableViewPboardType"];
841 - (BOOL)tableView:(NSTableView*)tableView acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)operation
845 NSString *dragData, *temp;
847 pb = [info draggingPasteboard];
849 if ([[pb types] containsObject:@"MenuTableViewPboardType"]) {
850 dragData = [pb stringForType:@"MenuTableViewPboardType"];
851 dragRow = [dragData intValue];
852 temp = [myItems objectAtIndex:dragRow];
854 if (tableView == menuTableView) {
855 [myItems insertObject:temp atIndex:row];
857 [myItems removeObjectAtIndex:dragRow];
859 [myItems removeObjectAtIndex:dragRow + 1];
862 if (![temp isEqualToString:@"separator"]) {
863 [availableItems addObject:temp];
865 [myItems removeObjectAtIndex:dragRow];
867 } else if ([[pb types] containsObject:@"AllTableViewPboardType"]) {
868 dragData = [pb stringForType:@"AllTableViewPboardType"];
869 dragRow = [dragData intValue];
870 temp = [availableItems objectAtIndex:dragRow];
872 [myItems insertObject:temp atIndex:row];
874 if (![temp isEqualToString:@"separator"]) {
875 [availableItems removeObjectAtIndex:dragRow];
879 [menuTableView reloadData];
880 [allTableView reloadData];
881 [self changeMenus:self];
885 - (NSDragOperation)tableView:(NSTableView*)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)operation
887 if (tableView == allTableView) {
888 if ([[[info draggingPasteboard] types] containsObject:@"AllTableViewPboardType"]) {
889 return NSDragOperationNone;
892 if ([[[info draggingPasteboard] types] containsObject:@"MenuTableViewPboardType"]) {
893 NSString *item = [myItems objectAtIndex:[[[info draggingPasteboard] stringForType:@"MenuTableViewPboardType"] intValue]];
894 if ([item isEqualToString:@"preferences"]) {
895 return NSDragOperationNone;
899 [tableView setDropRow:-1 dropOperation:NSTableViewDropOn];
900 return NSDragOperationGeneric;
903 if (operation == NSTableViewDropOn || row == -1)
905 return NSDragOperationNone;
908 return NSDragOperationGeneric;
912 /*************************************************************************/
914 #pragma mark DEALLOCATION METHODS
915 /*************************************************************************/
919 [self setKeyCombo:nil];
920 [hotKeysDictionary release];
921 [keyComboPanel release];
922 [menuTableView setDataSource:nil];
923 [allTableView setDataSource:nil];
924 [controller release];
925 [availableItems release];
926 [submenuItems release];