diff options
-rw-r--r-- | mk/modules.mk | 4 | ||||
-rw-r--r-- | modules/gtk/gtk_mod.c | 58 | ||||
-rw-r--r-- | modules/gtk/module.mk | 9 |
3 files changed, 62 insertions, 9 deletions
diff --git a/mk/modules.mk b/mk/modules.mk index 085a8c5..ac16662 100644 --- a/mk/modules.mk +++ b/mk/modules.mk @@ -225,6 +225,10 @@ ifeq ($(OS),freebsd) MODULES += dtmfio endif +ifneq ($(USE_GTK),) +USE_LIBNOTIFY := $(shell pkg-config 'libnotify glib-2.0 < 2.40' && echo "yes") +endif + endif # ------------------------------------------------------------------------- # diff --git a/modules/gtk/gtk_mod.c b/modules/gtk/gtk_mod.c index 427912c..2a99a28 100644 --- a/modules/gtk/gtk_mod.c +++ b/modules/gtk/gtk_mod.c @@ -12,6 +12,14 @@ #include <gio/gio.h> #include "gtk_mod.h" +#ifdef USE_LIBNOTIFY +#include <libnotify/notify.h> +#endif + +#if GLIB_CHECK_VERSION(2,40,0) || defined(USE_LIBNOTIFY) +#define USE_NOTIFICATIONS 1 +#endif + /* About */ #define COPYRIGHT " Copyright (C) 2010 - 2015 Alfred E. Heggestad et al." #define COMMENTS "A modular SIP User-Agent with audio and video support" @@ -265,18 +273,21 @@ static void accounts_menu_set_status(struct gtk_mod *mod, } +#ifdef USE_NOTIFICATIONS static void notify_incoming_call(struct gtk_mod *mod, struct call *call) { - GNotification *notification; - GVariant *target; + static const char *title = "Incoming call"; + const char *msg = call_peeruri(call); + +#if GLIB_CHECK_VERSION(2,40,0) char id[64]; + GVariant *target; + GNotification *notification = g_notification_new(title); re_snprintf(id, sizeof id, "incoming-call-%p", call); id[sizeof id - 1] = '\0'; - notification = g_notification_new("Incoming call"); - #if GLIB_CHECK_VERSION(2,42,0) g_notification_set_priority(notification, G_NOTIFICATION_PRIORITY_URGENT); @@ -285,14 +296,25 @@ static void notify_incoming_call(struct gtk_mod *mod, #endif target = g_variant_new_int64(GPOINTER_TO_INT(call)); - g_notification_set_body(notification, call_peeruri(call)); + g_notification_set_body(notification, msg); g_notification_add_button_with_target_value(notification, "Answer", "app.answer", target); g_notification_add_button_with_target_value(notification, "Reject", "app.reject", target); g_application_send_notification(mod->app, id, notification); + +#elif defined(USE_LIBNOTIFY) + if (!notify_is_initted()) + return; + NotifyNotification* notification = notify_notification_new(title, + msg, "midori"); + notify_notification_set_urgency(notification, NOTIFY_URGENCY_CRITICAL); + notify_notification_show(notification, NULL); + +#endif g_object_unref(notification); } +#endif static void denotify_incoming_call(struct gtk_mod *mod, @@ -392,9 +414,11 @@ static void ua_event_handler(struct ua *ua, accounts_menu_set_status(mod, ua, ev); break; +#ifdef USE_NOTIFICATIONS case UA_EVENT_CALL_INCOMING: notify_incoming_call(mod, call); break; +#endif case UA_EVENT_CALL_CLOSED: win = get_call_window(mod, call); @@ -435,15 +459,16 @@ static void ua_event_handler(struct ua *ua, gdk_threads_leave(); } +#ifdef USE_NOTIFICATIONS static void message_handler(const struct pl *peer, const struct pl *ctype, struct mbuf *body, void *arg) { struct gtk_mod *mod = arg; - GNotification *notification; char title[128]; char msg[512]; (void)ctype; + /* Display notification of chat */ re_snprintf(title, sizeof title, "Chat from %r", peer); @@ -452,11 +477,24 @@ static void message_handler(const struct pl *peer, const struct pl *ctype, re_snprintf(msg, sizeof msg, "%b", mbuf_buf(body), mbuf_get_left(body)); - notification = g_notification_new(title); +#if GLIB_CHECK_VERSION(2,40,0) + GNotification *notification = g_notification_new(title); g_notification_set_body(notification, msg); g_application_send_notification(mod->app, NULL, notification); + +#elif defined(USE_LIBNOTIFY) + (void)mod; + + if (!notify_is_initted()) + return; + NotifyNotification* notification = notify_notification_new(title, msg, + "baresip"); + notify_notification_show(notification, NULL); + +#endif g_object_unref(notification); } +#endif static void popup_menu(struct gtk_mod *mod, GtkMenuPositionFunc position, @@ -611,6 +649,10 @@ static void *gtk_thread(void *arg) err = NULL; } +#ifdef USE_LIBNOTIFY + notify_init("baresip"); +#endif + mod->status_icon = gtk_status_icon_new_from_icon_name("call-start"); gtk_status_icon_set_tooltip_text (mod->status_icon, "baresip"); @@ -859,9 +901,11 @@ static int module_init(void) return err; aufilt_register(&vumeter); +#ifdef USE_NOTIFICATIONS err = message_init(message_handler, &mod_obj); if (err) return err; +#endif err = cmd_register(cmdv, ARRAY_SIZE(cmdv)); diff --git a/modules/gtk/module.mk b/modules/gtk/module.mk index aae0145..2ed3709 100644 --- a/modules/gtk/module.mk +++ b/modules/gtk/module.mk @@ -8,8 +8,13 @@ MOD := gtk $(MOD)_SRCS += gtk_mod.c call_window.c dial_dialog.c transfer_dialog.c \ uri_entry.c -$(MOD)_LFLAGS += `pkg-config --libs gtk+-2.0 ` -$(MOD)_CFLAGS += `pkg-config --cflags gtk+-2.0 ` +$(MOD)_LFLAGS += `pkg-config --libs gtk+-2.0 $($(MOD)_EXTRA)` +$(MOD)_CFLAGS += `pkg-config --cflags gtk+-2.0 $($(MOD)_EXTRA)` $(MOD)_CFLAGS += -Wno-strict-prototypes +ifneq ($(USE_LIBNOTIFY),) +$(MOD)_EXTRA = libnotify +$(MOD)_CFLAGS += -DUSE_LIBNOTIFY=1 +endif + include mk/mod.mk |