gui/filter: Add a function for converting GtkTreePaths into tracks
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
6325779062
commit
f550d45811
14
gui/filter.c
14
gui/filter.c
|
@ -7,6 +7,12 @@
|
||||||
static GtkTreeModelFilter *filter_model = NULL;
|
static GtkTreeModelFilter *filter_model = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
static inline GtkTreePath *__gui_filter_convert_path(GtkTreePath *path)
|
||||||
|
{
|
||||||
|
return gtk_tree_model_filter_convert_path_to_child_path(filter_model,
|
||||||
|
path);
|
||||||
|
}
|
||||||
|
|
||||||
void gui_filter_init()
|
void gui_filter_init()
|
||||||
{
|
{
|
||||||
GtkTreeModel *model = GTK_TREE_MODEL(gui_model_get());
|
GtkTreeModel *model = GTK_TREE_MODEL(gui_model_get());
|
||||||
|
@ -23,3 +29,11 @@ GtkTreeModelFilter *gui_filter_get()
|
||||||
{
|
{
|
||||||
return filter_model;
|
return filter_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct track *gui_filter_path_get_track(GtkTreePath *path)
|
||||||
|
{
|
||||||
|
GtkTreePath *real = __gui_filter_convert_path(path);
|
||||||
|
struct track *track = real ? gui_model_path_get_track(real) : NULL;
|
||||||
|
gtk_tree_path_free(real);
|
||||||
|
return track;
|
||||||
|
}
|
||||||
|
|
15
gui/view.c
15
gui/view.c
|
@ -46,15 +46,6 @@ static inline GtkTreePath *__view_filter_convert_path(GtkTreePath *orig)
|
||||||
gui_filter_get(), orig);
|
gui_filter_get(), orig);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct track *__view_filter_get_track(GtkTreePath *orig)
|
|
||||||
{
|
|
||||||
GtkTreePath *real = __view_filter_convert_path(orig);
|
|
||||||
struct track *track = gui_model_path_get_track(real);
|
|
||||||
|
|
||||||
gtk_tree_path_free(real);
|
|
||||||
return track;
|
|
||||||
}
|
|
||||||
|
|
||||||
static unsigned int __view_filter_get_index(GtkTreePath *orig)
|
static unsigned int __view_filter_get_index(GtkTreePath *orig)
|
||||||
{
|
{
|
||||||
GtkTreePath *real = __view_filter_convert_path(orig);
|
GtkTreePath *real = __view_filter_convert_path(orig);
|
||||||
|
@ -135,7 +126,7 @@ void __view_row_activated(GtkTreeView *treeview, GtkTreePath *path,
|
||||||
GtkTreeViewColumn *col, gpointer data)
|
GtkTreeViewColumn *col, gpointer data)
|
||||||
{
|
{
|
||||||
view_no_scroll = true;
|
view_no_scroll = true;
|
||||||
audio_load(__view_filter_get_track(path));
|
audio_load(gui_filter_path_get_track(path));
|
||||||
queue_selected(&gui_model_get_playlist()->pl_queue,
|
queue_selected(&gui_model_get_playlist()->pl_queue,
|
||||||
gtk_tree_path_get_indices(path)[0]);
|
gtk_tree_path_get_indices(path)[0]);
|
||||||
view_no_scroll = false;
|
view_no_scroll = false;
|
||||||
|
@ -187,7 +178,7 @@ static void __view_add_to_playlist(GtkTreeModel *model, GtkTreePath *path,
|
||||||
GtkTreeIter *iter, gpointer data)
|
GtkTreeIter *iter, gpointer data)
|
||||||
{
|
{
|
||||||
struct view_add_data *vad = (struct view_add_data *)data;
|
struct view_add_data *vad = (struct view_add_data *)data;
|
||||||
playlist_add(vad->vad_type, vad->vad_name, __view_filter_get_track(path));
|
playlist_add(vad->vad_type, vad->vad_name, gui_filter_path_get_track(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __view_delete_selection(GtkTreeSelection *selection)
|
static void __view_delete_selection(GtkTreeSelection *selection)
|
||||||
|
@ -303,7 +294,7 @@ void __view_rc_add_hidden(GtkMenuItem *item, gpointer data)
|
||||||
GList *cur = g_list_reverse(rows);
|
GList *cur = g_list_reverse(rows);
|
||||||
|
|
||||||
while (cur) {
|
while (cur) {
|
||||||
playlist_add(PL_SYSTEM, "Hidden", __view_filter_get_track(cur->data));
|
playlist_add(PL_SYSTEM, "Hidden", gui_filter_path_get_track(cur->data));
|
||||||
cur = g_list_next(cur);
|
cur = g_list_next(cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,4 +14,7 @@ void gui_filter_deinit();
|
||||||
/* Called to get the filter model. */
|
/* Called to get the filter model. */
|
||||||
GtkTreeModelFilter *gui_filter_get();
|
GtkTreeModelFilter *gui_filter_get();
|
||||||
|
|
||||||
|
/* Called to convert a filter model path into a track. */
|
||||||
|
struct track *gui_filter_path_get_track(GtkTreePath *);
|
||||||
|
|
||||||
#endif /* OCARINA_GUI_FILTER_H */
|
#endif /* OCARINA_GUI_FILTER_H */
|
||||||
|
|
|
@ -37,8 +37,11 @@ struct core_init_data init_data = {
|
||||||
|
|
||||||
void test_filter()
|
void test_filter()
|
||||||
{
|
{
|
||||||
|
struct track *track;
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
|
GtkTreePath *path;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
g_assert_nonnull(gui_filter_get());
|
g_assert_nonnull(gui_filter_get());
|
||||||
g_assert_true(GTK_IS_TREE_MODEL_FILTER(gui_filter_get()));
|
g_assert_true(GTK_IS_TREE_MODEL_FILTER(gui_filter_get()));
|
||||||
|
@ -55,8 +58,18 @@ void test_filter()
|
||||||
|
|
||||||
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||||
while (idle_run_task()) {};
|
while (idle_run_task()) {};
|
||||||
g_assert_true(gtk_tree_model_get_iter_first(model, &iter));
|
|
||||||
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 13);
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(model, NULL), ==, 13);
|
||||||
|
|
||||||
|
g_assert_true(gtk_tree_model_get_iter_first(model, &iter));
|
||||||
|
path = gtk_tree_model_get_path(model, &iter);
|
||||||
|
for (i = 1; i <= 13; i++) {
|
||||||
|
track = gui_filter_path_get_track(path);
|
||||||
|
g_assert_nonnull(track);
|
||||||
|
g_assert_cmpuint(track->tr_track, ==, i);
|
||||||
|
gtk_tree_path_next(path);
|
||||||
|
}
|
||||||
|
g_assert_null(gui_filter_path_get_track(path));
|
||||||
|
gtk_tree_path_free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
|
Loading…
Reference in New Issue