Re: Patch to add libnotify support to nm-applet



On 02/15/2006 01:44 PM, Christopher Aillon wrote:
On 02/15/2006 01:18 PM, Robert Love wrote:
On Wed, 2006-02-15 at 13:06 -0500, Christopher Aillon wrote:

Has the issue with getting "(null)" as the current network (due to race conditions) been fixed yet? I have a libnotify patch in my tree that I thought I submitted already which fixes that as well, and also adds support for VPN notifies, which are in my opinion most important since support there will get rid of an entire dialog.

Nice!

Let's figure out the best bits of both and commit.

    Robert Love

Yeah, I'll try and post it tonight (I'm guessing its on a home box which is currently offline).

Okay, I just tracked this patch down. Here was a primitive patch that needs a small amount of love probably. It was based off 0.5.1 so it may not apply anymore, as its been a while since I looked at NM code (pre-wpa), but the basic problem was that there is a race in getting the network information from the applet. We get informed that we are connected via a DBUS call, we then ask for the properties of the network via DBUS and set a callback which races with the getProperties call. So, about 10% of the time, the wireless network is displayed as "(null)". My patch did not handle ad-hoc stuff like Rodrigo's did, but it does handle VPN stuff as well, so I think we should combine these two patches.


? clog
? po/clog
? src/device
? vpn-daemons/vpnc/clog
Index: configure.in
===================================================================
RCS file: /cvs/gnome/NetworkManager/configure.in,v
retrieving revision 1.96
diff -d -u -p -r1.96 configure.in
--- configure.in	28 Oct 2005 03:16:01 -0000	1.96
+++ configure.in	29 Nov 2005 19:47:56 -0000
@@ -159,6 +159,14 @@ PKG_CHECK_MODULES(LIBNL, libnl-1)
 AC_SUBST(LIBNL_CFLAGS)
 AC_SUBST(LIBNL_LIBS)
 
+PKG_CHECK_MODULES(LIBNOTIFY, libnotify, have_libnotify=yes, have_libnotify=no)
+AC_SUBST(LIBNOTIFY_CFLAGS)
+AC_SUBST(LIBNOTIFY_LIBS)
+AM_CONDITIONAL(HAVE_LIBNOTIFY, test x$have_libnotify = xyes)
+if test x"$have_libnotify" != xno; then
+  AC_DEFINE(HAVE_LIBNOTIFY, 1, [Define if you have libgcrypt])
+fi
+
 AC_ARG_WITH(gcrypt, AC_HELP_STRING([--with-gcrypt], [Use gcrypt library]), ac_gcrypt=$withval, ac_gcrypt=auto)
 if test x"$ac_gcrypt" != xno; then
   AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
Index: gnome/applet/Makefile.am
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/Makefile.am,v
retrieving revision 1.7
diff -d -u -p -r1.7 Makefile.am
--- gnome/applet/Makefile.am	17 Aug 2005 04:21:03 -0000	1.7
+++ gnome/applet/Makefile.am	29 Nov 2005 19:47:56 -0000
@@ -17,6 +17,7 @@ nm_applet_CPPFLAGS =						\
 	$(LIBGNOMEUI_CFLAGS)					\
 	$(PANEL_APPLET_CFLAGS)					\
 	$(GNOME_KEYRING_CFLAGS)					\
+	$(LIBNOTIFY_CFLAGS)					\
 	-DICONDIR=\""$(datadir)/pixmaps"\"			\
 	-DGLADEDIR=\""$(gladedir)"\"				\
 	-DBINDIR=\""$(bindir)"\"					\
@@ -42,6 +43,8 @@ nm_applet_SOURCES =			\
 	applet-dbus-vpn.h		\
 	applet-dbus-info.c		\
 	applet-dbus-info.h		\
+	applet-notifications.c		\
+	applet-notifications.h		\
 	wireless-network.c		\
 	wireless-network.h		\
 	nm-device.c			\
@@ -71,6 +74,7 @@ nm_applet_LDADD =						\
 	$(GCONF_LIBS)						\
 	$(LIBGNOMEUI_LIBS)					\
 	$(GNOME_KEYRING_LIBS)				\
+	$(LIBNOTIFY_LIBS)	\
 	$(top_builddir)/utils/libnmutils.la	\
 	$(NULL)
 
Index: gnome/applet/applet-dbus-devices.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet-dbus-devices.c,v
retrieving revision 1.32
diff -d -u -p -r1.32 applet-dbus-devices.c
--- gnome/applet/applet-dbus-devices.c	2 Nov 2005 18:27:19 -0000	1.32
+++ gnome/applet/applet-dbus-devices.c	29 Nov 2005 19:47:56 -0000
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib-lowlevel.h>
+#include "applet-notifications.h"
 #include "applet-dbus-devices.h"
 #include "applet-dbus.h"
 #include "applet.h"
@@ -784,6 +785,82 @@ void nmwa_dbus_device_update_one_device 
 		dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
 		if (pcall)
 			dbus_pending_call_set_notify (pcall, nmwa_dbus_device_properties_cb, applet, NULL);
+		dbus_message_unref (message);
+	}
+}
+
+typedef struct _DeviceActivatedCBData
+{
+	NMWirelessApplet *applet;
+	char	*essid;
+} DeviceActivatedCBData;
+
+static void free_device_activated_cb_data (DeviceActivatedCBData *obj)
+{
+	if (!obj)
+		return;
+
+	obj->applet = NULL;
+	if (obj->essid)
+		g_free (obj->essid);
+
+	memset (obj, 0, sizeof (DeviceActivatedCBData));
+	g_free (obj);
+}
+
+static void nmwa_dbus_device_activated_cb (DBusPendingCall *pcall, void *user_data)
+{
+	DeviceActivatedCBData *cb_data = (DeviceActivatedCBData*) user_data;
+	NMWirelessApplet *applet = cb_data->applet;
+	char *essid = cb_data->essid;
+
+	NetworkDevice *active_device;
+	WirelessNetwork *active_network;
+	char *summary;
+	char *message = NULL;
+	GdkPixbuf *icon;
+
+	nmwa_dbus_device_properties_cb (pcall, applet);
+
+	active_device = nmwa_get_first_active_device (applet->device_list);
+	if (active_device && network_device_is_wireless (active_device))
+		message = g_strdup_printf ("You are now connected to the wireless network '%s'.", essid);
+	else
+		message = g_strdup ("You are now connected to the wired network.");
+
+	icon = NULL;
+
+	nm_info ("%s", message);
+
+	if (message)
+	{
+		nmwa_send_event_notification (applet, "Connection Established", message, icon);
+		g_free (message);
+	}
+
+	free_device_activated_cb_data (cb_data);
+}
+
+
+void nmwa_dbus_device_activated (NMWirelessApplet *applet, const char *dev_path, const char *essid)
+{
+	DBusMessage *		message;
+	DBusPendingCall *	pcall = NULL;
+	DeviceActivatedCBData	*cb_data = NULL;
+
+	g_return_if_fail (applet != NULL);
+	g_return_if_fail (dev_path != NULL);
+
+	cb_data = g_malloc0 (sizeof (DeviceActivatedCBData));
+	cb_data->applet = applet;
+	if (essid)
+		cb_data->essid = g_strdup (essid);
+
+	if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev_path, NM_DBUS_INTERFACE_DEVICES, "getProperties")))
+	{
+		dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
+		if (pcall)
+			dbus_pending_call_set_notify (pcall, nmwa_dbus_device_activated_cb, cb_data, NULL);
 		dbus_message_unref (message);
 	}
 }
Index: gnome/applet/applet-dbus-devices.h
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet-dbus-devices.h,v
retrieving revision 1.6
diff -d -u -p -r1.6 applet-dbus-devices.h
--- gnome/applet/applet-dbus-devices.h	6 Sep 2005 19:04:09 -0000	1.6
+++ gnome/applet/applet-dbus-devices.h	29 Nov 2005 19:47:56 -0000
@@ -40,6 +40,7 @@ void			nmwa_dbus_update_devices					(NMW
 void			nmwa_dbus_update_dialup					(NMWirelessApplet *applet);
 void			nmwa_dbus_dialup_activate_connection		(NMWirelessApplet *applet, const char *name);
 void			nmwa_dbus_device_update_one_device			(NMWirelessApplet *applet, const char *dev_path);
+void			nmwa_dbus_device_activated			(NMWirelessApplet *applet, const char *dev_path, const char *essid);
 void			nmwa_dbus_device_remove_one_device			(NMWirelessApplet *applet, const char *dev_path);
 
 void			nmwa_dbus_device_update_one_network		(NMWirelessApplet *applet, const char *dev_path, const char *net_path, const char *active_net_path);
Index: gnome/applet/applet-dbus.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet-dbus.c,v
retrieving revision 1.18
diff -d -u -p -r1.18 applet-dbus.c
--- gnome/applet/applet-dbus.c	24 Oct 2005 23:03:42 -0000	1.18
+++ gnome/applet/applet-dbus.c	29 Nov 2005 19:47:56 -0000
@@ -197,7 +197,6 @@ static DBusHandlerResult nmwa_dbus_filte
 		}
 	}
 	else if (    dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceAdded")
-			|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNowActive")
 			|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNoLongerActive")
 			|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivating")
 			|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceCarrierOn")
@@ -208,6 +207,16 @@ static DBusHandlerResult nmwa_dbus_filte
 		if (dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID))
 			nmwa_dbus_device_update_one_device (applet, path);
 	}
+	else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNowActive"))
+	{
+		char *path = NULL;
+		char *essid = NULL;
+
+		if (dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_STRING, &essid, DBUS_TYPE_INVALID))
+			nmwa_dbus_device_activated (applet, path, essid);
+		else if (dbus_message_get_args (message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID))
+			nmwa_dbus_device_activated (applet, path, NULL);
+	}
 	else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceRemoved"))
 	{
 		char *path = NULL;
@@ -284,7 +293,7 @@ static DBusHandlerResult nmwa_dbus_filte
 		char *error_msg;
 
 		if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &vpn_name, DBUS_TYPE_STRING, &error_msg, DBUS_TYPE_INVALID)) {
-			nmwa_schedule_vpn_failure_dialog (applet, member, vpn_name, error_msg);
+			nmwa_schedule_vpn_failure_notification (applet, member, vpn_name, error_msg);
 			/* clear the 'last_attempt_success' key in gconf so we prompt for password next time */
 			set_vpn_last_attempt_status (applet, vpn_name, FALSE);
 		}
@@ -298,7 +307,7 @@ static DBusHandlerResult nmwa_dbus_filte
 		{
 			char *stripped = g_strstrip (g_strdup (banner));
 
-			nmwa_schedule_vpn_login_banner_dialog (applet, vpn_name, stripped);
+			nmwa_schedule_vpn_login_notification (applet, vpn_name, stripped);
 			g_free (stripped);
 
 			/* set the 'last_attempt_success' key in gconf so we DON'T prompt for password next time */
Index: gnome/applet/applet-notifications.c
===================================================================
RCS file: gnome/applet/applet-notifications.c
diff -N gnome/applet/applet-notifications.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnome/applet/applet-notifications.c	29 Nov 2005 19:47:56 -0000
@@ -0,0 +1,55 @@
+/* NetworkManager -- Network link manager
+ *
+ * Christopher Aillon <caillon redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * (C) Copyright 2005 Red Hat, Inc.
+ */
+#define HAVE_LIBNOTIFY
+#ifdef HAVE_LIBNOTIFY
+  #include <libnotify/notify.h>
+#endif
+
+#include "applet-notifications.h"
+
+void
+nmwa_send_event_notification (NMWirelessApplet *applet, 
+                              const char *summary,
+                              const char *message,
+                              GdkPixbuf *icon)
+{
+#ifdef HAVE_LIBNOTIFY
+	NotifyNotification *notification;
+	const gchar* icon_name = NULL;
+
+	g_return_if_fail (applet != NULL);
+
+	if (!notify_is_initted ())
+		notify_init ("NetworkManager");
+
+	if (icon == NULL)
+		icon_name = GTK_STOCK_NETWORK;
+
+	notification = notify_notification_new (summary, message, icon_name,
+	                                        GTK_WIDGET (applet));
+
+	if (icon != NULL)
+		notify_notification_set_icon_data_from_pixbuf (notification, icon);
+
+	notify_notification_show (notification, NULL);
+#endif /* HAVE_LIBNOTIFY */
+}
+
Index: gnome/applet/applet-notifications.h
===================================================================
RCS file: gnome/applet/applet-notifications.h
diff -N gnome/applet/applet-notifications.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnome/applet/applet-notifications.h	29 Nov 2005 19:47:56 -0000
@@ -0,0 +1,33 @@
+/* NetworkManager -- Network link manager
+ *
+ * Christopher Aillon <caillon redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * (C) Copyright 2005 Red Hat, Inc.
+ */
+
+#ifndef NM_NOTIFICATION_H__
+#define NM_NOTIFICATION_H__
+
+#include "applet.h"
+
+void
+nmwa_send_event_notification (NMWirelessApplet *applet, 
+                              const char *summary,
+                              const char *message,
+                              GdkPixbuf *icon);
+
+#endif /* NM_NOTIFICATION_H__ */
Index: gnome/applet/applet.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet.c,v
retrieving revision 1.79
diff -d -u -p -r1.79 applet.c
--- gnome/applet/applet.c	2 Nov 2005 20:03:28 -0000	1.79
+++ gnome/applet/applet.c	29 Nov 2005 19:47:56 -0000
@@ -48,6 +48,7 @@
 #include "applet-dbus-devices.h"
 #include "applet-dbus-vpn.h"
 #include "applet-dbus-info.h"
+#include "applet-notifications.h"
 #include "other-network-dialog.h"
 #include "passphrase-dialog.h"
 #include "menu-items.h"
@@ -425,21 +426,19 @@ static gboolean nmwa_show_vpn_failure_di
  * Schedule display of the VPN Failure dialog.
  *
  */
-void nmwa_schedule_vpn_failure_dialog (NMWirelessApplet *applet, const char *member, const char *vpn_name, const char *error_msg)
+void nmwa_schedule_vpn_failure_notification (NMWirelessApplet *applet, const char *member, const char *vpn_name, const char *error_msg)
 {
 	DialogCBData *cb_data = NULL;
 	gchar *error_head = NULL;
 	gchar *error_desc = NULL;
 	gchar *error_data = NULL;
+	gchar *message;
 
 	g_return_if_fail (applet != NULL);
 	g_return_if_fail (member != NULL);
 	g_return_if_fail (vpn_name != NULL);
 	g_return_if_fail (error_msg != NULL);
 
-	cb_data = g_malloc0 (sizeof (DialogCBData));
-	cb_data->title = g_strdup (_("VPN Error"));
-
 	if (!strcmp (member, NM_DBUS_VPN_SIGNAL_LOGIN_FAILED))
 	{
 		error_head = g_strdup (_("VPN Login Failure"));
@@ -467,20 +466,15 @@ void nmwa_schedule_vpn_failure_dialog (N
 	}
 	else
 	{
-		free_dialog_cb_data (cb_data);
 		return;
 	}
 
 	error_data = g_strdup_printf (_("The VPN service said: \"%s\""), error_msg);
 
-	cb_data->msg = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n"
-	                                "%s\n\n%s", error_head, error_desc, error_data);
-
-	g_free (error_head);
-	g_free (error_desc);
-	g_free (error_data);
+	message = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n"
+	                           "%s\n\n%s", error_head, error_desc, error_data);
 
-	g_idle_add ((GSourceFunc) nmwa_show_vpn_failure_dialog, cb_data);
+	nmwa_send_event_notification (applet, error_head, message, NULL);
 }
 
 
@@ -531,21 +525,19 @@ static gboolean nmwa_show_vpn_login_bann
  * Schedule display of the VPN Login Banner dialog.
  *
  */
-void nmwa_schedule_vpn_login_banner_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *banner)
+void nmwa_schedule_vpn_login_notification (NMWirelessApplet *applet, const char *vpn_name, const char *banner)
 {
-	char *msg;
+	char *head;
 	char *msg2;
 
 	g_return_if_fail (applet != NULL);
 	g_return_if_fail (vpn_name != NULL);
 	g_return_if_fail (banner != NULL);
 
-	msg2 = g_strdup_printf (_("VPN connection '%s' said:"), vpn_name);
-	msg = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s\n\n\"%s\"",
-	                       _("VPN Login Message"), msg2, banner);
-	g_free (msg2);
+	head = g_strdup_printf (_("VPN '%s' Now Active"), vpn_name);
 
-	g_idle_add ((GSourceFunc) nmwa_show_vpn_login_banner_dialog, msg);
+	nmwa_send_event_notification (applet, head, banner, NULL);
+	g_free (head);
 }
 
 
Index: gnome/applet/applet.h
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet.h,v
retrieving revision 1.23
diff -d -u -p -r1.23 applet.h
--- gnome/applet/applet.h	2 Nov 2005 18:27:19 -0000	1.23
+++ gnome/applet/applet.h	29 Nov 2005 19:47:56 -0000
@@ -139,8 +139,8 @@ NetworkDevice *	nmwa_get_device_for_nm_p
 NMWirelessApplet *	nmwa_new							(void);
 void				nmwa_schedule_warning_dialog			(NMWirelessApplet *applet, const char *msg);
 gboolean			nmwa_driver_notify					(gpointer user_data);
-void				nmwa_schedule_vpn_failure_dialog		(NMWirelessApplet *applet, const char *member, const char *vpn_name, const char *error_msg);
-void				nmwa_schedule_vpn_login_banner_dialog	(NMWirelessApplet *applet, const char *vpn_name, const char *banner);
+void				nmwa_schedule_vpn_failure_notification		(NMWirelessApplet *applet, const char *member, const char *vpn_name, const char *error_msg);
+void				nmwa_schedule_vpn_login_notification	(NMWirelessApplet *applet, const char *vpn_name, const char *banner);
 
 NetworkDevice *	nmwa_get_first_active_device			(GSList *dev_list);
 VPNConnection *	nmwa_get_first_active_vpn_connection	(NMWirelessApplet *applet);
Index: src/NetworkManagerPolicy.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerPolicy.c,v
retrieving revision 1.65
diff -d -u -p -r1.65 NetworkManagerPolicy.c
--- src/NetworkManagerPolicy.c	2 Nov 2005 06:29:06 -0000	1.65
+++ src/NetworkManagerPolicy.c	29 Nov 2005 19:47:56 -0000
@@ -48,6 +48,7 @@ static gboolean nm_policy_activation_fin
 {
 	NMDevice			*dev = NULL;
 	NMData			*data = NULL;
+	NMAccessPoint *	ap = NULL;
 
 	g_return_val_if_fail (req != NULL, FALSE);
 
@@ -61,9 +62,10 @@ static gboolean nm_policy_activation_fin
 	if (nm_device_is_wireless (dev))
 	{
 		struct ether_addr	addr;
-		NMAccessPoint *	ap = nm_act_request_get_ap (req);
 		NMAccessPoint *	tmp_ap;
 
+		ap = nm_act_request_get_ap (req);
+
 		/* Cache details in the info-daemon since the connect was successful */
 		nm_dbus_update_network_info (data->dbus_connection, ap, nm_act_request_get_user_requested (req));
 
@@ -81,7 +83,7 @@ static gboolean nm_policy_activation_fin
 	}
 
 	nm_info ("Activation (%s) successful, device activated.", nm_device_get_iface (dev));
-	nm_dbus_schedule_device_status_change_signal (data, dev, NULL, DEVICE_NOW_ACTIVE);
+	nm_dbus_schedule_device_status_change_signal (data, dev, ap, DEVICE_NOW_ACTIVE);
 	nm_schedule_state_change_signal_broadcast (data);
 
 	return FALSE;


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