qulogic/libgnt

Use GObject macros for GntBindable.

2019-04-03, Elliott Sales de Andrade
746987e29e4d
Parents b955bf6b3f13
Children c3de29b0a6c5
Use GObject macros for GntBindable.
  • +33 -48
    gntbindable.c
  • +3 -14
    gntbindable.h
  • --- a/gntbindable.c Wed Apr 03 19:04:31 2019 -0400
    +++ b/gntbindable.c Wed Apr 03 19:22:35 2019 -0400
    @@ -37,8 +37,6 @@
    #include "gntwindow.h"
    #include "gntlabel.h"
    -static GObjectClass *parent_class = NULL;
    -
    static struct
    {
    char * okeys; /* Old keystrokes */
    @@ -48,6 +46,18 @@
    GList * params; /* The list of paramaters */
    } rebind_info;
    +typedef struct
    +{
    + GHashTable *hash;
    + GntTree *tree;
    +} BindingView;
    +
    +G_DEFINE_TYPE(GntBindable, gnt_bindable, G_TYPE_OBJECT)
    +
    +/******************************************************************************
    + * Helpers
    + *****************************************************************************/
    +
    static void
    gnt_bindable_free_rebind_info(void)
    {
    @@ -106,6 +116,7 @@
    }
    return FALSE;
    }
    +
    static void
    gnt_bindable_rebinding_activate(GntBindable *data, gpointer bindable)
    {
    @@ -172,12 +183,6 @@
    gnt_widget_show(win);
    }
    -typedef struct
    -{
    - GHashTable *hash;
    - GntTree *tree;
    -} BindingView;
    -
    static void
    add_binding(gpointer key, gpointer value, gpointer data)
    {
    @@ -200,20 +205,6 @@
    g_hash_table_insert(bv->hash, value, key);
    }
    -static void
    -gnt_bindable_class_init(GntBindableClass *klass)
    -{
    - parent_class = g_type_class_peek_parent(klass);
    -
    - klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
    - (GDestroyNotify)gnt_bindable_action_free);
    - klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
    - (GDestroyNotify)gnt_bindable_action_param_free);
    -
    - gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
    - GNTDEBUG;
    -}
    -
    static gpointer
    bindable_clone(GntBindableAction *action)
    {
    @@ -254,34 +245,28 @@
    }
    /******************************************************************************
    + * GObject Implementation
    + *****************************************************************************/
    +
    +static void
    +gnt_bindable_init(G_GNUC_UNUSED GntBindable *bindable)
    +{
    +}
    +
    +static void
    +gnt_bindable_class_init(GntBindableClass *klass)
    +{
    + klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
    + (GDestroyNotify)gnt_bindable_action_free);
    + klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
    + (GDestroyNotify)gnt_bindable_action_param_free);
    +
    + gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
    +}
    +
    +/******************************************************************************
    * GntBindable API
    *****************************************************************************/
    -GType
    -gnt_bindable_get_type(void)
    -{
    - static GType type = 0;
    -
    - if (type == 0) {
    - static const GTypeInfo info = {
    - sizeof(GntBindableClass),
    - (GBaseInitFunc)duplicate_hashes, /* base_init */
    - NULL, /* base_finalize */
    - (GClassInitFunc)gnt_bindable_class_init,
    - NULL,
    - NULL, /* class_data */
    - sizeof(GntBindable),
    - 0, /* n_preallocs */
    - NULL, /* instance_init */
    - NULL /* value_table */
    - };
    -
    - type = g_type_register_static(G_TYPE_OBJECT,
    - "GntBindable",
    - &info, G_TYPE_FLAG_ABSTRACT);
    - }
    -
    - return type;
    -}
    /*
    * Key Remaps
    --- a/gntbindable.h Wed Apr 03 19:04:31 2019 -0400
    +++ b/gntbindable.h Wed Apr 03 19:22:35 2019 -0400
    @@ -33,22 +33,11 @@
    #include <glib.h>
    #include <glib-object.h>
    -#define GNT_TYPE_BINDABLE (gnt_bindable_get_type())
    -#define GNT_BINDABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_BINDABLE, GntBindable))
    -#define GNT_BINDABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_BINDABLE, GntBindableClass))
    -#define GNT_IS_BINDABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_BINDABLE))
    -#define GNT_IS_BINDABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_BINDABLE))
    -#define GNT_BINDABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_BINDABLE, GntBindableClass))
    +#define GNT_TYPE_BINDABLE gnt_bindable_get_type()
    #define GNTDEBUG
    -typedef struct _GntBindable GntBindable;
    -typedef struct _GntBindableClass GntBindableClass;
    -
    -struct _GntBindable
    -{
    - GObject inherit;
    -};
    +typedef struct _GntBindable GntBindable;
    struct _GntBindableClass
    {
    @@ -68,7 +57,7 @@
    G_BEGIN_DECLS
    -GType gnt_bindable_get_type(void);
    +G_DECLARE_DERIVABLE_TYPE(GntBindable, gnt_bindable, GNT, BINDABLE, GObject)
    /******************/
    /* Key Remaps */