diff --git a/data/dev.geopjr.Tuba.gschema.xml b/data/dev.geopjr.Tuba.gschema.xml index 1f992be7b..178c2e8f0 100644 --- a/data/dev.geopjr.Tuba.gschema.xml +++ b/data/dev.geopjr.Tuba.gschema.xml @@ -1,23 +1,30 @@ - + + + + 'public' + + + 'text/plain' + + + [] + + - '' 'system' - - 'public' - false @@ -60,9 +67,6 @@ false - - 'text/plain' - true @@ -79,12 +83,6 @@ true - - -1 - - - -1 - 600 @@ -94,8 +92,5 @@ false - - [] - diff --git a/src/Application.vala b/src/Application.vala index 538d924b6..ef9fe1835 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -267,7 +267,7 @@ namespace Tuba { protected override void shutdown () { #if !DEV_MODE - settings.apply (); + settings.apply_all (); #endif network.flush_cache (); diff --git a/src/Services/Accounts/SecretAccountStore.vala b/src/Services/Accounts/SecretAccountStore.vala index 5c97725ef..76cf64980 100644 --- a/src/Services/Accounts/SecretAccountStore.vala +++ b/src/Services/Accounts/SecretAccountStore.vala @@ -84,7 +84,7 @@ public class Tuba.SecretAccountStore : AccountStore { account.added (); // TODO: remove uuid fallback - if (force_save) save (); + if (force_save) safe_save (); } }); changed (saved); diff --git a/src/Services/Settings.vala b/src/Services/Settings.vala index 5933d8560..b14210639 100644 --- a/src/Services/Settings.vala +++ b/src/Services/Settings.vala @@ -1,8 +1,85 @@ public class Tuba.Settings : GLib.Settings { - public string active_account { get; set; } - public string default_language { get; set; default = "en"; } + class Account : GLib.Settings { + public string default_language { get; set; default = "en"; } + public string default_post_visibility { get; set; default = "public"; } + public string default_content_type { get; set; default = "text/plain"; } + public string[] muted_notification_types { get; set; default = {}; } + + private static string[] keys_to_init = { + "default-post-visibility", + "muted-notification-types", + "default-content-type" + }; + + public Account (string id) { + Object (schema_id: @"$(Build.DOMAIN).Account", path: @"/$(Build.DOMAIN.replace (".", "/"))/accounts/$id/"); + this.delay (); + + foreach (var key in keys_to_init) { + init (key); + } + } + + void init (string key) { + bind (key, this, key, SettingsBindFlags.DEFAULT); + } + } + + private Account active_account_settings { get; set; } + private string _active_account = ""; + public string active_account { + get { + return _active_account; + } + + set { + _active_account = value; + if (active_account_settings != null) active_account_settings.apply (); + active_account_settings = new Account (value); + } + } + + public string default_language { + get { + return active_account_settings.default_language; + } + + set { + active_account_settings.default_language = value; + } + } + + public string default_post_visibility { + get { + return active_account_settings.default_post_visibility; + } + + set { + active_account_settings.default_post_visibility = value; + } + } + + public string default_content_type { + get { + return active_account_settings.default_content_type; + } + + set { + active_account_settings.default_content_type = value; + } + } + + public string[] muted_notification_types { + get { + return active_account_settings.muted_notification_types; + } + + set { + active_account_settings.muted_notification_types = value; + } + } + public ColorScheme color_scheme { get; set; } - public string default_post_visibility { get; set; default = "public"; } public bool work_in_background { get; set; } public int timeline_page_size { get; set; } public bool live_updates { get; set; } @@ -17,18 +94,15 @@ public class Tuba.Settings : GLib.Settings { public bool letterbox_media { get; set; } public bool media_viewer_expand_pictures { get; set; } public bool enlarge_custom_emojis { get; set; } - public string default_content_type { get; set; default = "text/plain"; } public bool use_blurhash { get; set; } public bool group_push_notifications { get; set; } public bool advanced_boost_dialog { get; set; } public bool reply_to_old_post_reminder { get; set; } public bool spellchecker_enabled { get; set; } - public string[] muted_notification_types { get; set; default = {}; } private static string[] keys_to_init = { "active-account", "color-scheme", - "default-post-visibility", "timeline-page-size", "live-updates", "public-live-updates", @@ -42,8 +116,6 @@ public class Tuba.Settings : GLib.Settings { "letterbox-media", "media-viewer-expand-pictures", "enlarge-custom-emojis", - "muted-notification-types", - "default-content-type", "use-blurhash", "group-push-notifications", "advanced-boost-dialog", @@ -74,6 +146,12 @@ public class Tuba.Settings : GLib.Settings { if (key in apply_instantly_keys) apply (); #endif } + + public void apply_all () { + if (active_account_settings != null) active_account_settings.apply (); + + this.apply (); + } } public enum Tuba.ColorScheme {