From ddcb973d8eb229f615e0ba2f5c3f58edad476e79 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 16 Jan 2016 10:02:32 -0500 Subject: [PATCH] gui/model: Begin new custom tree model for queues I'm not even going to try converting my C++ code. Let's just start fresh, and write unit tests as we build this up. Signed-off-by: Anna Schumaker --- gui/model.c | 78 ++++++++++++++++++++++++++++++++++++++++++++ include/gui/model.h | 30 +++++++++++++++++ tests/gui/.gitignore | 1 + tests/gui/Sconscript | 1 + tests/gui/model.c | 20 ++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 gui/model.c create mode 100644 include/gui/model.h create mode 100644 tests/gui/model.c diff --git a/gui/model.c b/gui/model.c new file mode 100644 index 00000000..d0e85c7c --- /dev/null +++ b/gui/model.c @@ -0,0 +1,78 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#include + +static const GTypeInfo queue_type_info; +static const GInterfaceInfo queue_tree_model; +static GObjectClass *parent_class = NULL; + + +static void _queue_model_init(GuiQueueModel *model) +{ + model->gqm_stamp = g_random_int(); +} + +static void _queue_model_finalize(GObject *object) +{ + parent_class->finalize(object); +} + +static void _queue_model_class_init(GuiQueueModelClass *class) +{ + GObjectClass *object_class; + + parent_class = g_type_class_peek_parent(class); + object_class = (GObjectClass *)class; + + object_class->finalize = _queue_model_finalize; +} + +static void _queue_tree_model_init(GtkTreeModelIface *iface) +{ +} + + +GuiQueueModel *gui_queue_model_new() +{ + GuiQueueModel *model = g_object_new(GUI_QUEUE_MODEL_TYPE, NULL); + + g_assert(model != NULL); + return model; +} + +GType gui_queue_model_get_type() +{ + static GType queue_type = 0; + + if (queue_type == 0) { + queue_type = g_type_register_static(G_TYPE_OBJECT, + "GuiQueueModel", + &queue_type_info, + (GTypeFlags)0); + g_type_add_interface_static(queue_type, + GTK_TYPE_TREE_MODEL, + &queue_tree_model); + } + + return queue_type; +} + + +static const GTypeInfo queue_type_info = { + .class_size = sizeof(GuiQueueModelClass), + .base_init = NULL, + .base_finalize = NULL, + .class_init = (GClassInitFunc)_queue_model_class_init, + .class_finalize = NULL, + .class_data = NULL, + .instance_size = sizeof(GuiQueueModel), + .n_preallocs = 0, + .instance_init = (GInstanceInitFunc)_queue_model_init, +}; + +static const GInterfaceInfo queue_tree_model = { + .interface_init = (GInterfaceInitFunc)_queue_tree_model_init, + .interface_finalize = NULL, + .interface_data = NULL, +}; diff --git a/include/gui/model.h b/include/gui/model.h new file mode 100644 index 00000000..a3db4f16 --- /dev/null +++ b/include/gui/model.h @@ -0,0 +1,30 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#ifndef OCARINA_GUI_MODEL_H +#define OCARINA_GUI_MODEL_H +#include + +#define GUI_QUEUE_MODEL_TYPE (gui_queue_model_get_type()) + +typedef struct _gui_queue_model GuiQueueModel; +typedef struct _gui_queue_model_class GuiQueueModelClass; + +struct _gui_queue_model { + GObject gqm_parent; /* This MUST be the first member. */ + + gint gqm_stamp; /* This is used to check iter validity. */ +}; + +struct _gui_queue_model_class { + GObjectClass parent_class; +}; + + +/* Called to allocate a new GuiQueueModel */ +GuiQueueModel *gui_queue_model_new(); + +/* Called to find the GType of the GuiQueueModel */ +GType gui_queue_model_get_type(); + +#endif /* OCARINA_GUI_MODEL_H */ diff --git a/tests/gui/.gitignore b/tests/gui/.gitignore index 08e3561c..2313263b 100644 --- a/tests/gui/.gitignore +++ b/tests/gui/.gitignore @@ -1,5 +1,6 @@ builder settings +model queue window sidebar diff --git a/tests/gui/Sconscript b/tests/gui/Sconscript index de939d2b..e3c32463 100644 --- a/tests/gui/Sconscript +++ b/tests/gui/Sconscript @@ -26,6 +26,7 @@ def GuiTest(name): env.UsePackage("gmodule-export-2.0") res += [ GuiTest("builder") ] res += [ GuiTest("settings") ] +res += [ GuiTest("model") ] res += [ GuiTest("queue") ] res += [ GuiTest("window") ] res += [ GuiTest("sidebar") ] diff --git a/tests/gui/model.c b/tests/gui/model.c new file mode 100644 index 00000000..1b7c6d67 --- /dev/null +++ b/tests/gui/model.c @@ -0,0 +1,20 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#include +#include + +static void test_model() +{ + GuiQueueModel *model = gui_queue_model_new(); + + test_not_equal((void *)model, NULL); + test_equal(GTK_IS_TREE_MODEL(model), true); + + g_object_unref(model); + test_equal(G_IS_OBJECT(model), false); +} + +DECLARE_UNIT_TESTS( + UNIT_TEST("Queue Model", test_model), +);