From 054d3fec1627a9ee8d84d636d578aa68d3494d19 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 21 Aug 2022 00:10:59 +0200 Subject: Fix encryption button update and reduce its required GTK version MenuButton.activate only exists since 4.4 --- main/src/ui/chat_input/chat_input_controller.vala | 6 ++-- main/src/ui/chat_input/encryption_button.vala | 40 ++++++++++------------ main/src/ui/chat_input/view.vala | 2 +- .../conversation_item_skeleton.vala | 10 ++---- 4 files changed, 26 insertions(+), 32 deletions(-) (limited to 'main/src/ui') diff --git a/main/src/ui/chat_input/chat_input_controller.vala b/main/src/ui/chat_input/chat_input_controller.vala index b60a17d4..7b260695 100644 --- a/main/src/ui/chat_input/chat_input_controller.vala +++ b/main/src/ui/chat_input/chat_input_controller.vala @@ -77,11 +77,13 @@ public class ChatInputController : Object { chat_input.set_file_upload_active(active); } - private void on_encryption_changed(Plugins.EncryptionListEntry? encryption_entry) { + private void on_encryption_changed(Encryption encryption) { reset_input_field_status(); - if (encryption_entry == null) return; + if (encryption == Encryption.NONE) return; + Application app = GLib.Application.get_default() as Application; + var encryption_entry = app.plugin_registry.encryption_list_entries[encryption]; encryption_entry.encryption_activated(conversation, set_input_field_status); } diff --git a/main/src/ui/chat_input/encryption_button.vala b/main/src/ui/chat_input/encryption_button.vala index ab463f44..50497ee3 100644 --- a/main/src/ui/chat_input/encryption_button.vala +++ b/main/src/ui/chat_input/encryption_button.vala @@ -7,15 +7,15 @@ namespace Dino.Ui { public class EncryptionButton { - public signal void encryption_changed(Plugins.EncryptionListEntry? encryption_entry); + public signal void encryption_changed(Encryption encryption); private MenuButton menu_button; private Conversation? conversation; private CheckButton? button_unencrypted; - private Map encryption_radios = new HashMap(); private string? current_icon; private StreamInteractor stream_interactor; private SimpleAction action; + ulong conversation_encryption_handler_id = -1; public EncryptionButton(StreamInteractor stream_interactor, MenuButton menu_button) { this.stream_interactor = stream_interactor; @@ -28,8 +28,11 @@ public class EncryptionButton { unencrypted_item.set_action_and_target_value("enc.encryption", new Variant.int32(Encryption.NONE)); menu_model.append_item(unencrypted_item); + var encryption_entries = new ArrayList(); Application app = GLib.Application.get_default() as Application; - foreach (var e in app.plugin_registry.encryption_list_entries) { + encryption_entries.add_all(app.plugin_registry.encryption_list_entries.values); + encryption_entries.sort((a,b) => b.name.collate(a.name)); + foreach (var e in encryption_entries) { MenuItem item = new MenuItem(e.name, "enc.encryption"); item.set_action_and_target_value("enc.encryption", new Variant.int32(e.encryption)); menu_model.append_item(item); @@ -40,7 +43,8 @@ public class EncryptionButton { action = new SimpleAction.stateful("encryption", VariantType.INT32, new Variant.int32(Encryption.NONE)); action.activate.connect((parameter) => { action.set_state(parameter); - this.conversation.encryption = (Encryption) parameter.get_int32(); + conversation.encryption = (Encryption) parameter.get_int32(); + encryption_changed(conversation.encryption); }); action_group.insert(action); menu_button.insert_action_group("enc", action_group); @@ -54,24 +58,6 @@ public class EncryptionButton { update_visibility(); } }); - - menu_button.activate.connect(update_encryption_menu_state); - } - - private void encryption_button_toggled() { - foreach (CheckButton e in encryption_radios.keys) { - if (e.get_active()) { - conversation.encryption = encryption_radios[e].encryption; - encryption_changed(encryption_radios[e]); - update_encryption_menu_icon(); - return; - } - } - - // Selected unencrypted - conversation.encryption = Encryption.NONE; - update_encryption_menu_icon(); - encryption_changed(null); } private void update_encryption_menu_state() { @@ -109,10 +95,20 @@ public class EncryptionButton { } public void set_conversation(Conversation conversation) { + if (conversation_encryption_handler_id != -1 && this.conversation != null) { + this.conversation.disconnect(conversation_encryption_handler_id); + } + this.conversation = conversation; update_encryption_menu_state(); update_encryption_menu_icon(); update_visibility(); + encryption_changed(this.conversation.encryption); + + conversation_encryption_handler_id = conversation.notify["encryption"].connect(() => { + update_encryption_menu_state(); + update_encryption_menu_icon(); + }); } } diff --git a/main/src/ui/chat_input/view.vala b/main/src/ui/chat_input/view.vala index 3de060c6..4be4455b 100644 --- a/main/src/ui/chat_input/view.vala +++ b/main/src/ui/chat_input/view.vala @@ -88,7 +88,7 @@ public class View : Box { public void highlight_state_description() { chat_input_status.add_css_class("input-status-highlight-once"); - Timeout.add_seconds(1, () => { + Timeout.add(500, () => { chat_input_status.remove_css_class("input-status-highlight-once"); return false; }); diff --git a/main/src/ui/conversation_content_view/conversation_item_skeleton.vala b/main/src/ui/conversation_content_view/conversation_item_skeleton.vala index 14fcd536..e4e6b804 100644 --- a/main/src/ui/conversation_content_view/conversation_item_skeleton.vala +++ b/main/src/ui/conversation_content_view/conversation_item_skeleton.vala @@ -132,19 +132,15 @@ public class ConversationItemSkeleton : Plugins.ConversationItemWidgetInterface, ContentMetaItem ci = item as ContentMetaItem; if (item.encryption != Encryption.NONE && item.encryption != Encryption.UNKNOWN && ci != null) { string? icon_name = null; - foreach(var e in app.plugin_registry.encryption_list_entries) { - if (e.encryption == item.encryption) { - icon_name = e.get_encryption_icon_name(conversation, ci.content_item); - break; - } - } + var encryption_entry = app.plugin_registry.encryption_list_entries[item.encryption]; + icon_name = encryption_entry.get_encryption_icon_name(conversation, ci.content_item); encryption_image.icon_name = icon_name ?? "changes-prevent-symbolic"; encryption_image.visible = true; } if (item.encryption == Encryption.NONE) { if (conversation.encryption != Encryption.NONE) { - encryption_image.icon_name = "dino-changes-allowed-symbolic"; + encryption_image.icon_name = "changes-allow-symbolic"; encryption_image.tooltip_text = Util.string_if_tooltips_active(_("Unencrypted")); Util.force_error_color(encryption_image); encryption_image.visible = true; -- cgit v1.2.3-70-g09d2