[seahorse] Gkr: use GtkTemplate for new Keyring dialog.
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse] Gkr: use GtkTemplate for new Keyring dialog.
- Date: Thu, 10 May 2018 10:16:56 +0000 (UTC)
commit 92c84ee6057443f73429ee05d7071b4794457445
Author: Niels De Graef <nielsdegraef gmail com>
Date: Thu May 10 11:55:44 2018 +0200
Gkr: use GtkTemplate for new Keyring dialog.
data/seahorse.gresource.xml | 2 +-
gkr/gkr-keyring-add.vala | 98 +++++++++-----------
...-add-keyring.ui => seahorse-gkr-add-keyring.ui} | 46 ++++++++--
3 files changed, 81 insertions(+), 65 deletions(-)
---
diff --git a/data/seahorse.gresource.xml b/data/seahorse.gresource.xml
index 35e01fd..fd2eeda 100644
--- a/data/seahorse.gresource.xml
+++ b/data/seahorse.gresource.xml
@@ -17,7 +17,7 @@
<!-- GKR -->
<file alias="seahorse-gkr-add-item.ui"
preprocess="xml-stripblanks">../gkr/seahorse-gkr-add-item.ui</file>
- <file alias="seahorse-add-keyring.ui" preprocess="xml-stripblanks">../gkr/seahorse-add-keyring.ui</file>
+ <file alias="seahorse-gkr-add-keyring.ui"
preprocess="xml-stripblanks">../gkr/seahorse-gkr-add-keyring.ui</file>
<file alias="seahorse-gkr-item-properties.ui"
preprocess="xml-stripblanks">../gkr/seahorse-gkr-item-properties.ui</file>
<file alias="seahorse-gkr-keyring.ui" preprocess="xml-stripblanks">../gkr/seahorse-gkr-keyring.ui</file>
diff --git a/gkr/gkr-keyring-add.vala b/gkr/gkr-keyring-add.vala
index a6ac30f..cc5f816 100644
--- a/gkr/gkr-keyring-add.vala
+++ b/gkr/gkr-keyring-add.vala
@@ -17,59 +17,47 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-namespace Seahorse {
-namespace Gkr {
-
-public class KeyringAdd : Gtk.Dialog {
- construct {
- this.title = _("Add Password Keyring");
- this.modal = true;
- this.window_position = Gtk.WindowPosition.CENTER_ON_PARENT;
- this.border_width = 5;
-
- var builder = Util.load_built_contents(this, "add-keyring");
- this.add_buttons(Gtk.Stock.OK, Gtk.ResponseType.ACCEPT,
- Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL);
-
- var entry = (Gtk.Entry)builder.get_object("keyring-name");
- this.set_response_sensitive(Gtk.ResponseType.ACCEPT, false);
- entry.changed.connect((editable) => {
- var name = entry.get_text();
- this.set_response_sensitive(Gtk.ResponseType.ACCEPT, name != "");
- });
-
- this.response.connect((resp) => {
- if (resp == Gtk.ResponseType.ACCEPT) {
- var name = entry.get_text();
- var cancellable = Dialog.begin_request(this);
- var service = Backend.instance().service;
- Secret.Collection.create.begin(service, name, null,
-
Secret.CollectionCreateFlags.COLLECTION_CREATE_NONE,
- cancellable, (obj, res) => {
- /* Clear the operation without cancelling it since it is complete */
- Dialog.complete_request(this, false);
-
- try {
- Secret.Collection.create.end(res);
- } catch (GLib.Error err) {
- Util.show_error(this, _("Couldn’t add keyring"), err.message);
- }
-
- this.destroy();
- });
- } else {
- this.destroy();
- }
- });
-
- }
-
- public KeyringAdd(Gtk.Window? parent) {
- GLib.Object(transient_for: parent);
- this.show();
- this.present();
- }
-}
-
-}
+[GtkTemplate (ui = "/org/gnome/Seahorse/seahorse-gkr-add-keyring.ui")]
+public class Seahorse.Gkr.KeyringAdd : Gtk.Dialog {
+ [GtkChild]
+ private Gtk.Entry name_entry;
+
+ construct {
+ set_response_sensitive(Gtk.ResponseType.ACCEPT, false);
+ }
+
+ public KeyringAdd(Gtk.Window? parent) {
+ GLib.Object(transient_for: parent);
+ show();
+ present();
+ }
+
+ public override void response(int resp) {
+ if (resp != Gtk.ResponseType.ACCEPT) {
+ destroy();
+ return;
+ }
+
+ var cancellable = Dialog.begin_request(this);
+ var service = Backend.instance().service;
+ Secret.Collection.create.begin(service, this.name_entry.text, null,
+ Secret.CollectionCreateFlags.COLLECTION_CREATE_NONE,
+ cancellable, (obj, res) => {
+ /* Clear the operation without cancelling it since it is complete */
+ Dialog.complete_request(this, false);
+
+ try {
+ Secret.Collection.create.end(res);
+ } catch (GLib.Error err) {
+ Util.show_error(this, _("Couldn’t add keyring"), err.message);
+ }
+
+ destroy();
+ });
+ }
+
+ [GtkCallback]
+ private void on_name_entry_changed(Gtk.Editable editable) {
+ set_response_sensitive(Gtk.ResponseType.ACCEPT, this.name_entry.text != "");
+ }
}
diff --git a/gkr/seahorse-add-keyring.ui b/gkr/seahorse-gkr-add-keyring.ui
similarity index 60%
rename from gkr/seahorse-add-keyring.ui
rename to gkr/seahorse-gkr-add-keyring.ui
index 10dff83..3f6dc01 100644
--- a/gkr/seahorse-add-keyring.ui
+++ b/gkr/seahorse-gkr-add-keyring.ui
@@ -1,17 +1,24 @@
<?xml version="1.0"?>
<interface>
- <requires lib="gtk+" version="2.16"/>
- <!-- interface-naming-policy toplevel-contextual -->
- <object class="GtkVBox" id="add-keyring">
+ <requires lib="gtk+" version="3.22"/>
+ <template class="SeahorseGkrKeyringAdd" parent="GtkDialog">
+ <property name="modal">True</property>
+ <property name="title" translatable="yes">Add password keyring</property>
+ <property name="window-position">center-on-parent</property>
+ <property name="border_width">5</property>
+ <child internal-child="vbox">
+ <object class="GtkBox">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
- <object class="GtkVBox" id="vbox1">
+ <object class="GtkBox">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<property name="border_width">5</property>
<property name="spacing">6</property>
<child>
- <object class="GtkLabel" id="label4">
+ <object class="GtkLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Please choose a name for the new keyring. You will
be prompted for an unlock password.</property>
@@ -24,11 +31,12 @@
</packing>
</child>
<child>
- <object class="GtkHBox" id="hbox1">
+ <object class="GtkBox">
<property name="visible">True</property>
+ <property name="orientation">horizontal</property>
<property name="spacing">12</property>
<child>
- <object class="GtkLabel" id="label3">
+ <object class="GtkLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">New Keyring Name:</property>
@@ -40,15 +48,16 @@
</packing>
</child>
<child>
- <object class="GtkEntry" id="keyring-name">
+ <object class="GtkEntry" id="name_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="max_length">32</property>
+ <property name="hexpand">True</property>
<property name="invisible_char">●</property>
<property name="activates_default">True</property>
<property name="width_chars">16</property>
- <signal name="changed" handler="on_add_keyring_name_changed"/>
+ <signal name="changed" handler="on_name_entry_changed"/>
</object>
<packing>
<property name="position">1</property>
@@ -66,4 +75,23 @@
</packing>
</child>
</object>
+ </child>
+ <child type="action">
+ <object class="GtkButton" id="cancel_button">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Cancel</property>
+ </object>
+ </child>
+ <child type="action">
+ <object class="GtkButton" id="ok_button">
+ <property name="visible">True</property>
+ <property name="can-default">True</property>
+ <property name="label" translatable="yes">Ok</property>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="cancel">cancel_button</action-widget>
+ <action-widget response="accept" default="true">ok_button</action-widget>
+ </action-widgets>
+ </template>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]