[network-manager-applet/lr/pkcs11] cert-chooser: refactor to delegate file/pkcs11 operations from NMACertChooser
- From: Lubomir Rintel <lkundrak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/lr/pkcs11] cert-chooser: refactor to delegate file/pkcs11 operations from NMACertChooser
- Date: Thu, 16 Mar 2017 16:17:38 +0000 (UTC)
commit 5e7188214dbaceab04c4879e9b12f42643fe8b7c
Author: Thomas Haller <thaller redhat com>
Date: Wed Mar 15 16:19:24 2017 +0100
cert-chooser: refactor to delegate file/pkcs11 operations from NMACertChooser
Previously, NMACertChooser::constructor() would re-inject the actual
type based on the flags property, thus, instead of creating an instance
of type NMACertChooser, it would create an NMAFileCertChooser or
NMAPkcs11CertChooser.
Don't do that. Don't delegate using inheritence and NMACertChooserClass,
instead delegate using a vtable structure.
Also, hide the actual implementation of NMACertChooser and
NMACertChooserClass from public headers. This means, the classes
cannot be subclassed, but that is something that is not planned
to be supported (at least for the moment).
Makefile.am | 10 +-
src/libnma/nma-cert-chooser-private.h | 159 ++++++++++++++++++++++++
src/libnma/nma-cert-chooser.c | 216 +++++++++++++++-----------------
src/libnma/nma-cert-chooser.h | 126 ++------------------
src/libnma/nma-file-cert-chooser.c | 117 ++++++++----------
src/libnma/nma-file-cert-chooser.h | 50 --------
src/libnma/nma-pkcs11-cert-chooser.c | 132 +++++++++------------
src/libnma/nma-pkcs11-cert-chooser.h | 50 --------
8 files changed, 380 insertions(+), 480 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 63b7605..8d923c5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -497,14 +497,13 @@ libnma_c_real = \
src/libnma/nma-file-cert-chooser.c
libnma_h_priv_real = \
- src/libnma/nma-file-cert-chooser.h
+ src/libnma/nma-cert-chooser-private.h
if WITH_GCR
libnma_h_priv_real += \
src/libnma/nma-pkcs11-token-login-dialog.h \
src/libnma/nma-pkcs11-cert-chooser-dialog.h \
- src/libnma/nma-cert-chooser-button.h \
- src/libnma/nma-pkcs11-cert-chooser.h
+ src/libnma/nma-cert-chooser-button.h
libnma_c_real += \
src/libnma/nma-pkcs11-token-login-dialog.c \
@@ -879,11 +878,10 @@ CFILE_GLOB = $(top_srcdir)/src/libnma/*.c
IGNORE_HFILES = \
nma-resources.h \
nma-version.h \
- nma-file-cert-chooser.h \
+ nma-cert-chooser-private.h \
nma-pkcs11-token-login-dialog.h \
nma-pkcs11-cert-chooser-dialog.h \
- nma-cert-chooser-button.h \
- nma-pkcs11-cert-chooser.h
+ nma-cert-chooser-button.h
mkdb_ignore_c_files = \
nma-resources.c \
diff --git a/src/libnma/nma-cert-chooser-private.h b/src/libnma/nma-cert-chooser-private.h
new file mode 100644
index 0000000..6883500
--- /dev/null
+++ b/src/libnma/nma-cert-chooser-private.h
@@ -0,0 +1,159 @@
+/* NetworkManager Applet -- allow user control over networking
+ *
+ * Lubomir Rintel <lkundrak v3 sk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2015,2017 Red Hat, Inc.
+ */
+
+#ifndef NMA_CERT_CHOOSER_PRIVATE_H
+#define NMA_CERT_CHOOSER_PRIVATE_H
+
+#include "nma-cert-chooser.h"
+
+typedef struct _NMACertChooserVtable NMACertChooserVtable;
+
+typedef struct {
+ GtkWidget *key_button_label;
+ GtkWidget *key_password_label;
+ GtkWidget *cert_button_label;
+ GtkWidget *key_button;
+ GtkWidget *key_password;
+ GtkWidget *cert_button;
+ GtkWidget *show_password;
+} NMAFileCertChooserPrivate;
+
+typedef struct {
+ GtkWidget *key_button_label;
+ GtkWidget *key_password_label;
+ GtkWidget *cert_button_label;
+ GtkWidget *cert_password_label;
+ GtkWidget *key_button;
+ GtkWidget *key_password;
+ GtkWidget *cert_button;
+ GtkWidget *cert_password;
+} NMAPkcs11CertChooserPrivate;
+
+typedef struct {
+ const NMACertChooserVtable *vtable;
+
+ char *title;
+ guint flags;
+
+ struct {
+ union {
+ NMAFileCertChooserPrivate file;
+ NMAPkcs11CertChooserPrivate pkcs11;
+ };
+ } _sub;
+} NMACertChooserPrivate;
+
+struct _NMACertChooser {
+ GtkGrid parent;
+ NMACertChooserPrivate _priv;
+};
+
+struct _NMACertChooserClass {
+ GtkGridClass parent_class;
+};
+
+/**
+ * NMACertChooserVtable:
+ * @init: called early to initialize the type.
+ * @set_cert_uri: Set the certificate location for the chooser button.
+ * @get_cert_uri: Get the real certificate location from the chooser button along
+ * with the scheme.
+ * @set_cert_password: Set the password or a PIN that might be required to
+ * access the certificate.
+ * @get_cert_password: Obtain the password or a PIN that was be required to
+ * access the certificate.
+ * @set_key_uri: Set the key location for the chooser button.
+ * @get_key_uri: Get the real key location from the chooser button along with the
+ * scheme.
+ * @set_key_password: Set the password or a PIN that might be required to
+ * access the key.
+ * @get_key_password: Obtain the password or a PIN that was be required to
+ * access the key.
+ * @add_to_size_group: Add the labels to the specified size group so that they
+ * are aligned.
+ * @validate: Validate whether the chosen values make sense.
+ * @setup_cert_password_storage: Set up certificate password storage.
+ * @update_cert_password_storage: Update certificate password storage.
+ * @get_cert_password_flags: Return secret flags corresponding to the
+ * certificate password if one is present.
+ * @setup_key_password_storage: Set up key password storage.
+ * @update_key_password_storage: Update key password storage.
+ * @get_key_password_flags: Returns secret flags corresponding to the key
+ * password if one is present.
+ * @set_title: Setup the title property
+ * @set_flags: Setup the flags property
+ */
+struct _NMACertChooserVtable {
+ void (*init) (NMACertChooser *cert_chooser);
+ void (*set_cert_uri) (NMACertChooser *cert_chooser,
+ const gchar *uri);
+ gchar *(*get_cert_uri) (NMACertChooser *cert_chooser);
+ void (*set_cert_password) (NMACertChooser *cert_chooser,
+ const gchar *password);
+ const gchar *(*get_cert_password) (NMACertChooser *cert_chooser);
+ void (*set_key_uri) (NMACertChooser *cert_chooser,
+ const gchar *uri);
+ gchar *(*get_key_uri) (NMACertChooser *cert_chooser);
+ void (*set_key_password) (NMACertChooser *cert_chooser,
+ const gchar *password);
+ const gchar *(*get_key_password) (NMACertChooser *cert_chooser);
+
+ void (*add_to_size_group) (NMACertChooser *cert_chooser,
+ GtkSizeGroup *group);
+ gboolean (*validate) (NMACertChooser *cert_chooser,
+ GError **error);
+
+ void (*setup_cert_password_storage) (NMACertChooser *cert_chooser,
+ NMSettingSecretFlags initial_flags,
+ NMSetting *setting,
+ const char *password_flags_name,
+ gboolean with_not_required,
+ gboolean ask_mode);
+ void (*update_cert_password_storage) (NMACertChooser *cert_chooser,
+ NMSettingSecretFlags secret_flags,
+ NMSetting *setting,
+ const char *password_flags_name);
+ NMSettingSecretFlags (*get_cert_password_flags) (NMACertChooser *cert_chooser);
+ void (*setup_key_password_storage) (NMACertChooser *cert_chooser,
+ NMSettingSecretFlags initial_flags,
+ NMSetting *setting,
+ const char *password_flags_name,
+ gboolean with_not_required,
+ gboolean ask_mode);
+ void (*update_key_password_storage) (NMACertChooser *cert_chooser,
+ NMSettingSecretFlags secret_flags,
+ NMSetting *setting,
+ const char *password_flags_name);
+ NMSettingSecretFlags (*get_key_password_flags) (NMACertChooser *cert_chooser);
+
+ void (*set_title) (NMACertChooser *cert_chooser,
+ const gchar *title);
+ void (*set_flags) (NMACertChooser *cert_chooser,
+ NMACertChooserFlags flags);
+};
+
+extern const NMACertChooserVtable nma_cert_chooser_vtable_file;
+#if LIBNM_BUILD && WITH_GCR
+extern const NMACertChooserVtable nma_cert_chooser_vtable_pkcs11;
+#endif
+
+#endif /* NMA_CERT_CHOOSER_PRIVATE_H */
diff --git a/src/libnma/nma-cert-chooser.c b/src/libnma/nma-cert-chooser.c
index b158fec..ff38b83 100644
--- a/src/libnma/nma-cert-chooser.c
+++ b/src/libnma/nma-cert-chooser.c
@@ -22,8 +22,8 @@
#include "nm-default.h"
#include "nma-cert-chooser.h"
-#include "nma-file-cert-chooser.h"
-#include "nma-pkcs11-cert-chooser.h"
+
+#include "nma-cert-chooser-private.h"
/**
* SECTION:nma-cert-chooser
@@ -60,6 +60,9 @@ static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (NMACertChooser, nma_cert_chooser, GTK_TYPE_GRID)
+#define NMA_CERT_CHOOSER_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMACertChooser, NMA_IS_CERT_CHOOSER)
+#define NMA_CERT_CHOOSER_GET_VTABLE(o) (NMA_CERT_CHOOSER_GET_PRIVATE (o)->vtable)
+
static gboolean
accu_validation_error (GSignalInvocationHint *ihint,
GValue *return_accu,
@@ -146,13 +149,9 @@ void
nma_cert_chooser_set_cert_uri (NMACertChooser *cert_chooser,
const gchar *uri)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
-
g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
- if (!klass->set_cert_uri)
- return;
- klass->set_cert_uri (cert_chooser, uri);
+ NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser)->set_cert_uri (cert_chooser, uri);
}
/**
@@ -194,12 +193,9 @@ nma_cert_chooser_set_cert (NMACertChooser *cert_chooser,
gchar *
nma_cert_chooser_get_cert_uri (NMACertChooser *cert_chooser)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
-
g_return_val_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser), NULL);
- g_return_val_if_fail (klass->get_cert_uri, NULL);
- return klass->get_cert_uri (cert_chooser);
+ return NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser)->get_cert_uri (cert_chooser);
}
/**
@@ -236,12 +232,13 @@ nma_cert_chooser_get_cert (NMACertChooser *cert_chooser, NMSetting8021xCKScheme
void
nma_cert_chooser_set_cert_password (NMACertChooser *cert_chooser, const gchar *password)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
+ const NMACertChooserVtable *vtable;
g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
- if (klass->set_cert_password)
- klass->set_cert_password (cert_chooser, password);
+ vtable = NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser);
+ if (vtable->set_cert_password)
+ vtable->set_cert_password (cert_chooser, password);
else
g_warning ("Can't set certificate password");
}
@@ -259,13 +256,14 @@ nma_cert_chooser_set_cert_password (NMACertChooser *cert_chooser, const gchar *p
const gchar *
nma_cert_chooser_get_cert_password (NMACertChooser *cert_chooser)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
+ const NMACertChooserVtable *vtable;
g_return_val_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser), NULL);
- if (!klass->get_cert_password)
+ vtable = NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser);
+ if (!vtable->get_cert_password)
return NULL;
- return klass->get_cert_password (cert_chooser);
+ return vtable->get_cert_password (cert_chooser);
}
/**
@@ -281,13 +279,9 @@ void
nma_cert_chooser_set_key_uri (NMACertChooser *cert_chooser,
const gchar *uri)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
-
g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
- if (!klass->set_key_uri)
- return;
- klass->set_key_uri (cert_chooser, uri);
+ return NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser)->set_key_uri (cert_chooser, uri);
}
/**
@@ -351,12 +345,9 @@ nma_cert_chooser_get_key (NMACertChooser *cert_chooser, NMSetting8021xCKScheme *
gchar *
nma_cert_chooser_get_key_uri (NMACertChooser *cert_chooser)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
-
g_return_val_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser), NULL);
- g_return_val_if_fail (klass->get_key_uri, NULL);
- return klass->get_key_uri (cert_chooser);
+ return NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser)->get_key_uri (cert_chooser);
}
/**
@@ -371,12 +362,9 @@ nma_cert_chooser_get_key_uri (NMACertChooser *cert_chooser)
void
nma_cert_chooser_set_key_password (NMACertChooser *cert_chooser, const gchar *password)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
-
g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
- g_return_if_fail (klass->set_key_password);
- klass->set_key_password (cert_chooser, password);
+ NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser)->set_key_password (cert_chooser, password);
}
/**
@@ -392,13 +380,9 @@ nma_cert_chooser_set_key_password (NMACertChooser *cert_chooser, const gchar *pa
const gchar *
nma_cert_chooser_get_key_password (NMACertChooser *cert_chooser)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
-
g_return_val_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser), NULL);
- if (!klass->get_key_password)
- return NULL;
- return klass->get_key_password (cert_chooser);
+ return NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser)->get_key_password (cert_chooser);
}
/**
@@ -417,12 +401,9 @@ nma_cert_chooser_get_key_password (NMACertChooser *cert_chooser)
void
nma_cert_chooser_add_to_size_group (NMACertChooser *cert_chooser, GtkSizeGroup *group)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
-
g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
- if (klass->add_to_size_group)
- klass->add_to_size_group (cert_chooser, group);
+ NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser)->add_to_size_group (cert_chooser, group);
}
/**
@@ -441,13 +422,9 @@ nma_cert_chooser_add_to_size_group (NMACertChooser *cert_chooser, GtkSizeGroup *
gboolean
nma_cert_chooser_validate (NMACertChooser *cert_chooser, GError **error)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
-
g_return_val_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser), TRUE);
- if (!klass->validate)
- return TRUE;
- return klass->validate (cert_chooser, error);
+ return NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser)->validate (cert_chooser, error);
}
/**
@@ -472,17 +449,18 @@ nma_cert_chooser_setup_cert_password_storage (NMACertChooser *cert_chooser,
gboolean with_not_required,
gboolean ask_mode)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
+ const NMACertChooserVtable *vtable;
g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
- if (klass->setup_cert_password_storage) {
- klass->setup_cert_password_storage (cert_chooser,
- initial_flags,
- setting,
- password_flags_name,
- with_not_required,
- ask_mode);
+ vtable = NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser);
+ if (vtable->setup_cert_password_storage) {
+ vtable->setup_cert_password_storage (cert_chooser,
+ initial_flags,
+ setting,
+ password_flags_name,
+ with_not_required,
+ ask_mode);
}
}
@@ -504,15 +482,16 @@ nma_cert_chooser_update_cert_password_storage (NMACertChooser *cert_chooser,
NMSetting *setting,
const char *password_flags_name)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
+ const NMACertChooserVtable *vtable;
g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
- if (klass->update_cert_password_storage) {
- klass->update_cert_password_storage (cert_chooser,
- secret_flags,
- setting,
- password_flags_name);
+ vtable = NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser);
+ if (vtable->update_cert_password_storage) {
+ vtable->update_cert_password_storage (cert_chooser,
+ secret_flags,
+ setting,
+ password_flags_name);
}
}
@@ -532,14 +511,15 @@ nma_cert_chooser_update_cert_password_storage (NMACertChooser *cert_chooser,
NMSettingSecretFlags
nma_cert_chooser_get_cert_password_flags (NMACertChooser *cert_chooser)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
+ const NMACertChooserVtable *vtable;
g_return_val_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser),
NM_SETTING_SECRET_FLAG_NONE);
- if (!klass->get_cert_password_flags)
+ vtable = NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser);
+ if (!vtable->get_cert_password_flags)
return NM_SETTING_SECRET_FLAG_NONE;
- return klass->get_cert_password_flags (cert_chooser);
+ return vtable->get_cert_password_flags (cert_chooser);
}
@@ -565,18 +545,14 @@ nma_cert_chooser_setup_key_password_storage (NMACertChooser *cert_chooser,
gboolean with_not_required,
gboolean ask_mode)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
-
g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
- if (klass->setup_key_password_storage) {
- klass->setup_key_password_storage (cert_chooser,
- initial_flags,
- setting,
- password_flags_name,
- with_not_required,
- ask_mode);
- }
+ NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser)->setup_key_password_storage (cert_chooser,
+ initial_flags,
+ setting,
+ password_flags_name,
+ with_not_required,
+ ask_mode);
}
/**
@@ -597,16 +573,12 @@ nma_cert_chooser_update_key_password_storage (NMACertChooser *cert_chooser,
NMSetting *setting,
const char *password_flags_name)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
-
g_return_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser));
- if (klass->update_key_password_storage) {
- klass->update_key_password_storage (cert_chooser,
- secret_flags,
- setting,
- password_flags_name);
- }
+ NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser)->update_key_password_storage (cert_chooser,
+ secret_flags,
+ setting,
+ password_flags_name);
}
/**
@@ -625,54 +597,53 @@ nma_cert_chooser_update_key_password_storage (NMACertChooser *cert_chooser,
NMSettingSecretFlags
nma_cert_chooser_get_key_password_flags (NMACertChooser *cert_chooser)
{
- NMACertChooserClass *klass = NMA_CERT_CHOOSER_GET_CLASS (cert_chooser);
-
g_return_val_if_fail (NMA_IS_CERT_CHOOSER (cert_chooser),
NM_SETTING_SECRET_FLAG_NONE);
- if (!klass->get_key_password_flags)
- return NM_SETTING_SECRET_FLAG_NONE;
- return klass->get_key_password_flags (cert_chooser);
+ return NMA_CERT_CHOOSER_GET_VTABLE (cert_chooser)->get_key_password_flags (cert_chooser);
}
-static GObject *
-constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties)
+static void
+constructed (GObject *object)
{
- NMACertChooserFlags flags = NMA_CERT_CHOOSER_FLAG_NONE;
- int i;
+ NMACertChooser *self = NMA_CERT_CHOOSER (object);
+ NMACertChooserPrivate *priv = NMA_CERT_CHOOSER_GET_PRIVATE (self);
- if (type == NMA_TYPE_CERT_CHOOSER) {
- for (i = 0; i < n_construct_properties; i++) {
- if (strcmp (construct_properties[i].pspec->name, "flags") == 0)
- flags |= g_value_get_uint (construct_properties[i].value);
- }
- type = NMA_TYPE_FILE_CERT_CHOOSER;
+ priv->vtable = &nma_cert_chooser_vtable_file;
#if LIBNM_BUILD && WITH_GCR
- if ((flags & NMA_CERT_CHOOSER_FLAG_PEM) == 0)
- type = NMA_TYPE_PKCS11_CERT_CHOOSER;
+ if ((priv->flags & NMA_CERT_CHOOSER_FLAG_PEM) == 0)
+ priv->vtable = &nma_cert_chooser_vtable_pkcs11;
#endif
- }
- return G_OBJECT_CLASS (nma_cert_chooser_parent_class)->constructor (type,
- n_construct_properties,
- construct_properties);
+ priv->vtable->init (self);
+
+ 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);
}
static void
set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
- NMACertChooserClass *cert_chooser_class = NMA_CERT_CHOOSER_GET_CLASS (object);
+ NMACertChooserPrivate *priv = NMA_CERT_CHOOSER_GET_PRIVATE (NMA_CERT_CHOOSER (object));
switch (property_id) {
case PROP_TITLE:
- g_return_if_fail (cert_chooser_class->set_title);
- cert_chooser_class->set_title (NMA_CERT_CHOOSER (object),
- g_value_get_string (value));
+ /* construct-only */
+ priv->title = g_value_dup_string (value);
break;
case PROP_FLAGS:
- g_return_if_fail (cert_chooser_class->set_flags);
- cert_chooser_class->set_flags (NMA_CERT_CHOOSER (object),
- g_value_get_uint (value));
+ /* construct-only */
+ priv->flags = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -683,7 +654,19 @@ set_property (GObject *object, guint property_id, const GValue *value, GParamSpe
static void
get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ NMACertChooserPrivate *priv = NMA_CERT_CHOOSER_GET_PRIVATE (NMA_CERT_CHOOSER (object));
+
+ switch (property_id) {
+ case PROP_TITLE:
+ g_value_set_string (value, priv->title);
+ break;
+ case PROP_FLAGS:
+ g_value_set_uint (value, priv->flags);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
}
static void
@@ -691,7 +674,10 @@ nma_cert_chooser_class_init (NMACertChooserClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->constructor = constructor;
+ 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->set_property = set_property;
@@ -707,7 +693,7 @@ nma_cert_chooser_class_init (NMACertChooserClass *klass)
"Title",
"Certificate Chooser Title",
NULL,
- G_PARAM_WRITABLE
+ G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS);
@@ -746,7 +732,7 @@ nma_cert_chooser_class_init (NMACertChooserClass *klass)
signals[CERT_VALIDATE] = g_signal_new ("cert-validate",
NMA_TYPE_CERT_CHOOSER,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NMACertChooserClass, cert_validate),
+ 0,
accu_validation_error, NULL, NULL,
G_TYPE_ERROR, 0);
@@ -763,7 +749,7 @@ nma_cert_chooser_class_init (NMACertChooserClass *klass)
signals[CERT_PASSWORD_VALIDATE] = g_signal_new ("cert-password-validate",
NMA_TYPE_CERT_CHOOSER,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NMACertChooserClass,
cert_password_validate),
+ 0,
accu_validation_error, NULL, NULL,
G_TYPE_ERROR, 0);
@@ -780,7 +766,7 @@ nma_cert_chooser_class_init (NMACertChooserClass *klass)
signals[KEY_VALIDATE] = g_signal_new ("key-validate",
NMA_TYPE_CERT_CHOOSER,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NMACertChooserClass, key_validate),
+ 0,
accu_validation_error, NULL, NULL,
G_TYPE_ERROR, 0);
@@ -797,7 +783,7 @@ nma_cert_chooser_class_init (NMACertChooserClass *klass)
signals[KEY_PASSWORD_VALIDATE] = g_signal_new ("key-password-validate",
NMA_TYPE_CERT_CHOOSER,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NMACertChooserClass,
key_password_validate),
+ 0,
accu_validation_error, NULL, NULL,
G_TYPE_ERROR, 0);
@@ -812,7 +798,7 @@ nma_cert_chooser_class_init (NMACertChooserClass *klass)
signals[CHANGED] = g_signal_new ("changed",
NMA_TYPE_CERT_CHOOSER,
G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE,
- G_STRUCT_OFFSET (NMACertChooserClass, changed),
+ 0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
diff --git a/src/libnma/nma-cert-chooser.h b/src/libnma/nma-cert-chooser.h
index 0d1d55d..b48fbe8 100644
--- a/src/libnma/nma-cert-chooser.h
+++ b/src/libnma/nma-cert-chooser.h
@@ -30,18 +30,6 @@
G_BEGIN_DECLS
-#define NMA_TYPE_CERT_CHOOSER (nma_cert_chooser_get_type ())
-#define NMA_CERT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMA_TYPE_CERT_CHOOSER,
NMACertChooser))
-#define NMA_CERT_CHOOSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMA_TYPE_CERT_CHOOSER,
NMACertChooserClass))
-#define NMA_IS_CERT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMA_TYPE_CERT_CHOOSER))
-#define NMA_IS_CERT_CHOOSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMA_TYPE_CERT_CHOOSER))
-#define NMA_CERT_CHOOSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMA_TYPE_CERT_CHOOSER,
NMACertChooserClass))
-
-NMA_AVAILABLE_IN_1_8
-typedef struct {
- GtkGrid parent;
-} NMACertChooser;
-
/**
* NMACertChooserFlags:
* @NMA_CERT_CHOOSER_FLAG_NONE: No flags
@@ -63,112 +51,18 @@ typedef enum {
NMA_CERT_CHOOSER_FLAG_PEM = 0x4,
} NMACertChooserFlags;
-/**
- * NMACertChooserClass:
- * @parent_class: The parent class.
- * @set_cert_uri: Set the certificate location for the chooser button.
- * @get_cert_uri: Get the real certificate location from the chooser button along
- * with the scheme.
- * @set_cert_password: Set the password or a PIN that might be required to
- * access the certificate.
- * @get_cert_password: Obtain the password or a PIN that was be required to
- * access the certificate.
- * @set_key_uri: Set the key location for the chooser button.
- * @get_key_uri: Get the real key location from the chooser button along with the
- * scheme.
- * @set_key_password: Set the password or a PIN that might be required to
- * access the key.
- * @get_key_password: Obtain the password or a PIN that was be required to
- * access the key.
- * @add_to_size_group: Add the labels to the specified size group so that they
- * are aligned.
- * @validate: Validate whether the chosen values make sense.
- * @setup_cert_password_storage: Set up certificate password storage.
- * @update_cert_password_storage: Update certificate password storage.
- * @get_cert_password_flags: Return secret flags corresponding to the
- * certificate password if one is present.
- * @setup_key_password_storage: Set up key password storage.
- * @update_key_password_storage: Update key password storage.
- * @get_key_password_flags: Returns secret flags corresponding to the key
- * password if one is present.
- * @cert_validate: Emitted when the certificate needs validation.
- * @cert_password_validate: Emitted when the certificate password needs
- * validation.
- * @key_validate: Emitted when the key needs validation.
- * @key_password_validate: Emitted when the key password needs validation.
- * @changed: Emitted when anything changes in the certificate chooser.
- *
- * Since: 1.8.0
- */
+#define NMA_TYPE_CERT_CHOOSER (nma_cert_chooser_get_type ())
+#define NMA_CERT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMA_TYPE_CERT_CHOOSER,
NMACertChooser))
+#define NMA_CERT_CHOOSER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMA_TYPE_CERT_CHOOSER,
NMACertChooserClass))
+#define NMA_IS_CERT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMA_TYPE_CERT_CHOOSER))
+#define NMA_IS_CERT_CHOOSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMA_TYPE_CERT_CHOOSER))
+#define NMA_CERT_CHOOSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMA_TYPE_CERT_CHOOSER,
NMACertChooserClass))
+
+NMA_AVAILABLE_IN_1_8
+typedef struct _NMACertChooser NMACertChooser;
+
NMA_AVAILABLE_IN_1_8
-typedef struct {
- GtkGridClass parent_class;
-
- /* virtual methods */
- void (*set_cert_uri) (NMACertChooser *cert_chooser,
- const gchar *uri);
- gchar *(*get_cert_uri) (NMACertChooser *cert_chooser);
- void (*set_cert_password) (NMACertChooser *cert_chooser,
- const gchar *password);
- const gchar *(*get_cert_password) (NMACertChooser *cert_chooser);
- void (*set_key_uri) (NMACertChooser *cert_chooser,
- const gchar *uri);
- gchar *(*get_key_uri) (NMACertChooser *cert_chooser);
- void (*set_key_password) (NMACertChooser *cert_chooser,
- const gchar *password);
- const gchar *(*get_key_password) (NMACertChooser *cert_chooser);
-
- void (*add_to_size_group) (NMACertChooser *cert_chooser,
- GtkSizeGroup *group);
- gboolean (*validate) (NMACertChooser *cert_chooser,
- GError **error);
-
- void (*setup_cert_password_storage) (NMACertChooser *cert_chooser,
- NMSettingSecretFlags initial_flags,
- NMSetting *setting,
- const char *password_flags_name,
- gboolean with_not_required,
- gboolean ask_mode);
- void (*update_cert_password_storage) (NMACertChooser *cert_chooser,
- NMSettingSecretFlags secret_flags,
- NMSetting *setting,
- const char *password_flags_name);
- NMSettingSecretFlags (*get_cert_password_flags) (NMACertChooser *cert_chooser);
- void (*setup_key_password_storage) (NMACertChooser *cert_chooser,
- NMSettingSecretFlags initial_flags,
- NMSetting *setting,
- const char *password_flags_name,
- gboolean with_not_required,
- gboolean ask_mode);
- void (*update_key_password_storage) (NMACertChooser *cert_chooser,
- NMSettingSecretFlags secret_flags,
- NMSetting *setting,
- const char *password_flags_name);
- NMSettingSecretFlags (*get_key_password_flags) (NMACertChooser *cert_chooser);
-
- /* signals */
- GError *(*cert_validate) (NMACertChooser *cert_chooser);
- GError *(*cert_password_validate) (NMACertChooser *cert_chooser);
- GError *(*key_validate) (NMACertChooser *cert_chooser);
- GError *(*key_password_validate) (NMACertChooser *cert_chooser);
- void (*changed) (NMACertChooser *cert_chooser);
-
- /*< private >*/
- void (*set_title) (NMACertChooser *cert_chooser,
- const gchar *title);
- void (*set_flags) (NMACertChooser *cert_chooser,
- NMACertChooserFlags flags);
-
- void (*slot_1) (void);
- void (*slot_2) (void);
- void (*slot_3) (void);
- void (*slot_4) (void);
- void (*slot_5) (void);
- void (*slot_6) (void);
- void (*slot_7) (void);
- void (*slot_8) (void);
-
-} NMACertChooserClass;
+typedef struct _NMACertChooserClass NMACertChooserClass;
NMA_AVAILABLE_IN_1_8
GType nma_cert_chooser_get_type (void);
diff --git a/src/libnma/nma-file-cert-chooser.c b/src/libnma/nma-file-cert-chooser.c
index 4f53f07..9f85717 100644
--- a/src/libnma/nma-file-cert-chooser.c
+++ b/src/libnma/nma-file-cert-chooser.c
@@ -22,29 +22,15 @@
*/
#include "nm-default.h"
-#include "nma-file-cert-chooser.h"
+#include "nma-cert-chooser-private.h"
+#include "utils.h"
#ifdef LIBNM_BUILD
#include "nma-ui-utils.h"
#else
#include "nm-ui-utils.h"
#endif
-#include "utils.h"
-
-typedef struct {
- GtkWidget *key_button_label;
- GtkWidget *key_password_label;
- GtkWidget *cert_button_label;
- GtkWidget *key_button;
- GtkWidget *key_password;
- GtkWidget *cert_button;
- GtkWidget *show_password;
-} NMAFileCertChooserPrivate;
-#define NMA_FILE_CERT_CHOOSER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
- NMA_TYPE_FILE_CERT_CHOOSER, \
- NMAFileCertChooserPrivate))
-
-G_DEFINE_TYPE (NMAFileCertChooser, nma_file_cert_chooser, NMA_TYPE_CERT_CHOOSER)
+#define NMA_FILE_CERT_CHOOSER_GET_PRIVATE(self) (&(_NM_GET_PRIVATE (self, NMACertChooser,
NMA_IS_CERT_CHOOSER)->_sub.file))
static void
set_key_password (NMACertChooser *cert_chooser, const gchar *password)
@@ -217,7 +203,7 @@ reset_filter (GtkWidget *widget, GParamSpec *spec, gpointer user_data)
static void
cert_changed_cb (GtkFileChooserButton *file_chooser_button, gpointer user_data)
{
- NMAFileCertChooserPrivate *priv = NMA_FILE_CERT_CHOOSER_GET_PRIVATE (user_data);
+ NMAFileCertChooserPrivate *priv = NMA_FILE_CERT_CHOOSER_GET_PRIVATE (NMA_CERT_CHOOSER (user_data));
if (gtk_widget_get_visible (priv->key_button)) {
gtk_widget_set_sensitive (priv->key_button, TRUE);
@@ -229,7 +215,7 @@ cert_changed_cb (GtkFileChooserButton *file_chooser_button, gpointer user_data)
static void
key_changed_cb (GtkFileChooserButton *file_chooser_button, gpointer user_data)
{
- NMAFileCertChooserPrivate *priv = NMA_FILE_CERT_CHOOSER_GET_PRIVATE (user_data);
+ NMAFileCertChooserPrivate *priv = NMA_FILE_CERT_CHOOSER_GET_PRIVATE (NMA_CERT_CHOOSER (user_data));
gtk_widget_set_sensitive (priv->key_password, TRUE);
gtk_widget_set_sensitive (priv->key_password_label, TRUE);
@@ -245,7 +231,7 @@ key_password_changed_cb (GtkEntry *entry, gpointer user_data)
static void
show_toggled_cb (GtkCheckButton *button, gpointer user_data)
{
- NMAFileCertChooserPrivate *priv = NMA_FILE_CERT_CHOOSER_GET_PRIVATE (user_data);
+ NMAFileCertChooserPrivate *priv = NMA_FILE_CERT_CHOOSER_GET_PRIVATE (NMA_CERT_CHOOSER (user_data));
gtk_entry_set_visibility (GTK_ENTRY (priv->key_password),
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)));
@@ -300,99 +286,73 @@ set_flags (NMACertChooser *cert_chooser, NMACertChooserFlags flags)
}
static void
-nma_file_cert_chooser_class_init (NMAFileCertChooserClass *klass)
+init (NMACertChooser *cert_chooser)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- NMACertChooserClass *chooser_class = NMA_CERT_CHOOSER_CLASS (klass);
-
- g_type_class_add_private (object_class, sizeof (NMAFileCertChooserPrivate));
-
- chooser_class->set_title = set_title;
- chooser_class->set_flags = set_flags;
-
- chooser_class->set_cert_uri = set_cert_uri;
- chooser_class->get_cert_uri = get_cert_uri;
- chooser_class->set_key_uri = set_key_uri;
- chooser_class->get_key_uri = get_key_uri;
- chooser_class->set_key_password = set_key_password;
- chooser_class->get_key_password = get_key_password;
-
- chooser_class->add_to_size_group = add_to_size_group;
- chooser_class->validate = validate;
-
- chooser_class->setup_key_password_storage = setup_key_password_storage;
- chooser_class->update_key_password_storage = update_key_password_storage;
- chooser_class->get_key_password_flags = get_key_password_flags;
-}
-
-static void
-nma_file_cert_chooser_init (NMAFileCertChooser *file_cert_chooser)
-{
- NMAFileCertChooserPrivate *priv = NMA_FILE_CERT_CHOOSER_GET_PRIVATE (file_cert_chooser);
+ NMAFileCertChooserPrivate *priv = NMA_FILE_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
GtkFileFilter *filter;
- gtk_grid_insert_column (GTK_GRID (file_cert_chooser), 2);
- gtk_grid_set_row_spacing (GTK_GRID (file_cert_chooser), 6);
- gtk_grid_set_column_spacing (GTK_GRID (file_cert_chooser), 12);
+ gtk_grid_insert_column (GTK_GRID (cert_chooser), 2);
+ gtk_grid_set_row_spacing (GTK_GRID (cert_chooser), 6);
+ gtk_grid_set_column_spacing (GTK_GRID (cert_chooser), 12);
/* The key chooser */
- gtk_grid_insert_row (GTK_GRID (file_cert_chooser), 0);
+ gtk_grid_insert_row (GTK_GRID (cert_chooser), 0);
priv->key_button = g_object_new (GTK_TYPE_FILE_CHOOSER_BUTTON,
"action", GTK_FILE_CHOOSER_ACTION_OPEN,
"filter", utils_key_filter (),
"local-only", TRUE,
NULL);
- gtk_grid_attach (GTK_GRID (file_cert_chooser), priv->key_button, 1, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->key_button, 1, 0, 1, 1);
gtk_widget_set_hexpand (priv->key_button, TRUE);
gtk_widget_set_sensitive (priv->key_button, FALSE);
gtk_widget_show (priv->key_button);
gtk_widget_set_no_show_all (priv->key_button, TRUE);
- g_signal_connect (priv->key_button, "selection-changed",
- G_CALLBACK (key_changed_cb), file_cert_chooser);
+ g_signal_connect (priv->key_button, "selection-changed",
+ G_CALLBACK (key_changed_cb), cert_chooser);
priv->key_button_label = gtk_label_new (NULL);
g_object_set (priv->key_button_label, "xalign", (gfloat) 0, NULL);
gtk_label_set_mnemonic_widget (GTK_LABEL (priv->key_button_label), priv->key_button);
- gtk_grid_attach (GTK_GRID (file_cert_chooser), priv->key_button_label, 0, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->key_button_label, 0, 0, 1, 1);
gtk_widget_set_sensitive (priv->key_button_label, FALSE);
gtk_widget_show (priv->key_button_label);
gtk_widget_set_no_show_all (priv->key_button_label, TRUE);
/* The key password entry */
- gtk_grid_insert_row (GTK_GRID (file_cert_chooser), 1);
+ gtk_grid_insert_row (GTK_GRID (cert_chooser), 1);
priv->key_password = gtk_entry_new ();
gtk_entry_set_visibility (GTK_ENTRY (priv->key_password), FALSE);
- gtk_grid_attach (GTK_GRID (file_cert_chooser), priv->key_password, 1, 1, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->key_password, 1, 1, 1, 1);
gtk_widget_set_hexpand (priv->key_password, TRUE);
gtk_widget_set_sensitive (priv->key_password, FALSE);
gtk_widget_show (priv->key_password);
gtk_widget_set_no_show_all (priv->key_password, TRUE);
- g_signal_connect (priv->key_password, "changed",
- G_CALLBACK (key_password_changed_cb), file_cert_chooser);
+ g_signal_connect (priv->key_password, "changed",
+ G_CALLBACK (key_password_changed_cb), cert_chooser);
priv->key_password_label = gtk_label_new (NULL);
g_object_set (priv->key_password_label, "xalign", (gfloat) 0, NULL);
gtk_label_set_mnemonic_widget (GTK_LABEL (priv->key_password_label), priv->key_password);
- gtk_grid_attach (GTK_GRID (file_cert_chooser), priv->key_password_label, 0, 1, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->key_password_label, 0, 1, 1, 1);
gtk_widget_set_sensitive (priv->key_password_label, FALSE);
gtk_widget_show (priv->key_password_label);
gtk_widget_set_no_show_all (priv->key_password_label, TRUE);
/* Show password */
- gtk_grid_insert_row (GTK_GRID (file_cert_chooser), 2);
+ gtk_grid_insert_row (GTK_GRID (cert_chooser), 2);
priv->show_password = gtk_check_button_new_with_mnemonic ("Sho_w password");
- gtk_grid_attach (GTK_GRID (file_cert_chooser), priv->show_password, 1, 2, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->show_password, 1, 2, 1, 1);
gtk_widget_show (priv->show_password);
gtk_widget_set_no_show_all (priv->show_password, TRUE);
g_signal_connect (priv->show_password, "toggled",
- G_CALLBACK (show_toggled_cb), file_cert_chooser);
+ G_CALLBACK (show_toggled_cb), cert_chooser);
/* The certificate chooser */
- gtk_grid_insert_row (GTK_GRID (file_cert_chooser), 0);
+ gtk_grid_insert_row (GTK_GRID (cert_chooser), 0);
filter = utils_cert_filter ();
priv->cert_button = g_object_new (GTK_TYPE_FILE_CHOOSER_BUTTON,
@@ -400,7 +360,7 @@ nma_file_cert_chooser_init (NMAFileCertChooser *file_cert_chooser)
"filter", filter,
"local-only", TRUE,
NULL);
- gtk_grid_attach (GTK_GRID (file_cert_chooser), priv->cert_button, 1, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->cert_button, 1, 0, 1, 1);
gtk_widget_set_hexpand (priv->cert_button, TRUE);
gtk_widget_show (priv->cert_button);
gtk_widget_set_no_show_all (priv->cert_button, TRUE);
@@ -414,12 +374,33 @@ nma_file_cert_chooser_init (NMAFileCertChooser *file_cert_chooser)
G_CALLBACK (reset_filter), filter);
g_signal_connect (priv->cert_button, "selection-changed",
- G_CALLBACK (cert_changed_cb), file_cert_chooser);
+ G_CALLBACK (cert_changed_cb), cert_chooser);
priv->cert_button_label = gtk_label_new (NULL);
g_object_set (priv->cert_button_label, "xalign", (gfloat) 0, NULL);
gtk_label_set_mnemonic_widget (GTK_LABEL (priv->cert_button_label), priv->cert_button);
- gtk_grid_attach (GTK_GRID (file_cert_chooser), priv->cert_button_label, 0, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->cert_button_label, 0, 0, 1, 1);
gtk_widget_show (priv->cert_button_label);
gtk_widget_set_no_show_all (priv->cert_button_label, TRUE);
}
+
+const NMACertChooserVtable nma_cert_chooser_vtable_file = {
+ .init = init,
+
+ .set_title = set_title,
+ .set_flags = set_flags,
+
+ .set_cert_uri = set_cert_uri,
+ .get_cert_uri = get_cert_uri,
+ .set_key_uri = set_key_uri,
+ .get_key_uri = get_key_uri,
+ .set_key_password = set_key_password,
+ .get_key_password = get_key_password,
+
+ .add_to_size_group = add_to_size_group,
+ .validate = validate,
+
+ .setup_key_password_storage = setup_key_password_storage,
+ .update_key_password_storage = update_key_password_storage,
+ .get_key_password_flags = get_key_password_flags,
+};
diff --git a/src/libnma/nma-pkcs11-cert-chooser.c b/src/libnma/nma-pkcs11-cert-chooser.c
index fc8e388..852be2e 100644
--- a/src/libnma/nma-pkcs11-cert-chooser.c
+++ b/src/libnma/nma-pkcs11-cert-chooser.c
@@ -21,7 +21,7 @@
*/
#include "nm-default.h"
-#include "nma-pkcs11-cert-chooser.h"
+#include "nma-cert-chooser-private.h"
#include "nma-cert-chooser-button.h"
#include "nma-ui-utils.h"
#include "utils.h"
@@ -32,20 +32,7 @@
#include <fcntl.h>
#include <errno.h>
-typedef struct {
- GtkWidget *key_button_label;
- GtkWidget *key_password_label;
- GtkWidget *cert_button_label;
- GtkWidget *cert_password_label;
- GtkWidget *key_button;
- GtkWidget *key_password;
- GtkWidget *cert_button;
- GtkWidget *cert_password;
-} NMAPkcs11CertChooserPrivate;
-
-#define NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o),
NMA_TYPE_PKCS11_CERT_CHOOSER, NMAPkcs11CertChooserPrivate))
-
-G_DEFINE_TYPE (NMAPkcs11CertChooser, nma_pkcs11_cert_chooser, NMA_TYPE_CERT_CHOOSER)
+#define NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE(self) (&(_NM_GET_PRIVATE (self, NMACertChooser,
NMA_IS_CERT_CHOOSER)->_sub.pkcs11))
static void
set_key_password (NMACertChooser *cert_chooser, const gchar *password)
@@ -283,7 +270,7 @@ get_cert_password_flags (NMACertChooser *cert_chooser)
static void
cert_changed_cb (NMACertChooserButton *button, gpointer user_data)
{
- NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (user_data);
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (NMA_CERT_CHOOSER
(user_data));
GckUriData *uri_data;
gchar *pin = NULL;
const gchar *uri;
@@ -328,7 +315,7 @@ cert_changed_cb (NMACertChooserButton *button, gpointer user_data)
static void
key_changed_cb (NMACertChooserButton *button, gpointer user_data)
{
- NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (user_data);
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (NMA_CERT_CHOOSER
(user_data));
gchar *pin = NULL;
if (nma_cert_chooser_button_get_remember_pin (button))
@@ -359,7 +346,7 @@ cert_password_changed_cb (GtkEntry *entry, gpointer user_data)
static void
show_toggled_cb (GtkCheckButton *button, gpointer user_data)
{
- NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (user_data);
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (NMA_CERT_CHOOSER
(user_data));
gboolean active;
active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
@@ -420,138 +407,133 @@ set_flags (NMACertChooser *cert_chooser, NMACertChooserFlags flags)
}
static void
-nma_pkcs11_cert_chooser_class_init (NMAPkcs11CertChooserClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- NMACertChooserClass *chooser_class = NMA_CERT_CHOOSER_CLASS (klass);
-
- g_type_class_add_private (object_class, sizeof (NMAPkcs11CertChooserPrivate));
-
- chooser_class->set_title = set_title;
- chooser_class->set_flags = set_flags;
-
- chooser_class->set_cert_uri = set_cert_uri;
- chooser_class->get_cert_uri = get_cert_uri;
- chooser_class->set_cert_password = set_cert_password;
- chooser_class->get_cert_password = get_cert_password;
- chooser_class->set_key_uri = set_key_uri;
- chooser_class->get_key_uri = get_key_uri;
- chooser_class->set_key_password = set_key_password;
- chooser_class->get_key_password = get_key_password;
-
- chooser_class->add_to_size_group = add_to_size_group;
- chooser_class->validate = validate;
-
- chooser_class->setup_key_password_storage = setup_key_password_storage;
- chooser_class->update_key_password_storage = update_key_password_storage;
- chooser_class->get_key_password_flags = get_key_password_flags;
- chooser_class->setup_cert_password_storage = setup_cert_password_storage;
- chooser_class->update_cert_password_storage = update_cert_password_storage;
- chooser_class->get_cert_password_flags = get_cert_password_flags;
-}
-
-static void
-nma_pkcs11_cert_chooser_init (NMAPkcs11CertChooser *pkcs11_cert_chooser)
+init (NMACertChooser *cert_chooser)
{
- NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (pkcs11_cert_chooser);
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
GtkWidget *show_password;
- gtk_grid_insert_column (GTK_GRID (pkcs11_cert_chooser), 2);
- gtk_grid_set_row_spacing (GTK_GRID (pkcs11_cert_chooser), 6);
- gtk_grid_set_column_spacing (GTK_GRID (pkcs11_cert_chooser), 12);
+ gtk_grid_insert_column (GTK_GRID (cert_chooser), 2);
+ gtk_grid_set_row_spacing (GTK_GRID (cert_chooser), 6);
+ gtk_grid_set_column_spacing (GTK_GRID (cert_chooser), 12);
/* Show password */
- gtk_grid_insert_row (GTK_GRID (pkcs11_cert_chooser), 0);
+ gtk_grid_insert_row (GTK_GRID (cert_chooser), 0);
show_password = gtk_check_button_new_with_mnemonic ("Sho_w passwords");
- gtk_grid_attach (GTK_GRID (pkcs11_cert_chooser), show_password, 1, 2, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), show_password, 1, 2, 1, 1);
gtk_widget_show (show_password);
gtk_widget_set_no_show_all (show_password, TRUE);
g_signal_connect (show_password, "toggled",
- G_CALLBACK (show_toggled_cb), pkcs11_cert_chooser);
+ G_CALLBACK (show_toggled_cb), cert_chooser);
/* The key chooser */
- gtk_grid_insert_row (GTK_GRID (pkcs11_cert_chooser), 0);
+ gtk_grid_insert_row (GTK_GRID (cert_chooser), 0);
priv->key_button = nma_cert_chooser_button_new (NMA_CERT_CHOOSER_BUTTON_FLAG_KEY);
- gtk_grid_attach (GTK_GRID (pkcs11_cert_chooser), priv->key_button, 1, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->key_button, 1, 0, 1, 1);
gtk_widget_set_hexpand (priv->key_button, TRUE);
gtk_widget_set_sensitive (priv->key_button, FALSE);
gtk_widget_show (priv->key_button);
gtk_widget_set_no_show_all (priv->key_button, TRUE);
g_signal_connect (priv->key_button, "changed",
- G_CALLBACK (key_changed_cb), pkcs11_cert_chooser);
+ G_CALLBACK (key_changed_cb), cert_chooser);
priv->key_button_label = gtk_label_new (NULL);
g_object_set (priv->key_button_label, "xalign", (gfloat) 0, NULL);
gtk_label_set_mnemonic_widget (GTK_LABEL (priv->key_button_label), priv->key_button);
- gtk_grid_attach (GTK_GRID (pkcs11_cert_chooser), priv->key_button_label, 0, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->key_button_label, 0, 0, 1, 1);
gtk_widget_set_sensitive (priv->key_button_label, FALSE);
gtk_widget_show (priv->key_button_label);
gtk_widget_set_no_show_all (priv->key_button_label, TRUE);
/* The key password entry */
- gtk_grid_insert_row (GTK_GRID (pkcs11_cert_chooser), 1);
+ gtk_grid_insert_row (GTK_GRID (cert_chooser), 1);
priv->key_password = gtk_entry_new ();
gtk_entry_set_visibility (GTK_ENTRY (priv->key_password), FALSE);
- gtk_grid_attach (GTK_GRID (pkcs11_cert_chooser), priv->key_password, 1, 1, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->key_password, 1, 1, 1, 1);
gtk_widget_set_hexpand (priv->key_password, TRUE);
gtk_widget_set_sensitive (priv->key_password, FALSE);
gtk_widget_show (priv->key_password);
gtk_widget_set_no_show_all (priv->key_password, TRUE);
- g_signal_connect (priv->key_password, "changed",
- G_CALLBACK (key_password_changed_cb), pkcs11_cert_chooser);
+ g_signal_connect (priv->key_password, "changed",
+ G_CALLBACK (key_password_changed_cb), cert_chooser);
priv->key_password_label = gtk_label_new (NULL);
g_object_set (priv->key_password_label, "xalign", (gfloat) 0, NULL);
gtk_label_set_mnemonic_widget (GTK_LABEL (priv->key_password_label), priv->key_password);
- gtk_grid_attach (GTK_GRID (pkcs11_cert_chooser), priv->key_password_label, 0, 1, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->key_password_label, 0, 1, 1, 1);
gtk_widget_set_sensitive (priv->key_password_label, FALSE);
gtk_widget_show (priv->key_password_label);
gtk_widget_set_no_show_all (priv->key_password_label, TRUE);
/* The certificate chooser */
- gtk_grid_insert_row (GTK_GRID (pkcs11_cert_chooser), 0);
+ gtk_grid_insert_row (GTK_GRID (cert_chooser), 0);
priv->cert_button = nma_cert_chooser_button_new (NMA_CERT_CHOOSER_BUTTON_FLAG_NONE);
- gtk_grid_attach (GTK_GRID (pkcs11_cert_chooser), priv->cert_button, 1, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->cert_button, 1, 0, 1, 1);
gtk_widget_set_hexpand (priv->cert_button, TRUE);
gtk_widget_show (priv->cert_button);
gtk_widget_set_no_show_all (priv->cert_button, TRUE);
g_signal_connect (priv->cert_button, "changed",
- G_CALLBACK (cert_changed_cb), pkcs11_cert_chooser);
+ G_CALLBACK (cert_changed_cb), cert_chooser);
priv->cert_button_label = gtk_label_new (NULL);
g_object_set (priv->cert_button_label, "xalign", (gfloat) 0, NULL);
gtk_label_set_mnemonic_widget (GTK_LABEL (priv->cert_button_label), priv->cert_button);
- gtk_grid_attach (GTK_GRID (pkcs11_cert_chooser), priv->cert_button_label, 0, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->cert_button_label, 0, 0, 1, 1);
gtk_widget_show (priv->cert_button_label);
gtk_widget_set_no_show_all (priv->cert_button_label, TRUE);
/* The cert password entry */
- gtk_grid_insert_row (GTK_GRID (pkcs11_cert_chooser), 1);
+ gtk_grid_insert_row (GTK_GRID (cert_chooser), 1);
priv->cert_password = gtk_entry_new ();
gtk_entry_set_visibility (GTK_ENTRY (priv->cert_password), FALSE);
- gtk_grid_attach (GTK_GRID (pkcs11_cert_chooser), priv->cert_password, 1, 1, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->cert_password, 1, 1, 1, 1);
gtk_widget_set_hexpand (priv->cert_password, TRUE);
gtk_widget_set_sensitive (priv->cert_password, FALSE);
gtk_widget_show (priv->cert_password);
gtk_widget_set_no_show_all (priv->cert_password, TRUE);
- g_signal_connect (priv->cert_password, "changed",
- G_CALLBACK (cert_password_changed_cb), pkcs11_cert_chooser);
+ g_signal_connect (priv->cert_password, "changed",
+ G_CALLBACK (cert_password_changed_cb), cert_chooser);
priv->cert_password_label = gtk_label_new (NULL);
g_object_set (priv->cert_password_label, "xalign", (gfloat) 0, NULL);
gtk_label_set_mnemonic_widget (GTK_LABEL (priv->cert_password_label), priv->cert_password);
- gtk_grid_attach (GTK_GRID (pkcs11_cert_chooser), priv->cert_password_label, 0, 1, 1, 1);
+ gtk_grid_attach (GTK_GRID (cert_chooser), priv->cert_password_label, 0, 1, 1, 1);
gtk_widget_set_sensitive (priv->cert_password_label, FALSE);
gtk_widget_show (priv->cert_password_label);
gtk_widget_set_no_show_all (priv->cert_password_label, TRUE);
}
+
+const NMACertChooserVtable nma_cert_chooser_vtable_pkcs11 = {
+ .init = init,
+
+ .set_title = set_title,
+ .set_flags = set_flags,
+ .set_cert_uri = set_cert_uri,
+ .get_cert_uri = get_cert_uri,
+
+ .set_cert_password = set_cert_password,
+ .get_cert_password = get_cert_password,
+ .set_key_uri = set_key_uri,
+ .get_key_uri = get_key_uri,
+ .set_key_password = set_key_password,
+ .get_key_password = get_key_password,
+
+ .add_to_size_group = add_to_size_group,
+ .validate = validate,
+
+ .setup_key_password_storage = setup_key_password_storage,
+ .update_key_password_storage = update_key_password_storage,
+ .get_key_password_flags = get_key_password_flags,
+ .setup_cert_password_storage = setup_cert_password_storage,
+ .update_cert_password_storage = update_cert_password_storage,
+ .get_cert_password_flags = get_cert_password_flags,
+};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]