[network-manager-applet/lr/pkcs11: 21/21] fixup! libnma: add the PKCS#11 capable certificate chooser
- From: Lubomir Rintel <lkundrak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/lr/pkcs11: 21/21] fixup! libnma: add the PKCS#11 capable certificate chooser
- Date: Tue, 7 Mar 2017 12:29:00 +0000 (UTC)
commit 0dcafc741b2ca96d28a8f111c1b91483d97b5d94
Author: Lubomir Rintel <lkundrak v3 sk>
Date: Tue Mar 7 12:33:17 2017 +0100
fixup! libnma: add the PKCS#11 capable certificate chooser
Restructure to reflect that the NMACertChooser is a class. In
particular, separate the widget tree construction from setting of its
properties -- title and flags that affect widget visibility.
src/libnma/nma-pkcs11-cert-chooser.c | 273 ++++++++++++++++++----------------
src/libnma/nma-pkcs11-cert-chooser.h | 6 +-
2 files changed, 146 insertions(+), 133 deletions(-)
---
diff --git a/src/libnma/nma-pkcs11-cert-chooser.c b/src/libnma/nma-pkcs11-cert-chooser.c
index 2c77fa0..ddf00a0 100644
--- a/src/libnma/nma-pkcs11-cert-chooser.c
+++ b/src/libnma/nma-pkcs11-cert-chooser.c
@@ -32,8 +32,6 @@
#include <fcntl.h>
#include <errno.h>
-static void nma_cert_chooser_interface_init (NMACertChooserInterface *iface);
-
typedef struct {
GtkWidget *key_button_label;
GtkWidget *key_password_label;
@@ -47,9 +45,7 @@ typedef struct {
#define NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o),
NMA_TYPE_PKCS11_CERT_CHOOSER, NMAPkcs11CertChooserPrivate))
-G_DEFINE_TYPE_WITH_CODE (NMAPkcs11CertChooser, nma_pkcs11_cert_chooser, GTK_TYPE_GRID,
- G_IMPLEMENT_INTERFACE (NMA_TYPE_CERT_CHOOSER,
- nma_cert_chooser_interface_init))
+G_DEFINE_TYPE (NMAPkcs11CertChooser, nma_pkcs11_cert_chooser, NMA_TYPE_CERT_CHOOSER)
static void
set_key_password (NMACertChooser *cert_chooser, const gchar *password)
@@ -330,29 +326,6 @@ get_cert_password_flags (NMACertChooser *cert_chooser)
}
static void
-nma_cert_chooser_interface_init (NMACertChooserInterface *iface)
-{
- iface->set_cert = set_cert;
- iface->get_cert = get_cert;
- iface->set_cert_password = set_cert_password;
- iface->get_cert_password = get_cert_password;
- iface->set_key = set_key;
- iface->get_key = get_key;
- iface->set_key_password = set_key_password;
- iface->get_key_password = get_key_password;
-
- iface->add_to_size_group = add_to_size_group;
- iface->validate = validate;
-
- iface->setup_key_password_storage = setup_key_password_storage;
- iface->update_key_password_storage = update_key_password_storage;
- iface->get_key_password_flags = get_key_password_flags;
- iface->setup_cert_password_storage = setup_cert_password_storage;
- iface->update_cert_password_storage = update_cert_password_storage;
- iface->get_cert_password_flags = get_cert_password_flags;
-}
-
-static void
cert_changed_cb (NMACertChooserButton *button, gpointer user_data)
{
NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (user_data);
@@ -440,139 +413,181 @@ show_toggled_cb (GtkCheckButton *button, gpointer user_data)
gtk_entry_set_visibility (GTK_ENTRY (priv->key_password), active);
}
-GtkWidget *
-nma_pkcs11_cert_chooser_new (const gchar *title, NMACertChooserFlags flags)
+static void
+set_title (NMACertChooser *cert_chooser, const gchar *title)
{
- GtkWidget *self;
- NMAPkcs11CertChooserPrivate *priv;
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
gchar *text;
- GtkWidget *show_password;
- self = g_object_new (NMA_TYPE_PKCS11_CERT_CHOOSER, NULL);
- priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (self);
+ text = g_strdup_printf (_("Choose a key for %s Certificate"), title);
+ nma_cert_chooser_button_set_title (NMA_CERT_CHOOSER_BUTTON (priv->key_button), text);
+ g_free (text);
+
+ text = g_strdup_printf (_("%s private _key:"), title);
+ gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->key_button_label), text);
+ g_free (text);
+
+ text = g_strdup_printf (_("%s key _password:"), title);
+ gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->key_password_label), text);
+ g_free (text);
+
+ text = g_strdup_printf (_("Choose a %s Certificate"), title);
+ nma_cert_chooser_button_set_title (NMA_CERT_CHOOSER_BUTTON (priv->cert_button), text);
+ g_free (text);
+
+ text = g_strdup_printf (_("%s _certificate:"), title);
+ gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->cert_button_label), text);
+ g_free (text);
+
+ text = g_strdup_printf (_("%s certificate _password:"), title);
+ gtk_label_set_text_with_mnemonic (GTK_LABEL (priv->cert_password_label), text);
+ g_free (text);
+}
+
+static void
+set_flags (NMACertChooser *cert_chooser, NMACertChooserFlags flags)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (cert_chooser);
+
+ if (flags & NMA_CERT_CHOOSER_FLAG_CERT) {
+ gtk_widget_hide (priv->key_button);
+ gtk_widget_hide (priv->key_button_label);
+ gtk_widget_hide (priv->key_password);
+ gtk_widget_hide (priv->key_password_label);
+ }
+
+ if (flags & NMA_CERT_CHOOSER_FLAG_PASSWORDS) {
+ gtk_widget_hide (priv->cert_button);
+ gtk_widget_hide (priv->cert_button_label);
+ gtk_widget_hide (priv->key_button);
+ gtk_widget_hide (priv->key_button_label);
+ }
+}
+
+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 = set_cert;
+ chooser_class->get_cert = get_cert;
+ chooser_class->set_cert_password = set_cert_password;
+ chooser_class->get_cert_password = get_cert_password;
+ chooser_class->set_key = set_key;
+ chooser_class->get_key = get_key;
+ 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)
+{
+ NMAPkcs11CertChooserPrivate *priv = NMA_PKCS11_CERT_CHOOSER_GET_PRIVATE (pkcs11_cert_chooser);
+ GtkWidget *show_password;
- gtk_grid_insert_column (GTK_GRID (self), 2);
- gtk_grid_set_row_spacing (GTK_GRID (self), 6);
- gtk_grid_set_column_spacing (GTK_GRID (self), 12);
+ 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);
/* Show password */
- gtk_grid_insert_row (GTK_GRID (self), 0);
+ gtk_grid_insert_row (GTK_GRID (pkcs11_cert_chooser), 0);
show_password = gtk_check_button_new_with_mnemonic ("Sho_w passwords");
- gtk_grid_attach (GTK_GRID (self), show_password, 1, 2, 1, 1);
+ gtk_grid_attach (GTK_GRID (pkcs11_cert_chooser), show_password, 1, 2, 1, 1);
gtk_widget_show (show_password);
g_signal_connect (show_password, "toggled",
- G_CALLBACK (show_toggled_cb), self);
-
- if ((flags & NMA_CERT_CHOOSER_FLAG_CERT) == 0) {
- /* The key chooser */
- gtk_grid_insert_row (GTK_GRID (self), 0);
-
- text = g_strdup_printf (_("Choose a key for %s certificate"), title);
- priv->key_button = nma_cert_chooser_button_new (text,
- NMA_CERT_CHOOSER_BUTTON_FLAG_KEY);
- g_free (text);
-
- gtk_grid_attach (GTK_GRID (self), priv->key_button, 1, 0, 1, 1);
- gtk_widget_set_hexpand (priv->key_button, TRUE);
- gtk_widget_set_sensitive (priv->key_button, FALSE);
- if ((flags & NMA_CERT_CHOOSER_FLAG_PASSWORDS) == 0)
- gtk_widget_show (priv->key_button);
-
- g_signal_connect (priv->key_button, "changed",
- G_CALLBACK (key_changed_cb), self);
-
- text = g_strdup_printf (_("%s private _key:"), title);
- priv->key_button_label = gtk_label_new_with_mnemonic (text);
- 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 (self), priv->key_button_label, 0, 0, 1, 1);
- gtk_widget_set_sensitive (priv->key_button_label, FALSE);
- if ((flags & NMA_CERT_CHOOSER_FLAG_PASSWORDS) == 0)
- gtk_widget_show (priv->key_button_label);
- g_free (text);
-
- /* The key password entry */
- gtk_grid_insert_row (GTK_GRID (self), 1);
-
- priv->key_password = gtk_entry_new ();
- gtk_entry_set_visibility (GTK_ENTRY (priv->key_password), FALSE);
- gtk_grid_attach (GTK_GRID (self), 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);
-
- g_signal_connect (priv->key_password, "changed",
- G_CALLBACK (key_password_changed_cb), self);
-
- text = g_strdup_printf (_("%s key _password:"), title);
- priv->key_password_label = gtk_label_new_with_mnemonic (text);
- 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 (self), priv->key_password_label, 0, 1, 1, 1);
- gtk_widget_set_sensitive (priv->key_password_label, FALSE);
- gtk_widget_show (priv->key_password_label);
- g_free (text);
- }
+ G_CALLBACK (show_toggled_cb), pkcs11_cert_chooser);
+
+ /* The key chooser */
+ gtk_grid_insert_row (GTK_GRID (pkcs11_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_widget_set_hexpand (priv->key_button, TRUE);
+ gtk_widget_set_sensitive (priv->key_button, FALSE);
+ gtk_widget_show (priv->key_button);
+
+ g_signal_connect (priv->key_button, "changed",
+ G_CALLBACK (key_changed_cb), pkcs11_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_widget_set_sensitive (priv->key_button_label, FALSE);
+ gtk_widget_show (priv->key_button_label);
+
+ /* The key password entry */
+ gtk_grid_insert_row (GTK_GRID (pkcs11_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_widget_set_hexpand (priv->key_password, TRUE);
+ gtk_widget_set_sensitive (priv->key_password, FALSE);
+ gtk_widget_show (priv->key_password);
+
+ g_signal_connect (priv->key_password, "changed",
+ G_CALLBACK (key_password_changed_cb), pkcs11_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_widget_set_sensitive (priv->key_password_label, FALSE);
+ gtk_widget_show (priv->key_password_label);
/* The certificate chooser */
- gtk_grid_insert_row (GTK_GRID (self), 0);
+ gtk_grid_insert_row (GTK_GRID (pkcs11_cert_chooser), 0);
- text = g_strdup_printf (_("Choose %s certificate"), title);
- priv->cert_button = nma_cert_chooser_button_new (text,
- NMA_CERT_CHOOSER_BUTTON_FLAG_NONE);
- g_free (text);
+ priv->cert_button = nma_cert_chooser_button_new (NMA_CERT_CHOOSER_BUTTON_FLAG_NONE);
- gtk_grid_attach (GTK_GRID (self), priv->cert_button, 1, 0, 1, 1);
+ gtk_grid_attach (GTK_GRID (pkcs11_cert_chooser), priv->cert_button, 1, 0, 1, 1);
gtk_widget_set_hexpand (priv->cert_button, TRUE);
- if ((flags & NMA_CERT_CHOOSER_FLAG_PASSWORDS) == 0)
- gtk_widget_show (priv->cert_button);
+ gtk_widget_show (priv->cert_button);
g_signal_connect (priv->cert_button, "changed",
- G_CALLBACK (cert_changed_cb), self);
+ G_CALLBACK (cert_changed_cb), pkcs11_cert_chooser);
- text = g_strdup_printf (_("%s _certificate:"), title);
- priv->cert_button_label = gtk_label_new_with_mnemonic (text);
+ 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 (self), priv->cert_button_label, 0, 0, 1, 1);
- if ((flags & NMA_CERT_CHOOSER_FLAG_PASSWORDS) == 0)
- gtk_widget_show (priv->cert_button_label);
- g_free (text);
+ gtk_grid_attach (GTK_GRID (pkcs11_cert_chooser), priv->cert_button_label, 0, 0, 1, 1);
+ gtk_widget_show (priv->cert_button_label);
/* The cert password entry */
- gtk_grid_insert_row (GTK_GRID (self), 1);
+ gtk_grid_insert_row (GTK_GRID (pkcs11_cert_chooser), 1);
priv->cert_password = gtk_entry_new ();
gtk_entry_set_visibility (GTK_ENTRY (priv->cert_password), FALSE);
- gtk_grid_attach (GTK_GRID (self), priv->cert_password, 1, 1, 1, 1);
+ gtk_grid_attach (GTK_GRID (pkcs11_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);
g_signal_connect (priv->cert_password, "changed",
- G_CALLBACK (cert_password_changed_cb), self);
+ G_CALLBACK (cert_password_changed_cb), pkcs11_cert_chooser);
- text = g_strdup_printf (_("%s certificate _password:"), title);
- priv->cert_password_label = gtk_label_new_with_mnemonic (text);
+ 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 (self), priv->cert_password_label, 0, 1, 1, 1);
+ gtk_grid_attach (GTK_GRID (pkcs11_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);
- g_free (text);
-
- return self;
-}
-
-static void
-nma_pkcs11_cert_chooser_class_init (NMAPkcs11CertChooserClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- g_type_class_add_private (object_class, sizeof (NMAPkcs11CertChooserPrivate));
-}
-
-static void
-nma_pkcs11_cert_chooser_init (NMAPkcs11CertChooser *pkcs11_cert_chooser)
-{
}
diff --git a/src/libnma/nma-pkcs11-cert-chooser.h b/src/libnma/nma-pkcs11-cert-chooser.h
index bafa892..29971a5 100644
--- a/src/libnma/nma-pkcs11-cert-chooser.h
+++ b/src/libnma/nma-pkcs11-cert-chooser.h
@@ -36,17 +36,15 @@ G_BEGIN_DECLS
#define NMA_PKCS11_CERT_CHOOSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
NMA_TYPE_PKCS11_CERT_CHOOSER, NMAPkcs11CertChooserClass))
typedef struct {
- GtkGrid parent;
+ NMACertChooser parent;
} NMAPkcs11CertChooser;
typedef struct {
- GtkGridClass parent_class;
+ NMACertChooserClass parent_class;
} NMAPkcs11CertChooserClass;
GType nma_pkcs11_cert_chooser_get_type (void);
-GtkWidget *nma_pkcs11_cert_chooser_new (const gchar *title, NMACertChooserFlags flags);
-
G_END_DECLS
#endif /* NMA_PKCS11_CERT_CHOOSER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]