Now removing items from the submission queue after success.
authorKent Sutherland <ksuther@ithinksw.com>
Wed, 9 Nov 2005 16:56:55 +0000 (16:56 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Wed, 9 Nov 2005 16:56:55 +0000 (16:56 +0000)
Keychain update warning will now run at applictaion launch, instead of mid-execution.

AudioscrobblerController.h
AudioscrobblerController.m
MainController.m
PreferencesController.m

index 7daddea..ae0a20e 100644 (file)
@@ -24,7 +24,7 @@ typedef enum {
 @interface AudioscrobblerController : NSObject {
        BOOL _handshakeCompleted;
        AudioscrobblerStatus _currentStatus;
 @interface AudioscrobblerController : NSObject {
        BOOL _handshakeCompleted;
        AudioscrobblerStatus _currentStatus;
-       NSMutableArray *_tracks;
+       NSMutableArray *_tracks, *_submitTracks;
        NSDate *_delayDate;
        
        NSString *_md5Challenge;
        NSDate *_delayDate;
        
        NSString *_md5Challenge;
index 6206ad8..552d949 100644 (file)
@@ -54,6 +54,7 @@ static AudioscrobblerController *_sharedController = nil;
                _delayDate = nil;
                _responseData = nil;
                _tracks = [[NSMutableArray alloc] init];
                _delayDate = nil;
                _responseData = nil;
                _tracks = [[NSMutableArray alloc] init];
+               _submitTracks = [[NSMutableArray alloc] init];
                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioscrobblerNotification:) name:nil object:self];
        }
        return self;
                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioscrobblerNotification:) name:nil object:self];
        }
        return self;
@@ -64,6 +65,7 @@ static AudioscrobblerController *_sharedController = nil;
        [_md5Challenge release];
        [_postURL release];
        [_responseData release];
        [_md5Challenge release];
        [_postURL release];
        [_responseData release];
+       [_submitTracks release];
        [_tracks release];
        [super dealloc];
 }
        [_tracks release];
        [super dealloc];
 }
@@ -185,6 +187,7 @@ static AudioscrobblerController *_sharedController = nil;
                trackString = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)[NSString stringWithFormat:@"&a[%i]=%@&t[%i]=%@&b[%i]=%@&m[%i]=&l[%i]=%@&i[%i]=%@", i, [nextTrack objectForKey:@"artist"], i, [nextTrack objectForKey:@"title"], i, [nextTrack objectForKey:@"album"], i, i, [nextTrack objectForKey:@"length"], i, [nextTrack objectForKey:@"time"]], NULL, NULL, kCFStringEncodingUTF8);
                [requestString appendString:trackString];
                [trackString release];
                trackString = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)[NSString stringWithFormat:@"&a[%i]=%@&t[%i]=%@&b[%i]=%@&m[%i]=&l[%i]=%@&i[%i]=%@", i, [nextTrack objectForKey:@"artist"], i, [nextTrack objectForKey:@"title"], i, [nextTrack objectForKey:@"album"], i, i, [nextTrack objectForKey:@"length"], i, [nextTrack objectForKey:@"time"]], NULL, NULL, kCFStringEncodingUTF8);
                [requestString appendString:trackString];
                [trackString release];
+               [_submitTracks addObject:nextTrack];
        }
        
        //Create and send the request
        }
        
        //Create and send the request
@@ -253,6 +256,8 @@ static AudioscrobblerController *_sharedController = nil;
                }
        } else if (_currentStatus == AudioscrobblerSubmittingTracksStatus) {
                if ([responseAction isEqualToString:@"OK"]) {
                }
        } else if (_currentStatus == AudioscrobblerSubmittingTracksStatus) {
                if ([responseAction isEqualToString:@"OK"]) {
+                       [_tracks removeObjectsInArray:_submitTracks];
+                       [_submitTracks removeAllObjects];
                } else if ([responseAction isEqualToString:@"BADAUTH"]) {
                        //Bad auth
                } else if (([responseAction length] > 5) && [[responseAction substringToIndex:5] isEqualToString:@"FAILED"]) {
                } else if ([responseAction isEqualToString:@"BADAUTH"]) {
                        //Bad auth
                } else if (([responseAction length] > 5) && [[responseAction substringToIndex:5] isEqualToString:@"FAILED"]) {
index 7a8c874..4994a7d 100755 (executable)
@@ -199,7 +199,9 @@ static MainController *sharedController;
     [statusItem setAlternateImage:[NSImage imageNamed:@"MenuInverted"]];
 
        if ([df boolForKey:@"audioscrobblerEnabled"]) {
     [statusItem setAlternateImage:[NSImage imageNamed:@"MenuInverted"]];
 
        if ([df boolForKey:@"audioscrobblerEnabled"]) {
-               [[AudioscrobblerController sharedController] attemptHandshake:NO];
+               if ([PreferencesController getKeychainItemPasswordForUser:[df stringForKey:@"audioscrobblerUser"]] != nil) {
+                       [[AudioscrobblerController sharedController] attemptHandshake:NO];
+               }
        }
 
     [networkController startRemoteServerSearch];
        }
 
     [networkController startRemoteServerSearch];
index 6f8abfd..638be40 100755 (executable)
@@ -86,6 +86,10 @@ static PreferencesController *prefs = nil;
        SecKeychainAttribute attributes[3];
        SecKeychainAttributeList list;
 
        SecKeychainAttribute attributes[3];
        SecKeychainAttributeList list;
 
+       if ((user == nil) || ([user length] == 0)) {
+               return nil;
+       }
+
        ITDebugLog(@"Audioscrobbler: Searching for keychain item for %@.", user);
        attributes[0].tag = kSecAccountItemAttr;
        attributes[0].data = (char *)[user UTF8String];
        ITDebugLog(@"Audioscrobbler: Searching for keychain item for %@.", user);
        attributes[0].tag = kSecAccountItemAttr;
        attributes[0].data = (char *)[user UTF8String];