diff --git a/Base.lproj/QueueOptions.xib b/Base.lproj/QueueOptions.xib index 5b5f8e0..9a2fec9 100644 --- a/Base.lproj/QueueOptions.xib +++ b/Base.lproj/QueueOptions.xib @@ -1,8 +1,8 @@ - + - + @@ -13,13 +13,12 @@ - - + + - - - - - - - - + + @@ -115,18 +109,19 @@ - - - - + + + - - - + + + + + @@ -141,27 +136,24 @@ - - - - + + + - - - - + + + - - - + + @@ -171,9 +163,8 @@ - - - + + @@ -183,27 +174,24 @@ - - - - + + + - - - - + + + - - - + + @@ -230,9 +218,11 @@ - - - + + + + + @@ -254,9 +244,8 @@ - - - + + @@ -278,9 +267,8 @@ - - - + + @@ -290,9 +278,8 @@ - - - + + @@ -314,9 +301,8 @@ - - - + + @@ -326,9 +312,8 @@ - - - + + @@ -350,9 +335,8 @@ - - - - - - + + + @@ -392,9 +374,11 @@ - - - + + + + + @@ -416,8 +400,101 @@ + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Classes/SBQueue.h b/Classes/SBQueue.h index 5221a77..efda9ff 100644 --- a/Classes/SBQueue.h +++ b/Classes/SBQueue.h @@ -52,9 +52,8 @@ extern NSString *SBQueueCancelledNotification; - (void)removeItemsAtIndexes:(NSIndexSet *)indexes; - (void)removeItem:(SBQueueItem *)item; -@property (nonatomic, readonly, copy) NSIndexSet * _Nonnull removeCompletedItems; - -@property (nonatomic, readonly) BOOL saveQueueToDisk; +- (NSIndexSet *)removeCompletedItems; +- (BOOL)saveQueueToDisk; @end diff --git a/Classes/SBQueue.m b/Classes/SBQueue.m index 8281843..f8e42c9 100644 --- a/Classes/SBQueue.m +++ b/Classes/SBQueue.m @@ -173,6 +173,10 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; [self disableSleep]; dispatch_async(self.workQueue, ^{ + + NSUInteger completedCount = 0; + NSUInteger failedCount = 0; + for (;;) { @autoreleasepool { NSError *outError = nil; @@ -207,8 +211,10 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; if (noErr) { self.currentItem.status = SBQueueItemStatusCompleted; + completedCount += 1; } else { self.currentItem.status = SBQueueItemStatusFailed; + failedCount += 1; [self handleSBStatusFailed:outError]; } @@ -226,7 +232,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; // Disable sleep assertion [self enableSleep]; - [self handleSBStatusCompleted]; + [self handleSBStatusCompleted:completedCount failed:failedCount]; // Reset cancelled state self.cancelled = NO; @@ -265,9 +271,10 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; * Processes SBQueueStatusCompleted state information. Current implementation just * sends SBQueueCompletedNotification. */ -- (void)handleSBStatusCompleted { +- (void)handleSBStatusCompleted:(NSUInteger)completedCount failed:(NSUInteger)failedCount { self.status = SBQueueStatusCompleted; - [[NSNotificationCenter defaultCenter] postNotificationName:SBQueueCompletedNotification object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:SBQueueCompletedNotification object:self userInfo:@{@"CompletedCount": @(completedCount), + @"FailedCount": @(failedCount)}]; } /** diff --git a/Classes/SBQueueController.m b/Classes/SBQueueController.m index a45c26f..0882abb 100755 --- a/Classes/SBQueueController.m +++ b/Classes/SBQueueController.m @@ -94,7 +94,7 @@ static void *SBQueueContex = &SBQueueContex; [self.progressBar setIndeterminate:NO]; self.progressBar.doubleValue = [[info valueForKey:@"Progress"] doubleValue]; - if ([[info valueForKey:@"ItemIndex"] integerValue] != -1) { + if ([info[@"ItemIndex"] integerValue] != -1) { [self updateUI]; } }]; @@ -108,6 +108,24 @@ static void *SBQueueContex = &SBQueueContex; [self.statusLabel setStringValue:NSLocalizedString(@"Done", @"Queue -> Done")]; [self updateUI]; + + if ([self.options[SBQueueShowDoneNotification] boolValue]) { + NSDictionary *info = note.userInfo; + + NSUserNotification *notification = [[NSUserNotification alloc] init]; + notification.title = NSLocalizedString(@"Queue done", nil); + if ([info[@"FailedCount"] unsignedIntegerValue]) { + notification.informativeText = [NSString stringWithFormat:@"Completed: %lu; Failed: %lu", + [info[@"CompletedCount"] unsignedIntegerValue], + [info[@"FailedCount"] unsignedIntegerValue]]; + } + else { + notification.informativeText = [NSString stringWithFormat:@"Completed: %lu", + [info[@"CompletedCount"] unsignedIntegerValue]]; + } + notification.soundName = NSUserNotificationDefaultSoundName; + [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; + } }]; [[NSNotificationCenter defaultCenter] addObserverForName:SBQueueFailedNotification object:self.queue queue:mainQueue usingBlock:^(NSNotification *note) { diff --git a/Classes/SBQueuePreferences.h b/Classes/SBQueuePreferences.h index b304117..ae985d1 100644 --- a/Classes/SBQueuePreferences.h +++ b/Classes/SBQueuePreferences.h @@ -19,6 +19,7 @@ extern NSString * const SBQueueSet; extern NSString * const SBQueueAutoStart; extern NSString * const SBQueueOptimize; +extern NSString * const SBQueueShowDoneNotification; extern NSString * const SBQueueFixTrackLanguage; extern NSString * const SBQueueFixTrackLanguageValue; diff --git a/Classes/SBQueuePreferences.m b/Classes/SBQueuePreferences.m index 5e52b53..a79e0b3 100644 --- a/Classes/SBQueuePreferences.m +++ b/Classes/SBQueuePreferences.m @@ -19,6 +19,7 @@ NSString * const SBQueueSubtitles = @"SBQueueSubtitles"; NSString * const SBQueueAutoStart = @"SBQueueAutoStart"; NSString * const SBQueueOptimize = @"SBQueueOptimize"; +NSString * const SBQueueShowDoneNotification = @"SBQueueShowDoneNotification"; NSString * const SBQueueFixTrackLanguage = @"SBQueueFixTrackLanguage"; NSString * const SBQueueFixTrackLanguageValue = @"SBQueueFixTrackLanguageValue"; @@ -40,7 +41,7 @@ NSString * const SBQueueSet = @"SBQueueSet"; if (self) { _options = [[NSMutableDictionary alloc] init]; - NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueFixFallbacks, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage]; + NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueFixFallbacks, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize, SBQueueShowDoneNotification, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage]; [keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { self.options[obj] = [[NSUserDefaults standardUserDefaults] valueForKey:obj]; @@ -69,8 +70,11 @@ NSString * const SBQueueSet = @"SBQueueSet"; SBQueueFixFallbacks: @NO, SBQueueMetadata : @NO, SBQueueSubtitles: @YES, + SBQueueAutoStart: @NO, SBQueueOptimize : @YES, + SBQueueShowDoneNotification: @YES, + SBQueueMovieProvider : @"TheMovieDB", SBQueueTVShowProvider : @"TheTVDB", SBQueueMovieProviderLanguage : @"English", @@ -81,7 +85,7 @@ NSString * const SBQueueSet = @"SBQueueSet"; * Save the queue user defaults */ - (void)saveUserDefaults { - NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueFixFallbacks, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage]; + NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueFixFallbacks, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueShowDoneNotification, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage]; [keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [[NSUserDefaults standardUserDefaults] setValue:(self.options)[obj] forKey:obj];