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