1 #import "MainController.h"
2 #import "MenuController.h"
3 #import "PreferencesController.h"
4 #import "NetworkController.h"
5 #import "NetworkObject.h"
6 #import <ITKit/ITHotKeyCenter.h>
7 #import <ITKit/ITHotKey.h>
8 #import <ITKit/ITKeyCombo.h>
9 #import <ITKit/ITCategory-NSMenu.h>
10 #import "StatusWindow.h"
11 #import "StatusWindowController.h"
12 #import "StatusItemHack.h"
14 @interface NSMenu (MenuImpl)
18 @interface NSCarbonMenuImpl:NSObject
24 + (void)setupForNoMenuBar;
28 - (void)itemChanged:fp8;
29 - (void)itemAdded:fp8;
30 - (void)itemRemoved:fp8;
31 - (void)performActionWithHighlightingForItemAtIndex:(int)fp8;
32 - (void)performMenuAction:(SEL)fp8 withTarget:fp12;
33 - (void)setupCarbonMenuBar;
34 - (void)setAsMainCarbonMenuBar;
35 - (void)clearAsMainCarbonMenuBar;
36 - (void)popUpMenu:fp8 atLocation:(NSPoint)fp12 width:(float)fp20 forView:fp24 withSelectedItem:(int)fp28 withFont:fp32;
37 - (void)_popUpContextMenu:fp8 withEvent:fp12 forView:fp16 withFont:fp20;
38 - (void)_popUpContextMenu:fp8 withEvent:fp12 forView:fp16;
42 @implementation NSImage (SmoothAdditions)
44 - (NSImage *)imageScaledSmoothlyToSize:(NSSize)scaledSize
47 NSImageRep *rep = [self bestRepresentationForDevice:nil];
49 newImage = [[NSImage alloc] initWithSize:scaledSize];
52 [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
53 [[NSGraphicsContext currentContext] setShouldAntialias:YES];
54 [rep drawInRect:NSMakeRect(3, 3, scaledSize.width - 6, scaledSize.height - 6)];
56 [newImage unlockFocus];
57 return [newImage autorelease];
62 @interface MainController(Private)
63 - (ITMTRemote *)loadRemote;
64 - (void)setLatestSongIdentifier:(NSString *)newIdentifier;
65 - (void)applicationLaunched:(NSNotification *)note;
66 - (void)applicationTerminated:(NSNotification *)note;
69 static MainController *sharedController;
71 @implementation MainController
73 + (MainController *)sharedController
75 return sharedController;
78 /*************************************************************************/
80 #pragma mark INITIALIZATION/DEALLOCATION METHODS
81 /*************************************************************************/
85 if ( ( self = [super init] ) ) {
86 sharedController = self;
88 remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
89 [[PreferencesController sharedPrefs] setController:self];
90 statusWindowController = [StatusWindowController sharedController];
91 menuController = [[MenuController alloc] init];
92 df = [[NSUserDefaults standardUserDefaults] retain];
99 - (void)applicationDidFinishLaunching:(NSNotification *)note
101 NSString *iTunesPath = [df stringForKey:@"CustomPlayerPath"];
102 NSDictionary *iTunesInfoPlist;
105 //Turn on debug mode if needed
106 if ([df boolForKey:@"ITDebugMode"]) {
110 //Check if iTunes 4.7 or later is installed
112 iTunesPath = [[NSWorkspace sharedWorkspace] fullPathForApplication:@"iTunes.app"];
114 iTunesInfoPlist = [[NSBundle bundleWithPath:iTunesPath] infoDictionary];
115 iTunesVersion = [[iTunesInfoPlist objectForKey:@"CFBundleVersion"] floatValue];
116 ITDebugLog(@"iTunes version found: %f.", iTunesVersion);
117 if (iTunesVersion >= 4.7) {
123 if (([df integerForKey:@"appVersion"] < 1200) && ([df integerForKey:@"SongsInAdvance"] > 0)) {
124 [df removePersistentDomainForName:@"com.ithinksw.menutunes"];
126 [[PreferencesController sharedPrefs] registerDefaults];
127 [[StatusWindowController sharedController] showPreferencesUpdateWindow];
130 currentRemote = [self loadRemote];
131 [[self currentRemote] begin];
133 //Turn on network stuff if needed
134 networkController = [[NetworkController alloc] init];
135 if ([df boolForKey:@"enableSharing"]) {
136 [self setServerStatus:YES];
137 } else if ([df boolForKey:@"useSharedPlayer"]) {
138 [self checkForRemoteServerAndConnectImmediately:YES];
141 //Setup for notification of the remote player launching or quitting
142 [[[NSWorkspace sharedWorkspace] notificationCenter]
144 selector:@selector(applicationTerminated:)
145 name:NSWorkspaceDidTerminateApplicationNotification
148 [[[NSWorkspace sharedWorkspace] notificationCenter]
150 selector:@selector(applicationLaunched:)
151 name:NSWorkspaceDidLaunchApplicationNotification
154 if (![df objectForKey:@"menu"]) { // If this is nil, defaults have never been registered.
155 [[PreferencesController sharedPrefs] registerDefaults];
158 if ([df boolForKey:@"ITMTNoStatusItem"]) {
161 [StatusItemHack install];
162 statusItem = [[ITStatusItem alloc]
163 initWithStatusBar:[NSStatusBar systemStatusBar]
164 withLength:NSSquareStatusItemLength];
167 /*bling = [[MTBlingController alloc] init];
169 registerTimer = [[NSTimer scheduledTimerWithTimeInterval:10.0
171 selector:@selector(blingTime)
173 repeats:YES] retain];*/
176 if ([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) {
177 [self applicationLaunched:nil];
179 if ([df boolForKey:@"LaunchPlayerWithMT"])
182 [self applicationTerminated:nil];
185 [self networkError:localException];
188 [statusItem setImage:[NSImage imageNamed:@"MenuNormal"]];
189 [statusItem setAlternateImage:[NSImage imageNamed:@"MenuInverted"]];
191 [networkController startRemoteServerSearch];
193 [self performSelector:@selector(rawr) withObject:nil afterDelay:1.0];
195 bling = [[MTBlingController alloc] init];
197 registerTimer = [[NSTimer scheduledTimerWithTimeInterval:10.0
199 selector:@selector(blingTime)
201 repeats:YES] retain];
209 - (ITMTRemote *)loadRemote
211 NSString *folderPath = [[NSBundle mainBundle] builtInPlugInsPath];
212 ITDebugLog(@"Gathering remotes.");
214 NSArray *bundlePathList = [NSBundle pathsForResourcesOfType:@"remote" inDirectory:folderPath];
215 NSEnumerator *enumerator = [bundlePathList objectEnumerator];
216 NSString *bundlePath;
218 while ( (bundlePath = [enumerator nextObject]) ) {
219 NSBundle* remoteBundle = [NSBundle bundleWithPath:bundlePath];
222 Class remoteClass = [remoteBundle principalClass];
224 if ([remoteClass conformsToProtocol:@protocol(ITMTRemote)] &&
225 [(NSObject *)remoteClass isKindOfClass:[NSObject class]]) {
226 id remote = [remoteClass remote];
227 ITDebugLog(@"Adding remote at path %@", bundlePath);
228 [remoteArray addObject:remote];
233 // if ( [remoteArray count] > 0 ) { // UNCOMMENT WHEN WE HAVE > 1 PLUGIN
234 // if ( [remoteArray count] > 1 ) {
235 // [remoteArray sortUsingSelector:@selector(sortAlpha:)];
237 // [self loadModuleAccessUI]; //Comment out this line to disable remote visibility
240 // NSLog(@"%@", [remoteArray objectAtIndex:0]); //DEBUG
241 return [remoteArray objectAtIndex:0];
244 /*************************************************************************/
246 #pragma mark INSTANCE METHODS
247 /*************************************************************************/
249 /*- (void)startTimerInNewThread
251 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
252 NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
253 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
255 selector:@selector(timerUpdate)
257 repeats:YES] retain];
259 ITDebugLog(@"Timer started.");
263 - (void)setBlingTime:(NSDate*)date
265 NSMutableDictionary *globalPrefs;
267 globalPrefs = [[df persistentDomainForName:@".GlobalPreferences"] mutableCopy];
269 [globalPrefs setObject:date forKey:@"ITMTTrialStart"];
270 [globalPrefs setObject:[NSNumber numberWithInt:MT_CURRENT_VERSION] forKey:@"ITMTTrialVers"];
272 [globalPrefs removeObjectForKey:@"ITMTTrialStart"];
273 [globalPrefs removeObjectForKey:@"ITMTTrialVers"];
275 [df setPersistentDomain:globalPrefs forName:@".GlobalPreferences"];
277 [globalPrefs release];
280 - (NSDate*)getBlingTime
283 return [[df persistentDomainForName:@".GlobalPreferences"] objectForKey:@"ITMTTrialStart"];
288 NSDate *now = [NSDate date];
289 if (![self blingBling]) {
290 if ( (! [self getBlingTime] ) || ([now timeIntervalSinceDate:[self getBlingTime]] < 0) ) {
291 [self setBlingTime:now];
292 } else if ([[[df persistentDomainForName:@".GlobalPreferences"] objectForKey:@"ITMTTrialVers"] intValue] < MT_CURRENT_VERSION) {
293 if ([now timeIntervalSinceDate:[self getBlingTime]] >= 345600) {
294 [self setBlingTime:[now addTimeInterval:-259200]];
296 NSMutableDictionary *globalPrefs;
298 globalPrefs = [[df persistentDomainForName:@".GlobalPreferences"] mutableCopy];
299 [globalPrefs setObject:[NSNumber numberWithInt:MT_CURRENT_VERSION] forKey:@"ITMTTrialVers"];
300 [df setPersistentDomain:globalPrefs forName:@".GlobalPreferences"];
302 [globalPrefs release];
306 if ( ([now timeIntervalSinceDate:[self getBlingTime]] >= 604800) && (blinged != YES) ) {
308 [statusItem setEnabled:NO];
309 [[ITHotKeyCenter sharedCenter] setEnabled:NO];
310 if ([refreshTimer isValid]) {
311 [refreshTimer invalidate];
312 [refreshTimer release];
315 [statusWindowController showRegistrationQueryWindow];
319 [statusItem setEnabled:YES];
320 [[ITHotKeyCenter sharedCenter] setEnabled:YES];
321 if (_needsPolling && ![refreshTimer isValid]) {
322 [refreshTimer release];
323 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5)
325 selector:@selector(timerUpdate)
327 repeats:YES] retain];
331 [self setBlingTime:nil];
342 if ( ! ([bling checkDone] == 2475) ) {
349 - (BOOL)songIsPlaying
351 NSString *identifier = nil;
353 identifier = [[self currentRemote] playerStateUniqueIdentifier];
355 [self networkError:localException];
357 return ( ! ([identifier isEqualToString:@"0-0"]) );
360 - (BOOL)radioIsPlaying
362 ITMTRemotePlayerPlaylistClass class = nil;
364 class = [[self currentRemote] currentPlaylistClass];
366 [self networkError:localException];
368 return (class == ITMTRemotePlayerRadioPlaylist );
373 NSString *identifier = nil;
375 identifier = [[self currentRemote] playerStateUniqueIdentifier];
377 [self networkError:localException];
379 return ( ! [identifier isEqualToString:_latestSongIdentifier] );
382 - (NSString *)latestSongIdentifier
384 return _latestSongIdentifier;
387 - (void)setLatestSongIdentifier:(NSString *)newIdentifier
389 ITDebugLog(@"Setting latest song identifier:");
390 ITDebugLog(@" - Identifier: %@", newIdentifier);
391 [_latestSongIdentifier autorelease];
392 _latestSongIdentifier = [newIdentifier retain];
397 NSString *identifier = [[self currentRemote] playerStateUniqueIdentifier];
398 if (refreshTimer && identifier == nil) {
399 if ([statusItem isEnabled]) {
400 [statusItem setToolTip:@"iTunes not responding."];
402 [statusItem setEnabled:NO];
404 } else if (![statusItem isEnabled]) {
405 [statusItem setEnabled:YES];
406 [statusItem setToolTip:_toolTip];
410 if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) {
411 ITDebugLog(@"The song changed. '%@'", _latestSongIdentifier);
412 if ([df boolForKey:@"runScripts"]) {
413 NSArray *scripts = [[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
414 NSEnumerator *scriptsEnum = [scripts objectEnumerator];
415 NSString *nextScript;
416 ITDebugLog(@"Running AppleScripts for song change.");
417 while ( (nextScript = [scriptsEnum nextObject]) ) {
419 NSAppleScript *currentScript = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"] stringByAppendingPathComponent:nextScript]] error:&error];
420 ITDebugLog(@"Running script: %@", nextScript);
421 if (!currentScript || ![currentScript executeAndReturnError:nil]) {
422 ITDebugLog(@"Error running script %@.", nextScript);
424 [currentScript release];
429 [statusItem setEnabled:NO];
432 latestPlaylistClass = [[self currentRemote] currentPlaylistClass];
434 if ([menuController rebuildSubmenus]) {
435 if ( [df boolForKey:@"showSongInfoOnChange"] ) {
436 [self performSelector:@selector(showCurrentTrackInfo) withObject:nil afterDelay:0.0];
438 [self setLatestSongIdentifier:identifier];
439 //Create the tooltip for the status item
440 if ( [df boolForKey:@"showToolTip"] ) {
441 NSString *artist = [[self currentRemote] currentSongArtist];
442 NSString *title = [[self currentRemote] currentSongTitle];
443 ITDebugLog(@"Creating status item tooltip.");
445 _toolTip = [NSString stringWithFormat:@"%@ - %@", artist, title];
449 _toolTip = NSLocalizedString(@"noSongPlaying", @"No song is playing.");
451 [statusItem setToolTip:_toolTip];
453 [statusItem setToolTip:nil];
457 [self networkError:localException];
460 [statusItem setEnabled:YES];
463 if ([networkController isConnectedToServer]) {
464 [statusItem setMenu:([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) ? [menuController menu] : [menuController menuForNoPlayer]];
470 ITDebugLog(@"Menu clicked.");
472 if (([[self currentRemote] playerStateUniqueIdentifier] == nil) && playerRunningState == ITMTRemotePlayerRunning) {
474 if ([statusItem isEnabled]) {
475 [statusItem setToolTip:NSLocalizedString(@"iTunesNotResponding", @"iTunes is not responding.")];
477 [statusItem setEnabled:NO];
479 NSMenu *menu = [[NSMenu alloc] init];
480 [menu addItemWithTitle:NSLocalizedString(@"iTunesNotResponding", @"iTunes is not responding.") action:nil keyEquivalent:@""];
481 [statusItem setMenu:[menu autorelease]];
484 } else if (![statusItem isEnabled]) {
485 [statusItem setEnabled:YES];
486 [statusItem setToolTip:_toolTip];
490 if ([networkController isConnectedToServer]) {
491 //Used the cached version
496 if ([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) {
497 [statusItem setMenu:[menuController menu]];
499 [statusItem setMenu:[menuController menuForNoPlayer]];
502 [self networkError:localException];
506 - (void)trackChanged:(NSNotification *)note
508 //If we're running the timer, shut it off since we don't need it!
509 /*if (refreshTimer && [refreshTimer isValid]) {
510 ITDebugLog(@"Invalidating refresh timer.");
511 [refreshTimer invalidate];
512 [refreshTimer release];
516 if (![self songChanged]) {
519 NSString *identifier = [[self currentRemote] playerStateUniqueIdentifier];
520 if ( [df boolForKey:@"showSongInfoOnChange"] ) {
521 [self performSelector:@selector(showCurrentTrackInfo) withObject:nil afterDelay:0.0];
523 [_lastTrackInfo release];
524 _lastTrackInfo = [[note userInfo] retain];
526 [self setLatestSongIdentifier:identifier];
527 ITDebugLog(@"The song changed. '%@'", _latestSongIdentifier);
528 if ([df boolForKey:@"runScripts"]) {
529 NSArray *scripts = [[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
530 NSEnumerator *scriptsEnum = [scripts objectEnumerator];
531 NSString *nextScript;
532 ITDebugLog(@"Running AppleScripts for song change.");
533 while ( (nextScript = [scriptsEnum nextObject]) ) {
535 NSAppleScript *currentScript = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"] stringByAppendingPathComponent:nextScript]] error:&error];
536 ITDebugLog(@"Running script: %@", nextScript);
537 if (!currentScript || ![currentScript executeAndReturnError:nil]) {
538 ITDebugLog(@"Error running script %@.", nextScript);
540 [currentScript release];
544 [statusItem setEnabled:NO];
547 latestPlaylistClass = [[self currentRemote] currentPlaylistClass];
549 if ([menuController rebuildSubmenus]) {
550 /*if ( [df boolForKey:@"showSongInfoOnChange"] ) {
551 [self performSelector:@selector(showCurrentTrackInfo) withObject:nil afterDelay:0.0];
553 [self setLatestSongIdentifier:identifier];
554 //Create the tooltip for the status item
555 if ( [df boolForKey:@"showToolTip"] ) {
556 ITDebugLog(@"Creating status item tooltip.");
557 NSString *artist = [_lastTrackInfo objectForKey:@"Artist"], *title = [_lastTrackInfo objectForKey:@"Name"];
559 _toolTip = [NSString stringWithFormat:@"%@ - %@", artist, title];
563 _toolTip = NSLocalizedString(@"noSongPlaying", @"No song is playing.");;
565 [statusItem setToolTip:_toolTip];
567 [statusItem setToolTip:nil];
571 [self networkError:localException];
574 [statusItem setEnabled:YES];
576 if ([networkController isConnectedToServer]) {
577 [statusItem setMenu:([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) ? [menuController menu] : [menuController menuForNoPlayer]];
590 ITMTRemotePlayerPlayingState state = [[self currentRemote] playerPlayingState];
591 ITDebugLog(@"Play/Pause toggled");
592 if (state == ITMTRemotePlayerPlaying) {
593 [[self currentRemote] pause];
594 } else if ((state == ITMTRemotePlayerForwarding) || (state == ITMTRemotePlayerRewinding)) {
595 [[self currentRemote] pause];
596 [[self currentRemote] play];
598 [[self currentRemote] play];
601 [self networkError:localException];
611 ITDebugLog(@"Going to next song.");
613 [[self currentRemote] goToNextSong];
615 [self networkError:localException];
624 ITDebugLog(@"Going to previous song.");
626 [[self currentRemote] goToPreviousSong];
628 [self networkError:localException];
637 ITDebugLog(@"Fast forwarding.");
639 [[self currentRemote] forward];
641 [self networkError:localException];
650 ITDebugLog(@"Rewinding.");
652 [[self currentRemote] rewind];
654 [self networkError:localException];
661 - (void)selectPlaylistAtIndex:(int)index
663 ITDebugLog(@"Selecting playlist %i", index);
665 [[self currentRemote] switchToPlaylistAtIndex:(index % 1000) ofSourceAtIndex:(index / 1000)];
666 //[[self currentRemote] switchToPlaylistAtIndex:index];
668 [self networkError:localException];
675 - (void)selectSongAtIndex:(int)index
677 ITDebugLog(@"Selecting song %i", index);
679 [[self currentRemote] switchToSongAtIndex:index];
681 [self networkError:localException];
688 - (void)selectSongRating:(int)rating
690 ITDebugLog(@"Selecting song rating %i", rating);
692 [[self currentRemote] setCurrentSongRating:(float)rating / 100.0];
694 [self networkError:localException];
701 - (void)selectEQPresetAtIndex:(int)index
703 ITDebugLog(@"Selecting EQ preset %i", index);
706 [[self currentRemote] setEqualizerEnabled:![[self currentRemote] equalizerEnabled]];
708 [[self currentRemote] switchToEQAtIndex:index];
711 [self networkError:localException];
718 - (void)makePlaylistWithTerm:(NSString *)term ofType:(int)type
720 ITDebugLog(@"Making playlist with term %@, type %i", term, type);
722 [[self currentRemote] makePlaylistWithTerm:term ofType:type];
724 [self networkError:localException];
726 ITDebugLog(@"Done making playlist");
731 ITDebugLog(@"Beginning show player.");
732 //if ( ( playerRunningState == ITMTRemotePlayerRunning) ) {
733 ITDebugLog(@"Showing player interface.");
735 [[self currentRemote] showPrimaryInterface];
737 [self networkError:localException];
740 ITDebugLog(@"Launching player.");
743 if ( (path = [df stringForKey:@"CustomPlayerPath"]) ) {
745 pathITDebugLog(@"Showing player interface."); = [[self currentRemote] playerFullName];
747 if (![[NSWorkspace sharedWorkspace] launchApplication:path]) {
748 ITDebugLog(@"Error Launching Player");
751 [self networkError:localException];
754 ITDebugLog(@"Finished show player.");
757 - (void)showPreferences
759 ITDebugLog(@"Show preferences.");
760 [[PreferencesController sharedPrefs] showPrefsWindow:self];
763 - (void)showPreferencesAndClose
765 ITDebugLog(@"Show preferences.");
766 [[PreferencesController sharedPrefs] showPrefsWindow:self];
767 [[StatusWindow sharedWindow] setLocked:NO];
768 [[StatusWindow sharedWindow] vanish:self];
769 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
772 - (void)showTestWindow
774 [self showCurrentTrackInfo];
777 - (void)quitMenuTunes
779 ITDebugLog(@"Quitting MenuTunes.");
780 [NSApp terminate:self];
786 - (MenuController *)menuController
788 return menuController;
791 - (void)closePreferences
793 ITDebugLog(@"Preferences closed.");
794 if ( ( playerRunningState == ITMTRemotePlayerRunning) ) {
799 - (ITMTRemote *)currentRemote
801 if ([networkController isConnectedToServer] && ![[networkController networkObject] isValid]) {
802 [self networkError:nil];
805 return currentRemote;
816 NSEnumerator *hotKeyEnumerator = [[[ITHotKeyCenter sharedCenter] allHotKeys] objectEnumerator];
817 ITHotKey *nextHotKey;
818 ITDebugLog(@"Clearing hot keys.");
819 while ( (nextHotKey = [hotKeyEnumerator nextObject]) ) {
820 [[ITHotKeyCenter sharedCenter] unregisterHotKey:nextHotKey];
822 ITDebugLog(@"Done clearing hot keys.");
828 ITDebugLog(@"Setting up hot keys.");
830 if (playerRunningState == ITMTRemotePlayerNotRunning && ![[NetworkController sharedController] isConnectedToServer]) {
834 if ([df objectForKey:@"PlayPause"] != nil) {
835 ITDebugLog(@"Setting up play pause hot key.");
836 hotKey = [[ITHotKey alloc] init];
837 [hotKey setName:@"PlayPause"];
838 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PlayPause"]]];
839 [hotKey setTarget:self];
840 [hotKey setAction:@selector(playPause)];
841 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
844 if ([df objectForKey:@"NextTrack"] != nil) {
845 ITDebugLog(@"Setting up next track hot key.");
846 hotKey = [[ITHotKey alloc] init];
847 [hotKey setName:@"NextTrack"];
848 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"NextTrack"]]];
849 [hotKey setTarget:self];
850 [hotKey setAction:@selector(nextSong)];
851 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
854 if ([df objectForKey:@"PrevTrack"] != nil) {
855 ITDebugLog(@"Setting up previous track hot key.");
856 hotKey = [[ITHotKey alloc] init];
857 [hotKey setName:@"PrevTrack"];
858 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PrevTrack"]]];
859 [hotKey setTarget:self];
860 [hotKey setAction:@selector(prevSong)];
861 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
864 if ([df objectForKey:@"FastForward"] != nil) {
865 ITDebugLog(@"Setting up fast forward hot key.");
866 hotKey = [[ITHotKey alloc] init];
867 [hotKey setName:@"FastForward"];
868 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"FastForward"]]];
869 [hotKey setTarget:self];
870 [hotKey setAction:@selector(fastForward)];
871 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
874 if ([df objectForKey:@"Rewind"] != nil) {
875 ITDebugLog(@"Setting up rewind hot key.");
876 hotKey = [[ITHotKey alloc] init];
877 [hotKey setName:@"Rewind"];
878 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"Rewind"]]];
879 [hotKey setTarget:self];
880 [hotKey setAction:@selector(rewind)];
881 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
884 if ([df objectForKey:@"ShowPlayer"] != nil) {
885 ITDebugLog(@"Setting up show player hot key.");
886 hotKey = [[ITHotKey alloc] init];
887 [hotKey setName:@"ShowPlayer"];
888 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]]];
889 [hotKey setTarget:self];
890 [hotKey setAction:@selector(showPlayer)];
891 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
894 if ([df objectForKey:@"TrackInfo"] != nil) {
895 ITDebugLog(@"Setting up track info hot key.");
896 hotKey = [[ITHotKey alloc] init];
897 [hotKey setName:@"TrackInfo"];
898 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"TrackInfo"]]];
899 [hotKey setTarget:self];
900 [hotKey setAction:@selector(showCurrentTrackInfo)];
901 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
904 if ([df objectForKey:@"UpcomingSongs"] != nil) {
905 ITDebugLog(@"Setting up upcoming songs hot key.");
906 hotKey = [[ITHotKey alloc] init];
907 [hotKey setName:@"UpcomingSongs"];
908 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"UpcomingSongs"]]];
909 [hotKey setTarget:self];
910 [hotKey setAction:@selector(showUpcomingSongs)];
911 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
914 if ([df objectForKey:@"ToggleLoop"] != nil) {
915 ITDebugLog(@"Setting up toggle loop hot key.");
916 hotKey = [[ITHotKey alloc] init];
917 [hotKey setName:@"ToggleLoop"];
918 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleLoop"]]];
919 [hotKey setTarget:self];
920 [hotKey setAction:@selector(toggleLoop)];
921 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
924 if ([df objectForKey:@"ToggleShuffle"] != nil) {
925 ITDebugLog(@"Setting up toggle shuffle hot key.");
926 hotKey = [[ITHotKey alloc] init];
927 [hotKey setName:@"ToggleShuffle"];
928 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleShuffle"]]];
929 [hotKey setTarget:self];
930 [hotKey setAction:@selector(toggleShuffle)];
931 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
934 if ([df objectForKey:@"IncrementVolume"] != nil) {
935 ITDebugLog(@"Setting up increment volume hot key.");
936 hotKey = [[ITHotKey alloc] init];
937 [hotKey setName:@"IncrementVolume"];
938 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementVolume"]]];
939 [hotKey setTarget:self];
940 [hotKey setAction:@selector(incrementVolume)];
941 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
944 if ([df objectForKey:@"DecrementVolume"] != nil) {
945 ITDebugLog(@"Setting up decrement volume hot key.");
946 hotKey = [[ITHotKey alloc] init];
947 [hotKey setName:@"DecrementVolume"];
948 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementVolume"]]];
949 [hotKey setTarget:self];
950 [hotKey setAction:@selector(decrementVolume)];
951 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
954 if ([df objectForKey:@"IncrementRating"] != nil) {
955 ITDebugLog(@"Setting up increment rating hot key.");
956 hotKey = [[ITHotKey alloc] init];
957 [hotKey setName:@"IncrementRating"];
958 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementRating"]]];
959 [hotKey setTarget:self];
960 [hotKey setAction:@selector(incrementRating)];
961 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
964 if ([df objectForKey:@"DecrementRating"] != nil) {
965 ITDebugLog(@"Setting up decrement rating hot key.");
966 hotKey = [[ITHotKey alloc] init];
967 [hotKey setName:@"DecrementRating"];
968 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementRating"]]];
969 [hotKey setTarget:self];
970 [hotKey setAction:@selector(decrementRating)];
971 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
974 if ([df objectForKey:@"PopupMenu"] != nil) {
975 ITDebugLog(@"Setting up popup menu hot key.");
976 hotKey = [[ITHotKey alloc] init];
977 [hotKey setName:@"PopupMenu"];
978 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PopupMenu"]]];
979 [hotKey setTarget:self];
980 [hotKey setAction:@selector(popupMenu)];
981 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
985 for (i = 0; i <= 5; i++) {
986 NSString *curName = [NSString stringWithFormat:@"SetRating%i", i];
987 if ([df objectForKey:curName] != nil) {
988 ITDebugLog(@"Setting up set rating %i hot key.", i);
989 hotKey = [[ITHotKey alloc] init];
990 [hotKey setName:curName];
991 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:curName]]];
992 [hotKey setTarget:self];
993 [hotKey setAction:@selector(setRating:)];
994 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
997 ITDebugLog(@"Finished setting up hot keys.");
1000 - (void)showCurrentTrackInfo
1002 ITMTRemotePlayerSource source = 0;
1003 NSString *title = nil;
1004 NSString *album = nil;
1005 NSString *artist = nil;
1006 NSString *composer = nil;
1007 NSString *time = nil;
1008 NSString *track = nil;
1013 ITDebugLog(@"Showing track info status window.");
1016 source = [[self currentRemote] currentSource];
1017 title = [[self currentRemote] currentSongTitle];
1019 [self networkError:localException];
1023 if ( [df boolForKey:@"showAlbumArtwork"] ) {
1024 NSSize oldSize, newSize;
1026 art = [[self currentRemote] currentSongAlbumArt];
1027 oldSize = [art size];
1028 if (oldSize.width > oldSize.height) newSize = NSMakeSize(110,oldSize.height * (110.0f / oldSize.width));
1029 else newSize = NSMakeSize(oldSize.width * (110.0f / oldSize.height),110);
1030 art = [[[[NSImage alloc] initWithData:[art TIFFRepresentation]] autorelease] imageScaledSmoothlyToSize:newSize];
1032 [self networkError:localException];
1036 if ( [df boolForKey:@"showAlbum"] ) {
1038 album = [[self currentRemote] currentSongAlbum];
1040 [self networkError:localException];
1044 if ( [df boolForKey:@"showArtist"] ) {
1046 artist = [[self currentRemote] currentSongArtist];
1048 [self networkError:localException];
1052 if ( [df boolForKey:@"showComposer"] ) {
1054 composer = [[self currentRemote] currentSongComposer];
1056 [self networkError:localException];
1060 if ( [df boolForKey:@"showTime"] ) {
1062 time = [NSString stringWithFormat:@"%@: %@ / %@",
1063 NSLocalizedString(@"time", @"Time"),
1064 [[self currentRemote] currentSongElapsed],
1065 [[self currentRemote] currentSongLength]];
1067 [self networkError:localException];
1071 if ( [df boolForKey:@"showTrackNumber"] ) {
1076 trackNo = [[self currentRemote] currentSongTrack];
1077 trackCount = [[self currentRemote] currentAlbumTrackCount];
1079 [self networkError:localException];
1082 if ( (trackNo > 0) || (trackCount > 0) ) {
1083 track = [NSString stringWithFormat:@"%@: %i %@ %i",
1084 @"Track", trackNo, @"of", trackCount];
1088 if ( [df boolForKey:@"showTrackRating"] ) {
1089 float currentRating = 0;
1092 currentRating = [[self currentRemote] currentSongRating];
1094 [self networkError:localException];
1097 if (currentRating >= 0.0) {
1098 rating = ( currentRating * 5 );
1102 if ( [df boolForKey:@"showPlayCount"] && ![self radioIsPlaying] && [[self currentRemote] currentSource] == ITMTRemoteLibrarySource ) {
1104 playCount = [[self currentRemote] currentSongPlayCount];
1106 [self networkError:localException];
1110 title = NSLocalizedString(@"noSongPlaying", @"No song is playing.");
1112 ITDebugLog(@"Showing current track info status window.");
1113 [statusWindowController showSongInfoWindowWithSource:source
1125 - (void)showUpcomingSongs
1129 numSongs = [[self currentRemote] numberOfSongsInPlaylistAtIndex:[[self currentRemote] currentPlaylistIndex]];
1131 [self networkError:localException];
1134 ITDebugLog(@"Showing upcoming songs status window.");
1137 int numSongsInAdvance = [df integerForKey:@"SongsInAdvance"];
1138 NSMutableArray *songList = [NSMutableArray arrayWithCapacity:numSongsInAdvance];
1139 int curTrack = [[self currentRemote] currentSongIndex];
1142 for (i = curTrack + 1; i <= curTrack + numSongsInAdvance; i++) {
1143 if (i <= numSongs) {
1144 [songList addObject:[[self currentRemote] songTitleAtIndex:i]];
1148 if ([songList count] == 0) {
1149 [songList addObject:NSLocalizedString(@"noUpcomingSongs", @"No upcoming songs.")];
1152 [statusWindowController showUpcomingSongsWindowWithTitles:songList];
1154 [statusWindowController showUpcomingSongsWindowWithTitles:[NSArray arrayWithObject:NSLocalizedString(@"noUpcomingSongs", @"No upcoming songs.")]];
1157 [self networkError:localException];
1166 NSMenu *menu = [statusItem menu];
1167 [(NSCarbonMenuImpl *)[menu _menuImpl] popUpMenu:menu atLocation:[NSEvent mouseLocation] width:1 forView:nil withSelectedItem:-30 withFont:[NSFont menuFontOfSize:32]];
1172 - (void)incrementVolume
1175 float volume = [[self currentRemote] volume];
1176 float dispVol = volume;
1177 ITDebugLog(@"Incrementing volume.");
1186 ITDebugLog(@"Setting volume to %f", volume);
1187 [[self currentRemote] setVolume:volume];
1189 // Show volume status window
1190 [statusWindowController showVolumeWindowWithLevel:dispVol];
1192 [self networkError:localException];
1196 - (void)decrementVolume
1199 float volume = [[self currentRemote] volume];
1200 float dispVol = volume;
1201 ITDebugLog(@"Decrementing volume.");
1210 ITDebugLog(@"Setting volume to %f", volume);
1211 [[self currentRemote] setVolume:volume];
1213 //Show volume status window
1214 [statusWindowController showVolumeWindowWithLevel:dispVol];
1216 [self networkError:localException];
1220 - (void)incrementRating
1223 float rating = [[self currentRemote] currentSongRating];
1224 ITDebugLog(@"Incrementing rating.");
1226 if ([[self currentRemote] currentPlaylistIndex] == 0) {
1227 ITDebugLog(@"No song playing, rating change aborted.");
1235 ITDebugLog(@"Setting rating to %f", rating);
1236 [[self currentRemote] setCurrentSongRating:rating];
1238 //Show rating status window
1239 [statusWindowController showRatingWindowWithRating:rating];
1241 [self networkError:localException];
1245 - (void)decrementRating
1248 float rating = [[self currentRemote] currentSongRating];
1249 ITDebugLog(@"Decrementing rating.");
1251 if ([[self currentRemote] currentPlaylistIndex] == 0) {
1252 ITDebugLog(@"No song playing, rating change aborted.");
1260 ITDebugLog(@"Setting rating to %f", rating);
1261 [[self currentRemote] setCurrentSongRating:rating];
1263 //Show rating status window
1264 [statusWindowController showRatingWindowWithRating:rating];
1266 [self networkError:localException];
1270 - (void)setRating:(ITHotKey *)sender
1272 int stars = [[sender name] characterAtIndex:9] - 48;
1273 [self selectSongRating:stars * 20];
1274 [statusWindowController showRatingWindowWithRating:(float)stars / 5.0];
1280 ITMTRemotePlayerRepeatMode repeatMode = [[self currentRemote] repeatMode];
1281 ITDebugLog(@"Toggling repeat mode.");
1282 switch (repeatMode) {
1283 case ITMTRemotePlayerRepeatOff:
1284 repeatMode = ITMTRemotePlayerRepeatAll;
1286 case ITMTRemotePlayerRepeatAll:
1287 repeatMode = ITMTRemotePlayerRepeatOne;
1289 case ITMTRemotePlayerRepeatOne:
1290 repeatMode = ITMTRemotePlayerRepeatOff;
1293 ITDebugLog(@"Setting repeat mode to %i", repeatMode);
1294 [[self currentRemote] setRepeatMode:repeatMode];
1296 //Show loop status window
1297 [statusWindowController showRepeatWindowWithMode:repeatMode];
1299 [self networkError:localException];
1303 - (void)toggleShuffle
1306 BOOL newShuffleEnabled = ( ! [[self currentRemote] shuffleEnabled] );
1307 ITDebugLog(@"Toggling shuffle mode.");
1308 [[self currentRemote] setShuffleEnabled:newShuffleEnabled];
1309 //Show shuffle status window
1310 ITDebugLog(@"Setting shuffle mode to %i", newShuffleEnabled);
1311 [statusWindowController showShuffleWindow:newShuffleEnabled];
1313 [self networkError:localException];
1317 - (void)registerNowOK
1319 [[StatusWindow sharedWindow] setLocked:NO];
1320 [[StatusWindow sharedWindow] vanish:self];
1321 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
1326 - (void)registerNowCancel
1328 [[StatusWindow sharedWindow] setLocked:NO];
1329 [[StatusWindow sharedWindow] vanish:self];
1330 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
1332 [NSApp terminate:self];
1335 /*************************************************************************/
1337 #pragma mark NETWORK HANDLERS
1338 /*************************************************************************/
1340 - (void)setServerStatus:(BOOL)newStatus
1344 [networkController setServerStatus:YES];
1347 [networkController setServerStatus:NO];
1351 - (int)connectToServer
1354 ITDebugLog(@"Attempting to connect to shared remote.");
1355 result = [networkController connectToHost:[df stringForKey:@"sharedPlayerHost"]];
1358 [[PreferencesController sharedPrefs] resetRemotePlayerTextFields];
1359 currentRemote = [[[networkController networkObject] remote] retain];
1361 [self setupHotKeys];
1362 //playerRunningState = ITMTRemotePlayerRunning;
1363 playerRunningState = [[self currentRemote] playerRunningState];
1364 if (_needsPolling) {
1366 [refreshTimer invalidate];
1368 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5)
1370 selector:@selector(timerUpdate)
1372 repeats:YES] retain];
1375 ITDebugLog(@"Connection successful.");
1377 } else if (result == 0) {
1378 ITDebugLog(@"Connection failed.");
1379 currentRemote = [remoteArray objectAtIndex:0];
1382 //Do something about the password being invalid
1383 ITDebugLog(@"Connection failed.");
1384 currentRemote = [remoteArray objectAtIndex:0];
1389 - (BOOL)disconnectFromServer
1391 ITDebugLog(@"Disconnecting from shared remote.");
1393 [currentRemote release];
1394 currentRemote = [remoteArray objectAtIndex:0];
1395 [networkController disconnect];
1397 if ([[self currentRemote] playerRunningState] == ITMTRemotePlayerRunning) {
1398 [self applicationLaunched:nil];
1400 [self applicationTerminated:nil];
1408 - (void)checkForRemoteServer
1410 [self checkForRemoteServerAndConnectImmediately:NO];
1413 - (void)checkForRemoteServerAndConnectImmediately:(BOOL)connectImmediately
1415 ITDebugLog(@"Checking for remote server.");
1416 if (!_checkingForServer) {
1417 if (!_serverCheckLock) {
1418 _serverCheckLock = [[NSLock alloc] init];
1420 [_serverCheckLock lock];
1421 _checkingForServer = YES;
1422 [_serverCheckLock unlock];
1423 [NSThread detachNewThreadSelector:@selector(runRemoteServerCheck:) toTarget:self withObject:[NSNumber numberWithBool:connectImmediately]];
1427 - (void)runRemoteServerCheck:(id)sender
1429 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1430 ITDebugLog(@"Remote server check running.");
1431 if ([networkController checkForServerAtHost:[df stringForKey:@"sharedPlayerHost"]]) {
1432 ITDebugLog(@"Remote server found.");
1433 if ([sender boolValue]) {
1434 [self performSelectorOnMainThread:@selector(connectToServer) withObject:nil waitUntilDone:NO];
1436 [self performSelectorOnMainThread:@selector(remoteServerFound:) withObject:nil waitUntilDone:NO];
1439 ITDebugLog(@"Remote server not found.");
1440 [self performSelectorOnMainThread:@selector(remoteServerNotFound:) withObject:nil waitUntilDone:NO];
1442 [_serverCheckLock lock];
1443 _checkingForServer = NO;
1444 [_serverCheckLock unlock];
1448 - (void)remoteServerFound:(id)sender
1450 if (![networkController isServerOn] && ![networkController isConnectedToServer]) {
1451 [[StatusWindowController sharedController] showReconnectQueryWindow];
1455 - (void)remoteServerNotFound:(id)sender
1457 if (![[NetworkController sharedController] isConnectedToServer]) {
1458 [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
1462 - (void)networkError:(NSException *)exception
1464 ITDebugLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]);
1465 if ( ((exception == nil) || [[exception name] isEqualToString:NSPortTimeoutException]) && [networkController isConnectedToServer]) {
1466 //NSRunCriticalAlertPanel(@"Remote MenuTunes Disconnected", @"The MenuTunes server you were connected to stopped responding or quit. MenuTunes will revert back to the local player.", @"OK", nil, nil);
1467 [[StatusWindowController sharedController] showNetworkErrorQueryWindow];
1468 if ([self disconnectFromServer]) {
1469 [[PreferencesController sharedPrefs] resetRemotePlayerTextFields];
1470 [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
1472 ITDebugLog(@"CRITICAL ERROR, DISCONNECTING!");
1479 /*if ([self connectToServer] == 0) {
1480 [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
1482 [self checkForRemoteServerAndConnectImmediately:YES];
1483 [[StatusWindow sharedWindow] setLocked:NO];
1484 [[StatusWindow sharedWindow] vanish:self];
1485 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
1488 - (void)cancelReconnect
1490 [[StatusWindow sharedWindow] setLocked:NO];
1491 [[StatusWindow sharedWindow] vanish:self];
1492 [[StatusWindow sharedWindow] setIgnoresMouseEvents:YES];
1495 /*************************************************************************/
1497 #pragma mark WORKSPACE NOTIFICATION HANDLERS
1498 /*************************************************************************/
1500 - (void)applicationLaunched:(NSNotification *)note
1503 if (!note || ([[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[[self currentRemote] playerFullName]] && ![[NetworkController sharedController] isConnectedToServer])) {
1504 ITDebugLog(@"Remote application launched.");
1505 playerRunningState = ITMTRemotePlayerRunning;
1506 [[self currentRemote] begin];
1507 [self setLatestSongIdentifier:@""];
1509 if (_needsPolling) {
1510 refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:([networkController isConnectedToServer] ? 10.0 : 0.5)
1512 selector:@selector(timerUpdate)
1514 repeats:YES] retain];
1516 //[NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil];
1517 if (![df boolForKey:@"UsePollingOnly"]) {
1518 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(trackChanged:) name:@"ITMTTrackChanged" object:nil];
1520 [self setupHotKeys];
1523 [self networkError:localException];
1527 - (void)applicationTerminated:(NSNotification *)note
1530 if (!note || [[[note userInfo] objectForKey:@"NSApplicationName"] isEqualToString:[[self currentRemote] playerFullName]] && ![[NetworkController sharedController] isConnectedToServer]) {
1531 ITDebugLog(@"Remote application terminated.");
1532 playerRunningState = ITMTRemotePlayerNotRunning;
1533 [[self currentRemote] halt];
1534 [refreshTimer invalidate];
1535 [refreshTimer release];
1537 [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ITMTTrackChanged" object:nil];
1538 [statusItem setEnabled:YES];
1539 [statusItem setToolTip:@"iTunes not running."];
1540 [self clearHotKeys];
1543 if ([df objectForKey:@"ShowPlayer"] != nil) {
1545 ITDebugLog(@"Setting up show player hot key.");
1546 hotKey = [[ITHotKey alloc] init];
1547 [hotKey setName:@"ShowPlayer"];
1548 [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]]];
1549 [hotKey setTarget:self];
1550 [hotKey setAction:@selector(showPlayer)];
1551 [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]];
1555 [self networkError:localException];
1560 /*************************************************************************/
1562 #pragma mark NSApplication DELEGATE METHODS
1563 /*************************************************************************/
1565 - (void)applicationWillTerminate:(NSNotification *)note
1567 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
1568 [networkController stopRemoteServerSearch];
1569 [self clearHotKeys];
1570 [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
1573 - (void)applicationDidBecomeActive:(NSNotification *)note
1575 if (_open && !blinged && ![NSApp mainWindow] && ([[StatusWindow sharedWindow] exitMode] == ITTransientStatusWindowExitAfterDelay)) {
1576 [[MainController sharedController] showPreferences];
1580 /*************************************************************************/
1582 #pragma mark DEALLOCATION METHOD
1583 /*************************************************************************/
1587 [self applicationTerminated:nil];
1589 [statusItem release];
1590 [statusWindowController release];
1591 [menuController release];
1592 [networkController release];
1593 [_serverCheckLock release];