Blame SOURCES/xchat-2.8.8-link-against-libnotify.patch

8fa6cd
From: Christopher Aillon <caillon@redhat.com>
8fa6cd
Date: Thu, 7 Apr 2011 19:34:14 -0700
8fa6cd
Subject: [PATCH] Link directly against libnotify
8fa6cd
8fa6cd
Dynamically loading the library isn't ideal since the soname
8fa6cd
can change silently on us.  Additionally, notify-send is
8fa6cd
shipped as part of libnotify, so we aren't actually bringing
8fa6cd
in a new dependency.  Since we'd need to patch the source and
8fa6cd
rebuild for new sonames anyway, there's little benefit to
8fa6cd
dynamically loading libnotify.
8fa6cd
8fa6cd
Plus, this has the benefit of cleaning up the code, as well as
8fa6cd
ensuring we'll catch any future soname changes sooner.
8fa6cd
8fa6cd
https://bugzilla.redhat.com/show_bug.cgi?id=693362
8fa6cd
https://sourceforge.net/tracker/?func=detail&aid=3280223&group_id=239&atid=100239
8fa6cd
---
8fa6cd
 configure.in             |   23 +++++++
8fa6cd
 src/fe-gtk/plugin-tray.c |  144 ++++++++++-------------------------------------
8fa6cd
 2 files changed, 55 insertions(+), 112 deletions(-)
8fa6cd
8fa6cd
diff -p -U8 xchat-2.8.8/configure.in.libnotifyso4 xchat-2.8.8/configure.in
8fa6cd
--- xchat-2.8.8/configure.in.libnotifyso4	2010-05-29 23:01:16.000000000 -0700
8fa6cd
+++ xchat-2.8.8/configure.in	2011-04-07 19:27:00.448137113 -0700
8fa6cd
@@ -34,16 +34,17 @@ AH_VERBATIM([PREFIX],[#undef PREFIX])
8fa6cd
 AH_VERBATIM([XCHATLIBDIR],[#undef XCHATLIBDIR])
8fa6cd
 AH_VERBATIM([XCHATSHAREDIR],[#undef XCHATSHAREDIR])
8fa6cd
 AH_VERBATIM([SOCKS],[#undef SOCKS])
8fa6cd
 AH_VERBATIM([USE_MSPROXY],[#undef USE_MSPROXY])
8fa6cd
 dnl AH_VERBATIM([USE_GNOME],[#undef USE_GNOME])
8fa6cd
 AH_VERBATIM([USE_SHM],[#undef USE_SHM])
8fa6cd
 AH_VERBATIM([USE_GTKSPELL],[#undef USE_GTKSPELL])
8fa6cd
 AH_VERBATIM([USE_LIBSEXY],[#undef USE_LIBSEXY])
8fa6cd
+AH_VERBATIM([USE_LIBNOTIFY],[#undef USE_LIBNOTIFY])
8fa6cd
 AH_VERBATIM([USE_IPV6],[#undef USE_IPV6])
8fa6cd
 AH_VERBATIM([USE_MMX],[#undef USE_MMX])
8fa6cd
 AH_VERBATIM([USE_OPENSSL],[#undef USE_OPENSSL])
8fa6cd
 AH_VERBATIM([USE_PLUGIN],[#undef USE_PLUGIN])
8fa6cd
 AH_VERBATIM([USE_XFT],[#undef USE_XFT])
8fa6cd
 AH_VERBATIM([USE_XLIB],[#undef USE_XLIB])
8fa6cd
 AH_VERBATIM([USE_SIGACTION],[#undef USE_SIGACTION])
8fa6cd
 AH_VERBATIM([USING_FREEBSD],[#undef USING_FREEBSD])
8fa6cd
@@ -126,16 +127,20 @@ AC_ARG_ENABLE(tcl,
8fa6cd
 AC_ARG_ENABLE(plugin,
8fa6cd
 [  --disable-plugin        disable plugin support],
8fa6cd
         plugin=$enableval, plugin=yes)
8fa6cd
 
8fa6cd
 AC_ARG_ENABLE(dbus,
8fa6cd
 [  --disable-dbus          disable DBUS support],
8fa6cd
         dbus=$enableval, dbus=yes)
8fa6cd
 
8fa6cd
+AC_ARG_ENABLE(libnotify,
8fa6cd
+[  --disable-libnotify     disable libnotify support],
8fa6cd
+        libnotify=$enableval, libnotify=yes)
8fa6cd
+
8fa6cd
 AC_ARG_ENABLE(mmx,
8fa6cd
 [  --disable-mmx           disable MMX assembly routines],
8fa6cd
         mmx=$enableval, mmx=yes)
8fa6cd
 
8fa6cd
 AC_ARG_ENABLE(shm,
8fa6cd
 [  --enable-shm            enable use of XShm for fast tinting (default: no)],
8fa6cd
         shm=$enableval, shm=no)
8fa6cd
 
8fa6cd
@@ -482,16 +487,32 @@ if test "x$dbus" = "xyes" ; then
8fa6cd
 
8fa6cd
 		DBUS_SERVICES_DIR="$DATADIR/dbus-1/services"
8fa6cd
 		AC_SUBST(DBUS_SERVICES_DIR)
8fa6cd
 		AC_DEFINE_UNQUOTED(DBUS_SERVICES_DIR, "$DBUS_SERVICES_DIR", [Where services dir for DBUS is])
8fa6cd
 	fi
8fa6cd
 fi
8fa6cd
 
8fa6cd
 dnl *********************************************************************
8fa6cd
+dnl ** LIBNOTIFY ********************************************************
8fa6cd
+dnl *********************************************************************
8fa6cd
+
8fa6cd
+if test "x$libnotify" = "xyes" ; then
8fa6cd
+	PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= 0.4, [], [
8fa6cd
+		AC_MSG_RESULT(no)
8fa6cd
+		libnotify=no
8fa6cd
+	])
8fa6cd
+	if test "$libnotify" != "no" ; then
8fa6cd
+		GUI_LIBS="$GUI_LIBS $LIBNOTIFY_LIBS"
8fa6cd
+		GUI_CFLAGS="$GUI_CFLAGS $LIBNOTIFY_CFLAGS"
8fa6cd
+		AC_DEFINE(USE_LIBNOTIFY)
8fa6cd
+	fi
8fa6cd
+fi
8fa6cd
+
8fa6cd
+dnl *********************************************************************
8fa6cd
 dnl ** SPELL ************************************************************
8fa6cd
 dnl *********************************************************************
8fa6cd
 
8fa6cd
 if test "$spell" = "gtkspell" ; then
8fa6cd
 	PKG_CHECK_MODULES(GTKSPELL, gtkspell-2.0 >= 2.0.2, [], [
8fa6cd
 		AC_MSG_RESULT(no)
8fa6cd
 		spell=no
8fa6cd
 	])
8fa6cd
@@ -519,16 +540,17 @@ if test "$spell" = "static" ; then
8fa6cd
 fi
8fa6cd
 
8fa6cd
 dnl *********************************************************************
8fa6cd
 dnl ** CONDITIONALS *****************************************************
8fa6cd
 dnl *********************************************************************
8fa6cd
 
8fa6cd
 AM_CONDITIONAL(USE_OPENSSL, test "x$openssl" = "xyes")
8fa6cd
 AM_CONDITIONAL(USE_LIBSEXY, test "x$spell" = "xstatic")
8fa6cd
+AM_CONDITIONAL(USE_LIBNOTIFY, test "x$libnotify" = "xyes")
8fa6cd
 AM_CONDITIONAL(DO_TEXT, test "x$textfe" = "xyes")
8fa6cd
 AM_CONDITIONAL(DO_GTK, test "x$gtkfe" = "xyes")
8fa6cd
 AM_CONDITIONAL(DO_PERL, test "x$perl" = "xyes")
8fa6cd
 AM_CONDITIONAL(DO_PYTHON, test "x$python" = "xyes")
8fa6cd
 AM_CONDITIONAL(DO_TCL, test "x$tcl" = "xyes")
8fa6cd
 AM_CONDITIONAL(DO_PLUGIN, test "x$plugin" = "xyes")
8fa6cd
 AM_CONDITIONAL(USE_DBUS, test "x$dbus" = "xyes")
8fa6cd
 AM_CONDITIONAL(DO_GCONF, test "x$GCONFTOOL" != "xno")
8fa6cd
@@ -807,16 +829,17 @@ echo mmx tinting ......... : $mmx\	spell
8fa6cd
 echo XShm tinting ........ : $shm\	plugin interface ...... : $plugin
8fa6cd
 if test "$xft" = no; then
8fa6cd
   echo text backend ........ : pango\	nls/gettext ........... : $USE_NLS
8fa6cd
 else
8fa6cd
   echo text backend ........ : xft\	nls/gettext ........... : $USE_NLS
8fa6cd
 fi
8fa6cd
 echo openssl support ..... : $openssl\	ipv6 support .......... : $ipv6
8fa6cd
 echo dbus support ........ : $dbus\	msproxy ntlm \(ISA\) .... : $have_ntlm
8fa6cd
+echo libnotify support ... : $libnotify
8fa6cd
 echo
8fa6cd
 echo The binary will be installed in $prefix/bin
8fa6cd
 echo
8fa6cd
 
8fa6cd
 if test "$gtkfe" = no; then
8fa6cd
 	echo Warning: The GTK \(GUI\) frontend will not be built.
8fa6cd
 	echo
8fa6cd
 fi
8fa6cd
diff -p -U8 xchat-2.8.8/src/fe-gtk/plugin-tray.c.libnotifyso4 xchat-2.8.8/src/fe-gtk/plugin-tray.c
8fa6cd
--- xchat-2.8.8/src/fe-gtk/plugin-tray.c.libnotifyso4	2011-04-07 17:57:27.524307905 -0700
8fa6cd
+++ xchat-2.8.8/src/fe-gtk/plugin-tray.c	2011-04-07 19:18:33.429475719 -0700
8fa6cd
@@ -10,17 +10,27 @@
8fa6cd
 #include "../common/fe.h"
8fa6cd
 #include "../common/util.h"
8fa6cd
 #include "fe-gtk.h"
8fa6cd
 #include "pixmaps.h"
8fa6cd
 #include "maingui.h"
8fa6cd
 #include "menu.h"
8fa6cd
 #include <gtk/gtk.h>
8fa6cd
 
8fa6cd
-#define LIBNOTIFY
8fa6cd
+#ifdef USE_LIBNOTIFY
8fa6cd
+#include <libnotify/notify.h>
8fa6cd
+#ifndef NOTIFY_CHECK_VERSION
8fa6cd
+#define NOTIFY_CHECK_VERSION(x,y,z) 0
8fa6cd
+#endif
8fa6cd
+#if NOTIFY_CHECK_VERSION(0,7,0)
8fa6cd
+#define XC_NOTIFY_NEW(a,b,c,d) notify_notification_new(a,b,c)
8fa6cd
+#else
8fa6cd
+#define XC_NOTIFY_NEW(a,b,c,d) notify_notification_new(a,b,c,d)
8fa6cd
+#endif
8fa6cd
+#endif
8fa6cd
 
8fa6cd
 typedef enum	/* current icon status */
8fa6cd
 {
8fa6cd
 	TS_NONE,
8fa6cd
 	TS_MESSAGE,
8fa6cd
 	TS_HIGHLIGHT,
8fa6cd
 	TS_FILEOFFER,
8fa6cd
 	TS_CUSTOM /* plugin */
8fa6cd
@@ -112,90 +122,16 @@ tray_count_networks (void)
8fa6cd
 
8fa6cd
 void
8fa6cd
 fe_tray_set_tooltip (const char *text)
8fa6cd
 {
8fa6cd
 	if (sticon)
8fa6cd
 		gtk_status_icon_set_tooltip (sticon, text);
8fa6cd
 }
8fa6cd
 
8fa6cd
-#ifdef LIBNOTIFY
8fa6cd
-
8fa6cd
-/* dynamic access to libnotify.so */
8fa6cd
-
8fa6cd
-static void *nn_mod = NULL;
8fa6cd
-/* prototypes */
8fa6cd
-static gboolean (*nn_init) (char *);
8fa6cd
-static void (*nn_uninit) (void);
8fa6cd
-/* recent versions of libnotify don't take the fourth GtkWidget argument, but passing an
8fa6cd
- * extra NULL argument will be fine */
8fa6cd
-static void *(*nn_new) (const gchar *summary, const gchar *message, const gchar *icon, gpointer dummy);
8fa6cd
-static gboolean (*nn_show) (void *noti, GError **error);
8fa6cd
-static void (*nn_set_timeout) (void *noti, gint timeout);
8fa6cd
-
8fa6cd
-static void
8fa6cd
-libnotify_cleanup (void)
8fa6cd
-{
8fa6cd
-	if (nn_mod)
8fa6cd
-	{
8fa6cd
-		nn_uninit ();
8fa6cd
-		g_module_close (nn_mod);
8fa6cd
-		nn_mod = NULL;
8fa6cd
-	}
8fa6cd
-}
8fa6cd
-
8fa6cd
-static gboolean
8fa6cd
-libnotify_notify_new (const char *title, const char *text, GtkStatusIcon *icon)
8fa6cd
-{
8fa6cd
-	void *noti;
8fa6cd
-
8fa6cd
-	if (!nn_mod)
8fa6cd
-	{
8fa6cd
-		nn_mod = g_module_open ("libnotify", G_MODULE_BIND_LAZY);
8fa6cd
-		if (!nn_mod)
8fa6cd
-		{
8fa6cd
-			nn_mod = g_module_open ("libnotify.so.1", G_MODULE_BIND_LAZY);
8fa6cd
-			if (!nn_mod)
8fa6cd
-				return FALSE;
8fa6cd
-		}
8fa6cd
-
8fa6cd
-		if (!g_module_symbol (nn_mod, "notify_init", (gpointer)&nn_init))
8fa6cd
-			goto bad;
8fa6cd
-		if (!g_module_symbol (nn_mod, "notify_uninit", (gpointer)&nn_uninit))
8fa6cd
-			goto bad;
8fa6cd
-		if (!g_module_symbol (nn_mod, "notify_notification_new", (gpointer)&nn_new))
8fa6cd
-			goto bad;
8fa6cd
-		if (!g_module_symbol (nn_mod, "notify_notification_show", (gpointer)&nn_show))
8fa6cd
-			goto bad;
8fa6cd
-		if (!g_module_symbol (nn_mod, "notify_notification_set_timeout", (gpointer)&nn_set_timeout))
8fa6cd
-			goto bad;
8fa6cd
-		if (!nn_init (PACKAGE_NAME))
8fa6cd
-			goto bad;
8fa6cd
-	}
8fa6cd
-
8fa6cd
-	text = strip_color (text, -1, STRIP_ALL|STRIP_ESCMARKUP);
8fa6cd
-	title = strip_color (title, -1, STRIP_ALL);
8fa6cd
-	noti = nn_new (title, text, XCHATSHAREDIR"/pixmaps/xchat.png", NULL);
8fa6cd
-	g_free ((char *)title);
8fa6cd
-	g_free ((char *)text);
8fa6cd
-
8fa6cd
-	nn_set_timeout (noti, prefs.input_balloon_time*1000);
8fa6cd
-	nn_show (noti, NULL);
8fa6cd
-	g_object_unref (G_OBJECT (noti));
8fa6cd
-
8fa6cd
-	return TRUE;
8fa6cd
-
8fa6cd
-bad:
8fa6cd
-	g_module_close (nn_mod);
8fa6cd
-	nn_mod = NULL;
8fa6cd
-	return FALSE;
8fa6cd
-}
8fa6cd
-
8fa6cd
-#endif
8fa6cd
-
8fa6cd
 void
8fa6cd
 fe_tray_set_balloon (const char *title, const char *text)
8fa6cd
 {
8fa6cd
 #ifndef WIN32
8fa6cd
 	const char *argv[8];
8fa6cd
 	const char *path;
8fa6cd
 	char time[16];
8fa6cd
 	WinStatus ws;
8fa6cd
@@ -208,52 +144,36 @@ fe_tray_set_balloon (const char *title, 
8fa6cd
 	/* bit 1 of flags means "no balloons unless hidden/iconified" */
8fa6cd
 	if (ws != WS_HIDDEN && (prefs.gui_tray_flags & 2))
8fa6cd
 		return;
8fa6cd
 
8fa6cd
 	/* FIXME: this should close the current balloon */
8fa6cd
 	if (!text)
8fa6cd
 		return;
8fa6cd
 
8fa6cd
-#ifdef LIBNOTIFY
8fa6cd
-	/* try it via libnotify.so */
8fa6cd
-	if (libnotify_notify_new (title, text, sticon))
8fa6cd
-		return;	/* success */
8fa6cd
-#endif
8fa6cd
+#ifdef USE_LIBNOTIFY
8fa6cd
+	NotifyNotification *notification;
8fa6cd
+	char *notify_text, *notify_title;
8fa6cd
 
8fa6cd
-	/* try it the crude way */
8fa6cd
-	path = g_find_program_in_path ("notify-send");
8fa6cd
-	if (path)
8fa6cd
-	{
8fa6cd
-		sprintf(time, "%d000",prefs.input_balloon_time);
8fa6cd
-		argv[0] = path;
8fa6cd
-		argv[1] = "-i";
8fa6cd
-		argv[2] = "gtk-dialog-info";
8fa6cd
-		if (access (XCHATSHAREDIR"/pixmaps/xchat.png", R_OK) == 0)
8fa6cd
-			argv[2] = XCHATSHAREDIR"/pixmaps/xchat.png";
8fa6cd
-		argv[3] = "-t";
8fa6cd
-		argv[4] = time;
8fa6cd
-		argv[5] = title;
8fa6cd
-		text = strip_color (text, -1, STRIP_ALL|STRIP_ESCMARKUP);
8fa6cd
-		argv[6] = text;
8fa6cd
-		argv[7] = NULL;
8fa6cd
-		xchat_execv (argv);
8fa6cd
-		g_free ((char *)path);
8fa6cd
-		g_free ((char *)text);
8fa6cd
-	}
8fa6cd
-	else
8fa6cd
-	{
8fa6cd
-		/* show this error only once */
8fa6cd
-		static unsigned char said_it = FALSE;
8fa6cd
-		if (!said_it)
8fa6cd
-		{
8fa6cd
-			said_it = TRUE;
8fa6cd
-			fe_message (_("Cannot find 'notify-send' to open balloon alerts.\nPlease install libnotify."), FE_MSG_ERROR);
8fa6cd
-		}
8fa6cd
-	}
8fa6cd
+	if (!notify_is_initted())
8fa6cd
+		notify_init(PACKAGE_NAME);
8fa6cd
+
8fa6cd
+	notify_text = strip_color (text, -1, STRIP_ALL|STRIP_ESCMARKUP);
8fa6cd
+	notify_title = strip_color (title, -1, STRIP_ALL);
8fa6cd
+
8fa6cd
+	notification = XC_NOTIFY_NEW (notify_title, notify_text, XCHATSHAREDIR"/pixmaps/xchat.png", NULL);
8fa6cd
+
8fa6cd
+	g_free ((char *)notify_title);
8fa6cd
+	g_free ((char *)notify_text);
8fa6cd
+
8fa6cd
+	notify_notification_set_timeout (notification, prefs.input_balloon_time*1000);
8fa6cd
+	notify_notification_show (notification, NULL);
8fa6cd
+
8fa6cd
+	g_object_unref (notification);
8fa6cd
+#endif
8fa6cd
 #endif
8fa6cd
 }
8fa6cd
 
8fa6cd
 static void
8fa6cd
 tray_set_balloonf (const char *text, const char *format, ...)
8fa6cd
 {
8fa6cd
 	va_list args;
8fa6cd
 	char *buf;
8fa6cd
@@ -840,13 +760,13 @@ tray_plugin_init (xchat_plugin *plugin_h
8fa6cd
 	return 1;       /* return 1 for success */
8fa6cd
 }
8fa6cd
 
8fa6cd
 int
8fa6cd
 tray_plugin_deinit (xchat_plugin *plugin_handle)
8fa6cd
 {
8fa6cd
 #ifdef WIN32
8fa6cd
 	tray_cleanup ();
8fa6cd
-#elif defined(LIBNOTIFY)
8fa6cd
-	libnotify_cleanup ();
8fa6cd
+#elif defined(USE_LIBNOTIFY)
8fa6cd
+	notify_uninit ();
8fa6cd
 #endif
8fa6cd
 	return 1;
8fa6cd
 }