Setup default encryption settings
This commit is contained in:
parent
2a7063d992
commit
d3a2e52285
|
@ -35,7 +35,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; }
|
||||
|
||||
|
|
|
@ -11,6 +11,27 @@ namespace Dino.Entities {
|
|||
public bool is_some() {
|
||||
return this != NONE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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.UNKNOWN);
|
||||
}
|
||||
|
||||
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_; }
|
||||
|
@ -79,6 +86,20 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,49 @@
|
|||
<property name="search-enabled">False</property>
|
||||
<child>
|
||||
<object class="AdwPreferencesPage">
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup">
|
||||
<child>
|
||||
<object class="AdwActionRow">
|
||||
<property name="title" translatable="yes">Default encryption</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="default_encryption_box">
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="encryption_radio_undecided">
|
||||
<property name="label" translatable="yes">Ask</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">encryption_radio_undecided</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="encryption_radio_omemo">
|
||||
<property name="label" translatable="yes">OMEMO</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">encryption_radio_undecided</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="encryption_radio_openpgp">
|
||||
<property name="label" translatable="yes">OpenPGP</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">encryption_radio_undecided</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup">
|
||||
<child>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Gtk;
|
||||
using Dino.Entities;
|
||||
|
||||
namespace Dino.Ui {
|
||||
|
||||
|
@ -9,6 +10,9 @@ class SettingsDialog : Adw.PreferencesWindow {
|
|||
[GtkChild] private unowned Switch marker_switch;
|
||||
[GtkChild] private unowned Switch notification_switch;
|
||||
[GtkChild] private unowned Switch emoji_switch;
|
||||
[GtkChild] private unowned CheckButton encryption_radio_undecided;
|
||||
[GtkChild] private unowned CheckButton encryption_radio_omemo;
|
||||
[GtkChild] private unowned CheckButton encryption_radio_openpgp;
|
||||
|
||||
Dino.Entities.Settings settings = Dino.Application.get_default().settings;
|
||||
|
||||
|
@ -19,11 +23,34 @@ class SettingsDialog : Adw.PreferencesWindow {
|
|||
marker_switch.active = settings.send_marker;
|
||||
notification_switch.active = settings.notifications;
|
||||
emoji_switch.active = settings.convert_utf8_smileys;
|
||||
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_switch.notify["active"].connect(() => { settings.send_typing = typing_switch.active; } );
|
||||
marker_switch.notify["active"].connect(() => { settings.send_marker = marker_switch.active; } );
|
||||
notification_switch.notify["active"].connect(() => { settings.notifications = notification_switch.active; } );
|
||||
emoji_switch.notify["active"].connect(() => { settings.convert_utf8_smileys = emoji_switch.active; });
|
||||
|
||||
encryption_radio_undecided.notify["active"].connect(() => {
|
||||
if (encryption_radio_undecided.active) {
|
||||
settings.default_encryption = Encryption.UNKNOWN;
|
||||
}
|
||||
});
|
||||
|
||||
encryption_radio_omemo.notify["active"].connect(() => {
|
||||
if (encryption_radio_omemo.active) {
|
||||
settings.default_encryption = Encryption.OMEMO;
|
||||
}
|
||||
});
|
||||
|
||||
encryption_radio_openpgp.notify["active"].connect(() => {
|
||||
if (encryption_radio_openpgp.active) {
|
||||
settings.default_encryption = Encryption.PGP;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue