summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2012-06-30 11:18:36 +0100
committerChristophe Fergeau <cfergeau@redhat.com>2013-04-10 15:23:34 +0200
commit04dcd653edd294eb44464bf9df2ed7725154252c (patch)
tree2825103667178251e0c53d475fd322282863b085
parent7acd76f7a5981cacc434c7541612b27733734b85 (diff)
Sort release details.
To display the entries in the multiple release dialog in a consistent manner we need to be able to sort them. https://bugzilla.gnome.org/show_bug.cgi?id=674926
-rw-r--r--src/sj-main.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/sj-main.c b/src/sj-main.c
index ad6577d..2edd949 100644
--- a/src/sj-main.c
+++ b/src/sj-main.c
@@ -782,6 +782,91 @@ static void selected_album_changed (GtkTreeSelection *selection,
}
}
+
+/**
+ * NULL safe utility to collate utf8 strings
+ */
+static gint collate (const char *a, const char *b)
+{
+ gint ret_val = 0;
+
+ if (a) {
+ if (b) {
+ ret_val = g_utf8_collate (a, b);
+ } else {
+ ret_val = 1;
+ }
+ } else if (b) {
+ ret_val = -1;
+ }
+ return ret_val;
+}
+
+/**
+ * Utility function to sort albums in multiple_album_dialog
+ */
+static gint sort_release_info (GtkTreeModel *model, GtkTreeIter *a,
+ GtkTreeIter *b, gpointer user_data)
+{
+ AlbumDetails *album_a, *album_b;
+ GList *label_a, *label_b;
+ gint ret_val = 0;
+ const gint column = GPOINTER_TO_INT (user_data);
+
+ gtk_tree_model_get (model, a, column, &album_a, -1);
+ gtk_tree_model_get (model, b, column, &album_b, -1);
+
+ ret_val = collate (album_a->title, album_b->title);
+ if (ret_val)
+ return ret_val;
+
+ ret_val = collate (album_a->artist_sortname, album_b->artist_sortname);
+ if (ret_val)
+ return ret_val;
+
+ ret_val = collate (album_a->country, album_b->country);
+ if (ret_val)
+ return ret_val;
+
+ if (album_a->release_date) {
+ if (album_b->release_date) {
+ ret_val = g_date_compare (album_a->release_date, album_b->release_date);
+ if (ret_val)
+ return ret_val;
+ } else {
+ return -1;
+ }
+ } else if (album_b->release_date) {
+ return 1;
+ }
+
+ label_a = album_a->labels;
+ label_b = album_b->labels;
+ while (label_a && label_b) {
+ LabelDetails *a = label_a->data;
+ LabelDetails *b = label_b->data;
+ ret_val = collate (a->sortname,b->sortname);
+ if (ret_val)
+ return ret_val;
+
+ label_a = label_a->next;
+ label_b = label_b->next;
+ }
+ if (label_a && !label_b)
+ return -1;
+ if (!label_a && label_b)
+ return 1;
+
+ ret_val = (album_a->disc_number < album_b->disc_number) ? -1 :
+ ((album_a->disc_number > album_b->disc_number) ? 1 : 0);
+ if (ret_val)
+ return ret_val;
+
+ return (album_a->disc_count < album_b->disc_count) ? -1 :
+ ((album_a->disc_count > album_b->disc_count) ? 1 : 0);
+}
+
+
/**
* Utility function to format label string for multiple_album_dialog
*/