1 #import "PreferencesController.h"
2 #import "MainController.h"
3 #import "HotKeyCenter.h"
4 #import <ITKit/ITWindowPositioning.h>
6 #define SENDER_STATE (([sender state] == NSOnState) ? YES : NO)
8 /*************************************************************************/
10 #pragma mark PRIVATE INTERFACE
11 /*************************************************************************/
13 @interface PreferencesController (Private)
15 - (void)setupCustomizationTables;
16 - (void)setupMenuItems;
18 - (IBAction)changeMenus:(id)sender;
19 - (void)setLaunchesAtLogin:(BOOL)flag;
23 @implementation PreferencesController
26 /*************************************************************************/
28 #pragma mark STATIC VARIABLES
29 /*************************************************************************/
31 static PreferencesController *prefs = nil;
34 /*************************************************************************/
36 #pragma mark INITIALIZATION METHODS
37 /*************************************************************************/
39 + (PreferencesController *)sharedPrefs;
42 prefs = [[self alloc] init];
49 if ( (self = [super init]) ) {
50 df = [[NSUserDefaults standardUserDefaults] retain];
51 hotKeysDictionary = [[NSMutableDictionary alloc] init];
58 /*************************************************************************/
60 #pragma mark ACCESSOR METHODS
61 /*************************************************************************/
68 - (void)setController:(id)object
70 [controller autorelease];
71 controller = [object retain];
75 /*************************************************************************/
77 #pragma mark INSTANCE METHODS
78 /*************************************************************************/
80 - (IBAction)showPrefsWindow:(id)sender
82 if (! window) { // If window does not exist yet, then the nib hasn't been loaded.
83 [self setupWindow]; // Load in the nib, and perform any initial setup.
84 [self setupCustomizationTables]; // Setup the DnD manu config tables.
85 [self setupMenuItems]; // Setup the arrays of menu items
86 [self setupUI]; // Sets up additional UI
87 [window setDelegate:self];
90 [window setLevel:NSStatusWindowLevel];
92 [window makeKeyAndOrderFront:self];
93 [NSApp activateIgnoringOtherApps:YES];
96 - (IBAction)changeGeneralSetting:(id)sender
98 if ( [sender tag] == 1010) {
99 [self setLaunchesAtLogin:SENDER_STATE];
100 } else if ( [sender tag] == 1020) {
101 [df setBool:SENDER_STATE forKey:@"LaunchPlayerWithMT"];
102 } else if ( [sender tag] == 1030) {
103 [df setInteger:[sender intValue] forKey:@"SongsInAdvance"];
105 } else if ( [sender tag] == 1040) {
106 // This will not be executed. Song info always shows the title of the song.
107 // [df setBool:SENDER_STATE forKey:@"showName"];
108 } else if ( [sender tag] == 1050) {
109 [df setBool:SENDER_STATE forKey:@"showArtist"];
110 } else if ( [sender tag] == 1060) {
111 [df setBool:SENDER_STATE forKey:@"showAlbum"];
112 } else if ( [sender tag] == 1070) {
113 [df setBool:SENDER_STATE forKey:@"showTime"];
114 } else if ( [sender tag] == 1080) {
115 [df setBool:SENDER_STATE forKey:@"showTrackNumber"];
116 } else if ( [sender tag] == 1090) {
117 [df setBool:SENDER_STATE forKey:@"showTrackRating"];
122 - (IBAction)changeStatusWindowSetting:(id)sender
124 if ( [sender tag] == 2010) {
125 [df setInteger:[sender selectedRow] forKey:@"statusWindowVerticalPosition"];
126 [df setInteger:[sender selectedColumn] forKey:@"statusWindowHorizontalPosition"];
127 // update the window's position here
128 } else if ( [sender tag] == 2020) {
129 // update screen selection
130 } else if ( [sender tag] == 2030) {
131 // Update appearance effect
132 } else if ( [sender tag] == 2040) {
133 // Update Vanish Effect
134 } else if ( [sender tag] == 2050) {
135 // Update appearance speed
136 } else if ( [sender tag] == 2060) {
137 // Update vanish speed
138 } else if ( [sender tag] == 2070) {
139 // Update vanish delay
140 } else if ( [sender tag] == 2080) {
141 // Update "Song Info window when song changes" setting.
142 [df setBool:SENDER_STATE forKey:@"showSongInfoOnChange"];
146 - (IBAction)changeHotKey:(id)sender
148 [controller clearHotKeys];
149 switch ([sender tag])
152 [self setKeyCombo:[hotKeysDictionary objectForKey:@"PlayPause"]];
153 [self setCurrentHotKey:@"PlayPause"];
156 [self setKeyCombo:[hotKeysDictionary objectForKey:@"NextTrack"]];
157 [self setCurrentHotKey:@"NextTrack"];
160 [self setKeyCombo:[hotKeysDictionary objectForKey:@"PrevTrack"]];
161 [self setCurrentHotKey:@"PrevTrack"];
164 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ShowPlayer"]];
165 [self setCurrentHotKey:@"ShowPlayer"];
168 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleLoop"]];
169 [self setCurrentHotKey:@"ToggleLoop"];
172 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleShuffle"]];
173 [self setCurrentHotKey:@"ToggleShuffle"];
176 [self setKeyCombo:[hotKeysDictionary objectForKey:@"TrackInfo"]];
177 [self setCurrentHotKey:@"TrackInfo"];
180 [self setKeyCombo:[hotKeysDictionary objectForKey:@"UpcomingSongs"]];
181 [self setCurrentHotKey:@"UpcomingSongs"];
184 [self setKeyCombo:[hotKeysDictionary objectForKey:@"IncrementVolume"]];
185 [self setCurrentHotKey:@"IncrementVolume"];
188 [self setKeyCombo:[hotKeysDictionary objectForKey:@"DecrementVolume"]];
189 [self setCurrentHotKey:@"DecrementVolume"];
192 [self setKeyCombo:[hotKeysDictionary objectForKey:@"IncrementRating"]];
193 [self setCurrentHotKey:@"IncrementRating"];
196 [self setKeyCombo:[hotKeysDictionary objectForKey:@"DecrementRating"]];
197 [self setCurrentHotKey:@"DecrementRating"];
202 - (void)registerDefaults
205 NSMutableDictionary *loginWindow;
206 NSMutableArray *loginArray;
207 NSEnumerator *loginEnum;
210 [df setObject:[NSArray arrayWithObjects:
227 nil] forKey:@"menu"];
229 [df setInteger:5 forKey:@"SongsInAdvance"];
230 // [df setBool:YES forKey:@"showName"]; // Song info will always show song title.
231 [df setBool:YES forKey:@"showArtist"];
232 [df setBool:NO forKey:@"showAlbum"];
233 [df setBool:NO forKey:@"showTime"];
237 loginWindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
238 loginArray = [loginWindow objectForKey:@"AutoLaunchedApplicationDictionary"];
239 loginEnum = [loginArray objectEnumerator];
241 while ( (anItem = [loginEnum nextObject]) ) {
242 if ( [[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]] ) {
247 [loginWindow release];
250 // We must fix it so it is no longer suxy
252 if (NSRunInformationalAlertPanel(NSLocalizedString(@"autolaunch", @"Auto-launch MenuTunes"), NSLocalizedString(@"autolaunch_msg", @"Would you like MenuTunes to automatically launch at login?"), @"Yes", @"No", nil) == NSOKButton) {
253 AEDesc scriptDesc, resultDesc;
254 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]];
255 ComponentInstance asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
257 AECreateDesc(typeChar, [script cString], [script cStringLength],
260 OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
262 AEDisposeDesc(&scriptDesc);
263 AEDisposeDesc(&resultDesc);
265 CloseComponent(asComponent);
270 - (IBAction)cancelHotKey:(id)sender
272 [[NSNotificationCenter defaultCenter] removeObserver:self];
273 [NSApp endSheet:keyComboPanel];
274 [keyComboPanel orderOut:nil];
277 - (IBAction)clearHotKey:(id)sender
279 [self setKeyCombo:[KeyCombo clearKeyCombo]];
282 - (IBAction)okHotKey:(id)sender
284 NSString *string = [combo userDisplayRep];
285 NSEnumerator *enumerator = [hotKeysDictionary keyEnumerator];
292 while ( (enumKey = [enumerator nextObject]) ) {
293 if (![enumKey isEqualToString:currentHotKey]) {
294 if (![combo isEqual:[KeyCombo clearKeyCombo]] &&
295 [combo isEqual:[hotKeysDictionary objectForKey:enumKey]]) {
296 [window setLevel:NSNormalWindowLevel];
297 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) ) {
298 [hotKeysDictionary setObject:[KeyCombo clearKeyCombo] forKey:currentHotKey];
299 if ([enumKey isEqualToString:@"PlayPause"]) {
300 [playPauseButton setTitle:@""];
301 } else if ([enumKey isEqualToString:@"NextTrack"]) {
302 [nextTrackButton setTitle:@""];
303 } else if ([enumKey isEqualToString:@"PrevTrack"]) {
304 [previousTrackButton setTitle:@""];
305 } else if ([enumKey isEqualToString:@"ShowPlayer"]) {
306 [showPlayerButton setTitle:@""];
307 } else if ([enumKey isEqualToString:@"TrackInfo"]) {
308 [trackInfoButton setTitle:@""];
309 } else if ([enumKey isEqualToString:@"UpcomingSongs"]) {
310 [upcomingSongsButton setTitle:@""];
311 } else if ([enumKey isEqualToString:@"IncrementVolume"]) {
312 [volumeIncrementButton setTitle:@""];
313 } else if ([enumKey isEqualToString:@"DecrementVolume"]) {
314 [volumeDecrementButton setTitle:@""];
315 } else if ([enumKey isEqualToString:@"IncrementRating"]) {
316 [ratingIncrementButton setTitle:@""];
317 } else if ([enumKey isEqualToString:@"DecrementRating"]) {
318 [ratingDecrementButton setTitle:@""];
319 } else if ([enumKey isEqualToString:@"ToggleShuffle"]) {
320 [toggleShuffleButton setTitle:@""];
321 } else if ([enumKey isEqualToString:@"ToggleLoop"]) {
322 [toggleLoopButton setTitle:@""];
324 [df setKeyCombo:[KeyCombo clearKeyCombo] forKey:enumKey];
328 [window setLevel:NSStatusWindowLevel];
333 [hotKeysDictionary setObject:combo forKey:currentHotKey];
334 [df setKeyCombo:combo forKey:currentHotKey];
336 if ([currentHotKey isEqualToString:@"PlayPause"]) {
337 [playPauseButton setTitle:string];
338 //[[HotKeyCenter sharedCenter] addHotKey:@"PlayPause" combo:combo target:[MainController sharedController] action:@selector(playPause)];
339 } else if ([currentHotKey isEqualToString:@"NextTrack"]) {
340 [nextTrackButton setTitle:string];
341 //[[HotKeyCenter sharedCenter] addHotKey:@"NextTrack" combo:combo target:[MainController sharedController] action:@selector(nextSong)];
342 } else if ([currentHotKey isEqualToString:@"PrevTrack"]) {
343 [previousTrackButton setTitle:string];
344 //[[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack" combo:combo target:[MainController sharedController] action:@selector(prevSong)];
345 } else if ([currentHotKey isEqualToString:@"ShowPlayer"]) {
346 [showPlayerButton setTitle:string];
347 //[[HotKeyCenter sharedCenter] addHotKey:@"ShowPlayer" combo:combo target:[MainController sharedController] action:@selector(showPlayer)];
348 } else if ([currentHotKey isEqualToString:@"TrackInfo"]) {
349 [trackInfoButton setTitle:string];
350 //[[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo" combo:combo target:[MainController sharedController] action:@selector(showCurrentTrackInfo)];
351 } else if ([currentHotKey isEqualToString:@"UpcomingSongs"]) {
352 [upcomingSongsButton setTitle:string];
353 //[[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs" combo:combo target:[MainController sharedController] action:@selector(showUpcomingSongs)];
354 } else if ([currentHotKey isEqualToString:@"IncrementVolume"]) {
355 [volumeIncrementButton setTitle:string];
356 //[[HotKeyCenter sharedCenter] addHotKey:@"IncrementVolume" combo:combo target:[MainController sharedController] action:@selector(incrementVolume)];
357 } else if ([currentHotKey isEqualToString:@"DecrementVolume"]) {
358 [volumeDecrementButton setTitle:string];
359 //[[HotKeyCenter sharedCenter] addHotKey:@"DecrementVolume" combo:combo target:[MainController sharedController] action:@selector(decrementVolume)];
360 } else if ([currentHotKey isEqualToString:@"IncrementRating"]) {
361 [ratingIncrementButton setTitle:string];
362 //[[HotKeyCenter sharedCenter] addHotKey:@"IncrementRating" combo:combo target:[MainController sharedController] action:@selector(incrementRating)];
363 } else if ([currentHotKey isEqualToString:@"DecrementRating"]) {
364 [ratingDecrementButton setTitle:string];
365 //[[HotKeyCenter sharedCenter] addHotKey:@"DecrementRating" combo:combo target:[MainController sharedController] action:@selector(decrementRating)];
366 } else if ([currentHotKey isEqualToString:@"ToggleShuffle"]) {
367 [toggleShuffleButton setTitle:string];
368 //[[HotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle" combo:combo target:[MainController sharedController] action:@selector(toggleShuffle)];
369 } else if ([currentHotKey isEqualToString:@"ToggleLoop"]) {
370 [toggleLoopButton setTitle:string];
371 //[[HotKeyCenter sharedCenter] addHotKey:@"ToggleLoop" combo:combo target:[MainController sharedController] action:@selector(toggleLoop)];
373 [controller setupHotKeys];
374 [self cancelHotKey:sender];
379 /*************************************************************************/
381 #pragma mark HOTKEY SUPPORT METHODS
382 /*************************************************************************/
384 - (void)setCurrentHotKey:(NSString *)key
386 [currentHotKey autorelease];
387 currentHotKey = [key copy];
388 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyEvent:) name:@"KeyBroadcasterEvent" object:nil];
389 [NSApp beginSheet:keyComboPanel modalForWindow:window modalDelegate:self didEndSelector:nil contextInfo:nil];
392 - (void)keyEvent:(NSNotification *)note
394 NSDictionary *info = [note userInfo];
399 keyCode = [[info objectForKey:@"KeyCode"] shortValue];
400 modifiers = [[info objectForKey:@"Modifiers"] longValue];
402 newCombo = [[KeyCombo alloc] initWithKeyCode:keyCode andModifiers:modifiers];
403 [self setKeyCombo:newCombo];
406 - (void)setKeyCombo:(KeyCombo *)newCombo
410 combo = [newCombo copy];
412 string = [combo userDisplayRep];
416 [keyComboField setStringValue:string];
420 /*************************************************************************/
422 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
423 /*************************************************************************/
427 if (![NSBundle loadNibNamed:@"Preferences" owner:self]) {
428 NSLog(@"MenuTunes: Failed to load Preferences.nib");
434 - (void)setupCustomizationTables
436 NSImageCell *imgCell = [[[NSImageCell alloc] initImageCell:nil] autorelease];
438 // Set the table view cells up
439 [imgCell setImageScaling:NSScaleNone];
440 [[menuTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
441 [[allTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
443 // Register for drag and drop
444 [menuTableView registerForDraggedTypes:[NSArray arrayWithObjects:
445 @"MenuTableViewPboardType",
446 @"AllTableViewPboardType",
448 [allTableView registerForDraggedTypes:[NSArray arrayWithObjects:
449 @"MenuTableViewPboardType",
450 @"AllTableViewPboardType",
454 - (void)setupMenuItems
456 NSEnumerator *itemEnum;
458 // Set the list of items you can have.
459 availableItems = [[NSMutableArray alloc] initWithObjects:
474 // Get our preferred menu
475 myItems = [[df arrayForKey:@"menu"] mutableCopy];
477 // Delete items in the availableItems array that are already part of the menu
478 itemEnum = [myItems objectEnumerator];
479 while ( (anItem = [itemEnum nextObject]) ) {
480 if (![anItem isEqualToString:@"separator"]) {
481 [availableItems removeObject:anItem];
485 // Items that show should a submenu image
486 submenuItems = [[NSArray alloc] initWithObjects:
496 NSMutableDictionary *loginwindow;
497 NSMutableArray *loginarray;
498 NSEnumerator *loginEnum;
501 // Fill in the number of songs in advance to show field
502 [songsInAdvance setIntValue:[df integerForKey:@"SongsInAdvance"]];
504 // Fill in hot key buttons
505 if ([df objectForKey:@"PlayPause"]) {
506 anItem = [df keyComboForKey:@"PlayPause"];
507 [hotKeysDictionary setObject:anItem forKey:@"PlayPause"];
508 [playPauseButton setTitle:[anItem userDisplayRep]];
510 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"PlayPause"];
513 if ([df objectForKey:@"NextTrack"]) {
514 anItem = [df keyComboForKey:@"NextTrack"];
515 [hotKeysDictionary setObject:anItem forKey:@"NextTrack"];
516 [nextTrackButton setTitle:[anItem userDisplayRep]];
518 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"NextTrack"];
521 if ([df objectForKey:@"PrevTrack"]) {
522 anItem = [df keyComboForKey:@"PrevTrack"];
523 [hotKeysDictionary setObject:anItem forKey:@"PrevTrack"];
524 [previousTrackButton setTitle:[anItem userDisplayRep]];
526 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"PrevTrack"];
529 if ([df objectForKey:@"ShowPlayer"]) {
530 anItem = [df keyComboForKey:@"ShowPlayer"];
531 [hotKeysDictionary setObject:anItem forKey:@"ShowPlayer"];
532 [showPlayerButton setTitle:[anItem userDisplayRep]];
534 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ShowPlayer"];
537 if ([df objectForKey:@"TrackInfo"]) {
538 anItem = [df keyComboForKey:@"TrackInfo"];
539 [hotKeysDictionary setObject:anItem forKey:@"TrackInfo"];
540 [trackInfoButton setTitle:[anItem userDisplayRep]];
542 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"TrackInfo"];
545 if ([df objectForKey:@"UpcomingSongs"]) {
546 anItem = [df keyComboForKey:@"UpcomingSongs"];
547 [hotKeysDictionary setObject:anItem forKey:@"UpcomingSongs"];
548 [upcomingSongsButton setTitle:[anItem userDisplayRep]];
550 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"UpcomingSongs"];
553 if ([df objectForKey:@"IncrementVolume"]) {
554 anItem = [df keyComboForKey:@"IncrementVolume"];
555 [hotKeysDictionary setObject:anItem forKey:@"IncrementVolume"];
556 [volumeIncrementButton setTitle:[anItem userDisplayRep]];
558 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"IncrementVolume"];
561 if ([df objectForKey:@"DecrementVolume"]) {
562 anItem = [df keyComboForKey:@"DecrementVolume"];
563 [hotKeysDictionary setObject:anItem forKey:@"DecrementVolume"];
564 [volumeDecrementButton setTitle:[anItem userDisplayRep]];
566 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"DecrementVolume"];
569 if ([df objectForKey:@"IncrementRating"]) {
570 anItem = [df keyComboForKey:@"IncrementRating"];
571 [hotKeysDictionary setObject:anItem forKey:@"IncrementRating"];
572 [ratingIncrementButton setTitle:[anItem userDisplayRep]];
574 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"IncrementRating"];
577 if ([df objectForKey:@"DecrementRating"]) {
578 anItem = [df keyComboForKey:@"DecrementRating"];
579 [hotKeysDictionary setObject:anItem forKey:@"DecrementRating"];
580 [ratingDecrementButton setTitle:[anItem userDisplayRep]];
582 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"DecrementRating"];
585 if ([df objectForKey:@"ToggleLoop"]) {
586 anItem = [df keyComboForKey:@"ToggleLoop"];
587 [hotKeysDictionary setObject:anItem forKey:@"ToggleLoop"];
588 [toggleLoopButton setTitle:[anItem userDisplayRep]];
590 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleLoop"];
593 if ([df objectForKey:@"ToggleShuffle"]) {
594 anItem = [df keyComboForKey:@"ToggleShuffle"];
595 [hotKeysDictionary setObject:anItem forKey:@"ToggleShuffle"];
596 [toggleShuffleButton setTitle:[anItem userDisplayRep]];
598 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleShuffle"];
601 // Check current track info buttons
602 [albumCheckbox setState:[df boolForKey:@"showAlbum"] ? NSOnState : NSOffState];
603 [nameCheckbox setState:NSOnState]; // Song info will ALWAYS show song title.
604 [nameCheckbox setEnabled:NO]; // Song info will ALWAYS show song title.
605 [artistCheckbox setState:[df boolForKey:@"showArtist"] ? NSOnState : NSOffState];
606 [trackTimeCheckbox setState:[df boolForKey:@"showTime"] ? NSOnState : NSOffState];
607 [trackNumberCheckbox setState:[df boolForKey:@"showTrackNumber"] ? NSOnState : NSOffState];
609 // Set the launch at login checkbox state
611 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
612 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
614 loginEnum = [loginarray objectEnumerator];
615 while ( (anItem = [loginEnum nextObject]) ) {
616 if ([[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
617 [launchAtLoginCheckbox setState:NSOnState];
622 - (IBAction)changeMenus:(id)sender
624 [df setObject:myItems forKey:@"menu"];
628 - (void)setLaunchesAtLogin:(BOOL)flag
631 NSMutableDictionary *loginwindow;
632 NSMutableArray *loginarray;
633 ComponentInstance temp = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
638 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
639 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
641 for (i = 0; i < [loginarray count]; i++) {
642 NSDictionary *tempDict = [loginarray objectAtIndex:i];
643 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
649 AEDesc scriptDesc, resultDesc;
650 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]];
652 AECreateDesc(typeChar, [script cString], [script cStringLength],
655 OSADoScript(temp, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
657 AEDisposeDesc(&scriptDesc);
658 AEDisposeDesc(&resultDesc);
659 CloseComponent(temp);
663 NSMutableDictionary *loginwindow;
664 NSMutableArray *loginarray;
668 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
669 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
671 for (i = 0; i < [loginarray count]; i++) {
672 NSDictionary *tempDict = [loginarray objectAtIndex:i];
673 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
674 [loginarray removeObjectAtIndex:i];
675 [df setPersistentDomain:loginwindow forName:@"loginwindow"];
684 /*************************************************************************/
686 #pragma mark NSWindow DELEGATE METHODS
687 /*************************************************************************/
689 - (void)windowWillClose:(NSNotification *)note
691 [(MainController *)controller closePreferences];
695 /*************************************************************************/
697 #pragma mark NSTableView DATASOURCE METHODS
698 /*************************************************************************/
700 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
702 if (aTableView == menuTableView) {
703 return [myItems count];
705 return [availableItems count];
709 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
711 if (aTableView == menuTableView) {
712 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
713 NSString *object = [myItems objectAtIndex:rowIndex];
714 if ([object isEqualToString:@"Show Player"]) {
715 return [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), [[controller currentRemote] playerSimpleName]];
717 return NSLocalizedString(object, @"ERROR");
719 if ([submenuItems containsObject:[myItems objectAtIndex:rowIndex]])
721 return [NSImage imageNamed:@"submenu"];
727 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
728 return NSLocalizedString([availableItems objectAtIndex:rowIndex], @"ERROR");
730 if ([submenuItems containsObject:[availableItems objectAtIndex:rowIndex]]) {
731 return [NSImage imageNamed:@"submenu"];
739 - (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard
741 if (tableView == menuTableView) {
742 [pboard declareTypes:[NSArray arrayWithObjects:@"MenuTableViewPboardType", nil] owner:self];
743 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"MenuTableViewPboardType"];
747 if (tableView == allTableView) {
748 [pboard declareTypes:[NSArray arrayWithObjects:@"AllTableViewPboardType", nil] owner:self];
749 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"AllTableViewPboardType"];
755 - (BOOL)tableView:(NSTableView*)tableView acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)operation
759 NSString *dragData, *temp;
761 pb = [info draggingPasteboard];
763 if ([[pb types] containsObject:@"MenuTableViewPboardType"]) {
764 dragData = [pb stringForType:@"MenuTableViewPboardType"];
765 dragRow = [dragData intValue];
766 temp = [myItems objectAtIndex:dragRow];
767 if (tableView == menuTableView) {
768 [myItems insertObject:temp atIndex:row];
770 [myItems removeObjectAtIndex:dragRow];
772 [myItems removeObjectAtIndex:dragRow + 1];
775 if (![temp isEqualToString:@"separator"]) {
776 [availableItems addObject:temp];
777 [myItems removeObjectAtIndex:dragRow];
780 } else if ([[pb types] containsObject:@"AllTableViewPboardType"]) {
781 dragData = [pb stringForType:@"AllTableViewPboardType"];
782 dragRow = [dragData intValue];
783 temp = [availableItems objectAtIndex:dragRow];
785 [myItems insertObject:temp atIndex:row];
787 if (![temp isEqualToString:@"separator"]) {
788 [availableItems removeObjectAtIndex:dragRow];
792 [menuTableView reloadData];
793 [allTableView reloadData];
794 [self changeMenus:self];
798 - (NSDragOperation)tableView:(NSTableView*)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)operation
800 if (tableView == allTableView) {
801 if ([[[info draggingPasteboard] types] containsObject:@"AllTableViewPboardType"]) {
802 return NSDragOperationNone;
805 if ([[[info draggingPasteboard] types] containsObject:@"MenuTableViewPboardType"]) {
806 NSString *item = [myItems objectAtIndex:[[[info draggingPasteboard] stringForType:@"MenuTableViewPboardType"] intValue]];
807 if ([item isEqualToString:@"Preferences"] || [item isEqualToString:@"Quit"]) {
808 return NSDragOperationNone;
812 [tableView setDropRow:-1 dropOperation:NSTableViewDropOn];
813 return NSDragOperationGeneric;
816 if (operation == NSTableViewDropOn || row == -1)
818 return NSDragOperationNone;
821 return NSDragOperationGeneric;
825 /*************************************************************************/
827 #pragma mark DEALLOCATION METHODS
828 /*************************************************************************/
832 [self setKeyCombo:nil];
833 [hotKeysDictionary release];
834 [keyComboPanel release];
835 [menuTableView setDataSource:nil];
836 [allTableView setDataSource:nil];
837 [controller release];
838 [availableItems release];
839 [submenuItems release];