Show modal dialog to select default encryption if unknown

Thanks to mbeko for the UX suggestions.
This commit is contained in:
Xavier Del Campo Romero 2023-04-01 02:45:50 +02:00 committed by Maxim Logaev
parent d3a2e52285
commit 01070d089d
5 changed files with 165 additions and 1 deletions

View file

@ -67,6 +67,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

View file

@ -0,0 +1,77 @@
<?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">You are opening a new conversation without having set end-to-end encryption by default.
It is strongly recommended to enable it to prevent your messages from being read by third parties.
Please select an option to start this conversation with. Choosing one of the encryption methods will also set it as default in the global settings.
</property>
<property name="wrap">True</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="omemo">
<property name="label" translatable="yes">OMEMO (automatic setup)</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 (external setup required)</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</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">Apply</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>

View file

@ -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>

View file

@ -103,7 +103,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];

View file

@ -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);