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:
226 nil] forKey:@"menu"];
228 [df setInteger:5 forKey:@"SongsInAdvance"];
229 // [df setBool:YES forKey:@"showName"]; // Song info will always show song title.
230 [df setBool:YES forKey:@"showArtist"];
231 [df setBool:NO forKey:@"showAlbum"];
232 [df setBool:NO forKey:@"showTime"];
236 loginWindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
237 loginArray = [loginWindow objectForKey:@"AutoLaunchedApplicationDictionary"];
238 loginEnum = [loginArray objectEnumerator];
240 while ( (anItem = [loginEnum nextObject]) ) {
241 if ( [[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]] ) {
246 [loginWindow release];
249 // We must fix it so it is no longer suxy
251 if (NSRunInformationalAlertPanel(NSLocalizedString(@"autolaunch", @"Auto-launch MenuTunes"), NSLocalizedString(@"autolaunch_msg", @"Would you like MenuTunes to automatically launch at login?"), @"Yes", @"No", nil) == NSOKButton) {
252 AEDesc scriptDesc, resultDesc;
253 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]];
254 ComponentInstance asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
256 AECreateDesc(typeChar, [script cString], [script cStringLength],
259 OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
261 AEDisposeDesc(&scriptDesc);
262 AEDisposeDesc(&resultDesc);
264 CloseComponent(asComponent);
269 - (IBAction)cancelHotKey:(id)sender
271 [[NSNotificationCenter defaultCenter] removeObserver:self];
272 [NSApp endSheet:keyComboPanel];
273 [keyComboPanel orderOut:nil];
276 - (IBAction)clearHotKey:(id)sender
278 [self setKeyCombo:[KeyCombo clearKeyCombo]];
281 - (IBAction)okHotKey:(id)sender
283 NSString *string = [combo userDisplayRep];
284 NSEnumerator *enumerator = [hotKeysDictionary keyEnumerator];
291 while ( (enumKey = [enumerator nextObject]) ) {
292 if (![enumKey isEqualToString:currentHotKey]) {
293 if (![combo isEqual:[KeyCombo clearKeyCombo]] &&
294 [combo isEqual:[hotKeysDictionary objectForKey:enumKey]]) {
295 [window setLevel:NSNormalWindowLevel];
296 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) ) {
297 [hotKeysDictionary setObject:[KeyCombo clearKeyCombo] forKey:currentHotKey];
298 if ([enumKey isEqualToString:@"PlayPause"]) {
299 [playPauseButton setTitle:@""];
300 } else if ([enumKey isEqualToString:@"NextTrack"]) {
301 [nextTrackButton setTitle:@""];
302 } else if ([enumKey isEqualToString:@"PrevTrack"]) {
303 [previousTrackButton setTitle:@""];
304 } else if ([enumKey isEqualToString:@"ShowPlayer"]) {
305 [showPlayerButton setTitle:@""];
306 } else if ([enumKey isEqualToString:@"TrackInfo"]) {
307 [trackInfoButton setTitle:@""];
308 } else if ([enumKey isEqualToString:@"UpcomingSongs"]) {
309 [upcomingSongsButton setTitle:@""];
310 } else if ([enumKey isEqualToString:@"IncrementVolume"]) {
311 [volumeIncrementButton setTitle:@""];
312 } else if ([enumKey isEqualToString:@"DecrementVolume"]) {
313 [volumeDecrementButton setTitle:@""];
314 } else if ([enumKey isEqualToString:@"IncrementRating"]) {
315 [ratingIncrementButton setTitle:@""];
316 } else if ([enumKey isEqualToString:@"DecrementRating"]) {
317 [ratingDecrementButton setTitle:@""];
318 } else if ([enumKey isEqualToString:@"ToggleShuffle"]) {
319 [toggleShuffleButton setTitle:@""];
320 } else if ([enumKey isEqualToString:@"ToggleLoop"]) {
321 [toggleLoopButton setTitle:@""];
323 [df setKeyCombo:[KeyCombo clearKeyCombo] forKey:enumKey];
327 [window setLevel:NSStatusWindowLevel];
332 [hotKeysDictionary setObject:combo forKey:currentHotKey];
333 [df setKeyCombo:combo forKey:currentHotKey];
335 if ([currentHotKey isEqualToString:@"PlayPause"]) {
336 [playPauseButton setTitle:string];
337 [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause" combo:combo target:[MainController sharedController] action:@selector(playPause)];
338 } else if ([currentHotKey isEqualToString:@"NextTrack"]) {
339 [nextTrackButton setTitle:string];
340 [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack" combo:combo target:[MainController sharedController] action:@selector(nextSong)];
341 } else if ([currentHotKey isEqualToString:@"PrevTrack"]) {
342 [previousTrackButton setTitle:string];
343 [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack" combo:combo target:[MainController sharedController] action:@selector(prevSong)];
344 } else if ([currentHotKey isEqualToString:@"ShowPlayer"]) {
345 [showPlayerButton setTitle:string];
346 [[HotKeyCenter sharedCenter] addHotKey:@"ShowPlayer" combo:combo target:[MainController sharedController] action:@selector(showPlayer)];
347 } else if ([currentHotKey isEqualToString:@"TrackInfo"]) {
348 [trackInfoButton setTitle:string];
349 [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo" combo:combo target:[MainController sharedController] action:@selector(showCurrentTrackInfo)];
350 } else if ([currentHotKey isEqualToString:@"UpcomingSongs"]) {
351 [upcomingSongsButton setTitle:string];
352 [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs" combo:combo target:[MainController sharedController] action:@selector(showUpcomingSongs)];
353 } else if ([currentHotKey isEqualToString:@"IncrementVolume"]) {
354 [volumeIncrementButton setTitle:string];
355 [[HotKeyCenter sharedCenter] addHotKey:@"IncrementVolume" combo:combo target:[MainController sharedController] action:@selector(incrementVolume)];
356 } else if ([currentHotKey isEqualToString:@"DecrementVolume"]) {
357 [volumeDecrementButton setTitle:string];
358 [[HotKeyCenter sharedCenter] addHotKey:@"DecrementVolume" combo:combo target:[MainController sharedController] action:@selector(decrementVolume)];
359 } else if ([currentHotKey isEqualToString:@"IncrementRating"]) {
360 [ratingIncrementButton setTitle:string];
361 [[HotKeyCenter sharedCenter] addHotKey:@"IncrementRating" combo:combo target:[MainController sharedController] action:@selector(incrementRating)];
362 } else if ([currentHotKey isEqualToString:@"DecrementRating"]) {
363 [ratingDecrementButton setTitle:string];
364 [[HotKeyCenter sharedCenter] addHotKey:@"DecrementRating" combo:combo target:[MainController sharedController] action:@selector(decrementRating)];
365 } else if ([currentHotKey isEqualToString:@"ToggleShuffle"]) {
366 [toggleShuffleButton setTitle:string];
367 [[HotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle" combo:combo target:[MainController sharedController] action:@selector(toggleShuffle)];
368 } else if ([currentHotKey isEqualToString:@"ToggleLoop"]) {
369 [toggleLoopButton setTitle:string];
370 [[HotKeyCenter sharedCenter] addHotKey:@"ToggleLoop" combo:combo target:[MainController sharedController] action:@selector(toggleLoop)];
372 [self cancelHotKey:sender];
377 /*************************************************************************/
379 #pragma mark HOTKEY SUPPORT METHODS
380 /*************************************************************************/
382 - (void)setCurrentHotKey:(NSString *)key
384 [currentHotKey autorelease];
385 currentHotKey = [key copy];
386 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyEvent:) name:@"KeyBroadcasterEvent" object:nil];
387 [NSApp beginSheet:keyComboPanel modalForWindow:window modalDelegate:self didEndSelector:nil contextInfo:nil];
390 - (void)keyEvent:(NSNotification *)note
392 NSDictionary *info = [note userInfo];
397 keyCode = [[info objectForKey:@"KeyCode"] shortValue];
398 modifiers = [[info objectForKey:@"Modifiers"] longValue];
400 newCombo = [[KeyCombo alloc] initWithKeyCode:keyCode andModifiers:modifiers];
401 [self setKeyCombo:newCombo];
404 - (void)setKeyCombo:(KeyCombo *)newCombo
408 combo = [newCombo copy];
410 string = [combo userDisplayRep];
414 [keyComboField setStringValue:string];
418 /*************************************************************************/
420 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
421 /*************************************************************************/
425 if (![NSBundle loadNibNamed:@"Preferences" owner:self]) {
426 NSLog(@"MenuTunes: Failed to load Preferences.nib");
432 - (void)setupCustomizationTables
434 NSImageCell *imgCell = [[[NSImageCell alloc] initImageCell:nil] autorelease];
436 // Set the table view cells up
437 [imgCell setImageScaling:NSScaleNone];
438 [[menuTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
439 [[allTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
441 // Register for drag and drop
442 [menuTableView registerForDraggedTypes:[NSArray arrayWithObjects:
443 @"MenuTableViewPboardType",
444 @"AllTableViewPboardType",
446 [allTableView registerForDraggedTypes:[NSArray arrayWithObjects:
447 @"MenuTableViewPboardType",
448 @"AllTableViewPboardType",
452 - (void)setupMenuItems
454 NSEnumerator *itemEnum;
456 // Set the list of items you can have.
457 availableItems = [[NSMutableArray alloc] initWithObjects:
472 // Get our preferred menu
473 myItems = [[df arrayForKey:@"menu"] mutableCopy];
475 // Delete items in the availableItems array that are already part of the menu
476 itemEnum = [myItems objectEnumerator];
477 while ( (anItem = [itemEnum nextObject]) ) {
478 if (![anItem isEqualToString:@"separator"]) {
479 [availableItems removeObject:anItem];
483 // Items that show should a submenu image
484 submenuItems = [[NSArray alloc] initWithObjects:
494 NSMutableDictionary *loginwindow;
495 NSMutableArray *loginarray;
496 NSEnumerator *loginEnum;
499 // Fill in the number of songs in advance to show field
500 [songsInAdvance setIntValue:[df integerForKey:@"SongsInAdvance"]];
502 // Fill in hot key buttons
503 if ([df objectForKey:@"PlayPause"]) {
504 anItem = [df keyComboForKey:@"PlayPause"];
505 [hotKeysDictionary setObject:anItem forKey:@"PlayPause"];
506 [playPauseButton setTitle:[anItem userDisplayRep]];
508 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"PlayPause"];
511 if ([df objectForKey:@"NextTrack"]) {
512 anItem = [df keyComboForKey:@"NextTrack"];
513 [hotKeysDictionary setObject:anItem forKey:@"NextTrack"];
514 [nextTrackButton setTitle:[anItem userDisplayRep]];
516 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"NextTrack"];
519 if ([df objectForKey:@"PrevTrack"]) {
520 anItem = [df keyComboForKey:@"PrevTrack"];
521 [hotKeysDictionary setObject:anItem forKey:@"PrevTrack"];
522 [previousTrackButton setTitle:[anItem userDisplayRep]];
524 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"PrevTrack"];
527 if ([df objectForKey:@"ShowPlayer"]) {
528 anItem = [df keyComboForKey:@"ShowPlayer"];
529 [hotKeysDictionary setObject:anItem forKey:@"ShowPlayer"];
530 [showPlayerButton setTitle:[anItem userDisplayRep]];
532 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ShowPlayer"];
535 if ([df objectForKey:@"TrackInfo"]) {
536 anItem = [df keyComboForKey:@"TrackInfo"];
537 [hotKeysDictionary setObject:anItem forKey:@"TrackInfo"];
538 [trackInfoButton setTitle:[anItem userDisplayRep]];
540 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"TrackInfo"];
543 if ([df objectForKey:@"UpcomingSongs"]) {
544 anItem = [df keyComboForKey:@"UpcomingSongs"];
545 [hotKeysDictionary setObject:anItem forKey:@"UpcomingSongs"];
546 [upcomingSongsButton setTitle:[anItem userDisplayRep]];
548 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"UpcomingSongs"];
551 if ([df objectForKey:@"IncrementVolume"]) {
552 anItem = [df keyComboForKey:@"IncrementVolume"];
553 [hotKeysDictionary setObject:anItem forKey:@"IncrementVolume"];
554 [volumeIncrementButton setTitle:[anItem userDisplayRep]];
556 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"IncrementVolume"];
559 if ([df objectForKey:@"DecrementVolume"]) {
560 anItem = [df keyComboForKey:@"DecrementVolume"];
561 [hotKeysDictionary setObject:anItem forKey:@"DecrementVolume"];
562 [volumeDecrementButton setTitle:[anItem userDisplayRep]];
564 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"DecrementVolume"];
567 if ([df objectForKey:@"IncrementRating"]) {
568 anItem = [df keyComboForKey:@"IncrementRating"];
569 [hotKeysDictionary setObject:anItem forKey:@"IncrementRating"];
570 [ratingIncrementButton setTitle:[anItem userDisplayRep]];
572 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"IncrementRating"];
575 if ([df objectForKey:@"DecrementRating"]) {
576 anItem = [df keyComboForKey:@"DecrementRating"];
577 [hotKeysDictionary setObject:anItem forKey:@"DecrementRating"];
578 [ratingDecrementButton setTitle:[anItem userDisplayRep]];
580 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"DecrementRating"];
583 if ([df objectForKey:@"ToggleLoop"]) {
584 anItem = [df keyComboForKey:@"ToggleLoop"];
585 [hotKeysDictionary setObject:anItem forKey:@"ToggleLoop"];
586 [toggleLoopButton setTitle:[anItem userDisplayRep]];
588 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleLoop"];
591 if ([df objectForKey:@"ToggleShuffle"]) {
592 anItem = [df keyComboForKey:@"ToggleShuffle"];
593 [hotKeysDictionary setObject:anItem forKey:@"ToggleShuffle"];
594 [toggleShuffleButton setTitle:[anItem userDisplayRep]];
596 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleShuffle"];
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];
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];
775 [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];