From 054d3fec1627a9ee8d84d636d578aa68d3494d19 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 21 Aug 2022 00:10:59 +0200 Subject: [PATCH] Fix encryption button update and reduce its required GTK version MenuButton.activate only exists since 4.4 --- libdino/src/plugin/registry.vala | 10 ++--- main/data/theme.css | 17 ++++---- .../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 ++--- 6 files changed, 39 insertions(+), 46 deletions(-) diff --git a/libdino/src/plugin/registry.vala b/libdino/src/plugin/registry.vala index e28c4de7..e2801508 100644 --- a/libdino/src/plugin/registry.vala +++ b/libdino/src/plugin/registry.vala @@ -3,7 +3,7 @@ using Gee; namespace Dino.Plugins { public class Registry { - internal ArrayList encryption_list_entries = new ArrayList(); + internal HashMap encryption_list_entries = new HashMap(); internal HashMap call_encryption_entries = new HashMap(); internal ArrayList account_settings_entries = new ArrayList(); internal ArrayList contact_details_entries = new ArrayList(); @@ -17,11 +17,9 @@ public class Registry { public bool register_encryption_list_entry(EncryptionListEntry entry) { lock(encryption_list_entries) { - foreach(var e in encryption_list_entries) { - if (e.encryption == entry.encryption) return false; - } - encryption_list_entries.add(entry); - encryption_list_entries.sort((a,b) => b.name.collate(a.name)); + if (encryption_list_entries.has_key(entry.encryption)) return false; + + encryption_list_entries[entry.encryption] = entry; return true; } } diff --git a/main/data/theme.css b/main/data/theme.css index 782f980e..94cf1da5 100644 --- a/main/data/theme.css +++ b/main/data/theme.css @@ -242,7 +242,7 @@ box.dino-input-warning label { /*Chat input error*/ -box.dino-input-error frame border { +box.dino-input-error frame { border-color: @error_color; } @@ -251,19 +251,20 @@ box.dino-input-error frame separator { border: none; } -box.dino-input-error label { +box.dino-input-error .chat-input-status { color: @error_color; } @keyframes input-error-highlight { - 0% { color: mix(@error_color, @theme_fg_color, 0.3);} - 30% { color: @error_color; text-shadow: 0px 0px 2px alpha(@error_color, 0.4); } - 100% { color: mix(@error_color, @theme_fg_color, 0.3); } + 0% { transform: translate(0,0); } + 25% { transform: translate(-10px,0); } + 75% { transform: translate(10px,0); } + 100% { transform: translate(0,0); } } -box.dino-input-error label.input-status-highlight-once { - animation-duration: 1s; - animation-timing-function: linear; +box.dino-input-error .chat-input-status.input-status-highlight-once { + animation-duration: 0.5s; + animation-timing-function: ease-in-out; animation-iteration-count: 1; animation-name: input-error-highlight; } 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;