1 #import "PreferencesController.h"
2 #import "NewMainController.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 switch ([sender tag])
151 [self setKeyCombo:[hotKeysDictionary objectForKey:@"PlayPause"]];
152 [self setCurrentHotKey:@"PlayPause"];
155 [self setKeyCombo:[hotKeysDictionary objectForKey:@"NextTrack"]];
156 [self setCurrentHotKey:@"NextTrack"];
159 [self setKeyCombo:[hotKeysDictionary objectForKey:@"PrevTrack"]];
160 [self setCurrentHotKey:@"PrevTrack"];
163 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ShowPlayer"]];
164 [self setCurrentHotKey:@"ShowPlayer"];
167 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleLoop"]];
168 [self setCurrentHotKey:@"ToggleLoop"];
171 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleShuffle"]];
172 [self setCurrentHotKey:@"ToggleShuffle"];
175 [self setKeyCombo:[hotKeysDictionary objectForKey:@"TrackInfo"]];
176 [self setCurrentHotKey:@"TrackInfo"];
179 [self setKeyCombo:[hotKeysDictionary objectForKey:@"UpcomingSongs"]];
180 [self setCurrentHotKey:@"UpcomingSongs"];
183 [self setKeyCombo:[hotKeysDictionary objectForKey:@"IncrementVolume"]];
184 [self setCurrentHotKey:@"IncrementVolume"];
187 [self setKeyCombo:[hotKeysDictionary objectForKey:@"DecrementVolume"]];
188 [self setCurrentHotKey:@"DecrementVolume"];
191 [self setKeyCombo:[hotKeysDictionary objectForKey:@"IncrementRating"]];
192 [self setCurrentHotKey:@"IncrementRating"];
195 [self setKeyCombo:[hotKeysDictionary objectForKey:@"DecrementRating"]];
196 [self setCurrentHotKey:@"DecrementRating"];
201 - (void)registerDefaults
204 NSMutableDictionary *loginWindow;
205 NSMutableArray *loginArray;
206 NSEnumerator *loginEnum;
209 [df setObject:[NSArray arrayWithObjects:
224 @"Current Track Info",
225 nil] forKey:@"menu"];
227 [df setInteger:5 forKey:@"SongsInAdvance"];
228 // [df setBool:YES forKey:@"showName"]; // Song info will always show song title.
229 [df setBool:YES forKey:@"showArtist"];
230 [df setBool:NO forKey:@"showAlbum"];
231 [df setBool:NO forKey:@"showTime"];
235 loginWindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
236 loginArray = [loginWindow objectForKey:@"AutoLaunchedApplicationDictionary"];
237 loginEnum = [loginArray objectEnumerator];
239 while ( (anItem = [loginEnum nextObject]) ) {
240 if ( [[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]] ) {
245 [loginWindow release];
248 // We must fix it so it is no longer suxy
250 if (NSRunInformationalAlertPanel(@"Auto-launch MenuTunes", @"Would you like MenuTunes to automatically launch at login?", @"Yes", @"No", nil) == NSOKButton) {
251 AEDesc scriptDesc, resultDesc;
252 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]];
253 ComponentInstance asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
255 AECreateDesc(typeChar, [script cString], [script cStringLength],
258 OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
260 AEDisposeDesc(&scriptDesc);
261 AEDisposeDesc(&resultDesc);
263 CloseComponent(asComponent);
268 - (IBAction)cancelHotKey:(id)sender
270 [[NSNotificationCenter defaultCenter] removeObserver:self];
271 [NSApp endSheet:keyComboPanel];
272 [keyComboPanel orderOut:nil];
275 - (IBAction)clearHotKey:(id)sender
277 [self setKeyCombo:[KeyCombo clearKeyCombo]];
280 - (IBAction)okHotKey:(id)sender
282 NSString *string = [combo userDisplayRep];
283 NSEnumerator *enumerator = [hotKeysDictionary keyEnumerator];
290 while ( (enumKey = [enumerator nextObject]) ) {
291 if (![enumKey isEqualToString:currentHotKey]) {
292 if (![combo isEqual:[KeyCombo clearKeyCombo]] &&
293 [combo isEqual:[hotKeysDictionary objectForKey:enumKey]]) {
294 [window setLevel:NSNormalWindowLevel];
295 if ( NSRunAlertPanel(@"Duplicate Key Combo", @"The specified key combo is already in use...", @"Replace", @"Cancel", nil) ) {
296 [hotKeysDictionary setObject:[KeyCombo clearKeyCombo] forKey:currentHotKey];
297 if ([enumKey isEqualToString:@"PlayPause"]) {
298 [playPauseButton setTitle:@""];
299 } else if ([enumKey isEqualToString:@"NextTrack"]) {
300 [nextTrackButton setTitle:@""];
301 } else if ([enumKey isEqualToString:@"PrevTrack"]) {
302 [previousTrackButton setTitle:@""];
303 } else if ([enumKey isEqualToString:@"ShowPlayer"]) {
304 [showPlayerButton setTitle:@""];
305 } else if ([enumKey isEqualToString:@"TrackInfo"]) {
306 [trackInfoButton setTitle:@""];
307 } else if ([enumKey isEqualToString:@"UpcomingSongs"]) {
308 [upcomingSongsButton setTitle:@""];
309 } else if ([enumKey isEqualToString:@"IncrementVolume"]) {
310 [volumeIncrementButton setTitle:@""];
311 } else if ([enumKey isEqualToString:@"DecrementVolume"]) {
312 [volumeDecrementButton setTitle:@""];
313 } else if ([enumKey isEqualToString:@"IncrementRating"]) {
314 [ratingIncrementButton setTitle:@""];
315 } else if ([enumKey isEqualToString:@"DecrementRating"]) {
316 [ratingDecrementButton setTitle:@""];
317 } else if ([enumKey isEqualToString:@"ToggleShuffle"]) {
318 [toggleShuffleButton setTitle:@""];
319 } else if ([enumKey isEqualToString:@"ToggleLoop"]) {
320 [toggleLoopButton setTitle:@""];
322 [df setKeyCombo:[KeyCombo clearKeyCombo] forKey:enumKey];
326 [window setLevel:NSStatusWindowLevel];
331 [hotKeysDictionary setObject:combo forKey:currentHotKey];
332 [df setKeyCombo:combo forKey:currentHotKey];
334 if ([currentHotKey isEqualToString:@"PlayPause"]) {
335 [playPauseButton setTitle:string];
336 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause" combo:combo target:[MainController sharedController] action:@selector(playPause)];
337 } else if ([currentHotKey isEqualToString:@"NextTrack"]) {
338 [nextTrackButton setTitle:string];
339 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack" combo:combo target:[MainController sharedController] action:@selector(nextSong)];
340 } else if ([currentHotKey isEqualToString:@"PrevTrack"]) {
341 [previousTrackButton setTitle:string];
342 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack" combo:combo target:[MainController sharedController] action:@selector(prevSong)];
343 } else if ([currentHotKey isEqualToString:@"ShowPlayer"]) {
344 [showPlayerButton setTitle:string];
345 [[HotKeyCenter sharedCenter] addHotKey:@"ShowPlayer" combo:combo target:[MainController sharedController] action:@selector(showPlayer)];
346 } else if ([currentHotKey isEqualToString:@"TrackInfo"]) {
347 [trackInfoButton setTitle:string];
348 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo" combo:combo target:[MainController sharedController] action:@selector(showCurrentTrackInfo)];
349 } else if ([currentHotKey isEqualToString:@"UpcomingSongs"]) {
350 [upcomingSongsButton setTitle:string];
351 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs" combo:combo target:[MainController sharedController] action:@selector(showUpcomingSongs)];
352 } else if ([currentHotKey isEqualToString:@"IncrementVolume"]) {
353 [volumeIncrementButton setTitle:string];
354 [[HotKeyCenter sharedCenter] addHotKey:@"IncrementVolume" combo:combo target:[MainController sharedController] action:@selector(incrementVolume)];
355 } else if ([currentHotKey isEqualToString:@"DecrementVolume"]) {
356 [volumeDecrementButton setTitle:string];
357 [[HotKeyCenter sharedCenter] addHotKey:@"DecrementVolume" combo:combo target:[MainController sharedController] action:@selector(decrementVolume)];
358 } else if ([currentHotKey isEqualToString:@"IncrementRating"]) {
359 [ratingIncrementButton setTitle:string];
360 [[HotKeyCenter sharedCenter] addHotKey:@"IncrementRating" combo:combo target:[MainController sharedController] action:@selector(incrementRating)];
361 } else if ([currentHotKey isEqualToString:@"DecrementRating"]) {
362 [ratingDecrementButton setTitle:string];
363 [[HotKeyCenter sharedCenter] addHotKey:@"DecrementRating" combo:combo target:[MainController sharedController] action:@selector(decrementRating)];
364 } else if ([currentHotKey isEqualToString:@"ToggleShuffle"]) {
365 [toggleShuffleButton setTitle:string];
366 [[HotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle" combo:combo target:[MainController sharedController] action:@selector(toggleShuffle)];
367 } else if ([currentHotKey isEqualToString:@"ToggleLoop"]) {
368 [toggleLoopButton setTitle:string];
369 [[HotKeyCenter sharedCenter] addHotKey:@"ToggleLoop" combo:combo target:[MainController sharedController] action:@selector(toggleLoop)];
371 [self cancelHotKey:sender];
376 /*************************************************************************/
378 #pragma mark HOTKEY SUPPORT METHODS
379 /*************************************************************************/
381 - (void)setCurrentHotKey:(NSString *)key
383 [currentHotKey autorelease];
384 currentHotKey = [key copy];
385 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyEvent:) name:@"KeyBroadcasterEvent" object:nil];
386 [NSApp beginSheet:keyComboPanel modalForWindow:window modalDelegate:self didEndSelector:nil contextInfo:nil];
389 - (void)keyEvent:(NSNotification *)note
391 NSDictionary *info = [note userInfo];
396 keyCode = [[info objectForKey:@"KeyCode"] shortValue];
397 modifiers = [[info objectForKey:@"Modifiers"] longValue];
399 newCombo = [[KeyCombo alloc] initWithKeyCode:keyCode andModifiers:modifiers];
400 [self setKeyCombo:newCombo];
403 - (void)setKeyCombo:(KeyCombo *)newCombo
407 combo = [newCombo copy];
409 string = [combo userDisplayRep];
413 [keyComboField setStringValue:string];
417 /*************************************************************************/
419 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
420 /*************************************************************************/
424 if ( ! [NSBundle loadNibNamed:@"Preferences" owner:self] ) {
425 NSLog( @"Failed to load Preferences.nib" );
431 - (void)setupCustomizationTables
433 NSImageCell *imgCell = [[[NSImageCell alloc] initImageCell:nil] autorelease];
435 // Set the table view cells up
436 [imgCell setImageScaling:NSScaleNone];
437 [[menuTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
438 [[allTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
440 // Register for drag and drop
441 [menuTableView registerForDraggedTypes:[NSArray arrayWithObjects:
442 @"MenuTableViewPboardType",
443 @"AllTableViewPboardType",
445 [allTableView registerForDraggedTypes:[NSArray arrayWithObjects:
446 @"MenuTableViewPboardType",
447 @"AllTableViewPboardType",
451 - (void)setupMenuItems
453 NSEnumerator *itemEnum;
455 // Set the list of items you can have.
456 availableItems = [[NSMutableArray alloc] initWithObjects:
457 @"Current Track Info",
471 // Get our preferred menu
472 myItems = [[df arrayForKey:@"menu"] mutableCopy];
474 // Delete items in the availableItems array that are already part of the menu
475 itemEnum = [myItems objectEnumerator];
476 while ( (anItem = [itemEnum nextObject]) ) {
477 if ( ! [anItem isEqualToString:@"<separator>"] ) {
478 [availableItems removeObject:anItem];
482 // Items that show should a submenu image
483 submenuItems = [[NSArray alloc] initWithObjects:
493 NSMutableDictionary *loginwindow;
494 NSMutableArray *loginarray;
495 NSEnumerator *loginEnum;
498 // Fill in the number of songs in advance to show field
499 [songsInAdvance setIntValue:[df integerForKey:@"SongsInAdvance"]];
501 // Fill in hot key buttons
502 if ([df objectForKey:@"PlayPause"]){
503 anItem = [df keyComboForKey:@"PlayPause"];
504 [hotKeysDictionary setObject:anItem forKey:@"PlayPause"];
505 [playPauseButton setTitle:[anItem userDisplayRep]];
507 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"PlayPause"];
510 if ([df objectForKey:@"NextTrack"]) {
511 anItem = [df keyComboForKey:@"NextTrack"];
512 [hotKeysDictionary setObject:anItem forKey:@"NextTrack"];
513 [nextTrackButton setTitle:[anItem userDisplayRep]];
515 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"NextTrack"];
518 if ([df objectForKey:@"PrevTrack"]) {
519 anItem = [df keyComboForKey:@"PrevTrack"];
520 [hotKeysDictionary setObject:anItem forKey:@"PrevTrack"];
521 [previousTrackButton setTitle:[anItem userDisplayRep]];
523 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"PrevTrack"];
526 if ([df objectForKey:@"ShowPlayer"]) {
527 anItem = [df keyComboForKey:@"ShowPlayer"];
528 [hotKeysDictionary setObject:anItem forKey:@"ShowPlayer"];
529 [showPlayerButton setTitle:[anItem userDisplayRep]];
531 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ShowPlayer"];
534 if ([df objectForKey:@"TrackInfo"]) {
535 anItem = [df keyComboForKey:@"TrackInfo"];
536 [hotKeysDictionary setObject:anItem forKey:@"TrackInfo"];
537 [trackInfoButton setTitle:[anItem userDisplayRep]];
539 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"TrackInfo"];
542 if ([df objectForKey:@"UpcomingSongs"]) {
543 anItem = [df keyComboForKey:@"UpcomingSongs"];
544 [hotKeysDictionary setObject:anItem forKey:@"UpcomingSongs"];
545 [upcomingSongsButton setTitle:[anItem userDisplayRep]];
547 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"UpcomingSongs"];
550 if ([df objectForKey:@"IncrementVolume"]) {
551 anItem = [df keyComboForKey:@"IncrementVolume"];
552 [hotKeysDictionary setObject:anItem forKey:@"IncrementVolume"];
553 [volumeIncrementButton setTitle:[anItem userDisplayRep]];
555 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"IncrementVolume"];
558 if ([df objectForKey:@"DecrementVolume"]) {
559 anItem = [df keyComboForKey:@"DecrementVolume"];
560 [hotKeysDictionary setObject:anItem forKey:@"DecrementVolume"];
561 [volumeDecrementButton setTitle:[anItem userDisplayRep]];
563 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"DecrementVolume"];
566 if ([df objectForKey:@"IncrementRating"]) {
567 anItem = [df keyComboForKey:@"IncrementRating"];
568 [hotKeysDictionary setObject:anItem forKey:@"IncrementRating"];
569 [ratingIncrementButton setTitle:[anItem userDisplayRep]];
571 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"IncrementRating"];
574 if ([df objectForKey:@"DecrementRating"]) {
575 anItem = [df keyComboForKey:@"DecrementRating"];
576 [hotKeysDictionary setObject:anItem forKey:@"DecrementRating"];
577 [ratingDecrementButton setTitle:[anItem userDisplayRep]];
579 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"DecrementRating"];
582 if ([df objectForKey:@"ToggleLoop"]) {
583 anItem = [df keyComboForKey:@"ToggleLoop"];
584 [hotKeysDictionary setObject:anItem forKey:@"ToggleLoop"];
585 [toggleLoopButton setTitle:[anItem userDisplayRep]];
587 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleLoop"];
590 if ([df objectForKey:@"ToggleShuffle"]) {
591 anItem = [df keyComboForKey:@"ToggleShuffle"];
592 [hotKeysDictionary setObject:anItem forKey:@"ToggleShuffle"];
593 [toggleShuffleButton setTitle:[anItem userDisplayRep]];
595 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleShuffle"];
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:@"Show %@", [[controller currentRemote] playerSimpleName]];
716 if ([submenuItems containsObject:[myItems objectAtIndex:rowIndex]])
718 return [NSImage imageNamed:@"submenu"];
724 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
725 return [availableItems objectAtIndex:rowIndex];
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];
764 [myItems removeObjectAtIndex:dragRow];
766 if (tableView == menuTableView) {
768 [myItems insertObject:temp atIndex:row - 1];
770 [myItems insertObject:temp atIndex:row];
773 if (![temp isEqualToString:@"<separator>"]) {
774 [availableItems addObject:temp];
777 } else if ([[pb types] containsObject:@"AllTableViewPboardType"]) {
778 dragData = [pb stringForType:@"AllTableViewPboardType"];
779 dragRow = [dragData intValue];
780 temp = [availableItems objectAtIndex:dragRow];
782 if (![temp isEqualToString:@"<separator>"]) {
783 [availableItems removeObjectAtIndex:dragRow];
785 [myItems insertObject:temp atIndex:row];
788 [menuTableView reloadData];
789 [allTableView reloadData];
790 [self changeMenus:self];
794 - (NSDragOperation)tableView:(NSTableView*)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)operation
796 if (tableView == allTableView) {
797 if ([[[info draggingPasteboard] types] containsObject:@"AllTableViewPboardType"]) {
798 return NSDragOperationNone;
801 if ([[[info draggingPasteboard] types] containsObject:@"MenuTableViewPboardType"]) {
802 NSString *item = [myItems objectAtIndex:[[[info draggingPasteboard] stringForType:@"MenuTableViewPboardType"] intValue]];
803 if ([item isEqualToString:@"Preferences"] || [item isEqualToString:@"Quit"]) {
804 return NSDragOperationNone;
808 [tableView setDropRow:-1 dropOperation:NSTableViewDropOn];
809 return NSDragOperationGeneric;
812 if (operation == NSTableViewDropOn || row == -1)
814 return NSDragOperationNone;
817 return NSDragOperationGeneric;
821 /*************************************************************************/
823 #pragma mark DEALLOCATION METHODS
824 /*************************************************************************/
828 [self setKeyCombo:nil];
829 [hotKeysDictionary release];
830 [keyComboPanel release];
831 [menuTableView setDataSource:nil];
832 [allTableView setDataSource:nil];
833 [controller release];
834 [availableItems release];
835 [submenuItems release];