talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 3b5b4f75ddf190346e4e8a1ee4521f32cafd0a37
parent 74b625c53e38ed53a585fe43df23f12d50d447a6
Author: Andrej Kacian <ticho@claws-mail.org>
Date:   Thu, 14 Jul 2016 11:55:54 +0200

Added config versioning.

This allows us to change meaning of existing preferences,
without losing or mangling user data. Controlled by a common
pref "config_version", which is checked on startup after
reading all configuration. If this version is lower than
what is defined in CLAWS_CONFIG_VERSION, an upgrade is done
incrementally, from one version to the next and to the next,
so that all affected preferences are adjusted.

Diffstat:
Msrc/Makefile.am | 2++
Msrc/main.c | 3+++
Msrc/prefs_common.c | 3+++
Msrc/prefs_common.h | 4++++
Asrc/prefs_migration.c | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/prefs_migration.h | 25+++++++++++++++++++++++++
6 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am @@ -196,6 +196,7 @@ claws_mail_SOURCES = \ prefs_logging.c \ prefs_matcher.c \ prefs_message.c \ + prefs_migration.c \ prefs_msg_colors.c \ prefs_other.c \ prefs_quote.c \ @@ -314,6 +315,7 @@ claws_mailinclude_HEADERS = \ prefs_logging.h \ prefs_matcher.h \ prefs_message.h \ + prefs_migration.h \ prefs_msg_colors.h \ prefs_other.h \ prefs_quote.h \ diff --git a/src/main.c b/src/main.c @@ -79,6 +79,7 @@ #include "prefs_fonts.h" #include "prefs_image_viewer.h" #include "prefs_message.h" +#include "prefs_migration.h" #include "prefs_receive.h" #include "prefs_msg_colors.h" #include "prefs_quote.h" @@ -1457,6 +1458,8 @@ int main(int argc, char *argv[]) g_slist_free(plug_list); } + prefs_update_config_version(); + if (never_ran) { prefs_common_write_config(); plugin_load_standard_plugins (); diff --git a/src/prefs_common.c b/src/prefs_common.c @@ -141,6 +141,9 @@ static PrefParam param_os_specific[] = { */ static PrefParam param[] = { + {"config_version", "0", + &prefs_common.config_version, P_INT, NULL, NULL, NULL}, + /* Receive */ {"use_ext_inc", "FALSE", &prefs_common.use_extinc, P_BOOL, NULL, NULL, NULL}, diff --git a/src/prefs_common.h b/src/prefs_common.h @@ -36,6 +36,8 @@ #include "prefs_msg_colors.h" #include "prefs_summary_open.h" +#define CLAWS_CONFIG_VERSION 0 + typedef struct _PrefsCommon PrefsCommon; typedef enum { @@ -113,6 +115,8 @@ typedef enum struct _PrefsCommon { + gint config_version; + /* Receive */ gboolean use_extinc; gchar *extinc_cmd; diff --git a/src/prefs_migration.c b/src/prefs_migration.c @@ -0,0 +1,52 @@ +/* + * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client + * Copyright (C) 1999-2016 the Claws Mail team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#include "claws-features.h" +#endif + +#include "prefs_common.h" + +static void _update_config(gint version) +{ + switch (version) { + case 0: + default: + break; + } +} + +void prefs_update_config_version() +{ + gint ver = prefs_common_get_prefs()->config_version; + + debug_print("Starting config update at config_version %d.\n", ver); + if (ver == CLAWS_CONFIG_VERSION) { + debug_print("No update necessary, already at latest config_version.\n"); + return; + } + + while (ver < CLAWS_CONFIG_VERSION) { + _update_config(ver++); + prefs_common_get_prefs()->config_version = ver; + } + + debug_print("Config update done.\n"); +} diff --git a/src/prefs_migration.h b/src/prefs_migration.h @@ -0,0 +1,25 @@ +/* + * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client + * Copyright (C) 2016 the Claws Mail team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef __PREFS_MIGRATION_H__ +#define __PREFS_MIGRATION_H__ + +void prefs_update_config_version(); + +#endif /* __PREFS_MIGRATION_H__ */