gui/sidebar: Select the current playlist on startup

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2017-04-04 11:24:56 -04:00
parent e876f8125f
commit 83a21863b9
11 changed files with 92 additions and 7 deletions

View File

@ -15,6 +15,13 @@ static void (*update_size[PL_MAX_TYPE])(struct playlist *) = {
[PL_USER] = gui_pl_user_update,
};
static void (*select_playlist[PL_MAX_TYPE])(struct playlist *) = {
[PL_SYSTEM] = gui_pl_system_select,
[PL_ARTIST] = gui_pl_artist_select,
[PL_LIBRARY] = gui_pl_library_select,
[PL_USER] = gui_pl_user_select,
};
static inline void __gui_playlist_update_size(struct playlist *playlist)
{
update_size[playlist->pl_type](playlist);
@ -101,19 +108,16 @@ static bool __playlist_erase(struct queue *queue, struct track *track)
bool __gui_playlist_init_idle()
{
GtkTreeSelection *selection;
GtkTreeModel *filter;
GtkTreeIter iter;
struct playlist *playlist = playlist_cur();
GtkTreeModel *filter = GTK_TREE_MODEL(gui_sidebar_filter());
GtkTreeIter iter;
filter = GTK_TREE_MODEL(gui_sidebar_filter());
selection = gtk_tree_view_get_selection(gui_sidebar_treeview());
gtk_tree_model_get_iter_first(filter, &iter);
gtk_tree_selection_select_iter(selection, &iter);
do {
gui_sidebar_filter_set_expand(&iter);
} while (gtk_tree_model_iter_next(filter, &iter));
select_playlist[playlist->pl_type](playlist);
return true;
}

View File

@ -56,3 +56,15 @@ void gui_pl_artist_update(struct playlist *playlist)
if (gui_sidebar_iter_find(&child, playlist->pl_name, playlist->pl_type))
gui_sidebar_iter_update(&child);
}
void gui_pl_artist_select(struct playlist *playlist)
{
GtkTreeIter iter, child;
if (!__gui_pl_artist_header(&iter))
return;
if (!gui_sidebar_iter_down(&iter, &child))
return;
if (gui_sidebar_iter_find(&child, playlist->pl_name, playlist->pl_type))
gui_sidebar_iter_select(&child);
}

View File

@ -104,3 +104,14 @@ void gui_pl_library_update(struct playlist *playlist)
if (gui_sidebar_iter_find(&child, playlist->pl_name, playlist->pl_type))
gui_sidebar_iter_update(&child);
}
void gui_pl_library_select(struct playlist *playlist)
{
GtkTreeIter iter, child;
if (!__gui_pl_library_header(&iter))
return;
if (!gui_sidebar_iter_down(&iter, &child))
return;
if (gui_sidebar_iter_find(&child, playlist->pl_name, playlist->pl_type))
gui_sidebar_iter_select(&child);
}

View File

@ -106,6 +106,25 @@ void gui_pl_system_update(struct playlist *playlist)
gui_sidebar_iter_update(&iter);
}
void gui_pl_system_select(struct playlist *playlist)
{
GtkTreeIter iter;
if (__gui_pl_system_is_playlist(playlist)) {
if (!__gui_pl_system_find_descend_header(&iter, "Playlists"))
return;
} else if (__gui_pl_system_is_dynamic(playlist)) {
if (!__gui_pl_system_find_descend_header(&iter, "Dynamic"))
return;
} else {
if (!gui_sidebar_iter_first(&iter))
return;
}
if (gui_sidebar_iter_find(&iter, playlist->pl_name, playlist->pl_type))
gui_sidebar_iter_select(&iter);
}
void gui_pl_system_track_loaded(struct track *track)
{
gtk_toggle_button_set_active(gui_favorite_button(),

View File

@ -96,6 +96,18 @@ void gui_pl_user_update(struct playlist *playlist)
gui_sidebar_iter_update(&child);
}
void gui_pl_user_select(struct playlist *playlist)
{
GtkTreeIter iter, child;
if (!__gui_pl_user_header(&iter))
return;
if (!gui_sidebar_iter_down(&iter, &child))
return;
if (gui_sidebar_iter_find(&child, playlist->pl_name, playlist->pl_type))
gui_sidebar_iter_select(&child);
}
GList *gui_pl_user_list(void)
{
struct db_entry *user, *next;

View File

@ -305,6 +305,18 @@ void gui_sidebar_iter_update(GtkTreeIter *iter)
g_free(text);
}
void gui_sidebar_iter_select(GtkTreeIter *iter)
{
GtkTreeSelection *selection;
GtkTreeIter filter;
gtk_tree_model_filter_convert_child_iter_to_iter(gui_sidebar_filter(),
&filter, iter);
selection = gtk_tree_view_get_selection(gui_sidebar_treeview());
gtk_tree_selection_select_iter(selection, &filter);
}
void gui_sidebar_filter_path_select(GtkTreePath *path)
{
GtkTreeModel *model = GTK_TREE_MODEL(gui_sidebar_filter());

View File

@ -13,4 +13,7 @@ bool gui_pl_artist_add(struct playlist *);
/* Called to update an artist playlist. */
void gui_pl_artist_update(struct playlist *);
/* Called to select an artist playlist. */
void gui_pl_artist_select(struct playlist *);
#endif /* OCARINA_GUI_PLAYLISTS_ARTIST_H */

View File

@ -13,4 +13,7 @@ bool gui_pl_library_add(const gchar *);
/* Called to update a library path. */
void gui_pl_library_update(struct playlist *);
/* Called to select a library playlist. */
void gui_pl_library_select(struct playlist *);
#endif /* OCARINA_GUI_PLAYLISTS_LIBRARY_H */

View File

@ -11,6 +11,9 @@ void gui_pl_system_init();
/* Called to update a system playlist. */
void gui_pl_system_update(struct playlist *);
/* Called to select a system playlist. */
void gui_pl_system_select(struct playlist *);
/* Called to set favorites and hidden button states. */
void gui_pl_system_track_loaded(struct track *);

View File

@ -16,6 +16,9 @@ struct playlist *gui_pl_user_add_dialog(void);
/* Called to update a user playlist. */
void gui_pl_user_update(struct playlist *);
/* Called to select a user playlist. */
void gui_pl_user_select(struct playlist *);
/*
* Called to get a (sorted) list of user playlists.
* Note: The caller is responsible for freeing the list with g_list_free().

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 select the row at the current iterator. */
void gui_sidebar_iter_select(GtkTreeIter *);
/* Called to set the playlist at the given iterator as the default. */
void gui_sidebar_filter_path_select(GtkTreePath *);