[seahorse/wip/nielsdg/remove-more-deprecated: 5/8] pgp: Signature: Don't use g_type_class_add_private()



commit c7ca7c0a895a48e148af1346ec0117de4d2b66e9
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Tue Feb 19 06:12:58 2019 +0100

    pgp: Signature: Don't use g_type_class_add_private()
    
    It's been deprecated a while now in favor of `G_ADD_PRIVATE ()`

 pgp/seahorse-pgp-signature.c | 276 ++++++++++++++++++++++---------------------
 pgp/seahorse-pgp-signature.h |  23 +---
 2 files changed, 145 insertions(+), 154 deletions(-)
---
diff --git a/pgp/seahorse-pgp-signature.c b/pgp/seahorse-pgp-signature.c
index 97058bdc..e39f4dd8 100644
--- a/pgp/seahorse-pgp-signature.c
+++ b/pgp/seahorse-pgp-signature.c
@@ -30,174 +30,178 @@
 #include <glib/gi18n.h>
 
 enum {
-       PROP_0,
-       PROP_KEYID,
-       PROP_FLAGS,
-       PROP_SIGTYPE
+    PROP_0,
+    PROP_KEYID,
+    PROP_FLAGS,
+    PROP_SIGTYPE
 };
 
-G_DEFINE_TYPE (SeahorsePgpSignature, seahorse_pgp_signature, G_TYPE_OBJECT);
+typedef struct _SeahorsePgpSignaturePrivate {
+    guint flags;
+    gchar *keyid;
+} SeahorsePgpSignaturePrivate;
 
-struct _SeahorsePgpSignaturePrivate {
-       guint flags;
-       gchar *keyid;
-};
-
-/* -----------------------------------------------------------------------------
- * OBJECT 
- */
+G_DEFINE_TYPE_WITH_PRIVATE (SeahorsePgpSignature, seahorse_pgp_signature, G_TYPE_OBJECT);
 
-static void
-seahorse_pgp_signature_init (SeahorsePgpSignature *self)
+guint
+seahorse_pgp_signature_get_flags (SeahorsePgpSignature *self)
 {
-       self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, SEAHORSE_PGP_TYPE_SIGNATURE, 
SeahorsePgpSignaturePrivate);
-}
+    SeahorsePgpSignaturePrivate *priv
+        = seahorse_pgp_signature_get_instance_private (self);
 
-static void
-seahorse_pgp_signature_get_property (GObject *object, guint prop_id,
-                                  GValue *value, GParamSpec *pspec)
-{
-       SeahorsePgpSignature *self = SEAHORSE_PGP_SIGNATURE (object);
-       
-       switch (prop_id) {
-       case PROP_KEYID:
-               g_value_set_string (value, seahorse_pgp_signature_get_keyid (self));
-               break;
-       case PROP_FLAGS:
-               g_value_set_uint (value, seahorse_pgp_signature_get_flags (self));
-               break;
-       case PROP_SIGTYPE:
-               g_value_set_uint (value, seahorse_pgp_signature_get_sigtype (self));
-               break;
-       }
+    g_return_val_if_fail (SEAHORSE_PGP_IS_SIGNATURE (self), 0);
+    return priv->flags;
 }
 
-static void
-seahorse_pgp_signature_set_property (GObject *object, guint prop_id, const GValue *value, 
-                                  GParamSpec *pspec)
+void
+seahorse_pgp_signature_set_flags (SeahorsePgpSignature *self, guint flags)
 {
-       SeahorsePgpSignature *self = SEAHORSE_PGP_SIGNATURE (object);
-       
-       switch (prop_id) {
-       case PROP_KEYID:
-               seahorse_pgp_signature_set_keyid (self, g_value_get_string (value));
-               break;
-       case PROP_FLAGS:
-               seahorse_pgp_signature_set_flags (self, g_value_get_uint (value));
-               break;
-       }
+    SeahorsePgpSignaturePrivate *priv
+        = seahorse_pgp_signature_get_instance_private (self);
+    GObject *obj;
+
+    g_return_if_fail (SEAHORSE_PGP_IS_SIGNATURE (self));
+    priv->flags = flags;
+
+    obj = G_OBJECT (self);
+    g_object_freeze_notify (obj);
+    g_object_notify (obj, "flags");
+    g_object_notify (obj, "sigtype");
+    g_object_thaw_notify (obj);
 }
 
-static void
-seahorse_pgp_signature_finalize (GObject *gobject)
+const gchar*
+seahorse_pgp_signature_get_keyid (SeahorsePgpSignature *self)
 {
-       SeahorsePgpSignature *self = SEAHORSE_PGP_SIGNATURE (gobject);
+    SeahorsePgpSignaturePrivate *priv
+        = seahorse_pgp_signature_get_instance_private (self);
 
-       g_free (self->pv->keyid);
-       self->pv->keyid = NULL;
-    
-       G_OBJECT_CLASS (seahorse_pgp_signature_parent_class)->finalize (gobject);
+    g_return_val_if_fail (SEAHORSE_PGP_IS_SIGNATURE (self), NULL);
+    return priv->keyid;
 }
 
-static void
-seahorse_pgp_signature_class_init (SeahorsePgpSignatureClass *klass)
+void
+seahorse_pgp_signature_set_keyid (SeahorsePgpSignature *self, const gchar *keyid)
 {
-       GObjectClass *gobject_class = G_OBJECT_CLASS (klass);    
-
-       seahorse_pgp_signature_parent_class = g_type_class_peek_parent (klass);
-       g_type_class_add_private (klass, sizeof (SeahorsePgpSignaturePrivate));
-       
-       gobject_class->finalize = seahorse_pgp_signature_finalize;
-       gobject_class->set_property = seahorse_pgp_signature_set_property;
-       gobject_class->get_property = seahorse_pgp_signature_get_property;
-
-        g_object_class_install_property (gobject_class, PROP_KEYID,
-                g_param_spec_string ("keyid", "Key ID", "GPG Key ID",
-                                     "", G_PARAM_READWRITE));
-
-       g_object_class_install_property (gobject_class, PROP_FLAGS,
-               g_param_spec_uint ("flags", "Flags", "PGP signature flags",
-                                  0, G_MAXUINT, 0, G_PARAM_READWRITE));
-
-       g_object_class_install_property (gobject_class, PROP_SIGTYPE,
-               g_param_spec_uint ("sigtype", "Sig Type", "PGP signature type",
-                                  0, G_MAXUINT, 0, G_PARAM_READABLE));
+    SeahorsePgpSignaturePrivate *priv
+        = seahorse_pgp_signature_get_instance_private (self);
+    GObject *obj;
+
+    g_return_if_fail (SEAHORSE_PGP_IS_SIGNATURE (self));
+    g_free (priv->keyid);
+    priv->keyid = g_strdup (keyid);
+
+    obj = G_OBJECT (self);
+    g_object_freeze_notify (obj);
+    g_object_notify (obj, "keyid");
+    g_object_notify (obj, "sigtype");
+    g_object_thaw_notify (obj);
 }
 
-/* -----------------------------------------------------------------------------
- * PUBLIC 
- */
-
-SeahorsePgpSignature*
-seahorse_pgp_signature_new (const gchar *keyid)
-{
-       return g_object_new (SEAHORSE_PGP_TYPE_SIGNATURE, "keyid", keyid, NULL);
-}
- 
 guint
-seahorse_pgp_signature_get_flags (SeahorsePgpSignature *self)
+seahorse_pgp_signature_get_sigtype (SeahorsePgpSignature *self)
 {
-       g_return_val_if_fail (SEAHORSE_PGP_IS_SIGNATURE (self), 0);
-       return self->pv->flags;
+    SeahorsePgpSignaturePrivate *priv
+        = seahorse_pgp_signature_get_instance_private (self);
+    SeahorseGpgmeKeyring *keyring;
+    SeahorseGpgmeKey *key;
+    SeahorseObject *obj;
+
+    g_return_val_if_fail (SEAHORSE_PGP_IS_SIGNATURE (self), 0);
+
+    keyring = seahorse_pgp_backend_get_default_keyring (NULL);
+    key = seahorse_gpgme_keyring_lookup (keyring, priv->keyid);
+
+    if (key != NULL) {
+        obj = SEAHORSE_OBJECT (key);
+        if (seahorse_object_get_usage (obj) == SEAHORSE_USAGE_PRIVATE_KEY)
+            return SKEY_PGPSIG_TRUSTED | SKEY_PGPSIG_PERSONAL;
+        if (seahorse_object_get_flags (obj) & SEAHORSE_FLAG_TRUSTED)
+            return SKEY_PGPSIG_TRUSTED;
+    }
+
+    return 0;
 }
 
-void
-seahorse_pgp_signature_set_flags (SeahorsePgpSignature *self, guint flags)
+static void
+seahorse_pgp_signature_get_property (GObject *object, guint prop_id,
+                                  GValue *value, GParamSpec *pspec)
 {
-       GObject *obj;
-       
-       g_return_if_fail (SEAHORSE_PGP_IS_SIGNATURE (self));
-       self->pv->flags = flags;
-
-       obj = G_OBJECT (self);
-       g_object_freeze_notify (obj);
-       g_object_notify (obj, "flags");
-       g_object_notify (obj, "sigtype");
-       g_object_thaw_notify (obj);
+    SeahorsePgpSignature *self = SEAHORSE_PGP_SIGNATURE (object);
+
+    switch (prop_id) {
+    case PROP_KEYID:
+        g_value_set_string (value, seahorse_pgp_signature_get_keyid (self));
+        break;
+    case PROP_FLAGS:
+        g_value_set_uint (value, seahorse_pgp_signature_get_flags (self));
+        break;
+    case PROP_SIGTYPE:
+        g_value_set_uint (value, seahorse_pgp_signature_get_sigtype (self));
+        break;
+    }
 }
 
-const gchar*
-seahorse_pgp_signature_get_keyid (SeahorsePgpSignature *self)
+static void
+seahorse_pgp_signature_set_property (GObject *object, guint prop_id, const GValue *value,
+                                  GParamSpec *pspec)
 {
-       g_return_val_if_fail (SEAHORSE_PGP_IS_SIGNATURE (self), NULL);
-       return self->pv->keyid;
+    SeahorsePgpSignature *self = SEAHORSE_PGP_SIGNATURE (object);
+
+    switch (prop_id) {
+    case PROP_KEYID:
+        seahorse_pgp_signature_set_keyid (self, g_value_get_string (value));
+        break;
+    case PROP_FLAGS:
+        seahorse_pgp_signature_set_flags (self, g_value_get_uint (value));
+        break;
+    }
 }
 
-void
-seahorse_pgp_signature_set_keyid (SeahorsePgpSignature *self, const gchar *keyid)
+static void
+seahorse_pgp_signature_finalize (GObject *gobject)
 {
-       GObject *obj;
-       
-       g_return_if_fail (SEAHORSE_PGP_IS_SIGNATURE (self));
-       g_free (self->pv->keyid);
-       self->pv->keyid = g_strdup (keyid);
-       
-       obj = G_OBJECT (self);
-       g_object_freeze_notify (obj);
-       g_object_notify (obj, "keyid");
-       g_object_notify (obj, "sigtype");
-       g_object_thaw_notify (obj);
-}
+    SeahorsePgpSignature *self = SEAHORSE_PGP_SIGNATURE (gobject);
+    SeahorsePgpSignaturePrivate *priv
+        = seahorse_pgp_signature_get_instance_private (self);
 
-guint
-seahorse_pgp_signature_get_sigtype (SeahorsePgpSignature *self)
-{
-       SeahorseGpgmeKeyring *keyring;
-       SeahorseGpgmeKey *key;
-       SeahorseObject *obj;
+    g_clear_pointer (&priv->keyid, g_free);
 
-       g_return_val_if_fail (SEAHORSE_PGP_IS_SIGNATURE (self), 0);
+    G_OBJECT_CLASS (seahorse_pgp_signature_parent_class)->finalize (gobject);
+}
 
-       keyring = seahorse_pgp_backend_get_default_keyring (NULL);
-       key = seahorse_gpgme_keyring_lookup (keyring, self->pv->keyid);
+static void
+seahorse_pgp_signature_init (SeahorsePgpSignature *self)
+{
+}
 
-       if (key != NULL) {
-               obj = SEAHORSE_OBJECT (key);
-               if (seahorse_object_get_usage (obj) == SEAHORSE_USAGE_PRIVATE_KEY)
-                       return SKEY_PGPSIG_TRUSTED | SKEY_PGPSIG_PERSONAL;
-               if (seahorse_object_get_flags (obj) & SEAHORSE_FLAG_TRUSTED)
-                       return SKEY_PGPSIG_TRUSTED;
-       }
+static void
+seahorse_pgp_signature_class_init (SeahorsePgpSignatureClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+    gobject_class->finalize = seahorse_pgp_signature_finalize;
+    gobject_class->set_property = seahorse_pgp_signature_set_property;
+    gobject_class->get_property = seahorse_pgp_signature_get_property;
+
+    g_object_class_install_property (gobject_class, PROP_KEYID,
+        g_param_spec_string ("keyid", "Key ID", "GPG Key ID",
+                             "",
+                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+    g_object_class_install_property (gobject_class, PROP_FLAGS,
+        g_param_spec_uint ("flags", "Flags", "PGP signature flags",
+                           0, G_MAXUINT, 0,
+                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+    g_object_class_install_property (gobject_class, PROP_SIGTYPE,
+        g_param_spec_uint ("sigtype", "Sig Type", "PGP signature type",
+                           0, G_MAXUINT, 0,
+                           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+}
 
-       return 0;
+SeahorsePgpSignature*
+seahorse_pgp_signature_new (const gchar *keyid)
+{
+    return g_object_new (SEAHORSE_PGP_TYPE_SIGNATURE, "keyid", keyid, NULL);
 }
diff --git a/pgp/seahorse-pgp-signature.h b/pgp/seahorse-pgp-signature.h
index 50853c9c..365f1e4b 100644
--- a/pgp/seahorse-pgp-signature.h
+++ b/pgp/seahorse-pgp-signature.h
@@ -23,29 +23,16 @@
 
 #include "seahorse-common.h"
 
-#define SEAHORSE_PGP_TYPE_SIGNATURE            (seahorse_pgp_signature_get_type ())
+#define SEAHORSE_PGP_TYPE_SIGNATURE (seahorse_pgp_signature_get_type ())
+G_DECLARE_DERIVABLE_TYPE (SeahorsePgpSignature, seahorse_pgp_signature,
+                          SEAHORSE_PGP, SIGNATURE,
+                          GObject)
 
-#define SEAHORSE_PGP_SIGNATURE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
SEAHORSE_PGP_TYPE_SIGNATURE, SeahorsePgpSignature))
-#define SEAHORSE_PGP_SIGNATURE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
SEAHORSE_PGP_TYPE_SIGNATURE, SeahorsePgpSignatureClass))
-#define SEAHORSE_PGP_IS_SIGNATURE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
SEAHORSE_PGP_TYPE_SIGNATURE))
-#define SEAHORSE_PGP_IS_SIGNATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
SEAHORSE_PGP_TYPE_SIGNATURE))
-#define SEAHORSE_PGP_SIGNATURE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
SEAHORSE_PGP_TYPE_SIGNATURE, SeahorsePgpSignatureClass))
-
-typedef struct _SeahorsePgpSignature SeahorsePgpSignature;
-typedef struct _SeahorsePgpSignatureClass SeahorsePgpSignatureClass;
-typedef struct _SeahorsePgpSignaturePrivate SeahorsePgpSignaturePrivate;
-
-struct _SeahorsePgpSignature {
-       GObject parent;
-       SeahorsePgpSignaturePrivate *pv;
-};
 
 struct _SeahorsePgpSignatureClass {
-       GObjectClass parent_class;
+    GObjectClass parent_class;
 };
 
-GType                  seahorse_pgp_signature_get_type       (void);
-
 SeahorsePgpSignature*  seahorse_pgp_signature_new            (const gchar *keyid);
 
 const gchar*           seahorse_pgp_signature_get_keyid      (SeahorsePgpSignature *self);


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