[seahorse] Gkr: Use GtkTemplate for ItemAdd dialog.
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse] Gkr: Use GtkTemplate for ItemAdd dialog.
- Date: Thu, 10 May 2018 08:55:14 +0000 (UTC)
commit bb715cb8a66b702563c9c06a4bef175cdb2c3b0b
Author: Niels De Graef <nielsdegraef gmail com>
Date: Thu May 10 10:54:40 2018 +0200
Gkr: Use GtkTemplate for ItemAdd dialog.
gkr/gkr-item-add.vala | 189 +++++++++++++++++-------------------
gkr/meson.build | 5 +
gkr/seahorse-gkr-add-item.ui | 217 ++++++++++++++++++++++--------------------
3 files changed, 208 insertions(+), 203 deletions(-)
---
diff --git a/gkr/gkr-item-add.vala b/gkr/gkr-item-add.vala
index d57530b..90bed5a 100644
--- a/gkr/gkr-item-add.vala
+++ b/gkr/gkr-item-add.vala
@@ -2,6 +2,7 @@
* Seahorse
*
* Copyright (C) 2008 Stefan Walter
+ * Copyright (C) 2018 Niels De Graef
*
* 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
@@ -16,103 +17,93 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-namespace Seahorse {
-namespace Gkr {
-
-public class ItemAdd : Gtk.Dialog {
- construct {
- this.title = _("Add Password");
- this.modal = true;
- this.window_position = Gtk.WindowPosition.CENTER_ON_PARENT;
- this.border_width = 5;
-
- var builder = Util.load_built_contents(this, "gkr-add-item");
- this.add_buttons(Gtk.Stock.OK, Gtk.ResponseType.ACCEPT,
- Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL);
-
- /* Load up a list of all the keyrings, and select the default */
- var combo = (Gtk.ComboBox)builder.get_object("item-keyring");
- var store = new Gtk.ListStore(2, typeof(string), typeof(Secret.Collection));
- combo.set_model(store);
-
- var cell = new Gtk.CellRendererText();
- combo.pack_start(cell, true);
- combo.add_attribute(cell, "text", 0);
-
- foreach (var keyring in Backend.instance().get_keyrings()) {
- Gtk.TreeIter iter;
- store.append(out iter);
- store.set(iter,
- 0, keyring.label,
- 1, keyring,
- -1);
- if (keyring.is_default)
- combo.set_active_iter(iter);
- }
-
- var label = (Gtk.Entry)builder.get_object("item-label");
- this.set_response_sensitive(Gtk.ResponseType.ACCEPT, false);
- label.changed.connect((editable) => {
- var value = label.get_text();
- this.set_response_sensitive(Gtk.ResponseType.ACCEPT, value != "");
- });
-
- var area = (Gtk.Container)builder.get_object("password-area");
- var buffer = new Gcr.SecureEntryBuffer();
- var entry = new Gtk.Entry.with_buffer(buffer);
- entry.visibility = false;
- area.add(entry);
- entry.show();
-
- var check = (Gtk.ToggleButton)builder.get_object("show-password");
- check.toggled.connect(() => {
- entry.visibility = check.active;
- });
-
- this.response.connect((resp) => {
- if (resp != Gtk.ResponseType.ACCEPT) {
- this.destroy();
- return;
- }
-
- Gtk.TreeIter iter;
- if (!combo.get_active_iter(out iter))
- return;
-
- Secret.Collection collection;
- combo.model.get(iter, 1, out collection, -1);
-
- var secret = new Secret.Value(entry.get_text(), -1, "text/plain");
- var cancellable = Dialog.begin_request(this);
- var attributes = new GLib.HashTable<string, string>(GLib.str_hash, GLib.str_equal);
-
- /* TODO: Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=697681 */
- var schema = new Secret.Schema("org.gnome.keyring.Note", Secret.SchemaFlags.NONE);
-
- Secret.Item.create.begin(collection, schema, attributes,
- label.get_text(), secret, Secret.ItemCreateFlags.NONE,
- cancellable, (obj, res) => {
- try {
- /* Clear the operation without cancelling it since it is complete */
- Dialog.complete_request(this, false);
-
- Secret.Item.create.end(res);
- } catch (GLib.Error err) {
- Util.show_error(this, _("Couldn’t add item"), err.message);
- }
-
- this.destroy();
- });
-
- });
- }
-
- public ItemAdd(Gtk.Window? parent) {
- GLib.Object(transient_for: parent);
- this.show();
- this.present();
- }
-}
-
-}
+[GtkTemplate (ui = "/org/gnome/Seahorse/seahorse-gkr-add-item.ui")]
+public class Seahorse.Gkr.ItemAdd : Gtk.Dialog {
+ [GtkChild]
+ private Gtk.ComboBox item_keyring_combo;
+ [GtkChild]
+ private Gtk.Container password_area;
+ private Gtk.Entry password_entry;
+ [GtkChild]
+ private Gtk.Entry item_entry;
+ [GtkChild]
+ private Gtk.CheckButton show_password_checkbutton;
+
+ construct {
+ // Load up a list of all the keyrings, and select the default
+ var store = new Gtk.ListStore(2, typeof(string), typeof(Secret.Collection));
+ this.item_keyring_combo.set_model(store);
+
+ var cell = new Gtk.CellRendererText();
+ this.item_keyring_combo.pack_start(cell, true);
+ this.item_keyring_combo.add_attribute(cell, "text", 0);
+
+ foreach (var keyring in Backend.instance().get_keyrings()) {
+ Gtk.TreeIter iter;
+ store.append(out iter);
+ store.set(iter, 0, keyring.label,
+ 1, keyring);
+ if (keyring.is_default)
+ this.item_keyring_combo.set_active_iter(iter);
+ }
+
+ set_response_sensitive(Gtk.ResponseType.ACCEPT, false);
+
+ var buffer = new Gcr.SecureEntryBuffer();
+ this.password_entry = new Gtk.Entry.with_buffer(buffer);
+ this.password_entry.visibility = false;
+ this.password_area.add(this.password_entry);
+ this.password_entry.show();
+
+ this.show_password_checkbutton.toggled.connect(() => {
+ this.password_entry.visibility = this.show_password_checkbutton.active;
+ });
+ }
+
+ public ItemAdd(Gtk.Window? parent) {
+ GLib.Object(transient_for: parent);
+ this.show();
+ this.present();
+ }
+
+ [GtkCallback]
+ private void on_add_item_entry_changed (Gtk.Editable entry) {
+ set_response_sensitive(Gtk.ResponseType.ACCEPT, this.item_entry.text != "");
+ }
+
+ public override void response(int resp) {
+ if (resp != Gtk.ResponseType.ACCEPT) {
+ this.destroy();
+ return;
+ }
+
+ Gtk.TreeIter iter;
+ if (!this.item_keyring_combo.get_active_iter(out iter))
+ return;
+
+ Secret.Collection collection;
+ this.item_keyring_combo.model.get(iter, 1, out collection, -1);
+
+ var secret = new Secret.Value(this.password_entry.text, -1, "text/plain");
+ var cancellable = Dialog.begin_request(this);
+ var attributes = new HashTable<string, string>(GLib.str_hash, GLib.str_equal);
+
+ /* TODO: Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=697681 */
+ var schema = new Secret.Schema("org.gnome.keyring.Note", Secret.SchemaFlags.NONE);
+
+ Secret.Item.create.begin(collection, schema, attributes,
+ this.item_entry.text, secret, Secret.ItemCreateFlags.NONE,
+ cancellable, (obj, res) => {
+ try {
+ /* Clear the operation without cancelling it since it is complete */
+ Dialog.complete_request(this, false);
+
+ Secret.Item.create.end(res);
+ } catch (GLib.Error err) {
+ Util.show_error(this, _("Couldn’t add item"), err.message);
+ }
+
+ this.destroy();
+ });
+ }
}
diff --git a/gkr/meson.build b/gkr/meson.build
index 779cfbe..5cf37db 100644
--- a/gkr/meson.build
+++ b/gkr/meson.build
@@ -20,8 +20,13 @@ gkr_dependencies = [
common_dep,
]
+gkr_vala_args = [
+ '--gresources', resources_xml,
+]
+
gkr_lib = static_library('seahorse-gkr',
gkr_sources,
+ vala_args: gkr_vala_args,
dependencies: gkr_dependencies,
)
diff --git a/gkr/seahorse-gkr-add-item.ui b/gkr/seahorse-gkr-add-item.ui
index 8677f3b..b325f8f 100644
--- a/gkr/seahorse-gkr-add-item.ui
+++ b/gkr/seahorse-gkr-add-item.ui
@@ -1,118 +1,127 @@
<?xml version="1.0"?>
<interface>
- <requires lib="gtk+" version="2.16"/>
- <!-- interface-naming-policy toplevel-contextual -->
- <object class="GtkVBox" id="gkr-add-item">
+ <requires lib="gtk+" version="3.22"/>
+ <template class="SeahorseGkrItemAdd" parent="GtkDialog">
+ <property name="title" translatable="yes">Add Password</property>
+ <property name="modal">True</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="border_width">5</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkGrid">
<property name="visible">True</property>
- <property name="border_width">5</property>
- <property name="spacing">6</property>
+ <property name="column_spacing">12</property>
+ <property name="row_spacing">6</property>
<child>
- <object class="GtkTable" id="table1">
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Keyring:</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="top_attach">0</property>
+ <property name="left_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="item_keyring_combo">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="top_attach">0</property>
+ <property name="left_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Description:</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="left_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="item_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">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_item_entry_changed"/>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="left_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Password:</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="left_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="password_area">
<property name="visible">True</property>
- <property name="n_rows">4</property>
- <property name="n_columns">2</property>
- <property name="column_spacing">12</property>
- <property name="row_spacing">6</property>
- <child>
- <object class="GtkLabel" id="label3">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">_Description:</property>
- <property name="use_underline">True</property>
- </object>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkEntry" id="item-label">
- <property name="visible">True</property>
- <property name="can_focus">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_item_label_changed"/>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label1">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">_Password:</property>
- <property name="use_underline">True</property>
- </object>
- <packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="x_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkCheckButton" id="show-password">
- <property name="label" translatable="yes">_Show Password</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_underline">True</property>
- <property name="draw_indicator">True</property>
- <signal name="toggled" handler="on_add_item_password_toggled"/>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
- </packing>
- </child>
- <child>
- <object class="GtkAlignment" id="password-area">
- <property name="visible">True</property>
- <child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- </packing>
- </child>
- <child>
- <object class="GtkLabel" id="label2">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">_Keyring:</property>
- <property name="use_underline">True</property>
- </object>
- <packing>
- <property name="x_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <object class="GtkComboBox" id="item-keyring">
- <property name="visible">True</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- </packing>
- </child>
<child>
<placeholder/>
</child>
</object>
<packing>
- <property name="position">0</property>
+ <property name="top_attach">2</property>
+ <property name="left_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="show_password_checkbutton">
+ <property name="label" translatable="yes">_Show Password</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="top_attach">3</property>
+ <property name="left_attach">1</property>
</packing>
</child>
</object>
+ </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]