1 #import "PreferencesController.h"
2 #import "MainController.h"
3 #import <ITKit/ITHotKeyCenter.h>
4 #import <ITKit/ITKeyCombo.h>
5 #import <ITKit/ITWindowPositioning.h>
6 #import <ITKit/ITKeyBroadcaster.h>
8 #define SENDER_STATE (([sender state] == NSOnState) ? YES : NO)
10 /*************************************************************************/
12 #pragma mark PRIVATE INTERFACE
13 /*************************************************************************/
15 @interface PreferencesController (Private)
17 - (void)setupCustomizationTables;
18 - (void)setupMenuItems;
20 - (IBAction)changeMenus:(id)sender;
21 - (void)setLaunchesAtLogin:(BOOL)flag;
25 @implementation PreferencesController
28 /*************************************************************************/
30 #pragma mark STATIC VARIABLES
31 /*************************************************************************/
33 static PreferencesController *prefs = nil;
36 /*************************************************************************/
38 #pragma mark INITIALIZATION METHODS
39 /*************************************************************************/
41 + (PreferencesController *)sharedPrefs;
44 prefs = [[self alloc] init];
51 if ( (self = [super init]) ) {
52 df = [[NSUserDefaults standardUserDefaults] retain];
53 hotKeysDictionary = [[NSMutableDictionary alloc] init];
60 /*************************************************************************/
62 #pragma mark ACCESSOR METHODS
63 /*************************************************************************/
70 - (void)setController:(id)object
72 [controller autorelease];
73 controller = [object retain];
77 /*************************************************************************/
79 #pragma mark INSTANCE METHODS
80 /*************************************************************************/
82 - (IBAction)showPrefsWindow:(id)sender
84 if (! window) { // If window does not exist yet, then the nib hasn't been loaded.
85 [self setupWindow]; // Load in the nib, and perform any initial setup.
86 [self setupCustomizationTables]; // Setup the DnD manu config tables.
87 [self setupMenuItems]; // Setup the arrays of menu items
88 [self setupUI]; // Sets up additional UI
89 [window setDelegate:self];
90 [menuTableView reloadData];
92 //Change the launch player checkbox to the proper name
93 [launchPlayerAtLaunchCheckbox setTitle:[NSString stringWithFormat:@"Launch %@ when MenuTunes launches", [[controller currentRemote] playerSimpleName]]]; //This isn't localized...
96 [window setLevel:NSStatusWindowLevel];
98 [window makeKeyAndOrderFront:self];
99 [NSApp activateIgnoringOtherApps:YES];
102 - (IBAction)changeGeneralSetting:(id)sender
104 if ( [sender tag] == 1010) {
105 [self setLaunchesAtLogin:SENDER_STATE];
106 } else if ( [sender tag] == 1020) {
107 [df setBool:SENDER_STATE forKey:@"LaunchPlayerWithMT"];
108 } else if ( [sender tag] == 1030) {
109 [df setInteger:[sender intValue] forKey:@"SongsInAdvance"];
111 } else if ( [sender tag] == 1040) {
112 // This will not be executed. Song info always shows the title of the song.
113 // [df setBool:SENDER_STATE forKey:@"showName"];
114 } else if ( [sender tag] == 1050) {
115 [df setBool:SENDER_STATE forKey:@"showArtist"];
116 } else if ( [sender tag] == 1060) {
117 [df setBool:SENDER_STATE forKey:@"showAlbum"];
118 } else if ( [sender tag] == 1070) {
119 [df setBool:SENDER_STATE forKey:@"showTime"];
120 } else if ( [sender tag] == 1080) {
121 [df setBool:SENDER_STATE forKey:@"showTrackNumber"];
122 } else if ( [sender tag] == 1090) {
123 [df setBool:SENDER_STATE forKey:@"showTrackRating"];
128 - (IBAction)changeStatusWindowSetting:(id)sender
130 if ( [sender tag] == 2010) {
131 [df setInteger:[sender selectedRow] forKey:@"statusWindowVerticalPosition"];
132 [df setInteger:[sender selectedColumn] forKey:@"statusWindowHorizontalPosition"];
133 // update the window's position here
134 } else if ( [sender tag] == 2020) {
135 // update screen selection
136 } else if ( [sender tag] == 2030) {
137 // Update appearance effect
138 } else if ( [sender tag] == 2040) {
139 // Update Vanish Effect
140 } else if ( [sender tag] == 2050) {
141 // Update appearance speed
142 } else if ( [sender tag] == 2060) {
143 // Update vanish speed
144 } else if ( [sender tag] == 2070) {
145 // Update vanish delay
146 } else if ( [sender tag] == 2080) {
147 // Update "Song Info window when song changes" setting.
148 [df setBool:SENDER_STATE forKey:@"showSongInfoOnChange"];
152 - (IBAction)changeHotKey:(id)sender
154 [controller clearHotKeys];
155 switch ([sender tag])
158 [self setKeyCombo:[hotKeysDictionary objectForKey:@"PlayPause"]];
159 [self setCurrentHotKey:@"PlayPause"];
162 [self setKeyCombo:[hotKeysDictionary objectForKey:@"NextTrack"]];
163 [self setCurrentHotKey:@"NextTrack"];
166 [self setKeyCombo:[hotKeysDictionary objectForKey:@"PrevTrack"]];
167 [self setCurrentHotKey:@"PrevTrack"];
170 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ShowPlayer"]];
171 [self setCurrentHotKey:@"ShowPlayer"];
174 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleLoop"]];
175 [self setCurrentHotKey:@"ToggleLoop"];
178 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleShuffle"]];
179 [self setCurrentHotKey:@"ToggleShuffle"];
182 [self setKeyCombo:[hotKeysDictionary objectForKey:@"TrackInfo"]];
183 [self setCurrentHotKey:@"TrackInfo"];
186 [self setKeyCombo:[hotKeysDictionary objectForKey:@"UpcomingSongs"]];
187 [self setCurrentHotKey:@"UpcomingSongs"];
190 [self setKeyCombo:[hotKeysDictionary objectForKey:@"IncrementVolume"]];
191 [self setCurrentHotKey:@"IncrementVolume"];
194 [self setKeyCombo:[hotKeysDictionary objectForKey:@"DecrementVolume"]];
195 [self setCurrentHotKey:@"DecrementVolume"];
198 [self setKeyCombo:[hotKeysDictionary objectForKey:@"IncrementRating"]];
199 [self setCurrentHotKey:@"IncrementRating"];
202 [self setKeyCombo:[hotKeysDictionary objectForKey:@"DecrementRating"]];
203 [self setCurrentHotKey:@"DecrementRating"];
208 - (void)registerDefaults
211 NSMutableDictionary *loginWindow;
212 NSMutableArray *loginArray;
213 NSEnumerator *loginEnum;
216 [df setObject:[NSArray arrayWithObjects:
233 nil] forKey:@"menu"];
235 [df setInteger:5 forKey:@"SongsInAdvance"];
236 // [df setBool:YES forKey:@"showName"]; // Song info will always show song title.
237 [df setBool:YES forKey:@"showArtist"];
238 [df setBool:NO forKey:@"showAlbum"];
239 [df setBool:NO forKey:@"showTime"];
243 loginWindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
244 loginArray = [loginWindow objectForKey:@"AutoLaunchedApplicationDictionary"];
245 loginEnum = [loginArray objectEnumerator];
247 while ( (anItem = [loginEnum nextObject]) ) {
248 if ( [[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]] ) {
253 [loginWindow release];
256 // We must fix it so it is no longer suxy
258 if (NSRunInformationalAlertPanel(NSLocalizedString(@"autolaunch", @"Auto-launch MenuTunes"), NSLocalizedString(@"autolaunch_msg", @"Would you like MenuTunes to automatically launch at login?"), @"Yes", @"No", nil) == NSOKButton) {
259 AEDesc scriptDesc, resultDesc;
260 NSString *script = [NSString stringWithFormat:@"tell application \"System Events\"\nmake new login item at end of login items with properties {path:\"%@\", kind:\"APPLICATION\"}\nend tell", [[NSBundle mainBundle] bundlePath]];
261 ComponentInstance asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
263 AECreateDesc(typeChar, [script cString], [script cStringLength],
266 OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
268 AEDisposeDesc(&scriptDesc);
269 AEDisposeDesc(&resultDesc);
271 CloseComponent(asComponent);
276 - (IBAction)cancelHotKey:(id)sender
278 [[NSNotificationCenter defaultCenter] removeObserver:self];
279 [NSApp endSheet:keyComboPanel];
280 [keyComboPanel orderOut:nil];
283 - (IBAction)clearHotKey:(id)sender
285 [self setKeyCombo:[ITKeyCombo clearKeyCombo]];
288 - (IBAction)okHotKey:(id)sender
290 NSString *string = [combo description];
291 NSEnumerator *enumerator = [hotKeysDictionary keyEnumerator];
298 while ( (enumKey = [enumerator nextObject]) ) {
299 if (![enumKey isEqualToString:currentHotKey]) {
300 if (![combo isEqual:[ITKeyCombo clearKeyCombo]] &&
301 [combo isEqual:[hotKeysDictionary objectForKey:enumKey]]) {
302 [window setLevel:NSNormalWindowLevel];
303 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) ) {
304 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:currentHotKey];
305 if ([enumKey isEqualToString:@"PlayPause"]) {
306 [playPauseButton setTitle:@""];
307 } else if ([enumKey isEqualToString:@"NextTrack"]) {
308 [nextTrackButton setTitle:@""];
309 } else if ([enumKey isEqualToString:@"PrevTrack"]) {
310 [previousTrackButton setTitle:@""];
311 } else if ([enumKey isEqualToString:@"ShowPlayer"]) {
312 [showPlayerButton setTitle:@""];
313 } else if ([enumKey isEqualToString:@"TrackInfo"]) {
314 [trackInfoButton setTitle:@""];
315 } else if ([enumKey isEqualToString:@"UpcomingSongs"]) {
316 [upcomingSongsButton setTitle:@""];
317 } else if ([enumKey isEqualToString:@"IncrementVolume"]) {
318 [volumeIncrementButton setTitle:@""];
319 } else if ([enumKey isEqualToString:@"DecrementVolume"]) {
320 [volumeDecrementButton setTitle:@""];
321 } else if ([enumKey isEqualToString:@"IncrementRating"]) {
322 [ratingIncrementButton setTitle:@""];
323 } else if ([enumKey isEqualToString:@"DecrementRating"]) {
324 [ratingDecrementButton setTitle:@""];
325 } else if ([enumKey isEqualToString:@"ToggleShuffle"]) {
326 [toggleShuffleButton setTitle:@""];
327 } else if ([enumKey isEqualToString:@"ToggleLoop"]) {
328 [toggleLoopButton setTitle:@""];
330 [df setObject:[[ITKeyCombo clearKeyCombo] plistRepresentation] forKey:enumKey];
334 [window setLevel:NSStatusWindowLevel];
339 [hotKeysDictionary setObject:combo forKey:currentHotKey];
340 [df setObject:[combo plistRepresentation] forKey:currentHotKey];
342 if ([currentHotKey isEqualToString:@"PlayPause"]) {
343 [playPauseButton setTitle:string];
344 } else if ([currentHotKey isEqualToString:@"NextTrack"]) {
345 [nextTrackButton setTitle:string];
346 } else if ([currentHotKey isEqualToString:@"PrevTrack"]) {
347 [previousTrackButton setTitle:string];
348 } else if ([currentHotKey isEqualToString:@"ShowPlayer"]) {
349 [showPlayerButton setTitle:string];
350 } else if ([currentHotKey isEqualToString:@"TrackInfo"]) {
351 [trackInfoButton setTitle:string];
352 } else if ([currentHotKey isEqualToString:@"UpcomingSongs"]) {
353 [upcomingSongsButton setTitle:string];
354 } else if ([currentHotKey isEqualToString:@"IncrementVolume"]) {
355 [volumeIncrementButton setTitle:string];
356 } else if ([currentHotKey isEqualToString:@"DecrementVolume"]) {
357 [volumeDecrementButton setTitle:string];
358 } else if ([currentHotKey isEqualToString:@"IncrementRating"]) {
359 [ratingIncrementButton setTitle:string];
360 } else if ([currentHotKey isEqualToString:@"DecrementRating"]) {
361 [ratingDecrementButton setTitle:string];
362 } else if ([currentHotKey isEqualToString:@"ToggleShuffle"]) {
363 [toggleShuffleButton setTitle:string];
364 } else if ([currentHotKey isEqualToString:@"ToggleLoop"]) {
365 [toggleLoopButton setTitle:string];
367 [controller setupHotKeys];
368 [self cancelHotKey:sender];
373 /*************************************************************************/
375 #pragma mark HOTKEY SUPPORT METHODS
376 /*************************************************************************/
378 - (void)setCurrentHotKey:(NSString *)key
380 [currentHotKey autorelease];
381 currentHotKey = [key copy];
382 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyEvent:) name:ITKeyBroadcasterKeyEvent object:nil];
383 [NSApp beginSheet:keyComboPanel modalForWindow:window modalDelegate:self didEndSelector:nil contextInfo:nil];
386 - (void)keyEvent:(NSNotification *)note
388 [self setKeyCombo:[[[note userInfo] objectForKey:@"keyCombo"] copy]];
391 - (void)setKeyCombo:(ITKeyCombo *)newCombo
395 combo = [newCombo copy];
397 string = [combo description];
401 [keyComboField setStringValue:string];
405 /*************************************************************************/
407 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
408 /*************************************************************************/
412 if (![NSBundle loadNibNamed:@"Preferences" owner:self]) {
413 NSLog(@"MenuTunes: Failed to load Preferences.nib");
419 - (void)setupCustomizationTables
421 NSImageCell *imgCell = [[[NSImageCell alloc] initImageCell:nil] autorelease];
423 // Set the table view cells up
424 [imgCell setImageScaling:NSScaleNone];
425 [[menuTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
426 [[allTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
428 // Register for drag and drop
429 [menuTableView registerForDraggedTypes:[NSArray arrayWithObjects:
430 @"MenuTableViewPboardType",
431 @"AllTableViewPboardType",
433 [allTableView registerForDraggedTypes:[NSArray arrayWithObjects:
434 @"MenuTableViewPboardType",
435 @"AllTableViewPboardType",
439 - (void)setupMenuItems
441 NSEnumerator *itemEnum;
443 // Set the list of items you can have.
444 availableItems = [[NSMutableArray alloc] initWithObjects:
459 // Get our preferred menu
460 myItems = [[df arrayForKey:@"menu"] mutableCopy];
462 // Delete items in the availableItems array that are already part of the menu
463 itemEnum = [myItems objectEnumerator];
464 while ( (anItem = [itemEnum nextObject]) ) {
465 if (![anItem isEqualToString:@"separator"]) {
466 [availableItems removeObject:anItem];
470 // Items that show should a submenu image
471 submenuItems = [[NSArray alloc] initWithObjects:
481 NSMutableDictionary *loginwindow;
482 NSMutableArray *loginarray;
483 NSEnumerator *loginEnum;
486 // Fill in the number of songs in advance to show field
487 [songsInAdvance setIntValue:[df integerForKey:@"SongsInAdvance"]];
489 // Fill in hot key buttons
490 if ([df objectForKey:@"PlayPause"]) {
491 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PlayPause"]];
492 [hotKeysDictionary setObject:anItem forKey:@"PlayPause"];
493 [playPauseButton setTitle:[anItem description]];
495 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"PlayPause"];
496 [playPauseButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
499 if ([df objectForKey:@"NextTrack"]) {
500 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"NextTrack"]];
501 [hotKeysDictionary setObject:anItem forKey:@"NextTrack"];
502 [nextTrackButton setTitle:[anItem description]];
504 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"NextTrack"];
505 [nextTrackButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
508 if ([df objectForKey:@"PrevTrack"]) {
509 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PrevTrack"]];
510 [hotKeysDictionary setObject:anItem forKey:@"PrevTrack"];
511 [previousTrackButton setTitle:[anItem description]];
513 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"PrevTrack"];
514 [previousTrackButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
517 if ([df objectForKey:@"ShowPlayer"]) {
518 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]];
519 [hotKeysDictionary setObject:anItem forKey:@"ShowPlayer"];
520 [showPlayerButton setTitle:[anItem description]];
522 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"ShowPlayer"];
523 [showPlayerButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
526 if ([df objectForKey:@"TrackInfo"]) {
527 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"TrackInfo"]];
528 [hotKeysDictionary setObject:anItem forKey:@"TrackInfo"];
529 [trackInfoButton setTitle:[anItem description]];
531 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"TrackInfo"];
532 [trackInfoButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
535 if ([df objectForKey:@"UpcomingSongs"]) {
536 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"UpcomingSongs"]];
537 [hotKeysDictionary setObject:anItem forKey:@"UpcomingSongs"];
538 [upcomingSongsButton setTitle:[anItem description]];
540 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"UpcomingSongs"];
541 [upcomingSongsButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
544 if ([df objectForKey:@"IncrementVolume"]) {
545 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementVolume"]];
546 [hotKeysDictionary setObject:anItem forKey:@"IncrementVolume"];
547 [volumeIncrementButton setTitle:[anItem description]];
549 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"IncrementVolume"];
550 [volumeIncrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
553 if ([df objectForKey:@"DecrementVolume"]) {
554 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementVolume"]];
555 [hotKeysDictionary setObject:anItem forKey:@"DecrementVolume"];
556 [volumeDecrementButton setTitle:[anItem description]];
558 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"DecrementVolume"];
559 [volumeDecrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
562 if ([df objectForKey:@"IncrementRating"]) {
563 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementRating"]];
564 [hotKeysDictionary setObject:anItem forKey:@"IncrementRating"];
565 [ratingIncrementButton setTitle:[anItem description]];
567 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"IncrementRating"];
568 [ratingIncrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
571 if ([df objectForKey:@"DecrementRating"]) {
572 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementRating"]];
573 [hotKeysDictionary setObject:anItem forKey:@"DecrementRating"];
574 [ratingDecrementButton setTitle:[anItem description]];
576 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"DecrementRating"];
577 [ratingDecrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
580 if ([df objectForKey:@"ToggleLoop"]) {
581 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleLoop"]];
582 [hotKeysDictionary setObject:anItem forKey:@"ToggleLoop"];
583 [toggleLoopButton setTitle:[anItem description]];
585 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"ToggleLoop"];
586 [toggleLoopButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
589 if ([df objectForKey:@"ToggleShuffle"]) {
590 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleShuffle"]];
591 [hotKeysDictionary setObject:anItem forKey:@"ToggleShuffle"];
592 [toggleShuffleButton setTitle:[anItem description]];
594 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"ToggleShuffle"];
595 [toggleShuffleButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
598 // Check current track info buttons
599 [albumCheckbox setState:[df boolForKey:@"showAlbum"] ? NSOnState : NSOffState];
600 [nameCheckbox setState:NSOnState]; // Song info will ALWAYS show song title.
601 [nameCheckbox setEnabled:NO]; // Song info will ALWAYS show song title.
602 [artistCheckbox setState:[df boolForKey:@"showArtist"] ? NSOnState : NSOffState];
603 [trackTimeCheckbox setState:[df boolForKey:@"showTime"] ? NSOnState : NSOffState];
604 [trackNumberCheckbox setState:[df boolForKey:@"showTrackNumber"] ? NSOnState : NSOffState];
606 // Set the launch at login checkbox state
608 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
609 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
611 loginEnum = [loginarray objectEnumerator];
612 while ( (anItem = [loginEnum nextObject]) ) {
613 if ([[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
614 [launchAtLoginCheckbox setState:NSOnState];
619 - (IBAction)changeMenus:(id)sender
621 [df setObject:myItems forKey:@"menu"];
625 - (void)setLaunchesAtLogin:(BOOL)flag
628 NSMutableDictionary *loginwindow;
629 NSMutableArray *loginarray;
630 ComponentInstance temp = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
635 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
636 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
638 for (i = 0; i < [loginarray count]; i++) {
639 NSDictionary *tempDict = [loginarray objectAtIndex:i];
640 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
646 AEDesc scriptDesc, resultDesc;
647 NSString *script = [NSString stringWithFormat:@"tell application \"System Events\"\nmake new login item at end of login items with properties {path:\"%@\", kind:\"APPLICATION\"}\nend tell", [[NSBundle mainBundle] bundlePath]];
649 AECreateDesc(typeChar, [script cString], [script cStringLength],
652 OSADoScript(temp, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
654 AEDisposeDesc(&scriptDesc);
655 AEDisposeDesc(&resultDesc);
656 CloseComponent(temp);
660 NSMutableDictionary *loginwindow;
661 NSMutableArray *loginarray;
665 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
666 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
668 for (i = 0; i < [loginarray count]; i++) {
669 NSDictionary *tempDict = [loginarray objectAtIndex:i];
670 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
671 [loginarray removeObjectAtIndex:i];
672 [df setPersistentDomain:loginwindow forName:@"loginwindow"];
681 /*************************************************************************/
683 #pragma mark NSWindow DELEGATE METHODS
684 /*************************************************************************/
686 - (void)windowWillClose:(NSNotification *)note
688 [(MainController *)controller closePreferences];
692 /*************************************************************************/
694 #pragma mark NSTableView DATASOURCE METHODS
695 /*************************************************************************/
697 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
699 if (aTableView == menuTableView) {
700 return [myItems count];
702 return [availableItems count];
706 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
708 if (aTableView == menuTableView) {
709 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
710 NSString *object = [myItems objectAtIndex:rowIndex];
711 if ([object isEqualToString:@"Show Player"]) {
712 return [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), [[controller currentRemote] playerSimpleName]];
714 return NSLocalizedString(object, @"ERROR");
716 if ([submenuItems containsObject:[myItems objectAtIndex:rowIndex]])
718 return [NSImage imageNamed:@"submenu"];
724 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
725 return NSLocalizedString([availableItems objectAtIndex:rowIndex], @"ERROR");
727 if ([submenuItems containsObject:[availableItems objectAtIndex:rowIndex]]) {
728 return [NSImage imageNamed:@"submenu"];
736 - (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard
738 if (tableView == menuTableView) {
739 [pboard declareTypes:[NSArray arrayWithObjects:@"MenuTableViewPboardType", nil] owner:self];
740 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"MenuTableViewPboardType"];
744 if (tableView == allTableView) {
745 [pboard declareTypes:[NSArray arrayWithObjects:@"AllTableViewPboardType", nil] owner:self];
746 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"AllTableViewPboardType"];
752 - (BOOL)tableView:(NSTableView*)tableView acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)operation
756 NSString *dragData, *temp;
758 pb = [info draggingPasteboard];
760 if ([[pb types] containsObject:@"MenuTableViewPboardType"]) {
761 dragData = [pb stringForType:@"MenuTableViewPboardType"];
762 dragRow = [dragData intValue];
763 temp = [myItems objectAtIndex:dragRow];
765 if (tableView == menuTableView) {
766 [myItems insertObject:temp atIndex:row];
768 [myItems removeObjectAtIndex:dragRow];
770 [myItems removeObjectAtIndex:dragRow + 1];
773 if (![temp isEqualToString:@"separator"]) {
774 [availableItems addObject:temp];
776 [myItems removeObjectAtIndex:dragRow];
778 } else if ([[pb types] containsObject:@"AllTableViewPboardType"]) {
779 dragData = [pb stringForType:@"AllTableViewPboardType"];
780 dragRow = [dragData intValue];
781 temp = [availableItems objectAtIndex:dragRow];
783 [myItems insertObject:temp atIndex:row];
785 if (![temp isEqualToString:@"separator"]) {
786 [availableItems removeObjectAtIndex:dragRow];
790 [menuTableView reloadData];
791 [allTableView reloadData];
792 [self changeMenus:self];
796 - (NSDragOperation)tableView:(NSTableView*)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)operation
798 if (tableView == allTableView) {
799 if ([[[info draggingPasteboard] types] containsObject:@"AllTableViewPboardType"]) {
800 return NSDragOperationNone;
803 if ([[[info draggingPasteboard] types] containsObject:@"MenuTableViewPboardType"]) {
804 NSString *item = [myItems objectAtIndex:[[[info draggingPasteboard] stringForType:@"MenuTableViewPboardType"] intValue]];
805 if ([item isEqualToString:@"Preferences"] || [item isEqualToString:@"Quit"]) {
806 return NSDragOperationNone;
810 [tableView setDropRow:-1 dropOperation:NSTableViewDropOn];
811 return NSDragOperationGeneric;
814 if (operation == NSTableViewDropOn || row == -1)
816 return NSDragOperationNone;
819 return NSDragOperationGeneric;
823 /*************************************************************************/
825 #pragma mark DEALLOCATION METHODS
826 /*************************************************************************/
830 [self setKeyCombo:nil];
831 [hotKeysDictionary release];
832 [keyComboPanel release];
833 [menuTableView setDataSource:nil];
834 [allTableView setDataSource:nil];
835 [controller release];
836 [availableItems release];
837 [submenuItems release];