[gnome-control-center/order-background-items: 47/47] background: Order background items alphabetically




commit 398e707b00d7c6cd4649e83383445a4fbb5384c0
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Mar 22 14:26:15 2022 +0100

    background: Order background items alphabetically
    
    Except for the "Default Background" which skips the line and gets
    shown first.
    
    Fixes #1716

 panels/background/bg-wallpapers-source.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
---
diff --git a/panels/background/bg-wallpapers-source.c b/panels/background/bg-wallpapers-source.c
index 7d3b644e5..42f70ba99 100644
--- a/panels/background/bg-wallpapers-source.c
+++ b/panels/background/bg-wallpapers-source.c
@@ -35,6 +35,27 @@ struct _BgWallpapersSource
 
 G_DEFINE_TYPE (BgWallpapersSource, bg_wallpapers_source, BG_TYPE_SOURCE)
 
+static int
+sort_func (gconstpointer a,
+           gconstpointer b,
+           gpointer      user_data)
+{
+  CcBackgroundItem *item_a;
+  CcBackgroundItem *item_b;
+
+  item_a = (CcBackgroundItem *) a;
+  item_b = (CcBackgroundItem *) b;
+
+  if (strcmp (cc_background_item_get_name (item_a), "Default Background") == 0)
+    return -1;
+  if (strcmp (cc_background_item_get_name (item_b), "Default Background") == 0)
+    return 1;
+
+
+  return strcmp (cc_background_item_get_name (item_a),
+                 cc_background_item_get_name (item_b));
+}
+
 static void
 load_wallpapers (gchar              *key,
                  CcBackgroundItem   *item,
@@ -48,7 +69,7 @@ load_wallpapers (gchar              *key,
   if (deleted)
     return;
 
-  g_list_store_append (store, item);
+  g_list_store_insert_sorted (store, item, sort_func, NULL);
 }
 
 static void


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