[seahorse/wip/nielsdg/g-declare-server-source: 1/3] ServerSource: use G_DECLARE_DERIVABLE_TYPE



commit a4a5e12848bd2196c8e8eadcb2fd3e40473bd625
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Mon Jan 28 16:26:35 2019 +0100

    ServerSource: use G_DECLARE_DERIVABLE_TYPE

 pgp/seahorse-server-source.c | 82 ++++++++++++++++++++------------------------
 pgp/seahorse-server-source.h | 33 ++++++------------
 2 files changed, 47 insertions(+), 68 deletions(-)
---
diff --git a/pgp/seahorse-server-source.c b/pgp/seahorse-server-source.c
index 0d19920d..bbdc3040 100644
--- a/pgp/seahorse-server-source.c
+++ b/pgp/seahorse-server-source.c
@@ -55,17 +55,18 @@ enum {
 /* -----------------------------------------------------------------------------
  *  SERVER SOURCE
  */
- 
-struct _SeahorseServerSourcePrivate {
+
+typedef struct _SeahorseServerSourcePrivate {
     gchar *server;
     gchar *uri;
-};
+} SeahorseServerSourcePrivate;
 
 static void      seahorse_server_source_collection_init    (GcrCollectionIface *iface);
 
 static void      seahorse_server_source_place_iface        (SeahorsePlaceIface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (SeahorseServerSource, seahorse_server_source, G_TYPE_OBJECT,
+                         G_ADD_PRIVATE (SeahorseServerSource)
                          G_IMPLEMENT_INTERFACE (GCR_TYPE_COLLECTION, seahorse_server_source_collection_init);
                          G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_PLACE, seahorse_server_source_place_iface);
 );
@@ -77,19 +78,11 @@ static void seahorse_server_get_property      (GObject *object, guint prop_id,
 static void seahorse_server_set_property      (GObject *object, guint prop_id,
                                                const GValue *value, GParamSpec *pspec);
 
-/**
-* klass: Class to initialize
-*
-* Initialize the basic class stuff
-*
-**/
 static void
 seahorse_server_source_class_init (SeahorseServerSourceClass *klass)
 {
-    GObjectClass *gobject_class;
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
-    gobject_class = G_OBJECT_CLASS (klass);
-    
     gobject_class->finalize = seahorse_server_source_finalize;
     gobject_class->set_property = seahorse_server_set_property;
     gobject_class->get_property = seahorse_server_get_property;
@@ -116,37 +109,20 @@ seahorse_server_source_class_init (SeahorseServerSourceClass *klass)
                                  G_PARAM_READWRITE));
 }
 
-/**
-* ssrc: A #SeahorseServerSource object
-*
-* init context, private vars, set prefs, connect signals
-*
-**/
 static void
 seahorse_server_source_init (SeahorseServerSource *ssrc)
-
 {
-    /* init private vars */
-    ssrc->priv = g_new0 (SeahorseServerSourcePrivate, 1);
 }
 
-/**
-* gobject: A #SeahorseServerSource object
-*
-* free private vars
-*
-**/
 static void
 seahorse_server_source_finalize (GObject *gobject)
 {
-    SeahorseServerSource *ssrc;
-  
-    ssrc = SEAHORSE_SERVER_SOURCE (gobject);
-    g_assert (ssrc->priv);
-    
-    g_free (ssrc->priv->server);
-    g_free (ssrc->priv->uri);
-    g_free (ssrc->priv);
+    SeahorseServerSource *ssrc = SEAHORSE_SERVER_SOURCE (gobject);
+    SeahorseServerSourcePrivate *priv =
+        seahorse_server_source_get_instance_private (ssrc);
+
+    g_free (priv->server);
+    g_free (priv->uri);
  
     G_OBJECT_CLASS (seahorse_server_source_parent_class)->finalize (gobject);
 }
@@ -171,7 +147,11 @@ seahorse_server_source_load_finish (SeahorsePlace *self,
 static gchar *
 seahorse_server_source_get_label (SeahorsePlace* self)
 {
-       return g_strdup (SEAHORSE_SERVER_SOURCE (self)->priv->server);
+    SeahorseServerSource *ssrc = SEAHORSE_SERVER_SOURCE (self);
+    SeahorseServerSourcePrivate *priv =
+        seahorse_server_source_get_instance_private (ssrc);
+
+       return g_strdup (priv->server);
 }
 
 static void
@@ -182,13 +162,21 @@ seahorse_server_source_set_label (SeahorsePlace *self, const char *label)
 static gchar *
 seahorse_server_source_get_description (SeahorsePlace* self)
 {
-       return g_strdup (SEAHORSE_SERVER_SOURCE (self)->priv->uri);
+    SeahorseServerSource *ssrc = SEAHORSE_SERVER_SOURCE (self);
+    SeahorseServerSourcePrivate *priv =
+        seahorse_server_source_get_instance_private (ssrc);
+
+       return g_strdup (priv->uri);
 }
 
 static gchar *
 seahorse_server_source_get_uri (SeahorsePlace* self)
 {
-       return g_strdup (SEAHORSE_SERVER_SOURCE (self)->priv->uri);
+    SeahorseServerSource *ssrc = SEAHORSE_SERVER_SOURCE (self);
+    SeahorseServerSourcePrivate *priv =
+        seahorse_server_source_get_instance_private (ssrc);
+
+       return g_strdup (priv->uri);
 }
 
 static GIcon *
@@ -231,6 +219,8 @@ seahorse_server_set_property (GObject *object, guint prop_id,
                               const GValue *value, GParamSpec *pspec)
 {
     SeahorseServerSource *ssrc = SEAHORSE_SERVER_SOURCE (object);
+    SeahorseServerSourcePrivate *priv =
+        seahorse_server_source_get_instance_private (ssrc);
  
     switch (prop_id) {
     case PROP_LABEL:
@@ -238,14 +228,14 @@ seahorse_server_set_property (GObject *object, guint prop_id,
                                           g_value_get_boxed (value));
         break;
     case PROP_KEY_SERVER:
-        g_assert (ssrc->priv->server == NULL);
-        ssrc->priv->server = g_strdup (g_value_get_string (value));
-        g_return_if_fail (ssrc->priv->server && ssrc->priv->server[0]);
+        g_assert (priv->server == NULL);
+        priv->server = g_strdup (g_value_get_string (value));
+        g_return_if_fail (priv->server && priv->server[0]);
         break;
     case PROP_URI:
-        g_free (ssrc->priv->uri);
-        ssrc->priv->uri = g_strdup (g_value_get_string (value));
-        g_return_if_fail (ssrc->priv->uri && ssrc->priv->uri[0]);
+        g_free (priv->uri);
+        priv->uri = g_strdup (g_value_get_string (value));
+        g_return_if_fail (priv->uri && priv->uri[0]);
         break;
     default:
         break;
@@ -270,13 +260,15 @@ seahorse_server_get_property (GObject *obj,
 {
        SeahorseServerSource *self = SEAHORSE_SERVER_SOURCE (obj);
        SeahorsePlace *place = SEAHORSE_PLACE (self);
+    SeahorseServerSourcePrivate *priv =
+        seahorse_server_source_get_instance_private (self);
 
        switch (prop_id) {
        case PROP_LABEL:
                g_value_take_string (value, seahorse_server_source_get_label (place));
                break;
        case PROP_KEY_SERVER:
-               g_value_set_string (value, self->priv->server);
+               g_value_set_string (value, priv->server);
                break;
        case PROP_DESCRIPTION:
                g_value_take_string (value, seahorse_server_source_get_description (place));
diff --git a/pgp/seahorse-server-source.h b/pgp/seahorse-server-source.h
index feaf218f..bbdc4c2e 100644
--- a/pgp/seahorse-server-source.h
+++ b/pgp/seahorse-server-source.h
@@ -19,21 +19,21 @@
  */
 
 /**
- * SeahorseServerSoruce: A base class for key sources that retrieve keys
+ * SeahorseServerSource: A base class for key sources that retrieve keys
  * from remote key servers.
- * 
+ *
  * - Derived from SeahorseSource.
  * - Also includes functions for parsing keyserver URIs and mapping them
  *   to the appropriate key sources (such as SeahorseHKPSource)
- * - There's some GPGME specific stuff in here that may eventually need to be 
+ * - There's some GPGME specific stuff in here that may eventually need to be
  *   moved elsewhere.
- * 
+ *
  * Properties:
  *   key-type: (GQuark) The type of keys generated (ie: SKEY_PGP)
  *   location: (gchar*) The location of keys from this key source (ie: SEAHORSE_LOCATION_REMOTE)
  *   key-server: (gchar*) The host:port of the keyserver to search.
- *   uri: (gchar*) Only for remote key sources. The full URI of the keyserver 
- *        being used. 
+ *   uri: (gchar*) Only for remote key sources. The full URI of the keyserver
+ *        being used.
  */
 
 #pragma once
@@ -42,21 +42,10 @@
 
 #include <gcr/gcr.h>
 
-#define SEAHORSE_TYPE_SERVER_SOURCE            (seahorse_server_source_get_type ())
-#define SEAHORSE_SERVER_SOURCE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
SEAHORSE_TYPE_SERVER_SOURCE, SeahorseServerSource))
-#define SEAHORSE_SERVER_SOURCE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
SEAHORSE_TYPE_SERVER_SOURCE, SeahorseServerSourceClass))
-#define SEAHORSE_IS_SERVER_SOURCE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
SEAHORSE_TYPE_SERVER_SOURCE))
-#define SEAHORSE_IS_SERVER_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
SEAHORSE_TYPE_SERVER_SOURCE))
-#define SEAHORSE_SERVER_SOURCE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
SEAHORSE_TYPE_SERVER_SOURCE, SeahorseServerSourceClass))
-
-typedef struct _SeahorseServerSource SeahorseServerSource;
-typedef struct _SeahorseServerSourceClass SeahorseServerSourceClass;
-typedef struct _SeahorseServerSourcePrivate SeahorseServerSourcePrivate;
-
-struct _SeahorseServerSource {
-       GObject parent;
-       SeahorseServerSourcePrivate *priv;
-};
+#define SEAHORSE_TYPE_SERVER_SOURCE (seahorse_server_source_get_type ())
+G_DECLARE_DERIVABLE_TYPE (SeahorseServerSource, seahorse_server_source,
+                          SEAHORSE, SERVER_SOURCE,
+                          GObject)
 
 struct _SeahorseServerSourceClass {
        GObjectClass parent_class;
@@ -94,8 +83,6 @@ struct _SeahorseServerSourceClass {
                                                  GError **error);
 };
 
-GType                  seahorse_server_source_get_type         (void);
-
 SeahorseServerSource*  seahorse_server_source_new              (const gchar *uri);
 
 void                   seahorse_server_source_search_async     (SeahorseServerSource *self,


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