From 5d4de9c5b0aeecf1ec5b0325b3fab4419f389d08 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 4 May 2016 09:55:37 -0400 Subject: [PATCH] core/playlist: Add playlist_sort() function Signed-off-by: Anna Schumaker --- core/playlist.c | 5 +++++ core/playlists/system.c | 8 ++++++++ gui/view.c | 7 ++++++- include/core/playlist.h | 3 +++ include/core/playlists/type.h | 3 +++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/core/playlist.c b/core/playlist.c index d8c3422e..e96dbc54 100644 --- a/core/playlist.c +++ b/core/playlist.c @@ -58,6 +58,11 @@ bool playlist_get_random(const gchar *name) return queue_has_flag(playlist_get_queue(name), Q_RANDOM); } +void playlist_sort(const gchar *name, enum compare_t sort, bool reset) +{ + pl_system.pl_sort(name, sort, reset); +} + struct queue *playlist_get_queue(const gchar *name) { return pl_system.pl_get_queue(name); diff --git a/core/playlists/system.c b/core/playlists/system.c index 08043524..82c6ffb6 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -197,6 +197,13 @@ static void pl_system_set_flag(const gchar *name, enum queue_flags flag, queue_unset_flag(__sys_pl_queue(plist), flag); } +static void pl_system_sort(const gchar *name, enum compare_t sort, bool reset) +{ + enum sys_playlist_t plist = __sys_pl_convert(name); + + queue_sort(__sys_pl_queue(plist), sort, reset); +} + struct playlist_type pl_system = { .pl_get_queue = pl_system_get_queue, @@ -204,6 +211,7 @@ struct playlist_type pl_system = { .pl_remove_track = pl_system_remove_track, .pl_update = pl_system_update, .pl_set_flag = pl_system_set_flag, + .pl_sort = pl_system_sort, }; diff --git a/gui/view.c b/gui/view.c index bb51b5b8..11c4334f 100644 --- a/gui/view.c +++ b/gui/view.c @@ -168,12 +168,17 @@ void __view_column_clicked(GtkTreeViewColumn *col, gpointer data) { struct queue *queue = __view_filter_get_queue(); unsigned int index = __view_get_column_index(col); + bool reset = view_sort_count == 0; gchar *text; if (!queue || queue_has_flag(queue, Q_NO_SORT)) return; - queue_sort(queue, QUEUE_SORT[index], view_sort_count == 0); + if (playlist_get_queue(gui_queue(queue)->gq_text)) + playlist_sort(gui_queue(queue)->gq_text, QUEUE_SORT[index], reset); + else + queue_sort(queue, QUEUE_SORT[index], reset); + if (view_sort_count == 0) { text = g_strdup_printf("Sorting within %s", gtk_tree_view_column_get_title(col)); diff --git a/include/core/playlist.h b/include/core/playlist.h index a8ea0e9a..7ec166da 100644 --- a/include/core/playlist.h +++ b/include/core/playlist.h @@ -41,6 +41,9 @@ void playlist_set_random(const gchar *, bool); /* Called to check the playlist's random flag. */ bool playlist_get_random(const gchar *); +/* Called to change the sort order of the playlist. */ +void playlist_sort(const gchar *, enum compare_t, bool); + /* Called to access the playlist queue. */ struct queue *playlist_get_queue(const gchar *); diff --git a/include/core/playlists/type.h b/include/core/playlists/type.h index ea1ce5e3..2d07ba16 100644 --- a/include/core/playlists/type.h +++ b/include/core/playlists/type.h @@ -33,6 +33,9 @@ struct playlist_type { /* Called to set a playlist flag. */ void (*pl_set_flag)(const gchar *, enum queue_flags, bool); + + /* Called to sort a playlist. */ + void (*pl_sort)(const gchar *, enum compare_t, bool); };