diff --git a/gui/playlist.c b/gui/playlist.c index b9b75f8d..ad457b3b 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -10,12 +10,6 @@ #include #include -enum playlist_sidebar_columns { - P_SB_IMAGE, - P_SB_NAME, - P_SB_TYPE, -}; - static bool p_filter_enable = true; static bool p_init_done = false; @@ -27,22 +21,6 @@ static inline void __playlist_filter_get_iter(GtkTreeIter *iter, GtkTreeIter *ch child, iter); } -static void __playlist_set_size(GtkTreeIter *iter, const gchar *name) -{ - enum playlist_type_t type = gui_sidebar_iter_type(iter); - unsigned int size = playlist_size(type, name); - const gchar *fmt = "%s\n%d track%s"; - gchar *text; - - if (playlist_cur() == playlist_get(type, name)) - fmt = "%s\n%d track%s"; - - text = g_markup_printf_escaped(fmt, name, size, (size == 1) ? "" : "s"); - gtk_tree_store_set(gui_sidebar_store(), iter, P_SB_NAME, text, -1); - - g_free(text); -} - void __playlist_row_activated(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { @@ -62,7 +40,7 @@ void __playlist_row_activated(GtkTreeView *treeview, GtkTreePath *path, name = gui_sidebar_iter_name(&child); playlist_select(gui_sidebar_iter_type(&child), name); - __playlist_set_size(&child, name); + gui_sidebar_iter_update(&child); g_free(name); name = playlist_get_name(type, id); @@ -80,7 +58,7 @@ static bool __playlist_queue_set_size(struct queue *queue, GtkTreeIter *iter) if (match) match = string_match(name, gq->gq_text); if (match) - __playlist_set_size(iter, name); + gui_sidebar_iter_update(iter); g_free(name); return match; diff --git a/gui/sidebar.c b/gui/sidebar.c index 9a638500..a8f3caf5 100644 --- a/gui/sidebar.c +++ b/gui/sidebar.c @@ -281,6 +281,22 @@ void gui_sidebar_iter_append_child(GtkTreeIter *iter, struct playlist *playlist, __gui_sidebar_set_playlist(&new, playlist, image); } +void gui_sidebar_iter_update(GtkTreeIter *iter) +{ + enum playlist_type_t type = gui_sidebar_iter_type(iter); + gchar *name, *text; + + if (type >= PL_MAX_TYPE) + return; + + name = gui_sidebar_iter_name(iter); + text = __gui_sidebar_size_str(playlist_get(type, name)); + gtk_tree_store_set(gui_sidebar_store(), iter, SB_NAME, text, -1); + + g_free(name); + g_free(text); +} + gboolean gui_sidebar_iter_find(GtkTreeIter *iter, const gchar *name, enum playlist_type_t type) { diff --git a/include/gui/sidebar.h b/include/gui/sidebar.h index fc230508..4eeae4c3 100644 --- a/include/gui/sidebar.h +++ b/include/gui/sidebar.h @@ -38,6 +38,9 @@ void gui_sidebar_iter_sort_child(GtkTreeIter *, struct playlist *, void gui_sidebar_iter_append_child(GtkTreeIter *, struct playlist *, const gchar *); +/* Called to update the playlist at the current iterator. */ +void gui_sidebar_iter_update(GtkTreeIter *); + /* * Called to find a playlist with the given name and type, * starting from the current iterator position.