X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/f16e2f1f2b4778b4bc890162fa9cd31d7dd79b54..ae9dc4be17f66b2db7fe8e9932490647f1ca7329:/MainController.m?ds=inline diff --git a/MainController.m b/MainController.m index fffd741..f6838d9 100755 --- a/MainController.m +++ b/MainController.m @@ -2,6 +2,8 @@ #import "MenuController.h" #import "PreferencesController.h" #import +#import +#import #import "StatusWindowController.h" #import "StatusItemHack.h" @@ -81,8 +83,8 @@ static MainController *sharedController; } } - [statusItem setImage:[NSImage imageNamed:@"menu"]]; - [statusItem setAlternateImage:[NSImage imageNamed:@"selected_image"]]; + [statusItem setImage:[NSImage imageNamed:@"MenuNormal"]]; + [statusItem setAlternateImage:[NSImage imageNamed:@"MenuInverted"]]; } - (ITMTRemote *)loadRemote @@ -140,7 +142,7 @@ static MainController *sharedController; - (BOOL)songIsPlaying { - return ( ! ([[currentRemote currentSongUniqueIdentifier] isEqualToString:@"0-0"]) ); + return ( ! ([[currentRemote playerStateUniqueIdentifier] isEqualToString:@"0-0"]) ); } - (BOOL)radioIsPlaying @@ -150,7 +152,7 @@ static MainController *sharedController; - (BOOL)songChanged { - return ( ! [[currentRemote currentSongUniqueIdentifier] isEqualToString:_latestSongIdentifier] ); + return ( ! [[currentRemote playerStateUniqueIdentifier] isEqualToString:_latestSongIdentifier] ); } - (NSString *)latestSongIdentifier @@ -172,7 +174,7 @@ static MainController *sharedController; ( (! [self radioIsPlaying]) && (latestPlaylistClass == ITMTRemotePlayerRadioPlaylist) ) )*/ if ([self songChanged]) { - [self setLatestSongIdentifier:[currentRemote currentSongUniqueIdentifier]]; + [self setLatestSongIdentifier:[currentRemote playerStateUniqueIdentifier]]; latestPlaylistClass = [currentRemote currentPlaylistClass]; [menuController rebuildSubmenus]; @@ -296,92 +298,124 @@ static MainController *sharedController; - (void)clearHotKeys { - [[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"]; + NSEnumerator *hotKeyEnumerator = [[[ITHotKeyCenter sharedCenter] allHotKeys] objectEnumerator]; + ITHotKey *nextHotKey; + + while ( (nextHotKey = [hotKeyEnumerator nextObject]) ) { + [[ITHotKeyCenter sharedCenter] unregisterHotKey:nextHotKey]; + } } - (void)setupHotKeys { + ITHotKey *hotKey; + if ([df objectForKey:@"PlayPause"] != nil) { - [[ITHotKeyCenter sharedCenter] addHotKey:@"PlayPause" - combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PlayPause"]] - target:self action:@selector(playPause)]; + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"PlayPause"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PlayPause"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(playPause)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } if ([df objectForKey:@"NextTrack"] != nil) { - [[ITHotKeyCenter sharedCenter] addHotKey:@"NextTrack" - combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"NextTrack"]] - target:self action:@selector(nextSong)]; + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"NextTrack"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"NextTrack"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(nextSong)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } if ([df objectForKey:@"PrevTrack"] != nil) { - [[ITHotKeyCenter sharedCenter] addHotKey:@"PrevTrack" - combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PrevTrack"]] - target:self action:@selector(prevSong)]; + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"PrevTrack"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"PrevTrack"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(prevSong)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } if ([df objectForKey:@"ShowPlayer"] != nil) { - [[ITHotKeyCenter sharedCenter] addHotKey:@"ShowPlayer" - combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]] - target:self action:@selector(showPlayer)]; + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"ShowPlayer"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ShowPlayer"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(showPlayer)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } if ([df objectForKey:@"TrackInfo"] != nil) { - [[ITHotKeyCenter sharedCenter] addHotKey:@"TrackInfo" - combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"TrackInfo"]] - target:self action:@selector(showCurrentTrackInfo)]; + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"TrackInfo"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"TrackInfo"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(showCurrentTrackInfo)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } if ([df objectForKey:@"UpcomingSongs"] != nil) { - [[ITHotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs" - combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"UpcomingSongs"]] - target:self action:@selector(showUpcomingSongs)]; + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"UpcomingSongs"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"UpcomingSongs"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(showUpcomingSongs)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } if ([df objectForKey:@"ToggleLoop"] != nil) { - [[ITHotKeyCenter sharedCenter] addHotKey:@"ToggleLoop" - combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleLoop"]] - target:self action:@selector(toggleLoop)]; + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"ToggleLoop"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleLoop"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(toggleLoop)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } if ([df objectForKey:@"ToggleShuffle"] != nil) { - [[ITHotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle" - combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleShuffle"]] - target:self action:@selector(toggleShuffle)]; + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"ToggleShuffle"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"ToggleShuffle"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(toggleShuffle)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } if ([df objectForKey:@"IncrementVolume"] != nil) { - [[ITHotKeyCenter sharedCenter] addHotKey:@"IncrementVolume" - combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementVolume"]] - target:self action:@selector(incrementVolume)]; + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"IncrementVolume"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementVolume"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(incrementVolume)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } if ([df objectForKey:@"DecrementVolume"] != nil) { - [[ITHotKeyCenter sharedCenter] addHotKey:@"DecrementVolume" - combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementVolume"]] - target:self action:@selector(decrementVolume)]; + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"DecrementVolume"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementVolume"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(decrementVolume)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } if ([df objectForKey:@"IncrementRating"] != nil) { - [[ITHotKeyCenter sharedCenter] addHotKey:@"IncrementRating" - combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementRating"]] - target:self action:@selector(incrementRating)]; + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"IncrementRating"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"IncrementRating"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(incrementRating)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } if ([df objectForKey:@"DecrementRating"] != nil) { - [[ITHotKeyCenter sharedCenter] addHotKey:@"DecrementRating" - combo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementRating"]] - target:self action:@selector(decrementRating)]; + hotKey = [[ITHotKey alloc] init]; + [hotKey setName:@"DecrementRating"]; + [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"DecrementRating"]]]; + [hotKey setTarget:self]; + [hotKey setAction:@selector(decrementRating)]; + [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } }