This commit is contained in:
fiaxh 2017-03-12 18:12:30 +01:00
parent 39722a4973
commit fabd6ff251
2 changed files with 18 additions and 15 deletions

View file

@ -5,6 +5,7 @@
<child> <child>
<object class="GtkButton" id="button"> <object class="GtkButton" id="button">
<property name="relief">none</property> <property name="relief">none</property>
<property name="sensitive">False</property>
<property name="visible">True</property> <property name="visible">True</property>
<child> <child>
<object class="GtkLabel" id="label"> <object class="GtkLabel" id="label">

View file

@ -66,44 +66,42 @@ private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
} }
private void populate_list_store() { private void populate_list_store() {
if (keys.size == 0) {
label.set_markup(build_markup_string("Key publishing disabled", "No keys available. Generate one!"));
return;
}
TreeIter iter; TreeIter iter;
list_store.append(out iter); list_store.append(out iter);
list_store.set(iter, 0, "Disabled\n<span font='9'>Select key</span>", 1, null); list_store.set(iter, 0, build_markup_string("Key publishing disabled", "Select key"), 1, "");
set_label_active(iter, 0);
for (int i = 0; i < keys.size; i++) { for (int i = 0; i < keys.size; i++) {
list_store.append(out iter); list_store.append(out iter);
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, 0, build_markup_string(keys[i].uids[0].uid, keys[i].fpr[0:16]));
list_store.set(iter, 1, keys[i].fpr); list_store.set(iter, 1, keys[i].fpr);
if (keys[i].fpr == plugin.db.get_account_key(current_account)) { if (keys[i].fpr == plugin.db.get_account_key(current_account)) {
set_label_active(iter, i + 1); set_label_active(iter, i + 1);
} }
} }
activate_current_account(); activate_current_account();
button.sensitive = true;
} }
private void fetch_keys() { private void fetch_keys() {
TreeIter iter;
list_store.clear();
list_store.append(out iter);
label.set_markup(build_markup_string("Loading...", "Querying GnuPG"));
new Thread<void*> (null, () => { // Querying GnuPG might take some while 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 { try {
keys = GPGHelper.get_keylist(null, true); keys = GPGHelper.get_keylist(null, true);
Idle.add(() => { Idle.add(() => {
list_store.clear(); list_store.clear();
populate_list_store(); populate_list_store();
button.sensitive = true;
return false; return false;
}); });
} catch (Error e) { } catch (Error e) {
Idle.add(() => { Idle.add(() => {
TreeIter iter; label.set_markup(build_markup_string("Key publishing disabled", "Error in GnuPG"));
list_store.append(out iter);
list_store.set(iter, 0, @"Disabled\n<span font='9'>Error in GnuPG</span>", 1, null);
return false; return false;
}); });
} }
@ -135,6 +133,10 @@ private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
deactivate(); deactivate();
} }
} }
private string build_markup_string(string primary, string secondary) {
return @"$(Markup.escape_text(primary))\n<span font='9'>$(Markup.escape_text(secondary))</span>";
}
} }
} }