ocarina: Scroll to saved song
I save the song before refreshing the library so I can scroll back to it. This way the user isn't interrupted too much... Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
362a0697c9
commit
0aa8b950a9
|
@ -66,6 +66,7 @@ class SongList : public libsaria::SourceModel
|
|||
void refilter();
|
||||
void list_selected_ids(list<sid_t> &);
|
||||
void scroll_to(sid_t);
|
||||
sid_t current_id();
|
||||
|
||||
gint right_click(guint, guint64);
|
||||
};
|
||||
|
|
|
@ -34,13 +34,17 @@ namespace ocarina
|
|||
|
||||
void library::refilter()
|
||||
{
|
||||
sid_t cur = library_list.current_id();
|
||||
library_list.refilter();
|
||||
library_list.scroll_to(cur);
|
||||
}
|
||||
|
||||
void library::refresh()
|
||||
{
|
||||
sid_t cur = library_list.current_id();
|
||||
library_list.clear();
|
||||
library_list.fill();
|
||||
library_list.scroll_to(cur);
|
||||
}
|
||||
|
||||
void library::init()
|
||||
|
|
|
@ -18,16 +18,24 @@ void songlist_selected_inode(GtkTreeView *treeview, GtkTreePath *path, sid_t &in
|
|||
gtk_tree_model_get(model, &iter, 0, &inode, -1);
|
||||
}
|
||||
|
||||
void songlist_row_activated(GtkTreeView *treeview, GtkTreePath *path,
|
||||
GtkTreeViewColumn *column, gpointer data)
|
||||
sid_t songlist_current_id(GtkTreeView *treeview, GtkTreePath *path)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
sid_t inode;
|
||||
sid_t songid;
|
||||
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(treeview);
|
||||
gtk_tree_model_get_iter(model, &iter, path);
|
||||
gtk_tree_model_get(model, &iter, 0, &inode, -1);
|
||||
println("Double click! %lu", inode);
|
||||
libsaria::play_id(inode);
|
||||
gtk_tree_model_get(model, &iter, 0, &songid, -1);
|
||||
|
||||
return songid;
|
||||
}
|
||||
|
||||
void songlist_row_activated(GtkTreeView *treeview, GtkTreePath *path,
|
||||
GtkTreeViewColumn *column, gpointer data)
|
||||
{
|
||||
sid_t songid = songlist_current_id(treeview, path);
|
||||
println("Double click! %lu", songid);
|
||||
libsaria::play_id(songid);
|
||||
}
|
||||
|
||||
static void selected_foreach_func(GtkTreeModel *model, GtkTreePath *path,
|
||||
|
@ -109,6 +117,9 @@ void SongList::scroll_to(sid_t songid)
|
|||
data.songid = songid;
|
||||
data.treeview = treeview;
|
||||
|
||||
if (songid == 0)
|
||||
return;
|
||||
|
||||
gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(treeview), &data.rect);
|
||||
/* Widget not realized yet */
|
||||
if (data.rect.height == 0)
|
||||
|
@ -116,3 +127,22 @@ void SongList::scroll_to(sid_t songid)
|
|||
|
||||
gtk_tree_model_foreach(filter, scroll_to_check_row, &data);
|
||||
}
|
||||
|
||||
sid_t SongList::current_id()
|
||||
{
|
||||
sid_t songid = 0;
|
||||
GtkTreePath *path;
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
|
||||
GList *selected = gtk_tree_selection_get_selected_rows(selection, &model);
|
||||
GList *first = g_list_first(selected);
|
||||
|
||||
if (first != NULL) {
|
||||
path = (GtkTreePath *)first->data;
|
||||
songid = songlist_current_id(GTK_TREE_VIEW(treeview), path);
|
||||
}
|
||||
|
||||
g_list_foreach(selected, (GFunc)gtk_tree_path_free, NULL);
|
||||
g_list_free(selected);
|
||||
|
||||
return songid;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue