Skip to content

Commit

Permalink
MacGui: clean up HBCore, add a way to register a block as error handler.
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6799 b64f7644-9d1e-0410-96f1-a4d463321fa5
  • Loading branch information
galad87 committed Jan 23, 2015
1 parent 2ad2ed1 commit 1194137
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 95 deletions.
29 changes: 6 additions & 23 deletions macosx/HBAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,6 @@
#import "HBCore.h"
#import "HBController.h"

static void hb_error_handler(const char *errmsg)
{
NSString *error = @(errmsg);

if (error && [[NSUserDefaults standardUserDefaults] boolForKey:@"HBDebugAlert"])
{
dispatch_async(dispatch_get_main_queue(), ^{
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:NSLocalizedString(@"Internal Error.", @"")];
[alert runModal];
[alert release];
});
}

fprintf(stderr, "error: %s\n", errmsg);
}

@interface HBAppDelegate ()

@property (nonatomic, retain) HBPresetsManager *presetsManager;
Expand All @@ -54,15 +37,15 @@ - (instancetype)init
self = [super init];
if (self)
{
hb_global_init();
hb_register_error_handler(&hb_error_handler);
// Register the default preferences
[HBPreferencesController registerUserDefaults];

// Optionally use dvd nav
[HBCore initGlobal];
[HBCore registerErrorHandler:^(NSString *error) {
fprintf(stderr, "error: %s\n", error.UTF8String);
}];
[HBCore setDVDNav:[[[NSUserDefaults standardUserDefaults] objectForKey:@"UseDvdNav"] boolValue]];

// Register the defaults preferences
[HBPreferencesController registerUserDefaults];

_outputPanel = [[HBOutputPanelController alloc] init];

// Lets report the HandBrake version number here to the activity log and text log file
Expand Down
2 changes: 1 addition & 1 deletion macosx/HBController.m
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ - (void)performScan:(NSURL *)scanURL scanTitleNum:(NSInteger)scanTitleNum
fScanIndicator.doubleValue = 100.0 * p.progress;
#undef p
}
completationHandler:^(BOOL success)
completionHandler:^(BOOL success)
{
fScanHorizontalLine.hidden = NO;
fScanIndicator.hidden = YES;
Expand Down
42 changes: 25 additions & 17 deletions macosx/HBCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
Homepage: <http://handbrake.fr/>.
It may be used under the terms of the GNU General Public License. */

#import <Cocoa/Cocoa.h>

#import <Foundation/Foundation.h>
#include "hb.h"

@class HBJob;
Expand All @@ -23,7 +22,7 @@ typedef NS_ENUM(NSUInteger, HBState) {
};

typedef void (^HBCoreProgressHandler)(HBState state, hb_state_t hb_state);
typedef void (^HBCoreCompletationHandler)(BOOL success);
typedef void (^HBCoreCompletionHandler)(BOOL success);

/**
* HBCore is an Objective-C interface to the low-level HandBrake library.
Expand All @@ -40,18 +39,28 @@ typedef void (^HBCoreCompletationHandler)(BOOL success);
*/
+ (void)setDVDNav:(BOOL)enabled;

/**
* Inits libhb globals.
*/
+ (void)initGlobal;

/**
* Performs the final cleanup for the process.
*/
+ (void)closeGlobal;

/**
* Registers a global error handler block.
*
* @param handler a block called with the error message.
*/
+ (void)registerErrorHandler:(void (^)(NSString *error))handler;

/**
* Opens low level HandBrake library. This should be called once before other
* functions HBCore are used.
*
* @param loggingLevel the desired libhb logging level.
*
* @return YES if libhb was opened, NO if there was an error.
*/
- (instancetype)initWithLoggingLevel:(int)loggingLevel;

Expand Down Expand Up @@ -83,17 +92,14 @@ typedef void (^HBCoreCompletationHandler)(BOOL success);
/**
* Starts the asynchronous execution of a scan.
*
* @param url the URL of the input file.
* @param titleNum the number of the desired title. Use 0 to scan every title.
* @param previewsNum the number of previews image to generate.
* @param minTitleDuration the minimum duration of the wanted titles in seconds.
* @param url the URL of the input file.
* @param index the index of the desired title. Use 0 to scan every title.
* @param previewsNum the number of previews image to generate.
* @param seconds the minimum duration of the wanted titles in seconds.
* @param progressHandler a block called periodically with the progress information.
* @param completionHandler a block called with the scan result.
*/
- (void)scanURL:(NSURL *)url
titleIndex:(NSUInteger)titleNum
previews:(NSUInteger)previewsNum
minDuration:(NSUInteger)minTitleDuration
progressHandler:(HBCoreProgressHandler)progressHandler
completationHandler:(HBCoreCompletationHandler)completationHandler;
- (void)scanURL:(NSURL *)url titleIndex:(NSUInteger)index previews:(NSUInteger)previewsNum minDuration:(NSUInteger)seconds progressHandler:(HBCoreProgressHandler)progressHandler completionHandler:(HBCoreCompletionHandler)completionHandler;

/**
* Cancels the scan execution.
Expand All @@ -108,9 +114,11 @@ completationHandler:(HBCoreCompletationHandler)completationHandler;
/**
* Starts an asynchronous encoding session with the passed job.
*
* @param job the job to encode.
* @param job the job to encode
* @param progressHandler a block called periodically with the progress information.
* @param completionHandler a block called with the scan result
*/
- (void)encodeJob:(HBJob *)job progressHandler:(HBCoreProgressHandler)progressHandler completationHandler:(HBCoreCompletationHandler)completationHandler;
- (void)encodeJob:(HBJob *)job progressHandler:(HBCoreProgressHandler)progressHandler completionHandler:(HBCoreCompletionHandler)completionHandler;

/**
* Stops encoding session and releases resources.
Expand Down
Loading

0 comments on commit 1194137

Please sign in to comment.