gui/sidebar: Add a function for selecting the default playlist

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-08-31 16:55:19 -04:00
parent 1291a0d139
commit df2236db9f
4 changed files with 35 additions and 30 deletions

View File

@ -15,38 +15,11 @@ static bool p_init_done = false;
static void __playlist_update_sizes(struct queue *);
static inline void __playlist_filter_get_iter(GtkTreeIter *iter, GtkTreeIter *child)
{
gtk_tree_model_filter_convert_iter_to_child_iter(gui_sidebar_filter(),
child, iter);
}
void __playlist_row_activated(GtkTreeView *treeview, GtkTreePath *path,
GtkTreeViewColumn *col, gpointer data)
{
enum playlist_type_t type;
GtkTreeIter iter, child;
GtkTreeModel *model;
struct queue *queue;
unsigned int id;
gchar *name;
type = settings_get("core.playlist.cur.type");
id = settings_get("core.playlist.cur.id");
model = GTK_TREE_MODEL(gui_sidebar_filter());
gtk_tree_model_get_iter(model, &iter, path);
__playlist_filter_get_iter(&iter, &child);
name = gui_sidebar_iter_name(&child);
playlist_select(gui_sidebar_iter_type(&child), name);
gui_sidebar_iter_update(&child);
g_free(name);
name = playlist_get_name(type, id);
queue = playlist_get_queue(type, name);
__playlist_update_sizes(queue);
g_free(name);
gui_sidebar_filter_path_select(path);
__playlist_update_sizes(&playlist_cur()->pl_queue);
}
static bool __playlist_queue_set_size(struct queue *queue, GtkTreeIter *iter)

View File

@ -297,6 +297,26 @@ void gui_sidebar_iter_update(GtkTreeIter *iter)
g_free(text);
}
void gui_sidebar_filter_path_select(GtkTreePath *path)
{
GtkTreeModel *model = GTK_TREE_MODEL(gui_sidebar_filter());
enum playlist_type_t type;
GtkTreeIter iter, child;
gchar *name;
gtk_tree_model_get_iter(model, &iter, path);
__gui_sidebar_filter_iter_convert(&iter, &child);
type = gui_sidebar_iter_type(&child);
if (type >= PL_MAX_TYPE)
return;
name = gui_sidebar_iter_name(&child);
if (playlist_select(type, name))
gui_sidebar_iter_update(&child);
g_free(name);
}
gboolean gui_sidebar_iter_find(GtkTreeIter *iter, const gchar *name,
enum playlist_type_t type)
{

View File

@ -41,6 +41,9 @@ void gui_sidebar_iter_append_child(GtkTreeIter *, struct playlist *,
/* Called to update the playlist at the current iterator. */
void gui_sidebar_iter_update(GtkTreeIter *);
/* Called to set the playlist at the given iterator as the default. */
void gui_sidebar_filter_path_select(GtkTreePath *);
/*
* Called to find a playlist with the given name and type,
* starting from the current iterator position.

View File

@ -114,10 +114,14 @@ static void test_sidebar_selection()
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 6);
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
while (idle_run_task()) {}
playlist_add(PL_SYSTEM, "History", track_get(0));
playlist_add(PL_SYSTEM, "History", track_get(0));
playlist_add(PL_SYSTEM, "Favorites", track_get(0));
gtk_tree_model_filter_refilter(gui_sidebar_filter());
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 8);
playlist_set_random(PL_SYSTEM, "Collection", true);
g_assert_true(playlist_select(PL_SYSTEM, "Favorites"));
g_assert(playlist_cur() == playlist_get(PL_SYSTEM, "Favorites"));
g_assert_true(gui_sidebar_iter_first(&iter));
path = gtk_tree_model_get_path(gui_sidebar_model(), &iter);
@ -150,7 +154,12 @@ static void test_sidebar_selection()
g_assert_false(gtk_widget_get_sensitive(
GTK_WIDGET(random)));
}
gui_sidebar_filter_path_select(path);
g_assert(playlist_cur() == playlist_get(PL_SYSTEM, "Collection"));
gtk_tree_selection_unselect_all(selection);
gui_sidebar_iter_next(&iter);
gtk_tree_path_next(path);
}
gtk_tree_path_free(path);