From 366a49a82073a591c9b06979fd2bbb0c102a9581 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sun, 15 May 2022 11:50:26 +0200 Subject: Set up default encryption settings GUI --- libdino/src/entity/encryption.vala | 23 +++++++++++- libdino/src/entity/settings.vala | 20 +++++++++++ main/data/settings_dialog.ui | 71 ++++++++++++++++++++++++++++++++++++++ main/src/ui/settings_dialog.vala | 25 ++++++++++++++ 4 files changed, 138 insertions(+), 1 deletion(-) diff --git a/libdino/src/entity/encryption.vala b/libdino/src/entity/encryption.vala index 193d741b..f6427b02 100644 --- a/libdino/src/entity/encryption.vala +++ b/libdino/src/entity/encryption.vala @@ -6,7 +6,28 @@ public enum Encryption { OMEMO, DTLS_SRTP, SRTP, - UNKNOWN, + UNKNOWN; + + public static Encryption parse(string str) { + switch (str) { + case "DINO_ENTITIES_ENCRYPTION_NONE": + return NONE; + case "DINO_ENTITIES_ENCRYPTION_PGP": + return PGP; + case "DINO_ENTITIES_ENCRYPTION_OMEMO": + return OMEMO; + case "DINO_ENTITIES_ENCRYPTION_DTLS_SRTP": + return DTLS_SRTP; + case "DINO_ENTITIES_ENCRYPTION_SRTP": + return SRTP; + case "DINO_ENTITIES_ENCRYPTION_UNKNOWN": + // Fall through. + default: + break; + } + + return UNKNOWN; + } } } \ No newline at end of file diff --git a/libdino/src/entity/settings.vala b/libdino/src/entity/settings.vala index 97ea5482..716c5f7d 100644 --- a/libdino/src/entity/settings.vala +++ b/libdino/src/entity/settings.vala @@ -12,6 +12,7 @@ public class Settings : Object { notifications_ = col_to_bool_or_default("notifications", true); convert_utf8_smileys_ = col_to_bool_or_default("convert_utf8_smileys", true); check_spelling = col_to_bool_or_default("check_spelling", true); + default_encryption = col_to_encryption_or_default("default_encryption", Encryption.OMEMO); } private bool col_to_bool_or_default(string key, bool def) { @@ -19,6 +20,12 @@ public class Settings : Object { return val != null ? bool.parse(val) : def; } + private Encryption col_to_encryption_or_default(string key, Encryption def) { + var sval = db.settings.value; + string? val = db.settings.select({sval}).with(db.settings.key, "=", key)[sval]; + return val != null ? Encryption.parse(val) : def; + } + private bool send_typing_; public bool send_typing { get { return send_typing_; } @@ -78,6 +85,19 @@ public class Settings : Object { check_spelling_ = value; } } + + private Encryption default_encryption_; + public Encryption default_encryption { + get { return default_encryption_; } + set { + string valstr = value.to_string(); + db.settings.upsert() + .value(db.settings.key, "default_encryption", true) + .value(db.settings.value, valstr) + .perform(); + default_encryption_ = value; + } + } } } diff --git a/main/data/settings_dialog.ui b/main/data/settings_dialog.ui index d5b7ac92..2d4b52c3 100644 --- a/main/data/settings_dialog.ui +++ b/main/data/settings_dialog.ui @@ -77,6 +77,77 @@ 1 + + + True + False + + + Default encryption + True + + + False + True + 0 + + + + + Ask + True + True + False + True + True + encryption_radio_undecided + + + False + True + 1 + + + + + OMEMO + True + True + False + True + True + encryption_radio_undecided + + + False + True + 2 + + + + + OpenPGP + True + True + False + True + True + encryption_radio_undecided + + + False + True + 3 + + + + + 0 + 5 + 1 + 1 + + diff --git a/main/src/ui/settings_dialog.vala b/main/src/ui/settings_dialog.vala index e994e00c..59edef2c 100644 --- a/main/src/ui/settings_dialog.vala +++ b/main/src/ui/settings_dialog.vala @@ -1,4 +1,5 @@ using Gtk; +using Dino.Entities; namespace Dino.Ui { @@ -10,6 +11,9 @@ class SettingsDialog : Dialog { [GtkChild] private unowned CheckButton notification_checkbutton; [GtkChild] private unowned CheckButton emoji_checkbutton; [GtkChild] private unowned CheckButton check_spelling_checkbutton; + [GtkChild] private unowned RadioButton encryption_radio_undecided; + [GtkChild] private unowned RadioButton encryption_radio_omemo; + [GtkChild] private unowned RadioButton encryption_radio_openpgp; Dino.Entities.Settings settings = Dino.Application.get_default().settings; @@ -21,12 +25,33 @@ class SettingsDialog : Dialog { notification_checkbutton.active = settings.notifications; emoji_checkbutton.active = settings.convert_utf8_smileys; check_spelling_checkbutton.active = settings.check_spelling; + encryption_radio_undecided.active = settings.default_encryption == Encryption.UNKNOWN; + encryption_radio_omemo.active = settings.default_encryption == Encryption.OMEMO; + encryption_radio_openpgp.active = settings.default_encryption == Encryption.PGP; typing_checkbutton.toggled.connect(() => { settings.send_typing = typing_checkbutton.active; } ); marker_checkbutton.toggled.connect(() => { settings.send_marker = marker_checkbutton.active; } ); notification_checkbutton.toggled.connect(() => { settings.notifications = notification_checkbutton.active; } ); emoji_checkbutton.toggled.connect(() => { settings.convert_utf8_smileys = emoji_checkbutton.active; }); check_spelling_checkbutton.toggled.connect(() => { settings.check_spelling = check_spelling_checkbutton.active; }); + + encryption_radio_undecided.toggled.connect(() => { + if (encryption_radio_undecided.active) { + settings.default_encryption = Encryption.UNKNOWN; + } + }); + + encryption_radio_omemo.toggled.connect(() => { + if (encryption_radio_omemo.active) { + settings.default_encryption = Encryption.OMEMO; + } + }); + + encryption_radio_openpgp.toggled.connect(() => { + if (encryption_radio_openpgp.active) { + settings.default_encryption = Encryption.PGP; + } + }); } } -- cgit v1.2.3