openpgp: Fix invalid iter in key selection dialog
On empty pgp keyring the key selection dialog would display a label "No Keys available" which subsequently while selecting different accounts would disappear. Co-authored-by: Gnoxter <gnoxter+github@linuxlounge.net>
This commit is contained in:
parent
c656c7e9c2
commit
6f27c3e58f
|
@ -35,12 +35,16 @@ private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set_account(Account account) {
|
public void set_account(Account account) {
|
||||||
|
set_account_.begin(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void set_account_(Account account) {
|
||||||
this.current_account = account;
|
this.current_account = account;
|
||||||
if (keys == null) {
|
if (keys == null) {
|
||||||
fetch_keys();
|
yield fetch_keys();
|
||||||
} else {
|
populate_list_store();
|
||||||
activate_current_account();
|
|
||||||
}
|
}
|
||||||
|
activate_current_account();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void on_button_clicked() {
|
private void on_button_clicked() {
|
||||||
|
@ -52,6 +56,14 @@ private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
|
||||||
|
|
||||||
private void activate_current_account() {
|
private void activate_current_account() {
|
||||||
combobox.changed.disconnect(key_changed);
|
combobox.changed.disconnect(key_changed);
|
||||||
|
if (keys == null) {
|
||||||
|
label.set_markup(build_markup_string(_("Key publishing disabled"), _("Error in GnuPG")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (keys.size == 0) {
|
||||||
|
label.set_markup(build_markup_string(_("Key publishing disabled"), _("No keys available. Generate one!")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
string? account_key = plugin.db.get_account_key(current_account);
|
string? account_key = plugin.db.get_account_key(current_account);
|
||||||
int activate_index = 0;
|
int activate_index = 0;
|
||||||
|
@ -71,11 +83,11 @@ private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populate_list_store() {
|
private void populate_list_store() {
|
||||||
if (keys.size == 0) {
|
if (keys == null || keys.size == 0) {
|
||||||
label.set_markup(build_markup_string(_("Key publishing disabled"), _("No keys available. Generate one!")));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list_store.clear();
|
||||||
TreeIter iter;
|
TreeIter iter;
|
||||||
list_store.append(out iter);
|
list_store.append(out iter);
|
||||||
list_store.set(iter, 0, build_markup_string(_("Key publishing disabled"), _("Select key") + "<span font_family='monospace' font='8'> \n </span>"), 1, "");
|
list_store.set(iter, 0, build_markup_string(_("Key publishing disabled"), _("Select key") + "<span font_family='monospace' font='8'> \n </span>"), 1, "");
|
||||||
|
@ -87,31 +99,21 @@ private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
|
||||||
set_label_active(iter, i + 1);
|
set_label_active(iter, i + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
activate_current_account();
|
|
||||||
button.sensitive = true;
|
button.sensitive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetch_keys() {
|
private async void fetch_keys() {
|
||||||
TreeIter iter;
|
|
||||||
list_store.clear();
|
|
||||||
list_store.append(out iter);
|
|
||||||
label.set_markup(build_markup_string(_("Loading…"), _("Querying GnuPG")));
|
label.set_markup(build_markup_string(_("Loading…"), _("Querying GnuPG")));
|
||||||
|
|
||||||
|
SourceFunc callback = fetch_keys.callback;
|
||||||
new Thread<void*> (null, () => { // Querying GnuPG might take some time
|
new Thread<void*> (null, () => { // Querying GnuPG might take some time
|
||||||
try {
|
try {
|
||||||
keys = GPGHelper.get_keylist(null, true);
|
keys = GPGHelper.get_keylist(null, true);
|
||||||
Idle.add(() => {
|
} catch (Error e) { }
|
||||||
list_store.clear();
|
Idle.add((owned)callback);
|
||||||
populate_list_store();
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
} catch (Error e) {
|
|
||||||
Idle.add(() => {
|
|
||||||
label.set_markup(build_markup_string(_("Key publishing disabled"), _("Error in GnuPG")));
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
yield;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void set_label_active(TreeIter iter, int i = -1) {
|
private void set_label_active(TreeIter iter, int i = -1) {
|
||||||
|
|
Loading…
Reference in a new issue