[gnome-disk-utility] GduWindow: use g_strcmp0() as to sort items in device tree



commit ae731216b1283d20c36147c09093c29c966f5ce2
Author: David Zeuthen <davidz redhat com>
Date:   Thu Jan 26 11:10:33 2012 -0500

    GduWindow: use g_strcmp0() as to sort items in device tree
    
    Otherwise we won't sort the drive for /dev/sdz before /dev/sdaa
    because the tree view sort function sorts __aa before ___b (because it
    ignores leading underscores). With this change we show the devices in
    the expected order (e.g. kernel probe order):
    
     http://people.freedesktop.org/~david/udisks2-palimpsest-many-sas-and-sata-disks-kernel-sort-order.png
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 src/palimpsest/gduwindow.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index 1cadeb6..a4b12f6 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -837,6 +837,25 @@ on_constructed_in_idle (gpointer user_data)
   return FALSE; /* remove source */
 }
 
+static gint
+device_sort_function (GtkTreeModel *model,
+                      GtkTreeIter *a,
+                      GtkTreeIter *b,
+                      gpointer user_data)
+{
+  gchar *sa, *sb;
+
+  gtk_tree_model_get (model, a,
+                      GDU_DEVICE_TREE_MODEL_COLUMN_SORT_KEY, &sa,
+                      -1);
+  gtk_tree_model_get (model, b,
+                      GDU_DEVICE_TREE_MODEL_COLUMN_SORT_KEY, &sb,
+                      -1);
+
+  return g_strcmp0 (sa, sb);
+}
+
+
 static void
 gdu_window_constructed (GObject *object)
 {
@@ -905,6 +924,12 @@ gdu_window_constructed (GObject *object)
   gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (window->model),
                                         GDU_DEVICE_TREE_MODEL_COLUMN_SORT_KEY,
                                         GTK_SORT_ASCENDING);
+  /* Force g_strcmp0() as the sort function otherwise ___aa won't come before ____b ... */
+  gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (window->model),
+                                   GDU_DEVICE_TREE_MODEL_COLUMN_SORT_KEY,
+                                   device_sort_function,
+                                   NULL, /* user_data */
+                                   NULL); /* GDestroyNotify */
 
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (window->device_treeview));
   gtk_tree_selection_set_select_function (selection, dont_select_headings, NULL, NULL);



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