summaryrefslogtreecommitdiffstats
path: root/macosx/main.mm
blob: 1d7d6ed6981bb1834cf559904fe574c66bb50c4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* $Id: main.mm,v 1.3 2005/11/25 15:04:35 titer Exp $

   This file is part of the HandBrake source code.
   Homepage: <http://handbrake.fr/>.
   It may be used under the terms of the GNU General Public License. */

#import <Cocoa/Cocoa.h>
#include "hb.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);
}

int main(int argc, const char **argv)
{
    // Register a signal handler using grand central dispatch.
    dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGINT, 0, dispatch_get_main_queue());
    dispatch_source_set_event_handler(source, ^{
        [NSApp terminate:nil];
    });
    dispatch_resume(source);

    // Tell sigaction to ignore the SIGINT signal
    // because we handle it already with gcd.
    struct sigaction action = { {0}, 0, 0 };
    action.sa_handler = SIG_IGN;
    sigaction(SIGINT, &action, NULL);

    hb_global_init();
    hb_register_error_handler(&hb_error_handler);

    return NSApplicationMain(argc, argv);
}