2006-11-09 [wwp] 2.6.0cvs21
[claws.git] / src / prefs_common.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2006 Hiroyuki Yamamoto and 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 2 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29 #include <gdk/gdkkeysyms.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <unistd.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <errno.h>
37
38 #include "main.h"
39 #include "prefs_gtk.h"
40 #include "prefs_common.h"
41 #include "prefs_display_header.h"
42 #include "prefs_summary_column.h"
43 #include "prefs_folder_column.h"
44 #include "mainwindow.h"
45 #include "summaryview.h"
46 #include "folderview.h"
47 #include "messageview.h"
48 #include "manage_window.h"
49 #include "inc.h"
50 #include "menu.h"
51 #include "codeconv.h"
52 #include "utils.h"
53 #include "gtkutils.h"
54 #include "alertpanel.h"
55 #include "folder.h"
56 #include "socket.h"
57 #include "filesel.h"
58 #include "folderview.h"
59 #include "stock_pixmap.h"
60 #include "prefswindow.h"
61 #include "colorlabel.h"
62
63 enum {
64         DATEFMT_FMT,
65         DATEFMT_TXT,
66         N_DATEFMT_COLUMNS
67 };
68
69 PrefsCommon prefs_common;
70
71 GtkWidget *notebook;
72
73 #ifdef G_OS_WIN32
74 /*
75  * In the Windows version prefs_common contains
76  *   - the non-OS-specific settings of the "Common" section and
77  *   - the OS-specific settings of the "CommonWin32" section
78  * The OS-specific settings of the "Common" section are not used
79  * but saved in prefs_unix.
80  */
81
82 #  define SPECIFIC_PREFS prefs_unix
83
84 static PrefsCommon prefs_unix;
85
86 static PrefParam param_os_specific[] = {
87         /* Receive */
88         {"ext_inc_path", "",
89          &prefs_common.extinc_cmd, P_STRING, NULL, NULL, NULL},
90         {"newmail_notify_cmd", "",
91          &prefs_common.newmail_notify_cmd, P_STRING, NULL, NULL, NULL},
92
93         /* new fonts */
94         {"widget_font_gtk2",    NULL,
95           &prefs_common.widgetfont,             P_STRING, NULL, NULL, NULL},
96         {"message_font_gtk2",   "Monospace 9",
97          &prefs_common.textfont,                P_STRING, NULL, NULL, NULL},
98         {"print_font_gtk2",     "Monospace 9",
99          &prefs_common.printfont,               P_STRING, NULL, NULL, NULL},
100         {"small_font_gtk2",     "Sans 9",
101           &prefs_common.smallfont,              P_STRING, NULL, NULL, NULL},
102         {"normal_font_gtk2",    "Sans 9",
103           &prefs_common.normalfont,             P_STRING, NULL, NULL, NULL},
104
105         /* Message */
106         {"attach_save_directory", NULL,
107          &prefs_common.attach_save_dir, P_STRING, NULL, NULL, NULL},
108         {"attach_load_directory", NULL,
109          &prefs_common.attach_load_dir, P_STRING, NULL, NULL, NULL},
110
111         /* MIME viewer */
112         {"mime_textviewer", NULL,
113          &prefs_common.mime_textviewer,   P_STRING, NULL, NULL, NULL},
114         {"mime_open_command", "notepad '%s'",
115          &prefs_common.mime_open_cmd,     P_STRING, NULL, NULL, NULL},
116
117         /* Interface */
118         {"pixmap_theme_path", DEFAULT_PIXMAP_THEME, 
119          &prefs_common.pixmap_theme_path, P_STRING, NULL, NULL, NULL},
120
121         /* Other */
122         {"uri_open_command", NULL,
123          &prefs_common.uri_cmd, P_STRING, NULL, NULL, NULL},
124         {"print_command", "notepad /p %s",
125          &prefs_common.print_cmd, P_STRING, NULL, NULL, NULL},
126         {"ext_editor_command", "notepad %s",
127          &prefs_common.ext_editor_cmd, P_STRING, NULL, NULL, NULL},
128
129         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
130 };
131 #else
132 #  define SPECIFIC_PREFS prefs_common
133 #endif
134
135 /*
136    parameter name, default value, pointer to the prefs variable, data type,
137    pointer to the widget pointer,
138    pointer to the function for data setting,
139    pointer to the function for widget setting
140  */
141
142 static PrefParam param[] = {
143         /* Receive */
144         {"use_ext_inc", "FALSE", &prefs_common.use_extinc, P_BOOL,
145          NULL, NULL, NULL},
146         {"ext_inc_path", DEFAULT_INC_PATH, &SPECIFIC_PREFS.extinc_cmd, P_STRING,
147          NULL, NULL, NULL},
148
149         {"autochk_newmail", "FALSE", &prefs_common.autochk_newmail, P_BOOL,
150          NULL, NULL, NULL},
151         {"autochk_interval", "10", &prefs_common.autochk_itv, P_INT,
152          NULL, NULL, NULL},
153         {"check_on_startup", "FALSE", &prefs_common.chk_on_startup, P_BOOL,
154          NULL, NULL, NULL},
155         {"open_inbox_on_inc", "FALSE", &prefs_common.open_inbox_on_inc,
156          P_BOOL, NULL, NULL, NULL},
157         {"scan_all_after_inc", "FALSE", &prefs_common.scan_all_after_inc,
158          P_BOOL, NULL, NULL, NULL},
159         {"newmail_notify_manu", "FALSE", &prefs_common.newmail_notify_manu,
160          P_BOOL, NULL, NULL, NULL},
161         {"newmail_notify_auto", "FALSE", &prefs_common.newmail_notify_auto,
162         P_BOOL, NULL, NULL, NULL},
163         {"newmail_notify_cmd", "", &SPECIFIC_PREFS.newmail_notify_cmd, P_STRING,
164          NULL, NULL, NULL},
165         {"receive_dialog_mode", "1", &prefs_common.recv_dialog_mode, P_ENUM,
166          NULL, NULL, NULL},
167         {"receivewin_width", "460", &prefs_common.receivewin_width, P_INT,
168          NULL, NULL, NULL},
169         {"receivewin_height", "-1", &prefs_common.receivewin_height, P_INT,
170          NULL, NULL, NULL},
171         {"no_receive_error_panel", "FALSE", &prefs_common.no_recv_err_panel,
172          P_BOOL, NULL, NULL, NULL},
173         {"close_receive_dialog", "TRUE", &prefs_common.close_recv_dialog,
174          P_BOOL, NULL, NULL, NULL},
175  
176         /* Send */
177         {"save_message", "TRUE", &prefs_common.savemsg, P_BOOL,
178          NULL, NULL, NULL},
179         {"confirm_send_queued_messages", "FALSE", &prefs_common.confirm_send_queued_messages,
180          P_BOOL, NULL, NULL, NULL},
181         {"send_dialog_mode", "0", &prefs_common.send_dialog_mode, P_ENUM,
182          NULL, NULL, NULL},
183         {"sendwin_width", "460", &prefs_common.sendwin_width, P_INT,
184          NULL, NULL, NULL},
185         {"sendwin_height", "-1", &prefs_common.sendwin_height, P_INT,
186          NULL, NULL, NULL},
187
188         {"outgoing_charset", CS_AUTO, &prefs_common.outgoing_charset, P_STRING,
189          NULL, NULL, NULL},
190         {"encoding_method", "0", &prefs_common.encoding_method, P_ENUM,
191          NULL, NULL, NULL},
192
193         {"allow_jisx0201_kana", "FALSE", &prefs_common.allow_jisx0201_kana,
194          P_BOOL, NULL, NULL, NULL},
195
196         /* Compose */
197         {"auto_ext_editor", "FALSE", &prefs_common.auto_exteditor, P_BOOL,
198          NULL, NULL, NULL},
199         {"forward_as_attachment", "FALSE", &prefs_common.forward_as_attachment,
200          P_BOOL, NULL, NULL, NULL},
201         {"redirect_keep_from", "FALSE",
202          &prefs_common.redirect_keep_from, P_BOOL,
203          NULL, NULL, NULL},
204         {"undo_level", "50", &prefs_common.undolevels, P_INT,
205          NULL, NULL, NULL},
206         {"compose_with_format", "FALSE", &prefs_common.compose_with_format, P_BOOL,
207          NULL, NULL, NULL},
208         {"compose_subject_format", "",
209          &prefs_common.compose_subject_format, P_STRING, NULL, NULL, NULL},
210         {"compose_body_format", N_("Hello,\\n"),
211          &prefs_common.compose_body_format, P_STRING, NULL, NULL, NULL},
212
213         {"linewrap_length", "72", &prefs_common.linewrap_len, P_INT,
214          NULL, NULL, NULL},
215         {"linewrap_quotation", "TRUE", &prefs_common.linewrap_quote, P_BOOL,
216          NULL, NULL, NULL},
217         {"linewrap_pastes", "TRUE", &prefs_common.linewrap_pastes, P_BOOL,
218          NULL, NULL, NULL},
219         {"linewrap_auto", "TRUE", &prefs_common.autowrap, P_BOOL,
220          NULL, NULL, NULL},
221         {"autosave", "TRUE", &prefs_common.autosave,
222          P_BOOL, NULL, NULL, NULL},
223         {"autosave_length", "50", &prefs_common.autosave_length, P_INT,
224          NULL, NULL, NULL},
225 #if USE_ASPELL
226         {"enable_aspell", "TRUE", &prefs_common.enable_aspell, P_BOOL,
227          NULL, NULL, NULL},
228         {"aspell_path", ASPELL_PATH, &prefs_common.aspell_path, P_STRING,
229          NULL, NULL, NULL},
230         {"dictionary",  "", &prefs_common.dictionary, P_STRING,
231          NULL, NULL, NULL},
232         {"aspell_sugmode", "1", &prefs_common.aspell_sugmode, P_INT,
233          NULL, NULL, NULL},
234         {"use_alternate_dict", "FALSE", &prefs_common.use_alternate, P_BOOL,
235          NULL, NULL, NULL},
236         {"check_while_typing", "TRUE", &prefs_common.check_while_typing, P_BOOL,
237          NULL, NULL, NULL},
238         {"recheck_when_changing_dict", "TRUE", &prefs_common.recheck_when_changing_dict,
239          P_BOOL, NULL, NULL, NULL},
240         {"misspelled_color", "16711680", &prefs_common.misspelled_col, P_COLOR,
241          NULL, NULL, NULL},
242 #endif
243         {"reply_with_quote", "TRUE", &prefs_common.reply_with_quote, P_BOOL,
244          NULL, NULL, NULL},
245         {"compose_dnd_insert_or_attach", "0", &prefs_common.compose_dnd_mode, P_ENUM,
246          NULL, NULL, NULL},
247
248         /* Account autoselection */
249         {"reply_account_autoselect", "TRUE",
250          &prefs_common.reply_account_autosel, P_BOOL,
251          NULL, NULL, NULL},
252         {"forward_account_autoselect", "TRUE",
253          &prefs_common.forward_account_autosel, P_BOOL,
254          NULL, NULL, NULL},
255         {"reedit_account_autoselect", "TRUE",
256          &prefs_common.reedit_account_autosel, P_BOOL,
257          NULL, NULL, NULL},
258
259         {"default_reply_list", "TRUE", &prefs_common.default_reply_list, P_BOOL,
260          NULL, NULL, NULL},
261
262         {"show_ruler", "TRUE", &prefs_common.show_ruler, P_BOOL,
263          NULL, NULL, NULL},
264
265         /* Quote */
266         {"reply_quote_mark", "> ", &prefs_common.quotemark, P_STRING,
267          NULL, NULL, NULL},
268         {"reply_quote_format", N_("On %d\\n%f wrote:\\n\\n%q"),
269          &prefs_common.quotefmt, P_STRING, NULL, NULL, NULL},
270
271         {"forward_quote_mark", "> ", &prefs_common.fw_quotemark, P_STRING,
272          NULL, NULL, NULL},
273         {"forward_quote_format",
274          N_("\\n\\nBegin forwarded message:\\n\\n"
275          "?d{Date: %d\\n}?f{From: %f\\n}?t{To: %t\\n}?c{Cc: %c\\n}"
276          "?n{Newsgroups: %n\\n}?s{Subject: %s\\n}\\n\\n%M"),
277          &prefs_common.fw_quotefmt, P_STRING, NULL, NULL, NULL},
278         {"quote_chars", ">", &prefs_common.quote_chars, P_STRING,
279          NULL, NULL, NULL},
280
281         /* Display */
282         /* Obsolete fonts. For coexisting with Gtk+-1.2 version */
283         {"widget_font",         NULL,
284           &prefs_common.widgetfont_gtk1,        P_STRING, NULL, NULL, NULL},
285         {"message_font",        "-misc-fixed-medium-r-normal--14-*-*-*-*-*-*-*",
286          &prefs_common.textfont_gtk1,           P_STRING, NULL, NULL, NULL},
287         {"small_font",          "-*-helvetica-medium-r-normal--10-*-*-*-*-*-*-*",
288           &prefs_common.smallfont_gtk1,         P_STRING, NULL, NULL, NULL},
289         {"bold_font",           "-*-helvetica-bold-r-normal--12-*-*-*-*-*-*-*",
290           &prefs_common.boldfont_gtk1,          P_STRING, NULL, NULL, NULL},
291         {"normal_font",         "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
292           &prefs_common.normalfont_gtk1,        P_STRING, NULL, NULL, NULL},
293
294         /* new fonts */
295         {"widget_font_gtk2",    NULL,
296           &SPECIFIC_PREFS.widgetfont,           P_STRING, NULL, NULL, NULL},
297         {"message_font_gtk2",   "Monospace 9",
298          &SPECIFIC_PREFS.textfont,                      P_STRING, NULL, NULL, NULL},
299         {"print_font_gtk2",     "Monospace 9",
300          &SPECIFIC_PREFS.printfont,             P_STRING, NULL, NULL, NULL},
301         {"small_font_gtk2",     "Sans 9",
302           &SPECIFIC_PREFS.smallfont,            P_STRING, NULL, NULL, NULL},
303         {"normal_font_gtk2",    "Sans 9",
304           &SPECIFIC_PREFS.normalfont,           P_STRING, NULL, NULL, NULL},
305
306         /* custom colors */
307         {"custom_color1", "#ff9900", &prefs_common.custom_colorlabel[0].color, P_COLOR,
308          NULL, NULL, NULL},
309         {"custom_colorlabel1", N_("Orange"), &prefs_common.custom_colorlabel[0].label, P_STRING,
310          NULL, NULL, NULL},
311         {"custom_color2", "#ff0000", &prefs_common.custom_colorlabel[1].color, P_COLOR,
312          NULL, NULL, NULL},
313         {"custom_colorlabel2", N_("Red"), &prefs_common.custom_colorlabel[1].label, P_STRING,
314          NULL, NULL, NULL},
315         {"custom_color3", "#ff66ff", &prefs_common.custom_colorlabel[2].color, P_COLOR,
316          NULL, NULL, NULL},
317         {"custom_colorlabel3", N_("Pink"), &prefs_common.custom_colorlabel[2].label, P_STRING,
318          NULL, NULL, NULL},
319         {"custom_color4", "#00ccff", &prefs_common.custom_colorlabel[3].color, P_COLOR,
320          NULL, NULL, NULL},
321         {"custom_colorlabel4", N_("Sky blue"), &prefs_common.custom_colorlabel[3].label, P_STRING,
322          NULL, NULL, NULL},
323         {"custom_color5", "#0000ff", &prefs_common.custom_colorlabel[4].color, P_COLOR,
324          NULL, NULL, NULL},
325         {"custom_colorlabel5", N_("Blue"), &prefs_common.custom_colorlabel[4].label, P_STRING,
326          NULL, NULL, NULL},
327         {"custom_color6", "#009900", &prefs_common.custom_colorlabel[5].color, P_COLOR,
328          NULL, NULL, NULL},
329         {"custom_colorlabel6", N_("Green"), &prefs_common.custom_colorlabel[5].label, P_STRING,
330          NULL, NULL, NULL},
331         {"custom_color7", "#663366", &prefs_common.custom_colorlabel[6].color, P_COLOR,
332          NULL, NULL, NULL},
333         {"custom_colorlabel7", N_("Brown"), &prefs_common.custom_colorlabel[6].label, P_STRING,
334          NULL, NULL, NULL},
335
336         /* image viewer */
337         {"display_image", "TRUE", &prefs_common.display_img, P_BOOL,
338          NULL, NULL, NULL},
339         {"resize_image", "TRUE", &prefs_common.resize_img, P_BOOL,
340          NULL, NULL, NULL},
341         {"inline_image", "TRUE", &prefs_common.inline_img, P_BOOL,
342          NULL, NULL, NULL},
343
344         {"display_folder_unread_num", "FALSE",
345          &prefs_common.display_folder_unread, P_BOOL,
346          NULL, NULL, NULL},
347         {"newsgroup_abbrev_len", "16",
348          &prefs_common.ng_abbrev_len, P_INT,
349          NULL, NULL, NULL},
350
351         {"translate_header", "FALSE", &prefs_common.trans_hdr, P_BOOL,
352          NULL, NULL, NULL},
353
354         /* Display: Summary View */
355         {"use_address_book", "FALSE", &prefs_common.use_addr_book, P_BOOL,
356          NULL, NULL, NULL},
357         {"thread_by_subject", "TRUE", &prefs_common.thread_by_subject, P_BOOL,
358          NULL, NULL, NULL},
359         {"date_format", N_("%y/%m/%d(%a) %H:%M"), &prefs_common.date_format,
360          P_STRING, NULL, NULL, NULL},
361
362         {"bold_unread", "TRUE", &prefs_common.bold_unread, P_BOOL,
363          NULL, NULL, NULL},
364
365         {"enable_thread", "TRUE", &prefs_common.enable_thread, P_BOOL,
366          NULL, NULL, NULL},
367         {"toolbar_style", "3", &prefs_common.toolbar_style, P_ENUM,
368          NULL, NULL, NULL},
369         {"toolbar_detachable", "FALSE", &prefs_common.toolbar_detachable, P_BOOL,
370          NULL, NULL, NULL},
371         {"show_statusbar", "TRUE", &prefs_common.show_statusbar, P_BOOL,
372          NULL, NULL, NULL},
373         {"show_searchbar", "TRUE", &prefs_common.show_searchbar, P_BOOL,
374          NULL, NULL, NULL},
375
376
377         {"summary_col_show_mark", "TRUE",
378          &prefs_common.summary_col_visible[S_COL_MARK], P_BOOL, NULL, NULL, NULL},
379         {"summary_col_show_unread", "TRUE",
380          &prefs_common.summary_col_visible[S_COL_STATUS], P_BOOL, NULL, NULL, NULL},
381         {"summary_col_show_mime", "TRUE",
382          &prefs_common.summary_col_visible[S_COL_MIME], P_BOOL, NULL, NULL, NULL},
383         {"summary_col_show_subject", "TRUE",
384          &prefs_common.summary_col_visible[S_COL_SUBJECT], P_BOOL, NULL, NULL, NULL},
385         {"summary_col_show_from", "TRUE",
386          &prefs_common.summary_col_visible[S_COL_FROM], P_BOOL, NULL, NULL, NULL},
387         {"summary_col_show_to", "FALSE",
388          &prefs_common.summary_col_visible[S_COL_TO], P_BOOL, NULL, NULL, NULL},
389         {"summary_col_show_date", "TRUE",
390          &prefs_common.summary_col_visible[S_COL_DATE], P_BOOL, NULL, NULL, NULL},
391         {"summary_col_show_size", "TRUE",
392          &prefs_common.summary_col_visible[S_COL_SIZE], P_BOOL, NULL, NULL, NULL},
393         {"summary_col_show_number", "FALSE",
394          &prefs_common.summary_col_visible[S_COL_NUMBER], P_BOOL, NULL, NULL, NULL},
395         {"summary_col_show_score", "FALSE",
396          &prefs_common.summary_col_visible[S_COL_SCORE], P_BOOL, NULL, NULL, NULL},
397         {"summary_col_show_locked", "FALSE",
398          &prefs_common.summary_col_visible[S_COL_LOCKED], P_BOOL, NULL, NULL, NULL},
399
400         {"summary_col_pos_mark", "0",
401           &prefs_common.summary_col_pos[S_COL_MARK], P_INT, NULL, NULL, NULL},
402         {"summary_col_pos_unread", "1",
403           &prefs_common.summary_col_pos[S_COL_STATUS], P_INT, NULL, NULL, NULL},
404         {"summary_col_pos_mime", "2",
405           &prefs_common.summary_col_pos[S_COL_MIME], P_INT, NULL, NULL, NULL},
406         {"summary_col_pos_subject", "3",
407           &prefs_common.summary_col_pos[S_COL_SUBJECT], P_INT, NULL, NULL, NULL},
408         {"summary_col_pos_from", "4",
409           &prefs_common.summary_col_pos[S_COL_FROM], P_INT, NULL, NULL, NULL},
410         {"summary_col_pos_date", "5",
411           &prefs_common.summary_col_pos[S_COL_DATE], P_INT, NULL, NULL, NULL},
412         {"summary_col_pos_size", "6",
413           &prefs_common.summary_col_pos[S_COL_SIZE], P_INT, NULL, NULL, NULL},
414         {"summary_col_pos_number", "7",
415           &prefs_common.summary_col_pos[S_COL_NUMBER], P_INT, NULL, NULL, NULL},
416         {"summary_col_pos_score", "8",
417          &prefs_common.summary_col_pos[S_COL_SCORE], P_INT, NULL, NULL, NULL},
418         {"summary_col_pos_locked", "9",
419          &prefs_common.summary_col_pos[S_COL_LOCKED], P_INT, NULL, NULL, NULL},
420         {"summary_col_pos_to", "10",
421           &prefs_common.summary_col_pos[S_COL_TO], P_INT, NULL, NULL, NULL},
422
423         {"summary_col_size_mark", "10",
424          &prefs_common.summary_col_size[S_COL_MARK], P_INT, NULL, NULL, NULL},
425         {"summary_col_size_unread", "13",
426          &prefs_common.summary_col_size[S_COL_STATUS], P_INT, NULL, NULL, NULL},
427         {"summary_col_size_mime", "10",
428          &prefs_common.summary_col_size[S_COL_MIME], P_INT, NULL, NULL, NULL},
429         {"summary_col_size_subject", "200",
430          &prefs_common.summary_col_size[S_COL_SUBJECT], P_INT, NULL, NULL, NULL},
431         {"summary_col_size_from", "120",
432          &prefs_common.summary_col_size[S_COL_FROM], P_INT, NULL, NULL, NULL},
433         {"summary_col_size_to", "120",
434          &prefs_common.summary_col_size[S_COL_TO], P_INT, NULL, NULL, NULL},
435         {"summary_col_size_date", "118",
436          &prefs_common.summary_col_size[S_COL_DATE], P_INT, NULL, NULL, NULL},
437         {"summary_col_size_size", "45",
438          &prefs_common.summary_col_size[S_COL_SIZE], P_INT, NULL, NULL, NULL},
439         {"summary_col_size_number", "40",
440          &prefs_common.summary_col_size[S_COL_NUMBER], P_INT, NULL, NULL, NULL},
441         {"summary_col_size_score", "40",
442          &prefs_common.summary_col_size[S_COL_SCORE], P_INT, NULL, NULL, NULL},
443         {"summary_col_size_locked", "13",
444          &prefs_common.summary_col_size[S_COL_LOCKED], P_INT, NULL, NULL, NULL},
445
446         /* Widget size */
447         {"folderwin_x", "16", &prefs_common.folderwin_x, P_INT,
448          NULL, NULL, NULL},
449         {"folderwin_y", "16", &prefs_common.folderwin_y, P_INT,
450          NULL, NULL, NULL},
451         {"folderview_width", "270", &prefs_common.folderview_width, P_INT,
452          NULL, NULL, NULL},
453         {"folderview_height", "450", &prefs_common.folderview_height, P_INT,
454          NULL, NULL, NULL},
455         {"folderview_visible", "TRUE", &prefs_common.folderview_visible, P_BOOL,
456          NULL, NULL, NULL},
457
458         {"folder_col_show_folder", "TRUE",
459          &prefs_common.folder_col_visible[F_COL_FOLDER], P_BOOL, NULL, NULL, NULL},
460         {"folder_col_show_new", "TRUE",
461          &prefs_common.folder_col_visible[F_COL_NEW], P_BOOL, NULL, NULL, NULL},
462         {"folder_col_show_unread", "TRUE",
463          &prefs_common.folder_col_visible[F_COL_UNREAD], P_BOOL, NULL, NULL, NULL},
464         {"folder_col_show_total", "TRUE",
465          &prefs_common.folder_col_visible[F_COL_TOTAL], P_BOOL, NULL, NULL, NULL},
466
467         {"folder_col_pos_folder", "0",
468          &prefs_common.folder_col_pos[F_COL_FOLDER], P_INT, NULL, NULL, NULL},
469         {"folder_col_pos_new", "1",
470          &prefs_common.folder_col_pos[F_COL_NEW], P_INT, NULL, NULL, NULL},
471         {"folder_col_pos_unread", "2",
472          &prefs_common.folder_col_pos[F_COL_UNREAD], P_INT, NULL, NULL, NULL},
473         {"folder_col_pos_total", "3",
474          &prefs_common.folder_col_pos[F_COL_TOTAL], P_INT, NULL, NULL, NULL},
475
476         {"folder_col_size_folder", "120",
477          &prefs_common.folder_col_size[F_COL_FOLDER], P_INT, NULL, NULL, NULL},
478         {"folder_col_size_new", "32",
479          &prefs_common.folder_col_size[F_COL_NEW], P_INT, NULL, NULL, NULL},
480         {"folder_col_size_unread", "32",
481          &prefs_common.folder_col_size[F_COL_UNREAD], P_INT, NULL, NULL, NULL},
482         {"folder_col_size_total", "32",
483          &prefs_common.folder_col_size[F_COL_TOTAL], P_INT, NULL, NULL, NULL},
484
485         {"summaryview_width", "500", &prefs_common.summaryview_width, P_INT,
486          NULL, NULL, NULL},
487         {"summaryview_height", "244", &prefs_common.summaryview_height, P_INT,
488          NULL, NULL, NULL},
489
490         {"main_messagewin_x", "256", &prefs_common.main_msgwin_x, P_INT,
491          NULL, NULL, NULL},
492         {"main_messagewin_y", "210", &prefs_common.main_msgwin_y, P_INT,
493          NULL, NULL, NULL},
494         {"messageview_width", "500", &prefs_common.msgview_width, P_INT,
495          NULL, NULL, NULL},
496         {"messageview_height", "213", &prefs_common.msgview_height, P_INT,
497          NULL, NULL, NULL},
498         {"messageview_visible", "TRUE", &prefs_common.msgview_visible, P_BOOL,
499          NULL, NULL, NULL},
500
501         {"mainview_x", "64", &prefs_common.mainview_x, P_INT,
502          NULL, NULL, NULL},
503         {"mainview_y", "64", &prefs_common.mainview_y, P_INT,
504          NULL, NULL, NULL},
505         {"mainview_width", "500", &prefs_common.mainview_width, P_INT,
506          NULL, NULL, NULL},
507         {"mainview_height", "400", &prefs_common.mainview_height, P_INT,
508          NULL, NULL, NULL},
509         {"mainwin_x", "64", &prefs_common.mainwin_x, P_INT,
510          NULL, NULL, NULL},
511         {"mainwin_y", "64", &prefs_common.mainwin_y, P_INT,
512          NULL, NULL, NULL},
513         {"mainwin_width", "800", &prefs_common.mainwin_width, P_INT,
514          NULL, NULL, NULL},
515         {"mainwin_height", "600", &prefs_common.mainwin_height, P_INT,
516          NULL, NULL, NULL},
517         {"messagewin_width", "600", &prefs_common.msgwin_width, P_INT,
518          NULL, NULL, NULL},
519         {"messagewin_height", "540", &prefs_common.msgwin_height, P_INT,
520          NULL, NULL, NULL},
521         {"sourcewin_width", "600", &prefs_common.sourcewin_width, P_INT,
522          NULL, NULL, NULL},
523         {"sourcewin_height", "500", &prefs_common.sourcewin_height, P_INT,
524          NULL, NULL, NULL},
525         {"compose_width", "600", &prefs_common.compose_width, P_INT,
526          NULL, NULL, NULL},
527         {"compose_height", "560", &prefs_common.compose_height, P_INT,
528          NULL, NULL, NULL},
529         {"compose_x", "0", &prefs_common.compose_x, P_INT,
530          NULL, NULL, NULL},
531         {"compose_y", "0", &prefs_common.compose_y, P_INT,
532          NULL, NULL, NULL},
533         /* Message */
534         {"enable_color", "TRUE", &prefs_common.enable_color, P_BOOL,
535          NULL, NULL, NULL},
536
537         {"quote_level1_color", "179", &prefs_common.quote_level1_col, P_COLOR,
538          NULL, NULL, NULL},
539         {"quote_level2_color", "179", &prefs_common.quote_level2_col, P_COLOR,
540          NULL, NULL, NULL},
541         {"quote_level3_color", "179", &prefs_common.quote_level3_col, P_COLOR,
542          NULL, NULL, NULL},
543         {"enable_bgcolor", "FALSE", &prefs_common.enable_bgcolor, P_BOOL,
544          NULL, NULL, NULL},
545         {"quote_level1_bgcolor", "13421772", &prefs_common.quote_level1_bgcol, P_COLOR,
546          NULL, NULL, NULL},
547         {"quote_level2_bgcolor", "13948116", &prefs_common.quote_level2_bgcol, P_COLOR,
548          NULL, NULL, NULL},
549         {"quote_level3_bgcolor", "14540253", &prefs_common.quote_level3_bgcol, P_COLOR,
550          NULL, NULL, NULL},
551         {"uri_color", "32512", &prefs_common.uri_col, P_COLOR,
552          NULL, NULL, NULL},
553         {"target_folder_color", "14294218", &prefs_common.tgt_folder_col, P_COLOR,
554          NULL, NULL, NULL},
555         {"signature_color", "7960953", &prefs_common.signature_col, P_COLOR,
556          NULL, NULL, NULL},
557         {"recycle_quote_colors", "FALSE", &prefs_common.recycle_quote_colors,
558          P_BOOL, NULL, NULL, NULL},
559
560         {"display_header_pane", "FALSE", &prefs_common.display_header_pane,
561          P_BOOL, NULL, NULL, NULL},
562         {"display_header", "TRUE", &prefs_common.display_header, P_BOOL,
563          NULL, NULL, NULL},
564         {"display_xface", "TRUE", &prefs_common.display_xface,
565          P_BOOL, NULL, NULL, NULL},
566         {"render_html", "TRUE", &prefs_common.render_html, P_BOOL,
567          NULL, NULL, NULL},
568         {"invoke_plugin_on_html", "FALSE", &prefs_common.invoke_plugin_on_html, P_BOOL,
569          NULL, NULL, NULL},
570         {"line_space", "2", &prefs_common.line_space, P_INT,
571          NULL, NULL, NULL},
572         {"never_send_retrcpt", "FALSE", &prefs_common.never_send_retrcpt, P_BOOL,
573          NULL, NULL, NULL},
574
575         {"enable_smooth_scroll", "FALSE",
576          &prefs_common.enable_smooth_scroll, P_BOOL,
577          NULL, NULL, NULL},
578         {"scroll_step", "1", &prefs_common.scroll_step, P_INT,
579          NULL, NULL, NULL},
580         {"scroll_half_page", "FALSE", &prefs_common.scroll_halfpage, P_BOOL,
581          NULL, NULL, NULL},
582         {"respect_flowed_format", "FALSE", &prefs_common.respect_flowed_format, P_BOOL,
583          NULL, NULL, NULL},
584
585         {"show_other_header", "FALSE", &prefs_common.show_other_header, P_BOOL,
586          NULL, NULL, NULL},
587
588         {"use_different_print_font", "FALSE", &prefs_common.use_different_print_font, P_BOOL,
589          NULL, NULL, NULL},
590
591         {"attach_desc", "TRUE", &prefs_common.attach_desc, P_BOOL,
592          NULL, NULL, NULL},
593         {"attach_save_directory", NULL,
594          &SPECIFIC_PREFS.attach_save_dir, P_STRING, NULL, NULL, NULL},
595         {"attach_load_directory", NULL,
596          &SPECIFIC_PREFS.attach_load_dir, P_STRING, NULL, NULL, NULL},
597
598         /* MIME viewer */
599         {"mime_textviewer",   NULL,
600          &SPECIFIC_PREFS.mime_textviewer,   P_STRING, NULL, NULL, NULL},
601         {"mime_open_command", "gedit '%s'",
602          &SPECIFIC_PREFS.mime_open_cmd,     P_STRING, NULL, NULL, NULL},
603
604         /* Interface */
605         {"separate_folder", "FALSE", &prefs_common.sep_folder, P_BOOL,
606          NULL, NULL, NULL},
607         {"separate_message", "FALSE", &prefs_common.sep_msg, P_BOOL,
608          NULL, NULL, NULL},
609
610         /* {"emulate_emacs", "FALSE", &prefs_common.emulate_emacs, P_BOOL,
611          NULL, NULL, NULL}, */
612         {"always_show_message_when_selected", "FALSE",
613          &prefs_common.always_show_msg,
614          P_BOOL, NULL, NULL, NULL},
615         {"select_on_entry", "2", &prefs_common.select_on_entry,
616          P_ENUM, NULL, NULL, NULL},
617         {"mark_as_read_on_new_window", "FALSE",
618          &prefs_common.mark_as_read_on_new_window,
619          P_BOOL, NULL, NULL, NULL},
620         {"mark_as_read_delay", "0",
621          &prefs_common.mark_as_read_delay, P_INT, 
622          NULL, NULL, NULL},
623         {"immediate_execution", "TRUE", &prefs_common.immediate_exec, P_BOOL,
624          NULL, NULL, NULL},
625         {"nextunreadmsg_dialog", "1", &prefs_common.next_unread_msg_dialog, P_ENUM,
626          NULL, NULL, NULL},
627
628         {"pixmap_theme_path", DEFAULT_PIXMAP_THEME, 
629          &SPECIFIC_PREFS.pixmap_theme_path, P_STRING,
630          NULL, NULL, NULL},
631
632         {"ask_mark_all_read", "TRUE", &prefs_common.ask_mark_all_read, P_BOOL,
633          NULL, NULL, NULL},
634
635         {"ask_apply_per_account_filtering_rules", "TRUE", &prefs_common.ask_apply_per_account_filtering_rules, P_BOOL,
636          NULL, NULL, NULL},
637         {"apply_per_account_filtering_rules", "0", &prefs_common.apply_per_account_filtering_rules, P_ENUM,
638          NULL, NULL, NULL},
639
640         /* Other */
641         {"uri_open_command", DEFAULT_BROWSER_CMD,
642          &SPECIFIC_PREFS.uri_cmd, P_STRING, NULL, NULL, NULL},
643         {"print_command", "lpr %s",
644          &SPECIFIC_PREFS.print_cmd, P_STRING, NULL, NULL, NULL},
645         {"ext_editor_command", DEFAULT_EDITOR_CMD,
646          &SPECIFIC_PREFS.ext_editor_cmd, P_STRING, NULL, NULL, NULL},
647
648         {"add_address_by_click", "FALSE", &prefs_common.add_address_by_click,
649          P_BOOL, NULL, NULL, NULL},
650         {"confirm_on_exit", "FALSE", &prefs_common.confirm_on_exit, P_BOOL,
651          NULL, NULL, NULL},
652         {"clean_trash_on_exit", "FALSE", &prefs_common.clean_on_exit, P_BOOL,
653          NULL, NULL, NULL},
654         {"ask_on_cleaning", "TRUE", &prefs_common.ask_on_clean, P_BOOL,
655          NULL, NULL, NULL},
656         {"warn_queued_on_exit", "TRUE", &prefs_common.warn_queued_on_exit,
657          P_BOOL, NULL, NULL, NULL},
658         {"work_offline", "FALSE", &prefs_common.work_offline, P_BOOL,
659          NULL, NULL, NULL},
660         {"summary_quicksearch_type", "0", &prefs_common.summary_quicksearch_type, P_INT,
661          NULL, NULL, NULL},
662         {"summary_quicksearch_recurse", "1", &prefs_common.summary_quicksearch_recurse, P_INT,
663          NULL, NULL, NULL},
664
665         {"io_timeout_secs", "60", &prefs_common.io_timeout_secs,
666          P_INT, NULL, NULL, NULL},
667         {"hide_score", "-9999", &prefs_common.kill_score, P_INT,
668          NULL, NULL, NULL},
669         {"important_score", "1", &prefs_common.important_score, P_INT,
670          NULL, NULL, NULL},
671         {"clip_log", "TRUE", &prefs_common.cliplog, P_BOOL,
672          NULL, NULL, NULL},
673         {"log_length", "500", &prefs_common.loglength, P_INT,
674          NULL, NULL, NULL},
675         {"log_msg_color", "#00af00", &prefs_common.log_msg_color, P_COLOR,
676          NULL, NULL, NULL},
677         {"log_warn_color", "#af0000", &prefs_common.log_warn_color, P_COLOR,
678          NULL, NULL, NULL},
679         {"log_error_color", "#af0000", &prefs_common.log_error_color, P_COLOR,
680          NULL, NULL, NULL},
681         {"log_in_color", "#000000", &prefs_common.log_in_color, P_COLOR,
682          NULL, NULL, NULL},
683         {"log_out_color", "#0000ef", &prefs_common.log_out_color, P_COLOR,
684          NULL, NULL, NULL},
685
686         {"color_new", "179", &prefs_common.color_new, P_COLOR,
687          NULL, NULL, NULL},
688
689         /* Some windows' sizes */
690         {"filteringwin_width", "500", &prefs_common.filteringwin_width, P_INT,
691          NULL, NULL, NULL},
692         {"filteringwin_height", "-1", &prefs_common.filteringwin_height, P_INT,
693          NULL, NULL, NULL},
694
695         {"filteringactionwin_width", "490", &prefs_common.filteringactionwin_width, P_INT,
696          NULL, NULL, NULL},
697         {"filteringactionwin_height", "-1", &prefs_common.filteringactionwin_height, P_INT,
698          NULL, NULL, NULL},
699
700         {"matcherwin_width", "520", &prefs_common.matcherwin_width, P_INT,
701          NULL, NULL, NULL},
702         {"matcherwin_height", "-1", &prefs_common.matcherwin_height, P_INT,
703          NULL, NULL, NULL},
704
705         {"templateswin_width", "440", &prefs_common.templateswin_width, P_INT,
706          NULL, NULL, NULL},
707         {"templateswin_height", "-1", &prefs_common.templateswin_height, P_INT,
708          NULL, NULL, NULL},
709
710         {"actionswin_width", "486", &prefs_common.actionswin_width, P_INT,
711          NULL, NULL, NULL},
712         {"actionswin_height", "-1", &prefs_common.actionswin_height, P_INT,
713          NULL, NULL, NULL},
714
715         {"addressbookwin_width", "520", &prefs_common.addressbookwin_width, P_INT,
716          NULL, NULL, NULL},
717         {"addressbookwin_height", "-1", &prefs_common.addressbookwin_height, P_INT,
718          NULL, NULL, NULL},
719
720         {"addressbookeditpersonwin_width", "640", &prefs_common.addressbookeditpersonwin_width, P_INT,
721          NULL, NULL, NULL},
722         {"addressbookeditpersonwin_height", "-1", &prefs_common.addressbookeditpersonwin_height, P_INT,
723          NULL, NULL, NULL},
724
725         {"addressbookeditgroupwin_width", "580", &prefs_common.addressbookeditgroupwin_width, P_INT,
726          NULL, NULL, NULL},
727         {"addressbookeditgroupwin_height", "340", &prefs_common.addressbookeditgroupwin_height, P_INT,
728          NULL, NULL, NULL},
729
730         {"pluginswin_width", "480", &prefs_common.pluginswin_width, P_INT,
731          NULL, NULL, NULL},
732         {"pluginswin_height", "-1", &prefs_common.pluginswin_height, P_INT,
733          NULL, NULL, NULL},
734
735         {"prefswin_width", "600", &prefs_common.prefswin_width, P_INT,
736          NULL, NULL, NULL},
737         {"prefswin_height", "-1", &prefs_common.prefswin_height, P_INT,
738          NULL, NULL, NULL},
739
740         {"folderitemwin_width", "500", &prefs_common.folderitemwin_width, P_INT,
741          NULL, NULL, NULL},
742         {"folderitemwin_height", "-1", &prefs_common.folderitemwin_height, P_INT,
743          NULL, NULL, NULL},
744
745         {"editaccountwin_width", "500", &prefs_common.editaccountwin_width, P_INT,
746          NULL, NULL, NULL},
747         {"editaccountwin_height", "-1", &prefs_common.editaccountwin_height, P_INT,
748          NULL, NULL, NULL},
749
750         {"accountswin_width", "500", &prefs_common.accountswin_width, P_INT,
751          NULL, NULL, NULL},
752         {"accountswin_height", "-1", &prefs_common.accountswin_height, P_INT,
753          NULL, NULL, NULL},
754
755         {"logwin_width", "520", &prefs_common.logwin_width, P_INT,
756          NULL, NULL, NULL},
757         {"logwin_height", "-1", &prefs_common.logwin_height, P_INT,
758          NULL, NULL, NULL},
759
760         {"folderselwin_width", "300", &prefs_common.folderselwin_width, P_INT,
761          NULL, NULL, NULL},
762         {"folderselwin_height", "-1", &prefs_common.folderselwin_height, P_INT,
763          NULL, NULL, NULL},
764
765         {"addressaddwin_width", "300", &prefs_common.addressaddwin_width, P_INT,
766          NULL, NULL, NULL},
767         {"addressaddwin_height", "-1", &prefs_common.addressaddwin_height, P_INT,
768          NULL, NULL, NULL},
769
770         {"addressbook_folderselwin_width", "300", &prefs_common.addressbook_folderselwin_width, P_INT,
771          NULL, NULL, NULL},
772         {"addressbook_folderselwin_height", "-1", &prefs_common.addressbook_folderselwin_height, P_INT,
773          NULL, NULL, NULL},
774
775         /* Hidden */
776         {"warn_dnd", "1", &prefs_common.warn_dnd, P_INT,
777          NULL, NULL, NULL},
778         {"utf8_instead_of_locale_for_broken_mail", "0", 
779          &prefs_common.broken_are_utf8, P_INT,
780          NULL, NULL, NULL},
781         {"enable_swap_from", "FALSE", &prefs_common.swap_from, P_BOOL,
782          NULL, NULL, NULL},
783         {"use_stripes_everywhere", "TRUE", &prefs_common.use_stripes_everywhere, P_BOOL,
784          NULL, NULL, NULL},
785         {"use_stripes_in_summaries", "TRUE", &prefs_common.use_stripes_in_summaries, P_BOOL,
786          NULL, NULL, NULL},
787         {"stripes_color_offset", "4000", &prefs_common.stripes_color_offset, P_INT,
788          NULL, NULL, NULL},
789         {"enable_dotted_lines", "FALSE", &prefs_common.enable_dotted_lines, P_BOOL,
790          NULL, NULL, NULL},
791         {"enable_hscrollbar", "TRUE", &prefs_common.enable_hscrollbar, P_BOOL,
792          NULL, NULL, NULL},
793         {"folderview_vscrollbar_policy", "0",
794          &prefs_common.folderview_vscrollbar_policy, P_ENUM,
795          NULL, NULL, NULL},
796         {"textview_cursor_visible", "FALSE",
797          &prefs_common.textview_cursor_visible, P_BOOL,
798          NULL, NULL, NULL},
799         {"hover_timeout", "500", &prefs_common.hover_timeout, P_INT,
800          NULL, NULL, NULL},
801         {"cache_max_mem_usage", "4096", &prefs_common.cache_max_mem_usage, P_INT,
802          NULL, NULL, NULL},
803         {"cache_min_keep_time", "15", &prefs_common.cache_min_keep_time, P_INT,
804          NULL, NULL, NULL},
805         {"thread_by_subject_max_age", "10", &prefs_common.thread_by_subject_max_age,
806         P_INT, NULL, NULL, NULL },
807         {"summary_quicksearch_sticky", "1", &prefs_common.summary_quicksearch_sticky, P_INT,
808          NULL, NULL, NULL},
809         {"summary_quicksearch_dynamic", "0", &prefs_common.summary_quicksearch_dynamic, P_INT,
810          NULL, NULL, NULL},
811         {"statusbar_update_step", "10", &prefs_common.statusbar_update_step, P_INT,
812          NULL, NULL, NULL},
813         {"compose_no_markup", "FALSE", &prefs_common.compose_no_markup, P_BOOL,
814          NULL, NULL, NULL},
815         {"skip_ssl_cert_check", "FALSE", &prefs_common.skip_ssl_cert_check, P_BOOL,
816          NULL, NULL, NULL},
817         {"live_dangerously", "FALSE", &prefs_common.live_dangerously, P_BOOL,
818          NULL, NULL, NULL},
819         {"hide_quotes", "0", &prefs_common.hide_quotes, P_INT,
820          NULL, NULL, NULL},
821
822         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
823 };
824
825 PrefsCommon *prefs_common_get(void)
826 {
827         return &prefs_common;
828 }
829
830 /*
831  * Read history list from the specified history file
832  */
833 GList *prefs_common_read_history(const gchar *history) 
834 {
835         FILE *fp;
836         gchar *path;
837         gchar buf[PREFSBUFSIZE];
838         GList *tmp = NULL;
839
840         path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, history,
841                            NULL);
842         if ((fp = g_fopen(path, "rb")) == NULL) {
843                 if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
844                 g_free(path);
845                 return NULL;
846         }
847         g_free(path);
848         while (fgets(buf, sizeof(buf), fp) != NULL) {
849                 g_strstrip(buf);
850                 if (buf[0] == '\0') continue;
851                 tmp = add_history(tmp, buf);
852         }
853         fclose(fp);
854
855         tmp = g_list_reverse(tmp);
856
857         return tmp;
858 }
859
860 void prefs_common_read_config(void)
861 {
862         gchar *rcpath;
863         gchar *tmp;
864
865         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
866         prefs_read_config(param, "Common", rcpath, NULL);
867 #ifdef G_OS_WIN32
868         prefs_read_config(param_os_specific, "CommonWin32", rcpath, NULL);
869 #endif
870
871         g_free(rcpath);
872
873         tmp = g_strdup(gettext(prefs_common.quotefmt));
874         g_free(prefs_common.quotefmt);
875         prefs_common.quotefmt = tmp;
876
877         tmp = g_strdup(gettext(prefs_common.fw_quotefmt));
878         g_free(prefs_common.fw_quotefmt);
879         prefs_common.fw_quotefmt = tmp;
880         
881         tmp = g_strdup(gettext(prefs_common.date_format));
882         g_free(prefs_common.date_format);
883         prefs_common.date_format = tmp;
884
885         prefs_common.mime_open_cmd_history =
886                 prefs_common_read_history(COMMAND_HISTORY);
887         prefs_common.summary_quicksearch_history =
888                 prefs_common_read_history(QUICKSEARCH_HISTORY);
889
890         colorlabel_update_colortable_from_prefs();
891 }
892
893 /*
894  * Save history list to the specified history file
895  */
896 void prefs_common_save_history(const gchar *history, GList *list)
897 {
898         GList *cur;
899         FILE *fp;
900         gchar *path;
901
902         path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, history,
903                            NULL);
904         if ((fp = g_fopen(path, "wb")) == NULL) {
905                 FILE_OP_ERROR(path, "fopen");
906                 g_free(path);
907                 return;
908         }
909
910         for (cur = list; cur != NULL; cur = cur->next) {
911                 fputs((gchar *)cur->data, fp);
912                 fputc('\n', fp);
913         }
914
915         fclose(fp);
916         g_free(path);
917 }
918
919 void prefs_common_write_config(void)
920 {
921         prefs_write_config(param, "Common", COMMON_RC);
922 #ifdef G_OS_WIN32
923         prefs_write_config(param_os_specific, "CommonWin32", COMMON_RC);
924 #endif
925
926         prefs_common_save_history(COMMAND_HISTORY, 
927                 prefs_common.mime_open_cmd_history);
928         prefs_common_save_history(QUICKSEARCH_HISTORY, 
929                 prefs_common.summary_quicksearch_history);
930 }
931
932 /* make a copy of string 'in' into buffer 'out'. un-escape \ sequences.
933    both 'in' and 'out' must be non-NULL.
934    'out' must be a pointer to a buffer whose size is at least equal
935    to strlen(txt)+1, this buffer will get cleared. out's contents
936    will always get set to a valid string, even if it's "".*/
937 void pref_get_unescaped_pref(gchar *out, const gchar *in)
938 {
939         const gchar *i;
940         gchar *o;
941
942         *out = '\0';
943
944         g_return_if_fail( in != NULL );
945         g_return_if_fail( out != NULL );
946
947         i = in;
948         o = out;
949         memset(out, 0, strlen(in)+1);
950         while (*i != '\0') {
951                 if (*i == '\\' && *(i+1) == 'n') {
952                         *o++ = '\n';
953                         i++;
954                 } else if (*i == '\\' && *(i+1) == 't') {
955                         *o++ = '\t';
956                         i++;
957                 } else if (*i == '\\' && *(i+1) == '\\') {
958                         *o++ = '\\';
959                         i++;
960                 } else {
961                         *o++ = *i;
962                 }
963                 i++;
964         }
965         *o='\0';
966 }
967
968 /* make a copy of string 'in' into buffer 'out'. escape \ sequences.
969    both 'in' and 'out' must be non-NULL.
970    'out' must be a pointer to a buffer whose size is at least equal
971    to 2*strlen(txt)+1. out's contents will always get set to a valid
972    string, even if it's "". */
973 void pref_get_escaped_pref(gchar *out, const gchar *in)
974 {
975         const gchar *i;
976         gchar *o;
977
978         *out = '\0';
979
980         g_return_if_fail( in != NULL );
981         g_return_if_fail( out != NULL );
982
983         i = in;
984         o = out;
985         while (*i != '\0') {
986                 if (*i == '\n') {
987                         *o++ = '\\';
988                         *o++ = 'n';
989                 } else if (*i == '\t') {
990                         *o++ = '\\';
991                         *o++ = 't';
992                 } else if (*i == '\\') {
993                         *o++ = '\\';
994                         *o++ = '\\';
995                 } else {
996                         *o++ = *i;
997                 }
998                 i++;
999         }
1000         *o = '\0';
1001 }
1002                 
1003 /* set the contents of a textview widget from the internal \-escaped
1004   representation of a pref string. both txt and textview must be non-NULL. */
1005 void pref_set_textview_from_pref(GtkTextView *textview, const gchar *txt)
1006 {
1007         GtkTextBuffer *buffer;
1008         gchar *out = NULL;
1009
1010         g_return_if_fail( txt != NULL );
1011         g_return_if_fail( textview != NULL );
1012
1013         buffer = gtk_text_view_get_buffer(textview);
1014         out = malloc(strlen(txt)+1);
1015
1016         pref_get_unescaped_pref(out, txt);
1017
1018         gtk_text_buffer_set_text(buffer, out?out:"", -1);
1019         g_free(out);
1020 }
1021
1022 /* set the contents of a gtkentry widget from the internal \-escaped
1023   representation of a pref string. both txt and entry must be non-NULL. */
1024 void pref_set_entry_from_pref(GtkEntry *entry, const gchar *txt)
1025 {
1026         gchar *out = NULL;
1027
1028         g_return_if_fail( txt != NULL );
1029         g_return_if_fail( entry != NULL );
1030
1031         out = malloc(strlen(txt)+1);
1032
1033         pref_get_unescaped_pref(out, txt);
1034
1035         gtk_entry_set_text(entry, out?out:"");
1036         g_free(out);
1037 }
1038
1039 /* get the \-escaped internal representation of a pref from the contents of
1040    a textview widget. textview must be non-NULL. */
1041 gchar *pref_get_pref_from_textview(GtkTextView *textview) 
1042 {
1043         GtkTextBuffer *buffer;
1044         GtkTextIter start, end;
1045         gchar *out, *tmp;
1046         
1047         g_return_val_if_fail( textview != NULL, "" );
1048
1049         buffer = gtk_text_view_get_buffer(textview);
1050         gtk_text_buffer_get_start_iter(buffer, &start);
1051         gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
1052         tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
1053         out = malloc(2*strlen(tmp)+1);
1054         
1055         pref_get_escaped_pref(out, tmp);
1056         g_free(tmp);
1057
1058         return out?out:"";
1059 }
1060
1061 /* get the \-escaped internal representation of a pref from the contents of
1062    a gtkentry widget. entry must be non-NULL. */
1063 gchar *pref_get_pref_from_entry(GtkEntry *entry) 
1064 {
1065         gchar *out, *tmp;
1066
1067         g_return_val_if_fail( entry != NULL, "" );
1068
1069         tmp = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
1070         out = malloc(2*strlen(tmp)+1);
1071
1072         pref_get_escaped_pref(out, tmp);
1073         g_free(tmp);
1074
1075         return out?out:"";
1076 }