gui/idle: Split out idle queue functions
I want to use this outside of the collection, so let's move these functions into a new file. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
fc03b6cb95
commit
f01cce3b47
|
@ -2,11 +2,11 @@
|
||||||
* Copyright 2015 (c) Anna Schumaker.
|
* Copyright 2015 (c) Anna Schumaker.
|
||||||
*/
|
*/
|
||||||
#include <core/collection.h>
|
#include <core/collection.h>
|
||||||
#include <core/idle.h>
|
|
||||||
#include <core/playlist.h>
|
#include <core/playlist.h>
|
||||||
#include <core/tempq.h>
|
#include <core/tempq.h>
|
||||||
#include <gui/builder.h>
|
#include <gui/builder.h>
|
||||||
#include <gui/collection.h>
|
#include <gui/collection.h>
|
||||||
|
#include <gui/idle.h>
|
||||||
#include <gui/sidebar.h>
|
#include <gui/sidebar.h>
|
||||||
|
|
||||||
enum collection_sidebar_columns {
|
enum collection_sidebar_columns {
|
||||||
|
@ -52,7 +52,7 @@ void __collection_activated(GtkTreeView *treeview, GtkTreePath *path,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
collection_update(library);
|
collection_update(library);
|
||||||
gui_collection_idle_enable();
|
gui_idle_enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void __collection_toggled(GtkCheckMenuItem *check, gpointer data)
|
void __collection_toggled(GtkCheckMenuItem *check, gpointer data)
|
||||||
|
@ -146,7 +146,7 @@ void __collection_add(GtkButton *button, GtkFileChooser *chooser)
|
||||||
gtk_tree_store_insert_before(GTK_TREE_STORE(c_model), &iter, NULL, &last);
|
gtk_tree_store_insert_before(GTK_TREE_STORE(c_model), &iter, NULL, &last);
|
||||||
__collection_set_library(&iter, collection_add(filename));
|
__collection_set_library(&iter, collection_add(filename));
|
||||||
|
|
||||||
gui_collection_idle_enable();
|
gui_idle_enable();
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,19 +168,6 @@ void __collection_selection_changed(GtkTreeSelection *selection,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean __collection_on_idle(gpointer data)
|
|
||||||
{
|
|
||||||
GtkProgressBar *progress = GTK_PROGRESS_BAR(data);
|
|
||||||
|
|
||||||
if (idle_run_task()) {
|
|
||||||
gtk_progress_bar_set_fraction(progress, idle_progress());
|
|
||||||
return gtk_widget_is_visible(gui_builder_widget("o_window"));
|
|
||||||
} else {
|
|
||||||
gtk_widget_hide(GTK_WIDGET(progress));
|
|
||||||
return G_SOURCE_REMOVE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *__collection_init(struct queue *queue)
|
static void *__collection_init(struct queue *queue)
|
||||||
{
|
{
|
||||||
return gui_queue_alloc(queue, "Collection", GQ_CAN_RANDOM);
|
return gui_queue_alloc(queue, "Collection", GQ_CAN_RANDOM);
|
||||||
|
@ -233,15 +220,7 @@ void gui_collection_init()
|
||||||
gui_sidebar_on_select, NULL, NULL);
|
gui_sidebar_on_select, NULL, NULL);
|
||||||
|
|
||||||
gui_sidebar_set_size(gui_queue(collection_get_queue()));
|
gui_sidebar_set_size(gui_queue(collection_get_queue()));
|
||||||
gui_collection_idle_enable();
|
gui_idle_enable();
|
||||||
}
|
|
||||||
|
|
||||||
void gui_collection_idle_enable()
|
|
||||||
{
|
|
||||||
GtkWidget *progress = gui_builder_widget("o_idle_progress");
|
|
||||||
|
|
||||||
gtk_widget_show(progress);
|
|
||||||
g_idle_add(__collection_on_idle, progress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct queue_ops collection_ops = {
|
struct queue_ops collection_ops = {
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#include <core/idle.h>
|
||||||
|
#include <gui/builder.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
static gboolean __on_idle(gpointer data)
|
||||||
|
{
|
||||||
|
GtkProgressBar *progress = GTK_PROGRESS_BAR(data);
|
||||||
|
|
||||||
|
if (idle_run_task()) {
|
||||||
|
gtk_progress_bar_set_fraction(progress, idle_progress());
|
||||||
|
return gtk_widget_is_visible(gui_builder_widget("o_window"));
|
||||||
|
} else {
|
||||||
|
gtk_widget_hide(GTK_WIDGET(progress));
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_idle_enable()
|
||||||
|
{
|
||||||
|
GtkWidget *progress = gui_builder_widget("o_idle_progress");
|
||||||
|
|
||||||
|
gtk_widget_show(progress);
|
||||||
|
g_idle_add(__on_idle, progress);
|
||||||
|
}
|
|
@ -7,9 +7,6 @@
|
||||||
/* Called to initialize the GUI collection code. */
|
/* Called to initialize the GUI collection code. */
|
||||||
void gui_collection_init();
|
void gui_collection_init();
|
||||||
|
|
||||||
/* Called to enable processing idle queue tasks. */
|
|
||||||
void gui_collection_idle_enable();
|
|
||||||
|
|
||||||
/* Collection operations passed to core_init() */
|
/* Collection operations passed to core_init() */
|
||||||
extern struct queue_ops collection_ops;
|
extern struct queue_ops collection_ops;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#ifndef OCARINA_GUI_IDLE_H
|
||||||
|
#define OCARINA_GUI_IDLE_H
|
||||||
|
|
||||||
|
/* Called to enable processing idle queue tasks. */
|
||||||
|
void gui_idle_enable();
|
||||||
|
|
||||||
|
#endif /* OCARINA_GUI_IDLE_H */
|
|
@ -4,6 +4,7 @@ model
|
||||||
view
|
view
|
||||||
queue
|
queue
|
||||||
window
|
window
|
||||||
|
idle
|
||||||
sidebar
|
sidebar
|
||||||
collection
|
collection
|
||||||
playlist
|
playlist
|
||||||
|
|
|
@ -30,6 +30,7 @@ res += [ GuiTest("model") ]
|
||||||
res += [ GuiTest("view") ]
|
res += [ GuiTest("view") ]
|
||||||
res += [ GuiTest("queue") ]
|
res += [ GuiTest("queue") ]
|
||||||
res += [ GuiTest("window") ]
|
res += [ GuiTest("window") ]
|
||||||
|
res += [ GuiTest("idle") ]
|
||||||
res += [ GuiTest("sidebar") ]
|
res += [ GuiTest("sidebar") ]
|
||||||
res += [ GuiTest("collection") ]
|
res += [ GuiTest("collection") ]
|
||||||
res += [ GuiTest("playlist") ]
|
res += [ GuiTest("playlist") ]
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#define TEST_NEED_AUDIO
|
||||||
|
#define TEST_NEED_COLLECTION
|
||||||
|
#define TEST_NEED_PLAYLIST
|
||||||
|
#define TEST_NEED_SIDEBAR
|
||||||
|
#include <core/core.h>
|
||||||
|
#include <core/idle.h>
|
||||||
|
#include <gui/builder.h>
|
||||||
|
#include <gui/idle.h>
|
||||||
|
#include <tests/gui.h>
|
||||||
|
#include <tests/test.h>
|
||||||
|
|
||||||
|
static const unsigned int N = 100;
|
||||||
|
static unsigned int cur = -1;
|
||||||
|
static bool func_passed = false;
|
||||||
|
struct core_init_data init_data;
|
||||||
|
static GMainLoop *main_loop;
|
||||||
|
|
||||||
|
static void inc_cur(void *data)
|
||||||
|
{
|
||||||
|
unsigned int expected = GPOINTER_TO_INT(data);
|
||||||
|
cur++;
|
||||||
|
func_passed = (cur == expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int test_on_idle()
|
||||||
|
{
|
||||||
|
g_main_loop_quit(main_loop);
|
||||||
|
return G_SOURCE_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_idle()
|
||||||
|
{
|
||||||
|
GtkProgressBar *progress;
|
||||||
|
GtkWindow *window;
|
||||||
|
unsigned int i;
|
||||||
|
float fraction;
|
||||||
|
int argc = 0;
|
||||||
|
|
||||||
|
gtk_init(&argc, NULL);
|
||||||
|
gui_builder_init("share/ocarina/ocarina6.glade");
|
||||||
|
core_init(&argc, NULL, &init_data);
|
||||||
|
|
||||||
|
main_loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
window = GTK_WINDOW(gui_builder_widget("o_window"));
|
||||||
|
g_idle_add(test_on_idle, window);
|
||||||
|
|
||||||
|
progress = GTK_PROGRESS_BAR(gui_builder_widget("o_idle_progress"));
|
||||||
|
test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), false);
|
||||||
|
|
||||||
|
for (i = 0; i < N; i++)
|
||||||
|
idle_schedule(inc_cur, GINT_TO_POINTER(i));
|
||||||
|
|
||||||
|
gui_idle_enable();
|
||||||
|
|
||||||
|
for (i = 0; i < N; i++) {
|
||||||
|
test_loop_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), true, i);
|
||||||
|
g_main_loop_run(main_loop);
|
||||||
|
test_loop_equal(idle_progress(), ((i + 1) / (float)N), i);
|
||||||
|
test_loop_equal(func_passed, (bool)true, i);
|
||||||
|
if (i != (N - 1)) {
|
||||||
|
fraction = gtk_progress_bar_get_fraction(progress);
|
||||||
|
test_loop_equal(fraction, idle_progress(), i);
|
||||||
|
}
|
||||||
|
} test_loop_passed();
|
||||||
|
|
||||||
|
test_equal(gtk_widget_is_visible(GTK_WIDGET(progress)), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
DECLARE_UNIT_TESTS(
|
||||||
|
UNIT_TEST("Idle Progress Bar", test_idle),
|
||||||
|
);
|
Loading…
Reference in New Issue