From 82da46365f64451dc94d9038bf46469b232986be Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 20 Aug 2016 17:53:45 -0400 Subject: [PATCH] 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 --- gui/model.c | 50 +++++++++++++++++++++------------------------ include/gui/model.h | 3 +-- tests/gui/model.c | 1 + 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/gui/model.c b/gui/model.c index 6afdf0e7..5d4d2f05 100644 --- a/gui/model.c +++ b/gui/model.c @@ -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; } diff --git a/include/gui/model.h b/include/gui/model.h index f5690ddd..c6ea36c6 100644 --- a/include/gui/model.h +++ b/include/gui/model.h @@ -6,9 +6,8 @@ #include #include -#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, diff --git a/tests/gui/model.c b/tests/gui/model.c index 83469787..d9459e5d 100644 --- a/tests/gui/model.c +++ b/tests/gui/model.c @@ -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; }