diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-04-01 02:45:50 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-04-01 02:45:50 +0200 |
| commit | 2fd8837970dc9bfc3ca13c1b30132f0eea3fd5b7 (patch) | |
| tree | 2fb37fb6056a4e2d0dc6328242c222d0bf90ece3 | |
| parent | d166666acb2653c4522266be749fb3b2f3dd05eb (diff) | |
Show modal dialog to select default encryption if unknowndefault-encryption-gtk4
| -rw-r--r-- | main/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | main/data/default_encryption_dialog.ui | 78 | ||||
| -rw-r--r-- | main/data/gresource.xml | 1 | ||||
| -rw-r--r-- | main/src/ui/chat_input/chat_input_controller.vala | 2 | ||||
| -rw-r--r-- | main/src/ui/conversation_view_controller.vala | 85 |
5 files changed, 166 insertions, 1 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 1a66597c..681590b1 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -68,6 +68,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 global_search.ui diff --git a/main/data/default_encryption_dialog.ui b/main/data/default_encryption_dialog.ui new file mode 100644 index 00000000..60149e06 --- /dev/null +++ b/main/data/default_encryption_dialog.ui @@ -0,0 +1,78 @@ +<?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">True</property> + <property name="modal">True</property> + <property name="default_width">320</property> + <property name="default_height">260</property> + <child type="titlebar"> + <placeholder/> + </child> + <child> + <object class="GtkBox"> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <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="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> + </child> + <child> + <object class="GtkCheckButton" 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">False</property> + </object> + </child> + <child> + <object class="GtkCheckButton" 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">False</property> + <property name="group">omemo</property> + </object> + </child> + <child> + <object class="GtkCheckButton" 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">False</property> + <property name="group">omemo</property> + </object> + </child> + <child> + <object class="GtkButton" id="accept_button"> + <property name="label" translatable="yes">Accept</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + </object> + </child> + </object> + </child> + </object> + </child> + </object> +</interface> diff --git a/main/data/gresource.xml b/main/data/gresource.xml index 6d9febab..c8a3b014 100644 --- a/main/data/gresource.xml +++ b/main/data/gresource.xml @@ -16,6 +16,7 @@ <file>conversation_list_titlebar_csd.ui</file> <file>conversation_row.ui</file> <file>conversation_view.ui</file> + <file>default_encryption_dialog.ui</file> <file>dino-conversation-list-placeholder-arrow.svg</file> <file>file_default_widget.ui</file> <file>file_send_overlay.ui</file> diff --git a/main/src/ui/chat_input/chat_input_controller.vala b/main/src/ui/chat_input/chat_input_controller.vala index d9608a85..d6d71d53 100644 --- a/main/src/ui/chat_input/chat_input_controller.vala +++ b/main/src/ui/chat_input/chat_input_controller.vala @@ -104,7 +104,7 @@ public class ChatInputController : Object { private void on_encryption_changed(Encryption encryption) { reset_input_field_status(); - if (encryption == Encryption.NONE) return; + if (encryption == Encryption.NONE || encryption == Encryption.UNKNOWN) return; Application app = GLib.Application.get_default() as Application; var encryption_entry = app.plugin_registry.encryption_list_entries[encryption]; diff --git a/main/src/ui/conversation_view_controller.vala b/main/src/ui/conversation_view_controller.vala index da94b740..621bacae 100644 --- a/main/src/ui/conversation_view_controller.vala +++ b/main/src/ui/conversation_view_controller.vala @@ -114,6 +114,89 @@ public class ConversationViewController : Object { ((Gtk.Window)view.get_root()).add_shortcut(shortcut); } + 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 accept_button = selection_dialog_builder.get_object("accept_button") as Button; + var omemo_radio = selection_dialog_builder.get_object("omemo") as CheckButton; + var openpgp_radio = selection_dialog_builder.get_object("openpgp") as CheckButton; + var none_radio = selection_dialog_builder.get_object("none") as CheckButton; + Encryption selected_default = UNKNOWN; + + accept_button.sensitive = false; + + omemo_radio.toggled.connect(() => { + accept_button.sensitive = true; + }); + + openpgp_radio.toggled.connect(() => { + accept_button.sensitive = true; + }); + + none_radio.toggled.connect(() => { + accept_button.sensitive = true; + }); + + 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.response.connect((response_id) => { + if (response_id == Gtk.ResponseType.DELETE_EVENT) { + conversation.encryption = NONE; + } + else { + conversation.encryption = response_id; + + if (selected_default != NONE) { + settings.default_encryption = response_id; + } + else { + // Set conversation as unencrypted, but keep + // default encryption setting as undecided. + } + } + }); + + selection_dialog.show(); + } + 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); @@ -124,6 +207,8 @@ public class ConversationViewController : Object { this.conversation = conversation; + update_conversation_encryption(conversation); + // Set list model onto list view // Dino.Application app = GLib.Application.get_default() as Dino.Application; // var map_list_model = get_conversation_content_model(new ContentItemMetaModel(app.db, conversation, stream_interactor), stream_interactor); |
