From de4d1e98599544e53e3a6adaaf421a89bb6decb3 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Mon, 11 Dec 2017 21:56:20 +0100 Subject: [PATCH] Add infrastructure to handle preference schema migrations and use it to replace one preference The preference schema migration collects all schema mutations that can occur when upgrading to a newer gnucash version. The old gconf to gsettings conversion is integrated in this system as well. Newer schema mutations will happen based on version number upgrades though. The preference that got replaced is "use-theme-colors". Based on discussion in bug 746163 (https://bugzilla.gnome.org/show_bug.cgi?id=746163) and gnucash-docs PR#105 (https://github.com/Gnucash/gnucash-docs/pull/105) this has been replaced with "use-gnucash-color-theme" with inverted meaning. The old option is kept around for one or two major release cycles to allow seamless conversion. --- .../gnome-utils/gnc-tree-model-split-reg.c | 4 +-- .../gnome-utils/gnc-tree-model-split-reg.h | 2 +- gnucash/gnome-utils/gnc-tree-view-split-reg.c | 4 +-- .../gtkbuilder/dialog-preferences.glade | 8 ++--- .../gschemas/org.gnucash.gschema.xml.in.in | 14 ++++++-- gnucash/gnucash-bin.c | 5 ++- .../register/register-gnome/gnucash-sheet.c | 10 +++--- .../register/register-gnome/gnucash-sheetP.h | 2 +- libgnucash/app-utils/gnc-gsettings.c | 35 ++++++++++++++----- libgnucash/app-utils/gnc-gsettings.h | 12 ++++--- libgnucash/core-utils/gnc-prefs.h | 4 ++- 11 files changed, 67 insertions(+), 33 deletions(-) diff --git a/gnucash/gnome-utils/gnc-tree-model-split-reg.c b/gnucash/gnome-utils/gnc-tree-model-split-reg.c index 977510ddcc..6bfed4738a 100644 --- a/gnucash/gnome-utils/gnc-tree-model-split-reg.c +++ b/gnucash/gnome-utils/gnc-tree-model-split-reg.c @@ -486,7 +486,7 @@ gnc_tree_model_split_reg_new (SplitRegisterType2 reg_type, SplitRegisterStyle2 s /* Setup some config entries */ model->use_accounting_labels = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNTING_LABELS); - model->use_theme_colors = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL_REGISTER, GNC_PREF_USE_THEME_COLORS); + model->use_gnc_color_theme = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL_REGISTER, GNC_PREF_USE_GNUCASH_COLOR_THEME); model->alt_colors_by_txn = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL_REGISTER, GNC_PREF_ALT_COLOR_BY_TRANS); model->read_only = FALSE; @@ -1450,7 +1450,7 @@ gnc_tree_model_split_reg_get_row_color (GncTreeModelSplitReg *model, gboolean is gchar *cell_color = NULL; - if (!model->use_theme_colors) + if (model->use_gnc_color_theme) { if (model->use_double_line) { diff --git a/gnucash/gnome-utils/gnc-tree-model-split-reg.h b/gnucash/gnome-utils/gnc-tree-model-split-reg.h index 6259ca39d4..86f0bbc1e6 100644 --- a/gnucash/gnome-utils/gnc-tree-model-split-reg.h +++ b/gnucash/gnome-utils/gnc-tree-model-split-reg.h @@ -152,7 +152,7 @@ typedef struct gboolean use_accounting_labels; /**< whether to use accounting Labels */ gboolean separator_changed; /**< whether the separator has changed */ gboolean alt_colors_by_txn; /**< whether to use alternative colors by transaction */ - gboolean use_theme_colors; /**< whether to use theme colors */ + gboolean use_gnc_color_theme; /**< whether to use the gnucash built-in color theme */ gboolean read_only; /**< register is read only */ diff --git a/gnucash/gnome-utils/gnc-tree-view-split-reg.c b/gnucash/gnome-utils/gnc-tree-view-split-reg.c index d6b5268424..9a9b760bef 100644 --- a/gnucash/gnome-utils/gnc-tree-view-split-reg.c +++ b/gnucash/gnome-utils/gnc-tree-view-split-reg.c @@ -568,8 +568,8 @@ gnc_tree_view_split_reg_refresh_from_prefs (GncTreeViewSplitReg *view) model = gnc_tree_view_split_reg_get_model_from_view (view); - model->use_theme_colors = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL_REGISTER, - GNC_PREF_USE_THEME_COLORS); + model->use_gnc_color_theme = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL_REGISTER, + GNC_PREF_USE_GNUCASH_COLOR_THEME); model->use_accounting_labels = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNTING_LABELS); diff --git a/gnucash/gnome-utils/gtkbuilder/dialog-preferences.glade b/gnucash/gnome-utils/gtkbuilder/dialog-preferences.glade index 3b444030ad..4aff574e15 100644 --- a/gnucash/gnome-utils/gtkbuilder/dialog-preferences.glade +++ b/gnucash/gnome-utils/gtkbuilder/dialog-preferences.glade @@ -2245,14 +2245,14 @@ many months before the current month: - - Don't _use GnuCash built-in colors + + _Use GnuCash built-in color theme True True False True - GnuCash uses a yellow/green theme by default for register windows. Check this if you want to use the system color theme instead. - GnuCash uses a yellow/green theme by default for register windows. Check this if you want to use the system color theme instead. + GnuCash uses a yellow/green theme by default for register windows. Uncheck this if you want to use the system color theme instead. + GnuCash uses a yellow/green theme by default for register windows. Uncheck this if you want to use the system color theme instead. start 12 True diff --git a/gnucash/gnome/gschemas/org.gnucash.gschema.xml.in.in b/gnucash/gnome/gschemas/org.gnucash.gschema.xml.in.in index 88d222eeed..1e079ab3a4 100644 --- a/gnucash/gnome/gschemas/org.gnucash.gschema.xml.in.in +++ b/gnucash/gnome/gschemas/org.gnucash.gschema.xml.in.in @@ -5,6 +5,11 @@ + + 0 + The version of these settings + This is used internally to determine whether some preferences may need conversion when switching to a newer version of GnuCash. + true Save window sizes and locations @@ -225,10 +230,15 @@ + + true + Color the register using a gnucash specific color theme + When enabled the register will use a GnuCash specific color theme (green/yellow). Otherwise it will use the system color theme. Regardless of this setting the user can always override the color theme via a gnucash specific css file to be stored in the gnucash used config directory. More information can be found in the gnucash FAQ. + false - Color the register as specified by the system theme - If active, the register will be colored as specified by the system theme. This can be overridden to provide custom colors by editing the gtkrc file in the users home directory. Otherwise the standard register colors will be used that GnuCash has always used. + Superseded by "use-gnucash-color-theme" + This option is temporarily kept around for backwards compatibility. It will be removed in a future version. false diff --git a/gnucash/gnucash-bin.c b/gnucash/gnucash-bin.c index 0152a3a44e..c0446bd062 100644 --- a/gnucash/gnucash-bin.c +++ b/gnucash/gnucash-bin.c @@ -613,9 +613,8 @@ inner_main (void *closure, int argc, char **argv) main_mod = scm_c_resolve_module("gnucash main"); scm_set_current_module(main_mod); - /* GnuCash switched to gsettings to store its preferences in version 2.5.6 - * Migrate the user's preferences from gconf if needed */ - gnc_gsettings_migrate_from_gconf(); + /* Check whether the settings need a version update */ + gnc_gsettings_version_upgrade (); load_gnucash_modules(); diff --git a/gnucash/register/register-gnome/gnucash-sheet.c b/gnucash/register/register-gnome/gnucash-sheet.c index 311ab1b2a6..64d2b42435 100644 --- a/gnucash/register/register-gnome/gnucash-sheet.c +++ b/gnucash/register/register-gnome/gnucash-sheet.c @@ -1540,8 +1540,8 @@ gnucash_sheet_refresh_from_prefs (GnucashSheet *sheet) g_return_if_fail(sheet != NULL); g_return_if_fail(GNUCASH_IS_SHEET(sheet)); - sheet->use_theme_colors = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL_REGISTER, - GNC_PREF_USE_THEME_COLORS); + sheet->use_gnc_color_theme = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL_REGISTER, + GNC_PREF_USE_GNUCASH_COLOR_THEME); sheet->use_horizontal_lines = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL_REGISTER, GNC_PREF_DRAW_HOR_LINES); sheet->use_vertical_lines = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL_REGISTER, @@ -2472,13 +2472,13 @@ gnucash_get_style_classes (GnucashSheet *sheet, GtkStyleContext *stylectxt, break; } - if (sheet->use_theme_colors) + if (sheet->use_gnc_color_theme) + full_class = g_strconcat ("register-", style_class, NULL); + else { gtk_style_context_add_class (stylectxt, GTK_STYLE_CLASS_VIEW); full_class = g_strconcat (style_class, "-color", NULL); } - else - full_class = g_strconcat ("register-", style_class, NULL); gtk_style_context_add_class (stylectxt, full_class); diff --git a/gnucash/register/register-gnome/gnucash-sheetP.h b/gnucash/register/register-gnome/gnucash-sheetP.h index 1b9ffe9491..bd2ec3c2cb 100644 --- a/gnucash/register/register-gnome/gnucash-sheetP.h +++ b/gnucash/register/register-gnome/gnucash-sheetP.h @@ -63,7 +63,7 @@ struct _GnucashSheet GtkWidget *item_editor; GtkWidget *entry; - gboolean use_theme_colors; + gboolean use_gnc_color_theme; gboolean use_horizontal_lines; gboolean use_vertical_lines; diff --git a/libgnucash/app-utils/gnc-gsettings.c b/libgnucash/app-utils/gnc-gsettings.c index f8d6adc1b3..92a6edd8f3 100644 --- a/libgnucash/app-utils/gnc-gsettings.c +++ b/libgnucash/app-utils/gnc-gsettings.c @@ -694,7 +694,7 @@ xsltprocExternalEntityLoader(const char *URL, const char *ID, * from running again. So in normal circumstances the migration will * be executed only once. */ -void gnc_gsettings_migrate_from_gconf (void) +static void gnc_gsettings_migrate_from_gconf (void) { gchar *pkgdatadir, *stylesheet, *input, *output, *command; gchar *gconf_root, *gconf_apps, *gconf_gnucash; @@ -707,13 +707,6 @@ void gnc_gsettings_migrate_from_gconf (void) ENTER (); - /* Only attempt to migrate if no successful migration has been done before */ - if (gnc_gsettings_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_MIGRATE_PREFS_DONE)) - { - LEAVE ("Preferences migration ran successfully before. Skipping."); - return; - } - base_dir = g_strdup (g_get_home_dir ()); for (iter = base_dir; *iter != 0; iter++) { @@ -831,3 +824,29 @@ void gnc_gsettings_migrate_from_gconf (void) g_free (base_dir); } + + +void gnc_gsettings_version_upgrade (void) +{ + /* Use versioning to ensure this routine will only sync once for each + * superseded setting */ + int old_maj_min = gnc_gsettings_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION); + int cur_maj_min = GNUCASH_MAJOR_VERSION * 100 + GNUCASH_MINOR_VERSION; + + /* Migrate preferences from gconf to gsettings */ + if (!gnc_gsettings_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_MIGRATE_PREFS_DONE)) + gnc_gsettings_migrate_from_gconf (); + + /* Convert settings to 2.8 compatibility level */ + if (old_maj_min < 208) + { + /* 'use-theme-colors' has been replaced with 'use-gnucash-color-theme' + * which inverts the meaning of the setting */ + gboolean old_color_theme = gnc_gsettings_get_bool (GNC_PREFS_GROUP_GENERAL_REGISTER, GNC_PREF_USE_THEME_COLORS); + gnc_gsettings_set_bool (GNC_PREFS_GROUP_GENERAL_REGISTER, GNC_PREF_USE_GNUCASH_COLOR_THEME, !old_color_theme); + } + + /* Only write current version if it's more recent than what was set */ + if (cur_maj_min > old_maj_min) + gnc_gsettings_set_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_VERSION, cur_maj_min); +} diff --git a/libgnucash/app-utils/gnc-gsettings.h b/libgnucash/app-utils/gnc-gsettings.h index b66ae1dd3c..44dcb9910f 100644 --- a/libgnucash/app-utils/gnc-gsettings.h +++ b/libgnucash/app-utils/gnc-gsettings.h @@ -595,10 +595,14 @@ void gnc_gsettings_reset_schema (const gchar *schema); */ void gnc_gsettings_load_backend (void); - -/* Attempt to migrate preferences from gconf files - to gsettings if not already done so */ -void gnc_gsettings_migrate_from_gconf (void); +/** Check whether we need to adjust the user settings + * to a newer version. + * + * New version of GnuCash may come with changes in the + * settings schema. This function will take the necessary + * steps to convert old settings to new (when possible). + */ +void gnc_gsettings_version_upgrade (void); #endif /* GNC_GSETTINGS_H */ /** @} */ diff --git a/libgnucash/core-utils/gnc-prefs.h b/libgnucash/core-utils/gnc-prefs.h index 39f212cadf..41c241d461 100644 --- a/libgnucash/core-utils/gnc-prefs.h +++ b/libgnucash/core-utils/gnc-prefs.h @@ -57,6 +57,7 @@ #define GNC_PREFS_GROUP_ACCT_SUMMARY "window.pages.account-tree.summary" /* Preference names used across multiple modules */ +#define GNC_PREF_VERSION "prefs-version" #define GNC_PREF_SAVE_GEOMETRY "save-window-geometry" #define GNC_PREF_LAST_PATH "last-path" #define GNC_PREF_USE_NEW "use-new-window" @@ -74,7 +75,8 @@ #define GNC_PREF_DRAW_HOR_LINES "draw-horizontal-lines" #define GNC_PREF_DRAW_VERT_LINES "draw-vertical-lines" #define GNC_PREF_ALT_COLOR_BY_TRANS "alternate-color-by-transaction" -#define GNC_PREF_USE_THEME_COLORS "use-theme-colors" +#define GNC_PREF_USE_THEME_COLORS "use-theme-colors" // Obsolete, to remove in a future major version (> 2.8) +#define GNC_PREF_USE_GNUCASH_COLOR_THEME "use-gnucash-color-theme" #define GNC_PREF_TAB_TRANS_MEMORISED "tab-to-transfer-on-memorised" #define GNC_PREF_FUTURE_AFTER_BLANK "future-after-blank-transaction" /* Date preferences */