[gnome-bluetooth/wip/hadess/fix-devices-moving: 2/2] settings-widget: Sort by time created rather than alphabetically




commit bf19319ce0927ec6c5c2c797b0e63cea7f152580
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Feb 19 14:45:55 2021 +0100

    settings-widget: Sort by time created rather than alphabetically
    
    Sort devices by the time a row was created for them. This means that
    newly discovered devices should appear at the bottom of the list, rather
    than the top, making it less likely that the widget under the mouse or
    finger would change before it's clicked.
    
    This should also make the list of setup devices more static even if
    the device names are changed.
    
    Closes: #55

 lib/bluetooth-settings-widget.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
---
diff --git a/lib/bluetooth-settings-widget.c b/lib/bluetooth-settings-widget.c
index ae649d7b..8832f31f 100644
--- a/lib/bluetooth-settings-widget.c
+++ b/lib/bluetooth-settings-widget.c
@@ -1412,20 +1412,19 @@ device_sort_func (gconstpointer a, gconstpointer b, gpointer data)
        gboolean paired_a, paired_b;
        gboolean trusted_a, trusted_b;
        gboolean connected_a, connected_b;
-       g_autofree char *alias_a = NULL;
-       g_autofree char *alias_b = NULL;
+       gint64 time_a, time_b;
 
        g_object_get (row_a,
                      "paired", &paired_a,
                      "trusted", &trusted_a,
                      "connected", &connected_a,
-                     "alias", &alias_a,
+                     "time-created", &time_a,
                      NULL);
        g_object_get (row_b,
                      "paired", &paired_b,
                      "trusted", &trusted_b,
                      "connected", &connected_b,
-                     "alias", &alias_b,
+                     "time-created", &time_b,
                      NULL);
 
        /* First, paired or trusted devices (setup devices) */
@@ -1446,13 +1445,8 @@ device_sort_func (gconstpointer a, gconstpointer b, gpointer data)
                        return 1;
        }
 
-       if (alias_a == NULL)
-               return 1;
-       if (alias_b == NULL)
-               return -1;
-
-       /* And all being equal, alphabetically */
-       return g_utf8_collate (alias_a, alias_b);
+       /* And all being equal, oldest ones first */
+       return (time_a > time_b) ? 1 : -1;
 }
 
 static void


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