GmpcMpdDataModel: make the sorting for merging utf8 aware.
authorQball <qball@s010375t.(none)>
Wed, 17 Feb 2010 11:53:09 +0000 (12:53 +0100)
committerQball <qball@s010375t.(none)>
Wed, 17 Feb 2010 11:53:09 +0000 (12:53 +0100)
src/browsers/playlist3-tag2-browser.c
src/gmpc-mpddata-model.gob

index d2f2b44..e8f4ab5 100644 (file)
@@ -115,36 +115,6 @@ gmpcPlugin tag2_plug = {
 };
 
 
-static gint __add_sort(gpointer aa, gpointer bb, gpointer data)
-{
-    MpdData_real *a = *(MpdData_real **)aa;
-    MpdData_real *b = *(MpdData_real **)bb;
-    if(a->type == MPD_DATA_TYPE_TAG && b->type == MPD_DATA_TYPE_TAG)
-    {
-        if(a->tag_type != b->tag_type)
-            return a->tag_type - b->tag_type;
-        if(a->tag== NULL && b->tag != NULL)
-            return -1;
-        else if(b->tag == NULL && a->tag != NULL)
-            return 1;
-        else if (a->tag  && b->tag)
-        {
-            int val;
-            if(a->tag && b->tag) {
-                gchar *sa,*sb;
-                sa = g_utf8_strdown(a->tag, -1);
-                sb = g_utf8_strdown(b->tag, -1);
-                val = g_utf8_collate(sa,sb);
-                g_free(sa);
-                g_free(sb);
-            } else {
-                val = (a == NULL)?((b==NULL)?0:-1):1;
-            }
-            return val;
-        }
-    }
-    return a->type - b->type;
-}
 /** Little hack to work around gmpc's limitations */
 static GList *tag2_ht = NULL;
 /** This stucture contains all the needed data for a browser
@@ -653,7 +623,6 @@ static void tag2_changed(GtkTreeSelection *sel2, tag_element *te)
              */
             sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(te_i->tree));
 
-            data = misc_sort_mpddata(data, (GCompareDataFunc)__add_sort , NULL);
             gmpc_mpddata_model_set_mpd_data_slow(GMPC_MPDDATA_MODEL(te_i->model), data);
             /* this make sure the selected row is centered in the middle of the treeview.
              * Otherwise the user could have the tedious job of finding it again
@@ -801,7 +770,6 @@ static void tag2_column_header_menu_item_clicked(GtkCheckMenuItem *item, tag_ele
             {
                 mpd_database_search_field_start(connection, te->type);
                 data = mpd_database_search_commit(connection);
-                data = misc_sort_mpddata(data, (GCompareDataFunc)__add_sort , NULL);
                 gmpc_mpddata_model_set_mpd_data(GMPC_MPDDATA_MODEL(te->model), data);
             }else {
                 gmpc_mpddata_model_set_mpd_data(GMPC_MPDDATA_MODEL(te->model), NULL);
@@ -902,7 +870,6 @@ static void tag2_songlist_clear_selection(GtkWidget *button, tag_browser *browse
             mpd_database_search_field_start(connection, te->type);
 
             data = mpd_database_search_commit(connection);
-            data = misc_sort_mpddata(data, (GCompareDataFunc)__add_sort , NULL);
             gmpc_mpddata_model_set_mpd_data_slow(GMPC_MPDDATA_MODEL(te->model), data);
         }else 
             gmpc_mpddata_model_set_mpd_data_slow(GMPC_MPDDATA_MODEL(te->model), NULL);
@@ -1359,7 +1326,6 @@ static void tag2_connection_changed_foreach(tag_browser *browser, gpointer userd
             {
                 mpd_database_search_field_start(connection, te->type);
                 data = mpd_database_search_commit(connection);
-                data = misc_sort_mpddata(data, (GCompareDataFunc)__add_sort , NULL);
                 gmpc_mpddata_model_set_mpd_data_slow(GMPC_MPDDATA_MODEL(te->model), data);
             }else {
                 gmpc_mpddata_model_set_mpd_data_slow(GMPC_MPDDATA_MODEL(te->model), NULL);
index 1b79b50..287ca30 100644 (file)
@@ -1056,9 +1056,33 @@ end:
         {
             MpdData_real *a = *(MpdData_real **)ppaa;
             MpdData_real *b = *(MpdData_real **)ppbb;
-            return strcmp(a->tag, b->tag); 
+            if(a->type == MPD_DATA_TYPE_TAG && b->type == MPD_DATA_TYPE_TAG)
+            {
+                if(a->tag_type != b->tag_type)
+                    return a->tag_type - b->tag_type;
+                if(a->tag== NULL && b->tag != NULL)
+                    return -1;
+                else if(b->tag == NULL && a->tag != NULL)
+                    return 1;
+                else if (a->tag  && b->tag)
+                {
+                    int val;
+                    if(a->tag && b->tag) {
+                        gchar *sa,*sb;
+                        sa = g_utf8_strdown(a->tag, -1);
+                        sb = g_utf8_strdown(b->tag, -1);
+                        val = g_utf8_collate(sa,sb);
+                        g_free(sa);
+                        g_free(sb);
+                    } else {
+                        val = (a == NULL)?((b==NULL)?0:-1):1;
+                    }
+                    return val;
+                }
+            }
+            return a->type - b->type;
         }
-
+        
         /**
          * For now this assumes tag list only.
          */