2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 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
,
84 {"save_copy_to_folder", NULL
, &tmp_prefs
.save_copy_to_folder
, P_BOOL
,
86 {"folder_color", "", &tmp_prefs
.color
, P_INT
,
88 {"enable_processing", "FALSE", &tmp_prefs
.enable_processing
, P_BOOL
,
90 {"newmailcheck", "TRUE", &tmp_prefs
.newmailcheck
, P_BOOL
,
92 {"offlinesync", "FALSE", &tmp_prefs
.offlinesync
, P_BOOL
,
94 {NULL
, NULL
, NULL
, P_OTHER
, NULL
, NULL
, NULL
}
97 static FolderItemPrefs
*folder_item_prefs_clear(FolderItemPrefs
*prefs
);
99 void folder_item_prefs_read_config(FolderItem
* item
)
104 id
= folder_item_get_identifier(item
);
105 folder_item_prefs_clear(&tmp_prefs
);
106 rcpath
= g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S
, FOLDERITEM_RC
, NULL
);
107 prefs_read_config(param
, id
, rcpath
, NULL
);
111 *item
->prefs
= tmp_prefs
;
114 * MIGRATION: next lines are migration code. the idea is that
115 * if used regularly, claws folder config ends up
116 * in the same file as sylpheed-main
119 item
->ret_rcpt
= tmp_prefs
.request_return_receipt
? TRUE
: FALSE
;
121 /* MIGRATION: 0.7.8main+ has persistent sort order. claws had the sort
122 * order in different members, which is ofcourse a little
124 if (item
->sort_key
== SORT_BY_NONE
) {
125 item
->sort_key
= (tmp_prefs
.sort_by_number
? SORT_BY_NUMBER
:
126 tmp_prefs
.sort_by_size
? SORT_BY_SIZE
:
127 tmp_prefs
.sort_by_date
? SORT_BY_DATE
:
128 tmp_prefs
.sort_by_from
? SORT_BY_FROM
:
129 tmp_prefs
.sort_by_subject
? SORT_BY_SUBJECT
:
130 tmp_prefs
.sort_by_score
? SORT_BY_SCORE
:
132 item
->sort_type
= tmp_prefs
.sort_descending
? SORT_DESCENDING
: SORT_ASCENDING
;
136 void folder_item_prefs_save_config(FolderItem
* item
)
140 tmp_prefs
= * item
->prefs
;
142 id
= folder_item_get_identifier(item
);
144 prefs_write_config(param
, id
, FOLDERITEM_RC
);
147 /* MIGRATION: make sure migrated items are not saved
151 void folder_item_prefs_set_config(FolderItem
* item
,
152 int sort_type
, gint sort_mode
)
155 g_warning("folder_item_prefs_set_config() should never be called\n");
156 item
->sort_key
= sort_type
;
157 item
->sort_type
= sort_mode
;
160 static FolderItemPrefs
*folder_item_prefs_clear(FolderItemPrefs
*prefs
)
162 prefs
->sort_by_number
= FALSE
;
163 prefs
->sort_by_size
= FALSE
;
164 prefs
->sort_by_date
= FALSE
;
165 prefs
->sort_by_from
= FALSE
;
166 prefs
->sort_by_subject
= FALSE
;
167 prefs
->sort_by_score
= FALSE
;
168 prefs
->sort_descending
= FALSE
;
170 prefs
->request_return_receipt
= FALSE
;
171 prefs
->enable_default_to
= FALSE
;
172 prefs
->default_to
= NULL
;
173 prefs
->enable_default_reply_to
= FALSE
;
174 prefs
->default_reply_to
= NULL
;
175 prefs
->enable_simplify_subject
= FALSE
;
176 prefs
->simplify_subject_regexp
= NULL
;
177 prefs
->enable_folder_chmod
= FALSE
;
178 prefs
->folder_chmod
= 0;
179 prefs
->enable_default_account
= FALSE
;
180 prefs
->default_account
= 0;
182 prefs
->enable_default_dictionary
= FALSE
;
183 prefs
->default_dictionary
= NULL
;
185 prefs
->save_copy_to_folder
= FALSE
;
188 prefs
->enable_processing
= TRUE
;
189 prefs
->processing
= NULL
;
191 prefs
->newmailcheck
= TRUE
;
192 prefs
->offlinesync
= FALSE
;
197 FolderItemPrefs
* folder_item_prefs_new(void)
199 FolderItemPrefs
* prefs
;
201 prefs
= g_new0(FolderItemPrefs
, 1);
203 return folder_item_prefs_clear(prefs
);
206 void folder_item_prefs_free(FolderItemPrefs
* prefs
)
208 g_free(prefs
->default_to
);
209 g_free(prefs
->default_reply_to
);
213 gint
folder_item_prefs_get_sort_mode(FolderItem
* item
)
215 g_assert(item
!= NULL
);
216 g_warning("folder_item_prefs_get_sort_mode() should never be called\n");
217 return item
->sort_key
;
220 gint
folder_item_prefs_get_sort_type(FolderItem
* item
)
222 g_assert(item
!= NULL
);
223 g_warning("folder_item_prefs_get_sort_type() should never be called\n");
224 return item
->sort_type
;
227 #define SAFE_STRING(str) \
230 void folder_item_prefs_copy_prefs(FolderItem
* src
, FolderItem
* dest
)
232 GSList
*tmp_prop_list
= NULL
, *tmp
;
233 folder_item_prefs_read_config(src
);
235 tmp_prefs
.directory
= g_strdup(src
->prefs
->directory
);
236 tmp_prefs
.sort_by_number
= src
->prefs
->sort_by_number
;
237 tmp_prefs
.sort_by_size
= src
->prefs
->sort_by_size
;
238 tmp_prefs
.sort_by_date
= src
->prefs
->sort_by_date
;
239 tmp_prefs
.sort_by_from
= src
->prefs
->sort_by_from
;
240 tmp_prefs
.sort_by_subject
= src
->prefs
->sort_by_subject
;
241 tmp_prefs
.sort_by_score
= src
->prefs
->sort_by_score
;
242 tmp_prefs
.sort_descending
= src
->prefs
->sort_descending
;
243 tmp_prefs
.enable_thread
= src
->prefs
->enable_thread
;
244 tmp_prefs
.enable_processing
= src
->prefs
->enable_processing
;
245 tmp_prefs
.newmailcheck
= src
->prefs
->newmailcheck
;
246 tmp_prefs
.offlinesync
= src
->prefs
->offlinesync
;
248 prefs_matcher_read_config();
250 for (tmp
= src
->prefs
->processing
; tmp
!= NULL
&& tmp
->data
!= NULL
;) {
251 FilteringProp
*prop
= (FilteringProp
*)tmp
->data
;
253 tmp_prop_list
= g_slist_append(tmp_prop_list
,
254 filteringprop_copy(prop
));
257 tmp_prefs
.processing
= tmp_prop_list
;
259 tmp_prefs
.request_return_receipt
= src
->prefs
->request_return_receipt
;
260 tmp_prefs
.enable_default_to
= src
->prefs
->enable_default_to
;
261 tmp_prefs
.default_to
= g_strdup(src
->prefs
->default_to
);
262 tmp_prefs
.enable_default_reply_to
= src
->prefs
->enable_default_reply_to
;
263 tmp_prefs
.default_reply_to
= g_strdup(src
->prefs
->default_reply_to
);
264 tmp_prefs
.enable_simplify_subject
= src
->prefs
->enable_simplify_subject
;
265 tmp_prefs
.simplify_subject_regexp
= g_strdup(src
->prefs
->simplify_subject_regexp
);
266 tmp_prefs
.enable_folder_chmod
= src
->prefs
->enable_folder_chmod
;
267 tmp_prefs
.folder_chmod
= src
->prefs
->folder_chmod
;
268 tmp_prefs
.enable_default_account
= src
->prefs
->enable_default_account
;
269 tmp_prefs
.default_account
= src
->prefs
->default_account
;
271 tmp_prefs
.enable_default_dictionary
= src
->prefs
->enable_default_dictionary
;
272 tmp_prefs
.default_dictionary
= g_strdup(src
->prefs
->default_dictionary
);
274 tmp_prefs
.save_copy_to_folder
= src
->prefs
->save_copy_to_folder
;
275 tmp_prefs
.color
= src
->prefs
->color
;
277 *dest
->prefs
= tmp_prefs
;
278 folder_item_prefs_save_config(dest
);