aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/entity/settings.vala
diff options
context:
space:
mode:
Diffstat (limited to 'libdino/src/entity/settings.vala')
-rw-r--r--libdino/src/entity/settings.vala147
1 files changed, 147 insertions, 0 deletions
diff --git a/libdino/src/entity/settings.vala b/libdino/src/entity/settings.vala
index c71a8e57..d03bb39f 100644
--- a/libdino/src/entity/settings.vala
+++ b/libdino/src/entity/settings.vala
@@ -2,6 +2,8 @@ namespace Dino.Entities {
public class Settings : Object {
+ public signal void account_color_changed(Account account, string color);
+
private Database db;
public Settings.from_db(Database db) {
@@ -11,8 +13,17 @@ public class Settings : Object {
send_marker_ = col_to_bool_or_default("send_marker", true);
share_time_ = col_to_bool_or_default("share_time", true);
notifications_ = col_to_bool_or_default("notifications", true);
+ notifications_files_ = col_to_bool_or_default("notifications_files", notifications_);
+ notifications_calls_ = col_to_bool_or_default("notifications_calls", true);
+ notifications_subscription_requests_ = col_to_bool_or_default("notifications_subscription_requests", true);
+ notifications_group_chat_invitations_ = col_to_bool_or_default("notifications_group_chat_invitations", true);
+ notifications_permission_requests_ = col_to_bool_or_default("notifications_permission_requests", true);
+ notifications_connection_errors_ = col_to_bool_or_default("notifications_connection_errors", true);
+ notifications_badge_ = col_to_bool_or_default("notifications_badge", true);
convert_utf8_smileys_ = col_to_bool_or_default("convert_utf8_smileys", true);
check_spelling = col_to_bool_or_default("check_spelling", true);
+ avatar_roundness_ = col_to_int_or_default("avatar_roundness", 20).clamp(0, 100);
+ custom_css_ = db.settings.select({db.settings.value}).with(db.settings.key, "=", "custom_css")[db.settings.value] ?? "";
}
private bool col_to_bool_or_default(string key, bool def) {
@@ -20,6 +31,12 @@ public class Settings : Object {
return val != null ? bool.parse(val) : def;
}
+ private int col_to_int_or_default(string key, int def) {
+ string? val = db.settings.select({db.settings.value}).with(db.settings.key, "=", key)[db.settings.value];
+ int parsed = def;
+ return val != null && int.try_parse(val, out parsed) ? parsed : def;
+ }
+
private bool send_typing_;
public bool send_typing {
get { return send_typing_; }
@@ -68,6 +85,90 @@ public class Settings : Object {
}
}
+ private bool notifications_files_;
+ public bool notifications_files {
+ get { return notifications_files_; }
+ set {
+ db.settings.upsert()
+ .value(db.settings.key, "notifications_files", true)
+ .value(db.settings.value, value.to_string())
+ .perform();
+ notifications_files_ = value;
+ }
+ }
+
+ private bool notifications_calls_;
+ public bool notifications_calls {
+ get { return notifications_calls_; }
+ set {
+ db.settings.upsert()
+ .value(db.settings.key, "notifications_calls", true)
+ .value(db.settings.value, value.to_string())
+ .perform();
+ notifications_calls_ = value;
+ }
+ }
+
+ private bool notifications_subscription_requests_;
+ public bool notifications_subscription_requests {
+ get { return notifications_subscription_requests_; }
+ set {
+ db.settings.upsert()
+ .value(db.settings.key, "notifications_subscription_requests", true)
+ .value(db.settings.value, value.to_string())
+ .perform();
+ notifications_subscription_requests_ = value;
+ }
+ }
+
+ private bool notifications_group_chat_invitations_;
+ public bool notifications_group_chat_invitations {
+ get { return notifications_group_chat_invitations_; }
+ set {
+ db.settings.upsert()
+ .value(db.settings.key, "notifications_group_chat_invitations", true)
+ .value(db.settings.value, value.to_string())
+ .perform();
+ notifications_group_chat_invitations_ = value;
+ }
+ }
+
+ private bool notifications_permission_requests_;
+ public bool notifications_permission_requests {
+ get { return notifications_permission_requests_; }
+ set {
+ db.settings.upsert()
+ .value(db.settings.key, "notifications_permission_requests", true)
+ .value(db.settings.value, value.to_string())
+ .perform();
+ notifications_permission_requests_ = value;
+ }
+ }
+
+ private bool notifications_connection_errors_;
+ public bool notifications_connection_errors {
+ get { return notifications_connection_errors_; }
+ set {
+ db.settings.upsert()
+ .value(db.settings.key, "notifications_connection_errors", true)
+ .value(db.settings.value, value.to_string())
+ .perform();
+ notifications_connection_errors_ = value;
+ }
+ }
+
+ private bool notifications_badge_;
+ public bool notifications_badge {
+ get { return notifications_badge_; }
+ set {
+ db.settings.upsert()
+ .value(db.settings.key, "notifications_badge", true)
+ .value(db.settings.value, value.to_string())
+ .perform();
+ notifications_badge_ = value;
+ }
+ }
+
private bool convert_utf8_smileys_;
public bool convert_utf8_smileys {
get { return convert_utf8_smileys_; }
@@ -93,6 +194,31 @@ public class Settings : Object {
}
}
+ private int avatar_roundness_;
+ public int avatar_roundness {
+ get { return avatar_roundness_; }
+ set {
+ int clamped_value = value.clamp(0, 100);
+ db.settings.upsert()
+ .value(db.settings.key, "avatar_roundness", true)
+ .value(db.settings.value, clamped_value.to_string())
+ .perform();
+ avatar_roundness_ = clamped_value;
+ }
+ }
+
+ private string custom_css_;
+ public string custom_css {
+ get { return custom_css_; }
+ set {
+ db.settings.upsert()
+ .value(db.settings.key, "custom_css", true)
+ .value(db.settings.value, value)
+ .perform();
+ custom_css_ = value;
+ }
+ }
+
public Encryption get_default_encryption(Account account) {
string? setting = db.account_settings.get_value(account.id, "default-encryption");
if (setting != null) {
@@ -110,6 +236,27 @@ public class Settings : Object {
}
+
+ public string get_account_color(Account account) {
+ string? setting = db.account_settings.get_value(account.id, "conversation-list-color");
+ if (setting != null && setting.length > 0) {
+ return setting;
+ }
+
+ uint8[] rgb = Xmpp.Xep.ConsistentColor.string_to_rgb(account.bare_jid.to_string());
+ return "#%02x%02x%02x".printf(rgb[0], rgb[1], rgb[2]).up();
+ }
+
+ public void set_account_color(Account account, string color) {
+ if (color == get_account_color(account)) return;
+
+ db.account_settings.upsert()
+ .value(db.account_settings.key, "conversation-list-color", true)
+ .value(db.account_settings.account_id, account.id, true)
+ .value(db.account_settings.value, color)
+ .perform();
+ account_color_changed(account, color);
+ }
}
}