0ee859c4d2699f1b7badfec59a743948a8d4fa82
[claws.git] / src / prefs_migration.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2016 the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #include "claws-features.h"
22 #endif
23
24 #include "account.h"
25 #include "prefs_account.h"
26 #include "prefs_common.h"
27
28 static void _update_config(gint version)
29 {
30         GList *cur;
31         PrefsAccount *ac_prefs;
32
33         debug_print("Updating config version %d to %d.\n", version, version + 1);
34
35         switch (version) {
36                 case 0:
37
38                         /* Removing A_APOP and A_RPOP from RecvProtocol enum,
39                          * protocol numbers above A_POP3 need to be adjusted.
40                          *
41                          * In config_version=0:
42                          * A_POP3 is 0,
43                          * A_APOP is 1,
44                          * A_RPOP is 2,
45                          * A_IMAP and the rest are from 3 up.
46                          * We can't use the macros, since they may change in the
47                          * future. Numbers do not change. :) */
48                         for (cur = account_get_list(); cur != NULL; cur = cur->next) {
49                                 ac_prefs = (PrefsAccount *)cur->data;
50                                 if (ac_prefs->protocol == 1) {
51                                         ac_prefs->protocol = 0;
52                                 } else if (ac_prefs->protocol > 2) {
53                                         /* A_IMAP and above gets bumped down by 2. */
54                                         ac_prefs->protocol -= 2;
55                                 }
56                         }
57
58                         break;
59
60                 case 1:
61
62                         /* The autochk_interval preference is now
63                          * interpreted as seconds instead of minutes */
64                         prefs_common.autochk_itv *= 60;
65
66                         break;
67
68                 default:
69                         break;
70         }
71 }
72
73 void prefs_update_config_version()
74 {
75         gint ver = prefs_common_get_prefs()->config_version;
76
77         debug_print("Starting config update at config_version %d.\n", ver);
78         if (ver == CLAWS_CONFIG_VERSION) {
79                 debug_print("No update necessary, already at latest config_version.\n");
80                 return;
81         }
82
83         while (ver < CLAWS_CONFIG_VERSION) {
84                 _update_config(ver++);
85                 prefs_common_get_prefs()->config_version = ver;
86         }
87
88         debug_print("Config update done.\n");
89 }