aboutsummaryrefslogtreecommitdiff
path: root/libdino
diff options
context:
space:
mode:
Diffstat (limited to 'libdino')
-rw-r--r--libdino/CMakeLists.txt18
-rw-r--r--libdino/data/dino.gschema.xml25
-rw-r--r--libdino/src/application.vala6
-rw-r--r--libdino/src/dbus/networkmanager.vala2
-rw-r--r--libdino/src/entity/conversation.vala6
-rw-r--r--libdino/src/entity/settings.vala58
-rw-r--r--libdino/src/service/database.vala17
-rw-r--r--libdino/src/service/message_processor.vala1
-rw-r--r--libdino/src/settings.vala38
9 files changed, 85 insertions, 86 deletions
diff --git a/libdino/CMakeLists.txt b/libdino/CMakeLists.txt
index aa2ab253..11486293 100644
--- a/libdino/CMakeLists.txt
+++ b/libdino/CMakeLists.txt
@@ -15,10 +15,11 @@ SOURCES
src/dbus/upower.vala
src/entity/account.vala
+ src/entity/encryption.vala
src/entity/conversation.vala
src/entity/jid.vala
src/entity/message.vala
- src/entity/encryption.vala
+ src/entity/settings.vala
src/plugin/interfaces.vala
src/plugin/loader.vala
@@ -41,7 +42,6 @@ SOURCES
src/service/stream_interactor.vala
src/service/util.vala
- src/settings.vala
src/util.vala
CUSTOM_VAPIS
"${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi"
@@ -73,25 +73,11 @@ DEPENDS
${CMAKE_BINARY_DIR}/exports/dino_i18n.h
)
-add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/gschemas.compiled
-COMMAND
- glib-compile-schemas --targetdir=${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/data
-DEPENDS
- ${CMAKE_CURRENT_SOURCE_DIR}/data/dino.gschema.xml
-)
-
-add_custom_target(dino-gsettings-schema-compiled
-DEPENDS
- ${CMAKE_BINARY_DIR}/gschemas.compiled
-)
-
add_definitions(${VALA_CFLAGS} -DDINO_PLUGINS_SYSTEM_PLUGIN_DIR="${PLUGIN_INSTALL_DIR}" -DDINO_PLUGINS_SYSTEM_LIBDIR_NAME="${LIBDIR_NAME}")
add_library(libdino SHARED ${LIBDINO_VALA_C} ${CMAKE_BINARY_DIR}/exports/dino_i18n.h)
-add_dependencies(libdino dino-vapi dino-gsettings-schema-compiled)
target_link_libraries(libdino xmpp-vala qlite ${LIBDINO_PACKAGES} m)
set_target_properties(libdino PROPERTIES PREFIX "" VERSION 0.0 SOVERSION 0)
install(TARGETS libdino ${TARGET_INSTALL})
install(FILES ${CMAKE_BINARY_DIR}/exports/dino.vapi ${CMAKE_BINARY_DIR}/exports/dino.deps DESTINATION ${VAPI_INSTALL_DIR})
install(FILES ${CMAKE_BINARY_DIR}/exports/dino.h ${CMAKE_BINARY_DIR}/exports/dino_i18n.h DESTINATION ${INCLUDE_INSTALL_DIR})
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/dino.gschema.xml DESTINATION ${SHARE_INSTALL_PREFIX}/glib-2.0/schemas/) \ No newline at end of file
diff --git a/libdino/data/dino.gschema.xml b/libdino/data/dino.gschema.xml
deleted file mode 100644
index 7d1e82fd..00000000
--- a/libdino/data/dino.gschema.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<schemalist>
- <schema id="org.dino-im" path="/org/dino-im/" gettext-domain="dino">
-
- <key name="send-typing" type="b">
- <default>true</default>
- <summary>Whether to send typing notifications</summary>
- </key>
-
- <key name="send-marker" type="b">
- <default>true</default>
- <summary>Whether to confirm that a message was received or read</summary>
- </key>
-
- <key name="notifications" type="b">
- <default>true</default>
- <summary>Whether to get notifications</summary>
- </key>
-
- <key name="convert-utf8-smileys" type="b">
- <default>true</default>
- <summary>Whether to convert common ascii smileys into unicode</summary>
- </key>
-
- </schema>
-</schemalist>
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));
- }
-}
-
-}