gui/model: Register the GuiModel type during gui_model_init()

This only needs to happen once, so let's do it when we initialize the
model rather than waiting for the first allocation.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-08-20 17:53:45 -04:00
parent e522475d38
commit 82da46365f
3 changed files with 25 additions and 29 deletions

View File

@ -10,8 +10,9 @@
static gboolean __gui_model_iter_nth_child(GtkTreeModel *, GtkTreeIter *,
GtkTreeIter *, gint);
static GObjectClass *parent_class = NULL;
static GuiModel *queue_model = NULL;
static GObjectClass *parent_class = NULL;
static GuiModel *queue_model = NULL;
static GType gui_model_type = 0;
static GType gui_model_columns[GUI_MODEL_N_COLUMNS] = {
[GUI_MODEL_TRACK_NR] = G_TYPE_UINT,
@ -234,6 +235,26 @@ static const GInterfaceInfo gui_tree_model = {
};
void gui_model_init(void)
{
gui_model_type = g_type_register_static(G_TYPE_OBJECT, "GuiModel",
&gui_model_type_info,
(GTypeFlags)0);
g_type_add_interface_static(gui_model_type, GTK_TYPE_TREE_MODEL,
&gui_tree_model);
queue_model = g_object_new(gui_model_type, NULL);
g_assert(queue_model != NULL);
queue_model->gm_queue = NULL;
}
void gui_model_deinit(void)
{
g_object_unref(queue_model);
gui_model_type = 0;
queue_model = NULL;
}
static void __gui_model_set_runtime(void)
{
gchar *len = NULL;
@ -245,19 +266,6 @@ static void __gui_model_set_runtime(void)
g_free(len);
}
void gui_model_init(void)
{
queue_model = g_object_new(GUI_MODEL_TYPE, NULL);
g_assert(queue_model != NULL);
queue_model->gm_queue = NULL;
}
void gui_model_deinit(void)
{
g_object_unref(queue_model);
queue_model = NULL;
}
GuiModel *gui_model_get(void)
{
return queue_model;
@ -265,18 +273,6 @@ GuiModel *gui_model_get(void)
GType gui_model_get_type()
{
static GType gui_model_type = 0;
if (gui_model_type == 0) {
gui_model_type = g_type_register_static(G_TYPE_OBJECT,
"GuiModel",
&gui_model_type_info,
(GTypeFlags)0);
g_type_add_interface_static(gui_model_type,
GTK_TYPE_TREE_MODEL,
&gui_tree_model);
}
return gui_model_type;
}

View File

@ -6,9 +6,8 @@
#include <core/queue.h>
#include <gtk/gtk.h>
#define GUI_MODEL_TYPE (gui_model_get_type())
#define GUI_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
GUI_MODEL_TYPE, GuiModel))
gui_model_get_type(), GuiModel))
enum gui_model_columns {
GUI_MODEL_TRACK_NR,

View File

@ -298,5 +298,6 @@ int main(int argc, char **argv)
g_assert_false(G_IS_OBJECT(gui_model_get()));
g_assert_null(gui_model_get_queue());
g_assert_cmpuint(gui_model_get_type(), ==, 0);
return ret;
}