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