Drop static variable collection_list_sort_method
authorArkadiy Illarionov <[email protected]>
Tue, 8 Jul 2025 18:54:36 +0000 (21:54 +0300)
committerColin Clark <[email protected]>
Wed, 9 Jul 2025 09:15:20 +0000 (10:15 +0100)
Use sort with data.

src/collect.cc

index 0ee3b4d6f91abf50228e6c7227b676fe1e831255..5b5c09ecd296d44a8e379210d43ba179291a7070 100644 (file)
@@ -134,18 +134,14 @@ void collection_info_set_thumb(CollectInfo *ci, GdkPixbuf *pixbuf)
        ci->pixbuf = pixbuf;
 }
 
-/* an ugly static var, well what ya gonna do ? */
-static SortType collection_list_sort_method = SORT_NAME;
-
-static gint collection_list_sort_cb(gconstpointer a, gconstpointer b)
+static gint collection_list_sort_cb(gconstpointer a, gconstpointer b,
+                                    gpointer user_data)
 {
        auto cia = static_cast<const CollectInfo *>(a);
        auto cib = static_cast<const CollectInfo *>(b);
 
-       switch (collection_list_sort_method)
+       switch (GPOINTER_TO_INT(user_data))
                {
-               case SORT_NAME:
-                       break;
                case SORT_NONE:
                        return 0;
                        break;
@@ -197,9 +193,7 @@ GList *collection_list_sort(GList *list, SortType method)
 {
        if (method == SORT_NONE) return list;
 
-       collection_list_sort_method = method;
-
-       return g_list_sort(list, collection_list_sort_cb);
+       return g_list_sort_with_data(list, collection_list_sort_cb, GINT_TO_POINTER(method));
 }
 
 static GList *collection_list_randomize(GList *list)
@@ -230,8 +224,7 @@ GList *collection_list_add(GList *list, CollectInfo *ci, SortType method)
 {
        if (method != SORT_NONE)
                {
-               collection_list_sort_method = method;
-               list = g_list_insert_sorted(list, ci, collection_list_sort_cb);
+               list = g_list_insert_sorted_with_data(list, ci, collection_list_sort_cb, GINT_TO_POINTER(method));
                }
        else
                {
@@ -245,8 +238,7 @@ GList *collection_list_insert(GList *list, CollectInfo *ci, CollectInfo *insert_
 {
        if (method != SORT_NONE)
                {
-               collection_list_sort_method = method;
-               list = g_list_insert_sorted(list, ci, collection_list_sort_cb);
+               list = g_list_insert_sorted_with_data(list, ci, collection_list_sort_cb, GINT_TO_POINTER(method));
                }
        else
                {