#import <ITKit/ITCategory-NSMenu.h>
#import "StatusWindow.h"
#import "StatusWindowController.h"
+#import "AudioscrobblerController.h"
#import "StatusItemHack.h"
@interface NSMenu (MenuImpl)
sharedController = self;
_statusWindowUpdateTimer = nil;
+ _audioscrobblerTimer = nil;
remoteArray = [[NSMutableArray alloc] initWithCapacity:1];
[[PreferencesController sharedPrefs] setController:self];
[statusItem setToolTip:nil];
}
}
+
+ if ([df boolForKey:@"audioscrobblerEnabled"]) {
+ int length = [[self currentRemote] currentSongDuration];
+ if (_audioscrobblerTimer) {
+ [_audioscrobblerTimer invalidate];
+ }
+ if (length > 0) {
+ _audioscrobblerTimer = [NSTimer scheduledTimerWithTimeInterval:((length < 240) ? length / 2 : 120) target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:NO];
+ }
+ } else {
+ _audioscrobblerTimer = nil;
+ }
NS_HANDLER
[self networkError:localException];
NS_ENDHANDLER
[statusItem setToolTip:nil];
}
}
+
+ if ([df boolForKey:@"audioscrobblerEnabled"]) {
+ int length = [[self currentRemote] currentSongDuration];
+ if (_audioscrobblerTimer) {
+ [_audioscrobblerTimer invalidate];
+ }
+ if (length > 0) {
+ _audioscrobblerTimer = [NSTimer scheduledTimerWithTimeInterval:((length < 240) ? length / 2 : 120) target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:NO];
+ }
+ } else {
+ _audioscrobblerTimer = nil;
+ }
NS_HANDLER
[self networkError:localException];
NS_ENDHANDLER
}
}
+- (void)submitAudioscrobblerTrack:(NSTimer *)timer
+{
+ if ([df boolForKey:@"audioscrobblerEnabled"]) {
+ NS_DURING
+ NSString *title = [[self currentRemote] currentSongTitle], *artist = [[self currentRemote] currentSongArtist];
+ if (title && artist) {
+ [[AudioscrobblerController sharedController] submitTrack:title
+ artist:artist
+ album:[[self currentRemote] currentSongAlbum]
+ length:[[self currentRemote] currentSongDuration]];
+ }
+ NS_HANDLER
+ [self networkError:localException];
+ NS_ENDHANDLER
+ [timer invalidate];
+ _audioscrobblerTimer = nil;
+ }
+}
+
//
//
// Menu Selectors
int playCount = -1;
//If we're already visible and the setting says so, vanish instead of displaying again.
- if ([[StatusWindowController sharedController] currentStatusWindowType] == StatusWindowTrackInfoType && [[StatusWindow sharedWindow] visibilityState] == ITWindowVisibleState) {
+ if ([df boolForKey:@"ToggleTrackInfoWithHotKey"] && [statusWindowController currentStatusWindowType] == StatusWindowTrackInfoType && [[StatusWindow sharedWindow] visibilityState] == ITWindowVisibleState) {
+ ITDebugLog(@"Track window is already visible, hiding track window.");
[self invalidateStatusWindowUpdateTimer];
[[StatusWindow sharedWindow] vanish:nil];
return;
if ( title ) {
if ( [df boolForKey:@"showAlbumArtwork"] ) {
- NSSize oldSize, newSize;
- NS_DURING
- art = [[self currentRemote] currentSongAlbumArt];
- oldSize = [art size];
- if (oldSize.width > oldSize.height) newSize = NSMakeSize(110,oldSize.height * (110.0f / oldSize.width));
- else newSize = NSMakeSize(oldSize.width * (110.0f / oldSize.height),110);
- art = [[[[NSImage alloc] initWithData:[art TIFFRepresentation]] autorelease] imageScaledSmoothlyToSize:newSize];
- NS_HANDLER
- [self networkError:localException];
- NS_ENDHANDLER
+ NSSize oldSize, newSize;
+ NS_DURING
+ art = [[self currentRemote] currentSongAlbumArt];
+ oldSize = [art size];
+ if (oldSize.width > oldSize.height) {
+ newSize = NSMakeSize(110,oldSize.height * (110.0f / oldSize.width));
+ }
+ else newSize = NSMakeSize(oldSize.width * (110.0f / oldSize.height),110);
+ art = [[[[NSImage alloc] initWithData:[art TIFFRepresentation]] autorelease] imageScaledSmoothlyToSize:newSize];
+ NS_HANDLER
+ [self networkError:localException];
+ NS_ENDHANDLER
}
if ( [df boolForKey:@"showAlbum"] ) {
- (void)setRating:(ITHotKey *)sender
{
- int stars = [[sender name] characterAtIndex:9] - 48;
- [self selectSongRating:stars * 20];
- [statusWindowController showRatingWindowWithRating:(float)stars / 5.0];
+ if ([self songIsPlaying]) {
+ int stars = [[sender name] characterAtIndex:9] - 48;
+ [self selectSongRating:stars * 20];
+ [statusWindowController showRatingWindowWithRating:(float)stars / 5.0];
+ }
}
- (void)toggleLoop