aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/chat_input/encryption_button.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2022-05-14 14:45:59 +0200
committerfiaxh <git@lightrise.org>2022-07-27 20:34:20 +0200
commitf44cbe02c17df1f02ad49c63cd784fec0ea02d85 (patch)
tree4cab9b5f84d88769d19b0698e24b318f50b6144e /main/src/ui/chat_input/encryption_button.vala
parent2b3ce5fc95c63ed7d54e207db0585c8b8bbcd603 (diff)
downloaddino-f44cbe02c17df1f02ad49c63cd784fec0ea02d85.tar.gz
dino-f44cbe02c17df1f02ad49c63cd784fec0ea02d85.zip
Improve Gtk4 port
Diffstat (limited to 'main/src/ui/chat_input/encryption_button.vala')
-rw-r--r--main/src/ui/chat_input/encryption_button.vala54
1 files changed, 30 insertions, 24 deletions
diff --git a/main/src/ui/chat_input/encryption_button.vala b/main/src/ui/chat_input/encryption_button.vala
index e5831802..ab463f44 100644
--- a/main/src/ui/chat_input/encryption_button.vala
+++ b/main/src/ui/chat_input/encryption_button.vala
@@ -15,16 +15,39 @@ public class EncryptionButton {
private Map<CheckButton, Plugins.EncryptionListEntry> encryption_radios = new HashMap<CheckButton, Plugins.EncryptionListEntry>();
private string? current_icon;
private StreamInteractor stream_interactor;
+ private SimpleAction action;
public EncryptionButton(StreamInteractor stream_interactor, MenuButton menu_button) {
this.stream_interactor = stream_interactor;
this.menu_button = menu_button;
- Builder builder = new Builder.from_resource("/im/dino/Dino/menu_encryption.ui");
- menu_button.popover = builder.get_object("menu_encryption") as PopoverMenu;
- Box encryption_box = builder.get_object("encryption_box") as Box;
- button_unencrypted = builder.get_object("button_unencrypted") as CheckButton;
- button_unencrypted.toggled.connect(encryption_button_toggled);
+ // Build menu model including "Unencrypted" and all registered encryption entries
+ Menu menu_model = new Menu();
+
+ MenuItem unencrypted_item = new MenuItem(_("Unencrypted"), "enc.encryption");
+ unencrypted_item.set_action_and_target_value("enc.encryption", new Variant.int32(Encryption.NONE));
+ menu_model.append_item(unencrypted_item);
+
+ Application app = GLib.Application.get_default() as Application;
+ foreach (var e in app.plugin_registry.encryption_list_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);
+ }
+
+ // Create action to act on menu selections (stateful => radio buttons)
+ SimpleActionGroup action_group = new SimpleActionGroup();
+ 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();
+ });
+ action_group.insert(action);
+ menu_button.insert_action_group("enc", action_group);
+
+ // Create and set popover menu
+ Gtk.PopoverMenu popover_menu = new Gtk.PopoverMenu.from_model(menu_model);
+ menu_button.popover = popover_menu;
stream_interactor.get_module(MucManager.IDENTITY).room_info_updated.connect((account, muc_jid) => {
if (conversation != null && conversation.account.equals(account) && conversation.counterpart.equals(muc_jid)) {
@@ -32,15 +55,6 @@ public class EncryptionButton {
}
});
- Application app = GLib.Application.get_default() as Application;
- foreach (var e in app.plugin_registry.encryption_list_entries) {
- CheckButton btn = new CheckButton.with_label(e.name);
- btn.set_group(button_unencrypted);
- encryption_radios[btn] = e;
- btn.toggled.connect(encryption_button_toggled);
- btn.visible = true;
- encryption_box.prepend(btn);
- }
menu_button.activate.connect(update_encryption_menu_state);
}
@@ -61,16 +75,8 @@ public class EncryptionButton {
}
private void update_encryption_menu_state() {
- foreach (CheckButton e in encryption_radios.keys) {
- if (conversation.encryption == encryption_radios[e].encryption) {
- e.set_active(true);
- encryption_changed(encryption_radios[e]);
- }
- }
- if (conversation.encryption == Encryption.NONE) {
- button_unencrypted.set_active(true);
- encryption_changed(null);
- }
+ action.set_state(new Variant.int32(conversation.encryption));
+ action.change_state(new Variant.int32(conversation.encryption));
}
private void set_icon(string icon) {