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