summaryrefslogtreecommitdiffstats
path: root/macosx/main.mm
diff options
context:
space:
mode:
Diffstat (limited to 'macosx/main.mm')
-rw-r--r--macosx/main.mm80
1 files changed, 24 insertions, 56 deletions
diff --git a/macosx/main.mm b/macosx/main.mm
index 4915d2f5b..300000273 100644
--- a/macosx/main.mm
+++ b/macosx/main.mm
@@ -4,72 +4,40 @@
Homepage: <http://handbrake.fr/>.
It may be used under the terms of the GNU General Public License. */
-#include <Cocoa/Cocoa.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
+#import <Cocoa/Cocoa.h>
+#include "hb.h"
-#import "hb.h"
-
-void SigHandler( int signal );
-void hb_error_handler( const char *errmsg );
-char * str_printf(const char *fmt, ...);
-
-void SigHandler( int signal )
-{
- [NSApp terminate: NULL];
-}
-
-/****************************************************************************
- * hb_error_handler
- *
- * Change this to display a dialog box - and maybe move it somewhere else,
- * this is the only place I could find that looked like C :)
-****************************************************************************/
-void hb_error_handler( const char *errmsg )
-{
- fprintf(stderr, "GUI ERROR dialog: %s\n", errmsg );
-}
-
-char * str_printf(const char *fmt, ...)
+static void hb_error_handler(const char *errmsg)
{
- /* Guess we need no more than 100 bytes. */
- int len;
- va_list ap;
- int size = 100;
- char *tmp, *str = NULL;
-
- str = (char*)malloc(size);
- while (1)
+ @autoreleasepool
{
- /* Try to print in the allocated space. */
- va_start(ap, fmt);
- len = vsnprintf(str, size, fmt, ap);
- va_end(ap);
-
- /* If that worked, return the string. */
- if (len > -1 && len < size) {
- return str;
- }
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert setMessageText:NSLocalizedString(@"Internal Error.", @"")];
+ [alert setInformativeText:@(errmsg)];
+ [alert runModal];
+ [alert release];
- /* Else try again with more space. */
- if (len > -1) /* glibc 2.1 */
- size = len+1; /* precisely what is needed */
- else /* glibc 2.0 */
- size *= 2; /* twice the old size */
-
- tmp = (char*)realloc(str, size);
- if (tmp == NULL) {
- return str;
- }
- str = tmp;
+ fprintf(stderr, "GUI ERROR dialog: %s\n", errmsg );
}
}
int main(int argc, const char **argv)
{
- signal(SIGINT, SigHandler);
+ // 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 };
+ action.sa_handler = SIG_IGN;
+ sigaction(SIGINT, &action, NULL);
+
hb_global_init();
hb_register_error_handler(&hb_error_handler);
+
return NSApplicationMain(argc, argv);
}