add shadow to rule list (like everywhere else)
[claws.git] / src / prefs_migration.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 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 #ifdef ENABLE_NLS
25 #include <glib/gi18n.h>
26 #else
27 #define _(a) (a)
28 #define N_(a) (a)
29 #endif
30
31 #include "defs.h"
32 #include "account.h"
33 #include "prefs_account.h"
34 #include "prefs_common.h"
35 #include "alertpanel.h"
36
37 static void _update_config(gint version)
38 {
39         GList *cur;
40         PrefsAccount *ac_prefs;
41
42         debug_print("Updating config version %d to %d.\n", version, version + 1);
43
44         switch (version) {
45                 case 0:
46
47                         /* Removing A_APOP and A_RPOP from RecvProtocol enum,
48                          * protocol numbers above A_POP3 need to be adjusted.
49                          *
50                          * In config_version=0:
51                          * A_POP3 is 0,
52                          * A_APOP is 1,
53                          * A_RPOP is 2,
54                          * A_IMAP and the rest are from 3 up.
55                          * We can't use the macros, since they may change in the
56                          * future. Numbers do not change. :) */
57                         for (cur = account_get_list(); cur != NULL; cur = cur->next) {
58                                 ac_prefs = (PrefsAccount *)cur->data;
59                                 if (ac_prefs->protocol == 1) {
60                                         ac_prefs->protocol = 0;
61                                 } else if (ac_prefs->protocol > 2) {
62                                         /* A_IMAP and above gets bumped down by 2. */
63                                         ac_prefs->protocol -= 2;
64                                 }
65                         }
66
67                         break;
68
69                 case 1:
70
71                         /* The autochk_interval preference is now
72                          * interpreted as seconds instead of minutes */
73                         prefs_common.autochk_itv *= 60;
74
75                         break;
76
77                 default:
78                         break;
79         }
80 }
81
82 int prefs_update_config_version()
83 {
84         gint ver = prefs_common_get_prefs()->config_version;
85
86         if (ver > CLAWS_CONFIG_VERSION) {
87                 gchar *msg;
88                 gchar *markup;
89                 AlertValue av;
90
91                 markup = g_strdup_printf(
92                         "<a href=\"%s\"><span underline=\"none\">",
93                         CONFIG_VERSIONS_URI);
94                 msg = g_strdup_printf(
95                         _("Your Claws Mail configuration is from a newer "
96                           "version than the version which you are currently "
97                           "using.\n\n"
98                           "This is not recommended.\n\n"
99                           "For further information see the %sClaws Mail "
100                           "website%s.\n\n"
101                           "Do you want to exit now?"),
102                           markup, "</span></a>");
103                 g_free(markup);
104                 av = alertpanel_full(_("Configuration warning"), msg,
105                                         GTK_STOCK_NO, GTK_STOCK_YES, NULL,
106                                         FALSE, NULL,
107                                         ALERT_ERROR, G_ALERTALTERNATE);
108                 g_free(msg);
109
110                 if (av != G_ALERTDEFAULT)
111                         return -1; /* abort startup */
112
113                 return 0; /* hic sunt dracones */
114         }
115
116         debug_print("Starting config update at config_version %d.\n", ver);
117         if (ver == CLAWS_CONFIG_VERSION) {
118                 debug_print("No update necessary, already at latest config_version.\n");
119                 return 0; /* nothing to do */
120         }
121
122         while (ver < CLAWS_CONFIG_VERSION) {
123                 _update_config(ver++);
124                 prefs_common_get_prefs()->config_version = ver;
125         }
126
127         debug_print("Config update done.\n");
128         return 1; /* update done */
129 }