Re: nm-applet



On Sun, 2008-04-20 at 16:42 -0700, Michael wrote: 
> I am a bit of a noob on this linux programming stuff in general and
> very new to NM.  I could use a little direction.  I am running NM on
> Ubuntu Gusty (7.01) and I have not been able to build two of the
> projects after getting it from CVS.  Following the directions on the
> project page (http://www.gnome.org/projects/NetworkManager/developers/),
> 
>  I am using gcc version 4.1.3 (Ubu 4.1.2-16ubuntu2)
> 
> ========>>
> 
> after all the checks, NetworkManager build fails with:
> "configure: error: wireless-tools >= 28pre9 not installed or not functional"

You'll need to install a good enough version of the wireless-tools-dev
package from Ubuntu repositories.  If it's not in your repositories,
you'll have to grab it and build it yourself.

> after all the checks, nm-applet build fails with this line:
> root Ridgeview:/home/michael/network-manager-applet# ./autogen.sh
> --prefix=/usr --sysconfdir=/etc --localstatedir=/var
> libtoolize: `config.guess' exists: use `--force' to overwrite
> libtoolize: `config.sub' exists: use `--force' to overwrite
> libtoolize: `ltmain.sh' exists: use `--force' to overwrite
> You should update your 'aclocal.m4' by running aclocal.
> checking for a BSD-compatible install... /usr/bin/install -c
> checking whether build environment is sane... yes
> checking for gawk... gawk
> 
>     ...
> 
> checking for NMA... configure: error: Package requirements (dbus-glib-1 >= 0.72
>                  glib-2.0 >= 2.10
>                  NetworkManager >= 0.7.0
>                  libnm_glib
>                  libnm-util
>                  gtk+-2.0 >= 2.10
>                  libglade-2.0
>                  gmodule-export-2.0
>                  gconf-2.0
>                  gnome-keyring-1
>                  libnotify >= 0.4.3) were not met:
> 
> No package 'dbus-glib-1' found
> No package 'NetworkManager' found
> No package 'libnm_glib' found
> No package 'libnm-util' found
> No package 'gtk+-2.0' found
> No package 'libglade-2.0' found
> No package 'gconf-2.0' found
> No package 'gnome-keyring-1' found
> No package 'libnotify' found
> 
> Consider adjusting the PKG_CONFIG_PATH environment variable if you
> installed software in a non-standard prefix.
> 
> ========>>
> 
> Secondly, I was wondering if someone could give a quick answer as to
> what it would take to add in a channel number to the wifi listings?  I
> have peeked at the nm-applet code, but I was not sure how the XML gets
> created or if the channel number is even available in it.

So first, I probably wouldn't take this patch, because I don't think
it's useful for most people, and because the applet coalesces APs that
are on different channels and have the same security, band, and mode.
So if you have a WEP AP 'foobar' on channel 1, and a WEP AP 'foobar' on
channel 6, the applet will _by design_ only show one AP in the menu, not
two.  You could put both channels in the menu entry, but this breaks
down pretty quickly after 3 or 4 APs of the same SSID (which is quite
common in some situations).

But I whipped up the attached patch.  It should give you an idea on how
to do what you want.

Dan

Index: src/applet-device-wireless.c
===================================================================
--- src/applet-device-wireless.c	(revision 689)
+++ src/applet-device-wireless.c	(working copy)
@@ -450,6 +450,8 @@ add_new_ap_item (NMDevice80211Wireless *
 	                                dup_data->hash, AP_HASH_LEN);
 	item = NM_NETWORK_MENU_ITEM (foo);
 
+	nm_network_menu_item_add_dupe (item, ap);
+
 	ssid = nm_access_point_get_ssid (ap);
 	nm_network_menu_item_set_ssid (item, (GByteArray *) ssid);
 
@@ -457,7 +459,6 @@ add_new_ap_item (NMDevice80211Wireless *
 	nm_network_menu_item_set_strength (item, strength);
 
 	nm_network_menu_item_set_detail (item, ap, applet->adhoc_icon);
-	nm_network_menu_item_add_dupe (item, ap);
 
 	g_object_set_data (G_OBJECT (item), "device", NM_DEVICE (device));
 
Index: src/ap-menu-item.c
===================================================================
--- src/ap-menu-item.c	(revision 689)
+++ src/ap-menu-item.c	(working copy)
@@ -47,6 +47,8 @@ nm_network_menu_item_init (NMNetworkMenu
 	PangoLanguage * lang;
 	int ascent;
 
+	item->ap_ssid = g_byte_array_sized_new (32);
+
 	gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (item), TRUE);
 	item->hbox = gtk_hbox_new (FALSE, 6);
 	item->ssid = gtk_label_new (NULL);
@@ -121,9 +123,11 @@ nm_network_menu_item_class_dispose (GObj
 	item->destroyed = TRUE;
 	g_free (item->hash);
 
-	g_slist_foreach (item->dupes, (GFunc) g_free, NULL);
+	g_slist_foreach (item->dupes, (GFunc) g_object_unref, NULL);
 	g_slist_free (item->dupes);
 
+	g_byte_array_free (item->ap_ssid, TRUE);
+
 	G_OBJECT_CLASS (nm_network_menu_item_parent_class)->dispose (object);
 }
 
@@ -136,22 +140,57 @@ nm_network_menu_item_class_init (NMNetwo
 	object_class->dispose = nm_network_menu_item_class_dispose;
 }
 
+static void
+update_ssid_text (NMNetworkMenuItem *item)
+{
+	GString *str = g_string_new ("");
+	char *ssid_str = NULL;
+	GSList *iter;
+	gboolean more_than_one = FALSE;
+
+	ssid_str = nm_utils_ssid_to_utf8 ((const char *) item->ap_ssid->data, item->ap_ssid->len);
+	if (!ssid_str) {
+		// FIXME: shouldn't happen; always coerce the SSID to _something_
+		g_string_append (str, "<unknown>");
+		goto done;
+	}
+
+	g_string_append (str, ssid_str);
+	g_string_append (str, " (");
+
+	for (iter = item->dupes; iter; iter = g_slist_next (iter)) {
+		NMAccessPoint *ap = NM_ACCESS_POINT (iter->data);
+		guint32 freq = nm_access_point_get_frequency (ap);
+
+		if (more_than_one)
+			g_string_append_printf (str, ", %d", utils_freq_to_channel (freq));
+		else {
+			g_string_append_printf (str, "%d", utils_freq_to_channel (freq));
+			more_than_one = TRUE;
+		}
+	}
+
+	g_string_append_c (str, ')');
+
+done:
+	g_free (ssid_str);
+	gtk_label_set_text (GTK_LABEL (item->ssid), str->str);
+	g_string_free (str, TRUE);
+}
+
 void
 nm_network_menu_item_set_ssid (NMNetworkMenuItem * item, GByteArray * ssid)
 {
-	char *display_ssid = NULL;
-
 	g_return_if_fail (item != NULL);
 	g_return_if_fail (ssid != NULL);
 
-	display_ssid = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len);
-	if (!display_ssid) {
-		// FIXME: shouldn't happen; always coerce the SSID to _something_
-		gtk_label_set_text (GTK_LABEL (item->ssid), "<unknown>");
-	} else {
-		gtk_label_set_text (GTK_LABEL (item->ssid), display_ssid);
-		g_free (display_ssid);
+	if (item->ap_ssid) {
+		g_byte_array_free (item->ap_ssid, TRUE);
+		item->ap_ssid = g_byte_array_sized_new (32);
 	}
+
+	g_byte_array_append (item->ap_ssid, ssid->data, ssid->len);
+	update_ssid_text (item);
 }
 
 guint32
@@ -228,7 +267,8 @@ nm_network_menu_item_find_dupe (NMNetwor
 
 	path = nm_object_get_path (NM_OBJECT (ap));
 	for (iter = item->dupes; iter; iter = g_slist_next (iter)) {
-		if (!strcmp (path, iter->data))
+		const char *dupe_path = nm_object_get_path (NM_OBJECT (iter->data));
+		if (!strcmp (path, dupe_path))
 			return TRUE;
 	}
 	return FALSE;
@@ -237,12 +277,10 @@ nm_network_menu_item_find_dupe (NMNetwor
 void
 nm_network_menu_item_add_dupe (NMNetworkMenuItem *item, NMAccessPoint *ap)
 {
-	const char *path;
-
 	g_return_if_fail (NM_IS_NETWORK_MENU_ITEM (item));
 	g_return_if_fail (NM_IS_ACCESS_POINT (ap));
 
-	path = nm_object_get_path (NM_OBJECT (ap));
-	item->dupes = g_slist_prepend (item->dupes, g_strdup (path));
+	item->dupes = g_slist_prepend (item->dupes, g_object_ref (ap));
+	update_ssid_text (item);
 }
 
Index: src/ap-menu-item.h
===================================================================
--- src/ap-menu-item.h	(revision 689)
+++ src/ap-menu-item.h	(working copy)
@@ -57,6 +57,8 @@ struct _NMNetworkMenuItem
 	guint32     hash_len;
 	gboolean    destroyed;
 	GSList *    dupes;
+
+	GByteArray *ap_ssid;
 };
 
 struct _NMNetworkMenuItemClass


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