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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-01-16 10:02:32 -05:00
parent a313160f94
commit ddcb973d8e
5 changed files with 130 additions and 0 deletions

78
gui/model.c Normal file
View File

@ -0,0 +1,78 @@
/*
* Copyright 2016 (c) Anna Schumaker.
*/
#include <gui/model.h>
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,
};

30
include/gui/model.h Normal file
View File

@ -0,0 +1,30 @@
/*
* Copyright 2016 (c) Anna Schumaker.
*/
#ifndef OCARINA_GUI_MODEL_H
#define OCARINA_GUI_MODEL_H
#include <gtk/gtk.h>
#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 */

View File

@ -1,5 +1,6 @@
builder
settings
model
queue
window
sidebar

View File

@ -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") ]

20
tests/gui/model.c Normal file
View File

@ -0,0 +1,20 @@
/*
* Copyright 2016 (c) Anna Schumaker.
*/
#include <gui/model.h>
#include <tests/test.h>
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),
);