[network-manager-applet/wimax: 7/7] applet: fix device sorting for WiMAX
- From: Dan Williams <dcbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/wimax: 7/7] applet: fix device sorting for WiMAX
- Date: Tue, 4 Jan 2011 22:22:56 +0000 (UTC)
commit 95c57d42db18263eb88dbb2cddca7cd31d98a7f4
Author: Dan Williams <dcbw redhat com>
Date: Tue Jan 4 16:22:47 2011 -0600
applet: fix device sorting for WiMAX
src/applet.c | 59 +++++++++++++++++++++++++--------------------------------
1 files changed, 26 insertions(+), 33 deletions(-)
---
diff --git a/src/applet.c b/src/applet.c
index feaf3a2..dfc00e5 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -1160,11 +1160,8 @@ sort_devices (gconstpointer a, gconstpointer b)
{
NMDevice *aa = NM_DEVICE (a);
NMDevice *bb = NM_DEVICE (b);
- GType aa_type;
- GType bb_type;
-
- aa_type = G_OBJECT_TYPE (G_OBJECT (aa));
- bb_type = G_OBJECT_TYPE (G_OBJECT (bb));
+ GType aa_type = G_OBJECT_TYPE (G_OBJECT (aa));
+ GType bb_type = G_OBJECT_TYPE (G_OBJECT (bb));
if (aa_type == bb_type) {
char *aa_desc = NULL;
@@ -1178,42 +1175,40 @@ sort_devices (gconstpointer a, gconstpointer b)
if (!bb_desc)
bb_desc = (char *) nm_device_get_iface (bb);
- if (!aa_desc && bb_desc)
- return -1;
- else if (aa_desc && !bb_desc)
- return 1;
- else if (!aa_desc && !bb_desc)
- return 0;
-
- g_assert (aa_desc);
- g_assert (bb_desc);
- return strcmp (aa_desc, bb_desc);
+ return g_strcmp0 (aa_desc, bb_desc);
}
- if (aa_type == NM_TYPE_DEVICE_ETHERNET && bb_type == NM_TYPE_DEVICE_WIFI)
- return -1;
- if (aa_type == NM_TYPE_DEVICE_ETHERNET && bb_type == NM_TYPE_GSM_DEVICE)
- return -1;
- if (aa_type == NM_TYPE_DEVICE_ETHERNET && bb_type == NM_TYPE_CDMA_DEVICE)
- return -1;
- if (aa_type == NM_TYPE_DEVICE_ETHERNET && bb_type == NM_TYPE_DEVICE_BT)
+ /* Ethernet always first */
+ if (aa_type == NM_TYPE_DEVICE_ETHERNET)
return -1;
+ if (bb_type == NM_TYPE_DEVICE_ETHERNET)
+ return 1;
- if (aa_type == NM_TYPE_GSM_DEVICE && bb_type == NM_TYPE_CDMA_DEVICE)
- return -1;
- if (aa_type == NM_TYPE_GSM_DEVICE && bb_type == NM_TYPE_DEVICE_WIFI)
- return -1;
- if (aa_type == NM_TYPE_GSM_DEVICE && bb_type == NM_TYPE_DEVICE_BT)
+ /* GSM next */
+ if (aa_type == NM_TYPE_GSM_DEVICE)
return -1;
+ if (bb_type == NM_TYPE_GSM_DEVICE)
+ return 1;
- if (aa_type == NM_TYPE_CDMA_DEVICE && bb_type == NM_TYPE_DEVICE_WIFI)
+ /* CDMA next */
+ if (aa_type == NM_TYPE_CDMA_DEVICE)
return -1;
- if (aa_type == NM_TYPE_CDMA_DEVICE && bb_type == NM_TYPE_DEVICE_BT)
+ if (bb_type == NM_TYPE_CDMA_DEVICE)
+ return 1;
+
+ /* Bluetooth next */
+ if (aa_type == NM_TYPE_DEVICE_BT)
return -1;
+ if (bb_type == NM_TYPE_DEVICE_BT)
+ return 1;
- if (aa_type == NM_TYPE_DEVICE_BT && bb_type == NM_TYPE_DEVICE_WIFI)
+ /* WiMAX next */
+ if (aa_type == NM_TYPE_DEVICE_WIMAX)
return -1;
+ if (bb_type == NM_TYPE_DEVICE_WIMAX)
+ return 1;
+ /* WiFi last because it has many menu items */
return 1;
}
@@ -1395,9 +1390,7 @@ nma_menu_add_devices (GtkWidget *menu, NMApplet *applet)
temp = nm_client_get_devices (applet->nm_client);
for (i = 0; temp && (i < temp->len); i++)
- devices = g_slist_append (devices, g_ptr_array_index (temp, i));
- if (devices)
- devices = g_slist_sort (devices, sort_devices);
+ devices = g_slist_insert_sorted (devices, g_ptr_array_index (temp, i), sort_devices);
for (iter = devices; iter; iter = iter->next) {
NMDevice *device = NM_DEVICE (iter->data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]