[network-manager-applet/lr/pkcs11: 22/22] fixup! cert-chooser: refactor to delegate file/pkcs11 operations from NMACertChooser



commit 1ed26190ebd71329ecd72d15b73dc98fb6d6a7ce
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Fri Mar 17 19:32:25 2017 +0100

    fixup! cert-chooser: refactor to delegate file/pkcs11 operations from NMACertChooser

 src/libnma/nma-cert-chooser-private.h |    3 -
 src/libnma/nma-cert-chooser.c         |   81 ++++++++++++++-------------------
 2 files changed, 35 insertions(+), 49 deletions(-)
---
diff --git a/src/libnma/nma-cert-chooser-private.h b/src/libnma/nma-cert-chooser-private.h
index 6883500..e1852bc 100644
--- a/src/libnma/nma-cert-chooser-private.h
+++ b/src/libnma/nma-cert-chooser-private.h
@@ -51,9 +51,6 @@ typedef struct {
 typedef struct {
        const NMACertChooserVtable *vtable;
 
-       char *title;
-       guint flags;
-
        struct {
                union {
                        NMAFileCertChooserPrivate file;
diff --git a/src/libnma/nma-cert-chooser.c b/src/libnma/nma-cert-chooser.c
index ff38b83..b4f9572 100644
--- a/src/libnma/nma-cert-chooser.c
+++ b/src/libnma/nma-cert-chooser.c
@@ -603,65 +603,56 @@ nma_cert_chooser_get_key_password_flags (NMACertChooser *cert_chooser)
        return NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser)->get_key_password_flags (cert_chooser);
 }
 
-static void
-constructed (GObject *object)
-{
-       NMACertChooser *self = NMA_CERT_CHOOSER (object);
-       NMACertChooserPrivate *priv = NMA_CERT_CHOOSER_GET_PRIVATE (self);
-
+static GObject *
+constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties)
+{
+       GObject *object;
+       NMACertChooser *cert_chooser;
+       NMACertChooserFlags flags = NMA_CERT_CHOOSER_FLAG_NONE;
+       NMACertChooserPrivate *priv;
+       int i;
+       const gchar *title = NULL;
+
+       object = G_OBJECT_CLASS (nma_cert_chooser_parent_class)->constructor (type,
+                                                                             n_construct_properties,
+                                                                             construct_properties);
+       cert_chooser = NMA_CERT_CHOOSER (object);
+       priv = NMA_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+       for (i = 0; i < n_construct_properties; i++) {
+               if (strcmp (construct_properties[i].pspec->name, "title") == 0)
+                       title = g_value_get_string (construct_properties[i].value);
+               if (strcmp (construct_properties[i].pspec->name, "flags") == 0)
+                       flags |= g_value_get_uint (construct_properties[i].value);
+       }
        priv->vtable = &nma_cert_chooser_vtable_file;
 #if LIBNM_BUILD && WITH_GCR
-       if ((priv->flags & NMA_CERT_CHOOSER_FLAG_PEM) == 0)
+       if ((flags & NMA_CERT_CHOOSER_FLAG_PEM) == 0)
                priv->vtable = &nma_cert_chooser_vtable_pkcs11;
 #endif
 
-       priv->vtable->init (self);
+       /* Initialize the vtable and construct-time properties */
+       priv->vtable->init (cert_chooser);
+       priv->vtable->set_flags (cert_chooser, flags);
+       priv->vtable->set_title (cert_chooser, title);
 
-       G_OBJECT_CLASS (nma_cert_chooser_parent_class)->constructed (object);
-}
-
-static void
-finalize (GObject *object)
-{
-       NMACertChooser *self = NMA_CERT_CHOOSER (object);
-       NMACertChooserPrivate *priv = NMA_CERT_CHOOSER_GET_PRIVATE (self);
-
-       g_free (priv->title);
-
-       G_OBJECT_CLASS (nma_cert_chooser_parent_class)->finalize (object);
+       return object;
 }
 
 static void
 set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
-       NMACertChooserPrivate *priv = NMA_CERT_CHOOSER_GET_PRIVATE (NMA_CERT_CHOOSER (object));
+       NMACertChooser *cert_chooser = NMA_CERT_CHOOSER (object);
+       const NMACertChooserVtable *vtable;
 
-       switch (property_id) {
-       case PROP_TITLE:
-               /* construct-only */
-               priv->title = g_value_dup_string (value);
-               break;
-       case PROP_FLAGS:
-               /* construct-only */
-               priv->flags = g_value_get_uint (value);
-               break;
-       default:
-               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-               break;
-       }
-}
+       g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
 
-static void
-get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
-{
-       NMACertChooserPrivate *priv = NMA_CERT_CHOOSER_GET_PRIVATE (NMA_CERT_CHOOSER (object));
+       vtable = NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser);
 
        switch (property_id) {
        case PROP_TITLE:
-               g_value_set_string (value, priv->title);
-               break;
        case PROP_FLAGS:
-               g_value_set_uint (value, priv->flags);
+               /* Just ignore these, should be set at construct time */
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -676,9 +667,7 @@ nma_cert_chooser_class_init (NMACertChooserClass *klass)
 
        g_type_class_add_private (object_class, sizeof (NMACertChooserPrivate));
 
-       object_class->constructed = constructed;
-       object_class->finalize = finalize;
-       object_class->get_property = get_property;
+       object_class->constructor = constructor;
        object_class->set_property = set_property;
 
        /**
@@ -693,7 +682,7 @@ nma_cert_chooser_class_init (NMACertChooserClass *klass)
                                                     "Title",
                                                     "Certificate Chooser Title",
                                                     NULL,
-                                                      G_PARAM_READWRITE
+                                                      G_PARAM_WRITABLE
                                                     | G_PARAM_CONSTRUCT_ONLY
                                                     | G_PARAM_STATIC_STRINGS);
 
@@ -713,7 +702,7 @@ nma_cert_chooser_class_init (NMACertChooserClass *klass)
                                                    | NMA_CERT_CHOOSER_FLAG_PASSWORDS
                                                    | NMA_CERT_CHOOSER_FLAG_PEM,
                                                    NMA_CERT_CHOOSER_FLAG_NONE,
-                                                     G_PARAM_READWRITE
+                                                      G_PARAM_WRITABLE
                                                    | G_PARAM_CONSTRUCT_ONLY
                                                    | G_PARAM_STATIC_STRINGS);
 


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