From 75c022c49f96e9a1a8d61c847174cd6819cbc046 Mon Sep 17 00:00:00 2001 From: TingPing Date: Wed, 4 Feb 2015 21:38:45 -0500 Subject: [PATCH] Implement OSX notification backend --- configure.ac | 3 ++ src/fe-gtk/Makefile.am | 5 ++ src/fe-gtk/notifications/notification-osx.m | 54 +++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/fe-gtk/notifications/notification-osx.m diff --git a/configure.ac b/configure.ac index d93b2e04..99bbd3ef 100644 --- a/configure.ac +++ b/configure.ac @@ -206,6 +206,8 @@ dnl ********************************************************************* _gdk_tgt=`$PKG_CONFIG --variable=target gdk-2.0` if test "x$_gdk_tgt" = xquartz; then + AC_PROG_OBJC + PKG_CHECK_MODULES(GTK_MAC, gtk-mac-integration-gtk2, [ GUI_LIBS="$GUI_LIBS $GTK_MAC_LIBS" GUI_CFLAGS="$GUI_CFLAGS $GTK_MAC_CFLAGS" @@ -597,6 +599,7 @@ AM_CONDITIONAL(DO_SYSINFO, test "x$sysinfo" = "xyes") AM_CONDITIONAL(DO_STATIC_ANALYSIS, test "x$analyze" = "xyes") AM_CONDITIONAL(USE_DBUS, test "x$dbus" = "xyes") AM_CONDITIONAL(HAVE_ISO_CODES, test "x$isocodes" = "xyes") +AM_CONDITIONAL(HAVE_GTK_MAC, test "x$_gdk_tgt" = xquartz) AM_CONDITIONAL(WITH_TM, test "x$theme_manager" != "xno") dnl ********************************************************************* diff --git a/src/fe-gtk/Makefile.am b/src/fe-gtk/Makefile.am index 28c932b1..71179853 100644 --- a/src/fe-gtk/Makefile.am +++ b/src/fe-gtk/Makefile.am @@ -32,8 +32,13 @@ endif if USE_LIBNOTIFY notify_c = notifications/notification-libnotify.c else +if HAVE_GTK_MAC +notify_c = notifications/notification-osx.m +hexchat_LDFLAGS = -framework Foundation +else notify_c = notifications/notification-dummy.c endif +endif hexchat_SOURCES = ascii.c banlist.c chanlist.c chanview.c custom-list.c \ dccgui.c editlist.c fe-gtk.c fkeys.c gtkutil.c ignoregui.c joind.c menu.c \ diff --git a/src/fe-gtk/notifications/notification-osx.m b/src/fe-gtk/notifications/notification-osx.m new file mode 100644 index 00000000..c97c6629 --- /dev/null +++ b/src/fe-gtk/notifications/notification-osx.m @@ -0,0 +1,54 @@ +/* HexChat + * Copyright (C) 2015 Patrick Griffis. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#import +#include + +void +notification_backend_show (const char *title, const char *text, int timeout) +{ + NSString *str_title = [[NSString alloc] initWithUTF8String:title]; + NSString *str_text = [[NSString alloc] initWithUTF8String:text]; + + NSUserNotification *userNotification = [NSUserNotification new]; + userNotification.title = str_title; + userNotification.informativeText = str_text; + + NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter]; + [center scheduleNotification:userNotification]; + + [str_title release]; + [str_text release]; +} + +int +notification_backend_init (void) +{ + return 1; +} + +void +notification_backend_deinit (void) +{ +} + +int +notification_backend_supported (void) +{ + return gtkosx_application_get_bundle_id () != NULL; +}