From 445aa5e62290e3532e881fe58dc8a1f536eb41da Mon Sep 17 00:00:00 2001 From: Perberos Date: Fri, 3 May 2013 12:14:47 -0300 Subject: better sort on filename images for comic book archives This should fix the issue with files 1.jpg ... 10.jpg --- backend/comics/comics-document.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/backend/comics/comics-document.c b/backend/comics/comics-document.c index 9079ee7b..a135a743 100644 --- a/backend/comics/comics-document.c +++ b/backend/comics/comics-document.c @@ -433,7 +433,43 @@ static int sort_page_names (gconstpointer a, gconstpointer b) { - return strcmp (* (const char **) a, * (const char **) b); + const char *name_1, *name_2; + gchar *key_1, *key_2; + gboolean sort_last_1, sort_last_2; + int compare; + + name_1 = * (const char **) a; + name_2 = * (const char **) b; + + #define SORT_LAST_CHAR1 '.' + #define SORT_LAST_CHAR2 '#' + + sort_last_1 = name_1[0] == SORT_LAST_CHAR1 || name_1[0] == SORT_LAST_CHAR2; + sort_last_2 = name_2[0] == SORT_LAST_CHAR1 || name_2[0] == SORT_LAST_CHAR2; + + #undef SORT_LAST_CHAR1 + #undef SORT_LAST_CHAR2 + + if (sort_last_1 && !sort_last_2) + { + compare = +1; + } + else if (!sort_last_1 && sort_last_2) + { + compare = -1; + } + else + { + key_1 = g_utf8_collate_key_for_filename (name_1, -1); + key_2 = g_utf8_collate_key_for_filename (name_2, -1); + + compare = strcmp (key_1, key_2); + + g_free (key_1); + g_free (key_2); + } + + return compare; } static gboolean -- cgit v1.2.1