Perform migration for GSettings. Bug 766196.

This commit is contained in:
Niels De Graef 2016-12-08 11:23:35 +01:00
parent 4b5b2ee6e1
commit ec9acc8989
3 changed files with 43 additions and 5 deletions

View file

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

View file

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

View file

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