[network-manager-netbook] Sort the lists.
- From: Tambet Ingo <tambeti src gnome org>
- To: svn-commits-list gnome org
- Subject: [network-manager-netbook] Sort the lists.
- Date: Thu, 4 Jun 2009 06:33:50 -0400 (EDT)
commit caf74b0340ea101fd95edb4e01971a297341a915
Author: Tambet Ingo <tambet gmail com>
Date: Wed Jun 3 11:31:28 2009 +0300
Sort the lists.
---
TODO | 1 -
src/nmn-ethernet-item.c | 7 +++++++
src/nmn-item.c | 26 +++++++++-----------------
src/nmn-item.h | 7 +++----
src/nmn-list.c | 39 +++++++++++++++++++++++++++++++++++++++
src/nmn-network-item.c | 20 +++++++++++++++++++-
src/nmn-serial-item.c | 9 +++++++++
src/nmn-wifi-item.c | 14 ++++++++++++++
8 files changed, 100 insertions(+), 23 deletions(-)
diff --git a/TODO b/TODO
index 6aad066..cc554ea 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,2 @@
-* Networks/AP lists are not sorted, in random order.
* "Advanced" button doesn't do anything, used for specifying static IP, manual DNS, etc.
* Hidden APs are not supported at all.
diff --git a/src/nmn-ethernet-item.c b/src/nmn-ethernet-item.c
index ff8158f..22fe310 100644
--- a/src/nmn-ethernet-item.c
+++ b/src/nmn-ethernet-item.c
@@ -95,6 +95,12 @@ disconnect (NmnItem *item)
NMN_ITEM_CLASS (nmn_ethernet_item_parent_class)->disconnect (item);
}
+static guint
+get_priority (NmnItem *item)
+{
+ return NMN_ITEM_CLASS (nmn_ethernet_item_parent_class)->get_priority (item) + 50;
+}
+
static void
nmn_ethernet_item_init (NmnEthernetItem *item)
{
@@ -155,4 +161,5 @@ nmn_ethernet_item_class_init (NmnEthernetItemClass *class)
item_class->connect = connect;
item_class->disconnect = disconnect;
+ item_class->get_priority = get_priority;
}
diff --git a/src/nmn-item.c b/src/nmn-item.c
index 1f8224f..a32490b 100644
--- a/src/nmn-item.c
+++ b/src/nmn-item.c
@@ -30,7 +30,6 @@ typedef struct {
GtkButton *connect;
GtkWidget *remove;
NmnItemStatus status;
- guint priority;
} NmnItemPrivate;
GtkWidget *
@@ -204,24 +203,20 @@ nmn_item_remove_request (NmnItem *self)
guint
nmn_item_get_priority (NmnItem *self)
{
- g_return_val_if_fail (NMN_IS_ITEM (self), G_MAXUINT);
+ g_return_val_if_fail (NMN_IS_ITEM (self), 0);
- return NMN_ITEM_GET_PRIVATE (self)->priority;
+ if (NMN_ITEM_GET_CLASS (self)->get_priority)
+ return NMN_ITEM_GET_CLASS (self)->get_priority (self);
+
+ return 0;
}
void
-nmn_item_set_priority (NmnItem *self,
- guint priority)
+nmn_item_priority_changed (NmnItem *self)
{
- NmnItemPrivate *priv;
-
g_return_if_fail (NMN_IS_ITEM (self));
- priv = NMN_ITEM_GET_PRIVATE (self);
- if (priv->priority != priority) {
- priv->priority = priority;
- g_signal_emit (self, signals[PRIORITY_CHANGED], 0, priority);
- }
+ g_signal_emit (self, signals[PRIORITY_CHANGED], 0);
}
static void
@@ -302,8 +297,6 @@ nmn_item_init (NmnItem *item)
priv->remove = NULL;
- priv->priority = G_MAXUINT;
-
gtk_container_add (GTK_CONTAINER (item), GTK_WIDGET (priv->box));
gtk_widget_show_all (GTK_WIDGET (priv->box));
}
@@ -361,7 +354,6 @@ nmn_item_class_init (NmnItemClass *class)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (NmnItemClass, priority_changed),
NULL, NULL,
- g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE, 1,
- G_TYPE_UINT);
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
diff --git a/src/nmn-item.h b/src/nmn-item.h
index 095ba08..a68a39d 100644
--- a/src/nmn-item.h
+++ b/src/nmn-item.h
@@ -22,14 +22,14 @@ typedef struct {
/* Methods */
void (*connect) (NmnItem *self);
void (*disconnect) (NmnItem *self);
+ guint (*get_priority) (NmnItem *self);
/* Signals */
void (*connect_requested) (NmnItem *self);
void (*disconnect_requested) (NmnItem *self);
void (*remove_requested) (NmnItem *self);
void (*delete) (NmnItem *self);
- void (*priority_changed) (NmnItem *self,
- guint priority);
+ void (*priority_changed) (NmnItem *self);
} NmnItemClass;
typedef enum {
@@ -67,7 +67,6 @@ void nmn_item_disconnect_request (NmnItem *self);
void nmn_item_remove_request (NmnItem *self);
guint nmn_item_get_priority (NmnItem *self);
-void nmn_item_set_priority (NmnItem *self,
- guint priority);
+void nmn_item_priority_changed (NmnItem *self);
#endif /* NMN_ITEM_H */
diff --git a/src/nmn-list.c b/src/nmn-list.c
index 4cac77e..d82c063 100644
--- a/src/nmn-list.c
+++ b/src/nmn-list.c
@@ -120,6 +120,40 @@ drag_end (GtkWidget *widget, GdkDragContext *drag_context, gpointer user_data)
gtk_widget_destroy (priv->dnd_window);
}
+static gint
+compare_items (gconstpointer a,
+ gconstpointer b)
+{
+ guint aa;
+ guint bb;
+
+ aa = nmn_item_get_priority (NMN_ITEM (a));
+ bb = nmn_item_get_priority (NMN_ITEM (b));
+
+ if (aa < bb)
+ return 1;
+
+ if (aa == bb)
+ return 0;
+
+ return -1;
+}
+
+static void
+nmn_list_sort (NmnList *list)
+{
+ GList *items;
+ GList *iter;
+ int i;
+
+ items = gtk_container_get_children (GTK_CONTAINER (list));
+ items = g_list_sort (items, compare_items);
+ i = 0;
+
+ for (iter = items; iter; iter = iter->next)
+ gtk_box_reorder_child (GTK_BOX (list), GTK_WIDGET (iter->data), i++);
+}
+
void
nmn_list_add_item (NmnList *list,
NmnItem *item)
@@ -147,7 +181,12 @@ nmn_list_add_item (NmnList *list,
G_CALLBACK (drag_end),
list);
+ g_signal_connect_swapped (item, "priority-changed",
+ G_CALLBACK (nmn_list_sort),
+ list);
+
gtk_box_pack_start (GTK_BOX (list), GTK_WIDGET (item), FALSE, FALSE, 0);
+ nmn_list_sort (list);
gtk_widget_show (GTK_WIDGET (item));
}
diff --git a/src/nmn-network-item.c b/src/nmn-network-item.c
index 3377de2..9161f13 100644
--- a/src/nmn-network-item.c
+++ b/src/nmn-network-item.c
@@ -85,6 +85,7 @@ ac_state_changed (NMActiveConnection *ac,
status = NMN_ITEM_STATUS_DISCONNECTED;
nmn_item_set_status (NMN_ITEM (user_data), status);
+ nmn_item_priority_changed (NMN_ITEM (user_data));
}
void
@@ -276,11 +277,27 @@ item_delete (NmnItem *item)
{
NMExportedConnection *exported = nmn_network_item_get_connection (NMN_NETWORK_ITEM (item));
- g_debug ("network item remove requested (%p)", exported);
if (exported)
nm_exported_connection_delete (exported, NULL);
}
+static guint
+get_priority (NmnItem *item)
+{
+ NMActiveConnection *ac;
+ guint priority = 0;
+
+ ac = nmn_network_item_get_active_connection (NMN_NETWORK_ITEM (item));
+ if (ac) {
+ priority = 90;
+
+ if (nm_active_connection_get_default (ac))
+ priority += 10;
+ }
+
+ return priority;
+}
+
static void
nmn_network_item_init (NmnNetworkItem *item)
{
@@ -405,6 +422,7 @@ nmn_network_item_class_init (NmnNetworkItemClass *class)
item_class->connect = connect;
item_class->disconnect = disconnect;
item_class->delete = item_delete;
+ item_class->get_priority = get_priority;
/* properties */
g_object_class_install_property
diff --git a/src/nmn-serial-item.c b/src/nmn-serial-item.c
index cf5d1ab..2b9ccf9 100644
--- a/src/nmn-serial-item.c
+++ b/src/nmn-serial-item.c
@@ -52,6 +52,12 @@ nmn_serial_item_new (NmnNMData *nm_data,
NULL));
}
+static guint
+get_priority (NmnItem *item)
+{
+ return NMN_ITEM_CLASS (nmn_serial_item_parent_class)->get_priority (item) + 10;
+}
+
static void
nmn_serial_item_init (NmnSerialItem *item)
{
@@ -104,9 +110,12 @@ static void
nmn_serial_item_class_init (NmnSerialItemClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
+ NmnItemClass *item_class = NMN_ITEM_CLASS (class);
g_type_class_add_private (object_class, sizeof (NmnSerialItemPrivate));
object_class->constructor = constructor;
object_class->dispose = dispose;
+
+ item_class->get_priority = get_priority;
}
diff --git a/src/nmn-wifi-item.c b/src/nmn-wifi-item.c
index 0343c46..8283b41 100644
--- a/src/nmn-wifi-item.c
+++ b/src/nmn-wifi-item.c
@@ -489,6 +489,18 @@ disconnect (NmnItem *item)
NMN_ITEM_CLASS (nmn_wifi_item_parent_class)->disconnect (item);
}
+static guint
+get_priority (NmnItem *item)
+{
+ guint priority;
+
+ priority = NMN_ITEM_CLASS (nmn_wifi_item_parent_class)->get_priority (item) + 20;
+
+ /* FIXME: Add some more based on SSID? signal strength? */
+
+ return priority;
+}
+
static const char *
get_specific_object (NmnNetworkItem *network_item)
{
@@ -725,6 +737,8 @@ nmn_wifi_item_class_init (NmnWifiItemClass *class)
item_class->connect = connect;
item_class->disconnect = disconnect;
+ item_class->get_priority = get_priority;
+
network_item_class->get_specific_object = get_specific_object;
network_item_class->secrets_requested = secrets_requested;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]