[geary] Perform migration for GSettings. Bug 766196.
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary] Perform migration for GSettings. Bug 766196.
- Date: Thu, 8 Dec 2016 11:54:15 +0000 (UTC)
commit ec9acc8989b5f47e453de098268672a3d1dc42fe
Author: Niels De Graef <nielsdegraef gmail com>
Date: Thu Dec 8 11:23:35 2016 +0100
Perform migration for GSettings. Bug 766196.
desktop/org.gnome.Geary.gschema.xml | 6 ++++++
src/client/application/geary-config.vala | 13 ++++++++-----
src/client/util/util-migrate.vala | 29 +++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 5 deletions(-)
---
diff --git a/desktop/org.gnome.Geary.gschema.xml b/desktop/org.gnome.Geary.gschema.xml
index d174183..4a70038 100644
--- a/desktop/org.gnome.Geary.gschema.xml
+++ b/desktop/org.gnome.Geary.gschema.xml
@@ -121,6 +121,12 @@
<summary>zoom of conversation viewer</summary>
<description>The zoom to apply on the conservation view.</description>
</key>
+
+ <key name="migrated-config" type="b">
+ <default>false</default>
+ <summary>Whether we migrated the old settings</summary>
+ <description>False to check for the old 'org.yorba.geary'-schema and copy its values</description>
+ </key>
</schema>
</schemalist>
diff --git a/src/client/application/geary-config.vala b/src/client/application/geary-config.vala
index 5a4e208..7900a63 100644
--- a/src/client/application/geary-config.vala
+++ b/src/client/application/geary-config.vala
@@ -24,6 +24,7 @@ public class Configuration {
public const string COMPOSE_AS_HTML_KEY = "compose-as-html";
public const string SPELL_CHECK_VISIBLE_LANGUAGES = "spell-check-visible-languages";
public const string SPELL_CHECK_LANGUAGES = "spell-check-languages";
+ public const string SEARCH_STRATEGY_KEY = "search-strategy";
public const string CONVERSATION_VIEWER_ZOOM_KEY = "conversation-viewer-zoom";
public enum DesktopEnvironment {
@@ -153,6 +154,8 @@ public class Configuration {
// Start GSettings.
settings = new Settings(schema_id);
gnome_interface = new Settings("org.gnome.desktop.interface");
+
+ Migrate.old_app_config(settings);
}
// is_installed: set to true if installed, else false.
@@ -177,7 +180,7 @@ public class Configuration {
}
public Geary.SearchQuery.Strategy get_search_strategy() {
- switch (settings.get_string("search-strategy").down()) {
+ switch (settings.get_string(SEARCH_STRATEGY_KEY).down()) {
case "exact":
return Geary.SearchQuery.Strategy.EXACT;
@@ -196,20 +199,20 @@ public class Configuration {
public void set_search_strategy(Geary.SearchQuery.Strategy strategy) {
switch (strategy) {
case Geary.SearchQuery.Strategy.EXACT:
- settings.set_string("search-strategy", "exact");
+ settings.set_string(SEARCH_STRATEGY_KEY, "exact");
break;
case Geary.SearchQuery.Strategy.AGGRESSIVE:
- settings.set_string("search-strategy", "aggressive");
+ settings.set_string(SEARCH_STRATEGY_KEY, "aggressive");
break;
case Geary.SearchQuery.Strategy.HORIZON:
- settings.set_string("search-strategy", "horizon");
+ settings.set_string(SEARCH_STRATEGY_KEY, "horizon");
break;
case Geary.SearchQuery.Strategy.CONSERVATIVE:
default:
- settings.set_string("search-strategy", "conservative");
+ settings.set_string(SEARCH_STRATEGY_KEY, "conservative");
break;
}
}
diff --git a/src/client/util/util-migrate.vala b/src/client/util/util-migrate.vala
index c4bcde3..89a590c 100644
--- a/src/client/util/util-migrate.vala
+++ b/src/client/util/util-migrate.vala
@@ -108,4 +108,33 @@ namespace Migrate {
is_migrated.create(FileCreateFlags.PRIVATE);
}
}
+
+ private const string OLD_APP_ID = "org.yorba.geary";
+ private const string MIGRATED_CONFIG_KEY = "migrated-config";
+
+ public static void old_app_config(Settings newSettings, string old_app_id = OLD_APP_ID) {
+ SettingsSchemaSource schemaSource = SettingsSchemaSource.get_default();
+ if (GearyApplication.GSETTINGS_DIR != null) {
+ try {
+ schemaSource = new SettingsSchemaSource.from_directory(GearyApplication.GSETTINGS_DIR, null,
false);
+ } catch (Error e) {
+ // If it didn't work, do nothing (i.e. use the default GSettings dir)
+ }
+ }
+ SettingsSchema oldSettingsSchema = schemaSource.lookup(old_app_id, false);
+
+ if (newSettings.get_boolean(MIGRATED_CONFIG_KEY))
+ return;
+
+ if (oldSettingsSchema != null) {
+ Settings oldSettings = new Settings.full(oldSettingsSchema, null, null);
+
+ string[] oldKeys = oldSettings.list_keys();
+ foreach (string key in newSettings.list_keys())
+ if (key in oldKeys)
+ newSettings.set_value(key, oldSettings.get_value(key));
+ }
+
+ newSettings.set_boolean(MIGRATED_CONFIG_KEY, true);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]