Re: Patch to add libnotify support to nm-applet



Tim Niemueller wrote:
> Rodney Dawes wrote:
> 
>> notifications with libnotify/notification-daemon, to nm-applet. It's
> 
> I like it. But I would even like it better if it would display the
> notification like gnome-power-manager with an arrow pointing to the
> object in the notification area that this notification belongs to.

I stole the bits from g-p-m and applied it to your patch.
The notification is now placed "correctly".
Feel free to use it.

Cheers,
Michael

-- 
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?
? dispatcher-daemon/.deps
? gnome/applet/.deps
? gnome/libnm_glib/.deps
? gnome/vpn-properties/.deps
? libnm-util/.deps
? po/stamp-it
? src/.deps
? src/backends/.deps
? src/dhcp-manager/.deps
? src/named-manager/.deps
? src/vpn-manager/.deps
? test/.deps
? test/libnm-util/.deps
? test/test-common/.deps
? utils/.deps
? vpn-daemons/pptp/auth-dialog/.deps
? vpn-daemons/pptp/po/stamp-it
? vpn-daemons/pptp/properties/.deps
? vpn-daemons/pptp/src/.deps
? vpn-daemons/vpnc/auth-dialog/.deps
? vpn-daemons/vpnc/po/stamp-it
? vpn-daemons/vpnc/properties/.deps
? vpn-daemons/vpnc/src/.deps
Index: gnome/applet/Makefile.am
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/Makefile.am,v
retrieving revision 1.16
diff -u -3 -p -r1.16 Makefile.am
--- gnome/applet/Makefile.am	16 Jan 2006 18:34:13 -0000	1.16
+++ gnome/applet/Makefile.am	15 Feb 2006 03:37:58 -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 -3 -p -r1.103 applet.c
--- gnome/applet/applet.c	30 Jan 2006 18:45:16 -0000	1.103
+++ gnome/applet/applet.c	15 Feb 2006 03:37:59 -0000
@@ -33,6 +33,7 @@
 
 #include <string.h>
 #include <gtk/gtk.h>
+#include <gtk/gtkwidget.h>
 #include <glib/gi18n.h>
 #include <libgnomeui/libgnomeui.h>
 
@@ -43,6 +44,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"
@@ -1063,6 +1068,116 @@ static gboolean animation_timeout (NMWir
 	return TRUE;
 }
 
+#ifdef ENABLE_NOTIFY
+/*
+ * get_widget_position
+ *
+ * Helper function to determine the x/y location of a widget
+ *
+ */
+static gboolean get_widget_position (GtkWidget *widget,
+				     int       *x,
+				     int       *y)
+{
+        /* assertion checks */
+        g_assert (widget);
+        g_assert (x);
+        g_assert (y);
+
+        gdk_window_get_origin (GDK_WINDOW (widget->window), x, y);
+
+        *x += widget->allocation.x;
+        *y += widget->allocation.y;
+        *x += widget->allocation.width / 2;
+        *y += widget->allocation.height;
+
+        /* g_debug ("widget position x=%i, y=%i", *x, *y); */
+
+        return TRUE;
+}
+#endif
+
+/*
+ * 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;
+	int                   x;
+	int                   y;
+
+	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);
+		
+		get_widget_position(GTK_WIDGET (applet), &x, &y);
+		notify_notification_set_hint_int32 (n, "x", x);
+		notify_notification_set_hint_int32 (n, "y", y);
+		
+		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
@@ -1188,6 +1303,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)

Attachment: signature.asc
Description: OpenPGP digital signature



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