summaryrefslogtreecommitdiff
path: root/backend/comics
diff options
context:
space:
mode:
authorPerberos <[email protected]>2013-05-03 12:14:47 -0300
committerPerberos <[email protected]>2013-05-03 12:14:47 -0300
commit445aa5e62290e3532e881fe58dc8a1f536eb41da (patch)
treea0b0b659ff419beebbc213b78a14ec7fca241bae /backend/comics
parent2f51974845f64d15748af035287694176e66adb3 (diff)
downloadatril-445aa5e62290e3532e881fe58dc8a1f536eb41da.tar.bz2
atril-445aa5e62290e3532e881fe58dc8a1f536eb41da.tar.xz
better sort on filename images for comic book archives
This should fix the issue with files 1.jpg ... 10.jpg
Diffstat (limited to 'backend/comics')
-rw-r--r--backend/comics/comics-document.c38
1 files changed, 37 insertions, 1 deletions
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