gui/filter: Create a new file for treeview filter code
Right now filtering is split between queue.c and view.c, which can make things somewhat complicated. I think this is a sign that we need a new file to manage filtering. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
27a1e2e12a
commit
6325779062
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#include <gui/filter.h>
|
||||||
|
#include <gui/model.h>
|
||||||
|
|
||||||
|
static GtkTreeModelFilter *filter_model = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
void gui_filter_init()
|
||||||
|
{
|
||||||
|
GtkTreeModel *model = GTK_TREE_MODEL(gui_model_get());
|
||||||
|
GtkTreeModel *filter = gtk_tree_model_filter_new(model, NULL);
|
||||||
|
filter_model = GTK_TREE_MODEL_FILTER(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_filter_deinit()
|
||||||
|
{
|
||||||
|
g_object_unref(G_OBJECT(filter_model));
|
||||||
|
}
|
||||||
|
|
||||||
|
GtkTreeModelFilter *gui_filter_get()
|
||||||
|
{
|
||||||
|
return filter_model;
|
||||||
|
}
|
|
@ -6,6 +6,7 @@
|
||||||
#include <gui/audio.h>
|
#include <gui/audio.h>
|
||||||
#include <gui/builder.h>
|
#include <gui/builder.h>
|
||||||
#include <gui/collection.h>
|
#include <gui/collection.h>
|
||||||
|
#include <gui/filter.h>
|
||||||
#include <gui/idle.h>
|
#include <gui/idle.h>
|
||||||
#include <gui/model.h>
|
#include <gui/model.h>
|
||||||
#include <gui/playlist.h>
|
#include <gui/playlist.h>
|
||||||
|
@ -103,6 +104,7 @@ static void __ocarina_startup(GApplication *application, gpointer data)
|
||||||
core_init(&startup_argc, &startup_argv, &init_data);
|
core_init(&startup_argc, &startup_argv, &init_data);
|
||||||
gui_window_init(icon);
|
gui_window_init(icon);
|
||||||
gui_model_init();
|
gui_model_init();
|
||||||
|
gui_filter_init();
|
||||||
gui_view_init();
|
gui_view_init();
|
||||||
gui_queue_init();
|
gui_queue_init();
|
||||||
gui_sidebar_init();
|
gui_sidebar_init();
|
||||||
|
@ -121,6 +123,7 @@ static void __ocarina_shutdown(GApplication *application, gpointer data)
|
||||||
gui_idle_disable();
|
gui_idle_disable();
|
||||||
core_deinit();
|
core_deinit();
|
||||||
|
|
||||||
|
gui_filter_deinit();
|
||||||
gui_model_deinit();
|
gui_model_deinit();
|
||||||
gui_window_deinit();
|
gui_window_deinit();
|
||||||
gui_builder_deinit();
|
gui_builder_deinit();
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <core/playlist.h>
|
#include <core/playlist.h>
|
||||||
#include <core/string.h>
|
#include <core/string.h>
|
||||||
#include <gui/builder.h>
|
#include <gui/builder.h>
|
||||||
|
#include <gui/filter.h>
|
||||||
#include <gui/model.h>
|
#include <gui/model.h>
|
||||||
#include <gui/queue.h>
|
#include <gui/queue.h>
|
||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
|
@ -102,7 +103,7 @@ void __queue_filter(GtkSearchEntry *entry, gpointer data)
|
||||||
gq_queue->gq_active = gtk_combo_box_get_active(combo);
|
gq_queue->gq_active = gtk_combo_box_get_active(combo);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_tree_model_filter_refilter(gui_view_get_filter());
|
gtk_tree_model_filter_refilter(gui_filter_get());
|
||||||
gui_view_scroll();
|
gui_view_scroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ void __queue_filter_how_changed(int n)
|
||||||
|
|
||||||
void gui_queue_init(void)
|
void gui_queue_init(void)
|
||||||
{
|
{
|
||||||
gtk_tree_model_filter_set_visible_func(gui_view_get_filter(),
|
gtk_tree_model_filter_set_visible_func(gui_filter_get(),
|
||||||
__queue_visible_func,
|
__queue_visible_func,
|
||||||
gui_builder_object("o_search"),
|
gui_builder_object("o_search"),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
17
gui/view.c
17
gui/view.c
|
@ -5,6 +5,7 @@
|
||||||
#include <core/playlist.h>
|
#include <core/playlist.h>
|
||||||
#include <core/settings.h>
|
#include <core/settings.h>
|
||||||
#include <gui/builder.h>
|
#include <gui/builder.h>
|
||||||
|
#include <gui/filter.h>
|
||||||
#include <gui/model.h>
|
#include <gui/model.h>
|
||||||
#include <gui/queue.h>
|
#include <gui/queue.h>
|
||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
|
@ -36,13 +37,13 @@ static const enum compare_t QUEUE_SORT[GUI_MODEL_N_COLUMNS] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static GtkTreeView *view_treeview = NULL;
|
static GtkTreeView *view_treeview = NULL;
|
||||||
static GtkTreeModelFilter *view_filter = NULL;
|
|
||||||
static unsigned int view_sort_count = 0;
|
static unsigned int view_sort_count = 0;
|
||||||
static bool view_no_scroll = false;
|
static bool view_no_scroll = false;
|
||||||
|
|
||||||
static inline GtkTreePath *__view_filter_convert_path(GtkTreePath *orig)
|
static inline GtkTreePath *__view_filter_convert_path(GtkTreePath *orig)
|
||||||
{
|
{
|
||||||
return gtk_tree_model_filter_convert_path_to_child_path(view_filter, orig);
|
return gtk_tree_model_filter_convert_path_to_child_path(
|
||||||
|
gui_filter_get(), orig);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct track *__view_filter_get_track(GtkTreePath *orig)
|
static struct track *__view_filter_get_track(GtkTreePath *orig)
|
||||||
|
@ -406,8 +407,6 @@ void gui_view_init()
|
||||||
int i, pos;
|
int i, pos;
|
||||||
|
|
||||||
view_treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
view_treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
||||||
view_filter = GTK_TREE_MODEL_FILTER(gtk_tree_model_filter_new(
|
|
||||||
GTK_TREE_MODEL(gui_model_get()), NULL));
|
|
||||||
|
|
||||||
for (i = 0; i < GUI_MODEL_N_COLUMNS; i++) {
|
for (i = 0; i < GUI_MODEL_N_COLUMNS; i++) {
|
||||||
col = gtk_tree_view_get_column(view_treeview, i);
|
col = gtk_tree_view_get_column(view_treeview, i);
|
||||||
|
@ -416,12 +415,7 @@ void gui_view_init()
|
||||||
gtk_tree_view_column_set_fixed_width(col, pos);
|
gtk_tree_view_column_set_fixed_width(col, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_tree_view_set_model(view_treeview, GTK_TREE_MODEL(view_filter));
|
gtk_tree_view_set_model(view_treeview, GTK_TREE_MODEL(gui_filter_get()));
|
||||||
}
|
|
||||||
|
|
||||||
GtkTreeModelFilter *gui_view_get_filter(void)
|
|
||||||
{
|
|
||||||
return view_filter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_view_set_playlist(struct playlist *playlist)
|
void gui_view_set_playlist(struct playlist *playlist)
|
||||||
|
@ -445,7 +439,8 @@ void gui_view_scroll()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
real = gtk_tree_path_new_from_indices(queue->q_cur.it_pos, -1);
|
real = gtk_tree_path_new_from_indices(queue->q_cur.it_pos, -1);
|
||||||
path = gtk_tree_model_filter_convert_child_path_to_path(view_filter, real);
|
path = gtk_tree_model_filter_convert_child_path_to_path(
|
||||||
|
gui_filter_get(), real);
|
||||||
if (!path)
|
if (!path)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#ifndef OCARINA_GUI_FILTER_H
|
||||||
|
#define OCARINA_GUI_FILTER_H
|
||||||
|
#include <gui/builder.h>
|
||||||
|
|
||||||
|
/* Called to initialize the filter model. */
|
||||||
|
void gui_filter_init();
|
||||||
|
|
||||||
|
/* Called to deinitialize the filter model. */
|
||||||
|
void gui_filter_deinit();
|
||||||
|
|
||||||
|
/* Called to get the filter model. */
|
||||||
|
GtkTreeModelFilter *gui_filter_get();
|
||||||
|
|
||||||
|
#endif /* OCARINA_GUI_FILTER_H */
|
|
@ -12,9 +12,6 @@ void gui_view_init();
|
||||||
/* Called to scroll the GUI treeview to the queue's current position. */
|
/* Called to scroll the GUI treeview to the queue's current position. */
|
||||||
void gui_view_scroll();
|
void gui_view_scroll();
|
||||||
|
|
||||||
/* Called to get the GtkTreeModelFilter */
|
|
||||||
GtkTreeModelFilter *gui_view_get_filter(void);
|
|
||||||
|
|
||||||
/* Called to set the currently displayed model. */
|
/* Called to set the currently displayed model. */
|
||||||
void gui_view_set_playlist(struct playlist *);
|
void gui_view_set_playlist(struct playlist *);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ builder
|
||||||
window
|
window
|
||||||
idle
|
idle
|
||||||
model
|
model
|
||||||
|
filter
|
||||||
view
|
view
|
||||||
queue
|
queue
|
||||||
sidebar
|
sidebar
|
||||||
|
|
|
@ -8,6 +8,7 @@ gui_unit_test(Builder)
|
||||||
gui_unit_test(Window)
|
gui_unit_test(Window)
|
||||||
gui_unit_test(Idle)
|
gui_unit_test(Idle)
|
||||||
gui_unit_test(Model)
|
gui_unit_test(Model)
|
||||||
|
gui_unit_test(Filter)
|
||||||
gui_unit_test(View)
|
gui_unit_test(View)
|
||||||
gui_unit_test(Queue)
|
gui_unit_test(Queue)
|
||||||
gui_unit_test(Sidebar)
|
gui_unit_test(Sidebar)
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#include <core/core.h>
|
||||||
|
#include <core/idle.h>
|
||||||
|
#include <gui/filter.h>
|
||||||
|
#include <gui/model.h>
|
||||||
|
#include <gui/window.h>
|
||||||
|
|
||||||
|
void *test_queue_init(struct queue *queue, void *data)
|
||||||
|
{ return NULL; }
|
||||||
|
void test_queue_deinit(struct queue *queue)
|
||||||
|
{ }
|
||||||
|
void test_queue_add(struct queue *queue, unsigned int n)
|
||||||
|
{ gui_model_add(queue->q_private, n); }
|
||||||
|
void test_queue_remove(struct queue *queue, unsigned int n)
|
||||||
|
{ gui_model_remove(queue->q_private, n); }
|
||||||
|
void test_queue_clear(struct queue *queue, unsigned int n)
|
||||||
|
{ gui_model_clear(queue->q_private, n); }
|
||||||
|
void test_queue_save(struct queue *queue, enum queue_flags flag) {}
|
||||||
|
void test_queue_update(struct queue *queue, unsigned int n)
|
||||||
|
{ gui_model_update(queue->q_private, n); }
|
||||||
|
|
||||||
|
struct queue_ops test_ops = {
|
||||||
|
.qop_init = test_queue_init,
|
||||||
|
.qop_deinit = test_queue_deinit,
|
||||||
|
.qop_added = test_queue_add,
|
||||||
|
.qop_removed = test_queue_remove,
|
||||||
|
.qop_cleared = test_queue_clear,
|
||||||
|
.qop_save = test_queue_save,
|
||||||
|
.qop_updated = test_queue_update,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct core_init_data init_data = {
|
||||||
|
.playlist_ops = &test_ops,
|
||||||
|
};
|
||||||
|
|
||||||
|
void test_filter()
|
||||||
|
{
|
||||||
|
GtkTreeModel *model;
|
||||||
|
GtkTreeIter iter;
|
||||||
|
|
||||||
|
g_assert_nonnull(gui_filter_get());
|
||||||
|
g_assert_true(GTK_IS_TREE_MODEL_FILTER(gui_filter_get()));
|
||||||
|
g_assert(gtk_tree_model_filter_get_model(gui_filter_get()) ==
|
||||||
|
GTK_TREE_MODEL(gui_model_get()));
|
||||||
|
|
||||||
|
model = GTK_TREE_MODEL(gui_filter_get());
|
||||||
|
playlist_get_queue(PL_SYSTEM, "Collection")->q_private =
|
||||||
|
playlist_get(PL_SYSTEM, "Collection");
|
||||||
|
|
||||||
|
g_assert_false(gtk_tree_model_get_iter_first(model, &iter));
|
||||||
|
gui_model_set_playlist(playlist_get(PL_SYSTEM, "Collection"));
|
||||||
|
g_assert_false(gtk_tree_model_get_iter_first(model, &iter));
|
||||||
|
|
||||||
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
gtk_init(&argc, NULL);
|
||||||
|
core_init(&argc, NULL, &init_data);
|
||||||
|
gui_builder_init("share/ocarina/ocarina.ui");
|
||||||
|
gui_window_init("share/ocarina/ocarina.png");
|
||||||
|
gui_model_init();
|
||||||
|
gui_filter_init();
|
||||||
|
|
||||||
|
g_test_init(&argc, &argv, NULL);
|
||||||
|
g_test_add_func("/Gui/Filter", test_filter);
|
||||||
|
ret = g_test_run();
|
||||||
|
|
||||||
|
gui_filter_deinit();
|
||||||
|
gui_model_deinit();
|
||||||
|
gui_window_deinit();
|
||||||
|
gui_builder_deinit();
|
||||||
|
core_deinit();
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
#include <core/core.h>
|
#include <core/core.h>
|
||||||
#include <core/idle.h>
|
#include <core/idle.h>
|
||||||
#include <gui/builder.h>
|
#include <gui/builder.h>
|
||||||
|
#include <gui/filter.h>
|
||||||
#include <gui/model.h>
|
#include <gui/model.h>
|
||||||
#include <gui/playlist.h>
|
#include <gui/playlist.h>
|
||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
|
@ -107,6 +108,7 @@ int main(int argc, char **argv)
|
||||||
gui_builder_init("share/ocarina/ocarina.ui");
|
gui_builder_init("share/ocarina/ocarina.ui");
|
||||||
core_init(&argc, NULL, &init_data);
|
core_init(&argc, NULL, &init_data);
|
||||||
gui_model_init();
|
gui_model_init();
|
||||||
|
gui_filter_init();
|
||||||
gui_view_init();
|
gui_view_init();
|
||||||
gui_playlist_init();
|
gui_playlist_init();
|
||||||
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||||
|
@ -117,6 +119,7 @@ int main(int argc, char **argv)
|
||||||
ret = g_test_run();
|
ret = g_test_run();
|
||||||
|
|
||||||
core_deinit();
|
core_deinit();
|
||||||
|
gui_filter_deinit();
|
||||||
gui_builder_deinit();
|
gui_builder_deinit();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <core/idle.h>
|
#include <core/idle.h>
|
||||||
#include <core/playlist.h>
|
#include <core/playlist.h>
|
||||||
#include <gui/builder.h>
|
#include <gui/builder.h>
|
||||||
|
#include <gui/filter.h>
|
||||||
#include <gui/queue.h>
|
#include <gui/queue.h>
|
||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
#include <tests/test.h>
|
#include <tests/test.h>
|
||||||
|
@ -103,7 +104,7 @@ static void test_tracks()
|
||||||
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||||
while (idle_run_task() == true) {}
|
while (idle_run_task() == true) {}
|
||||||
|
|
||||||
filter = GTK_TREE_MODEL(gui_view_get_filter());
|
filter = GTK_TREE_MODEL(gui_filter_get());
|
||||||
g_assert_nonnull(gq);
|
g_assert_nonnull(gq);
|
||||||
g_assert_nonnull(filter);
|
g_assert_nonnull(filter);
|
||||||
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 13);
|
g_assert_cmpuint(gtk_tree_model_iter_n_children(filter, NULL), ==, 13);
|
||||||
|
@ -135,6 +136,7 @@ int main(int argc, char **argv)
|
||||||
gui_builder_init("share/ocarina/ocarina.ui");
|
gui_builder_init("share/ocarina/ocarina.ui");
|
||||||
core_init(&argc, NULL, &init_data);
|
core_init(&argc, NULL, &init_data);
|
||||||
gui_model_init();
|
gui_model_init();
|
||||||
|
gui_filter_init();
|
||||||
gui_view_init();
|
gui_view_init();
|
||||||
gui_queue_init();
|
gui_queue_init();
|
||||||
while (idle_run_task()) {};
|
while (idle_run_task()) {};
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <core/playlist.h>
|
#include <core/playlist.h>
|
||||||
#include <core/settings.h>
|
#include <core/settings.h>
|
||||||
#include <gui/builder.h>
|
#include <gui/builder.h>
|
||||||
|
#include <gui/filter.h>
|
||||||
#include <gui/model.h>
|
#include <gui/model.h>
|
||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
#include <tests/test.h>
|
#include <tests/test.h>
|
||||||
|
@ -54,7 +55,7 @@ static void test_treeview()
|
||||||
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||||
while (idle_run_task() == true) {}
|
while (idle_run_task() == true) {}
|
||||||
gui_model_set_playlist(playlist_get(PL_SYSTEM, "Collection"));
|
gui_model_set_playlist(playlist_get(PL_SYSTEM, "Collection"));
|
||||||
filter = GTK_TREE_MODEL(gui_view_get_filter());
|
filter = GTK_TREE_MODEL(gui_filter_get());
|
||||||
|
|
||||||
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
|
||||||
|
|
||||||
|
@ -90,7 +91,7 @@ static void test_treeview()
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert((void *)gtk_tree_view_get_model(treeview) ==
|
g_assert((void *)gtk_tree_view_get_model(treeview) ==
|
||||||
(void *)gui_view_get_filter());
|
(void *)gui_filter_get());
|
||||||
|
|
||||||
gtk_tree_model_iter_nth_child(filter, &iter, NULL, 3);
|
gtk_tree_model_iter_nth_child(filter, &iter, NULL, 3);
|
||||||
path = gtk_tree_model_get_path(filter, &iter);
|
path = gtk_tree_model_get_path(filter, &iter);
|
||||||
|
|
Loading…
Reference in New Issue