Added a status field to the audioscrobbler preferences. Using alloc'd NSTimers in...
authorKent Sutherland <ksuther@ithinksw.com>
Fri, 23 Dec 2005 09:36:21 +0000 (09:36 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Fri, 23 Dec 2005 09:36:21 +0000 (09:36 +0000)
AudioscrobblerController.h
AudioscrobblerController.m
English.lproj/Preferences.nib/classes.nib
English.lproj/Preferences.nib/info.nib
English.lproj/Preferences.nib/keyedobjects.nib
MainController.h
MainController.m
PreferencesController.h
PreferencesController.m

index 78cfdb3..a2dc6c4 100644 (file)
@@ -27,12 +27,13 @@ typedef enum {
        NSMutableArray *_tracks, *_submitTracks;
        NSDate *_delayDate;
        
        NSMutableArray *_tracks, *_submitTracks;
        NSDate *_delayDate;
        
-       NSString *_md5Challenge;
+       NSString *_md5Challenge, *_lastStatus;
        NSURL *_postURL;
        NSMutableData *_responseData;
 }
 + (AudioscrobblerController *)sharedController;
 
        NSURL *_postURL;
        NSMutableData *_responseData;
 }
 + (AudioscrobblerController *)sharedController;
 
+- (NSString *)lastStatus;
 - (void)attemptHandshake;
 - (void)attemptHandshake:(BOOL)force;
 - (BOOL)handshakeCompleted;
 - (void)attemptHandshake;
 - (void)attemptHandshake:(BOOL)force;
 - (BOOL)handshakeCompleted;
index a3d3b6b..3864a0c 100644 (file)
@@ -16,7 +16,7 @@
 #import <openssl/evp.h>
 #import <ITFoundation/ITDebug.h>
 
 #import <openssl/evp.h>
 #import <ITFoundation/ITDebug.h>
 
-#define AUDIOSCROBBLER_ID @"tst"
+#define AUDIOSCROBBLER_ID @"mtu"
 #define AUDIOSCROBBLER_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
 
 static AudioscrobblerController *_sharedController = nil;
 #define AUDIOSCROBBLER_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
 
 static AudioscrobblerController *_sharedController = nil;
@@ -46,13 +46,14 @@ static AudioscrobblerController *_sharedController = nil;
                _responseData = nil;
                _tracks = [[NSMutableArray alloc] init];
                _submitTracks = [[NSMutableArray alloc] init];
                _responseData = nil;
                _tracks = [[NSMutableArray alloc] init];
                _submitTracks = [[NSMutableArray alloc] init];
-               [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioscrobblerNotification:) name:nil object:self];
+               [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioscrobblerNotification:) name:@"AudioscrobblerHandshakeComplete" object:self];
        }
        return self;
 }
 
 - (void)dealloc
 {
        }
        return self;
 }
 
 - (void)dealloc
 {
+       [_lastStatus release];
        [_md5Challenge release];
        [_postURL release];
        [_responseData release];
        [_md5Challenge release];
        [_postURL release];
        [_responseData release];
@@ -62,6 +63,11 @@ static AudioscrobblerController *_sharedController = nil;
        [super dealloc];
 }
 
        [super dealloc];
 }
 
+- (NSString *)lastStatus
+{
+       return _lastStatus;
+}
+
 - (void)attemptHandshake
 {
        [self attemptHandshake:NO];
 - (void)attemptHandshake
 {
        [self attemptHandshake:NO];
@@ -221,10 +227,8 @@ static AudioscrobblerController *_sharedController = nil;
 
 - (void)handleAudioscrobblerNotification:(NSNotification *)note
 {
 
 - (void)handleAudioscrobblerNotification:(NSNotification *)note
 {
-       if ([[note name] isEqualToString:@"AudioscrobblerHandshakeComplete"]) {
-               if ([_tracks count] > 0) {
-                       [self performSelector:@selector(submitTracks) withObject:nil afterDelay:2];
-               }
+       if ([_tracks count] > 0) {
+               [self performSelector:@selector(submitTracks) withObject:nil afterDelay:2];
        }
 }
 
        }
 }
 
@@ -232,6 +236,9 @@ static AudioscrobblerController *_sharedController = nil;
 
 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
 {
 
 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
 {
+       [_lastStatus release];
+       _lastStatus = [[NSString stringWithFormat:NSLocalizedString(@"audioscrobbler_error", @"Error - %@"), [error localizedDescription]] retain];
+       [[NSNotificationCenter defaultCenter] postNotificationName:@"AudioscrobblerStatusChanged" object:self userInfo:[NSDictionary dictionaryWithObject:_lastStatus forKey:@"StatusString"]];
        ITDebugLog(@"Audioscrobbler: Connection error \"%@\"", error);
 }
 
        ITDebugLog(@"Audioscrobbler: Connection error \"%@\"", error);
 }
 
@@ -244,7 +251,7 @@ static AudioscrobblerController *_sharedController = nil;
 {
        NSString *string = [[NSString alloc] initWithData:_responseData encoding:NSASCIIStringEncoding];
        NSArray *lines = [string componentsSeparatedByString:@"\n"];
 {
        NSString *string = [[NSString alloc] initWithData:_responseData encoding:NSASCIIStringEncoding];
        NSArray *lines = [string componentsSeparatedByString:@"\n"];
-       NSString *responseAction = nil;
+       NSString *responseAction = nil, *key = nil, *comment = nil;
        
        if ([lines count] > 0) {
                responseAction = [lines objectAtIndex:0];
        
        if ([lines count] > 0) {
                responseAction = [lines objectAtIndex:0];
@@ -261,33 +268,52 @@ static AudioscrobblerController *_sharedController = nil;
                                _postURL = [[NSURL alloc] initWithString:[lines objectAtIndex:2]];
                                _handshakeCompleted = YES;
                                [[NSNotificationCenter defaultCenter] postNotificationName:@"AudioscrobblerHandshakeComplete" object:self];
                                _postURL = [[NSURL alloc] initWithString:[lines objectAtIndex:2]];
                                _handshakeCompleted = YES;
                                [[NSNotificationCenter defaultCenter] postNotificationName:@"AudioscrobblerHandshakeComplete" object:self];
+                               key = @"audioscrobbler_handshake_complete";
+                               comment = @"Handshake complete";
                        } else {
                                //We have a protocol error
                        }
                } else if (([responseAction length] > 5) && [[responseAction substringToIndex:5] isEqualToString:@"FAILED"]) {
                        ITDebugLog(@"Audioscrobbler: Handshake failed (%@)", [responseAction substringFromIndex:6]);
                        } else {
                                //We have a protocol error
                        }
                } else if (([responseAction length] > 5) && [[responseAction substringToIndex:5] isEqualToString:@"FAILED"]) {
                        ITDebugLog(@"Audioscrobbler: Handshake failed (%@)", [responseAction substringFromIndex:6]);
+                       key = @"audioscrobbler_handshake_failed";
+                       comment = @"Handshake failed";
                        //We have a error
                } else if ([responseAction isEqualToString:@"BADUSER"]) {
                        ITDebugLog(@"Audioscrobbler: Bad user name");
                        //We have a error
                } else if ([responseAction isEqualToString:@"BADUSER"]) {
                        ITDebugLog(@"Audioscrobbler: Bad user name");
+                       key = @"audioscrobbler_bad_user";
+                       comment = @"Handshake failed - invalid user name";
                        //We have a bad user
                } else {
                        ITDebugLog(@"Audioscrobbler: Handshake failed, protocol error");
                        //We have a bad user
                } else {
                        ITDebugLog(@"Audioscrobbler: Handshake failed, protocol error");
+                       key = @"audioscrobbler_protocol_error";
+                       comment = @"Internal protocol error";
                        //We have a protocol error
                }
        } else if (_currentStatus == AudioscrobblerSubmittingTracksStatus) {
                        //We have a protocol error
                }
        } else if (_currentStatus == AudioscrobblerSubmittingTracksStatus) {
+               //For now we're not going to cache results, as it is less of a headache
+               [_tracks removeObjectsInArray:_submitTracks];
+               [_submitTracks removeAllObjects];
+               
                if ([responseAction isEqualToString:@"OK"]) {
                        ITDebugLog(@"Audioscrobbler: Submission successful, clearing queue.");
                if ([responseAction isEqualToString:@"OK"]) {
                        ITDebugLog(@"Audioscrobbler: Submission successful, clearing queue.");
-                       [_tracks removeObjectsInArray:_submitTracks];
-                       [_submitTracks removeAllObjects];
+                       /*[_tracks removeObjectsInArray:_submitTracks];
+                       [_submitTracks removeAllObjects];*/
                        if ([_tracks count] > 0) {
                                ITDebugLog(@"Audioscrobbler: Tracks remaining in queue, submitting remaining tracks");
                                [self performSelector:@selector(submitTracks) withObject:nil afterDelay:2];
                        }
                        if ([_tracks count] > 0) {
                                ITDebugLog(@"Audioscrobbler: Tracks remaining in queue, submitting remaining tracks");
                                [self performSelector:@selector(submitTracks) withObject:nil afterDelay:2];
                        }
+                       key = @"audioscrobbler_submission_ok";
+                       comment = @"Last track submission successful";
                } else if ([responseAction isEqualToString:@"BADAUTH"]) {
                        ITDebugLog(@"Audioscrobbler: Bad password");
                } else if ([responseAction isEqualToString:@"BADAUTH"]) {
                        ITDebugLog(@"Audioscrobbler: Bad password");
+                       key = @"audioscrobbler_bad_password";
+                       comment = @"Last track submission failed - invalid password";
                        //Bad auth
                } else if (([responseAction length] > 5) && [[responseAction substringToIndex:5] isEqualToString:@"FAILED"]) {
                        ITDebugLog(@"Audioscrobbler: Submission failed (%@)", [responseAction substringFromIndex:6]);
                        //Bad auth
                } else if (([responseAction length] > 5) && [[responseAction substringToIndex:5] isEqualToString:@"FAILED"]) {
                        ITDebugLog(@"Audioscrobbler: Submission failed (%@)", [responseAction substringFromIndex:6]);
+                       NSLog(@"Audioscrobbler: Submission failed (%@)", [responseAction substringFromIndex:6]);
+                       key = @"audioscrobbler_submission_failed";
+                       comment = @"Last track submission failed - see console for error";
                        //Failed
                }
        }
                        //Failed
                }
        }
@@ -302,7 +328,9 @@ static AudioscrobblerController *_sharedController = nil;
                ITDebugLog(@"No interval response.");
                //We have a protocol error
        }
                ITDebugLog(@"No interval response.");
                //We have a protocol error
        }
-       
+       [_lastStatus release];
+       _lastStatus = [NSLocalizedString(key, comment) retain];
+       [[NSNotificationCenter defaultCenter] postNotificationName:@"AudioscrobblerStatusChanged" object:nil userInfo:[NSDictionary dictionaryWithObject:_lastStatus forKey:@"StatusString"]];
        [string release];
        [_responseData release];
 }
        [string release];
        [_responseData release];
 }
index 3f7a192..9ddd004 100755 (executable)
@@ -23,6 +23,7 @@
                 artistCheckbox = NSButton; 
                 audioscrobblerEnabledCheckbox = NSButton; 
                 audioscrobblerPasswordTextField = NSSecureTextField; 
                 artistCheckbox = NSButton; 
                 audioscrobblerEnabledCheckbox = NSButton; 
                 audioscrobblerPasswordTextField = NSSecureTextField; 
+                audioscrobblerStatusTextField = NSTextField; 
                 audioscrobblerUseCacheCheckbox = NSButton; 
                 audioscrobblerUserTextField = NSTextField; 
                 backgroundColorPopup = NSPopUpButton; 
                 audioscrobblerUseCacheCheckbox = NSButton; 
                 audioscrobblerUserTextField = NSTextField; 
                 backgroundColorPopup = NSPopUpButton; 
index 33225c9..4c9701e 100755 (executable)
@@ -12,7 +12,7 @@
                <string>386 450 380 122 0 0 1152 746 </string>
        </dict>
        <key>IBFramework Version</key>
                <string>386 450 380 122 0 0 1152 746 </string>
        </dict>
        <key>IBFramework Version</key>
-       <string>439.0</string>
+       <string>443.0</string>
        <key>IBLockedObjects</key>
        <array>
                <integer>281</integer>
        <key>IBLockedObjects</key>
        <array>
                <integer>281</integer>
index 48b0873..351b863 100755 (executable)
Binary files a/English.lproj/Preferences.nib/keyedobjects.nib and b/English.lproj/Preferences.nib/keyedobjects.nib differ
index 7348a81..c4ed84b 100755 (executable)
@@ -47,6 +47,7 @@
     BOOL timerUpdating, _checkingForServer, _popped, _open, _needsPolling;
     BOOL blinged;
        int _timeUpdateCount; //Keeps track of how many times the time has been updated in the info status window
     BOOL timerUpdating, _checkingForServer, _popped, _open, _needsPolling;
     BOOL blinged;
        int _timeUpdateCount; //Keeps track of how many times the time has been updated in the info status window
+       int _audioscrobblerInterval;
     NSLock *_serverCheckLock;
 }
 + (MainController *)sharedController;
     NSLock *_serverCheckLock;
 }
 + (MainController *)sharedController;
index 14bfb59..b39d34d 100755 (executable)
@@ -479,11 +479,12 @@ static MainController *sharedController;
                        
                        if ([df boolForKey:@"audioscrobblerEnabled"]) {
                                int length = [[self currentRemote] currentSongDuration];
                        
                        if ([df boolForKey:@"audioscrobblerEnabled"]) {
                                int length = [[self currentRemote] currentSongDuration];
-                               if (_audioscrobblerTimer) {
-                                       [_audioscrobblerTimer invalidate];
-                               }
                                if (length > 30) {
                                if (length > 30) {
-                                       _audioscrobblerTimer = [NSTimer scheduledTimerWithTimeInterval:((length / 2 < 240) ? length / 2 : 240) target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:YES];
+                                       _audioscrobblerInterval = ((length / 2 < 240) ? length / 2 : 240);
+                                       [_audioscrobblerTimer invalidate];
+                                       [_audioscrobblerTimer release];
+                                       _audioscrobblerTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:_audioscrobblerInterval] interval:nil target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:NO];
+                                       [[NSRunLoop currentRunLoop] addTimer:_audioscrobblerTimer forMode:NSDefaultRunLoopMode];
                                }
                        } else {
                                _audioscrobblerTimer = nil;
                                }
                        } else {
                                _audioscrobblerTimer = nil;
@@ -605,11 +606,12 @@ static MainController *sharedController;
                
                if ([df boolForKey:@"audioscrobblerEnabled"]) {
                        int length = [[self currentRemote] currentSongDuration];
                
                if ([df boolForKey:@"audioscrobblerEnabled"]) {
                        int length = [[self currentRemote] currentSongDuration];
-                       if (_audioscrobblerTimer) {
-                               [_audioscrobblerTimer invalidate];
-                       }
                        if (length > 30) {
                        if (length > 30) {
-                               _audioscrobblerTimer = [NSTimer scheduledTimerWithTimeInterval:((length / 2 < 240) ? length / 2 : 240) target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:YES];
+                               _audioscrobblerInterval = ((length / 2 < 240) ? length / 2 : 240);
+                               [_audioscrobblerTimer invalidate];
+                               [_audioscrobblerTimer release];
+                               _audioscrobblerTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:_audioscrobblerInterval] interval:1.0 target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:NO];
+                               [[NSRunLoop currentRunLoop] addTimer:_audioscrobblerTimer forMode:NSDefaultRunLoopMode];
                        }
                } else {
                        _audioscrobblerTimer = nil;
                        }
                } else {
                        _audioscrobblerTimer = nil;
@@ -627,14 +629,12 @@ static MainController *sharedController;
 
 - (void)submitAudioscrobblerTrack:(NSTimer *)timer
 {
 
 - (void)submitAudioscrobblerTrack:(NSTimer *)timer
 {
-       int interval = [timer timeInterval];
-       [timer invalidate];
-       _audioscrobblerTimer = nil;
        ITDebugLog(@"Audioscrobbler: Attempting to submit current track");
        ITDebugLog(@"Audioscrobbler: Attempting to submit current track");
+       [timer invalidate];
        if ([df boolForKey:@"audioscrobblerEnabled"]) {
                NS_DURING
                        int elapsed = [[self currentRemote] currentSongPlayed];
        if ([df boolForKey:@"audioscrobblerEnabled"]) {
                NS_DURING
                        int elapsed = [[self currentRemote] currentSongPlayed];
-                       if ((abs(elapsed - interval) < 5) && ([[self currentRemote] playerPlayingState] == ITMTRemotePlayerPlaying)) {
+                       if ((abs(elapsed - _audioscrobblerInterval) < 5) && ([[self currentRemote] playerPlayingState] == ITMTRemotePlayerPlaying)) {
                                NSString *title = [[self currentRemote] currentSongTitle], *artist = [[self currentRemote] currentSongArtist];
                                if (title && artist) {
                                        ITDebugLog(@"Audioscrobbler: Submitting current track");
                                NSString *title = [[self currentRemote] currentSongTitle], *artist = [[self currentRemote] currentSongArtist];
                                if (title && artist) {
                                        ITDebugLog(@"Audioscrobbler: Submitting current track");
@@ -643,9 +643,12 @@ static MainController *sharedController;
                                                                                                                                        album:[[self currentRemote] currentSongAlbum]
                                                                                                                                        length:[[self currentRemote] currentSongDuration]];
                                }
                                                                                                                                        album:[[self currentRemote] currentSongAlbum]
                                                                                                                                        length:[[self currentRemote] currentSongDuration]];
                                }
-                       } else if (interval - elapsed > 0) {
-                               ITDebugLog(@"Audioscrobbler: Creating a new timer that will run in %i seconds", interval - elapsed);
-                               _audioscrobblerTimer = [NSTimer scheduledTimerWithTimeInterval:(interval - elapsed) target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:YES];
+                       } else if (_audioscrobblerInterval - elapsed > 0) {
+                               ITDebugLog(@"Audioscrobbler: Creating a new timer that will run in %i seconds", _audioscrobblerInterval - elapsed);
+                               _audioscrobblerInterval -= elapsed;
+                               [_audioscrobblerTimer release];
+                               _audioscrobblerTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:_audioscrobblerInterval] interval:nil target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:NO];
+                               [[NSRunLoop currentRunLoop] addTimer:_audioscrobblerTimer forMode:NSDefaultRunLoopMode];
                        }
                NS_HANDLER
                        [self networkError:localException];
                        }
                NS_HANDLER
                        [self networkError:localException];
index 06841ef..5b2810b 100755 (executable)
@@ -26,6 +26,7 @@
     IBOutlet NSButton *artistCheckbox;
        IBOutlet NSButton *audioscrobblerEnabledCheckbox;
        IBOutlet NSTextField *audioscrobblerPasswordTextField;
     IBOutlet NSButton *artistCheckbox;
        IBOutlet NSButton *audioscrobblerEnabledCheckbox;
        IBOutlet NSTextField *audioscrobblerPasswordTextField;
+       IBOutlet NSTextField *audioscrobblerStatusTextField;
        IBOutlet NSButton *audioscrobblerUseCacheCheckbox;
        IBOutlet NSTextField *audioscrobblerUserTextField;
     IBOutlet NSPopUpButton *backgroundStylePopup;
        IBOutlet NSButton *audioscrobblerUseCacheCheckbox;
        IBOutlet NSTextField *audioscrobblerUserTextField;
     IBOutlet NSPopUpButton *backgroundStylePopup;
index 638be40..106b9b6 100755 (executable)
@@ -272,12 +272,12 @@ static PreferencesController *prefs = nil;
                                                        @"Toggle Loop",
                                                                                                           @"Toggle Song Included In Shuffle",
                                                        @"Pop-up status menu",
                                                        @"Toggle Loop",
                                                                                                           @"Toggle Song Included In Shuffle",
                                                        @"Pop-up status menu",
-                                                       [NSString stringWithUTF8String:"Set Rating: â\98\86â\98\86â\98\86â\98\86â\98\86"],
-                                                       [NSString stringWithUTF8String:"Set Rating: â\98\85â\98\86â\98\86â\98\86â\98\86"],
-                                                       [NSString stringWithUTF8String:"Set Rating: â\98\85â\98\85â\98\86â\98\86â\98\86"],
-                                                       [NSString stringWithUTF8String:"Set Rating: â\98\85â\98\85â\98\85â\98\86â\98\86"],
-                                                       [NSString stringWithUTF8String:"Set Rating: â\98\85â\98\85â\98\85â\98\85â\98\86"],
-                                                       [NSString stringWithUTF8String:"Set Rating: â\98\85â\98\85â\98\85â\98\85â\98\85"],
+                                                       [NSString stringWithUTF8String:"Set Rating: â\80\9aòÃ\9câ\80\9aòÃ\9câ\80\9aòÃ\9câ\80\9aòÃ\9câ\80\9aòÃ\9c"],
+                                                       [NSString stringWithUTF8String:"Set Rating: â\80\9aòÃ\96â\80\9aòÃ\9câ\80\9aòÃ\9câ\80\9aòÃ\9câ\80\9aòÃ\9c"],
+                                                       [NSString stringWithUTF8String:"Set Rating: â\80\9aòÃ\96â\80\9aòÃ\96â\80\9aòÃ\9câ\80\9aòÃ\9câ\80\9aòÃ\9c"],
+                                                       [NSString stringWithUTF8String:"Set Rating: â\80\9aòÃ\96â\80\9aòÃ\96â\80\9aòÃ\96â\80\9aòÃ\9câ\80\9aòÃ\9c"],
+                                                       [NSString stringWithUTF8String:"Set Rating: â\80\9aòÃ\96â\80\9aòÃ\96â\80\9aòÃ\96â\80\9aòÃ\96â\80\9aòÃ\9c"],
+                                                       [NSString stringWithUTF8String:"Set Rating: â\80\9aòÃ\96â\80\9aòÃ\96â\80\9aòÃ\96â\80\9aòÃ\96â\80\9aòÃ\96"],
                                                        nil];
         hotKeysDictionary = [[NSMutableDictionary alloc] init];
         controller = nil;
                                                        nil];
         hotKeysDictionary = [[NSMutableDictionary alloc] init];
         controller = nil;
@@ -426,6 +426,9 @@ static PreferencesController *prefs = nil;
                [audioscrobblerUseCacheCheckbox setEnabled:SENDER_STATE];
                [audioscrobblerUserTextField setEnabled:SENDER_STATE];
                [audioscrobblerPasswordTextField setEnabled:SENDER_STATE];
                [audioscrobblerUseCacheCheckbox setEnabled:SENDER_STATE];
                [audioscrobblerUserTextField setEnabled:SENDER_STATE];
                [audioscrobblerPasswordTextField setEnabled:SENDER_STATE];
+               if (SENDER_STATE) {
+                       [[AudioscrobblerController sharedController] attemptHandshake:NO];
+               }
        } else if ( [sender tag ] == 6015) {
                //Here we create a new keychain item if needed and deletes the keychain item if the field is cleared.
                NSString *currentAccount = [df stringForKey:@"audioscrobblerUser"], *newAccount = [sender stringValue];
        } else if ( [sender tag ] == 6015) {
                //Here we create a new keychain item if needed and deletes the keychain item if the field is cleared.
                NSString *currentAccount = [df stringForKey:@"audioscrobblerUser"], *newAccount = [sender stringValue];
@@ -607,7 +610,7 @@ static PreferencesController *prefs = nil;
 
 - (IBAction)changeStatusWindowSetting:(id)sender
 {
 
 - (IBAction)changeStatusWindowSetting:(id)sender
 {
-    StatusWindow *sw = [StatusWindow sharedWindow];
+    StatusWindow *sw = (StatusWindow *)[StatusWindow sharedWindow];
     ITDebugLog(@"Changing status window setting of tag %i", [sender tag]);
     
     if ( [sender tag] == 2010) {
     ITDebugLog(@"Changing status window setting of tag %i", [sender tag]);
     
     if ( [sender tag] == 2010) {
@@ -890,6 +893,11 @@ static PreferencesController *prefs = nil;
 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
 /*************************************************************************/
 
 #pragma mark PRIVATE METHOD IMPLEMENTATIONS
 /*************************************************************************/
 
+- (void)audioscrobblerStatusChanged:(NSNotification *)note
+{
+       [audioscrobblerStatusTextField setStringValue:[[note userInfo] objectForKey:@"StatusString"]];
+}
+
 - (void)setupWindow
 {
     ITDebugLog(@"Loading Preferences.nib.");
 - (void)setupWindow
 {
     ITDebugLog(@"Loading Preferences.nib.");
@@ -975,6 +983,12 @@ static PreferencesController *prefs = nil;
     int selectedBGStyle;
     id anItem;
        
     int selectedBGStyle;
     id anItem;
        
+       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioscrobblerStatusChanged:) name:@"AudioscrobblerStatusChanged" object:nil];
+       if ([df boolForKey:@"audioscrobblerEnabled"]) {
+               NSString *status = [[AudioscrobblerController sharedController] lastStatus];
+               [audioscrobblerStatusTextField setStringValue:(status == nil) ? @"Idle" : status];
+       }
+       
     [df setInteger:MT_CURRENT_VERSION forKey:@"appVersion"];
     
     ITDebugLog(@"Setting up preferences UI.");
     [df setInteger:MT_CURRENT_VERSION forKey:@"appVersion"];
     
     ITDebugLog(@"Setting up preferences UI.");
@@ -1166,7 +1180,7 @@ static PreferencesController *prefs = nil;
 
 - (void)setStatusWindowEntryEffect:(Class)effectClass
 {
 
 - (void)setStatusWindowEntryEffect:(Class)effectClass
 {
-    StatusWindow *sw = [StatusWindow sharedWindow];
+    StatusWindow *sw = (StatusWindow *)[StatusWindow sharedWindow];
     
     float time = ([df floatForKey:@"statusWindowAppearanceSpeed"] ? [df floatForKey:@"statusWindowAppearanceSpeed"] : 0.8);
     [df setObject:NSStringFromClass(effectClass) forKey:@"statusWindowAppearanceEffect"];
     
     float time = ([df floatForKey:@"statusWindowAppearanceSpeed"] ? [df floatForKey:@"statusWindowAppearanceSpeed"] : 0.8);
     [df setObject:NSStringFromClass(effectClass) forKey:@"statusWindowAppearanceEffect"];
@@ -1177,7 +1191,7 @@ static PreferencesController *prefs = nil;
 
 - (void)setStatusWindowExitEffect:(Class)effectClass
 {
 
 - (void)setStatusWindowExitEffect:(Class)effectClass
 {
-    StatusWindow *sw = [StatusWindow sharedWindow];
+    StatusWindow *sw = (StatusWindow *)[StatusWindow sharedWindow];
     
     float time = ([df floatForKey:@"statusWindowVanishSpeed"] ? [df floatForKey:@"statusWindowVanishSpeed"] : 0.8);
     [df setObject:NSStringFromClass(effectClass) forKey:@"statusWindowVanishEffect"];
     
     float time = ([df floatForKey:@"statusWindowVanishSpeed"] ? [df floatForKey:@"statusWindowVanishSpeed"] : 0.8);
     [df setObject:NSStringFromClass(effectClass) forKey:@"statusWindowVanishEffect"];