ocarina: Scroll to current song
Only on non-draining playlists when that playlist selects a song. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
acef058afa
commit
319d68e8d2
|
@ -31,6 +31,8 @@ namespace ocarina
|
|||
void set_playlist(libsaria::Playlist *);
|
||||
void prepare_for_removal();
|
||||
|
||||
void goto_index(unsigned int);
|
||||
|
||||
void insert_prepare();
|
||||
void insert(libsaria::Track *, unsigned int);
|
||||
void insert_done();
|
||||
|
|
|
@ -55,6 +55,35 @@ namespace ocarina
|
|||
body::switch_to_page(box);
|
||||
}
|
||||
|
||||
void Playlist::goto_index(unsigned int index)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreePath *path;
|
||||
GtkTreeViewColumn *col;
|
||||
GdkRectangle area;
|
||||
unsigned int height, n;
|
||||
|
||||
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore), &iter);
|
||||
path = gtk_tree_model_get_path(GTK_TREE_MODEL(liststore), &iter);
|
||||
col = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0);
|
||||
|
||||
gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(treeview), &area);
|
||||
height = area.height;
|
||||
gtk_tree_view_get_cell_area(GTK_TREE_VIEW(treeview), path, col, &area);
|
||||
n = height / area.height;
|
||||
n = index - (n / 2);
|
||||
|
||||
for (unsigned int i = 0; i < n; i++)
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview), path, NULL, TRUE, 0, 0);
|
||||
|
||||
for (unsigned int i = 0; i < (index - n); i++)
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_view_set_cursor_on_cell(GTK_TREE_VIEW(treeview), path, NULL, NULL, FALSE);
|
||||
|
||||
gtk_tree_path_free(path);
|
||||
}
|
||||
|
||||
void Playlist::set_playlist(libsaria::Playlist *p)
|
||||
{
|
||||
libsaria::PlaylistRenderer::set_playlist(p);
|
||||
|
|
Loading…
Reference in New Issue