diff options
author | fiaxh <git@lightrise.org> | 2022-08-21 00:10:59 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2022-08-21 14:16:31 +0200 |
commit | 054d3fec1627a9ee8d84d636d578aa68d3494d19 (patch) | |
tree | b01b7ab4be03d40ec24275de7cc31b21b76bc18b /main/src/ui/chat_input | |
parent | d6afa6e8ff4cfb533140d9434b83f18f627f11ca (diff) | |
download | dino-054d3fec1627a9ee8d84d636d578aa68d3494d19.tar.gz dino-054d3fec1627a9ee8d84d636d578aa68d3494d19.zip |
Fix encryption button update and reduce its required GTK version
MenuButton.activate only exists since 4.4
Diffstat (limited to 'main/src/ui/chat_input')
-rw-r--r-- | main/src/ui/chat_input/chat_input_controller.vala | 6 | ||||
-rw-r--r-- | main/src/ui/chat_input/encryption_button.vala | 40 | ||||
-rw-r--r-- | main/src/ui/chat_input/view.vala | 2 |
3 files changed, 23 insertions, 25 deletions
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<CheckButton, Plugins.EncryptionListEntry> encryption_radios = new HashMap<CheckButton, Plugins.EncryptionListEntry>(); 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<Plugins.EncryptionListEntry>(); 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; }); |