diff options
Diffstat (limited to 'libdino/src')
-rw-r--r-- | libdino/src/application.vala | 6 | ||||
-rw-r--r-- | libdino/src/dbus/networkmanager.vala | 2 | ||||
-rw-r--r-- | libdino/src/entity/conversation.vala | 6 | ||||
-rw-r--r-- | libdino/src/entity/settings.vala | 58 | ||||
-rw-r--r-- | libdino/src/service/database.vala | 17 | ||||
-rw-r--r-- | libdino/src/service/message_processor.vala | 1 | ||||
-rw-r--r-- | libdino/src/settings.vala | 38 |
7 files changed, 83 insertions, 45 deletions
diff --git a/libdino/src/application.vala b/libdino/src/application.vala index 72dbfeae..4b5f3b64 100644 --- a/libdino/src/application.vala +++ b/libdino/src/application.vala @@ -3,6 +3,7 @@ using Dino.Entities; public interface Dino.Application : GLib.Application { public abstract Database db { get; set; } + public abstract Dino.Entities.Settings settings { get; set; } public abstract StreamInteractor stream_interaction { get; set; } public abstract Plugins.Registry plugin_registry { get; set; } public abstract SearchPathGenerator? search_path_generator { get; set; } @@ -20,6 +21,7 @@ public interface Dino.Application : GLib.Application { } this.db = new Database(Path.build_filename(get_storage_dir(), "dino.db")); + this.settings = new Dino.Entities.Settings.from_db(db); this.stream_interaction = new StreamInteractor(db); AvatarManager.start(stream_interaction, db); @@ -43,6 +45,10 @@ public interface Dino.Application : GLib.Application { return Path.build_filename(Environment.get_user_data_dir(), "dino"); } + public static unowned Application get_default() { + return (Dino.Application) GLib.Application.get_default(); + } + protected void add_connection(Account account) { stream_interaction.connect(account); } diff --git a/libdino/src/dbus/networkmanager.vala b/libdino/src/dbus/networkmanager.vala index fb8ac0cc..be9fb42b 100644 --- a/libdino/src/dbus/networkmanager.vala +++ b/libdino/src/dbus/networkmanager.vala @@ -19,4 +19,4 @@ public static NetworkManager? get_network_manager() { return nm; } -}
\ No newline at end of file +} 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; + } + } +} + +} diff --git a/libdino/src/service/database.vala b/libdino/src/service/database.vala index 5a7eb46d..91a62cce 100644 --- a/libdino/src/service/database.vala +++ b/libdino/src/service/database.vala @@ -6,7 +6,7 @@ using Dino.Entities; namespace Dino { public class Database : Qlite.Database { - private const int VERSION = 4; + private const int VERSION = 5; public class AccountTable : Table { public Column<int> id = new Column.Integer("id") { primary_key = true, auto_increment = true }; @@ -133,6 +133,17 @@ public class Database : Qlite.Database { } } + public class SettingsTable : Table { + public Column<int> id = new Column.Integer("id") { primary_key = true, auto_increment = true }; + public Column<string> key = new Column.Text("key") { unique = true, not_null = true }; + public Column<string> value = new Column.Text("value"); + + internal SettingsTable(Database db) { + base(db, "settings"); + init({id, key, value}); + } + } + public AccountTable account { get; private set; } public JidTable jid { get; private set; } public MessageTable message { get; private set; } @@ -141,6 +152,7 @@ public class Database : Qlite.Database { public AvatarTable avatar { get; private set; } public EntityFeatureTable entity_feature { get; private set; } public RosterTable roster { get; private set; } + public SettingsTable settings { get; private set; } public Map<int, string> jid_table_cache = new HashMap<int, string>(); public Map<string, int> jid_table_reverse = new HashMap<string, int>(); @@ -156,7 +168,8 @@ public class Database : Qlite.Database { avatar = new AvatarTable(this); entity_feature = new EntityFeatureTable(this); roster = new RosterTable(this); - init({ account, jid, message, real_jid, conversation, avatar, entity_feature, roster }); + settings = new SettingsTable(this); + init({ account, jid, message, real_jid, conversation, avatar, entity_feature, roster, settings }); exec("PRAGMA synchronous=0"); } diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index d1490aa0..cc99bcc3 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -107,7 +107,6 @@ public class MessageProcessor : StreamInteractionModule, Object { bool is_mam_message = Xep.MessageArchiveManagement.MessageFlag.get_flag(stanza) != null; bool is_recent = new_message.local_time.compare(new DateTime.now_utc().add_hours(-24)) > 0; if (!is_mam_message || is_recent) { - print(new_message.local_time.to_string() + "\n"); if (new_message.direction == Entities.Message.DIRECTION_SENT) { message_sent(new_message, conversation); } else { diff --git a/libdino/src/settings.vala b/libdino/src/settings.vala deleted file mode 100644 index aac83917..00000000 --- a/libdino/src/settings.vala +++ /dev/null @@ -1,38 +0,0 @@ -namespace Dino { - -public class Settings { - - private GLib.Settings gsettings; - - public bool send_typing { - get { return gsettings.get_boolean("send-typing"); } - set { gsettings.set_boolean("send-typing", value); } - } - - public bool send_marker { - get { return gsettings.get_boolean("send-marker"); } - set { gsettings.set_boolean("send-marker", value); } - } - - public bool notifications { - get { return gsettings.get_boolean("notifications"); } - set { gsettings.set_boolean("notifications", value); } - } - - public bool convert_utf8_smileys { - get { return gsettings.get_boolean("convert-utf8-smileys"); } - set { gsettings.set_boolean("convert-utf8-smileys", value); } - } - - public Settings(GLib.Settings gsettings) { - this.gsettings = gsettings; - } - - public static Settings instance() { - SettingsSchemaSource sss = SettingsSchemaSource.get_default(); - SettingsSchema? schema = sss.lookup("org.dino-im", true); - return new Settings(new GLib.Settings.full(schema, null, null)); - } -} - -} |