b2f5458877dbfa26ba23247ceabe9100eaaf8440
[claws.git] / src / prefs_common.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2005 Hiroyuki Yamamoto
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
62 enum {
63         DATEFMT_FMT,
64         DATEFMT_TXT,
65         N_DATEFMT_COLUMNS
66 };
67
68 PrefsCommon prefs_common;
69
70 GtkWidget *notebook;
71
72 /*
73    parameter name, default value, pointer to the prefs variable, data type,
74    pointer to the widget pointer,
75    pointer to the function for data setting,
76    pointer to the function for widget setting
77  */
78
79 static PrefParam param[] = {
80         /* Receive */
81         {"use_ext_inc", "FALSE", &prefs_common.use_extinc, P_BOOL,
82          NULL, NULL, NULL},
83         {"ext_inc_path", DEFAULT_INC_PATH, &prefs_common.extinc_cmd, P_STRING,
84          NULL, NULL, NULL},
85
86         {"autochk_newmail", "FALSE", &prefs_common.autochk_newmail, P_BOOL,
87          NULL, NULL, NULL},
88         {"autochk_interval", "10", &prefs_common.autochk_itv, P_INT,
89          NULL, NULL, NULL},
90         {"check_on_startup", "FALSE", &prefs_common.chk_on_startup, P_BOOL,
91          NULL, NULL, NULL},
92         {"open_inbox_on_inc", "FALSE", &prefs_common.open_inbox_on_inc,
93          P_BOOL, NULL, NULL, NULL},
94         {"scan_all_after_inc", "FALSE", &prefs_common.scan_all_after_inc,
95          P_BOOL, NULL, NULL, NULL},
96         {"newmail_notify_manu", "FALSE", &prefs_common.newmail_notify_manu,
97          P_BOOL, NULL, NULL, NULL},
98         {"newmail_notify_auto", "FALSE", &prefs_common.newmail_notify_auto,
99         P_BOOL, NULL, NULL, NULL},
100         {"newmail_notify_cmd", "", &prefs_common.newmail_notify_cmd, P_STRING,
101          NULL, NULL, NULL},
102         {"receive_dialog_mode", "1", &prefs_common.recv_dialog_mode, P_ENUM,
103          NULL, NULL, NULL},
104         {"no_receive_error_panel", "FALSE", &prefs_common.no_recv_err_panel,
105          P_BOOL, NULL, NULL, NULL},
106         {"close_receive_dialog", "TRUE", &prefs_common.close_recv_dialog,
107          P_BOOL, NULL, NULL, NULL},
108  
109         /* Send */
110         {"save_message", "TRUE", &prefs_common.savemsg, P_BOOL,
111          NULL, NULL, NULL},
112         {"confirm_send_queued_messages", "FALSE", &prefs_common.confirm_send_queued_messages,
113          P_BOOL, NULL, NULL, NULL},
114         {"send_dialog_mode", "0", &prefs_common.send_dialog_mode, P_ENUM,
115          NULL, NULL, NULL},
116
117         {"outgoing_charset", CS_AUTO, &prefs_common.outgoing_charset, P_STRING,
118          NULL, NULL, NULL},
119         {"encoding_method", "0", &prefs_common.encoding_method, P_ENUM,
120          NULL, NULL, NULL},
121
122         {"allow_jisx0201_kana", "FALSE", &prefs_common.allow_jisx0201_kana,
123          P_BOOL, NULL, NULL, NULL},
124
125         /* Compose */
126         {"auto_ext_editor", "FALSE", &prefs_common.auto_exteditor, P_BOOL,
127          NULL, NULL, NULL},
128         {"forward_as_attachment", "FALSE", &prefs_common.forward_as_attachment,
129          P_BOOL, NULL, NULL, NULL},
130         {"redirect_keep_from", "FALSE",
131          &prefs_common.redirect_keep_from, P_BOOL,
132          NULL, NULL, NULL},
133         {"undo_level", "50", &prefs_common.undolevels, P_INT,
134          NULL, NULL, NULL},
135
136         {"linewrap_length", "72", &prefs_common.linewrap_len, P_INT,
137          NULL, NULL, NULL},
138         {"linewrap_quotation", "TRUE", &prefs_common.linewrap_quote, P_BOOL,
139          NULL, NULL, NULL},
140         {"linewrap_pastes", "TRUE", &prefs_common.linewrap_pastes, P_BOOL,
141          NULL, NULL, NULL},
142         {"linewrap_auto", "TRUE", &prefs_common.autowrap, P_BOOL,
143          NULL, NULL, NULL},
144         {"linewrap_before_sending", "FALSE", &prefs_common.linewrap_at_send, P_BOOL, 
145          NULL, NULL, NULL},
146         {"autosave", "TRUE", &prefs_common.autosave,
147          P_BOOL, NULL, NULL, NULL},
148         {"autosave_length", "50", &prefs_common.autosave_length, P_INT,
149          NULL, NULL, NULL},
150 #if USE_ASPELL
151         {"enable_aspell", "TRUE", &prefs_common.enable_aspell, P_BOOL,
152          NULL, NULL, NULL},
153         {"aspell_path", ASPELL_PATH, &prefs_common.aspell_path, P_STRING,
154          NULL, NULL, NULL},
155         {"dictionary",  "", &prefs_common.dictionary, P_STRING,
156          NULL, NULL, NULL},
157         {"aspell_sugmode", "1", &prefs_common.aspell_sugmode, P_INT,
158          NULL, NULL, NULL},
159         {"use_alternate_dict", "FALSE", &prefs_common.use_alternate, P_BOOL,
160          NULL, NULL, NULL},
161         {"check_while_typing", "TRUE", &prefs_common.check_while_typing, P_BOOL,
162          NULL, NULL, NULL},
163         {"misspelled_color", "16711680", &prefs_common.misspelled_col, P_COLOR,
164          NULL, NULL, NULL},
165 #endif
166         {"reply_with_quote", "TRUE", &prefs_common.reply_with_quote, P_BOOL,
167          NULL, NULL, NULL},
168
169         /* Account autoselection */
170         {"reply_account_autoselect", "TRUE",
171          &prefs_common.reply_account_autosel, P_BOOL,
172          NULL, NULL, NULL},
173         {"forward_account_autoselect", "TRUE",
174          &prefs_common.forward_account_autosel, P_BOOL,
175          NULL, NULL, NULL},
176         {"reedit_account_autoselect", "TRUE",
177          &prefs_common.reedit_account_autosel, P_BOOL,
178          NULL, NULL, NULL},
179
180         {"default_reply_list", "TRUE", &prefs_common.default_reply_list, P_BOOL,
181          NULL, NULL, NULL},
182
183         {"show_ruler", "TRUE", &prefs_common.show_ruler, P_BOOL,
184          NULL, NULL, NULL},
185
186         /* Quote */
187         {"reply_quote_mark", "> ", &prefs_common.quotemark, P_STRING,
188          NULL, NULL, NULL},
189         {"reply_quote_format", N_("On %d\\n%f wrote:\\n\\n%q"),
190          &prefs_common.quotefmt, P_STRING, NULL, NULL, NULL},
191
192         {"forward_quote_mark", "> ", &prefs_common.fw_quotemark, P_STRING,
193          NULL, NULL, NULL},
194         {"forward_quote_format",
195          N_("\\n\\nBegin forwarded message:\\n\\n"
196          "?d{Date: %d\\n}?f{From: %f\\n}?t{To: %t\\n}?c{Cc: %c\\n}"
197          "?n{Newsgroups: %n\\n}?s{Subject: %s\\n}\\n\\n%M"),
198          &prefs_common.fw_quotefmt, P_STRING, NULL, NULL, NULL},
199         {"quote_chars", ">", &prefs_common.quote_chars, P_STRING,
200          NULL, NULL, NULL},
201
202         /* Display */
203         /* Obsolete fonts. For coexisting with Gtk+-1.2 version */
204         {"widget_font",         NULL,
205           &prefs_common.widgetfont_gtk1,        P_STRING, NULL, NULL, NULL},
206         {"message_font",        "-misc-fixed-medium-r-normal--14-*-*-*-*-*-*-*",
207          &prefs_common.textfont_gtk1,           P_STRING, NULL, NULL, NULL},
208         {"small_font",          "-*-helvetica-medium-r-normal--10-*-*-*-*-*-*-*",
209           &prefs_common.smallfont_gtk1,         P_STRING, NULL, NULL, NULL},
210         {"bold_font",           "-*-helvetica-bold-r-normal--12-*-*-*-*-*-*-*",
211           &prefs_common.boldfont_gtk1,          P_STRING, NULL, NULL, NULL},
212         {"normal_font",         "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
213           &prefs_common.normalfont_gtk1,        P_STRING, NULL, NULL, NULL},
214
215         /* new fonts */
216         {"widget_font_gtk2",    NULL,
217           &prefs_common.widgetfont,             P_STRING, NULL, NULL, NULL},
218         {"message_font_gtk2",   "Monospace 9",
219          &prefs_common.textfont,                P_STRING, NULL, NULL, NULL},
220         {"small_font_gtk2",     "Sans 9",
221           &prefs_common.smallfont,              P_STRING, NULL, NULL, NULL},
222         {"normal_font_gtk2",    "Sans 9",
223           &prefs_common.normalfont,             P_STRING, NULL, NULL, NULL},
224
225         /* image viewer */
226         {"display_image", "TRUE", &prefs_common.display_img, P_BOOL,
227          NULL, NULL, NULL},
228         {"resize_image", "TRUE", &prefs_common.resize_img, P_BOOL,
229          NULL, NULL, NULL},
230         {"inline_image", "TRUE", &prefs_common.inline_img, P_BOOL,
231          NULL, NULL, NULL},
232
233         {"display_folder_unread_num", "FALSE",
234          &prefs_common.display_folder_unread, P_BOOL,
235          NULL, NULL, NULL},
236         {"newsgroup_abbrev_len", "16",
237          &prefs_common.ng_abbrev_len, P_INT,
238          NULL, NULL, NULL},
239
240         {"translate_header", "TRUE", &prefs_common.trans_hdr, P_BOOL,
241          NULL, NULL, NULL},
242
243         /* Display: Summary View */
244         {"use_address_book", "FALSE", &prefs_common.use_addr_book, P_BOOL,
245          NULL, NULL, NULL},
246         {"thread_by_subject", "TRUE", &prefs_common.thread_by_subject, P_BOOL,
247          NULL, NULL, NULL},
248         {"date_format", N_("%y/%m/%d(%a) %H:%M"), &prefs_common.date_format,
249          P_STRING, NULL, NULL, NULL},
250
251         {"bold_unread", "TRUE", &prefs_common.bold_unread, P_BOOL,
252          NULL, NULL, NULL},
253
254         {"enable_thread", "TRUE", &prefs_common.enable_thread, P_BOOL,
255          NULL, NULL, NULL},
256         {"toolbar_style", "3", &prefs_common.toolbar_style, P_ENUM,
257          NULL, NULL, NULL},
258         {"toolbar_detachable", "FALSE", &prefs_common.toolbar_detachable, P_BOOL,
259          NULL, NULL, NULL},
260         {"show_statusbar", "TRUE", &prefs_common.show_statusbar, P_BOOL,
261          NULL, NULL, NULL},
262         {"show_searchbar", "TRUE", &prefs_common.show_searchbar, P_BOOL,
263          NULL, NULL, NULL},
264
265
266         {"summary_col_show_mark", "TRUE",
267          &prefs_common.summary_col_visible[S_COL_MARK], P_BOOL, NULL, NULL, NULL},
268         {"summary_col_show_unread", "TRUE",
269          &prefs_common.summary_col_visible[S_COL_STATUS], P_BOOL, NULL, NULL, NULL},
270         {"summary_col_show_mime", "TRUE",
271          &prefs_common.summary_col_visible[S_COL_MIME], P_BOOL, NULL, NULL, NULL},
272         {"summary_col_show_subject", "TRUE",
273          &prefs_common.summary_col_visible[S_COL_SUBJECT], P_BOOL, NULL, NULL, NULL},
274         {"summary_col_show_from", "TRUE",
275          &prefs_common.summary_col_visible[S_COL_FROM], P_BOOL, NULL, NULL, NULL},
276         {"summary_col_show_to", "FALSE",
277          &prefs_common.summary_col_visible[S_COL_TO], P_BOOL, NULL, NULL, NULL},
278         {"summary_col_show_date", "TRUE",
279          &prefs_common.summary_col_visible[S_COL_DATE], P_BOOL, NULL, NULL, NULL},
280         {"summary_col_show_size", "TRUE",
281          &prefs_common.summary_col_visible[S_COL_SIZE], P_BOOL, NULL, NULL, NULL},
282         {"summary_col_show_number", "FALSE",
283          &prefs_common.summary_col_visible[S_COL_NUMBER], P_BOOL, NULL, NULL, NULL},
284         {"summary_col_show_score", "FALSE",
285          &prefs_common.summary_col_visible[S_COL_SCORE], P_BOOL, NULL, NULL, NULL},
286         {"summary_col_show_locked", "FALSE",
287          &prefs_common.summary_col_visible[S_COL_LOCKED], P_BOOL, NULL, NULL, NULL},
288
289         {"summary_col_pos_mark", "0",
290           &prefs_common.summary_col_pos[S_COL_MARK], P_INT, NULL, NULL, NULL},
291         {"summary_col_pos_unread", "1",
292           &prefs_common.summary_col_pos[S_COL_STATUS], P_INT, NULL, NULL, NULL},
293         {"summary_col_pos_mime", "2",
294           &prefs_common.summary_col_pos[S_COL_MIME], P_INT, NULL, NULL, NULL},
295         {"summary_col_pos_subject", "3",
296           &prefs_common.summary_col_pos[S_COL_SUBJECT], P_INT, NULL, NULL, NULL},
297         {"summary_col_pos_from", "4",
298           &prefs_common.summary_col_pos[S_COL_FROM], P_INT, NULL, NULL, NULL},
299         {"summary_col_pos_date", "5",
300           &prefs_common.summary_col_pos[S_COL_DATE], P_INT, NULL, NULL, NULL},
301         {"summary_col_pos_size", "6",
302           &prefs_common.summary_col_pos[S_COL_SIZE], P_INT, NULL, NULL, NULL},
303         {"summary_col_pos_number", "7",
304           &prefs_common.summary_col_pos[S_COL_NUMBER], P_INT, NULL, NULL, NULL},
305         {"summary_col_pos_score", "8",
306          &prefs_common.summary_col_pos[S_COL_SCORE], P_INT, NULL, NULL, NULL},
307         {"summary_col_pos_locked", "9",
308          &prefs_common.summary_col_pos[S_COL_LOCKED], P_INT, NULL, NULL, NULL},
309         {"summary_col_pos_to", "10",
310           &prefs_common.summary_col_pos[S_COL_TO], P_INT, NULL, NULL, NULL},
311
312         {"summary_col_size_mark", "10",
313          &prefs_common.summary_col_size[S_COL_MARK], P_INT, NULL, NULL, NULL},
314         {"summary_col_size_unread", "13",
315          &prefs_common.summary_col_size[S_COL_STATUS], P_INT, NULL, NULL, NULL},
316         {"summary_col_size_mime", "10",
317          &prefs_common.summary_col_size[S_COL_MIME], P_INT, NULL, NULL, NULL},
318         {"summary_col_size_subject", "200",
319          &prefs_common.summary_col_size[S_COL_SUBJECT], P_INT, NULL, NULL, NULL},
320         {"summary_col_size_from", "120",
321          &prefs_common.summary_col_size[S_COL_FROM], P_INT, NULL, NULL, NULL},
322         {"summary_col_size_to", "120",
323          &prefs_common.summary_col_size[S_COL_TO], P_INT, NULL, NULL, NULL},
324         {"summary_col_size_date", "118",
325          &prefs_common.summary_col_size[S_COL_DATE], P_INT, NULL, NULL, NULL},
326         {"summary_col_size_size", "45",
327          &prefs_common.summary_col_size[S_COL_SIZE], P_INT, NULL, NULL, NULL},
328         {"summary_col_size_number", "40",
329          &prefs_common.summary_col_size[S_COL_NUMBER], P_INT, NULL, NULL, NULL},
330         {"summary_col_size_score", "40",
331          &prefs_common.summary_col_size[S_COL_SCORE], P_INT, NULL, NULL, NULL},
332         {"summary_col_size_locked", "13",
333          &prefs_common.summary_col_size[S_COL_LOCKED], P_INT, NULL, NULL, NULL},
334
335         /* Widget size */
336         {"folderwin_x", "16", &prefs_common.folderwin_x, P_INT,
337          NULL, NULL, NULL},
338         {"folderwin_y", "16", &prefs_common.folderwin_y, P_INT,
339          NULL, NULL, NULL},
340         {"folderview_width", "270", &prefs_common.folderview_width, P_INT,
341          NULL, NULL, NULL},
342         {"folderview_height", "450", &prefs_common.folderview_height, P_INT,
343          NULL, NULL, NULL},
344         {"folderview_visible", "TRUE", &prefs_common.folderview_visible, P_BOOL,
345          NULL, NULL, NULL},
346
347         {"folder_col_show_folder", "TRUE",
348          &prefs_common.folder_col_visible[F_COL_FOLDER], P_BOOL, NULL, NULL, NULL},
349         {"folder_col_show_new", "TRUE",
350          &prefs_common.folder_col_visible[F_COL_NEW], P_BOOL, NULL, NULL, NULL},
351         {"folder_col_show_unread", "TRUE",
352          &prefs_common.folder_col_visible[F_COL_UNREAD], P_BOOL, NULL, NULL, NULL},
353         {"folder_col_show_total", "TRUE",
354          &prefs_common.folder_col_visible[F_COL_TOTAL], P_BOOL, NULL, NULL, NULL},
355
356         {"folder_col_pos_folder", "0",
357          &prefs_common.folder_col_pos[F_COL_FOLDER], P_INT, NULL, NULL, NULL},
358         {"folder_col_pos_new", "1",
359          &prefs_common.folder_col_pos[F_COL_NEW], P_INT, NULL, NULL, NULL},
360         {"folder_col_pos_unread", "2",
361          &prefs_common.folder_col_pos[F_COL_UNREAD], P_INT, NULL, NULL, NULL},
362         {"folder_col_pos_total", "3",
363          &prefs_common.folder_col_pos[F_COL_TOTAL], P_INT, NULL, NULL, NULL},
364
365         {"folder_col_size_folder", "120",
366          &prefs_common.folder_col_size[F_COL_FOLDER], P_INT, NULL, NULL, NULL},
367         {"folder_col_size_new", "32",
368          &prefs_common.folder_col_size[F_COL_NEW], P_INT, NULL, NULL, NULL},
369         {"folder_col_size_unread", "32",
370          &prefs_common.folder_col_size[F_COL_UNREAD], P_INT, NULL, NULL, NULL},
371         {"folder_col_size_total", "32",
372          &prefs_common.folder_col_size[F_COL_TOTAL], P_INT, NULL, NULL, NULL},
373
374         {"summaryview_width", "500", &prefs_common.summaryview_width, P_INT,
375          NULL, NULL, NULL},
376         {"summaryview_height", "244", &prefs_common.summaryview_height, P_INT,
377          NULL, NULL, NULL},
378
379         {"main_messagewin_x", "256", &prefs_common.main_msgwin_x, P_INT,
380          NULL, NULL, NULL},
381         {"main_messagewin_y", "210", &prefs_common.main_msgwin_y, P_INT,
382          NULL, NULL, NULL},
383         {"messageview_width", "500", &prefs_common.msgview_width, P_INT,
384          NULL, NULL, NULL},
385         {"messageview_height", "213", &prefs_common.msgview_height, P_INT,
386          NULL, NULL, NULL},
387         {"messageview_visible", "TRUE", &prefs_common.msgview_visible, P_BOOL,
388          NULL, NULL, NULL},
389
390         {"mainview_x", "64", &prefs_common.mainview_x, P_INT,
391          NULL, NULL, NULL},
392         {"mainview_y", "64", &prefs_common.mainview_y, P_INT,
393          NULL, NULL, NULL},
394         {"mainview_width", "500", &prefs_common.mainview_width, P_INT,
395          NULL, NULL, NULL},
396         {"mainview_height", "400", &prefs_common.mainview_height, P_INT,
397          NULL, NULL, NULL},
398         {"mainwin_x", "64", &prefs_common.mainwin_x, P_INT,
399          NULL, NULL, NULL},
400         {"mainwin_y", "64", &prefs_common.mainwin_y, P_INT,
401          NULL, NULL, NULL},
402         {"mainwin_width", "800", &prefs_common.mainwin_width, P_INT,
403          NULL, NULL, NULL},
404         {"mainwin_height", "600", &prefs_common.mainwin_height, P_INT,
405          NULL, NULL, NULL},
406         {"messagewin_width", "600", &prefs_common.msgwin_width, P_INT,
407          NULL, NULL, NULL},
408         {"messagewin_height", "540", &prefs_common.msgwin_height, P_INT,
409          NULL, NULL, NULL},
410         {"sourcewin_width", "600", &prefs_common.sourcewin_width, P_INT,
411          NULL, NULL, NULL},
412         {"sourcewin_height", "500", &prefs_common.sourcewin_height, P_INT,
413          NULL, NULL, NULL},
414         {"compose_width", "600", &prefs_common.compose_width, P_INT,
415          NULL, NULL, NULL},
416         {"compose_height", "560", &prefs_common.compose_height, P_INT,
417          NULL, NULL, NULL},
418         {"compose_x", "0", &prefs_common.compose_x, P_INT,
419          NULL, NULL, NULL},
420         {"compose_y", "0", &prefs_common.compose_y, P_INT,
421          NULL, NULL, NULL},
422         /* Message */
423         {"enable_color", "TRUE", &prefs_common.enable_color, P_BOOL,
424          NULL, NULL, NULL},
425
426         {"quote_level1_color", "179", &prefs_common.quote_level1_col, P_COLOR,
427          NULL, NULL, NULL},
428         {"quote_level2_color", "179", &prefs_common.quote_level2_col, P_COLOR,
429          NULL, NULL, NULL},
430         {"quote_level3_color", "179", &prefs_common.quote_level3_col, P_COLOR,
431          NULL, NULL, NULL},
432         {"uri_color", "32512", &prefs_common.uri_col, P_COLOR,
433          NULL, NULL, NULL},
434         {"target_folder_color", "14294218", &prefs_common.tgt_folder_col, P_COLOR,
435          NULL, NULL, NULL},
436         {"signature_color", "7960953", &prefs_common.signature_col, P_COLOR,
437          NULL, NULL, NULL},
438         {"recycle_quote_colors", "FALSE", &prefs_common.recycle_quote_colors,
439          P_BOOL, NULL, NULL, NULL},
440
441         {"display_header_pane", "FALSE", &prefs_common.display_header_pane,
442          P_BOOL, NULL, NULL, NULL},
443         {"display_header", "TRUE", &prefs_common.display_header, P_BOOL,
444          NULL, NULL, NULL},
445         {"display_xface", "TRUE", &prefs_common.display_xface,
446          P_BOOL, NULL, NULL, NULL},
447         {"render_html", "TRUE", &prefs_common.render_html, P_BOOL,
448          NULL, NULL, NULL},
449         {"line_space", "2", &prefs_common.line_space, P_INT,
450          NULL, NULL, NULL},
451
452         {"enable_smooth_scroll", "FALSE",
453          &prefs_common.enable_smooth_scroll, P_BOOL,
454          NULL, NULL, NULL},
455         {"scroll_step", "1", &prefs_common.scroll_step, P_INT,
456          NULL, NULL, NULL},
457         {"scroll_half_page", "FALSE", &prefs_common.scroll_halfpage, P_BOOL,
458          NULL, NULL, NULL},
459
460         {"show_other_header", "FALSE", &prefs_common.show_other_header, P_BOOL,
461          NULL, NULL, NULL},
462
463         {"attach_desc", "TRUE", &prefs_common.attach_desc, P_BOOL,
464          NULL, NULL, NULL},
465         {"attach_save_directory", NULL,
466          &prefs_common.attach_save_dir, P_STRING, NULL, NULL, NULL},
467         {"attach_load_directory", NULL,
468          &prefs_common.attach_load_dir, P_STRING, NULL, NULL, NULL},
469
470         /* MIME viewer */
471         {"mime_image_viewer", DEFAULT_IMAGE_VIEWER_CMD,
472          &prefs_common.mime_image_viewer, P_STRING, NULL, NULL, NULL},
473         {"mime_audio_player", DEFAULT_AUDIO_PLAYER_CMD,
474          &prefs_common.mime_audio_player, P_STRING, NULL, NULL, NULL},
475         {"mime_open_command", "gedit '%s'",
476          &prefs_common.mime_open_cmd, P_STRING, NULL, NULL, NULL},
477
478         /* Interface */
479         {"separate_folder", "FALSE", &prefs_common.sep_folder, P_BOOL,
480          NULL, NULL, NULL},
481         {"separate_message", "FALSE", &prefs_common.sep_msg, P_BOOL,
482          NULL, NULL, NULL},
483
484         /* {"emulate_emacs", "FALSE", &prefs_common.emulate_emacs, P_BOOL,
485          NULL, NULL, NULL}, */
486         {"always_show_message_when_selected", "FALSE",
487          &prefs_common.always_show_msg,
488          P_BOOL, NULL, NULL, NULL},
489         {"select_on_entry", "2", &prefs_common.select_on_entry,
490          P_ENUM, NULL, NULL, NULL},
491         {"mark_as_read_on_new_window", "FALSE",
492          &prefs_common.mark_as_read_on_new_window,
493          P_BOOL, NULL, NULL, NULL},
494         {"mark_as_read_delay", "0",
495          &prefs_common.mark_as_read_delay, P_INT, 
496          NULL, NULL, NULL},
497         {"immediate_execution", "TRUE", &prefs_common.immediate_exec, P_BOOL,
498          NULL, NULL, NULL},
499         {"nextunreadmsg_dialog", "1", &prefs_common.next_unread_msg_dialog, P_ENUM,
500          NULL, NULL, NULL},
501
502         {"pixmap_theme_path", DEFAULT_PIXMAP_THEME, 
503          &prefs_common.pixmap_theme_path, P_STRING,
504          NULL, NULL, NULL},
505
506         {"ask_mark_all_read", "TRUE", &prefs_common.ask_mark_all_read, P_BOOL,
507          NULL, NULL, NULL},
508
509         /* Other */
510         {"uri_open_command", DEFAULT_BROWSER_CMD,
511          &prefs_common.uri_cmd, P_STRING, NULL, NULL, NULL},
512         {"print_command", "lpr %s", &prefs_common.print_cmd, P_STRING,
513          NULL, NULL, NULL},
514         {"ext_editor_command", "gedit %s",
515          &prefs_common.ext_editor_cmd, P_STRING, NULL, NULL, NULL},
516
517         {"add_address_by_click", "FALSE", &prefs_common.add_address_by_click,
518          P_BOOL, NULL, NULL, NULL},
519         {"confirm_on_exit", "FALSE", &prefs_common.confirm_on_exit, P_BOOL,
520          NULL, NULL, NULL},
521         {"clean_trash_on_exit", "FALSE", &prefs_common.clean_on_exit, P_BOOL,
522          NULL, NULL, NULL},
523         {"ask_on_cleaning", "TRUE", &prefs_common.ask_on_clean, P_BOOL,
524          NULL, NULL, NULL},
525         {"warn_queued_on_exit", "TRUE", &prefs_common.warn_queued_on_exit,
526          P_BOOL, NULL, NULL, NULL},
527         {"work_offline", "FALSE", &prefs_common.work_offline, P_BOOL,
528          NULL, NULL, NULL},
529         {"summary_quicksearch_type", "0", &prefs_common.summary_quicksearch_type, P_INT,
530          NULL, NULL, NULL},
531         {"summary_quicksearch_recurse", "1", &prefs_common.summary_quicksearch_recurse, P_INT,
532          NULL, NULL, NULL},
533
534         {"io_timeout_secs", "60", &prefs_common.io_timeout_secs,
535          P_INT, NULL, NULL, NULL},
536         {"hide_score", "-9999", &prefs_common.kill_score, P_INT,
537          NULL, NULL, NULL},
538         {"important_score", "1", &prefs_common.important_score, P_INT,
539          NULL, NULL, NULL},
540         {"clip_log", "TRUE", &prefs_common.cliplog, P_BOOL,
541          NULL, NULL, NULL},
542         {"log_length", "500", &prefs_common.loglength, P_INT,
543          NULL, NULL, NULL},
544
545         {"color_new", "179", &prefs_common.color_new, P_COLOR,
546          NULL, NULL, NULL},
547
548         /* Some windows' sizes */
549         {"filteringwin_width", "500", &prefs_common.filteringwin_width, P_INT,
550          NULL, NULL, NULL},
551         {"filteringwin_height", "-1", &prefs_common.filteringwin_height, P_INT,
552          NULL, NULL, NULL},
553
554         {"filteringactionwin_width", "490", &prefs_common.filteringactionwin_width, P_INT,
555          NULL, NULL, NULL},
556         {"filteringactionwin_height", "-1", &prefs_common.filteringactionwin_height, P_INT,
557          NULL, NULL, NULL},
558
559         {"matcherwin_width", "520", &prefs_common.matcherwin_width, P_INT,
560          NULL, NULL, NULL},
561         {"matcherwin_height", "-1", &prefs_common.matcherwin_height, P_INT,
562          NULL, NULL, NULL},
563
564         {"templateswin_width", "440", &prefs_common.templateswin_width, P_INT,
565          NULL, NULL, NULL},
566         {"templateswin_height", "-1", &prefs_common.templateswin_height, P_INT,
567          NULL, NULL, NULL},
568
569         {"actionswin_width", "486", &prefs_common.actionswin_width, P_INT,
570          NULL, NULL, NULL},
571         {"actionswin_height", "-1", &prefs_common.actionswin_height, P_INT,
572          NULL, NULL, NULL},
573
574         {"addressbookwin_width", "520", &prefs_common.addressbookwin_width, P_INT,
575          NULL, NULL, NULL},
576         {"addressbookwin_height", "-1", &prefs_common.addressbookwin_height, P_INT,
577          NULL, NULL, NULL},
578
579         {"addressbookeditpersonwin_width", "640", &prefs_common.addressbookeditpersonwin_width, P_INT,
580          NULL, NULL, NULL},
581         {"addressbookeditpersonwin_height", "-1", &prefs_common.addressbookeditpersonwin_height, P_INT,
582          NULL, NULL, NULL},
583
584         {"pluginswin_width", "480", &prefs_common.pluginswin_width, P_INT,
585          NULL, NULL, NULL},
586         {"pluginswin_height", "-1", &prefs_common.pluginswin_height, P_INT,
587          NULL, NULL, NULL},
588
589         {"prefswin_width", "600", &prefs_common.prefswin_width, P_INT,
590          NULL, NULL, NULL},
591         {"prefswin_height", "-1", &prefs_common.prefswin_height, P_INT,
592          NULL, NULL, NULL},
593
594         {"folderitemwin_width", "500", &prefs_common.folderitemwin_width, P_INT,
595          NULL, NULL, NULL},
596         {"folderitemwin_height", "-1", &prefs_common.folderitemwin_height, P_INT,
597          NULL, NULL, NULL},
598
599         {"editaccountwin_width", "500", &prefs_common.editaccountwin_width, P_INT,
600          NULL, NULL, NULL},
601         {"editaccountwin_height", "-1", &prefs_common.editaccountwin_height, P_INT,
602          NULL, NULL, NULL},
603
604         {"accountswin_width", "500", &prefs_common.accountswin_width, P_INT,
605          NULL, NULL, NULL},
606         {"accountswin_height", "-1", &prefs_common.accountswin_height, P_INT,
607          NULL, NULL, NULL},
608
609         {"logwin_width", "520", &prefs_common.logwin_width, P_INT,
610          NULL, NULL, NULL},
611         {"logwin_height", "-1", &prefs_common.logwin_height, P_INT,
612          NULL, NULL, NULL},
613
614         /* Hidden */
615         {"warn_dnd", "1", &prefs_common.warn_dnd, P_INT,
616          NULL, NULL, NULL},
617         {"utf8_instead_of_locale_for_broken_mail", "0", 
618          &prefs_common.broken_are_utf8, P_INT,
619          NULL, NULL, NULL},
620         {"enable_swap_from", "FALSE", &prefs_common.swap_from, P_BOOL,
621          NULL, NULL, NULL},
622         {"enable_rules_hint", "TRUE", &prefs_common.enable_rules_hint, P_BOOL,
623          NULL, NULL, NULL},
624         {"enable_hscrollbar", "TRUE", &prefs_common.enable_hscrollbar, P_BOOL,
625          NULL, NULL, NULL},
626         {"folderview_vscrollbar_policy", "0",
627          &prefs_common.folderview_vscrollbar_policy, P_ENUM,
628          NULL, NULL, NULL},
629         {"textview_cursor_visible", "FALSE",
630          &prefs_common.textview_cursor_visible, P_BOOL,
631          NULL, NULL, NULL},
632         {"hover_timeout", "500", &prefs_common.hover_timeout, P_INT,
633          NULL, NULL, NULL},
634         {"cache_max_mem_usage", "4096", &prefs_common.cache_max_mem_usage, P_INT,
635          NULL, NULL, NULL},
636         {"cache_min_keep_time", "15", &prefs_common.cache_min_keep_time, P_INT,
637          NULL, NULL, NULL},
638         {"thread_by_subject_max_age", "10", &prefs_common.thread_by_subject_max_age,
639         P_INT, NULL, NULL, NULL },
640         {"summary_quicksearch_sticky", "1", &prefs_common.summary_quicksearch_sticky, P_INT,
641          NULL, NULL, NULL},
642         {"statusbar_update_step", "10", &prefs_common.statusbar_update_step, P_INT,
643          NULL, NULL, NULL},
644
645         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
646 };
647
648 PrefsCommon *prefs_common_get(void)
649 {
650         return &prefs_common;
651 }
652
653 /*
654  * Read history list from the specified history file
655  */
656 GList *prefs_common_read_history(const gchar *history) 
657 {
658         FILE *fp;
659         gchar *path;
660         gchar buf[PREFSBUFSIZE];
661         GList *tmp = NULL;
662
663         path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, history,
664                            NULL);
665         if ((fp = g_fopen(path, "rb")) == NULL) {
666                 if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
667                 g_free(path);
668                 return NULL;
669         }
670         g_free(path);
671         while (fgets(buf, sizeof(buf), fp) != NULL) {
672                 g_strstrip(buf);
673                 if (buf[0] == '\0') continue;
674                 tmp = add_history(tmp, buf);
675         }
676         fclose(fp);
677
678         tmp = g_list_reverse(tmp);
679
680         return tmp;
681 }
682
683 void prefs_common_read_config(void)
684 {
685         gchar *rcpath;
686
687         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
688         prefs_read_config(param, "Common", rcpath, NULL);
689         g_free(rcpath);
690
691         prefs_common.quotefmt = gettext(prefs_common.quotefmt);
692         prefs_common.fw_quotefmt = gettext(prefs_common.fw_quotefmt);
693         prefs_common.date_format = gettext(prefs_common.date_format);
694
695         prefs_common.mime_open_cmd_history =
696                 prefs_common_read_history(COMMAND_HISTORY);
697         prefs_common.summary_quicksearch_history =
698                 prefs_common_read_history(QUICKSEARCH_HISTORY);
699 }
700
701 /*
702  * Save history list to the specified history file
703  */
704 void prefs_common_save_history(const gchar *history, GList *list)
705 {
706         GList *cur;
707         FILE *fp;
708         gchar *path;
709
710         path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, history,
711                            NULL);
712         if ((fp = g_fopen(path, "wb")) == NULL) {
713                 FILE_OP_ERROR(path, "fopen");
714                 g_free(path);
715                 return;
716         }
717
718         for (cur = list; cur != NULL; cur = cur->next) {
719                 fputs((gchar *)cur->data, fp);
720                 fputc('\n', fp);
721         }
722
723         fclose(fp);
724         g_free(path);
725 }
726
727 void prefs_common_write_config(void)
728 {
729         prefs_write_config(param, "Common", COMMON_RC);
730
731         prefs_common_save_history(COMMAND_HISTORY, 
732                 prefs_common.mime_open_cmd_history);
733         prefs_common_save_history(QUICKSEARCH_HISTORY, 
734                 prefs_common.summary_quicksearch_history);
735 }
736
737 void pref_set_textview_from_pref(GtkTextView *textview, gchar *txt)
738 {
739         GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
740         gchar *o_out, *out = malloc(txt?(strlen(txt)+1):1);
741         gchar *t = txt;
742         memset(out, 0, strlen(txt)+1);
743         o_out = out;
744         while (*t != '\0') {
745                 if (*t == '\\' && *(t+1) == 'n') {
746                         *out++ = '\n';
747                         t++;
748                 } else if (*t == '\\') {
749                         t++;
750                 } else {
751                         *out++ = *t;
752                 }
753                 t++;
754         }
755         *out='\0';
756
757         gtk_text_buffer_set_text(buffer, o_out?o_out:"", -1);
758         g_free(o_out);
759 }
760
761 gchar *pref_get_pref_from_textview(GtkTextView *textview) 
762 {
763         GtkTextBuffer *buffer;
764         GtkTextIter start, end;
765         gchar *o_out, *out, *tmp, *t;
766         
767         buffer = gtk_text_view_get_buffer(textview);
768         gtk_text_buffer_get_start_iter(buffer, &start);
769         gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
770         tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
771         t = tmp;
772         o_out = out = malloc(2*strlen(tmp)+1);
773         
774         while (*t != '\0') {
775                 if (*t == '\n') {
776                         *out++ = '\\';
777                         *out++ = 'n';
778                 } else if (*t == '\\') {
779                         *out++ = '\\';
780                         *out++ = '\\';
781                 } else {
782                         *out++ = *t;
783                 }
784                 t++;
785         }
786         *out = '\0';
787         g_free(tmp);
788
789         return o_out;
790 }