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