[seahorse/wip/nielsdg/port-interaction] common: Port SeahorseInteraction to Vala



commit afefd958af0f9a5f552990ec675a12a4463a66c7
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Dec 30 10:37:43 2018 +0100

    common: Port SeahorseInteraction to Vala
    
    Note that there are some issues with Gcr bindings.

 common/config.vapi                 |   6 --
 common/interaction.vala            |  63 ++++++++++++
 common/meson.build                 |   1 +
 libseahorse/meson.build            |   1 -
 libseahorse/seahorse-interaction.c | 191 -------------------------------------
 libseahorse/seahorse-interaction.h |  57 -----------
 po/POTFILES.in                     |   8 +-
 7 files changed, 71 insertions(+), 256 deletions(-)
---
diff --git a/common/config.vapi b/common/config.vapi
index 6838ebc0..20a6b5a9 100644
--- a/common/config.vapi
+++ b/common/config.vapi
@@ -37,12 +37,6 @@ public static GLib.HashFunc<ulong?> ulong_hash;
 [CCode (cheader_filename = "libseahorse/seahorse-util.h")]
 public static GLib.EqualFunc<ulong?> ulong_equal;
 
-[CCode (cheader_filename = "libseahorse/seahorse-interaction.h")]
-public class Interaction : GLib.TlsInteraction {
-       public Interaction(Gtk.Window? parent);
-       public Gtk.Window? parent;
-}
-
 [CCode (cheader_filename = "libseahorse/seahorse-progress.h")]
 namespace Progress {
        public void show(GLib.Cancellable? cancellable, string title, bool delayed);
diff --git a/common/interaction.vala b/common/interaction.vala
new file mode 100644
index 00000000..36986d82
--- /dev/null
+++ b/common/interaction.vala
@@ -0,0 +1,63 @@
+/*
+ * Seahorse
+ *
+ * Copyright (C) 2008 Stefan Walter
+ * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2017 Niels De Graef
+ *
+ * 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/>.
+ */
+
+
+// FIXME: there are no bindings generated for these functions
+extern string gcr_secure_memory_strdup(string str);
+extern void gcr_secure_memory_free(void* str);
+
+public class Seahorse.Interaction : GLib.TlsInteraction {
+
+    /**
+     * The parent window
+     */
+    public weak Gtk.Window? parent { get; set; }
+
+    public Interaction(Gtk.Window? parent) {
+        this.parent = parent;
+    }
+
+    public override TlsInteractionResult ask_password(TlsPassword password,
+                                                      Cancellable? cancellable = null)
+            throws GLib.Error {
+        string description = calc_description (password);
+        PassphrasePrompt dialog = PassphrasePrompt.show_dialog(null, description, null, null, false);
+
+        if (this.parent != null)
+            dialog.transient_for = this.parent;
+
+        int response = dialog.run();
+        dialog.destroy();
+
+        if (response != Gtk.ResponseType.ACCEPT)
+            throw new GLib.IOError.CANCELLED("The password request was cancelled by the user");
+
+        password.set_value_full((uint8[])gcr_secure_memory_strdup(dialog.get_text()),
+                                gcr_secure_memory_free);
+
+        return TlsInteractionResult.HANDLED;
+    }
+
+    private string calc_description (GLib.TlsPassword password) {
+        return _("Enter PIN or password for: %s").printf(password.description);
+    }
+}
diff --git a/common/meson.build b/common/meson.build
index 20a800c4..36788790 100644
--- a/common/meson.build
+++ b/common/meson.build
@@ -11,6 +11,7 @@ common_sources = [
   'exporter.vala',
   'icons.vala',
   'key-manager-store.vala',
+  'interaction.vala',
   'lockable.vala',
   'object.vala',
   'passphrase-prompt.vala',
diff --git a/libseahorse/meson.build b/libseahorse/meson.build
index 2b9205c5..0e77d8e1 100644
--- a/libseahorse/meson.build
+++ b/libseahorse/meson.build
@@ -6,7 +6,6 @@ marshaller = gnome.genmarshal('seahorse-marshal',
 
 libseahorse_sources = [
   'seahorse-bind.c',
-  'seahorse-interaction.c',
   'seahorse-object-list.c',
   'seahorse-object-model.c',
   'seahorse-object-widget.c',
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ce453d62..1ea50ab2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@ common/delete-dialog.vala
 common/exportable.vala
 common/key-manager-store.vala
 common/object.vala
+common/interaction.vala
 common/passphrase-prompt.vala
 common/prefs.vala
 common/seahorse-add-keyserver.ui
@@ -30,7 +31,12 @@ gkr/seahorse-gkr-add-keyring.ui
 gkr/seahorse-gkr-item-properties.ui
 gkr/seahorse-gkr-keyring.ui
 libegg/egg-datetime.c
-libseahorse/seahorse-interaction.c
+libseahorse/seahorse-add-keyserver.ui
+libseahorse/seahorse-application.c
+libseahorse/seahorse-key-manager-store.c
+libseahorse/seahorse-object.c
+libseahorse/seahorse-prefs.c
+libseahorse/seahorse-prefs.ui
 libseahorse/seahorse-progress.ui
 libseahorse/seahorse-util.c
 libseahorse/seahorse-widget.c


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