diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-05-15 15:29:15 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-10-05 14:32:07 +0200 |
| commit | 302e770a98c8fc024bf3dae4266dc034a8e14d09 (patch) | |
| tree | 76dfb0bc482959c5d8e9bf8dcbbb749ad5cfe7f3 | |
| parent | 366a49a82073a591c9b06979fd2bbb0c102a9581 (diff) | |
Show modal dialog to select default encryption if unknown
| -rw-r--r-- | libdino/src/entity/conversation.vala | 2 | ||||
| -rw-r--r-- | main/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | main/data/default_encryption_dialog.ui | 125 | ||||
| -rw-r--r-- | main/src/ui/conversation_view_controller.vala | 63 |
4 files changed, 190 insertions, 1 deletions
diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala index 9376dca9..57f0037d 100644 --- a/libdino/src/entity/conversation.vala +++ b/libdino/src/entity/conversation.vala @@ -33,7 +33,7 @@ public class Conversation : Object { } } } - public Encryption encryption { get; set; default = Encryption.NONE; } + public Encryption encryption { get; set; default = Encryption.UNKNOWN; } public Message? read_up_to { get; set; } public int read_up_to_item { get; set; default=-1; } diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 2326253c..765188ec 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -64,6 +64,7 @@ set(RESOURCE_LIST conversation_list_titlebar_csd.ui conversation_row.ui conversation_view.ui + default_encryption_dialog.ui file_default_widget.ui file_send_overlay.ui emojichooser.ui diff --git a/main/data/default_encryption_dialog.ui b/main/data/default_encryption_dialog.ui new file mode 100644 index 00000000..81e794ae --- /dev/null +++ b/main/data/default_encryption_dialog.ui @@ -0,0 +1,125 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.2 --> +<interface> + <requires lib="gtk+" version="3.6"/> + <object class="GtkDialog" id="dialog"> + <property name="can_focus">False</property> + <property name="modal">True</property> + <property name="default_width">320</property> + <property name="default_height">260</property> + <property name="type_hint">dialog</property> + <child type="titlebar"> + <placeholder/> + </child> + <child internal-child="vbox"> + <object class="GtkBox"> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <child internal-child="action_area"> + <object class="GtkButtonBox"> + <property name="can_focus">False</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="accept_button"> + <property name="label" translatable="yes">OK</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkLabel" id="default_encryption_warning_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xpad">10</property> + <property name="ypad">10</property> + <property name="label" translatable="yes">No default end-to-end encryption method has been previously selected for this conversation. XMPP defines some XEP for end-to-end encryption that Dino supports. + +It is strongly recommended that one of the following end-to-end encryption methods below is selected before sending a message. + +TAKE INTO ACCOUNT UNENCRYPTED CONVERSATIONS COULD BE READ BY THIRD PARTIES. + +These settings can be later changed from the Settings menu.</property> + <property name="wrap">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="omemo"> + <property name="label" translatable="yes">OMEMO (XEP-0384)</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="openpgp"> + <property name="label" translatable="yes">OpenPGP (XEP-0027)</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + <property name="group">omemo</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="none"> + <property name="label" translatable="yes">Unencrypted (not recommended)</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + <property name="group">omemo</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">3</property> + </packing> + </child> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + </object> + </child> + </object> +</interface> diff --git a/main/src/ui/conversation_view_controller.vala b/main/src/ui/conversation_view_controller.vala index bd52c50c..7cea3212 100644 --- a/main/src/ui/conversation_view_controller.vala +++ b/main/src/ui/conversation_view_controller.vala @@ -110,6 +110,67 @@ public class ConversationViewController : Object { ((Gtk.Window)view.get_toplevel()).add_accel_group(accel_group); } + private void update_conversation_encryption(Conversation? conversation) { + if (conversation == null) { + return; + } + + bool visible = false; + + // FIXME duplicate logic from encryption_button.vala + switch (conversation.type_) { + case Conversation.Type.CHAT: + visible = true; + break; + case Conversation.Type.GROUPCHAT_PM: + visible = false; + break; + case Conversation.Type.GROUPCHAT: + visible = stream_interactor.get_module(MucManager.IDENTITY).is_private_room(conversation.account, conversation.counterpart); + break; + } + + if (visible && conversation.encryption == UNKNOWN) { + Dino.Entities.Settings settings = Dino.Application.get_default().settings; + + if (settings.default_encryption == UNKNOWN) { + var selection_dialog_builder = new Builder.from_resource("/im/dino/Dino/default_encryption_dialog.ui"); + var selection_dialog = selection_dialog_builder.get_object("dialog") as Dialog; + var omemo_radio = selection_dialog_builder.get_object("omemo") as RadioButton; + var openpgp_radio = selection_dialog_builder.get_object("openpgp") as RadioButton; + var none_radio = selection_dialog_builder.get_object("none") as RadioButton; + var accept_button = selection_dialog_builder.get_object("accept_button") as Button; + Encryption selected_default = UNKNOWN; + + accept_button.clicked.connect(() => { + if (omemo_radio.active) {selected_default = OMEMO;} + else if (openpgp_radio.active) {selected_default = PGP;} + else if (none_radio.active) {selected_default = NONE;} + + selection_dialog.response(selected_default); + selection_dialog.close(); + }); + + selection_dialog.run(); + conversation.encryption = selected_default; + + if (selected_default != NONE) { + settings.default_encryption = selected_default; + } + else { + // Set conversation as unencrypted, but keep + // default encryption setting as undecided. + } + } + else { + conversation.encryption = settings.default_encryption; + } + } + else if (!visible) { + conversation.encryption = Encryption.NONE; + } + } + public void select_conversation(Conversation? conversation, bool default_initialize_conversation) { if (this.conversation != null) { conversation.notify["encryption"].disconnect(update_file_upload_status); @@ -120,6 +181,8 @@ public class ConversationViewController : Object { this.conversation = conversation; + update_conversation_encryption(conversation); + conversation.notify["encryption"].connect(update_file_upload_status); chat_input_controller.set_conversation(conversation); |
