Move settings from GSettings to own db

This commit is contained in:
fiaxh 2017-08-21 17:16:25 +02:00
parent a8aceb1e39
commit 4a4b5956c9
13 changed files with 90 additions and 90 deletions

View File

@ -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/)

View File

@ -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>

View File

@ -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);
}

View File

@ -19,4 +19,4 @@ public static NetworkManager? get_network_manager() {
return nm;
}
}
}

View File

@ -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) {

View File

@ -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;
}
}
}
}

View File

@ -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");
}

View File

@ -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 {

View File

@ -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));
}
}
}

View File

@ -8,6 +8,7 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
private UnifiedWindow window;
public Database db { get; set; }
public Dino.Entities.Settings settings { get; set; }
public StreamInteractor stream_interaction { get; set; }
public Plugins.Registry plugin_registry { get; set; default = new Plugins.Registry(); }
public SearchPathGenerator? search_path_generator { get; set; }

View File

@ -42,7 +42,7 @@ class SmileyConverter {
}
private void check_convert() {
if (Dino.Settings.instance().convert_utf8_smileys) {
if (Dino.Application.get_default().settings.convert_utf8_smileys) {
foreach (string smiley in smiley_translations.keys) {
if (text_input.buffer.text.has_suffix(smiley)) {
if (text_input.buffer.text.length == smiley.length ||
@ -55,4 +55,4 @@ class SmileyConverter {
}
}
}
}

View File

@ -100,4 +100,4 @@ public class SettingsProvider : Plugins.ContactDetailsProvider, Object {
}
}
}
}

View File

@ -10,7 +10,7 @@ class SettingsDialog : Dialog {
[GtkChild] private CheckButton notification_checkbutton;
[GtkChild] private CheckButton emoji_checkbutton;
Dino.Settings settings = Dino.Settings.instance();
Dino.Entities.Settings settings = Dino.Application.get_default().settings;
public SettingsDialog() {
Object(use_header_bar : 1);