gnome-keyring [PATCH 7/9] ui: add PKCS#11 object chooser dialog



---
 ui/Makefile.am                  |   2 +
 ui/gcr-object-chooser-dialog.c  | 168 ++++++++++++++++++++++++++++++++++++++++
 ui/gcr-object-chooser-dialog.h  |  40 ++++++++++
 ui/gcr-object-chooser-dialog.ui |  44 +++++++++++
 ui/gcr-ui.symbols               |   2 +
 ui/gcr.gresource.xml            |   1 +
 6 files changed, 257 insertions(+)
 create mode 100644 ui/gcr-object-chooser-dialog.c
 create mode 100644 ui/gcr-object-chooser-dialog.h
 create mode 100644 ui/gcr-object-chooser-dialog.ui

diff --git a/ui/Makefile.am b/ui/Makefile.am
index 86e22e4..74709b8 100644
--- a/ui/Makefile.am
+++ b/ui/Makefile.am
@@ -59,6 +59,7 @@ ui_HEADER_FILES = \
        ui/gcr-key-widget.h \
        ui/gcr-import-button.h \
        ui/gcr-list-selector.h \
+       ui/gcr-object-chooser-dialog.h \
        ui/gcr-object-chooser.h \
        ui/gcr-object-chooser-widget.h \
        ui/gcr-prompt-dialog.h \
@@ -87,6 +88,7 @@ ui_PUBLIC_FILES = \
        ui/gcr-import-button.c  ui/gcr-import-button.h \
        ui/gcr-list-selector.c ui/gcr-list-selector.h \
        ui/gcr-object-chooser.c ui/gcr-object-chooser.h \
+       ui/gcr-object-chooser-dialog.c ui/gcr-object-chooser-dialog.h \
        ui/gcr-prompt-dialog.c ui/gcr-prompt-dialog.h \
        ui/gcr-renderer.c ui/gcr-renderer.h \
        ui/gcr-secure-entry-buffer.c ui/gcr-secure-entry-buffer.h \
diff --git a/ui/gcr-object-chooser-dialog.c b/ui/gcr-object-chooser-dialog.c
new file mode 100644
index 0000000..a37fd73
--- /dev/null
+++ b/ui/gcr-object-chooser-dialog.c
@@ -0,0 +1,168 @@
+/*
+ * 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-object-chooser-dialog.h"
+#include "gcr-object-chooser-widget.h"
+
+#include <gtk/gtk.h>
+
+/**
+ * SECTION:gcr-object-chooser-dialog
+ * @title: GcrObjectChooserDialog
+ * @short_description: The PKCS11 Object Chooser Dialog
+ * @see_also: #GcrObjectChooser
+ *
+ * #GcrObjectChooserDialog is the PKCS11 object chooser dialog.
+ */
+
+struct _GcrObjectChooserDialogPrivate
+{
+       GcrObjectChooserWidget *chooser_widget;
+};
+
+static void gcr_object_chooser_iface_init (GcrObjectChooserInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GcrObjectChooserDialog, gcr_object_chooser_dialog, GTK_TYPE_DIALOG,
+                         G_ADD_PRIVATE (GcrObjectChooserDialog)
+                         G_IMPLEMENT_INTERFACE (GCR_TYPE_OBJECT_CHOOSER, gcr_object_chooser_iface_init));
+
+static void
+object_selected (GcrObjectChooser *chooser, GcrObjectChooserDialog *self)
+{
+       GcrObjectChooserDialogPrivate *priv = GCR_OBJECT_CHOOSER_DIALOG (self)->priv;
+       gchar *uri;
+
+       uri = gcr_object_chooser_get_uri (GCR_OBJECT_CHOOSER (priv->chooser_widget));
+       gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT, uri != NULL);
+       g_free (uri);
+}
+
+static void
+object_activated (GcrObjectChooser *chooser, GcrObjectChooserDialog *self)
+{
+       if (gtk_window_activate_default (GTK_WINDOW (self)))
+               return;
+}
+
+static void
+set_uri (GcrObjectChooser *self, const gchar *uri)
+{
+       GcrObjectChooserDialogPrivate *priv = GCR_OBJECT_CHOOSER_DIALOG (self)->priv;
+
+       return gcr_object_chooser_set_uri (GCR_OBJECT_CHOOSER (priv->chooser_widget), uri);
+}
+
+static gchar *
+get_uri (GcrObjectChooser *self)
+{
+       GcrObjectChooserDialogPrivate *priv = GCR_OBJECT_CHOOSER_DIALOG (self)->priv;
+
+       return gcr_object_chooser_get_uri (GCR_OBJECT_CHOOSER (priv->chooser_widget));
+}
+
+static void
+gcr_object_chooser_iface_init (GcrObjectChooserInterface *iface)
+{
+       iface->set_uri = set_uri;
+       iface->get_uri = get_uri;
+}
+
+static void
+gcr_object_chooser_dialog_class_init (GcrObjectChooserDialogClass *klass)
+{
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+       g_type_ensure (GCR_TYPE_OBJECT_CHOOSER_WIDGET);
+       gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/gcr/ui/gcr-object-chooser-dialog.ui");
+
+       gtk_widget_class_bind_template_child_private (widget_class, GcrObjectChooserDialog, chooser_widget);
+       gtk_widget_class_bind_template_callback (widget_class, object_selected);
+       gtk_widget_class_bind_template_callback (widget_class, object_activated);
+}
+
+static void
+gcr_object_chooser_dialog_init (GcrObjectChooserDialog *self)
+{
+       GcrObjectChooserDialogPrivate *priv;
+
+       self->priv = gcr_object_chooser_dialog_get_instance_private (self);
+       priv = self->priv;
+
+       gtk_widget_init_template (GTK_WIDGET (self));
+       g_object_set (G_OBJECT (priv->chooser_widget), "parent-window", self, NULL);
+       gtk_widget_show_all (GTK_WIDGET (priv->chooser_widget));
+}
+
+static GtkWidget *
+gcr_object_chooser_dialog_new_valist (const gchar *title, GtkWindow *parent,
+                                      GtkDialogFlags flags,
+                                      const gchar *first_button_text,
+                                      va_list varargs)
+{
+       GtkWidget *self;
+       const char *button_text = first_button_text;
+       gint response_id;
+
+       self = g_object_new (GCR_TYPE_OBJECT_CHOOSER_DIALOG,
+                              "use-header-bar", !!(flags & GTK_DIALOG_USE_HEADER_BAR),
+                              "title", title,
+                              NULL);
+
+       if (parent)
+               gtk_window_set_transient_for (GTK_WINDOW (self), parent);
+
+       while (button_text) {
+               response_id = va_arg (varargs, gint);
+               gtk_dialog_add_button (GTK_DIALOG (self), button_text, response_id);
+               button_text = va_arg (varargs, const gchar *);
+       }
+
+       gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT);
+       gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT, FALSE);
+
+       return self;
+}
+
+/**
+ * gcr_object_chooser_dialog_new:
+ * @title: The dialog window title
+ * @parent: (allow-none): The parent window or %NULL
+ * @flags: The dialog flags
+ * @first_button_text: (allow-none): The text of the first button
+ * @...: response ID for the first button, texts and response ids for other buttons, terminated with %NULL
+ *
+ * Creates the new #GcrObjectChooserDialog.
+ *
+ * Returns: newly created #GcrObjectChooserDialog
+ */
+
+GtkWidget *
+gcr_object_chooser_dialog_new (const gchar *title, GtkWindow *parent,
+                               GtkDialogFlags flags,
+                               const gchar *first_button_text, ...)
+{
+       GtkWidget *result;
+       va_list varargs;
+
+       va_start (varargs, first_button_text);
+       result = gcr_object_chooser_dialog_new_valist (title, parent, flags,
+                                                      first_button_text,
+                                                      varargs);
+       va_end (varargs);
+
+       return result;
+}
diff --git a/ui/gcr-object-chooser-dialog.h b/ui/gcr-object-chooser-dialog.h
new file mode 100644
index 0000000..a2011b0
--- /dev/null
+++ b/ui/gcr-object-chooser-dialog.h
@@ -0,0 +1,40 @@
+/*
+ * 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_OBJECT_CHOOSER_DIALOG_H__
+#define __GCR_OBJECT_CHOOSER_DIALOG_H__
+
+#include <gtk/gtk.h>
+
+#include "gcr-object-chooser.h"
+
+typedef struct _GcrObjectChooserDialogPrivate GcrObjectChooserDialogPrivate;
+
+struct _GcrObjectChooserDialog
+{
+        GtkDialog parent_instance;
+        GcrObjectChooserDialogPrivate *priv;
+};
+
+#define GCR_TYPE_OBJECT_CHOOSER_DIALOG gcr_object_chooser_dialog_get_type ()
+G_DECLARE_FINAL_TYPE (GcrObjectChooserDialog, gcr_object_chooser_dialog, GCR, OBJECT_CHOOSER_DIALOG, 
GtkDialog)
+
+GtkWidget *gcr_object_chooser_dialog_new (const gchar *title, GtkWindow *parent, GtkDialogFlags flags,
+                                          const gchar *first_button_text, ...);
+
+#endif /* __GCR_OBJECT_CHOOSER_DIALOG_H__ */
diff --git a/ui/gcr-object-chooser-dialog.ui b/ui/gcr-object-chooser-dialog.ui
new file mode 100644
index 0000000..b02fc09
--- /dev/null
+++ b/ui/gcr-object-chooser-dialog.ui
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface domain="gtk30">
+  <requires lib="gtk+" version="3.10"/>
+  <template class="GcrObjectChooserDialog" parent="GtkDialog">
+    <property name="can_focus">False</property>
+    <property name="role">GcrObjectChooserDialog</property>
+    <property name="default_width">600</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GcrObjectChooserWidget" id="chooser_widget">
+            <property name="visible">1</property>
+            <signal name="object-selected" handler="object_selected" swapped="no"/>
+            <signal name="object-activated" handler="object_activated" swapped="no"/>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+  <object class="GtkSizeGroup" id="buttons">
+    <property name="mode">vertical</property>
+  </object>
+</interface>
diff --git a/ui/gcr-ui.symbols b/ui/gcr-ui.symbols
index dcec48a..afd2262 100644
--- a/ui/gcr-ui.symbols
+++ b/ui/gcr-ui.symbols
@@ -62,6 +62,8 @@ gcr_list_selector_get_selected
 gcr_list_selector_get_type
 gcr_list_selector_new
 gcr_list_selector_set_selected
+gcr_object_chooser_dialog_get_type
+gcr_object_chooser_dialog_new
 gcr_object_chooser_get_type
 gcr_object_chooser_get_uri
 gcr_object_chooser_set_uri
diff --git a/ui/gcr.gresource.xml b/ui/gcr.gresource.xml
index deea9f8..55841cc 100644
--- a/ui/gcr.gresource.xml
+++ b/ui/gcr.gresource.xml
@@ -3,6 +3,7 @@
        <gresource prefix="/org/gnome/gcr/ui">
                <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-object-chooser-dialog.ui</file>
                <file preprocess="xml-stripblanks">gcr-object-chooser-widget.ui</file>
                <file preprocess="xml-stripblanks">gcr-token-login-dialog.ui</file>
                <file preprocess="xml-stripblanks">gcr-tokens-sidebar-row.ui</file>
-- 
2.9.3



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