[seahorse] Gkr: KeyringProperties: Use Gtk.LockButton



commit 22022c3248f0acce6bb6338e3b5c47c6972e2e4a
Author: Anukul Sangwan <anukulsangwan icloud com>
Date:   Tue Oct 1 20:03:04 2019 +0000

    Gkr: KeyringProperties: Use Gtk.LockButton

 gkr/gkr-keyring-permission.vala | 50 +++++++++++++++++++++++++++++++++++
 gkr/gkr-keyring-properties.vala | 34 +++---------------------
 gkr/meson.build                 |  1 +
 gkr/seahorse-gkr-keyring.ui     | 58 +++--------------------------------------
 po/POTFILES.in                  |  1 +
 5 files changed, 59 insertions(+), 85 deletions(-)
---
diff --git a/gkr/gkr-keyring-permission.vala b/gkr/gkr-keyring-permission.vala
new file mode 100644
index 00000000..8e0acd21
--- /dev/null
+++ b/gkr/gkr-keyring-permission.vala
@@ -0,0 +1,50 @@
+/*
+ * Seahorse
+ *
+ * Copyright (C) 2018 Anukul Sangwan
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+public class Seahorse.Gkr.KeyringPermission : GLib.Permission {
+
+    private Keyring keyring;
+
+    public KeyringPermission(Keyring keyring) {
+        this.keyring = keyring;
+        refresh();
+    }
+
+    private void disable() {
+        this.impl_update(false, false, false);
+    }
+
+    private void refresh() {
+        this.impl_update(!this.keyring.locked, Lockable.can_unlock(this.keyring), 
Lockable.can_lock(this.keyring));
+    }
+
+    public override async bool acquire_async(GLib.Cancellable? cancellable = null) throws GLib.Error {
+        disable();
+        yield this.keyring.unlock(null, null);
+        refresh();
+        return true;
+    }
+
+    public override async bool release_async(GLib.Cancellable? cancellable = null) throws GLib.Error {
+        disable();
+        yield this.keyring.lock(null, null);
+        refresh();
+        return true;
+    }
+
+}
diff --git a/gkr/gkr-keyring-properties.vala b/gkr/gkr-keyring-properties.vala
index d384d711..33329c09 100644
--- a/gkr/gkr-keyring-properties.vala
+++ b/gkr/gkr-keyring-properties.vala
@@ -31,9 +31,7 @@ public class Seahorse.Gkr.KeyringProperties : Gtk.Dialog {
     [GtkChild]
     private Gtk.Button set_default_button;
     [GtkChild]
-    private Gtk.Button lock_unlock_button;
-    [GtkChild]
-    private Gtk.Stack lock_unlock_stack;
+    private Gtk.LockButton lock_button;
 
     construct {
         this.use_header_bar = 1;
@@ -51,7 +49,6 @@ public class Seahorse.Gkr.KeyringProperties : Gtk.Dialog {
         // The buttons
         this.keyring.bind_property("is-default", this.set_default_button, "sensitive",
                                    BindingFlags.SYNC_CREATE | BindingFlags.INVERT_BOOLEAN);
-        update_lock_unlock_button();
     }
 
     public KeyringProperties(Keyring keyring, Gtk.Window? parent) {
@@ -59,6 +56,8 @@ public class Seahorse.Gkr.KeyringProperties : Gtk.Dialog {
             keyring: keyring,
             transient_for: parent
         );
+        var perm = new KeyringPermission(this.keyring);
+        this.lock_button.set_permission(perm);
     }
 
     private void set_created(uint64 timestamp) {
@@ -75,31 +74,4 @@ public class Seahorse.Gkr.KeyringProperties : Gtk.Dialog {
     private void on_change_pw_button_clicked(Gtk.Button button) {
         this.keyring.change_password();
     }
-
-    private void update_lock_unlock_button() {
-        this.lock_unlock_stack.visible_child_name
-            = this.keyring.locked? "lock_unlock_button_unlocked" : "lock_unlock_button_locked";
-    }
-
-    private async void set_keyring_locked() {
-        this.lock_unlock_button.sensitive = false;
-        try {
-            if (this.keyring.locked)
-                yield this.keyring.unlock(null, null);
-            else
-                yield this.keyring.lock(null, null);
-        } catch (Error e) {
-            warning("Couldn't %s keyring <%s>",
-                this.keyring.locked? "unlock" : "lock",
-                this.keyring.label);
-        }
-
-        update_lock_unlock_button();
-        this.lock_unlock_button.sensitive = true;
-    }
-
-    [GtkCallback]
-    private void on_lock_unlock_button_clicked(Gtk.Button button) {
-        set_keyring_locked.begin();
-    }
 }
diff --git a/gkr/meson.build b/gkr/meson.build
index e0e671fc..668885a1 100644
--- a/gkr/meson.build
+++ b/gkr/meson.build
@@ -5,6 +5,7 @@ gkr_sources = [
   'gkr-item-properties.vala',
   'gkr-item.vala',
   'gkr-keyring-add.vala',
+  'gkr-keyring-permission.vala',
   'gkr-keyring-properties.vala',
   'gkr-keyring.vala',
   'gkr-module.vala',
diff --git a/gkr/seahorse-gkr-keyring.ui b/gkr/seahorse-gkr-keyring.ui
index f02eb500..c9ff8c75 100644
--- a/gkr/seahorse-gkr-keyring.ui
+++ b/gkr/seahorse-gkr-keyring.ui
@@ -8,61 +8,11 @@
         <property name="show_close_button">True</property>
         <property name="title" translatable="yes">Keyring properties</property>
         <child>
-          <object class="GtkButton" id="lock_unlock_button">
+          <object class="GtkLockButton" id="lock_button">
             <property name="visible">True</property>
-            <signal name="clicked" handler="on_lock_unlock_button_clicked"/>
-            <child>
-              <object class="GtkStack" id="lock_unlock_stack">
-                <property name="visible">True</property>
-                <property name="homogeneous">False</property>
-                <child>
-                  <object class="GtkBox">
-                    <property name="visible">True</property>
-                    <property name="orientation">horizontal</property>
-                    <property name="spacing">6</property>
-                    <property name="tooltip_text" translatable="yes">Keyring is locked</property>
-                    <child>
-                      <object class="GtkImage">
-                        <property name="visible">true</property>
-                        <property name="icon_name">changes-allow-symbolic</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkLabel">
-                        <property name="visible">true</property>
-                        <property name="label" translatable="yes">Unlock</property>
-                      </object>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="name">lock_unlock_button_unlocked</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkBox">
-                    <property name="visible">True</property>
-                    <property name="orientation">horizontal</property>
-                    <property name="spacing">6</property>
-                    <property name="tooltip_text" translatable="yes">Keyring is unlocked</property>
-                    <child>
-                      <object class="GtkImage">
-                        <property name="visible">true</property>
-                        <property name="icon_name">changes-prevent-symbolic</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkLabel">
-                        <property name="visible">true</property>
-                        <property name="label" translatable="yes">Lock</property>
-                      </object>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="name">lock_unlock_button_locked</property>
-                  </packing>
-                </child>
-              </object>
-            </child>
+            <property name="tooltip_lock">Keyring is unlocked</property>
+            <property name="tooltip_unlock">Keyring is locked</property>
+            <property name="tooltip_not_authorized"></property>
           </object>
         </child>
       </object>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ca06fd1d..5686b395 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -24,6 +24,7 @@ gkr/gkr-item-properties.vala
 gkr/gkr-item.vala
 gkr/gkr-keyring-add.vala
 gkr/gkr-keyring-properties.vala
+gkr/gkr-keyring-permission.vala
 gkr/gkr-keyring.vala
 gkr/gkr-password-entry.vala
 gkr/seahorse-gkr-add-item.ui


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