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



Author: dcbw
Date: Thu Feb  5 18:00:30 2009
New Revision: 1130
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=1130&view=rev

Log:
2009-02-05  Dan Williams  <dcbw redhat com>

	* src/applet.c
		- (nma_menu_device_check_unusable): add common code for checking
			whether a device is in a usable state and creating the
			menu item for it

	* src/applet-device-gsm.c
	  src/applet-device-wifi.c
	  src/applet-device-cdma.c
	  src/applet-device-wired.c
		- (*_add_menu_item): use nma_menu_device_check_unusable()



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	Thu Feb  5 18:00:30 2009
@@ -258,10 +258,9 @@
 	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 	gtk_widget_show (item);
 
-	/* Notify user of unmanaged device */
-	if (!nm_device_get_managed (device)) {
-		item = gtk_menu_item_new_with_label (_("device is unmanaged"));
-		gtk_widget_set_sensitive (item, FALSE);
+	/* Notify user of unmanaged or unavailable device */
+	item = nma_menu_device_check_unusable (device, NULL);
+	if (item) {
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 		gtk_widget_show (item);
 		goto out;

Modified: trunk/src/applet-device-gsm.c
==============================================================================
--- trunk/src/applet-device-gsm.c	(original)
+++ trunk/src/applet-device-gsm.c	Thu Feb  5 18:00:30 2009
@@ -259,10 +259,9 @@
 	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 	gtk_widget_show (item);
 
-	/* Notify user of unmanaged device */
-	if (!nm_device_get_managed (device)) {
-		item = gtk_menu_item_new_with_label (_("device is unmanaged"));
-		gtk_widget_set_sensitive (item, FALSE);
+	/* Notify user of unmanaged or unavailable device */
+	item = nma_menu_device_check_unusable (device, NULL);
+	if (item) {
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 		gtk_widget_show (item);
 		goto out;

Modified: trunk/src/applet-device-wifi.c
==============================================================================
--- trunk/src/applet-device-wifi.c	(original)
+++ trunk/src/applet-device-wifi.c	Thu Feb  5 18:00:30 2009
@@ -673,6 +673,7 @@
 	GSList *connections = NULL, *all, *sorted_aps = NULL, *iter;
 	GtkWidget *label;
 	char *bold_text;
+	gboolean wireless_enabled = TRUE;
 
 	wdev = NM_DEVICE_WIFI (device);
 	aps = nm_device_wifi_get_access_points (wdev);
@@ -709,19 +710,10 @@
 	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 	gtk_widget_show (item);
 
-	/* Don't display APs when wireless is disabled */
-	if (!nm_client_wireless_get_enabled (applet->nm_client)) {
-		item = gtk_menu_item_new_with_label (_("wireless is disabled"));
-		gtk_widget_set_sensitive (item, FALSE);
-		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-		gtk_widget_show (item);
-		goto out;
-	}
-
-	/* Notify user of unmanaged device */
-	if (!nm_device_get_managed (device)) {
-		item = gtk_menu_item_new_with_label (_("device is unmanaged"));
-		gtk_widget_set_sensitive (item, FALSE);
+	/* Notify user of unmanaged or unavailable device */
+	wireless_enabled = nm_client_wireless_get_enabled (applet->nm_client);
+	item = nma_menu_device_check_unusable (device, wireless_enabled ? NULL : _("wireless is disabled"));
+	if (item) {
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 		gtk_widget_show (item);
 		goto out;

Modified: trunk/src/applet-device-wired.c
==============================================================================
--- trunk/src/applet-device-wired.c	(original)
+++ trunk/src/applet-device-wired.c	Thu Feb  5 18:00:30 2009
@@ -223,10 +223,9 @@
 	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 	gtk_widget_show (item);
 
-	/* Notify user of unmanaged device */
-	if (!nm_device_get_managed (device)) {
-		item = gtk_menu_item_new_with_label (_("device is unmanaged"));
-		gtk_widget_set_sensitive (item, FALSE);
+	/* Notify user of unmanaged or unavailable device */
+	item = nma_menu_device_check_unusable (device, carrier ? NULL : _("disconnected"));
+	if (item) {
 		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 		gtk_widget_show (item);
 		goto out;

Modified: trunk/src/applet.c
==============================================================================
--- trunk/src/applet.c	(original)
+++ trunk/src/applet.c	Thu Feb  5 18:00:30 2009
@@ -994,6 +994,38 @@
 	return connection;
 }
 
+GtkWidget *
+nma_menu_device_check_unusable (NMDevice *device,
+                                const char *unavailable_msg)
+{
+	GtkWidget *item = NULL;
+	gboolean managed = TRUE;
+
+	if (!unavailable_msg)
+		unavailable_msg = _("device not ready");
+
+	switch (nm_device_get_state (device)) {
+	case NM_DEVICE_STATE_UNKNOWN:
+	case NM_DEVICE_STATE_UNAVAILABLE:
+		item = gtk_menu_item_new_with_label (unavailable_msg);
+		break;
+	case NM_DEVICE_STATE_UNMANAGED:
+		managed = FALSE;
+		break;
+	default:
+		managed = nm_device_get_managed (device);
+		break;
+	}
+
+	if (!managed)
+		item = gtk_menu_item_new_with_label (_("device not managed"));
+
+	if (item)
+		gtk_widget_set_sensitive (item, FALSE);
+
+	return item;
+}
+
 static guint32
 nma_menu_add_devices (GtkWidget *menu, NMApplet *applet)
 {

Modified: trunk/src/applet.h
==============================================================================
--- trunk/src/applet.h	(original)
+++ trunk/src/applet.h	Thu Feb  5 18:00:30 2009
@@ -195,6 +195,9 @@
 
 GSList *applet_get_all_connections (NMApplet *applet);
 
+GtkWidget *nma_menu_device_check_unusable (NMDevice *device,
+                                           const char *unavailable_msg);
+
 void applet_menu_item_activate_helper (NMDevice *device,
                                        NMConnection *connection,
                                        const char *specific_object,



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