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];
88 [menuTableView reloadData];
90 //Change the launch player checkbox to the proper name
91 [launchPlayerAtLaunchCheckbox setTitle:[NSString stringWithFormat:@"Launch %@ when MenuTunes launches", [[controller currentRemote] playerSimpleName]]]; //This isn't localized...
94 [window setLevel:NSStatusWindowLevel];
96 [window makeKeyAndOrderFront:self];
97 [NSApp activateIgnoringOtherApps:YES];
100 - (IBAction)changeGeneralSetting:(id)sender
102 if ( [sender tag] == 1010) {
103 [self setLaunchesAtLogin:SENDER_STATE];
104 } else if ( [sender tag] == 1020) {
105 [df setBool:SENDER_STATE forKey:@"LaunchPlayerWithMT"];
106 } else if ( [sender tag] == 1030) {
107 [df setInteger:[sender intValue] forKey:@"SongsInAdvance"];
109 } else if ( [sender tag] == 1040) {
110 // This will not be executed. Song info always shows the title of the song.
111 // [df setBool:SENDER_STATE forKey:@"showName"];
112 } else if ( [sender tag] == 1050) {
113 [df setBool:SENDER_STATE forKey:@"showArtist"];
114 } else if ( [sender tag] == 1060) {
115 [df setBool:SENDER_STATE forKey:@"showAlbum"];
116 } else if ( [sender tag] == 1070) {
117 [df setBool:SENDER_STATE forKey:@"showTime"];
118 } else if ( [sender tag] == 1080) {
119 [df setBool:SENDER_STATE forKey:@"showTrackNumber"];
120 } else if ( [sender tag] == 1090) {
121 [df setBool:SENDER_STATE forKey:@"showTrackRating"];
126 - (IBAction)changeStatusWindowSetting:(id)sender
128 if ( [sender tag] == 2010) {
129 [df setInteger:[sender selectedRow] forKey:@"statusWindowVerticalPosition"];
130 [df setInteger:[sender selectedColumn] forKey:@"statusWindowHorizontalPosition"];
131 // update the window's position here
132 } else if ( [sender tag] == 2020) {
133 // update screen selection
134 } else if ( [sender tag] == 2030) {
135 // Update appearance effect
136 } else if ( [sender tag] == 2040) {
137 // Update Vanish Effect
138 } else if ( [sender tag] == 2050) {
139 // Update appearance speed
140 } else if ( [sender tag] == 2060) {
141 // Update vanish speed
142 } else if ( [sender tag] == 2070) {
143 // Update vanish delay
144 } else if ( [sender tag] == 2080) {
145 // Update "Song Info window when song changes" setting.
146 [df setBool:SENDER_STATE forKey:@"showSongInfoOnChange"];
150 - (IBAction)changeHotKey:(id)sender
152 [controller clearHotKeys];
153 switch ([sender tag])
156 [self setKeyCombo:[hotKeysDictionary objectForKey:@"PlayPause"]];
157 [self setCurrentHotKey:@"PlayPause"];
160 [self setKeyCombo:[hotKeysDictionary objectForKey:@"NextTrack"]];
161 [self setCurrentHotKey:@"NextTrack"];
164 [self setKeyCombo:[hotKeysDictionary objectForKey:@"PrevTrack"]];
165 [self setCurrentHotKey:@"PrevTrack"];
168 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ShowPlayer"]];
169 [self setCurrentHotKey:@"ShowPlayer"];
172 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleLoop"]];
173 [self setCurrentHotKey:@"ToggleLoop"];
176 [self setKeyCombo:[hotKeysDictionary objectForKey:@"ToggleShuffle"]];
177 [self setCurrentHotKey:@"ToggleShuffle"];
180 [self setKeyCombo:[hotKeysDictionary objectForKey:@"TrackInfo"]];
181 [self setCurrentHotKey:@"TrackInfo"];
184 [self setKeyCombo:[hotKeysDictionary objectForKey:@"UpcomingSongs"]];
185 [self setCurrentHotKey:@"UpcomingSongs"];
188 [self setKeyCombo:[hotKeysDictionary objectForKey:@"IncrementVolume"]];
189 [self setCurrentHotKey:@"IncrementVolume"];
192 [self setKeyCombo:[hotKeysDictionary objectForKey:@"DecrementVolume"]];
193 [self setCurrentHotKey:@"DecrementVolume"];
196 [self setKeyCombo:[hotKeysDictionary objectForKey:@"IncrementRating"]];
197 [self setCurrentHotKey:@"IncrementRating"];
200 [self setKeyCombo:[hotKeysDictionary objectForKey:@"DecrementRating"]];
201 [self setCurrentHotKey:@"DecrementRating"];
206 - (void)registerDefaults
209 NSMutableDictionary *loginWindow;
210 NSMutableArray *loginArray;
211 NSEnumerator *loginEnum;
214 [df setObject:[NSArray arrayWithObjects:
231 nil] forKey:@"menu"];
233 [df setInteger:5 forKey:@"SongsInAdvance"];
234 // [df setBool:YES forKey:@"showName"]; // Song info will always show song title.
235 [df setBool:YES forKey:@"showArtist"];
236 [df setBool:NO forKey:@"showAlbum"];
237 [df setBool:NO forKey:@"showTime"];
241 loginWindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
242 loginArray = [loginWindow objectForKey:@"AutoLaunchedApplicationDictionary"];
243 loginEnum = [loginArray objectEnumerator];
245 while ( (anItem = [loginEnum nextObject]) ) {
246 if ( [[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]] ) {
251 [loginWindow release];
254 // We must fix it so it is no longer suxy
256 if (NSRunInformationalAlertPanel(NSLocalizedString(@"autolaunch", @"Auto-launch MenuTunes"), NSLocalizedString(@"autolaunch_msg", @"Would you like MenuTunes to automatically launch at login?"), @"Yes", @"No", nil) == NSOKButton) {
257 AEDesc scriptDesc, resultDesc;
258 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]];
259 ComponentInstance asComponent = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
261 AECreateDesc(typeChar, [script cString], [script cStringLength],
264 OSADoScript(asComponent, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
266 AEDisposeDesc(&scriptDesc);
267 AEDisposeDesc(&resultDesc);
269 CloseComponent(asComponent);
274 - (IBAction)cancelHotKey:(id)sender
276 [[NSNotificationCenter defaultCenter] removeObserver:self];
277 [NSApp endSheet:keyComboPanel];
278 [keyComboPanel orderOut:nil];
281 - (IBAction)clearHotKey:(id)sender
283 [self setKeyCombo:[KeyCombo clearKeyCombo]];
286 - (IBAction)okHotKey:(id)sender
288 NSString *string = [combo userDisplayRep];
289 NSEnumerator *enumerator = [hotKeysDictionary keyEnumerator];
296 while ( (enumKey = [enumerator nextObject]) ) {
297 if (![enumKey isEqualToString:currentHotKey]) {
298 if (![combo isEqual:[KeyCombo clearKeyCombo]] &&
299 [combo isEqual:[hotKeysDictionary objectForKey:enumKey]]) {
300 [window setLevel:NSNormalWindowLevel];
301 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) ) {
302 [hotKeysDictionary setObject:[KeyCombo clearKeyCombo] forKey:currentHotKey];
303 if ([enumKey isEqualToString:@"PlayPause"]) {
304 [playPauseButton setTitle:@""];
305 } else if ([enumKey isEqualToString:@"NextTrack"]) {
306 [nextTrackButton setTitle:@""];
307 } else if ([enumKey isEqualToString:@"PrevTrack"]) {
308 [previousTrackButton setTitle:@""];
309 } else if ([enumKey isEqualToString:@"ShowPlayer"]) {
310 [showPlayerButton setTitle:@""];
311 } else if ([enumKey isEqualToString:@"TrackInfo"]) {
312 [trackInfoButton setTitle:@""];
313 } else if ([enumKey isEqualToString:@"UpcomingSongs"]) {
314 [upcomingSongsButton setTitle:@""];
315 } else if ([enumKey isEqualToString:@"IncrementVolume"]) {
316 [volumeIncrementButton setTitle:@""];
317 } else if ([enumKey isEqualToString:@"DecrementVolume"]) {
318 [volumeDecrementButton setTitle:@""];
319 } else if ([enumKey isEqualToString:@"IncrementRating"]) {
320 [ratingIncrementButton setTitle:@""];
321 } else if ([enumKey isEqualToString:@"DecrementRating"]) {
322 [ratingDecrementButton setTitle:@""];
323 } else if ([enumKey isEqualToString:@"ToggleShuffle"]) {
324 [toggleShuffleButton setTitle:@""];
325 } else if ([enumKey isEqualToString:@"ToggleLoop"]) {
326 [toggleLoopButton setTitle:@""];
328 [df setKeyCombo:[KeyCombo clearKeyCombo] forKey:enumKey];
332 [window setLevel:NSStatusWindowLevel];
337 [hotKeysDictionary setObject:combo forKey:currentHotKey];
338 [df setKeyCombo:combo forKey:currentHotKey];
340 if ([currentHotKey isEqualToString:@"PlayPause"]) {
341 [playPauseButton setTitle:string];
342 //[[HotKeyCenter sharedCenter] addHotKey:@"PlayPause" combo:combo target:[MainController sharedController] action:@selector(playPause)];
343 } else if ([currentHotKey isEqualToString:@"NextTrack"]) {
344 [nextTrackButton setTitle:string];
345 //[[HotKeyCenter sharedCenter] addHotKey:@"NextTrack" combo:combo target:[MainController sharedController] action:@selector(nextSong)];
346 } else if ([currentHotKey isEqualToString:@"PrevTrack"]) {
347 [previousTrackButton setTitle:string];
348 //[[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack" combo:combo target:[MainController sharedController] action:@selector(prevSong)];
349 } else if ([currentHotKey isEqualToString:@"ShowPlayer"]) {
350 [showPlayerButton setTitle:string];
351 //[[HotKeyCenter sharedCenter] addHotKey:@"ShowPlayer" combo:combo target:[MainController sharedController] action:@selector(showPlayer)];
352 } else if ([currentHotKey isEqualToString:@"TrackInfo"]) {
353 [trackInfoButton setTitle:string];
354 //[[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo" combo:combo target:[MainController sharedController] action:@selector(showCurrentTrackInfo)];
355 } else if ([currentHotKey isEqualToString:@"UpcomingSongs"]) {
356 [upcomingSongsButton setTitle:string];
357 //[[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs" combo:combo target:[MainController sharedController] action:@selector(showUpcomingSongs)];
358 } else if ([currentHotKey isEqualToString:@"IncrementVolume"]) {
359 [volumeIncrementButton setTitle:string];
360 //[[HotKeyCenter sharedCenter] addHotKey:@"IncrementVolume" combo:combo target:[MainController sharedController] action:@selector(incrementVolume)];
361 } else if ([currentHotKey isEqualToString:@"DecrementVolume"]) {
362 [volumeDecrementButton setTitle:string];
363 //[[HotKeyCenter sharedCenter] addHotKey:@"DecrementVolume" combo:combo target:[MainController sharedController] action:@selector(decrementVolume)];
364 } else if ([currentHotKey isEqualToString:@"IncrementRating"]) {
365 [ratingIncrementButton setTitle:string];
366 //[[HotKeyCenter sharedCenter] addHotKey:@"IncrementRating" combo:combo target:[MainController sharedController] action:@selector(incrementRating)];
367 } else if ([currentHotKey isEqualToString:@"DecrementRating"]) {
368 [ratingDecrementButton setTitle:string];
369 //[[HotKeyCenter sharedCenter] addHotKey:@"DecrementRating" combo:combo target:[MainController sharedController] action:@selector(decrementRating)];
370 } else if ([currentHotKey isEqualToString:@"ToggleShuffle"]) {
371 [toggleShuffleButton setTitle:string];
372 //[[HotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle" combo:combo target:[MainController sharedController] action:@selector(toggleShuffle)];
373 } else if ([currentHotKey isEqualToString:@"ToggleLoop"]) {
374 [toggleLoopButton setTitle:string];
375 //[[HotKeyCenter sharedCenter] addHotKey:@"ToggleLoop" combo:combo target:[MainController sharedController] action:@selector(toggleLoop)];
377 [controller setupHotKeys];
378 [self cancelHotKey:sender];
383 /*************************************************************************/
385 #pragma mark HOTKEY SUPPORT METHODS
386 /*************************************************************************/
388 - (void)setCurrentHotKey:(NSString *)key
390 [currentHotKey autorelease];
391 currentHotKey = [key copy];
392 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyEvent:) name:@"KeyBroadcasterEvent" object:nil];
393 [NSApp beginSheet:keyComboPanel modalForWindow:window modalDelegate:self didEndSelector:nil contextInfo:nil];
396 - (void)keyEvent:(NSNotification *)note
398 NSDictionary *info = [note userInfo];
403 keyCode = [[info objectForKey:@"KeyCode"] shortValue];
404 modifiers = [[info objectForKey:@"Modifiers"] longValue];
406 newCombo = [[KeyCombo alloc] initWithKeyCode:keyCode andModifiers:modifiers];
407 [self setKeyCombo:newCombo];
410 - (void)setKeyCombo:(KeyCombo *)newCombo
414 combo = [newCombo copy];
416 string = [combo userDisplayRep];
420 [keyComboField setStringValue:string];
424 /*************************************************************************/
426 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
427 /*************************************************************************/
431 if (![NSBundle loadNibNamed:@"Preferences" owner:self]) {
432 NSLog(@"MenuTunes: Failed to load Preferences.nib");
438 - (void)setupCustomizationTables
440 NSImageCell *imgCell = [[[NSImageCell alloc] initImageCell:nil] autorelease];
442 // Set the table view cells up
443 [imgCell setImageScaling:NSScaleNone];
444 [[menuTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
445 [[allTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
447 // Register for drag and drop
448 [menuTableView registerForDraggedTypes:[NSArray arrayWithObjects:
449 @"MenuTableViewPboardType",
450 @"AllTableViewPboardType",
452 [allTableView registerForDraggedTypes:[NSArray arrayWithObjects:
453 @"MenuTableViewPboardType",
454 @"AllTableViewPboardType",
458 - (void)setupMenuItems
460 NSEnumerator *itemEnum;
462 // Set the list of items you can have.
463 availableItems = [[NSMutableArray alloc] initWithObjects:
478 // Get our preferred menu
479 myItems = [[df arrayForKey:@"menu"] mutableCopy];
481 // Delete items in the availableItems array that are already part of the menu
482 itemEnum = [myItems objectEnumerator];
483 while ( (anItem = [itemEnum nextObject]) ) {
484 if (![anItem isEqualToString:@"separator"]) {
485 [availableItems removeObject:anItem];
489 // Items that show should a submenu image
490 submenuItems = [[NSArray alloc] initWithObjects:
500 NSMutableDictionary *loginwindow;
501 NSMutableArray *loginarray;
502 NSEnumerator *loginEnum;
505 // Fill in the number of songs in advance to show field
506 [songsInAdvance setIntValue:[df integerForKey:@"SongsInAdvance"]];
508 // Fill in hot key buttons
509 if ([df objectForKey:@"PlayPause"]) {
510 anItem = [df keyComboForKey:@"PlayPause"];
511 [hotKeysDictionary setObject:anItem forKey:@"PlayPause"];
512 [playPauseButton setTitle:[anItem userDisplayRep]];
514 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"PlayPause"];
517 if ([df objectForKey:@"NextTrack"]) {
518 anItem = [df keyComboForKey:@"NextTrack"];
519 [hotKeysDictionary setObject:anItem forKey:@"NextTrack"];
520 [nextTrackButton setTitle:[anItem userDisplayRep]];
522 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"NextTrack"];
525 if ([df objectForKey:@"PrevTrack"]) {
526 anItem = [df keyComboForKey:@"PrevTrack"];
527 [hotKeysDictionary setObject:anItem forKey:@"PrevTrack"];
528 [previousTrackButton setTitle:[anItem userDisplayRep]];
530 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"PrevTrack"];
533 if ([df objectForKey:@"ShowPlayer"]) {
534 anItem = [df keyComboForKey:@"ShowPlayer"];
535 [hotKeysDictionary setObject:anItem forKey:@"ShowPlayer"];
536 [showPlayerButton setTitle:[anItem userDisplayRep]];
538 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ShowPlayer"];
541 if ([df objectForKey:@"TrackInfo"]) {
542 anItem = [df keyComboForKey:@"TrackInfo"];
543 [hotKeysDictionary setObject:anItem forKey:@"TrackInfo"];
544 [trackInfoButton setTitle:[anItem userDisplayRep]];
546 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"TrackInfo"];
549 if ([df objectForKey:@"UpcomingSongs"]) {
550 anItem = [df keyComboForKey:@"UpcomingSongs"];
551 [hotKeysDictionary setObject:anItem forKey:@"UpcomingSongs"];
552 [upcomingSongsButton setTitle:[anItem userDisplayRep]];
554 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"UpcomingSongs"];
557 if ([df objectForKey:@"IncrementVolume"]) {
558 anItem = [df keyComboForKey:@"IncrementVolume"];
559 [hotKeysDictionary setObject:anItem forKey:@"IncrementVolume"];
560 [volumeIncrementButton setTitle:[anItem userDisplayRep]];
562 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"IncrementVolume"];
565 if ([df objectForKey:@"DecrementVolume"]) {
566 anItem = [df keyComboForKey:@"DecrementVolume"];
567 [hotKeysDictionary setObject:anItem forKey:@"DecrementVolume"];
568 [volumeDecrementButton setTitle:[anItem userDisplayRep]];
570 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"DecrementVolume"];
573 if ([df objectForKey:@"IncrementRating"]) {
574 anItem = [df keyComboForKey:@"IncrementRating"];
575 [hotKeysDictionary setObject:anItem forKey:@"IncrementRating"];
576 [ratingIncrementButton setTitle:[anItem userDisplayRep]];
578 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"IncrementRating"];
581 if ([df objectForKey:@"DecrementRating"]) {
582 anItem = [df keyComboForKey:@"DecrementRating"];
583 [hotKeysDictionary setObject:anItem forKey:@"DecrementRating"];
584 [ratingDecrementButton setTitle:[anItem userDisplayRep]];
586 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"DecrementRating"];
589 if ([df objectForKey:@"ToggleLoop"]) {
590 anItem = [df keyComboForKey:@"ToggleLoop"];
591 [hotKeysDictionary setObject:anItem forKey:@"ToggleLoop"];
592 [toggleLoopButton setTitle:[anItem userDisplayRep]];
594 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleLoop"];
597 if ([df objectForKey:@"ToggleShuffle"]) {
598 anItem = [df keyComboForKey:@"ToggleShuffle"];
599 [hotKeysDictionary setObject:anItem forKey:@"ToggleShuffle"];
600 [toggleShuffleButton setTitle:[anItem userDisplayRep]];
602 [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleShuffle"];
605 // Check current track info buttons
606 [albumCheckbox setState:[df boolForKey:@"showAlbum"] ? NSOnState : NSOffState];
607 [nameCheckbox setState:NSOnState]; // Song info will ALWAYS show song title.
608 [nameCheckbox setEnabled:NO]; // Song info will ALWAYS show song title.
609 [artistCheckbox setState:[df boolForKey:@"showArtist"] ? NSOnState : NSOffState];
610 [trackTimeCheckbox setState:[df boolForKey:@"showTime"] ? NSOnState : NSOffState];
611 [trackNumberCheckbox setState:[df boolForKey:@"showTrackNumber"] ? NSOnState : NSOffState];
613 // Set the launch at login checkbox state
615 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
616 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
618 loginEnum = [loginarray objectEnumerator];
619 while ( (anItem = [loginEnum nextObject]) ) {
620 if ([[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
621 [launchAtLoginCheckbox setState:NSOnState];
626 - (IBAction)changeMenus:(id)sender
628 [df setObject:myItems forKey:@"menu"];
632 - (void)setLaunchesAtLogin:(BOOL)flag
635 NSMutableDictionary *loginwindow;
636 NSMutableArray *loginarray;
637 ComponentInstance temp = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
642 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
643 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
645 for (i = 0; i < [loginarray count]; i++) {
646 NSDictionary *tempDict = [loginarray objectAtIndex:i];
647 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
653 AEDesc scriptDesc, resultDesc;
654 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]];
656 AECreateDesc(typeChar, [script cString], [script cStringLength],
659 OSADoScript(temp, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
661 AEDisposeDesc(&scriptDesc);
662 AEDisposeDesc(&resultDesc);
663 CloseComponent(temp);
667 NSMutableDictionary *loginwindow;
668 NSMutableArray *loginarray;
672 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
673 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
675 for (i = 0; i < [loginarray count]; i++) {
676 NSDictionary *tempDict = [loginarray objectAtIndex:i];
677 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
678 [loginarray removeObjectAtIndex:i];
679 [df setPersistentDomain:loginwindow forName:@"loginwindow"];
688 /*************************************************************************/
690 #pragma mark NSWindow DELEGATE METHODS
691 /*************************************************************************/
693 - (void)windowWillClose:(NSNotification *)note
695 [(MainController *)controller closePreferences];
699 /*************************************************************************/
701 #pragma mark NSTableView DATASOURCE METHODS
702 /*************************************************************************/
704 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
706 if (aTableView == menuTableView) {
707 return [myItems count];
709 return [availableItems count];
713 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
715 if (aTableView == menuTableView) {
716 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
717 NSString *object = [myItems objectAtIndex:rowIndex];
718 if ([object isEqualToString:@"Show Player"]) {
719 return [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"show", @"Show"), [[controller currentRemote] playerSimpleName]];
721 return NSLocalizedString(object, @"ERROR");
723 if ([submenuItems containsObject:[myItems objectAtIndex:rowIndex]])
725 return [NSImage imageNamed:@"submenu"];
731 if ([[aTableColumn identifier] isEqualToString:@"name"]) {
732 return NSLocalizedString([availableItems objectAtIndex:rowIndex], @"ERROR");
734 if ([submenuItems containsObject:[availableItems objectAtIndex:rowIndex]]) {
735 return [NSImage imageNamed:@"submenu"];
743 - (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray*)rows toPasteboard:(NSPasteboard*)pboard
745 if (tableView == menuTableView) {
746 [pboard declareTypes:[NSArray arrayWithObjects:@"MenuTableViewPboardType", nil] owner:self];
747 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"MenuTableViewPboardType"];
751 if (tableView == allTableView) {
752 [pboard declareTypes:[NSArray arrayWithObjects:@"AllTableViewPboardType", nil] owner:self];
753 [pboard setString:[[rows objectAtIndex:0] stringValue] forType:@"AllTableViewPboardType"];
759 - (BOOL)tableView:(NSTableView*)tableView acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)operation
763 NSString *dragData, *temp;
765 pb = [info draggingPasteboard];
767 if ([[pb types] containsObject:@"MenuTableViewPboardType"]) {
768 dragData = [pb stringForType:@"MenuTableViewPboardType"];
769 dragRow = [dragData intValue];
770 temp = [myItems objectAtIndex:dragRow];
772 if (tableView == menuTableView) {
773 [myItems insertObject:temp atIndex:row];
775 [myItems removeObjectAtIndex:dragRow];
777 [myItems removeObjectAtIndex:dragRow + 1];
780 if (![temp isEqualToString:@"separator"]) {
781 [availableItems addObject:temp];
783 [myItems removeObjectAtIndex:dragRow];
785 } else if ([[pb types] containsObject:@"AllTableViewPboardType"]) {
786 dragData = [pb stringForType:@"AllTableViewPboardType"];
787 dragRow = [dragData intValue];
788 temp = [availableItems objectAtIndex:dragRow];
790 [myItems insertObject:temp atIndex:row];
792 if (![temp isEqualToString:@"separator"]) {
793 [availableItems removeObjectAtIndex:dragRow];
797 [menuTableView reloadData];
798 [allTableView reloadData];
799 [self changeMenus:self];
803 - (NSDragOperation)tableView:(NSTableView*)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)operation
805 if (tableView == allTableView) {
806 if ([[[info draggingPasteboard] types] containsObject:@"AllTableViewPboardType"]) {
807 return NSDragOperationNone;
810 if ([[[info draggingPasteboard] types] containsObject:@"MenuTableViewPboardType"]) {
811 NSString *item = [myItems objectAtIndex:[[[info draggingPasteboard] stringForType:@"MenuTableViewPboardType"] intValue]];
812 if ([item isEqualToString:@"Preferences"] || [item isEqualToString:@"Quit"]) {
813 return NSDragOperationNone;
817 [tableView setDropRow:-1 dropOperation:NSTableViewDropOn];
818 return NSDragOperationGeneric;
821 if (operation == NSTableViewDropOn || row == -1)
823 return NSDragOperationNone;
826 return NSDragOperationGeneric;
830 /*************************************************************************/
832 #pragma mark DEALLOCATION METHODS
833 /*************************************************************************/
837 [self setKeyCombo:nil];
838 [hotKeysDictionary release];
839 [keyComboPanel release];
840 [menuTableView setDataSource:nil];
841 [allTableView setDataSource:nil];
842 [controller release];
843 [availableItems release];
844 [submenuItems release];