Patch to add libnotify support to nm-applet



Hi guys,

Here's a patch that I just finished up to add network state change
notifications with libnotify/notification-daemon, to nm-applet. It's
working pretty good for me. Do you think I can commit this upstream?
Thanks.

-- dobey

2006-02-14  Rodney Dawes  <dobey novell com>

	* configure.in: Add a check for libnotify, to enable notifications

	* gnome/applet/Makefile.am: Add NOTIFY_{CFLAGS,LIBS} for the applet

	* gnome/applet/applet.c: Include notify.h if notifications are enabled
	(nmwa_notify_state): New method to notify the user of changes
	(nmwa_update_state): Call the new nmwa_notify_state method here, if
	we have enabled notifications

Index: configure.in
===================================================================
RCS file: /cvs/gnome/NetworkManager/configure.in,v
retrieving revision 1.118
diff -u -p -r1.118 configure.in
--- configure.in	1 Feb 2006 18:14:10 -0000	1.118
+++ configure.in	14 Feb 2006 21:43:27 -0000
@@ -159,6 +159,13 @@ PKG_CHECK_MODULES(GNOME_KEYRING, gnome-k
 AC_SUBST(GNOME_KEYRING_CFLAGS)
 AC_SUBST(GNOME_KEYRING_LIBS)
 
+PKG_CHECK_MODULES([NOTIFY], [libnotify >= 0.3.0], [enable_notify=yes],
+			    [enable_notify=no])
+if test "x$enable_notify" != "xno"; then
+   AC_DEFINE_UNQUOTED([ENABLE_NOTIFY], [1],
+   [Enable notifications with libnotify])
+fi
+
 PKG_CHECK_MODULES(LIBNL, libnl-1)
 AC_SUBST(LIBNL_CFLAGS)
 AC_SUBST(LIBNL_LIBS)
Index: gnome/applet/Makefile.am
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/Makefile.am,v
retrieving revision 1.16
diff -u -p -r1.16 Makefile.am
--- gnome/applet/Makefile.am	16 Jan 2006 18:34:13 -0000	1.16
+++ gnome/applet/Makefile.am	14 Feb 2006 21:43:27 -0000
@@ -17,6 +17,7 @@ nm_applet_CPPFLAGS =						\
 	$(LIBGNOMEUI_CFLAGS)					\
 	$(PANEL_APPLET_CFLAGS)					\
 	$(GNOME_KEYRING_CFLAGS)					\
+	$(NOTIFY_CFLAGS)					\
 	-DICONDIR=\""$(datadir)/pixmaps"\"			\
 	-DGLADEDIR=\""$(gladedir)"\"				\
 	-DBINDIR=\""$(bindir)"\"					\
@@ -97,6 +98,7 @@ nm_applet_LDADD =						\
 	$(GCONF_LIBS)						\
 	$(LIBGNOMEUI_LIBS)					\
 	$(GNOME_KEYRING_LIBS)				\
+	$(NOTIFY_LIBS)					\
 	$(top_builddir)/utils/libnmutils.la	\
 	$(top_builddir)/libnm-util/libnm-util.la	\
 	$(NULL)
Index: gnome/applet/applet.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet.c,v
retrieving revision 1.103
diff -u -p -r1.103 applet.c
--- gnome/applet/applet.c	30 Jan 2006 18:45:16 -0000	1.103
+++ gnome/applet/applet.c	14 Feb 2006 21:43:28 -0000
@@ -43,6 +43,10 @@
 #include <glade/glade.h>
 #include <gconf/gconf-client.h>
 
+#ifdef ENABLE_NOTIFY
+#include <libnotify/notify.h>
+#endif
+
 #include "applet.h"
 #include "applet-compat.h"
 #include "applet-dbus.h"
@@ -1065,6 +1069,81 @@ static gboolean animation_timeout (NMWir
 
 
 /*
+ * nmwa_notify_state
+ *
+ * Notify the user of change in connectivity
+ *
+ */
+static void nmwa_notify_state (NMWirelessApplet *applet, NetworkDevice *act_dev, WirelessNetwork *active_network)
+{
+#ifdef ENABLE_NOTIFY
+	NotifyNotification *  n;
+	NotifyUrgency         urgency = NOTIFY_URGENCY_NORMAL;
+	char *                title = NULL;
+	char *                msg = NULL;
+	char *                icon = NULL;
+	static int            state = NM_STATE_ASLEEP;
+
+	if (!notify_is_initted ())
+		notify_init ("NetworkManager");
+
+	switch (applet->nm_state)
+	{
+	     case NM_STATE_ASLEEP:
+	     case NM_STATE_DISCONNECTED:
+			title = g_strdup (_("Disconnected"));
+			msg = g_strdup (_("The network connection has been disconnected."));
+			icon = g_strdup ("nm-no-connection");
+			urgency = NOTIFY_URGENCY_CRITICAL;
+			break;
+
+	     case NM_STATE_CONNECTED:
+			title = g_strdup (_("Connected"));
+			if (network_device_is_wired (act_dev))
+			{
+				msg = g_strdup (_("Connected to a wired network interface."));
+				icon = g_strdup ("nm-device-wired");
+				urgency = NOTIFY_URGENCY_LOW;
+			}
+			else if (network_device_is_wireless (act_dev))
+			{
+				if (applet->is_adhoc)
+				{
+					msg = g_strdup (_("An ad-hoc wireless network connection has been established."));
+					icon = g_strdup ("nm-adhoc");
+				}
+				else
+				{
+					msg = g_strdup_printf (_("A wireless network connection to '%s' has been established."),
+									   active_network ? wireless_network_get_essid (active_network) : "(unknown)");
+					icon = g_strdup ("nm-device-wireless");
+				}
+			}
+
+			break;
+
+	     default:
+			break;
+	}
+
+	if (state != applet->nm_state && title && msg && icon) {
+		n = notify_notification_new (title, msg, icon, NULL);
+		notify_notification_set_urgency (n, urgency);
+
+		notify_notification_show (n, NULL);
+
+		g_object_unref (n);
+	}
+	g_free (icon);
+	g_free (msg);
+	g_free (title);
+
+	state = applet->nm_state;
+#endif
+}
+
+
+/*
  * nmwa_update_state
  *
  * Figure out what the currently active device is from NetworkManager, its type,
@@ -1188,6 +1267,8 @@ done:
 		else
 			show_applet = FALSE;
 	}
+
+	nmwa_notify_state (applet, act_dev, active_network);
 
 	/* determine if we should hide the notification icon */
 	if (show_applet)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]