aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-03-12 16:21:46 +0100
committerfiaxh <git@mx.ax.lt>2017-03-12 16:25:42 +0100
commit39722a4973eb3450d7b92a8fac4e67aae7b3ceae (patch)
treebb691b3782d77d5d75b1c3f92f3ce3eda70a0643 /plugins
parenta4cb998ec4b60360d10a0b39126efc78639817bb (diff)
downloaddino-39722a4973eb3450d7b92a8fac4e67aae7b3ceae.tar.gz
dino-39722a4973eb3450d7b92a8fac4e67aae7b3ceae.zip
Query GPG in other thread + only once (account settings)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/openpgp/data/account_settings_item.ui1
-rw-r--r--plugins/openpgp/src/account_settings_widget.vala83
2 files changed, 63 insertions, 21 deletions
diff --git a/plugins/openpgp/data/account_settings_item.ui b/plugins/openpgp/data/account_settings_item.ui
index 299b9a89..0c10b84b 100644
--- a/plugins/openpgp/data/account_settings_item.ui
+++ b/plugins/openpgp/data/account_settings_item.ui
@@ -20,7 +20,6 @@
<child>
<object class="GtkComboBox" id="combobox">
<property name="hexpand">True</property>
- <property name="width_request">200</property>
<property name="visible">True</property>
</object>
<packing>
diff --git a/plugins/openpgp/src/account_settings_widget.vala b/plugins/openpgp/src/account_settings_widget.vala
index 71739096..5340db30 100644
--- a/plugins/openpgp/src/account_settings_widget.vala
+++ b/plugins/openpgp/src/account_settings_widget.vala
@@ -1,3 +1,4 @@
+using Gee;
using Gtk;
using Dino.Entities;
@@ -13,6 +14,7 @@ private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
private Plugin plugin;
private Account current_account;
+ private Gee.List<GPG.Key> keys = null;
private Gtk.ListStore list_store = new Gtk.ListStore(2, typeof(string), typeof(string?));
public AccountSettingsWidget(Plugin plugin) {
@@ -22,6 +24,7 @@ private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
renderer.set_padding(0, 0);
combobox.pack_start(renderer, true);
combobox.add_attribute(renderer, "markup", 0);
+ combobox.set_model(list_store);
button.clicked.connect(on_button_clicked);
combobox.changed.connect(key_changed);
@@ -33,7 +36,11 @@ private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
public void set_account(Account account) {
this.current_account = account;
- populate(account);
+ if (keys == null) {
+ fetch_keys();
+ } else {
+ activate_current_account();
+ }
}
private void on_button_clicked() {
@@ -42,30 +49,66 @@ private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
combobox.popup();
}
- private void populate(Account account) {
- TreeIter iter;
- combobox.set_model(list_store);
+ private void activate_current_account() {
+ string? account_key = plugin.db.get_account_key(current_account);
+ int activate_index = 0;
+ for (int i = 0; i < keys.size; i++) {
+ GPG.Key key = keys[i];
+ if (key.fpr == account_key) {
+ activate_index = i + 1;
+ }
+ }
+ combobox.active = activate_index;
- list_store.clear();
- try {
- Gee.List<GPG.Key> keys = GPGHelper.get_keylist(null, true);
+ TreeIter selected;
+ combobox.get_active_iter(out selected);
+ set_label_active(selected);
+ }
+ private void populate_list_store() {
+ TreeIter iter;
+ list_store.append(out iter);
+ list_store.set(iter, 0, "Disabled\n<span font='9'>Select key</span>", 1, null);
+ set_label_active(iter, 0);
+ for (int i = 0; i < keys.size; i++) {
list_store.append(out iter);
- list_store.set(iter, 0, "Disabled\n<span font='9'>Select key</span>", 1, null);
- set_label_active(iter, 0);
- for (int i = 0; i < keys.size; i++) {
- list_store.append(out iter);
- string text = @"<span font='11'>$(Markup.escape_text(keys[i].uids[0].uid))</span>\n<span font='9'>0x$(Markup.escape_text(keys[i].fpr[0:16]))</span>";
- list_store.set(iter, 0, text);
- list_store.set(iter, 1, keys[i].fpr);
- if (keys[i].fpr == plugin.db.get_account_key(account)) {
- set_label_active(iter, i + 1);
- }
+ list_store.set(iter, 0, @"$(Markup.escape_text(keys[i].uids[0].uid))\n<span font='9'>0x$(Markup.escape_text(keys[i].fpr[0:16]))</span>");
+ list_store.set(iter, 1, keys[i].fpr);
+ if (keys[i].fpr == plugin.db.get_account_key(current_account)) {
+ set_label_active(iter, i + 1);
}
- } catch (Error e){
- list_store.append(out iter);
- list_store.set(iter, 0, @"Disabled\n<span font='9'>Error: $(Markup.escape_text(e.message))</span>", 1, null);
}
+ activate_current_account();
+ }
+
+ private void fetch_keys() {
+ new Thread<void*> (null, () => { // Querying GnuPG might take some while
+ Idle.add(() => {
+ TreeIter iter;
+ list_store.clear();
+ list_store.append(out iter);
+ button.sensitive = false;
+ label.set_markup("Loading...\n<span font='9'>Querying GnuPG</span>");
+ return false;
+ });
+ try {
+ keys = GPGHelper.get_keylist(null, true);
+ Idle.add(() => {
+ list_store.clear();
+ populate_list_store();
+ button.sensitive = true;
+ return false;
+ });
+ } catch (Error e) {
+ Idle.add(() => {
+ TreeIter iter;
+ list_store.append(out iter);
+ list_store.set(iter, 0, @"Disabled\n<span font='9'>Error in GnuPG</span>", 1, null);
+ return false;
+ });
+ }
+ return null;
+ });
}
private void set_label_active(TreeIter iter, int i = -1) {