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 2 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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 /* alfons - all folder item specific settings should migrate into
21 * folderlist.xml!!! the old folderitemrc file will only serve for a few
22 * versions (for compatibility) */
29 #include <glib/gi18n.h>
34 #include "prefs_gtk.h"
35 #include "filtering.h"
36 #include "folder_item_prefs.h"
38 FolderItemPrefs tmp_prefs
;
40 static PrefParam param
[] = {
41 {"sort_by_number", "FALSE", &tmp_prefs
.sort_by_number
, P_BOOL
,
43 {"sort_by_size", "FALSE", &tmp_prefs
.sort_by_size
, P_BOOL
,
45 {"sort_by_date", "FALSE", &tmp_prefs
.sort_by_date
, P_BOOL
,
47 {"sort_by_from", "FALSE", &tmp_prefs
.sort_by_from
, P_BOOL
,
49 {"sort_by_subject", "FALSE", &tmp_prefs
.sort_by_subject
, P_BOOL
,
51 {"sort_by_score", "FALSE", &tmp_prefs
.sort_by_score
, P_BOOL
,
53 {"sort_descending", "FALSE", &tmp_prefs
.sort_descending
, P_BOOL
,
56 {"request_return_receipt", "", &tmp_prefs
.request_return_receipt
, P_BOOL
,
58 {"enable_default_to", "", &tmp_prefs
.enable_default_to
, P_BOOL
,
60 {"default_to", "", &tmp_prefs
.default_to
, P_STRING
,
62 {"enable_default_reply_to", "", &tmp_prefs
.enable_default_reply_to
, P_BOOL
,
64 {"default_reply_to", "", &tmp_prefs
.default_reply_to
, P_STRING
,
66 {"enable_simplify_subject", "", &tmp_prefs
.enable_simplify_subject
, P_BOOL
,
68 {"simplify_subject_regexp", "", &tmp_prefs
.simplify_subject_regexp
, P_STRING
,
70 {"enable_folder_chmod", "", &tmp_prefs
.enable_folder_chmod
, P_BOOL
,
72 {"folder_chmod", "", &tmp_prefs
.folder_chmod
, P_INT
,
74 {"enable_default_account", "", &tmp_prefs
.enable_default_account
, P_BOOL
,
76 {"default_account", NULL
, &tmp_prefs
.default_account
, P_INT
,
79 {"enable_default_dictionary", "", &tmp_prefs
.enable_default_dictionary
, P_BOOL
,
81 {"default_dictionary", NULL
, &tmp_prefs
.default_dictionary
, P_STRING
,
83 {"enable_default_alt_dictionary", "", &tmp_prefs
.enable_default_alt_dictionary
, P_BOOL
,
85 {"default_alt_dictionary", NULL
, &tmp_prefs
.default_alt_dictionary
, P_STRING
,
88 {"save_copy_to_folder", NULL
, &tmp_prefs
.save_copy_to_folder
, P_BOOL
,
90 {"folder_color", "", &tmp_prefs
.color
, P_INT
,
92 {"enable_processing", "FALSE", &tmp_prefs
.enable_processing
, P_BOOL
,
94 {"newmailcheck", "TRUE", &tmp_prefs
.newmailcheck
, P_BOOL
,
96 {"offlinesync", "FALSE", &tmp_prefs
.offlinesync
, P_BOOL
,
99 {"compose_with_format", "FALSE", &tmp_prefs
.compose_with_format
, P_BOOL
,
101 {"compose_subject_format", NULL
, &tmp_prefs
.compose_subject_format
, P_STRING
,
103 {"compose_body_format", NULL
, &tmp_prefs
.compose_body_format
, P_STRING
,
105 {"reply_with_format", "FALSE", &tmp_prefs
.reply_with_format
, P_BOOL
,
107 {"reply_quotemark", NULL
, &tmp_prefs
.reply_quotemark
, P_STRING
,
109 {"reply_body_format", NULL
, &tmp_prefs
.reply_body_format
, P_STRING
,
111 {"forward_with_format", "FALSE", &tmp_prefs
.forward_with_format
, P_BOOL
,
113 {"forward_quotemark", NULL
, &tmp_prefs
.forward_quotemark
, P_STRING
,
115 {"forward_body_format", NULL
, &tmp_prefs
.forward_body_format
, P_STRING
,
117 {NULL
, NULL
, NULL
, P_OTHER
, NULL
, NULL
, NULL
}
120 static FolderItemPrefs
*folder_item_prefs_clear(FolderItemPrefs
*prefs
);
122 void folder_item_prefs_read_config(FolderItem
* item
)
127 id
= folder_item_get_identifier(item
);
128 folder_item_prefs_clear(&tmp_prefs
);
129 rcpath
= g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S
, FOLDERITEM_RC
, NULL
);
130 prefs_read_config(param
, id
, rcpath
, NULL
);
134 *item
->prefs
= tmp_prefs
;
137 * MIGRATION: next lines are migration code. the idea is that
138 * if used regularly, claws folder config ends up
139 * in the same file as sylpheed-main
142 item
->ret_rcpt
= tmp_prefs
.request_return_receipt
? TRUE
: FALSE
;
144 /* MIGRATION: 0.7.8main+ has persistent sort order. claws had the sort
145 * order in different members, which is ofcourse a little
147 if (item
->sort_key
== SORT_BY_NONE
) {
148 item
->sort_key
= (tmp_prefs
.sort_by_number
? SORT_BY_NUMBER
:
149 tmp_prefs
.sort_by_size
? SORT_BY_SIZE
:
150 tmp_prefs
.sort_by_date
? SORT_BY_DATE
:
151 tmp_prefs
.sort_by_from
? SORT_BY_FROM
:
152 tmp_prefs
.sort_by_subject
? SORT_BY_SUBJECT
:
153 tmp_prefs
.sort_by_score
? SORT_BY_SCORE
:
155 item
->sort_type
= tmp_prefs
.sort_descending
? SORT_DESCENDING
: SORT_ASCENDING
;
159 void folder_item_prefs_save_config(FolderItem
* item
)
163 tmp_prefs
= * item
->prefs
;
165 id
= folder_item_get_identifier(item
);
167 prefs_write_config(param
, id
, FOLDERITEM_RC
);
170 /* MIGRATION: make sure migrated items are not saved
174 static FolderItemPrefs
*folder_item_prefs_clear(FolderItemPrefs
*prefs
)
176 prefs
->sort_by_number
= FALSE
;
177 prefs
->sort_by_size
= FALSE
;
178 prefs
->sort_by_date
= FALSE
;
179 prefs
->sort_by_from
= FALSE
;
180 prefs
->sort_by_subject
= FALSE
;
181 prefs
->sort_by_score
= FALSE
;
182 prefs
->sort_descending
= FALSE
;
184 prefs
->request_return_receipt
= FALSE
;
185 prefs
->enable_default_to
= FALSE
;
186 prefs
->default_to
= NULL
;
187 prefs
->enable_default_reply_to
= FALSE
;
188 prefs
->default_reply_to
= NULL
;
189 prefs
->enable_simplify_subject
= FALSE
;
190 prefs
->simplify_subject_regexp
= NULL
;
191 prefs
->enable_folder_chmod
= FALSE
;
192 prefs
->folder_chmod
= 0;
193 prefs
->enable_default_account
= FALSE
;
194 prefs
->default_account
= 0;
196 prefs
->enable_default_dictionary
= FALSE
;
197 prefs
->default_dictionary
= NULL
;
198 prefs
->enable_default_alt_dictionary
= FALSE
;
199 prefs
->default_alt_dictionary
= NULL
;
201 prefs
->save_copy_to_folder
= FALSE
;
204 prefs
->enable_processing
= TRUE
;
205 prefs
->processing
= NULL
;
207 prefs
->newmailcheck
= TRUE
;
208 prefs
->offlinesync
= FALSE
;
210 prefs
->compose_with_format
= FALSE
;
211 prefs
->compose_subject_format
= NULL
;
212 prefs
->compose_body_format
= NULL
;
213 prefs
->reply_with_format
= FALSE
;
214 prefs
->reply_quotemark
= NULL
;
215 prefs
->reply_body_format
= NULL
;
216 prefs
->forward_with_format
= FALSE
;
217 prefs
->forward_quotemark
= NULL
;
218 prefs
->forward_body_format
= NULL
;
223 FolderItemPrefs
* folder_item_prefs_new(void)
225 FolderItemPrefs
* prefs
;
227 prefs
= g_new0(FolderItemPrefs
, 1);
229 return folder_item_prefs_clear(prefs
);
232 void folder_item_prefs_free(FolderItemPrefs
* prefs
)
234 g_free(prefs
->default_to
);
235 g_free(prefs
->default_reply_to
);
236 g_free(prefs
->compose_subject_format
);
237 g_free(prefs
->compose_body_format
);
238 g_free(prefs
->reply_quotemark
);
239 g_free(prefs
->reply_body_format
);
240 g_free(prefs
->forward_quotemark
);
241 g_free(prefs
->forward_body_format
);
245 #define SAFE_STRING(str) \
248 void folder_item_prefs_copy_prefs(FolderItem
* src
, FolderItem
* dest
)
250 GSList
*tmp_prop_list
= NULL
, *tmp
;
251 folder_item_prefs_read_config(src
);
253 tmp_prefs
.directory
= g_strdup(src
->prefs
->directory
);
254 tmp_prefs
.sort_by_number
= src
->prefs
->sort_by_number
;
255 tmp_prefs
.sort_by_size
= src
->prefs
->sort_by_size
;
256 tmp_prefs
.sort_by_date
= src
->prefs
->sort_by_date
;
257 tmp_prefs
.sort_by_from
= src
->prefs
->sort_by_from
;
258 tmp_prefs
.sort_by_subject
= src
->prefs
->sort_by_subject
;
259 tmp_prefs
.sort_by_score
= src
->prefs
->sort_by_score
;
260 tmp_prefs
.sort_descending
= src
->prefs
->sort_descending
;
261 tmp_prefs
.enable_thread
= src
->prefs
->enable_thread
;
262 tmp_prefs
.enable_processing
= src
->prefs
->enable_processing
;
263 tmp_prefs
.newmailcheck
= src
->prefs
->newmailcheck
;
264 tmp_prefs
.offlinesync
= src
->prefs
->offlinesync
;
266 prefs_matcher_read_config();
268 for (tmp
= src
->prefs
->processing
; tmp
!= NULL
&& tmp
->data
!= NULL
;) {
269 FilteringProp
*prop
= (FilteringProp
*)tmp
->data
;
271 tmp_prop_list
= g_slist_append(tmp_prop_list
,
272 filteringprop_copy(prop
));
275 tmp_prefs
.processing
= tmp_prop_list
;
277 tmp_prefs
.request_return_receipt
= src
->prefs
->request_return_receipt
;
278 tmp_prefs
.enable_default_to
= src
->prefs
->enable_default_to
;
279 tmp_prefs
.default_to
= g_strdup(src
->prefs
->default_to
);
280 tmp_prefs
.enable_default_reply_to
= src
->prefs
->enable_default_reply_to
;
281 tmp_prefs
.default_reply_to
= g_strdup(src
->prefs
->default_reply_to
);
282 tmp_prefs
.enable_simplify_subject
= src
->prefs
->enable_simplify_subject
;
283 tmp_prefs
.simplify_subject_regexp
= g_strdup(src
->prefs
->simplify_subject_regexp
);
284 tmp_prefs
.enable_folder_chmod
= src
->prefs
->enable_folder_chmod
;
285 tmp_prefs
.folder_chmod
= src
->prefs
->folder_chmod
;
286 tmp_prefs
.enable_default_account
= src
->prefs
->enable_default_account
;
287 tmp_prefs
.default_account
= src
->prefs
->default_account
;
289 tmp_prefs
.enable_default_dictionary
= src
->prefs
->enable_default_dictionary
;
290 tmp_prefs
.default_dictionary
= g_strdup(src
->prefs
->default_dictionary
);
291 tmp_prefs
.enable_default_alt_dictionary
= src
->prefs
->enable_default_alt_dictionary
;
292 tmp_prefs
.default_alt_dictionary
= g_strdup(src
->prefs
->default_alt_dictionary
);
294 tmp_prefs
.save_copy_to_folder
= src
->prefs
->save_copy_to_folder
;
295 tmp_prefs
.color
= src
->prefs
->color
;
297 tmp_prefs
.compose_with_format
= src
->prefs
->compose_with_format
;
298 tmp_prefs
.compose_subject_format
= g_strdup(src
->prefs
->compose_subject_format
);
299 tmp_prefs
.compose_body_format
= g_strdup(src
->prefs
->compose_body_format
);
300 tmp_prefs
.reply_with_format
= src
->prefs
->reply_with_format
;
301 tmp_prefs
.reply_quotemark
= g_strdup(src
->prefs
->reply_quotemark
);
302 tmp_prefs
.reply_body_format
= g_strdup(src
->prefs
->reply_body_format
);
303 tmp_prefs
.forward_with_format
= src
->prefs
->forward_with_format
;
304 tmp_prefs
.forward_quotemark
= g_strdup(src
->prefs
->forward_quotemark
);
305 tmp_prefs
.forward_body_format
= g_strdup(src
->prefs
->forward_body_format
);
307 *dest
->prefs
= tmp_prefs
;
308 folder_item_prefs_save_config(dest
);