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:@"(None)"];
307 } else if ([enumKey isEqualToString:@"NextTrack"]) {
308 [nextTrackButton setTitle:@"(None)"];
309 } else if ([enumKey isEqualToString:@"PrevTrack"]) {
310 [previousTrackButton setTitle:@"(None)"];
311 } else if ([enumKey isEqualToString:@"ShowPlayer"]) {
312 [showPlayerButton setTitle:@"(None)"];
313 } else if ([enumKey isEqualToString:@"TrackInfo"]) {
314 [trackInfoButton setTitle:@"(None)"];
315 } else if ([enumKey isEqualToString:@"UpcomingSongs"]) {
316 [upcomingSongsButton setTitle:@"(None)"];
317 } else if ([enumKey isEqualToString:@"IncrementVolume"]) {
318 [volumeIncrementButton setTitle:@"(None)"];
319 } else if ([enumKey isEqualToString:@"DecrementVolume"]) {
320 [volumeDecrementButton setTitle:@"(None)"];
321 } else if ([enumKey isEqualToString:@"IncrementRating"]) {
322 [ratingIncrementButton setTitle:@"(None)"];
323 } else if ([enumKey isEqualToString:@"DecrementRating"]) {
324 [ratingDecrementButton setTitle:@"(None)"];
325 } else if ([enumKey isEqualToString:@"ToggleShuffle"]) {
326 [toggleShuffleButton setTitle:@"(None)"];
327 } else if ([enumKey isEqualToString:@"ToggleLoop"]) {
328 [toggleLoopButton setTitle:@"(None)"];
330 [df setObject:[[ITKeyCombo clearKeyCombo] plistRepresentation] forKey:enumKey];
331 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:enumKey];
335 [window setLevel:NSStatusWindowLevel];
340 [hotKeysDictionary setObject:combo forKey:currentHotKey];
341 [df setObject:[combo plistRepresentation] forKey:currentHotKey];
343 if ([currentHotKey isEqualToString:@"PlayPause"]) {
344 [playPauseButton setTitle:string];
345 } else if ([currentHotKey isEqualToString:@"NextTrack"]) {
346 [nextTrackButton setTitle:string];
347 } else if ([currentHotKey isEqualToString:@"PrevTrack"]) {
348 [previousTrackButton setTitle:string];
349 } else if ([currentHotKey isEqualToString:@"ShowPlayer"]) {
350 [showPlayerButton setTitle:string];
351 } else if ([currentHotKey isEqualToString:@"TrackInfo"]) {
352 [trackInfoButton setTitle:string];
353 } else if ([currentHotKey isEqualToString:@"UpcomingSongs"]) {
354 [upcomingSongsButton setTitle:string];
355 } else if ([currentHotKey isEqualToString:@"IncrementVolume"]) {
356 [volumeIncrementButton setTitle:string];
357 } else if ([currentHotKey isEqualToString:@"DecrementVolume"]) {
358 [volumeDecrementButton setTitle:string];
359 } else if ([currentHotKey isEqualToString:@"IncrementRating"]) {
360 [ratingIncrementButton setTitle:string];
361 } else if ([currentHotKey isEqualToString:@"DecrementRating"]) {
362 [ratingDecrementButton setTitle:string];
363 } else if ([currentHotKey isEqualToString:@"ToggleShuffle"]) {
364 [toggleShuffleButton setTitle:string];
365 } else if ([currentHotKey isEqualToString:@"ToggleLoop"]) {
366 [toggleLoopButton setTitle:string];
368 [controller setupHotKeys];
369 [self cancelHotKey:sender];
374 /*************************************************************************/
376 #pragma mark HOTKEY SUPPORT METHODS
377 /*************************************************************************/
379 - (void)setCurrentHotKey:(NSString *)key
381 [currentHotKey autorelease];
382 currentHotKey = [key copy];
383 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyEvent:) name:ITKeyBroadcasterKeyEvent object:nil];
384 [NSApp beginSheet:keyComboPanel modalForWindow:window modalDelegate:self didEndSelector:nil contextInfo:nil];
387 - (void)keyEvent:(NSNotification *)note
389 [self setKeyCombo:[[[note userInfo] objectForKey:@"keyCombo"] copy]];
392 - (void)setKeyCombo:(ITKeyCombo *)newCombo
396 combo = [newCombo copy];
398 string = [combo description];
402 [keyComboField setStringValue:string];
406 /*************************************************************************/
408 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
409 /*************************************************************************/
413 if (![NSBundle loadNibNamed:@"Preferences" owner:self]) {
414 NSLog(@"MenuTunes: Failed to load Preferences.nib");
420 - (void)setupCustomizationTables
422 NSImageCell *imgCell = [[[NSImageCell alloc] initImageCell:nil] autorelease];
424 // Set the table view cells up
425 [imgCell setImageScaling:NSScaleNone];
426 [[menuTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
427 [[allTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
429 // Register for drag and drop
430 [menuTableView registerForDraggedTypes:[NSArray arrayWithObjects:
431 @"MenuTableViewPboardType",
432 @"AllTableViewPboardType",
434 [allTableView registerForDraggedTypes:[NSArray arrayWithObjects:
435 @"MenuTableViewPboardType",
436 @"AllTableViewPboardType",
440 - (void)setupMenuItems
442 NSEnumerator *itemEnum;
444 // Set the list of items you can have.
445 availableItems = [[NSMutableArray alloc] initWithObjects:
460 // Get our preferred menu
461 myItems = [[df arrayForKey:@"menu"] mutableCopy];
463 // Delete items in the availableItems array that are already part of the menu
464 itemEnum = [myItems objectEnumerator];
465 while ( (anItem = [itemEnum nextObject]) ) {
466 if (![anItem isEqualToString:@"separator"]) {
467 [availableItems removeObject:anItem];
471 // Items that show should a submenu image
472 submenuItems = [[NSArray alloc] initWithObjects:
482 NSMutableDictionary *loginwindow;
483 NSMutableArray *loginarray;
484 NSEnumerator *loginEnum;
487 // Fill in the number of songs in advance to show field
488 [songsInAdvance setIntValue:[df integerForKey:@"SongsInAdvance"]];
490 // Fill in hot key buttons
491 if ([df objectForKey:@"PlayPause"]) {
492 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PlayPause"]];
493 [hotKeysDictionary setObject:anItem forKey:@"PlayPause"];
494 [playPauseButton setTitle:[anItem description]];
496 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"PlayPause"];
497 [playPauseButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
500 if ([df objectForKey:@"NextTrack"]) {
501 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"NextTrack"]];
502 [hotKeysDictionary setObject:anItem forKey:@"NextTrack"];
503 [nextTrackButton setTitle:[anItem description]];
505 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"NextTrack"];
506 [nextTrackButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
509 if ([df objectForKey:@"PrevTrack"]) {
510 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PrevTrack"]];
511 [hotKeysDictionary setObject:anItem forKey:@"PrevTrack"];
512 [previousTrackButton setTitle:[anItem description]];
514 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"PrevTrack"];
515 [previousTrackButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
518 if ([df objectForKey:@"ShowPlayer"]) {
519 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]];
520 [hotKeysDictionary setObject:anItem forKey:@"ShowPlayer"];
521 [showPlayerButton setTitle:[anItem description]];
523 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"ShowPlayer"];
524 [showPlayerButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
527 if ([df objectForKey:@"TrackInfo"]) {
528 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"TrackInfo"]];
529 [hotKeysDictionary setObject:anItem forKey:@"TrackInfo"];
530 [trackInfoButton setTitle:[anItem description]];
532 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"TrackInfo"];
533 [trackInfoButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
536 if ([df objectForKey:@"UpcomingSongs"]) {
537 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"UpcomingSongs"]];
538 [hotKeysDictionary setObject:anItem forKey:@"UpcomingSongs"];
539 [upcomingSongsButton setTitle:[anItem description]];
541 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"UpcomingSongs"];
542 [upcomingSongsButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
545 if ([df objectForKey:@"IncrementVolume"]) {
546 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementVolume"]];
547 [hotKeysDictionary setObject:anItem forKey:@"IncrementVolume"];
548 [volumeIncrementButton setTitle:[anItem description]];
550 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"IncrementVolume"];
551 [volumeIncrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
554 if ([df objectForKey:@"DecrementVolume"]) {
555 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementVolume"]];
556 [hotKeysDictionary setObject:anItem forKey:@"DecrementVolume"];
557 [volumeDecrementButton setTitle:[anItem description]];
559 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"DecrementVolume"];
560 [volumeDecrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
563 if ([df objectForKey:@"IncrementRating"]) {
564 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementRating"]];
565 [hotKeysDictionary setObject:anItem forKey:@"IncrementRating"];
566 [ratingIncrementButton setTitle:[anItem description]];
568 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"IncrementRating"];
569 [ratingIncrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
572 if ([df objectForKey:@"DecrementRating"]) {
573 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementRating"]];
574 [hotKeysDictionary setObject:anItem forKey:@"DecrementRating"];
575 [ratingDecrementButton setTitle:[anItem description]];
577 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"DecrementRating"];
578 [ratingDecrementButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
581 if ([df objectForKey:@"ToggleLoop"]) {
582 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleLoop"]];
583 [hotKeysDictionary setObject:anItem forKey:@"ToggleLoop"];
584 [toggleLoopButton setTitle:[anItem description]];
586 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"ToggleLoop"];
587 [toggleLoopButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
590 if ([df objectForKey:@"ToggleShuffle"]) {
591 anItem = [ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleShuffle"]];
592 [hotKeysDictionary setObject:anItem forKey:@"ToggleShuffle"];
593 [toggleShuffleButton setTitle:[anItem description]];
595 [hotKeysDictionary setObject:[ITKeyCombo clearKeyCombo] forKey:@"ToggleShuffle"];
596 [toggleShuffleButton setTitle:[[ITKeyCombo clearKeyCombo] description]];
599 // Check current track info buttons
600 [albumCheckbox setState:[df boolForKey:@"showAlbum"] ? NSOnState : NSOffState];
601 [nameCheckbox setState:NSOnState]; // Song info will ALWAYS show song title.
602 [nameCheckbox setEnabled:NO]; // Song info will ALWAYS show song title.
603 [artistCheckbox setState:[df boolForKey:@"showArtist"] ? NSOnState : NSOffState];
604 [trackTimeCheckbox setState:[df boolForKey:@"showTime"] ? NSOnState : NSOffState];
605 [trackNumberCheckbox setState:[df boolForKey:@"showTrackNumber"] ? NSOnState : NSOffState];
607 // Set the launch at login checkbox state
609 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
610 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
612 loginEnum = [loginarray objectEnumerator];
613 while ( (anItem = [loginEnum nextObject]) ) {
614 if ([[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
615 [launchAtLoginCheckbox setState:NSOnState];
620 - (IBAction)changeMenus:(id)sender
622 [df setObject:myItems forKey:@"menu"];
626 - (void)setLaunchesAtLogin:(BOOL)flag
629 NSMutableDictionary *loginwindow;
630 NSMutableArray *loginarray;
631 ComponentInstance temp = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
636 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
637 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
639 for (i = 0; i < [loginarray count]; i++) {
640 NSDictionary *tempDict = [loginarray objectAtIndex:i];
641 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
647 AEDesc scriptDesc, resultDesc;
648 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]];
650 AECreateDesc(typeChar, [script cString], [script cStringLength],
653 OSADoScript(temp, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
655 AEDisposeDesc(&scriptDesc);
656 AEDisposeDesc(&resultDesc);
657 CloseComponent(temp);
661 NSMutableDictionary *loginwindow;
662 NSMutableArray *loginarray;
666 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
667 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
669 for (i = 0; i < [loginarray count]; i++) {
670 NSDictionary *tempDict = [loginarray objectAtIndex:i];
671 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
672 [loginarray removeObjectAtIndex:i];
673 [df setPersistentDomain:loginwindow forName:@"loginwindow"];
682 /*************************************************************************/
684 #pragma mark NSWindow DELEGATE METHODS
685 /*************************************************************************/
687 - (void)windowWillClose:(NSNotification *)note
689 [(MainController *)controller closePreferences];
693 /*************************************************************************/
695 #pragma mark NSTableView DATASOURCE METHODS
696 /*************************************************************************/
698 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
700 if (aTableView == menuTableView) {
701 return [myItems count];
703 return [availableItems count];
707 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
709 if (aTableView == menuTableView) {
710 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
711 NSString *object = [myItems objectAtIndex:rowIndex];
712 if ([object isEqualToString:@"Show Player"]) {
713 return [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), [[controller currentRemote] playerSimpleName]];
715 return NSLocalizedString(object, @"ERROR");
717 if ([submenuItems containsObject:[myItems objectAtIndex:rowIndex]])
719 return [NSImage imageNamed:@"submenu"];
725 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
726 return NSLocalizedString([availableItems objectAtIndex:rowIndex], @"ERROR");
728 if ([submenuItems containsObject:[availableItems objectAtIndex:rowIndex]]) {
729 return [NSImage imageNamed:@"submenu"];
737 - (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard
739 if (tableView == menuTableView) {
740 [pboard declareTypes:[NSArray arrayWithObjects:@"MenuTableViewPboardType", nil] owner:self];
741 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"MenuTableViewPboardType"];
745 if (tableView == allTableView) {
746 [pboard declareTypes:[NSArray arrayWithObjects:@"AllTableViewPboardType", nil] owner:self];
747 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"AllTableViewPboardType"];
753 - (BOOL)tableView:(NSTableView*)tableView acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)operation
757 NSString *dragData, *temp;
759 pb = [info draggingPasteboard];
761 if ([[pb types] containsObject:@"MenuTableViewPboardType"]) {
762 dragData = [pb stringForType:@"MenuTableViewPboardType"];
763 dragRow = [dragData intValue];
764 temp = [myItems objectAtIndex:dragRow];
766 if (tableView == menuTableView) {
767 [myItems insertObject:temp atIndex:row];
769 [myItems removeObjectAtIndex:dragRow];
771 [myItems removeObjectAtIndex:dragRow + 1];
774 if (![temp isEqualToString:@"separator"]) {
775 [availableItems addObject:temp];
777 [myItems removeObjectAtIndex:dragRow];
779 } else if ([[pb types] containsObject:@"AllTableViewPboardType"]) {
780 dragData = [pb stringForType:@"AllTableViewPboardType"];
781 dragRow = [dragData intValue];
782 temp = [availableItems objectAtIndex:dragRow];
784 [myItems insertObject:temp atIndex:row];
786 if (![temp isEqualToString:@"separator"]) {
787 [availableItems removeObjectAtIndex:dragRow];
791 [menuTableView reloadData];
792 [allTableView reloadData];
793 [self changeMenus:self];
797 - (NSDragOperation)tableView:(NSTableView*)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)operation
799 if (tableView == allTableView) {
800 if ([[[info draggingPasteboard] types] containsObject:@"AllTableViewPboardType"]) {
801 return NSDragOperationNone;
804 if ([[[info draggingPasteboard] types] containsObject:@"MenuTableViewPboardType"]) {
805 NSString *item = [myItems objectAtIndex:[[[info draggingPasteboard] stringForType:@"MenuTableViewPboardType"] intValue]];
806 if ([item isEqualToString:@"Preferences"] || [item isEqualToString:@"Quit"]) {
807 return NSDragOperationNone;
811 [tableView setDropRow:-1 dropOperation:NSTableViewDropOn];
812 return NSDragOperationGeneric;
815 if (operation == NSTableViewDropOn || row == -1)
817 return NSDragOperationNone;
820 return NSDragOperationGeneric;
824 /*************************************************************************/
826 #pragma mark DEALLOCATION METHODS
827 /*************************************************************************/
831 [self setKeyCombo:nil];
832 [hotKeysDictionary release];
833 [keyComboPanel release];
834 [menuTableView setDataSource:nil];
835 [allTableView setDataSource:nil];
836 [controller release];
837 [availableItems release];
838 [submenuItems release];