From: Andreas Obergrusberger Date: Sat, 28 Oct 2006 08:36:46 +0000 (+0000) Subject: filelist sorting improved X-Git-Tag: v0.12_alpha1~356 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4d2b64970156306cfd986d19e0aed22cb7c30479;p=ncmpc.git filelist sorting improved git-svn-id: https://svn.musicpd.org/ncmpc/branches/tradiaz@4953 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- diff --git a/ChangeLog b/ChangeLog index 6d9722b..bf4ec54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2006-10-28 Anderas Obergrusberger + * Daniel has added sorting by caring about LC_COLLATE + 2006-10-26 Andreas Obergrusberger * updated the galician translation by Johám-Luís Miguéns Vila diff --git a/src/main.c b/src/main.c index 35e343b..02311ad 100644 --- a/src/main.c +++ b/src/main.c @@ -190,6 +190,8 @@ main(int argc, const char *argv[]) #ifdef HAVE_LOCALE_H /* time and date formatting */ setlocale(LC_TIME,""); + /* care about sorting order etc */ + setlocale(LC_COLLATE,""); /* charset */ setlocale(LC_CTYPE,""); /* initialize charset conversions */ diff --git a/src/mpdclient.c b/src/mpdclient.c index 88330b2..b13146f 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -42,6 +42,31 @@ /* from utils.c */ extern GList *string_list_free(GList *string_list); + +/* filelist sorting functions */ +static gint +compare_filelistentry_dir(gconstpointer filelist_entry1, gconstpointer filelist_entry2) +{ + mpd_InfoEntity *e1, *e2; + char *key1, *key2; + int n = 0; + + e1 = ((filelist_entry_t *)filelist_entry1)->entity; + e2 = ((filelist_entry_t *)filelist_entry2)->entity; + if (e1 && e2 && + e1->type == MPD_INFO_ENTITY_TYPE_DIRECTORY && + e2->type == MPD_INFO_ENTITY_TYPE_DIRECTORY) + { + key1 = g_utf8_collate_key(e1->info.directory->path,-1); + key2 = g_utf8_collate_key(e2->info.directory->path,-1); + n = strcmp(key1,key2); + g_free(key1); + g_free(key2); + } + return n; +} + + /* Error callbacks */ static gint error_cb(mpdclient_t *c, gint error, gchar *msg) @@ -853,6 +878,7 @@ mpdclient_filelist_get(mpdclient_t *c, gchar *path) mpdclient_filelist_t *filelist; mpd_InfoEntity *entity; gchar *path_utf8 = locale_to_utf8(path); + gboolean has_dirs_only = TRUE; D("mpdclient_filelist_get(%s)\n", path); mpd_sendLsInfoCommand(c->connection, path_utf8); @@ -873,6 +899,11 @@ mpdclient_filelist_get(mpdclient_t *c, gchar *path) entry->entity = entity; filelist->list = g_list_append(filelist->list, (gpointer) entry); filelist->length++; + + if (has_dirs_only && entity->type != MPD_INFO_ENTITY_TYPE_DIRECTORY) + { + has_dirs_only = FALSE; + } } /* If there's an error, ignore it. We'll return an empty filelist. */ @@ -882,6 +913,13 @@ mpdclient_filelist_get(mpdclient_t *c, gchar *path) filelist->path = g_strdup(path); filelist->updated = TRUE; + // If there are only directory entities in the filelist, we sort it + if (has_dirs_only) + { + D("mpdclient_filelist_get: only dirs; sorting!\n"); + filelist->list = g_list_sort(filelist->list, compare_filelistentry_dir); + } + return filelist; }