tools: gst-play: sort directory entries

When adding a directory to the playlist, the order would be whatever
g_dir_read_name returned. Sorting these using natural sort order.

https://bugzilla.gnome.org/show_bug.cgi?id=750585
This commit is contained in:
Vivia Nikolaidou 2015-06-08 20:32:02 +03:00 committed by Tim-Philipp Müller
parent 6221c95d48
commit 4fdbe215dc

View file

@ -588,6 +588,21 @@ do_play (GstPlay * play)
g_main_loop_run (play->loop);
}
static gint
compare (gconstpointer a, gconstpointer b)
{
gchar *a1, *b1;
gint ret;
a1 = g_utf8_collate_key_for_filename ((gchar *) a, -1);
b1 = g_utf8_collate_key_for_filename ((gchar *) b, -1);
ret = strcmp (a1, b1);
g_free (a1);
g_free (b1);
return ret;
}
static void
add_to_playlist (GPtrArray * playlist, const gchar * filename)
{
@ -601,17 +616,24 @@ add_to_playlist (GPtrArray * playlist, const gchar * filename)
if ((dir = g_dir_open (filename, 0, NULL))) {
const gchar *entry;
GList *l, *files = NULL;
/* FIXME: sort entries for each directory? */
while ((entry = g_dir_read_name (dir))) {
gchar *path;
path = g_strconcat (filename, G_DIR_SEPARATOR_S, entry, NULL);
add_to_playlist (playlist, path);
g_free (path);
files = g_list_insert_sorted (files, path, compare);
}
g_dir_close (dir);
for (l = files; l != NULL; l = l->next) {
gchar *path = (gchar *) l->data;
add_to_playlist (playlist, path);
g_free (path);
}
g_list_free (files);
return;
}