aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/entity
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-08-21 17:16:25 +0200
committerfiaxh <git@mx.ax.lt>2017-08-22 16:22:56 +0200
commit4a4b5956c9b12bbfb583da1794ef0184e760ac33 (patch)
tree05a8581e46cc839e3064e5978e0708ad37a056db /libdino/src/entity
parenta8aceb1e395e3d0d5a570f6570a1613e2f990d87 (diff)
downloaddino-4a4b5956c9b12bbfb583da1794ef0184e760ac33.tar.gz
dino-4a4b5956c9b12bbfb583da1794ef0184e760ac33.zip
Move settings from GSettings to own db
Diffstat (limited to 'libdino/src/entity')
-rw-r--r--libdino/src/entity/conversation.vala6
-rw-r--r--libdino/src/entity/settings.vala58
2 files changed, 61 insertions, 3 deletions
diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala
index fa78c619..d0a3e9d7 100644
--- a/libdino/src/entity/conversation.vala
+++ b/libdino/src/entity/conversation.vala
@@ -93,7 +93,7 @@ public class Conversation : Object {
public NotifySetting get_notification_setting(StreamInteractor stream_interactor) {
Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(account);
if (notify_setting != NotifySetting.DEFAULT) return notify_setting;
- if (!Settings.instance().notifications) return NotifySetting.OFF;
+ if (!Application.get_default().settings.notifications) return NotifySetting.OFF;
if (type_ == Type.GROUPCHAT) {
bool members_only = stream.get_flag(Xmpp.Xep.Muc.Flag.IDENTITY).has_room_feature(counterpart.bare_jid.to_string(), Xmpp.Xep.Muc.Feature.MEMBERS_ONLY);
return members_only ? NotifySetting.ON : NotifySetting.HIGHLIGHT;
@@ -104,12 +104,12 @@ public class Conversation : Object {
public Setting get_send_typing_setting() {
if (send_typing != Setting.DEFAULT) return send_typing;
- return Settings.instance().send_typing ? Setting.ON : Setting.OFF;
+ return Application.get_default().settings.send_typing ? Setting.ON : Setting.OFF;
}
public Setting get_send_marker_setting() {
if (send_marker != Setting.DEFAULT) return send_marker;
- return Settings.instance().send_marker ? Setting.ON : Setting.OFF;
+ return Application.get_default().settings.send_marker ? Setting.ON : Setting.OFF;
}
public bool equals(Conversation? conversation) {
diff --git a/libdino/src/entity/settings.vala b/libdino/src/entity/settings.vala
new file mode 100644
index 00000000..bf1ebed4
--- /dev/null
+++ b/libdino/src/entity/settings.vala
@@ -0,0 +1,58 @@
+namespace Dino.Entities {
+
+public class Settings : Object {
+
+ private Database db;
+
+ public Settings.from_db(Database db) {
+ this.db = db;
+
+ send_typing_ = col_to_bool_or_default("send_typing", true);
+ send_marker_ = col_to_bool_or_default("send_marker", true);
+ notifications_ = col_to_bool_or_default("notifications", true);
+ convert_utf8_smileys_ = col_to_bool_or_default("convert_utf8_smileys", true);
+ }
+
+ private bool col_to_bool_or_default(string key, bool def) {
+ string? val = db.settings.select({db.settings.value}).with(db.settings.key, "=", key)[db.settings.value];
+ return val != null ? bool.parse(val) : def;
+ }
+
+ private bool send_typing_;
+ public bool send_typing {
+ get { return send_typing_; }
+ set {
+ db.settings.insert().or("REPLACE").value(db.settings.key, "send_typing").value(db.settings.value, value.to_string()).perform();
+ send_typing_ = value;
+ }
+ }
+
+ private bool send_marker_;
+ public bool send_marker {
+ get { return send_marker_; }
+ set {
+ db.settings.insert().or("REPLACE").value(db.settings.key, "send_marker").value(db.settings.value, value.to_string()).perform();
+ send_marker_ = value;
+ }
+ }
+
+ private bool notifications_;
+ public bool notifications {
+ get { return notifications_; }
+ set {
+ db.settings.insert().or("REPLACE").value(db.settings.key, "notifications").value(db.settings.value, value.to_string()).perform();
+ notifications_ = value;
+ }
+ }
+
+ private bool convert_utf8_smileys_;
+ public bool convert_utf8_smileys {
+ get { return convert_utf8_smileys_; }
+ set {
+ db.settings.insert().or("REPLACE").value(db.settings.key, "convert_utf8_smileys").value(db.settings.value, value.to_string()).perform();
+ convert_utf8_smileys_ = value;
+ }
+ }
+}
+
+}