Show modal dialog to select default encryption if unknown

This commit is contained in:
Xavier Del Campo Romero 2023-04-01 02:45:50 +02:00
parent d166666acb
commit 2fd8837970
5 changed files with 166 additions and 1 deletions

View File

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

View File

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

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

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

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