network-manager-applet r1013 - in trunk: . src



Author: dcbw
Date: Fri Nov  7 14:47:13 2008
New Revision: 1013
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=1013&view=rev

Log:
2008-11-07  Dan Williams  <dcbw redhat com>

	Fix bgo #505211 and harmonize tooltips

	* src/applet.c
	  src/applet.h
		- (nma_menu_deactivate_cb): refresh the tooltip when the menu closes,
			since it was cleared when the menu was shown
		- (applet_common_get_device_icon): NEED_AUTH state shouldn't just show
			a disconnected icon; should do better here though in the future
		- (get_tip_for_device_state): fallback tooltips if the device class
			didn't set any
		- (get_tip_for_vpn): VPN tips
		- (applet_update_icon): show both default device and VPN tips

	* src/applet-device-cdma.c
	  src/applet-device-gsm.c
	  src/applet-device-wifi.c
	  src/applet-device-wired.c
		- Make tooltips consistent, and emphasize the actual connection which
			is being activated or is active



Modified:
   trunk/ChangeLog
   trunk/src/applet-device-cdma.c
   trunk/src/applet-device-gsm.c
   trunk/src/applet-device-wifi.c
   trunk/src/applet-device-wired.c
   trunk/src/applet.c
   trunk/src/applet.h

Modified: trunk/src/applet-device-cdma.c
==============================================================================
--- trunk/src/applet-device-cdma.c	(original)
+++ trunk/src/applet-device-cdma.c	Fri Nov  7 14:47:13 2008
@@ -315,35 +315,32 @@
                char **tip,
                NMApplet *applet)
 {
+	NMSettingConnection *s_con;
 	GdkPixbuf *pixbuf = NULL;
-	const char *iface;
-	NMSettingConnection *s_con = NULL;
+	const char *id;
 
-	iface = nm_device_get_iface (NM_DEVICE (device));
-	if (connection)
-		s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+	id = nm_device_get_iface (NM_DEVICE (device));
+	if (connection) {
+		s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+		id = nm_setting_connection_get_id (s_con);
+	}
 
 	switch (state) {
 	case NM_DEVICE_STATE_PREPARE:
-		*tip = g_strdup_printf (_("Dialing mobile broadband device %s..."), iface);
+		*tip = g_strdup_printf (_("Preparing mobile broadband connection '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_CONFIG:
-		*tip = g_strdup_printf (_("Starting PPP on device %s..."), iface);
+		*tip = g_strdup_printf (_("Configuring mobile broadband connection '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_NEED_AUTH:
-		*tip = g_strdup_printf (_("Waiting for user authentication on device '%s'..."), iface);
+		*tip = g_strdup_printf (_("User authentication required for mobile broadband connection '%s'..."), id);
+		break;
+	case NM_DEVICE_STATE_IP_CONFIG:
+		*tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_ACTIVATED:
-		if (s_con) {
-			const char *id = nm_setting_connection_get_id (s_con);
-			if (id)
-				*tip = g_strdup_printf (_("Mobile broadband connection '%s'"), id);
-		}
-
-		if (!*tip)
-			*tip = g_strdup (_("Mobile broadband connection"));
-
 		pixbuf = applet->wwan_icon;
+		*tip = g_strdup_printf (_("Mobile broadband connection '%s' active"), id);
 		break;
 	default:
 		break;

Modified: trunk/src/applet-device-gsm.c
==============================================================================
--- trunk/src/applet-device-gsm.c	(original)
+++ trunk/src/applet-device-gsm.c	Fri Nov  7 14:47:13 2008
@@ -316,34 +316,32 @@
               char **tip,
               NMApplet *applet)
 {
+	NMSettingConnection *s_con;
 	GdkPixbuf *pixbuf = NULL;
-	const char *iface;
-	NMSettingConnection *s_con = NULL;
+	const char *id;
 
-	iface = nm_device_get_iface (NM_DEVICE (device));
-	if (connection)
-		s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+	id = nm_device_get_iface (NM_DEVICE (device));
+	if (connection) {
+		s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+		id = nm_setting_connection_get_id (s_con);
+	}
 
 	switch (state) {
 	case NM_DEVICE_STATE_PREPARE:
-		*tip = g_strdup_printf (_("Dialing mobile broadband device %s..."), iface);
+		*tip = g_strdup_printf (_("Preparing mobile broadband connection '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_CONFIG:
-		*tip = g_strdup_printf (_("Starting PPP on device %s..."), iface);
+		*tip = g_strdup_printf (_("Configuring mobile broadband connection '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_NEED_AUTH:
-		*tip = g_strdup_printf (_("Waiting for user authentication on device '%s'..."), iface);
+		*tip = g_strdup_printf (_("User authentication required for mobile broadband connection '%s'..."), id);
+		break;
+	case NM_DEVICE_STATE_IP_CONFIG:
+		*tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_ACTIVATED:
-		if (s_con) {
-			const char *id;
-
-			id = nm_setting_connection_get_id (s_con);
-			if (id)
-				*tip = g_strdup_printf (_("Mobile broadband connection '%s'"), id);
-		} else
-			*tip = g_strdup (_("Mobile broadband connection"));
 		pixbuf = applet->wwan_icon;
+		*tip = g_strdup_printf (_("Mobile broadband connection '%s' active"), id);
 		break;
 	default:
 		break;

Modified: trunk/src/applet-device-wifi.c
==============================================================================
--- trunk/src/applet-device-wifi.c	(original)
+++ trunk/src/applet-device-wifi.c	Fri Nov  7 14:47:13 2008
@@ -1195,37 +1195,42 @@
                    char **tip,
                    NMApplet *applet)
 {
+	NMSettingConnection *s_con;
 	NMAccessPoint *ap;
 	GdkPixbuf *pixbuf = NULL;
-	const char *iface;
-	char *esc_ssid = NULL;
+	const char *id;
+	char *ssid = NULL;
 
 	ap = g_object_get_data (G_OBJECT (device), ACTIVE_AP_TAG);
 	if (ap) {
-		const GByteArray *ssid;
+		const GByteArray *tmp;
 
-		ssid = nm_access_point_get_ssid (ap);
-		if (ssid)
-			esc_ssid = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len);
+		tmp = nm_access_point_get_ssid (ap);
+		if (tmp)
+			ssid = nm_utils_ssid_to_utf8 ((const char *) tmp->data, tmp->len);
 	}
 
-	if (!esc_ssid)
-		esc_ssid = g_strdup (_("(none)"));
+	if (!ssid)
+		ssid = g_strdup (_("(none)"));
 
-	iface = nm_device_get_iface (device);
+	id = nm_device_get_iface (device);
+	if (connection) {
+		s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+		id = nm_setting_connection_get_id (s_con);
+	}
 
 	switch (state) {
 	case NM_DEVICE_STATE_PREPARE:
-		*tip = g_strdup_printf (_("Preparing device %s for the wireless network '%s'..."), iface, esc_ssid);
+		*tip = g_strdup_printf (_("Preparing wireless network connection '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_CONFIG:
-		*tip = g_strdup_printf (_("Attempting to join the wireless network '%s'..."), esc_ssid);
-		break;
-	case NM_DEVICE_STATE_IP_CONFIG:
-		*tip = g_strdup_printf (_("Requesting a network address from the wireless network '%s'..."), esc_ssid);
+		*tip = g_strdup_printf (_("Configuring wireless network connection '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_NEED_AUTH:
-		*tip = g_strdup_printf (_("Waiting for Network Key for the wireless network '%s'..."), esc_ssid);
+		*tip = g_strdup_printf (_("User authentication required for wireless network '%s'..."), id);
+		break;
+	case NM_DEVICE_STATE_IP_CONFIG:
+		*tip = g_strdup_printf (_("Requesting a wireless network address for '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_ACTIVATED:
 		if (ap) {
@@ -1245,18 +1250,18 @@
 			else
 				pixbuf = applet->wireless_00_icon;
 
-			*tip = g_strdup_printf (_("Wireless network connection to '%s' (%d%%)"),
-			                        esc_ssid, strength);
+			*tip = g_strdup_printf (_("Wireless network connection '%s' active: %s (%d%%)"),
+			                        id, ssid, strength);
 		} else {
 			pixbuf = applet->wireless_00_icon;
-			*tip = g_strdup_printf (_("Wireless network connection to '%s'"), esc_ssid);
+			*tip = g_strdup_printf (_("Wireless network connection '%s' active"), id);
 		}
 		break;
 	default:
 		break;
 	}
 
-	g_free (esc_ssid);
+	g_free (ssid);
 	return pixbuf;
 }
 

Modified: trunk/src/applet-device-wired.c
==============================================================================
--- trunk/src/applet-device-wired.c	(original)
+++ trunk/src/applet-device-wired.c	Fri Nov  7 14:47:13 2008
@@ -279,24 +279,32 @@
                 char **tip,
                 NMApplet *applet)
 {
+	NMSettingConnection *s_con;
 	GdkPixbuf *pixbuf = NULL;
-	const char *iface;
+	const char *id;
 
-	iface = nm_device_get_iface (NM_DEVICE (device));
+	id = nm_device_get_iface (NM_DEVICE (device));
+	if (connection) {
+		s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+		id = nm_setting_connection_get_id (s_con);
+	}
 
 	switch (state) {
 	case NM_DEVICE_STATE_PREPARE:
-		*tip = g_strdup_printf (_("Preparing device %s for the wired network..."), iface);
+		*tip = g_strdup_printf (_("Preparing wired network connection '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_CONFIG:
-		*tip = g_strdup_printf (_("Configuring device %s for the wired network..."), iface);
+		*tip = g_strdup_printf (_("Configuring wired network connection '%s'..."), id);
+		break;
+	case NM_DEVICE_STATE_NEED_AUTH:
+		*tip = g_strdup_printf (_("User authentication required for wired network connection '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_IP_CONFIG:
-		*tip = g_strdup_printf (_("Requesting a network address from the wired network..."));
+		*tip = g_strdup_printf (_("Requesting a wired network address for '%s'..."), id);
 		break;
 	case NM_DEVICE_STATE_ACTIVATED:
 		pixbuf = applet->wired_icon;
-		*tip = g_strdup (_("Wired network connection"));
+		*tip = g_strdup_printf (_("Wired network connection '%s' active"), id);
 		break;
 	default:
 		break;

Modified: trunk/src/applet.c
==============================================================================
--- trunk/src/applet.c	(original)
+++ trunk/src/applet.c	Fri Nov  7 14:47:13 2008
@@ -1170,6 +1170,9 @@
 	 * fires for an item.
 	 */
 	g_idle_add_full (G_PRIORITY_LOW, (GSourceFunc) nma_menu_clear, applet, NULL);
+
+	/* Re-set the tooltip */
+	gtk_status_icon_set_tooltip (applet->status_icon, applet->tip);
 }
 
 /*
@@ -1653,6 +1656,7 @@
 		stage = 0;
 		break;
 	case NM_DEVICE_STATE_CONFIG:
+	case NM_DEVICE_STATE_NEED_AUTH:
 		stage = 1;
 		break;
 	case NM_DEVICE_STATE_IP_CONFIG:
@@ -1672,6 +1676,42 @@
 	return pixbuf;
 }
 
+static char *
+get_tip_for_device_state (NMDevice *device,
+                          NMDeviceState state,
+                          NMConnection *connection)
+{
+	NMSettingConnection *s_con;
+	char *tip = NULL;
+	const char *id = NULL;
+
+	id = nm_device_get_iface (device);
+	if (connection) {
+		s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+		id = nm_setting_connection_get_id (s_con);
+	}
+
+	switch (state) {
+	case NM_DEVICE_STATE_PREPARE:
+	case NM_DEVICE_STATE_CONFIG:
+		tip = g_strdup_printf (_("Preparing network connection '%s'..."), id);
+		break;
+	case NM_DEVICE_STATE_NEED_AUTH:
+		tip = g_strdup_printf (_("User authentication required for network connection '%s'..."), id);
+		break;
+	case NM_DEVICE_STATE_IP_CONFIG:
+		tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
+		break;
+	case NM_DEVICE_STATE_ACTIVATED:
+		tip = g_strdup_printf (_("Network connection '%s' active"), id);
+		break;
+	default:
+		break;
+	}
+
+	return tip;
+}
+
 static GdkPixbuf *
 applet_get_device_icon_for_state (NMApplet *applet, char **tip)
 {
@@ -1702,6 +1742,8 @@
 
 		connection = applet_find_active_connection_for_device (device, applet, NULL);
 		pixbuf = dclass->get_icon (device, state, connection, tip, applet);
+		if (!*tip)
+			*tip = get_tip_for_device_state (device, state, connection);
 	}
 
 out:
@@ -1710,15 +1752,67 @@
 	return pixbuf;
 }
 
+static char *
+get_tip_for_vpn (NMActiveConnection *active, NMVPNConnectionState state, NMApplet *applet)
+{
+	NMConnectionScope scope;
+	char *tip = NULL;
+	const char *path, *id = NULL;
+	GSList *iter, *list;
+
+	scope = nm_active_connection_get_scope (active);
+	path = nm_active_connection_get_connection (active);
+	g_return_val_if_fail (path != NULL, NULL);
+
+	list = applet_get_all_connections (applet);
+	for (iter = list; iter; iter = g_slist_next (iter)) {
+		NMConnection *candidate = NM_CONNECTION (iter->data);
+		NMSettingConnection *s_con;
+
+		if (   (nm_connection_get_scope (candidate) == scope)
+		    && !strcmp (nm_connection_get_path (candidate), path)) {
+			s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION));
+			id = nm_setting_connection_get_id (s_con);
+			break;
+		}
+	}
+	g_slist_free (list);
+
+	if (!id)
+		return NULL;
+
+	switch (state) {
+	case NM_VPN_CONNECTION_STATE_CONNECT:
+	case NM_VPN_CONNECTION_STATE_PREPARE:
+		tip = g_strdup_printf (_("Starting VPN connection '%s'..."), id);
+		break;
+	case NM_VPN_CONNECTION_STATE_NEED_AUTH:
+		tip = g_strdup_printf (_("User authentication required for VPN connection '%s'..."), id);
+		break;
+	case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET:
+		tip = g_strdup_printf (_("Requesting a VPN address for '%s'..."), id);
+		break;
+	case NM_VPN_CONNECTION_STATE_ACTIVATED:
+		tip = g_strdup_printf (_("VPN connection '%s' active"), id);
+		break;
+	default:
+		break;
+	}
+
+	return tip;
+}
+
 static gboolean
 applet_update_icon (gpointer user_data)
 {
 	NMApplet *applet = NM_APPLET (user_data);
 	GdkPixbuf *pixbuf = NULL;
 	NMState state;
-	char *tip = NULL;
+	char *dev_tip = NULL, *vpn_tip = NULL;
+	GString *tip;
 	NMVPNConnectionState vpn_state = NM_VPN_SERVICE_STATE_UNKNOWN;
 	gboolean nm_running;
+	NMActiveConnection *active_vpn = NULL;
 
 	applet->update_icon_id = 0;
 
@@ -1735,26 +1829,23 @@
 	case NM_STATE_UNKNOWN:
 	case NM_STATE_ASLEEP:
 		pixbuf = applet->no_connection_icon;
-		tip = g_strdup (_("Networking disabled"));
+		dev_tip = g_strdup (_("Networking disabled"));
 		break;
 	case NM_STATE_DISCONNECTED:
 		pixbuf = applet->no_connection_icon;
-		tip = g_strdup (_("No network connection"));
+		dev_tip = g_strdup (_("No network connection"));
 		break;
 	default:
-		pixbuf = applet_get_device_icon_for_state (applet, &tip);
+		pixbuf = applet_get_device_icon_for_state (applet, &dev_tip);
 		break;
 	}
 
 	foo_set_icon (applet, pixbuf, ICON_LAYER_LINK);
-	if (tip) {
-		gtk_status_icon_set_tooltip (applet->status_icon, tip);
-		g_free (tip);
-	}
 
 	/* VPN state next */
 	pixbuf = NULL;
-	if (applet_get_first_active_vpn_connection (applet, &vpn_state)) {
+	active_vpn = applet_get_first_active_vpn_connection (applet, &vpn_state);
+	if (active_vpn) {
 		switch (vpn_state) {
 		case NM_VPN_CONNECTION_STATE_ACTIVATED:
 			pixbuf = applet->vpn_lock_icon;
@@ -1771,9 +1862,30 @@
 		default:
 			break;
 		}
+
+		vpn_tip = get_tip_for_vpn (active_vpn, vpn_state, applet);
 	}
 	foo_set_icon (applet, pixbuf, ICON_LAYER_VPN);
 
+	if (applet->tip) {
+		g_free (applet->tip);
+		applet->tip = NULL;
+	}
+
+	if (dev_tip || vpn_tip) {
+		tip = g_string_new (dev_tip);
+
+		if (vpn_tip)
+			g_string_append_printf (tip, "%s%s", tip->len ? "\n" : "", vpn_tip);
+
+		if (tip->len)
+			applet->tip = tip->str;
+
+		g_string_free (tip, FALSE);
+	}
+
+	gtk_status_icon_set_tooltip (applet->status_icon, applet->tip);
+
 	return FALSE;
 }
 
@@ -2296,6 +2408,8 @@
 	nma_menu_clear (applet);
 	nma_icons_free (applet);
 
+	g_free (applet->tip);
+
 	if (applet->notification) {
 		notify_notification_close (applet->notification, NULL);
 		g_object_unref (applet->notification);

Modified: trunk/src/applet.h
==============================================================================
--- trunk/src/applet.h	(original)
+++ trunk/src/applet.h	Fri Nov  7 14:47:13 2008
@@ -129,6 +129,7 @@
 
 	GtkWidget *		menu;
 	GtkSizeGroup *	encryption_size_group;
+	char *          tip;
 
 	GtkWidget *		context_menu;
 	GtkWidget *		networking_enabled_item;



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