diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2023-06-28 21:35:52 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2023-06-28 21:35:52 +0200 |
commit | b86540b743f1a87a163ffb811c8fe22a01fefa38 (patch) | |
tree | b47cb3bb83c2377234226fb3987ab3320a987dd9 /src/config/GSettingsEngine.vala | |
parent | ac6e0b731b9f0b2efd392e3309a5c07e2a66adad (diff) | |
parent | e905d8e16eec152d19797937f13ba3cf4b8f8aca (diff) |
Merge branch 'release/debian/0.32.1-1'debian/0.32.1-1
Diffstat (limited to 'src/config/GSettingsEngine.vala')
-rw-r--r-- | src/config/GSettingsEngine.vala | 88 |
1 files changed, 81 insertions, 7 deletions
diff --git a/src/config/GSettingsEngine.vala b/src/config/GSettingsEngine.vala index d35eb93..d4d95c6 100644 --- a/src/config/GSettingsEngine.vala +++ b/src/config/GSettingsEngine.vala @@ -5,7 +5,7 @@ */ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object { - private const string ROOT_SCHEMA_NAME = "org.yorba.shotwell"; + private const string ROOT_SCHEMA_NAME = "org.gnome.shotwell"; private const string PREFS_SCHEMA_NAME = ROOT_SCHEMA_NAME + ".preferences"; private const string UI_PREFS_SCHEMA_NAME = PREFS_SCHEMA_NAME + ".ui"; private const string SLIDESHOW_PREFS_SCHEMA_NAME = PREFS_SCHEMA_NAME + ".slideshow"; @@ -25,8 +25,11 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object { private string[] schema_names; private string[] key_names; private Gee.HashMap<string, Settings> settings_cache = new Gee.HashMap<string, Settings>(); - - public GSettingsConfigurationEngine() { + + private string profile = ""; + + public GSettingsConfigurationEngine(string? profile) { + this.profile = profile == null ? "" : profile; schema_names = new string[ConfigurableProperty.NUM_PROPERTIES]; schema_names[ConfigurableProperty.AUTO_IMPORT_FROM_LIBRARY] = FILES_PREFS_SCHEMA_NAME; @@ -47,6 +50,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object { schema_names[ConfigurableProperty.DISPLAY_EXTENDED_PROPERTIES] = UI_PREFS_SCHEMA_NAME; schema_names[ConfigurableProperty.DISPLAY_SIDEBAR] = UI_PREFS_SCHEMA_NAME; schema_names[ConfigurableProperty.DISPLAY_TOOLBAR] = UI_PREFS_SCHEMA_NAME; + schema_names[ConfigurableProperty.DISPLAY_MAP_WIDGET] = UI_PREFS_SCHEMA_NAME; schema_names[ConfigurableProperty.DISPLAY_SEARCH_BAR] = UI_PREFS_SCHEMA_NAME; schema_names[ConfigurableProperty.DISPLAY_PHOTO_RATINGS] = UI_PREFS_SCHEMA_NAME; schema_names[ConfigurableProperty.DISPLAY_PHOTO_TAGS] = UI_PREFS_SCHEMA_NAME; @@ -120,6 +124,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object { key_names[ConfigurableProperty.DISPLAY_EXTENDED_PROPERTIES] = "display-extended-properties"; key_names[ConfigurableProperty.DISPLAY_SIDEBAR] = "display-sidebar"; key_names[ConfigurableProperty.DISPLAY_TOOLBAR] = "display-toolbar"; + key_names[ConfigurableProperty.DISPLAY_MAP_WIDGET] = "display-map-widget"; key_names[ConfigurableProperty.DISPLAY_SEARCH_BAR] = "display-search-bar"; key_names[ConfigurableProperty.DISPLAY_PHOTO_RATINGS] = "display-photo-ratings"; key_names[ConfigurableProperty.DISPLAY_PHOTO_TAGS] = "display-photo-tags"; @@ -176,7 +181,14 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object { private Settings get_settings(string schema) { if (!this.settings_cache.has_key(schema)) { - this.settings_cache[schema] = new Settings(schema); + if (schema.has_prefix (ROOT_SCHEMA_NAME)) { + var path = schema.replace(ROOT_SCHEMA_NAME, ""); + path = "/org/gnome/shotwell/%s%s/".printf(profile == "" ? "" : "profiles/" + profile, path.replace(".", "/")); + path = path.replace("//", "/"); + this.settings_cache[schema] = new Settings.with_path (schema, path); + } else { + this.settings_cache[schema] = new Settings(schema); + } } return this.settings_cache[schema]; @@ -229,7 +241,9 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object { Settings schema_object = get_settings(schema); - return schema_object.get_int(key); + var v = schema_object.get_int(key); + + return v; } private void set_gs_int(string schema, string key, int value) throws ConfigurationError { @@ -292,7 +306,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object { if (cleaned_id == null) cleaned_id = "default"; - cleaned_id = cleaned_id.replace("org.yorba.shotwell.", ""); + cleaned_id = cleaned_id.replace("org.gnome.shotwell.", ""); cleaned_id = cleaned_id.replace(".", "-"); return cleaned_id; @@ -304,7 +318,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object { cleaned_id = "default"; cleaned_id = cleaned_id.replace(".", "-"); - return "org.yorba.shotwell.%s.%s".printf(domain, cleaned_id); + return "org.gnome.shotwell.%s.%s".printf(domain, cleaned_id); } private static string make_gsettings_key(string gconf_key) { @@ -513,4 +527,64 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object { } } + /*! @brief Migrates settings data over from old-style /org/yorba/ paths to /org/gnome/ ones. + * Should only be called ONCE, during DB upgrading; otherwise, stale data may be copied + * over newer data by accident. + */ + public static void run_gsettings_migrator_v2() { + var source = SettingsSchemaSource.get_default(); + var schema = source.lookup("org.yorba.shotwell", true); + var settings = new Settings.full(schema, null, null); + + copy_schema(settings); + + Settings.sync(); + } + + static void copy_schema(Settings settings) { + SettingsSchema schema; + ((Object)settings).get("settings-schema", out schema, null); + var id = schema.get_id(); + var path = schema.get_path(); + + var new_id = id.replace("org.yorba.shotwell", "org.gnome.shotwell"); + var new_path = path.replace("/org/yorba/shotwell", "/org/gnome/shotwell"); + + var new_schema = SettingsSchemaSource.get_default().lookup(new_id, true); + + // If we cannot find this schema, we cannot migrate the keys anyway, so skip it + if (new_schema != null) { + var new_settings = new Settings.with_path(new_id, new_path); + new_settings.delay(); + + foreach (var k in schema.list_keys()) { + var key = schema.get_key(k); + var default_value = key.get_default_value(); + var val = settings.get_value(k); + if (val.equal(default_value)) { + debug("%s is default value, skipping", k); + continue; + } + + if (!new_schema.has_key(k)) { + debug("Cannot migrate %s as it does not exist", k); + continue; + } + + debug("Will migrate %s %s @ %s -> %s:%s %s", k, id, path, new_id, new_path, val.print(true)); + if (!new_settings.set_value(k, val)) { + debug(" Failed..."); + } + } + new_settings.apply(); + } + else { + debug("%s does not exist, skipping\n", new_id); + } + + foreach (var c in schema.list_children()) { + var child = settings.get_child(c); + copy_schema(child); + } + } } |