[gnome-flashback] input-sources: make GfInputSource derivable



commit f023945151388088af8f19fbb185ceab7d5f1866
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Thu Jan 2 02:25:38 2020 +0200

    input-sources: make GfInputSource derivable

 gnome-flashback/libinput-sources/gf-input-source.c | 143 ++++++++++++++-------
 gnome-flashback/libinput-sources/gf-input-source.h |  14 +-
 2 files changed, 111 insertions(+), 46 deletions(-)
---
diff --git a/gnome-flashback/libinput-sources/gf-input-source.c 
b/gnome-flashback/libinput-sources/gf-input-source.c
index 0e34c4e..c3d6de3 100644
--- a/gnome-flashback/libinput-sources/gf-input-source.c
+++ b/gnome-flashback/libinput-sources/gf-input-source.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015 Sebastian Geiger
+ * Copyright (C) 2019 Alberts Muktupāvels
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,16 +17,14 @@
  */
 
 #include "config.h"
+#include "gf-input-source.h"
 
 #include <string.h>
 
 #include "gf-ibus-manager.h"
-#include "gf-input-source.h"
 
-struct _GfInputSource
+typedef struct
 {
-  GObject        parent;
-
   GfIBusManager *ibus_manager;
 
   gchar         *type;
@@ -39,7 +38,7 @@ struct _GfInputSource
   IBusPropList  *prop_list;
 
   char          *icon_file;
-};
+} GfInputSourcePrivate;
 
 enum
 {
@@ -68,20 +67,22 @@ enum
 
 static GParamSpec *properties[LAST_PROP] = { NULL };
 
-G_DEFINE_TYPE (GfInputSource, gf_input_source, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GfInputSource, gf_input_source, G_TYPE_OBJECT)
 
 static gchar *
 get_xkb_id (GfInputSource *source)
 {
+  GfInputSourcePrivate *priv;
   IBusEngineDesc *engine_desc;
   const gchar *layout_variant;
   const gchar *layout;
 
-  engine_desc = gf_ibus_manager_get_engine_desc (source->ibus_manager,
-                                                 source->id);
+  priv = gf_input_source_get_instance_private (source);
+
+  engine_desc = gf_ibus_manager_get_engine_desc (priv->ibus_manager, priv->id);
 
   if (!engine_desc)
-    return g_strdup (source->id);
+    return g_strdup (priv->id);
 
   layout = ibus_engine_desc_get_layout (engine_desc);
   layout_variant = ibus_engine_desc_get_layout_variant (engine_desc);
@@ -99,33 +100,35 @@ gf_input_source_get_property (GObject    *object,
                               GParamSpec *pspec)
 {
   GfInputSource *source;
+  GfInputSourcePrivate *priv;
 
   source = GF_INPUT_SOURCE (object);
+  priv = gf_input_source_get_instance_private (source);
 
   switch (prop_id)
     {
       case PROP_IBUS_MANAGER:
-        g_value_set_object (value, source->ibus_manager);
+        g_value_set_object (value, priv->ibus_manager);
         break;
 
       case PROP_TYPE:
-        g_value_set_string (value, source->type);
+        g_value_set_string (value, priv->type);
         break;
 
       case PROP_ID:
-        g_value_set_string (value, source->id);
+        g_value_set_string (value, priv->id);
         break;
 
       case PROP_DISPLAY_NAME:
-        g_value_set_string (value, source->display_name);
+        g_value_set_string (value, priv->display_name);
         break;
 
       case PROP_SHORT_NAME:
-        g_value_set_string (value, source->short_name);
+        g_value_set_string (value, priv->short_name);
         break;
 
       case PROP_INDEX:
-        g_value_set_uint (value, source->index);
+        g_value_set_uint (value, priv->index);
         break;
 
       default:
@@ -141,33 +144,35 @@ gf_input_source_set_property (GObject      *object,
                               GParamSpec   *pspec)
 {
   GfInputSource *source;
+  GfInputSourcePrivate *priv;
 
   source = GF_INPUT_SOURCE (object);
+  priv = gf_input_source_get_instance_private (source);
 
   switch (prop_id)
     {
       case PROP_IBUS_MANAGER:
-        source->ibus_manager = g_value_get_object (value);
+        priv->ibus_manager = g_value_get_object (value);
         break;
 
       case PROP_TYPE:
-        source->type = g_value_dup_string (value);
+        priv->type = g_value_dup_string (value);
         break;
 
       case PROP_ID:
-        source->id = g_value_dup_string (value);
+        priv->id = g_value_dup_string (value);
         break;
 
       case PROP_DISPLAY_NAME:
-        source->display_name = g_value_dup_string (value);
+        priv->display_name = g_value_dup_string (value);
         break;
 
       case PROP_SHORT_NAME:
-        source->short_name = g_value_dup_string (value);
+        priv->short_name = g_value_dup_string (value);
         break;
 
       case PROP_INDEX:
-        source->index = g_value_get_uint (value);
+        priv->index = g_value_get_uint (value);
         break;
 
       default:
@@ -180,10 +185,12 @@ static void
 gf_input_source_dispose (GObject *object)
 {
   GfInputSource *source;
+  GfInputSourcePrivate *priv;
 
   source = GF_INPUT_SOURCE (object);
+  priv = gf_input_source_get_instance_private (source);
 
-  g_clear_object (&source->prop_list);
+  g_clear_object (&priv->prop_list);
 
   G_OBJECT_CLASS (gf_input_source_parent_class)->dispose (object);
 }
@@ -192,15 +199,17 @@ static void
 gf_input_source_finalize (GObject *object)
 {
   GfInputSource *source;
+  GfInputSourcePrivate *priv;
 
   source = GF_INPUT_SOURCE (object);
+  priv = gf_input_source_get_instance_private (source);
 
-  g_free (source->type);
-  g_free (source->id);
-  g_free (source->display_name);
-  g_free (source->short_name);
-  g_free (source->xkb_id);
-  g_free (source->icon_file);
+  g_free (priv->type);
+  g_free (priv->id);
+  g_free (priv->display_name);
+  g_free (priv->short_name);
+  g_free (priv->xkb_id);
+  g_free (priv->icon_file);
 
   G_OBJECT_CLASS (gf_input_source_parent_class)->finalize (object);
 }
@@ -209,12 +218,14 @@ static void
 gf_input_source_constructed (GObject *object)
 {
   GfInputSource *source;
+  GfInputSourcePrivate *priv;
 
   source = GF_INPUT_SOURCE (object);
+  priv = gf_input_source_get_instance_private (source);
 
   G_OBJECT_CLASS (gf_input_source_parent_class)->constructed (object);
 
-  source->xkb_id = get_xkb_id (source);
+  priv->xkb_id = get_xkb_id (source);
 }
 
 static void
@@ -303,36 +314,56 @@ gf_input_source_new (GfIBusManager *ibus_manager,
 const gchar *
 gf_input_source_get_source_type (GfInputSource *source)
 {
-  return source->type;
+  GfInputSourcePrivate *priv;
+
+  priv = gf_input_source_get_instance_private (source);
+
+  return priv->type;
 }
 
 const gchar *
 gf_input_source_get_id (GfInputSource *source)
 {
-  return source->id;
+  GfInputSourcePrivate *priv;
+
+  priv = gf_input_source_get_instance_private (source);
+
+  return priv->id;
 }
 
 const gchar *
 gf_input_source_get_display_name (GfInputSource *source)
 {
-  return source->display_name;
+  GfInputSourcePrivate *priv;
+
+  priv = gf_input_source_get_instance_private (source);
+
+  return priv->display_name;
 }
 
 const gchar *
 gf_input_source_get_short_name (GfInputSource *source)
 {
-  return source->short_name;
+  GfInputSourcePrivate *priv;
+
+  priv = gf_input_source_get_instance_private (source);
+
+  return priv->short_name;
 }
 
 void
 gf_input_source_set_short_name  (GfInputSource *source,
                                  const gchar   *short_name)
 {
-  if (g_strcmp0 (source->short_name, short_name) == 0)
+  GfInputSourcePrivate *priv;
+
+  priv = gf_input_source_get_instance_private (source);
+
+  if (g_strcmp0 (priv->short_name, short_name) == 0)
     return;
 
-  g_free (source->short_name);
-  source->short_name = g_strdup (short_name);
+  g_free (priv->short_name);
+  priv->short_name = g_strdup (short_name);
 
   g_signal_emit (source, signals[SIGNAL_CHANGED], 0);
 }
@@ -340,13 +371,21 @@ gf_input_source_set_short_name  (GfInputSource *source,
 guint
 gf_input_source_get_index (GfInputSource *source)
 {
-  return source->index;
+  GfInputSourcePrivate *priv;
+
+  priv = gf_input_source_get_instance_private (source);
+
+  return priv->index;
 }
 
 const gchar *
 gf_input_source_get_xkb_id (GfInputSource *source)
 {
-  return source->xkb_id;
+  GfInputSourcePrivate *priv;
+
+  priv = gf_input_source_get_instance_private (source);
+
+  return priv->xkb_id;
 }
 
 void
@@ -359,29 +398,45 @@ gf_input_source_activate (GfInputSource *source,
 IBusPropList *
 gf_input_source_get_properties (GfInputSource *source)
 {
-  return source->prop_list;
+  GfInputSourcePrivate *priv;
+
+  priv = gf_input_source_get_instance_private (source);
+
+  return priv->prop_list;
 }
 
 void
 gf_input_source_set_properties (GfInputSource *source,
                                 IBusPropList  *prop_list)
 {
-  g_clear_object (&source->prop_list);
+  GfInputSourcePrivate *priv;
+
+  priv = gf_input_source_get_instance_private (source);
+
+  g_clear_object (&priv->prop_list);
 
   if (prop_list != NULL)
-    source->prop_list = g_object_ref (prop_list);
+    priv->prop_list = g_object_ref (prop_list);
 }
 
 const char *
 gf_input_source_get_icon_file (GfInputSource *self)
 {
-  return self->icon_file;
+  GfInputSourcePrivate *priv;
+
+  priv = gf_input_source_get_instance_private (self);
+
+  return priv->icon_file;
 }
 
 void
 gf_input_source_set_icon_file (GfInputSource *self,
                                const char    *icon_file)
 {
-  g_clear_pointer (&self->icon_file, g_free);
-  self->icon_file = g_strdup (icon_file);
+  GfInputSourcePrivate *priv;
+
+  priv = gf_input_source_get_instance_private (self);
+
+  g_clear_pointer (&priv->icon_file, g_free);
+  priv->icon_file = g_strdup (icon_file);
 }
diff --git a/gnome-flashback/libinput-sources/gf-input-source.h 
b/gnome-flashback/libinput-sources/gf-input-source.h
index fe0a166..75ac12f 100644
--- a/gnome-flashback/libinput-sources/gf-input-source.h
+++ b/gnome-flashback/libinput-sources/gf-input-source.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015 Sebastian Geiger
+ * Copyright (C) 2019 Alberts Muktupāvels
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -23,9 +24,16 @@
 
 #include "gf-ibus-manager.h"
 
+G_BEGIN_DECLS
+
 #define GF_TYPE_INPUT_SOURCE gf_input_source_get_type ()
-G_DECLARE_FINAL_TYPE (GfInputSource, gf_input_source,
-                      GF, INPUT_SOURCE, GObject)
+G_DECLARE_DERIVABLE_TYPE (GfInputSource, gf_input_source,
+                          GF, INPUT_SOURCE, GObject)
+
+struct _GfInputSourceClass
+{
+  GObjectClass parent_class;
+};
 
 GfInputSource *gf_input_source_new              (GfIBusManager *ibus_manager,
                                                  const gchar   *type,
@@ -62,4 +70,6 @@ const char    *gf_input_source_get_icon_file    (GfInputSource *self);
 void           gf_input_source_set_icon_file    (GfInputSource *self,
                                                  const char    *icon_file);
 
+G_END_DECLS
+
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]