summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2010-10-11 23:45:15 -0400
committerJason Woodward2010-10-11 23:45:15 -0400
commit86e575e19432ba7fddd19d431235c5928803bf9e (patch)
treeef877239da6a8c80f68589f5f5c167fa0c240b3a
parent108e69366906bd4a944cd6d4cf9a39c9a09b0f69 (diff)
downloadslapt-update-service-86e575e19432ba7fddd19d431235c5928803bf9e.tar.gz
make notifications optional at build time using --with-notification0.5.0b
-rw-r--r--configure.ac14
-rw-r--r--src/client.c14
2 files changed, 25 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 978ee10..f31c3a8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,9 +46,17 @@ AC_SUBST(DBUS_LIBS)
PKG_CHECK_MODULES(GTK, [gtk+-2.0])
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
-PKG_CHECK_MODULES(NOTIFY, [libnotify])
-AC_SUBST(NOTIFY_CFLAGS)
-AC_SUBST(NOTIFY_LIBS)
+AC_ARG_WITH(
+ [notification],
+ AC_HELP_STRING([--with-notification], [use notification (default is no)]),
+)
+AS_IF([test "x$with_notification" = "xyes"], [
+ PKG_CHECK_MODULES(NOTIFY, [libnotify])
+ AC_DEFINE(USE_LIBNOTIFY, 1, [has notification])
+ AC_SUBST(NOTIFY_CFLAGS)
+ AC_SUBST(NOTIFY_LIBS)
+])
+
AS_AC_EXPAND(DATADIR, $datadir)
DBUS_SYSTEM_SERVICES_DIR="$DATADIR/dbus-1/system-services"
diff --git a/src/client.c b/src/client.c
index 7e471f0..f360e1b 100644
--- a/src/client.c
+++ b/src/client.c
@@ -26,7 +26,9 @@
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
+#ifdef USE_LIBNOTIFY
#include <libnotify/notify.h>
+#endif
#define _(x) gettext(x)
#define SUN_RUNNING_ICON PIXMAPS_DIR "/slapt-update-notifier-idle.png"
@@ -98,6 +100,7 @@ void tray_menu (GtkStatusIcon *status_icon, guint button, guint activate_time, g
);
}
+#ifdef USE_LIBNOTIFY
static void notify_callback(NotifyNotification *handle, const char *action, void *user_data)
{
GMainLoop *loop = (GMainLoop*)user_data;
@@ -141,6 +144,7 @@ gboolean show_notification (gpointer data)
return FALSE;
}
+#endif
void tray_destroy (struct slapt_update_notifier *sun)
{
@@ -155,11 +159,14 @@ void tray_destroy (struct slapt_update_notifier *sun)
static void hide_sun (void)
{
+#ifdef USE_LIBNOTIFY
NotifyNotification *n = g_object_get_data(G_OBJECT(sun->tray_icon),"notification");
+#endif
GMainLoop *loop = g_object_get_data(G_OBJECT(sun->tray_icon), "notification_loop");
gtk_status_icon_set_visible(sun->tray_icon, FALSE);
+#ifdef USE_LIBNOTIFY
if ( n != NULL ) {
GError *error = NULL;
if (notify_notification_close(n, &error) != TRUE) {
@@ -167,6 +174,7 @@ static void hide_sun (void)
g_error_free (error);
}
}
+#endif
if ( loop != NULL )
g_main_loop_quit(loop);
@@ -191,7 +199,9 @@ static void check_for_updates_callback (DBusGProxy *proxy, guint OUT_count, GErr
}
gtk_status_icon_set_visible(sun->tray_icon, TRUE);
+#ifdef USE_LIBNOTIFY
show_notification(NULL);
+#endif
}
static void refresh_cache_callback (DBusGProxy *proxy, GError *error, gpointer userdata)
@@ -227,7 +237,9 @@ int main (int argc, char *argv[])
GtkWidget *menuitem = NULL;
gtk_init (&argc, &argv);
+#ifdef USE_LIBNOTIFY
notify_init("slapt-update-notifier");
+#endif
sun = malloc(sizeof *sun);
sun->tray_icon = gtk_status_icon_new ();
@@ -267,7 +279,9 @@ int main (int argc, char *argv[])
g_object_unref (sun->proxy);
free(sun);
+#ifdef USE_LIBNOTIFY
notify_uninit();
+#endif
return 0;
}