]> granicus.if.org Git - handbrake/commitdiff
MacGui: add a way to differentiate a cancelled scan/encoded from a failed scan/encode
authorDamiano Galassi <damiog@gmail.com>
Wed, 30 Sep 2015 05:47:00 +0000 (07:47 +0200)
committerDamiano Galassi <damiog@gmail.com>
Wed, 30 Sep 2015 05:47:00 +0000 (07:47 +0200)
macosx/HBController.m
macosx/HBCore.h
macosx/HBCore.m
macosx/HBPreviewGenerator.m
macosx/HBQueueController.m

index 79ff331696fbc2c396b6a8542644dcac3987866c..5fd1a4ae81db5567d3845513cc7a4529580fefb0 100644 (file)
             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];
             }
index c8817b2206f8b456cd0b8f07d427e5ba2fcf3927..36335114e70d6c0f1b43bf9102258317570943ff 100644 (file)
@@ -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.
index 7acbf34901cd5a0a8e716bf9f88ca12596f89c09..c6925abbf04dddafdb5f09c01bd6574a1ce924a7 100644 (file)
@@ -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
index cd7cfd690d8dfbd4aa918c19ef625b9628cf95b0..04fc055b078cea68136d1b4c784c3b966e4289c7 100644 (file)
              [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];
            }
index b54143ff22df4630b83e22688e35954ae9c59913..7ae19da3e74d75b81a92fca942371e81eb5fb218 100644 (file)
            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];
        }
              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;