gnome-keyring [PATCH 3/9] ui: add row widget for PKCS#11 token sidebar
- From: Lubomir Rintel <lkundrak v3 sk>
- To: gnome-keyring-list gnome org
- Cc: David Woodhouse <dwmw2 infradead org>, Prashant Tyagi <prashanttyagi221295 gmail com>, Lubomir Rintel <lkundrak v3 sk>
- Subject: gnome-keyring [PATCH 3/9] ui: add row widget for PKCS#11 token sidebar
- Date: Tue, 13 Dec 2016 19:20:04 +0100
For internal use by the PKCS#11 token sidebar.
---
po/POTFILES.in | 1 +
ui/Makefile.am | 2 +
ui/gcr-tokens-sidebar-row.c | 212 +++++++++++++++++++++++++++++++++++++++++++
ui/gcr-tokens-sidebar-row.h | 39 ++++++++
ui/gcr-tokens-sidebar-row.ui | 97 ++++++++++++++++++++
ui/gcr-ui.symbols | 3 +
ui/gcr.gresource.xml | 1 +
7 files changed, 355 insertions(+)
create mode 100644 ui/gcr-tokens-sidebar-row.c
create mode 100644 ui/gcr-tokens-sidebar-row.h
create mode 100644 ui/gcr-tokens-sidebar-row.ui
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a57d084..5afd4f2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -34,6 +34,7 @@ ui/gcr-prompt-dialog.c
ui/gcr-prompter.desktop.in.in
ui/gcr-token-login-dialog.c
[type: gettext/glade]ui/gcr-token-login-dialog.ui
+ui/gcr-tokens-sidebar-row.c
ui/gcr-certificate-exporter.c
[type: gettext/glade]ui/gcr-unlock-options-widget.ui
ui/gcr-unlock-renderer.c
diff --git a/ui/Makefile.am b/ui/Makefile.am
index 0b515ff..12fdd5f 100644
--- a/ui/Makefile.am
+++ b/ui/Makefile.am
@@ -63,6 +63,7 @@ ui_HEADER_FILES = \
ui/gcr-renderer.h \
ui/gcr-secure-entry-buffer.h \
ui/gcr-token-login-dialog.h \
+ ui/gcr-tokens-sidebar-row.h \
ui/gcr-tree-selector.h \
ui/gcr-unlock-options-widget.h \
ui/gcr-viewer.h \
@@ -109,6 +110,7 @@ ui_PRIVATE_FILES = \
ui/gcr-pkcs11-import-dialog.c ui/gcr-pkcs11-import-dialog.h \
ui/gcr-pkcs11-import-interaction.c ui/gcr-pkcs11-import-interaction.h \
ui/gcr-token-login-dialog.c ui/gcr-token-login-dialog.h \
+ ui/gcr-tokens-sidebar-row.c ui/gcr-tokens-sidebar-row.h \
ui/gcr-unlock-renderer.c ui/gcr-unlock-renderer.h \
ui/gcr-viewer-window.c ui/gcr-viewer-window.h \
$(NULL)
diff --git a/ui/gcr-tokens-sidebar-row.c b/ui/gcr-tokens-sidebar-row.c
new file mode 100644
index 0000000..4c9229a
--- /dev/null
+++ b/ui/gcr-tokens-sidebar-row.c
@@ -0,0 +1,212 @@
+/*
+ * Copyright (C) 2016 Lubomir Rintel
+ *
+ * This program 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gcr-tokens-sidebar-row.h"
+
+#include <glib/gi18n.h>
+#include <gck/gck.h>
+
+/**
+ * SECTION:gcr-tokens-sidebar-row
+ * @title: GcrTokensSidebarRow
+ * @short_description: The PKCS11 Tokens Sidebar Row
+ * @see_also: #GcrTokensSidebarRow
+ *
+ * #GcrTokensSidebarRow is the tokens sidebar row widget.
+ */
+
+enum {
+ TOKEN_LOGIN,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+struct _GcrTokensSidebarRowPrivate
+{
+ GckSlot *slot;
+ GtkEventBox *event_box;
+ GtkImage *icon_widget;
+ GtkLabel *label_widget;
+ GtkButton *login_button;
+};
+
+G_DEFINE_TYPE_WITH_CODE (GcrTokensSidebarRow, gcr_tokens_sidebar_row, GTK_TYPE_LIST_BOX_ROW,
+ G_ADD_PRIVATE (GcrTokensSidebarRow));
+
+enum
+{
+ PROP_0,
+ PROP_SLOT,
+};
+
+static void
+get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ GcrTokensSidebarRow *self = GCR_TOKENS_SIDEBAR_ROW (object);
+ GcrTokensSidebarRowPrivate *priv = self->priv;
+
+ switch (prop_id) {
+ case PROP_SLOT:
+ if (priv->slot)
+ g_value_set_object (value, priv->slot);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ GcrTokensSidebarRow *self = GCR_TOKENS_SIDEBAR_ROW (object);
+ GcrTokensSidebarRowPrivate *priv = self->priv;
+ gboolean needs_login = FALSE;
+
+ switch (prop_id) {
+ case PROP_SLOT:
+ /* Construct only. */
+ priv->slot = g_value_dup_object (value);
+
+ if (priv->slot) {
+ GckTokenInfo *info;
+
+ info = gck_slot_get_token_info (priv->slot);
+ g_return_if_fail (info);
+ gtk_label_set_text (priv->label_widget, info->label);
+ needs_login = info->flags & CKF_LOGIN_REQUIRED;
+ gck_token_info_free (info);
+ } else {
+ gtk_widget_hide (GTK_WIDGET (priv->icon_widget));
+ gtk_widget_set_no_show_all (GTK_WIDGET (priv->icon_widget), TRUE);
+ gtk_label_set_markup (priv->label_widget, _("<b>All tokens</b>"));
+ }
+
+ if (!needs_login) {
+ gtk_widget_hide (GTK_WIDGET (priv->login_button));
+ gtk_widget_set_no_show_all (GTK_WIDGET (priv->login_button), TRUE);
+ }
+
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+finalize (GObject *object)
+{
+ GcrTokensSidebarRow *self = GCR_TOKENS_SIDEBAR_ROW (object);
+ GcrTokensSidebarRowPrivate *priv = self->priv;
+
+ g_clear_object (&priv->slot);
+
+ G_OBJECT_CLASS (gcr_tokens_sidebar_row_parent_class)->finalize (object);
+}
+
+
+static void
+login_clicked (GtkButton *button, gpointer user_data)
+{
+ GcrTokensSidebarRow *self = GCR_TOKENS_SIDEBAR_ROW (user_data);
+
+ g_signal_emit (self, signals[TOKEN_LOGIN], 0);
+}
+
+static void
+gcr_tokens_sidebar_row_class_init (GcrTokensSidebarRowClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->get_property = get_property;
+ object_class->set_property = set_property;
+ object_class->finalize = finalize;
+
+ /**
+ * GcrTokensSidebarRowClass::token-login:
+ *
+ * Emitted with the login button is clicked.
+ */
+ signals[TOKEN_LOGIN] = g_signal_new ("token-login",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ /**
+ * GcrTokensSidebarRowClass::slot:
+ *
+ * The PKCS#11 slot or %NULL for all slots.
+ */
+ g_object_class_install_property (object_class, PROP_SLOT,
+ g_param_spec_object ("slot", "Slot", "PKCS#11 Slot",
+ GCK_TYPE_SLOT,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/gcr/ui/gcr-tokens-sidebar-row.ui");
+
+ gtk_widget_class_bind_template_child_private (widget_class, GcrTokensSidebarRow, event_box);
+ gtk_widget_class_bind_template_child_private (widget_class, GcrTokensSidebarRow, icon_widget);
+ gtk_widget_class_bind_template_child_private (widget_class, GcrTokensSidebarRow, label_widget);
+ gtk_widget_class_bind_template_child_private (widget_class, GcrTokensSidebarRow, login_button);
+ gtk_widget_class_bind_template_callback (widget_class, login_clicked);
+
+ gtk_widget_class_set_css_name (widget_class, "row");
+}
+
+static void
+gcr_tokens_sidebar_row_init (GcrTokensSidebarRow *self)
+{
+ self->priv = gcr_tokens_sidebar_row_get_instance_private (self);
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+/**
+ * gcr_tokens_sidebar_row_get_slot:
+ * @self: The #GcrTokensSidebarRow
+ *
+ * The slot getter.
+ *
+ * Returns: the associated slot, or %NULL
+ */
+GckSlot *
+gcr_tokens_sidebar_row_get_slot (GcrTokensSidebarRow *self)
+{
+ GcrTokensSidebarRowPrivate *priv = self->priv;
+
+ return priv->slot;
+}
+
+/**
+ * gcr_tokens_sidebar_row_new:
+ * @slot: the associated %slot
+ *
+ * Creates the new #GcrTokensSidebarRow for given slot.
+ * If %NULL is given for the slot, then the "All slots" row
+ * is created.
+ *
+ * Returns: the newly created #GcrTokensSidebarRow
+ */
+GtkWidget *
+gcr_tokens_sidebar_row_new (GckSlot *slot)
+{
+ return GTK_WIDGET (g_object_new (GCR_TYPE_TOKENS_SIDEBAR_ROW,
+ "slot", slot, NULL));
+}
diff --git a/ui/gcr-tokens-sidebar-row.h b/ui/gcr-tokens-sidebar-row.h
new file mode 100644
index 0000000..56b7cd9
--- /dev/null
+++ b/ui/gcr-tokens-sidebar-row.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2016 Lubomir Rintel
+ *
+ * This program 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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 program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GCR_TOKENS_SIDEBAR_ROW_H__
+#define __GCR_TOKENS_SIDEBAR_ROW_H__
+
+#include <gtk/gtk.h>
+#include <gck/gck.h>
+
+typedef struct _GcrTokensSidebarRowPrivate GcrTokensSidebarRowPrivate;
+
+struct _GcrTokensSidebarRow
+{
+ GtkListBoxRow parent_instance;
+ GcrTokensSidebarRowPrivate *priv;
+};
+
+#define GCR_TYPE_TOKENS_SIDEBAR_ROW gcr_tokens_sidebar_row_get_type ()
+G_DECLARE_FINAL_TYPE (GcrTokensSidebarRow, gcr_tokens_sidebar_row, GCR, TOKENS_SIDEBAR_ROW, GtkListBoxRow);
+
+GtkWidget *gcr_tokens_sidebar_row_new (GckSlot *slot);
+
+GckSlot *gcr_tokens_sidebar_row_get_slot (GcrTokensSidebarRow *self);
+
+#endif /* __GCR_TOKENS_SIDEBAR_ROW_H__ */
diff --git a/ui/gcr-tokens-sidebar-row.ui b/ui/gcr-tokens-sidebar-row.ui
new file mode 100644
index 0000000..c27d494
--- /dev/null
+++ b/ui/gcr-tokens-sidebar-row.ui
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface domain="gtk30">
+ <requires lib="gtk+" version="3.10"/>
+ <template class="GcrTokensSidebarRow" parent="GtkListBoxRow">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_top">1</property>
+ <property name="margin_bottom">1</property>
+ <child>
+ <object class="GtkRevealer" id="revealer">
+ <property name="visible">1</property>
+ <property name="reveal-child">1</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkEventBox" id="event_box">
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkBox">
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkImage" id="icon_widget">
+ <property name="can_focus">False</property>
+ <property name="icon_name">media-flash-symbolic</property>
+ <style>
+ <class name="sidebar-icon"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_widget">
+ <property name="can_focus">False</property>
+ <property name="hexpand">False</property>
+ <property name="xalign">0</property>
+ <style>
+ <class name="sidebar-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="login_button">
+ <property name="can_focus">False</property>
+ <property name="receives_default">False</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="margin_start">4</property>
+ <signal name="clicked" handler="login_clicked" swapped="no"/>
+ <child>
+ <object class="GtkImage">
+ <property name="can_focus">False</property>
+ <property name="icon_name">dialog-password-symbolic</property>
+ <property name="icon_size">1</property>
+ </object>
+ </child>
+ <style>
+ <class name="image-button"/>
+ <class name="sidebar-button"/>
+ </style>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <style>
+ <class name="sidebar-revealer"/>
+ </style>
+ </object>
+ </child>
+ <style>
+ <class name="sidebar-row"/>
+ </style>
+ </template>
+ <object class="GtkSizeGroup">
+ <property name="mode">vertical</property>
+ <widgets>
+ <widget name="login_button"/>
+ <widget name="label_widget"/>
+ <widget name="icon_widget"/>
+ </widgets>
+ </object>
+</interface>
diff --git a/ui/gcr-ui.symbols b/ui/gcr-ui.symbols
index c7640e1..85db159 100644
--- a/ui/gcr-ui.symbols
+++ b/ui/gcr-ui.symbols
@@ -80,6 +80,9 @@ gcr_token_login_dialog_get_pin_value
gcr_token_login_dialog_get_remember_pin
gcr_token_login_dialog_get_type
gcr_token_login_dialog_new
+gcr_tokens_sidebar_row_get_slot
+gcr_tokens_sidebar_row_get_type
+gcr_tokens_sidebar_row_new
gcr_tree_selector_get_collection
gcr_tree_selector_get_columns
gcr_tree_selector_get_selected
diff --git a/ui/gcr.gresource.xml b/ui/gcr.gresource.xml
index 9e98153..00fdc53 100644
--- a/ui/gcr.gresource.xml
+++ b/ui/gcr.gresource.xml
@@ -4,5 +4,6 @@
<file preprocess="xml-stripblanks">gcr-pkcs11-import-dialog.ui</file>
<file preprocess="xml-stripblanks">gcr-unlock-options-widget.ui</file>
<file preprocess="xml-stripblanks">gcr-token-login-dialog.ui</file>
+ <file preprocess="xml-stripblanks">gcr-tokens-sidebar-row.ui</file>
</gresource>
</gresources>
--
2.9.3
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]