Fwd: updated patch



This is an update to the patch I sent the other day - it shifts the
min/max values used in channel_from_frequency() by half a step along
with some additional comments.

The min/max are simply used for amply-large tolerance in the frequency
comparison (it shouldn't need to be as wide as it is, but for sake of
simple calculations, why not?).

Thanks for considering my patch,

Katie
diff -upr nm-applet-0.6.5/ChangeLog nm-applet-0.6.5-kg/ChangeLog
--- nm-applet-0.6.5/ChangeLog	2007-04-19 14:01:22.000000000 -0400
+++ nm-applet-0.6.5-kg/ChangeLog	2007-10-20 14:38:32.000000000 -0400
@@ -1,3 +1,21 @@
+2007-10-20  Katelin Ganzer
+
+	* src/menu-items.c (network_menu_item_update): Set the channel #
+	text on the GtkProgressBar for the wireless network item.
+
+	* src/applet-dbus-devices.c (nma_dbus_net_properties_cb): Store
+	the channel info using the new wireless_network_set_channel()
+	function.
+	(channel_from_frequency): New function to map a frequency to a
+	channel.
+
+	* src/wireless-network.c (wireless_network_get_channel): New
+	function to get the stored channel # that his wireles network is
+	using.
+	(wireless_network_set_channel): New function to store the channel
+	# that this network is using.
+	(wireless_network_copy): Copy the channel #.
+
 2007-03-21  Pema Geyleg <pema geyleg gmail com>
 
 	* configure.ac: Added 'dz' to ALL_LINGUAS
diff -upr nm-applet-0.6.5/src/applet-dbus-devices.c nm-applet-0.6.5-kg/src/applet-dbus-devices.c
--- nm-applet-0.6.5/src/applet-dbus-devices.c	2007-04-19 14:01:13.000000000 -0400
+++ nm-applet-0.6.5-kg/src/applet-dbus-devices.c	2007-10-22 00:13:41.000000000 -0400
@@ -504,6 +504,68 @@ static void free_net_prop_cb_data (NetPr
 	g_free (data);
 }
 
+static struct ChanFreqRange {
+	guint8 chan_min;        /* first channel in range */
+	guint8 chan_max;        /* last channel in range */
+	guint8 chan_step;       /* channel step */
+	double freq_min;        /* first channel's frequency in GHz */
+	double freq_max;        /* last channel's frequency in GHz */
+	double freq_step;       /* frequency step in GHz */
+} chan_freq_ranges[] = {
+	{   1,  11, 1, 2.412f, 2.462f, 0.005f },
+	{  36,  64, 4, 5.18f,  5.320f, 0.020f },
+	{ 149, 165, 4, 5.745f, 5.825f, 0.020f }
+};
+
+/**
+ * channel_from_frequency:
+ * @freq: Frequency in Hz
+ *
+ * Maps the provided frequency with a channel.
+ *
+ * Returns the channel on success or 0 if unknown.
+ **/
+static guint8
+channel_from_frequency (double freq)
+{
+	struct ChanFreqRange *range = chan_freq_ranges;
+	double min, max;
+	guint8 chan;
+	int i;
+	
+	/* convert to GHz */
+	freq /= 1000000000.0;
+	
+	for (i = 0; i < G_N_ELEMENTS (chan_freq_ranges); i++, range++) {
+		max = range->freq_max + (range->freq_step / 2.0);
+		
+		if (freq > max) {
+			/* frequency not in this range, maybe in the next range? */
+			continue;
+		}
+		
+		min = range->freq_min - (range->freq_step / 2.0);
+		
+		if (freq < min) {
+			/* ranges go up in frequency, so if this is too high then later ranges won't match either */
+			break;
+		}
+		
+		max = min + range->freq_step;
+		for (chan = range->chan_min; chan <= range->chan_max; chan += range->chan_step) {
+			if (freq > min && freq < max)
+				return chan;
+			
+			min = max;
+			max += range->freq_step;
+		}
+	}
+	
+	/* unknown channel frequency */
+	
+	return 0;
+}
+
 
 /*
  * nma_dbus_net_properties_cb
@@ -566,7 +628,7 @@ static void nma_dbus_net_properties_cb (
 									DBUS_TYPE_INVALID))
 	{
 		NetworkDevice *	dev;
-
+		
 		if ((dev = nma_get_device_for_nm_path (applet->device_list, cb_data->dev_op)))
 		{
 			WirelessNetwork *	net = wireless_network_new (essid, op);
@@ -584,6 +646,7 @@ static void nma_dbus_net_properties_cb (
 			wireless_network_set_mode (net, mode);
 			wireless_network_set_capabilities (net, capabilities);
 			wireless_network_set_strength (net, strength);
+			wireless_network_set_channel (net, channel_from_frequency (freq));
 			if (act_net && strlen (act_net) && (strcmp (act_net, op) == 0))
 				wireless_network_set_active (net, TRUE);
 			g_free (act_net);
diff -upr nm-applet-0.6.5/src/menu-items.c nm-applet-0.6.5-kg/src/menu-items.c
--- nm-applet-0.6.5/src/menu-items.c	2007-04-19 14:01:13.000000000 -0400
+++ nm-applet-0.6.5-kg/src/menu-items.c	2007-10-20 14:35:29.000000000 -0400
@@ -242,7 +242,7 @@ GtkCheckMenuItem *network_menu_item_get_
 void network_menu_item_update (NMApplet *applet, NMNetworkMenuItem *item,
 						 WirelessNetwork *network, const gboolean is_encrypted)
 {
-	char *	display_essid;
+	char *	display_essid, *channel = NULL;
 	gdouble	percent;
 	gboolean	encrypted = FALSE;
 	gboolean	adhoc = FALSE;
@@ -253,6 +253,11 @@ void network_menu_item_update (NMApplet 
 	display_essid = nm_menu_network_escape_essid_for_display (wireless_network_get_essid (network));
 	gtk_label_set_text (GTK_LABEL (item->label), display_essid);
 	g_free (display_essid);
+	
+	if (wireless_network_get_channel (network) != 0)
+		channel = g_strdup_printf (_("Channel %d"), (int) wireless_network_get_channel (network));
+	gtk_progress_bar_set_text (GTK_PROGRESS_BAR (item->progress), channel);
+	g_free (channel);
 
 	percent = (double) CLAMP (wireless_network_get_strength (network), 0, 100) / 100.0;
 	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (item->progress), percent);
diff -upr nm-applet-0.6.5/src/wireless-network.c nm-applet-0.6.5-kg/src/wireless-network.c
--- nm-applet-0.6.5/src/wireless-network.c	2007-04-19 14:01:12.000000000 -0400
+++ nm-applet-0.6.5-kg/src/wireless-network.c	2007-10-20 14:31:47.000000000 -0400
@@ -37,6 +37,7 @@ struct WirelessNetwork
 	char *	essid;
 	gboolean	active;
 	gint8	strength;
+	guint8    channel;
 	int		mode;
 	int		capabilities;
 };
@@ -82,6 +83,7 @@ WirelessNetwork *wireless_network_copy (
 	net->active = src->active;
 	net->capabilities = src->capabilities;
 	net->strength = src->strength;
+	net->channel = src->channel;
 
 	return net;
 }
@@ -210,3 +212,19 @@ void wireless_network_set_strength (Wire
 	net->strength = strength;
 }
 
+/*
+ * Accesors for channel
+ */
+guint8 wireless_network_get_channel (WirelessNetwork *net)
+{
+	g_return_val_if_fail (net != NULL, FALSE);
+
+	return net->channel;
+}
+
+void wireless_network_set_channel (WirelessNetwork *net, guint8 channel)
+{
+	g_return_if_fail (net != NULL);
+
+	net->channel = channel;
+}
diff -upr nm-applet-0.6.5/src/wireless-network.h nm-applet-0.6.5-kg/src/wireless-network.h
--- nm-applet-0.6.5/src/wireless-network.h	2007-04-19 14:01:12.000000000 -0400
+++ nm-applet-0.6.5-kg/src/wireless-network.h	2007-10-20 14:32:07.000000000 -0400
@@ -47,4 +47,7 @@ void				wireless_network_set_mode		(Wire
 gint8			wireless_network_get_strength		(WirelessNetwork *net);
 void				wireless_network_set_strength		(WirelessNetwork *net, gint8 strength);
 
+guint8			wireless_network_get_channel		(WirelessNetwork *net);
+void				wireless_network_set_channel		(WirelessNetwork *net, guint8 channel);
+
 #endif


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