2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
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.
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.
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/>.
25 #include <glib/gi18n.h>
30 #include "prefs_gtk.h"
31 #include "filtering.h"
32 #include "folder_item_prefs.h"
34 FolderItemPrefs tmp_prefs;
36 static PrefParam param[] = {
37 {"enable_default_to", "", &tmp_prefs.enable_default_to, P_BOOL,
39 {"default_to", "", &tmp_prefs.default_to, P_STRING,
41 {"enable_default_reply_to", "", &tmp_prefs.enable_default_reply_to, P_BOOL,
43 {"default_reply_to", "", &tmp_prefs.default_reply_to, P_STRING,
45 {"enable_simplify_subject", "", &tmp_prefs.enable_simplify_subject, P_BOOL,
47 {"simplify_subject_regexp", "", &tmp_prefs.simplify_subject_regexp, P_STRING,
49 {"enable_folder_chmod", "", &tmp_prefs.enable_folder_chmod, P_BOOL,
51 {"folder_chmod", "", &tmp_prefs.folder_chmod, P_INT,
53 {"enable_default_account", "", &tmp_prefs.enable_default_account, P_BOOL,
55 {"default_account", NULL, &tmp_prefs.default_account, P_INT,
58 {"enable_default_dictionary", "", &tmp_prefs.enable_default_dictionary, P_BOOL,
60 {"default_dictionary", NULL, &tmp_prefs.default_dictionary, P_STRING,
62 {"enable_default_alt_dictionary", "", &tmp_prefs.enable_default_alt_dictionary, P_BOOL,
64 {"default_alt_dictionary", NULL, &tmp_prefs.default_alt_dictionary, P_STRING,
67 {"save_copy_to_folder", NULL, &tmp_prefs.save_copy_to_folder, P_BOOL,
69 {"folder_color", "", &tmp_prefs.color, P_INT,
71 {"enable_processing", "FALSE", &tmp_prefs.enable_processing, P_BOOL,
73 {"newmailcheck", "TRUE", &tmp_prefs.newmailcheck, P_BOOL,
75 {"offlinesync", "FALSE", &tmp_prefs.offlinesync, P_BOOL,
77 {"offlinesync_days", "0", &tmp_prefs.offlinesync_days, P_INT,
79 {"remove_old_bodies", "FALSE", &tmp_prefs.remove_old_bodies, P_BOOL,
82 {"compose_with_format", "FALSE", &tmp_prefs.compose_with_format, P_BOOL,
84 {"compose_subject_format", NULL, &tmp_prefs.compose_subject_format, P_STRING,
86 {"compose_body_format", NULL, &tmp_prefs.compose_body_format, P_STRING,
88 {"reply_with_format", "FALSE", &tmp_prefs.reply_with_format, P_BOOL,
90 {"reply_quotemark", NULL, &tmp_prefs.reply_quotemark, P_STRING,
92 {"reply_body_format", NULL, &tmp_prefs.reply_body_format, P_STRING,
94 {"forward_with_format", "FALSE", &tmp_prefs.forward_with_format, P_BOOL,
96 {"forward_quotemark", NULL, &tmp_prefs.forward_quotemark, P_STRING,
98 {"forward_body_format", NULL, &tmp_prefs.forward_body_format, P_STRING,
100 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
103 static FolderItemPrefs *folder_item_prefs_clear(FolderItemPrefs *prefs);
105 void folder_item_prefs_read_config(FolderItem * item)
110 id = folder_item_get_identifier(item);
111 folder_item_prefs_clear(&tmp_prefs);
112 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, FOLDERITEM_RC, NULL);
113 prefs_read_config(param, id, rcpath, NULL);
117 *item->prefs = tmp_prefs;
120 void folder_item_prefs_save_config(FolderItem * item)
124 tmp_prefs = * item->prefs;
126 id = folder_item_get_identifier(item);
127 debug_print("saving prefs for %s\n", id?id:"(null)");
128 prefs_write_config(param, id, FOLDERITEM_RC);
132 static gboolean folder_item_prefs_save_config_func(GNode *node, gpointer data)
134 FolderItem *item = (FolderItem *) node->data;
135 folder_item_prefs_save_config(item);
139 void folder_item_prefs_save_config_recursive(FolderItem * item)
141 g_node_traverse(item->node, G_PRE_ORDER, G_TRAVERSE_ALL,
142 -1, folder_item_prefs_save_config_func, NULL);
145 static FolderItemPrefs *folder_item_prefs_clear(FolderItemPrefs *prefs)
147 prefs->enable_default_to = FALSE;
148 prefs->default_to = NULL;
149 prefs->enable_default_reply_to = FALSE;
150 prefs->default_reply_to = NULL;
151 prefs->enable_simplify_subject = FALSE;
152 prefs->simplify_subject_regexp = NULL;
153 prefs->enable_folder_chmod = FALSE;
154 prefs->folder_chmod = 0;
155 prefs->enable_default_account = FALSE;
156 prefs->default_account = 0;
158 prefs->enable_default_dictionary = FALSE;
159 prefs->default_dictionary = NULL;
160 prefs->enable_default_alt_dictionary = FALSE;
161 prefs->default_alt_dictionary = NULL;
163 prefs->save_copy_to_folder = FALSE;
166 prefs->enable_processing = TRUE;
167 prefs->processing = NULL;
169 prefs->newmailcheck = TRUE;
170 prefs->offlinesync = FALSE;
171 prefs->offlinesync_days = 0;
172 prefs->remove_old_bodies = FALSE;
174 prefs->compose_with_format = FALSE;
175 prefs->compose_subject_format = NULL;
176 prefs->compose_body_format = NULL;
177 prefs->reply_with_format = FALSE;
178 prefs->reply_quotemark = NULL;
179 prefs->reply_body_format = NULL;
180 prefs->forward_with_format = FALSE;
181 prefs->forward_quotemark = NULL;
182 prefs->forward_body_format = NULL;
187 FolderItemPrefs * folder_item_prefs_new(void)
189 FolderItemPrefs * prefs;
191 prefs = g_new0(FolderItemPrefs, 1);
193 return folder_item_prefs_clear(prefs);
196 void folder_item_prefs_free(FolderItemPrefs * prefs)
198 g_free(prefs->default_to);
199 g_free(prefs->default_reply_to);
200 g_free(prefs->compose_subject_format);
201 g_free(prefs->compose_body_format);
202 g_free(prefs->reply_quotemark);
203 g_free(prefs->reply_body_format);
204 g_free(prefs->forward_quotemark);
205 g_free(prefs->forward_body_format);
209 #define SAFE_STRING(str) \
212 void folder_item_prefs_copy_prefs(FolderItem * src, FolderItem * dest)
214 GSList *tmp_prop_list = NULL, *tmp;
215 folder_item_prefs_read_config(src);
217 tmp_prefs.directory = g_strdup(src->prefs->directory);
218 tmp_prefs.enable_processing = src->prefs->enable_processing;
219 tmp_prefs.newmailcheck = src->prefs->newmailcheck;
220 tmp_prefs.offlinesync = src->prefs->offlinesync;
221 tmp_prefs.offlinesync_days = src->prefs->offlinesync_days;
222 tmp_prefs.remove_old_bodies = src->prefs->remove_old_bodies;
224 prefs_matcher_read_config();
226 for (tmp = src->prefs->processing; tmp != NULL && tmp->data != NULL;) {
227 FilteringProp *prop = (FilteringProp *)tmp->data;
229 tmp_prop_list = g_slist_append(tmp_prop_list,
230 filteringprop_copy(prop));
233 tmp_prefs.processing = tmp_prop_list;
235 tmp_prefs.request_return_receipt = src->prefs->request_return_receipt;
236 tmp_prefs.enable_default_to = src->prefs->enable_default_to;
237 tmp_prefs.default_to = g_strdup(src->prefs->default_to);
238 tmp_prefs.enable_default_reply_to = src->prefs->enable_default_reply_to;
239 tmp_prefs.default_reply_to = g_strdup(src->prefs->default_reply_to);
240 tmp_prefs.enable_simplify_subject = src->prefs->enable_simplify_subject;
241 tmp_prefs.simplify_subject_regexp = g_strdup(src->prefs->simplify_subject_regexp);
242 tmp_prefs.enable_folder_chmod = src->prefs->enable_folder_chmod;
243 tmp_prefs.folder_chmod = src->prefs->folder_chmod;
244 tmp_prefs.enable_default_account = src->prefs->enable_default_account;
245 tmp_prefs.default_account = src->prefs->default_account;
247 tmp_prefs.enable_default_dictionary = src->prefs->enable_default_dictionary;
248 tmp_prefs.default_dictionary = g_strdup(src->prefs->default_dictionary);
249 tmp_prefs.enable_default_alt_dictionary = src->prefs->enable_default_alt_dictionary;
250 tmp_prefs.default_alt_dictionary = g_strdup(src->prefs->default_alt_dictionary);
252 tmp_prefs.save_copy_to_folder = src->prefs->save_copy_to_folder;
253 tmp_prefs.color = src->prefs->color;
255 tmp_prefs.compose_with_format = src->prefs->compose_with_format;
256 tmp_prefs.compose_subject_format = g_strdup(src->prefs->compose_subject_format);
257 tmp_prefs.compose_body_format = g_strdup(src->prefs->compose_body_format);
258 tmp_prefs.reply_with_format = src->prefs->reply_with_format;
259 tmp_prefs.reply_quotemark = g_strdup(src->prefs->reply_quotemark);
260 tmp_prefs.reply_body_format = g_strdup(src->prefs->reply_body_format);
261 tmp_prefs.forward_with_format = src->prefs->forward_with_format;
262 tmp_prefs.forward_quotemark = g_strdup(src->prefs->forward_quotemark);
263 tmp_prefs.forward_body_format = g_strdup(src->prefs->forward_body_format);
265 *dest->prefs = tmp_prefs;
266 folder_item_prefs_save_config(dest);