[patch] special iconf or ad-hoc networks.



I grabbed my own gauntlet.

Attached patch gives Ad-Hoc networks a special icon.

I just used some gtk stock icon of a computer.  We can -- we must -- do
better.

Also, a TODO item: putting both the encrypted and an ad-hoc network icon
would be ugly and take up too much room.  So we should have a comingling
of the two icons that says "encrypted and ad-hoc".  Right now I ignore
that case and show all encrypted networks with the current encrypted
icon, Ad-hoc or not.

	Robert Love

Index: gnome/applet/applet-dbus-devices.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet-dbus-devices.c,v
retrieving revision 1.51.2.3
diff -u -r1.51.2.3 applet-dbus-devices.c
--- gnome/applet/applet-dbus-devices.c	20 Apr 2006 20:39:51 -0000	1.51.2.3
+++ gnome/applet/applet-dbus-devices.c	11 May 2006 21:30:44 -0000
@@ -106,7 +106,7 @@
 
 typedef struct DriverCBData
 {
-	NMApplet *	applet;
+	NMApplet *		applet;
 	NetworkDevice *	dev;
 } DriverCBData;
 
@@ -120,7 +120,7 @@
 static void nma_dbus_device_get_driver_cb (DBusPendingCall *pcall, void *user_data)
 {
 	DBusMessage *		reply;
-	NMApplet *	applet = (NMApplet *) user_data;
+	NMApplet *		applet = (NMApplet *) user_data;
 	DriverCBData *		data = (DriverCBData *) user_data;
 	const char *		driver;
 
@@ -164,7 +164,7 @@
 /*
  * nma_dbus_device_get_driver
  *
- * Get the a device's driver name
+ * Get the device's driver name
  *
  */
 static void nma_dbus_device_get_driver (NetworkDevice *dev, NMApplet *applet)
@@ -581,6 +581,7 @@
 				network_device_remove_wireless_network (dev, tmp_net);
 			}
 
+			wireless_network_set_mode (net, mode);
 			wireless_network_set_capabilities (net, capabilities);
 			wireless_network_set_strength (net, strength);
 			if (act_net && strlen (act_net) && (strcmp (act_net, op) == 0))
Index: gnome/applet/menu-items.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/menu-items.c,v
retrieving revision 1.12
diff -u -r1.12 menu-items.c
--- gnome/applet/menu-items.c	29 Dec 2005 16:54:34 -0000	1.12
+++ gnome/applet/menu-items.c	11 May 2006 21:30:45 -0000
@@ -33,6 +33,7 @@
 #include <stdio.h>
 #include <glib/gi18n.h>
 #include <string.h>
+#include <iwlib.h>
 
 #include "menu-items.h"
 #include "applet-dbus.h"
@@ -234,14 +235,15 @@
 }
 
 
-/* has_encrypted means that the wireless network has an encrypted
+/* is_encrypted means that the wireless network has an encrypted
  * area, and thus we need to allow for spacing.
  */
 void network_menu_item_update (NMNetworkMenuItem *item, WirelessNetwork *network, const gboolean is_encrypted)
 {
 	char *	display_essid;
 	gdouble	percent;
-	int		capabilities;
+	gboolean	encrypted = FALSE;
+	gboolean	adhoc = FALSE;
 
 	g_return_if_fail (item != NULL);
 	g_return_if_fail (network != NULL);
@@ -256,16 +258,21 @@
 	/* Deal with the encrypted icon */
 	g_object_set (item->security_image, "visible", is_encrypted, NULL);
 
-	capabilities = wireless_network_get_capabilities (network);
-	if (    (capabilities & NM_802_11_CAP_PROTO_WEP)
-		|| (capabilities & NM_802_11_CAP_PROTO_WPA)
-		|| (capabilities & NM_802_11_CAP_PROTO_WPA2))
+	if (wireless_network_get_capabilities (network) & (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_PROTO_WPA | NM_802_11_CAP_PROTO_WPA2))
+		encrypted = TRUE;
+
+	if (wireless_network_get_mode (network) == IW_MODE_ADHOC)
+		adhoc = TRUE;
+
+	if (encrypted)
 	{
 		/*
 		 * We want to use "network-wireless-encrypted," which was recently added to the icon spec,
 		 * but not all themes carry it as of yet.  Thus, we fall back to "gnome-lockscreen."
 		 *
 		 * XXX: Would be nice to require gtk-2.6.  For now, we have an ugly and a simple version.
+		 * XXX: This case handles all encrypted networks, Ad-Hoc or not.  Should probably have a third icon for
+		 *      for Ad-Hoc networks that are encrypted.
 		 */
 #if (GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 6)
 		GdkPixbuf *pixbuf;
@@ -283,7 +290,21 @@
 			gtk_image_set_from_icon_name (GTK_IMAGE (item->security_image), "gnome-lockscreen", GTK_ICON_SIZE_MENU);
 #endif
 	}
-	else
+	else if (!encrypted && adhoc)
+	{
+		/* XXX: Again, ugly code for gtk <= 2.6.  Would be nice to require gtk 2.6. */
+#if (GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 6)
+		GdkPixbuf *pixbuf;
+		GtkIconTheme *icon_theme;
+
+		icon_theme = gtk_icon_theme_get_default ();
+		pixbuf = gtk_icon_theme_load_icon (icon_theme, GTK_STOCK_NETWORK, GTK_ICON_SIZE_MENU, 0, NULL);
+		gtk_image_set_from_pixbuf (GTK_IMAGE (item->security_image), pixbuf);
+# else
+		gtk_image_set_from_icon_name (GTK_IMAGE (item->security_image), GTK_STOCK_NETWORK, GTK_ICON_SIZE_MENU);
+#endif
+	}
+	else	/* neither encrypted nor Ad-Hoc */
 		gtk_image_set_from_stock (GTK_IMAGE (item->security_image), NULL, GTK_ICON_SIZE_MENU);
 }
 
@@ -299,34 +320,34 @@
 static char *eel_make_valid_utf8 (const char *name)
 {
 	GString *string;
-	const char *remainder, *invalid;
+	const char *rem, *invalid;
 	int remaining_bytes, valid_bytes;
 
 	string = NULL;
-	remainder = name;
+	rem = name;
 	remaining_bytes = strlen (name);
 
 	while (remaining_bytes != 0) {
-		if (g_utf8_validate (remainder, remaining_bytes, &invalid)) {
+		if (g_utf8_validate (rem, remaining_bytes, &invalid)) {
 			break;
 		}
-		valid_bytes = invalid - remainder;
+		valid_bytes = invalid - rem;
 
 		if (string == NULL) {
 			string = g_string_sized_new (remaining_bytes);
 		}
-		g_string_append_len (string, remainder, valid_bytes);
+		g_string_append_len (string, rem, valid_bytes);
 		g_string_append_c (string, '?');
 
 		remaining_bytes -= valid_bytes + 1;
-		remainder = invalid + 1;
+		rem = invalid + 1;
 	}
 
 	if (string == NULL) {
 		return g_strdup (name);
 	}
 
-	g_string_append (string, remainder);
+	g_string_append (string, rem);
 	g_string_append (string, _(" (invalid Unicode)"));
 	g_assert (g_utf8_validate (string->str, -1, NULL));
 
Index: gnome/applet/wireless-network.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/wireless-network.c,v
retrieving revision 1.3
diff -u -r1.3 wireless-network.c
--- gnome/applet/wireless-network.c	29 Dec 2005 16:54:34 -0000	1.3
+++ gnome/applet/wireless-network.c	11 May 2006 21:30:45 -0000
@@ -22,6 +22,8 @@
 
 
 #include <glib.h>
+#include <iwlib.h>
+
 #include "wireless-network.h"
 
 /*
@@ -35,6 +37,7 @@
 	char *	essid;
 	gboolean	active;
 	gint8	strength;
+	int		mode;
 	int		capabilities;
 };
 
@@ -170,6 +173,24 @@
 	g_return_if_fail (net != NULL);
 
 	net->capabilities = capabilities;
+}
+
+/*
+ * Accessors for mode
+ */
+int wireless_network_get_mode (WirelessNetwork *net)
+{
+	g_return_val_if_fail (net != NULL, FALSE);
+
+	return net->mode;
+}
+
+void wireless_network_set_mode (WirelessNetwork *net, int mode)
+{
+	g_return_if_fail (net != NULL);
+	g_return_if_fail ((mode == IW_MODE_ADHOC) || (mode == IW_MODE_INFRA));
+
+	net->mode = mode;
 }
 
 /*
Index: gnome/applet/wireless-network.h
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/wireless-network.h,v
retrieving revision 1.2
diff -u -r1.2 wireless-network.h
--- gnome/applet/wireless-network.h	29 Dec 2005 16:54:34 -0000	1.2
+++ gnome/applet/wireless-network.h	11 May 2006 21:30:45 -0000
@@ -41,6 +41,9 @@
 int				wireless_network_get_capabilities	(WirelessNetwork *net);
 void				wireless_network_set_capabilities	(WirelessNetwork *net, int capabilities);
 
+int				wireless_network_get_mode		(WirelessNetwork *net);
+void				wireless_network_set_mode		(WirelessNetwork *net, int mode);
+
 gint8			wireless_network_get_strength		(WirelessNetwork *net);
 void				wireless_network_set_strength		(WirelessNetwork *net, gint8 strength);
 


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