diff options
author | Damiano Galassi <[email protected]> | 2015-09-30 07:47:00 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2015-09-30 07:47:00 +0200 |
commit | c667e5ae33ce3cb13d24925fe63e1e286192af5f (patch) | |
tree | 2b235c208c8ff36709bd30e92d30ec96a59b42f1 /macosx | |
parent | c5360d65dfec773d87735b6db0d012df4045bd04 (diff) |
MacGui: add a way to differentiate a cancelled scan/encoded from a failed scan/encode
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/HBController.m | 4 | ||||
-rw-r--r-- | macosx/HBCore.h | 9 | ||||
-rw-r--r-- | macosx/HBCore.m | 33 | ||||
-rw-r--r-- | macosx/HBPreviewGenerator.m | 4 | ||||
-rw-r--r-- | macosx/HBQueueController.m | 6 |
5 files changed, 27 insertions, 29 deletions
diff --git a/macosx/HBController.m b/macosx/HBController.m index 79ff33169..5fd1a4ae8 100644 --- a/macosx/HBController.m +++ b/macosx/HBController.m @@ -722,14 +722,14 @@ fScanHorizontalLine.hidden = YES; fScanIndicator.doubleValue = [formatter stateToPercentComplete:hb_state]; } - completionHandler:^(BOOL success) + completionHandler:^(HBCoreResult result) { fScanHorizontalLine.hidden = NO; fScanIndicator.hidden = YES; fScanIndicator.indeterminate = NO; fScanIndicator.doubleValue = 0.0; - if (success) + if (result == HBCoreResultDone) { [self showNewScan]; } diff --git a/macosx/HBCore.h b/macosx/HBCore.h index c8817b220..36335114e 100644 --- a/macosx/HBCore.h +++ b/macosx/HBCore.h @@ -25,8 +25,15 @@ typedef NS_ENUM(NSUInteger, HBState) { HBStateSearching = HB_STATE_SEARCHING ///< HB is searching }; +// These constants specify the result of a scan or encode. +typedef NS_ENUM(NSUInteger, HBCoreResult) { + HBCoreResultDone, + HBCoreResultCancelled, + HBCoreResultFailed, +}; + typedef void (^HBCoreProgressHandler)(HBState state, hb_state_t hb_state); -typedef void (^HBCoreCompletionHandler)(BOOL success); +typedef void (^HBCoreCompletionHandler)(HBCoreResult result); /** * HBCore is an Objective-C interface to the low-level HandBrake library. diff --git a/macosx/HBCore.m b/macosx/HBCore.m index 7acbf3490..c6925abbf 100644 --- a/macosx/HBCore.m +++ b/macosx/HBCore.m @@ -501,15 +501,24 @@ static void hb_error_handler(const char *errmsg) // Call the completion block and clean ups the handlers self.progressHandler = nil; + + HBCoreResult result = HBCoreResultDone; if (_hb_state->state == HB_STATE_WORKDONE) { - [self handleWorkCompletion]; + result = [self workDone] ? HBCoreResultDone : HBCoreResultFailed; } else { - [self handleScanCompletion]; + result = [self scanDone] ? HBCoreResultDone : HBCoreResultFailed; + } + + if (self.isCancelled) + { + result = HBCoreResultCancelled; } + [self runCompletionBlockAndCleanUpWithResult:result]; + // Reset the cancelled state. self.cancelled = NO; } @@ -519,7 +528,7 @@ static void hb_error_handler(const char *errmsg) * * @param result the result to pass to the completion block. */ -- (void)runCompletionBlockAndCleanUpWithResult:(BOOL)result +- (void)runCompletionBlockAndCleanUpWithResult:(HBCoreResult)result { if (self.completionHandler) { @@ -531,22 +540,4 @@ static void hb_error_handler(const char *errmsg) } } -/** - * Processes scan completion. - */ -- (void)handleScanCompletion -{ - BOOL result = [self scanDone]; - [self runCompletionBlockAndCleanUpWithResult:result]; -} - -/** - * Processes work completion. - */ -- (void)handleWorkCompletion -{ - BOOL result = [self workDone]; - [self runCompletionBlockAndCleanUpWithResult:result]; -} - @end diff --git a/macosx/HBPreviewGenerator.m b/macosx/HBPreviewGenerator.m index cd7cfd690..04fc055b0 100644 --- a/macosx/HBPreviewGenerator.m +++ b/macosx/HBPreviewGenerator.m @@ -207,9 +207,9 @@ [self.delegate updateProgress:[formatter stateToPercentComplete:hb_state] info:[formatter stateToString:hb_state title:@"preview"]]; } - completionHandler:^(BOOL success) { + completionHandler:^(HBCoreResult result) { // Encode done, call the delegate and close libhb handle - if (success) + if (result == HBCoreResultDone) { [self.delegate didCreateMovieAtURL:destURL]; } diff --git a/macosx/HBQueueController.m b/macosx/HBQueueController.m index b54143ff2..7ae19da3e 100644 --- a/macosx/HBQueueController.m +++ b/macosx/HBQueueController.m @@ -468,8 +468,8 @@ self.progressTextField.stringValue = status; [self.controller setQueueInfo:status progress:0 hidden:NO]; } - completionHandler:^(BOOL success) { - if (success) + completionHandler:^(HBCoreResult result) { + if (result == HBCoreResultDone) { [self doEncodeQueueItem]; } @@ -538,7 +538,7 @@ self.progressTextField.stringValue = string; [self.controller setQueueInfo:string progress:progress hidden:NO]; } - completionHandler:^(BOOL success) { + completionHandler:^(HBCoreResult result) { NSString *info = NSLocalizedString(@"Encode Finished.", @""); self.progressTextField.stringValue = info; |