Scripts now run when the player switches to no song playing.
[MenuTunes.git] / MainController.m
index 0f86024..bf3bda3 100755 (executable)
 #import "StatusWindowController.h"
 #import "StatusItemHack.h"
 
+@interface NSImage (WeeAdditions)
+- (NSImage *)imageScaledSmoothlyToSize:(NSSize)scaledSize;
+@end
+
+@implementation NSImage (WeeAdditions)
+
+- (NSImage *)imageScaledSmoothlyToSize:(NSSize)scaledSize
+{
+    NSImage *newImage;
+    NSImageRep *rep = [self bestRepresentationForDevice:nil];
+    
+    newImage = [[NSImage alloc] initWithSize:scaledSize];
+    [newImage lockFocus];
+    {
+        [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
+        [[NSGraphicsContext currentContext] setShouldAntialias:YES];
+        [rep drawInRect:NSMakeRect(3, 3, scaledSize.width - 6, scaledSize.height - 6)];
+    }
+    [newImage unlockFocus];
+    return [newImage autorelease];
+}
+
+@end
+
 @interface MainController(Private)
 - (ITMTRemote *)loadRemote;
 - (void)timerUpdate;
@@ -306,7 +330,7 @@ static MainController *sharedController;
     if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) {
         ITDebugLog(@"The song changed.");
         
-        if ([df boolForKey:@"runScripts"] && [[self currentRemote] currentSongTitle]) {
+        if ([df boolForKey:@"runScripts"]) {
             NSArray *scripts = [[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
             NSEnumerator *scriptsEnum = [scripts objectEnumerator];
             NSString *nextScript;
@@ -788,8 +812,13 @@ static MainController *sharedController;
         }
         
         if ( [df boolForKey:@"showAlbumArtwork"] ) {
+           NSSize oldSize, newSize;
              NS_DURING
-                art = [[self currentRemote] currentSongAlbumArt];
+                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
@@ -798,7 +827,6 @@ static MainController *sharedController;
     } else {
         title = NSLocalizedString(@"noSongPlaying", @"No song is playing.");
     }
-
     [statusWindowController showSongInfoWindowWithSource:source
                                                    title:title
                                                    album:album