From 8cfbb72337f76934002b8606fa715719cfe4d80c Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 4 Mar 2014 20:01:19 +0000 Subject: [PATCH 1/6] Added OSX desktop notifications using terminal-notifier Requires Xcode WIP - No configure.ac changes --- src/ui/notifier.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/ui/notifier.c b/src/ui/notifier.c index ebc61e0d..8582acf2 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -23,6 +23,7 @@ #include #include +#include #include #ifdef HAVE_LIBNOTIFY @@ -205,6 +206,25 @@ _notify(const char * const message, int timeout, Shell_NotifyIcon(NIM_MODIFY, &nid); #endif + GString *notify_command = g_string_new("terminal-notifier -title 'Profanity' -message '"); + g_string_append(notify_command, message); + g_string_append(notify_command, "'"); + + char *term_name = getenv("TERM_PROGRAM"); + char *app_id = NULL; + if (g_strcmp0(term_name, "Apple_Terminal") == 0) { + app_id = "com.apple.Terminal"; + } else if (g_strcmp0(term_name, "iTerm.app") == 0) { + app_id = "com.googlecode.iterm2"; + } + + if (app_id != NULL) { + g_string_append(notify_command, " -sender "); + g_string_append(notify_command, app_id); + } + + system(notify_command->str); + g_string_free(notify_command, TRUE); } void From 3f73a55cb0e1f25b1052bff9a0c769244dbb830e Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 4 Mar 2014 20:16:47 +0000 Subject: [PATCH 2/6] Log message when cannot send desktop nofication --- src/ui/notifier.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 8582acf2..7c366434 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -223,7 +223,11 @@ _notify(const char * const message, int timeout, g_string_append(notify_command, app_id); } - system(notify_command->str); + int res = system(notify_command->str); + if (res == -1) { + log_error("Could not send desktop notificaion."); + } + g_string_free(notify_command, TRUE); } From b5171cb054c9d9f4efb2ddb69c41a922b14f0aab Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 4 Mar 2014 22:59:09 +0000 Subject: [PATCH 3/6] Added configure checks to enable desktop notifications on OSX --- configure.ac | 37 ++++++++++++++++++++++++++++++------- src/ui/notifier.c | 2 ++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index efe4fcc3..245d20a3 100644 --- a/configure.ac +++ b/configure.ac @@ -23,7 +23,13 @@ AC_PROG_CC ### Get canonical host AC_CANONICAL_HOST -AS_IF([test "x$host_os" = xcygwin], +PLATFORM="unknown" +AS_CASE([$host_os], + [darwin*], [PLATFORM="osx"], + [cygwin], [PLATFORM="cygwin"], + [PLATFORM="nix"]) + +AS_IF([test "x$PLATFORM" = xcygwin], [AC_DEFINE([PLATFORM_CYGWIN], [1], [Cygwin])]) ### Options @@ -111,12 +117,28 @@ PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.26], [], [AC_MSG_ERROR([glib 2.26 or higher is required for profanity])]) PKG_CHECK_MODULES([curl], [libcurl], [], [AC_MSG_ERROR([libcurl is required for profanity])]) -AS_IF([test "x$enable_notifications" != xno], - [PKG_CHECK_MODULES([libnotify], [libnotify], - [AC_DEFINE([HAVE_LIBNOTIFY], [1], [libnotify module])], - [AS_IF([test "x$enable_notifications" = xyes], - [AC_MSG_ERROR([libnotify is required but does not exist])], - [AC_MSG_NOTICE([libnotify support will be disabled])])])]) + +### Check for desktop notification support +### Linux requires libnotify +### Windows uses native OS calls +### OSX requires terminal-notifier + +AS_IF([test "x$PLATFORM" = xosx], + [AS_IF([test "x$enable_notifications" != xno], + [NOTIFIER_PATH="no" + AC_PATH_PROG(NOTIFIER_PATH, terminal-notifier, no) + AS_IF([test "x$NOTIFIER_PATH" = xno], + [AS_IF([test "x$enable_notifications" = xyes], + [AC_MSG_ERROR([terminal-notifier not found, required for desktop notifications.])], + [AC_MSG_NOTICE([Desktop notifications not supported.])])], + [AC_DEFINE([HAVE_OSXNOTIFY], [1], [terminal notifier])])])], + [test "x$PLATFORM" = xnix], + [AS_IF([test "x$enable_notifications" != xno], + [PKG_CHECK_MODULES([libnotify], [libnotify], + [AC_DEFINE([HAVE_LIBNOTIFY], [1], [libnotify module])], + [AS_IF([test "x$enable_notifications" = xyes], + [AC_MSG_ERROR([libnotify is required but does not exist])], + [AC_MSG_NOTICE([libnotify support will be disabled])])])])]) # TODO: rewrite this if test "x$with_xscreensaver" = xyes; then @@ -193,6 +215,7 @@ AC_CONFIG_FILES([Makefile]) AC_OUTPUT echo "" +echo "PLATFORM : $host_os" echo "PACKAGE_STATUS : $PACKAGE_STATUS" echo "AM_CFLAGS : $AM_CFLAGS" echo "AM_CPPFLAGS : $AM_CPPFLAGS" diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 7c366434..16fd814f 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -206,6 +206,7 @@ _notify(const char * const message, int timeout, Shell_NotifyIcon(NIM_MODIFY, &nid); #endif +#ifdef HAVE_OSXNOTIFY GString *notify_command = g_string_new("terminal-notifier -title 'Profanity' -message '"); g_string_append(notify_command, message); g_string_append(notify_command, "'"); @@ -229,6 +230,7 @@ _notify(const char * const message, int timeout, } g_string_free(notify_command, TRUE); +#endif } void From 3f9ca603ae93d563d8eaa2eb444e998b98d11a77 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 4 Mar 2014 23:42:12 +0000 Subject: [PATCH 4/6] Added libgcrypt-devel to cygwin dependencies --- install-all.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install-all.sh b/install-all.sh index ed9293e6..7c2fcccc 100755 --- a/install-all.sh +++ b/install-all.sh @@ -51,9 +51,9 @@ cygwin_prepare() mv apt-cyg /usr/local/bin/ if [ -n "$CYG_MIRROR" ]; then - apt-cyg -m $CYG_MIRROR install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel + apt-cyg -m $CYG_MIRROR install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel else - apt-cyg install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel + apt-cyg install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel fi From a14c42a32a5ed238687ac1bbd3fa79de4cde7553 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 4 Mar 2014 23:57:57 +0000 Subject: [PATCH 5/6] Removed gcc linking from cygwin install --- install-all.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/install-all.sh b/install-all.sh index 7c2fcccc..32f6a128 100755 --- a/install-all.sh +++ b/install-all.sh @@ -57,8 +57,6 @@ cygwin_prepare() fi - ln -s /usr/bin/gcc-3.exe /usr/bin/gcc.exe - export LIBRARY_PATH=/usr/local/lib/ } From 4d00f788e90d5b0b76a51f21e2d8d87675046066 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 5 Mar 2014 00:11:18 +0000 Subject: [PATCH 6/6] Fixed spelling mistake in configure.ac --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index efe4fcc3..b282ee42 100644 --- a/configure.ac +++ b/configure.ac @@ -163,7 +163,7 @@ elif test "x$enable_otr" = x; then ]])], [AM_CONDITIONAL([BUILD_OTR], [true]) AM_CONDITIONAL([BUILD_OTR4], [true]) AC_DEFINE([HAVE_LIBOTR], [1], [Have libotr])], [AM_CONDITIONAL([BUILD_OTR], [true]) AM_CONDITIONAL([BUILD_OTR3], [true]) AC_DEFINE([HAVE_LIBOTR], [1], [Have libotr])])], - [AC_MSG_NOTICE([libotr not found, otr entryption support not enabled])]) + [AC_MSG_NOTICE([libotr not found, otr encryption support not enabled])]) fi ### cmocka is required only for tests, profanity shouldn't be linked with it