X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/35f6b7135a40f5d95777b74f84bc90db2a33ad2b..f16e2f1f2b4778b4bc890162fa9cd31d7dd79b54:/MainController.m?ds=inline diff --git a/MainController.m b/MainController.m index 0d34014..fffd741 100755 --- a/MainController.m +++ b/MainController.m @@ -1,13 +1,12 @@ -#import "NewMainController.h" +#import "MainController.h" #import "MenuController.h" #import "PreferencesController.h" -#import "HotKeyCenter.h" +#import #import "StatusWindowController.h" #import "StatusItemHack.h" @interface MainController(Private) - (ITMTRemote *)loadRemote; -- (void)setupHotKeys; - (void)timerUpdate; - (void)setLatestSongIdentifier:(NSString *)newIdentifier; - (void)showCurrentTrackInfo; @@ -72,7 +71,14 @@ static MainController *sharedController; if ([currentRemote playerRunningState] == ITMTRemotePlayerRunning) { [self applicationLaunched:nil]; } else { - [self applicationTerminated:nil]; + if ([df boolForKey:@"LaunchPlayerWithMT"]) + { + [self showPlayer]; + } + else + { + [self applicationTerminated:nil]; + } } [statusItem setImage:[NSImage imageNamed:@"menu"]]; @@ -251,7 +257,7 @@ static MainController *sharedController; [currentRemote showPrimaryInterface]; } else { if (![[NSWorkspace sharedWorkspace] launchApplication:[currentRemote playerFullName]]) { - NSLog(@"Error Launching Player"); + NSLog(@"MenuTunes: Error Launching Player"); } } } @@ -290,84 +296,91 @@ static MainController *sharedController; - (void)clearHotKeys { - [[HotKeyCenter sharedCenter] removeHotKey:@"PlayPause"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"NextTrack"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"ToggleLoop"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"ToggleShuffle"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"IncrementVolume"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"DecrementVolume"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"IncrementRating"]; - [[HotKeyCenter sharedCenter] removeHotKey:@"DecrementRating"]; + [[ITHotKeyCenter sharedCenter] removeHotKey:@"PlayPause"]; + [[ITHotKeyCenter sharedCenter] removeHotKey:@"NextTrack"]; + [[ITHotKeyCenter sharedCenter] removeHotKey:@"PrevTrack"]; + [[ITHotKeyCenter sharedCenter] removeHotKey:@"TrackInfo"]; + [[ITHotKeyCenter sharedCenter] removeHotKey:@"ShowPlayer"]; + [[ITHotKeyCenter sharedCenter] removeHotKey:@"UpcomingSongs"]; + [[ITHotKeyCenter sharedCenter] removeHotKey:@"ToggleLoop"]; + [[ITHotKeyCenter sharedCenter] removeHotKey:@"ToggleShuffle"]; + [[ITHotKeyCenter sharedCenter] removeHotKey:@"IncrementVolume"]; + [[ITHotKeyCenter sharedCenter] removeHotKey:@"DecrementVolume"]; + [[ITHotKeyCenter sharedCenter] removeHotKey:@"IncrementRating"]; + [[ITHotKeyCenter sharedCenter] removeHotKey:@"DecrementRating"]; } - (void)setupHotKeys { if ([df objectForKey:@"PlayPause"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause" - combo:[df keyComboForKey:@"PlayPause"] + [[ITHotKeyCenter sharedCenter] addHotKey:@"PlayPause" + combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PlayPause"]] target:self action:@selector(playPause)]; } if ([df objectForKey:@"NextTrack"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack" - combo:[df keyComboForKey:@"NextTrack"] + [[ITHotKeyCenter sharedCenter] addHotKey:@"NextTrack" + combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"NextTrack"]] target:self action:@selector(nextSong)]; } if ([df objectForKey:@"PrevTrack"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack" - combo:[df keyComboForKey:@"PrevTrack"] + [[ITHotKeyCenter sharedCenter] addHotKey:@"PrevTrack" + combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PrevTrack"]] target:self action:@selector(prevSong)]; } + if ([df objectForKey:@"ShowPlayer"] != nil) { + [[ITHotKeyCenter sharedCenter] addHotKey:@"ShowPlayer" + combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]] + target:self action:@selector(showPlayer)]; + } + if ([df objectForKey:@"TrackInfo"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo" - combo:[df keyComboForKey:@"TrackInfo"] + [[ITHotKeyCenter sharedCenter] addHotKey:@"TrackInfo" + combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"TrackInfo"]] target:self action:@selector(showCurrentTrackInfo)]; } if ([df objectForKey:@"UpcomingSongs"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs" - combo:[df keyComboForKey:@"UpcomingSongs"] + [[ITHotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs" + combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"UpcomingSongs"]] target:self action:@selector(showUpcomingSongs)]; } if ([df objectForKey:@"ToggleLoop"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"ToggleLoop" - combo:[df keyComboForKey:@"ToggleLoop"] + [[ITHotKeyCenter sharedCenter] addHotKey:@"ToggleLoop" + combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleLoop"]] target:self action:@selector(toggleLoop)]; } if ([df objectForKey:@"ToggleShuffle"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle" - combo:[df keyComboForKey:@"ToggleShuffle"] + [[ITHotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle" + combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleShuffle"]] target:self action:@selector(toggleShuffle)]; } if ([df objectForKey:@"IncrementVolume"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"IncrementVolume" - combo:[df keyComboForKey:@"IncrementVolume"] + [[ITHotKeyCenter sharedCenter] addHotKey:@"IncrementVolume" + combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementVolume"]] target:self action:@selector(incrementVolume)]; } if ([df objectForKey:@"DecrementVolume"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"DecrementVolume" - combo:[df keyComboForKey:@"DecrementVolume"] + [[ITHotKeyCenter sharedCenter] addHotKey:@"DecrementVolume" + combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementVolume"]] target:self action:@selector(decrementVolume)]; } if ([df objectForKey:@"IncrementRating"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"IncrementRating" - combo:[df keyComboForKey:@"IncrementRating"] + [[ITHotKeyCenter sharedCenter] addHotKey:@"IncrementRating" + combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementRating"]] target:self action:@selector(incrementRating)]; } if ([df objectForKey:@"DecrementRating"] != nil) { - [[HotKeyCenter sharedCenter] addHotKey:@"DecrementRating" - combo:[df keyComboForKey:@"DecrementRating"] + [[ITHotKeyCenter sharedCenter] addHotKey:@"DecrementRating" + combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementRating"]] target:self action:@selector(decrementRating)]; } } @@ -413,7 +426,7 @@ static MainController *sharedController; trackTotal:trackTotal rating:rating]; } else { - title = @"No song is playing."; + title = NSLocalizedString(@"noSongPlaying", @"No song is playing."); [statusWindowController showSongWindowWithTitle:title album:nil artist:nil @@ -444,7 +457,7 @@ static MainController *sharedController; [statusWindowController showUpcomingSongsWithTitles:songList]; } else { - [statusWindowController showUpcomingSongsWithTitles:[NSArray arrayWithObject:@"No upcoming songs."]]; + [statusWindowController showUpcomingSongsWithTitles:[NSArray arrayWithObject:NSLocalizedString(@"noUpcomingSongs", @"No upcoming songs.")]]; } } @@ -458,6 +471,7 @@ static MainController *sharedController; [currentRemote setVolume:volume]; //Show volume status window + [statusWindowController showVolumeWindowWithLevel:volume]; } - (void)decrementVolume @@ -470,6 +484,7 @@ static MainController *sharedController; [currentRemote setVolume:volume]; //Show volume status window + [statusWindowController showVolumeWindowWithLevel:volume]; } - (void)incrementRating @@ -482,6 +497,7 @@ static MainController *sharedController; [currentRemote setCurrentSongRating:rating]; //Show rating status window + [statusWindowController showRatingWindowWithLevel:rating]; } - (void)decrementRating @@ -494,6 +510,7 @@ static MainController *sharedController; [currentRemote setCurrentSongRating:rating]; //Show rating status window + [statusWindowController showRatingWindowWithLevel:rating]; } - (void)toggleLoop @@ -514,12 +531,15 @@ static MainController *sharedController; [currentRemote setRepeatMode:repeatMode]; //Show loop status window + [statusWindowController showLoopWindowWithMode:repeatMode]; } - (void)toggleShuffle { - [currentRemote setShuffleEnabled:![currentRemote shuffleEnabled]]; + bool newShuffleEnabled = ![currentRemote shuffleEnabled]; + [currentRemote setShuffleEnabled:newShuffleEnabled]; //Show shuffle status window + [statusWindowController showLoopWindowWithMode:newShuffleEnabled]; } /*************************************************************************/ @@ -533,7 +553,12 @@ static MainController *sharedController; [currentRemote begin]; [self setLatestSongIdentifier:@""]; [self timerUpdate]; - [NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil]; + refreshTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5 + target:self + selector:@selector(timerUpdate) + userInfo:nil + repeats:YES] retain]; + //[NSThread detachNewThreadSelector:@selector(startTimerInNewThread) toTarget:self withObject:nil]; [self setupHotKeys]; playerRunningState = ITMTRemotePlayerRunning; }