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];
}
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.
// 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;
}
*
* @param result the result to pass to the completion block.
*/
-- (void)runCompletionBlockAndCleanUpWithResult:(BOOL)result
+- (void)runCompletionBlockAndCleanUpWithResult:(HBCoreResult)result
{
if (self.completionHandler)
{
}
}
-/**
- * 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
[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];
}
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;