aboutsummaryrefslogtreecommitdiff
path: root/plugins/openpgp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/openpgp')
-rw-r--r--plugins/openpgp/CMakeLists.txt3
-rw-r--r--plugins/openpgp/data/account_settings_item.ui44
-rw-r--r--plugins/openpgp/src/account_settings_entry.vala156
-rw-r--r--plugins/openpgp/src/account_settings_widget.vala149
-rw-r--r--plugins/openpgp/src/contact_details_provider.vala2
-rw-r--r--plugins/openpgp/src/encryption_list_entry.vala6
6 files changed, 173 insertions, 187 deletions
diff --git a/plugins/openpgp/CMakeLists.txt b/plugins/openpgp/CMakeLists.txt
index 769d517d..649a55ad 100644
--- a/plugins/openpgp/CMakeLists.txt
+++ b/plugins/openpgp/CMakeLists.txt
@@ -9,7 +9,7 @@ find_packages(OPENPGP_PACKAGES REQUIRED
GLib
GModule
GObject
- GTK3
+ GTK4
)
set(RESOURCE_LIST
@@ -32,7 +32,6 @@ SOURCES
src/file_transfer/file_encryptor.vala
src/account_settings_entry.vala
- src/account_settings_widget.vala
src/contact_details_provider.vala
src/database.vala
src/encryption_list_entry.vala
diff --git a/plugins/openpgp/data/account_settings_item.ui b/plugins/openpgp/data/account_settings_item.ui
index f9757c2b..56808be0 100644
--- a/plugins/openpgp/data/account_settings_item.ui
+++ b/plugins/openpgp/data/account_settings_item.ui
@@ -1,31 +1,31 @@
-<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <template class="DinoPluginsOpenPgpAccountSettingsWidget">
- <property name="visible">True</property>
+ <requires lib="gtk" version="4.0"/>
+ <object class="GtkStack" id="stack">
<child>
- <object class="GtkButton" id="button">
- <property name="relief">none</property>
- <property name="sensitive">False</property>
- <property name="visible">True</property>
- <child>
- <object class="GtkLabel" id="label">
- <property name="xalign">0</property>
- <property name="visible">True</property>
+ <object class="GtkStackPage">
+ <property name="name">label</property>
+ <property name="child">
+ <object class="GtkButton" id="button">
+ <property name="has-frame">0</property>
+ <property name="sensitive">0</property>
+ <child>
+ <object class="GtkLabel" id="label">
+ <property name="xalign">0</property>
+ </object>
+ </child>
</object>
- </child>
+ </property>
</object>
- <packing>
- <property name="name">label</property>
- </packing>
</child>
<child>
- <object class="GtkComboBox" id="combobox">
- <property name="hexpand">True</property>
- <property name="visible">True</property>
- </object>
- <packing>
+ <object class="GtkStackPage">
<property name="name">entry</property>
- </packing>
+ <property name="child">
+ <object class="GtkComboBox" id="combobox">
+ <property name="hexpand">1</property>
+ </object>
+ </property>
+ </object>
</child>
- </template>
+ </object>
</interface> \ No newline at end of file
diff --git a/plugins/openpgp/src/account_settings_entry.vala b/plugins/openpgp/src/account_settings_entry.vala
index 75220c30..d2e5ac23 100644
--- a/plugins/openpgp/src/account_settings_entry.vala
+++ b/plugins/openpgp/src/account_settings_entry.vala
@@ -1,27 +1,161 @@
+using Dino.Entities;
+using Gtk;
+
namespace Dino.Plugins.OpenPgp {
public class AccountSettingsEntry : Plugins.AccountSettingsEntry {
+ private Label label;
+ private Button button;
+ private ComboBox combobox;
+ private Stack stack;
+
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 override string id { get { return "pgp_key_picker"; }}
+
+ public override string name { get { return "OpenPGP"; }}
public AccountSettingsEntry(Plugin plugin) {
this.plugin = plugin;
+
+ Builder builder = new Builder.from_resource("/im/dino/Dino/openpgp/account_settings_item.ui");
+ stack = (Stack) builder.get_object("stack");
+ label = (Label) builder.get_object("label");
+ button = (Button) builder.get_object("button");
+ combobox = (ComboBox) builder.get_object("combobox");
+
+ CellRendererText renderer = new CellRendererText();
+ 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);
}
- public override string id { get {
- return "pgp_key_picker";
- }}
+ public override void deactivate() {
+ stack.set_visible_child_name("label");
+ }
- public override string name { get {
- return "OpenPGP";
- }}
+ public override void set_account(Account account) {
+ set_account_.begin(account);
+ }
- public override Plugins.AccountSettingsWidget? get_widget(WidgetType type) {
- if (type == WidgetType.GTK) {
- return new AccountSettingsWidget(plugin);
+ private async void set_account_(Account account) {
+ this.current_account = account;
+ if (keys == null) {
+ yield fetch_keys();
+ populate_list_store();
}
- return null;
+ activate_current_account();
}
-}
+ private void on_button_clicked() {
+ activated();
+ stack.set_visible_child_name("entry");
+ combobox.grab_focus();
+ combobox.popup();
+ }
+
+ private void activate_current_account() {
+ 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);
+ 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;
+
+ TreeIter selected;
+ combobox.get_active_iter(out selected);
+ set_label_active(selected);
+
+ combobox.changed.connect(key_changed);
+ }
+
+ private void populate_list_store() {
+ if (keys == null || keys.size == 0) {
+ return;
+ }
+
+ list_store.clear();
+ TreeIter 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, "");
+ for (int i = 0; i < keys.size; i++) {
+ list_store.append(out iter);
+ list_store.set(iter, 0, @"$(Markup.escape_text(keys[i].uids[0].uid))\n<span font_family='monospace' font='8'>$(markup_colorize_id(keys[i].fpr, true))</span><span font='8'> </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);
+ }
+ }
+ button.sensitive = true;
+ }
+
+ private async void fetch_keys() {
+ label.set_markup(build_markup_string(_("Loading…"), _("Querying GnuPG")));
+
+ SourceFunc callback = fetch_keys.callback;
+ new Thread<void*> (null, () => { // Querying GnuPG might take some time
+ try {
+ keys = GPGHelper.get_keylist(null, true);
+ } catch (Error e) { }
+ Idle.add((owned)callback);
+ return null;
+ });
+ yield;
+ }
+
+ private void set_label_active(TreeIter iter, int i = -1) {
+ Value text;
+ list_store.get_value(iter, 0, out text);
+ label.set_markup((string) text);
+ if (i != -1) combobox.active = i;
+ }
+
+ private void key_changed() {
+ TreeIter selected;
+ bool iter_valid = combobox.get_active_iter(out selected);
+ if (iter_valid) {
+ Value key_value;
+ list_store.get_value(selected, 1, out key_value);
+ string? key_id = key_value as string;
+ if (key_id != null) {
+ if (plugin.modules.has_key(current_account)) {
+ plugin.modules[current_account].set_private_key_id(key_id);
+ }
+ plugin.db.set_account_key(current_account, key_id);
+ }
+ set_label_active(selected);
+ deactivate();
+ }
+ }
+
+ private string build_markup_string(string primary, string secondary) {
+ return @"$(Markup.escape_text(primary))\n<span font='8'>$secondary</span>";
+ }
+
+ public override Object? get_widget(WidgetType type) {
+ if (type != WidgetType.GTK4) return null;
+ return stack;
+ }
+}
} \ No newline at end of file
diff --git a/plugins/openpgp/src/account_settings_widget.vala b/plugins/openpgp/src/account_settings_widget.vala
deleted file mode 100644
index 7c417001..00000000
--- a/plugins/openpgp/src/account_settings_widget.vala
+++ /dev/null
@@ -1,149 +0,0 @@
-using Gee;
-using Gtk;
-
-using Dino.Entities;
-
-namespace Dino.Plugins.OpenPgp {
-
-[GtkTemplate (ui = "/im/dino/Dino/openpgp/account_settings_item.ui")]
-
-private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
- [GtkChild] private unowned Label label;
- [GtkChild] private unowned Button button;
- [GtkChild] private unowned ComboBox combobox;
-
- 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) {
- this.plugin = plugin;
-
- CellRendererText renderer = new CellRendererText();
- 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);
- }
-
- public void deactivate() {
- set_visible_child_name("label");
- }
-
- public void set_account(Account account) {
- set_account_.begin(account);
- }
-
- private async void set_account_(Account account) {
- this.current_account = account;
- if (keys == null) {
- yield fetch_keys();
- populate_list_store();
- }
- activate_current_account();
- }
-
- private void on_button_clicked() {
- activated();
- set_visible_child_name("entry");
- combobox.grab_focus();
- combobox.popup();
- }
-
- private void activate_current_account() {
- 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);
- 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;
-
- TreeIter selected;
- combobox.get_active_iter(out selected);
- set_label_active(selected);
-
- combobox.changed.connect(key_changed);
- }
-
- private void populate_list_store() {
- if (keys == null || keys.size == 0) {
- return;
- }
-
- list_store.clear();
- TreeIter 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, "");
- for (int i = 0; i < keys.size; i++) {
- list_store.append(out iter);
- list_store.set(iter, 0, @"$(Markup.escape_text(keys[i].uids[0].uid))\n<span font_family='monospace' font='8'>$(markup_colorize_id(keys[i].fpr, true))</span><span font='8'> </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);
- }
- }
- button.sensitive = true;
- }
-
- private async void fetch_keys() {
- label.set_markup(build_markup_string(_("Loading…"), _("Querying GnuPG")));
-
- SourceFunc callback = fetch_keys.callback;
- new Thread<void*> (null, () => { // Querying GnuPG might take some time
- try {
- keys = GPGHelper.get_keylist(null, true);
- } catch (Error e) { }
- Idle.add((owned)callback);
- return null;
- });
- yield;
- }
-
- private void set_label_active(TreeIter iter, int i = -1) {
- Value text;
- list_store.get_value(iter, 0, out text);
- label.set_markup((string) text);
- if (i != -1) combobox.active = i;
- }
-
- private void key_changed() {
- TreeIter selected;
- bool iter_valid = combobox.get_active_iter(out selected);
- if (iter_valid) {
- Value key_value;
- list_store.get_value(selected, 1, out key_value);
- string? key_id = key_value as string;
- if (key_id != null) {
- if (plugin.modules.has_key(current_account)) {
- plugin.modules[current_account].set_private_key_id(key_id);
- }
- plugin.db.set_account_key(current_account, key_id);
- }
- set_label_active(selected);
- deactivate();
- }
- }
-
- private string build_markup_string(string primary, string secondary) {
- return @"$(Markup.escape_text(primary))\n<span font='8'>$secondary</span>";
- }
-}
-
-}
diff --git a/plugins/openpgp/src/contact_details_provider.vala b/plugins/openpgp/src/contact_details_provider.vala
index aa2b1c47..db085a4d 100644
--- a/plugins/openpgp/src/contact_details_provider.vala
+++ b/plugins/openpgp/src/contact_details_provider.vala
@@ -14,7 +14,7 @@ public class ContactDetailsProvider : Plugins.ContactDetailsProvider, Object {
}
public void populate(Conversation conversation, Plugins.ContactDetails contact_details, WidgetType type) {
- if (conversation.type_ == Conversation.Type.CHAT && type == WidgetType.GTK) {
+ if (conversation.type_ == Conversation.Type.CHAT && type == WidgetType.GTK4) {
string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart);
if (key_id != null) {
Label label = new Label("") { use_markup=true, justify=Justification.RIGHT, selectable=true, visible=true };
diff --git a/plugins/openpgp/src/encryption_list_entry.vala b/plugins/openpgp/src/encryption_list_entry.vala
index 4169a2a2..cf5da8c4 100644
--- a/plugins/openpgp/src/encryption_list_entry.vala
+++ b/plugins/openpgp/src/encryption_list_entry.vala
@@ -24,12 +24,14 @@ private class EncryptionListEntry : Plugins.EncryptionListEntry, Object {
return "OpenPGP";
}}
- public static IconSize ICON_SIZE_HEADER = Gtk.icon_size_register("im.dino.Dino.HEADER_ICON3", 17, 12);
-
public Object? get_encryption_icon(Entities.Conversation conversation, ContentItem content_item) {
return null;
}
+ public string? get_encryption_icon_name(Entities.Conversation conversation, ContentItem content_item) {
+ return null;
+ }
+
public void encryption_activated(Entities.Conversation conversation, Plugins.SetInputFieldStatus input_status_callback) {
try {
GPGHelper.get_public_key(db.get_account_key(conversation.account) ?? "");