2005-05-31 [paul] 1.9.11cvs26
[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 static struct Receive {
71         GtkWidget *checkbtn_incext;
72         GtkWidget *entry_incext;
73         GtkWidget *button_incext;
74
75         GtkWidget *checkbtn_autochk;
76         GtkWidget *spinbtn_autochk;
77         GtkObject *spinbtn_autochk_adj;
78
79         GtkWidget *checkbtn_chkonstartup;
80         GtkWidget *checkbtn_scan_after_inc;
81
82
83         GtkWidget *checkbtn_newmail_auto;
84         GtkWidget *checkbtn_newmail_manu;
85         GtkWidget *entry_newmail_notify_cmd;
86         GtkWidget *hbox_newmail_notify;
87         GtkWidget *optmenu_recvdialog;
88         GtkWidget *checkbtn_no_recv_err_panel;
89         GtkWidget *checkbtn_close_recv_dialog;
90 } receive;
91
92 static struct Send {
93         GtkWidget *checkbtn_savemsg;
94         GtkWidget *optmenu_senddialog;
95
96         GtkWidget *optmenu_charset;
97         GtkWidget *optmenu_encoding_method;
98 } p_send;
99
100 static struct Display {
101         GtkWidget *chkbtn_folder_unread;
102         GtkWidget *entry_ng_abbrev_len;
103         GtkWidget *spinbtn_ng_abbrev_len;
104         GtkObject *spinbtn_ng_abbrev_len_adj;
105
106         GtkWidget *chkbtn_transhdr;
107
108         GtkWidget *chkbtn_swapfrom;
109         GtkWidget *chkbtn_useaddrbook;
110         GtkWidget *chkbtn_threadsubj;
111         GtkWidget *entry_datefmt;
112 } display;
113
114 static struct Message {
115         GtkWidget *chkbtn_mbalnum;
116         GtkWidget *chkbtn_disphdrpane;
117         GtkWidget *chkbtn_disphdr;
118         GtkWidget *chkbtn_html;
119         GtkWidget *chkbtn_cursor;
120         GtkWidget *spinbtn_linespc;
121         GtkObject *spinbtn_linespc_adj;
122
123         GtkWidget *chkbtn_smoothscroll;
124         GtkWidget *spinbtn_scrollstep;
125         GtkObject *spinbtn_scrollstep_adj;
126         GtkWidget *chkbtn_halfpage;
127
128         GtkWidget *chkbtn_attach_desc;
129 } message;
130
131 static struct Interface {
132         /* GtkWidget *checkbtn_emacs; */
133         GtkWidget *checkbtn_always_show_msg;
134         GtkWidget *checkbtn_openunread;
135         GtkWidget *checkbtn_mark_as_read_on_newwin;
136         GtkWidget *checkbtn_openinbox;
137         GtkWidget *checkbtn_immedexec;
138         GtkWidget *optmenu_nextunreadmsgdialog;
139 } interface;
140
141 static struct Other {
142         GtkWidget *checkbtn_addaddrbyclick;
143         GtkWidget *checkbtn_confonexit;
144         GtkWidget *checkbtn_cleanonexit;
145         GtkWidget *checkbtn_askonclean;
146         GtkWidget *checkbtn_warnqueued;
147         GtkWidget *checkbtn_cliplog;
148         GtkWidget *loglength_entry;
149 #if 0
150 #ifdef USE_OPENSSL
151         GtkWidget *checkbtn_ssl_ask_unknown_valid;
152 #endif
153 #endif
154
155         GtkWidget *spinbtn_iotimeout;
156         GtkObject *spinbtn_iotimeout_adj;
157 } other;
158
159 static struct KeybindDialog {
160         GtkWidget *window;
161         GtkWidget *combo;
162 } keybind;
163
164 static void prefs_common_charset_set_data_from_optmenu     (PrefParam *pparam);
165 static void prefs_common_charset_set_optmenu               (PrefParam *pparam);
166 static void prefs_common_encoding_set_data_from_optmenu    (PrefParam *pparam);
167 static void prefs_common_encoding_set_optmenu              (PrefParam *pparam);
168 static void prefs_common_recv_dialog_set_data_from_optmenu (PrefParam *pparam);
169 static void prefs_common_recv_dialog_set_optmenu           (PrefParam *pparam);
170 static void prefs_common_recv_dialog_newmail_notify_toggle_cb   (GtkWidget *w,
171                                                                  gpointer data);
172 static void prefs_common_recv_dialog_set_data_from_optmenu(PrefParam *pparam);
173 static void prefs_common_recv_dialog_set_optmenu(PrefParam *pparam);
174 static void prefs_common_send_dialog_set_data_from_optmenu(PrefParam *pparam);
175 static void prefs_common_send_dialog_set_optmenu(PrefParam *pparam);
176 static void prefs_nextunreadmsgdialog_set_data_from_optmenu(PrefParam *pparam);
177 static void prefs_nextunreadmsgdialog_set_optmenu(PrefParam *pparam);
178
179 /*
180    parameter name, default value, pointer to the prefs variable, data type,
181    pointer to the widget pointer,
182    pointer to the function for data setting,
183    pointer to the function for widget setting
184  */
185
186 static PrefParam param[] = {
187         /* Receive */
188         {"use_ext_inc", "FALSE", &prefs_common.use_extinc, P_BOOL,
189          &receive.checkbtn_incext,
190          prefs_set_data_from_toggle, prefs_set_toggle},
191         {"ext_inc_path", DEFAULT_INC_PATH, &prefs_common.extinc_cmd, P_STRING,
192          &receive.entry_incext,
193          prefs_set_data_from_entry, prefs_set_entry},
194
195         {"autochk_newmail", "FALSE", &prefs_common.autochk_newmail, P_BOOL,
196          &receive.checkbtn_autochk,
197          prefs_set_data_from_toggle, prefs_set_toggle},
198         {"autochk_interval", "10", &prefs_common.autochk_itv, P_INT,
199          &receive.spinbtn_autochk,
200          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
201         {"check_on_startup", "FALSE", &prefs_common.chk_on_startup, P_BOOL,
202          &receive.checkbtn_chkonstartup,
203          prefs_set_data_from_toggle, prefs_set_toggle},
204         {"scan_all_after_inc", "FALSE", &prefs_common.scan_all_after_inc,
205          P_BOOL, &receive.checkbtn_scan_after_inc,
206          prefs_set_data_from_toggle, prefs_set_toggle},
207         {"newmail_notify_manu", "FALSE", &prefs_common.newmail_notify_manu,
208          P_BOOL, &receive.checkbtn_newmail_manu,
209          prefs_set_data_from_toggle, prefs_set_toggle},
210         {"newmail_notify_auto", "FALSE", &prefs_common.newmail_notify_auto,
211         P_BOOL, &receive.checkbtn_newmail_auto,
212          prefs_set_data_from_toggle, prefs_set_toggle},
213         {"newmail_notify_cmd", "", &prefs_common.newmail_notify_cmd, P_STRING,
214          &receive.entry_newmail_notify_cmd,
215          prefs_set_data_from_entry, prefs_set_entry},
216         {"receive_dialog_mode", "1", &prefs_common.recv_dialog_mode, P_ENUM,
217          &receive.optmenu_recvdialog,
218          prefs_common_recv_dialog_set_data_from_optmenu,
219          prefs_common_recv_dialog_set_optmenu},
220         {"no_receive_error_panel", "FALSE", &prefs_common.no_recv_err_panel,
221          P_BOOL, &receive.checkbtn_no_recv_err_panel,
222          prefs_set_data_from_toggle, prefs_set_toggle},
223         {"close_receive_dialog", "TRUE", &prefs_common.close_recv_dialog,
224          P_BOOL, &receive.checkbtn_close_recv_dialog,
225          prefs_set_data_from_toggle, prefs_set_toggle},
226  
227         /* Send */
228         {"save_message", "TRUE", &prefs_common.savemsg, P_BOOL,
229          &p_send.checkbtn_savemsg,
230          prefs_set_data_from_toggle, prefs_set_toggle},
231         {"send_dialog_mode", "0", &prefs_common.send_dialog_mode, P_ENUM,
232          &p_send.optmenu_senddialog,
233          prefs_common_send_dialog_set_data_from_optmenu,
234          prefs_common_send_dialog_set_optmenu},
235
236         {"outgoing_charset", CS_AUTO, &prefs_common.outgoing_charset, P_STRING,
237          &p_send.optmenu_charset,
238          prefs_common_charset_set_data_from_optmenu,
239          prefs_common_charset_set_optmenu},
240         {"encoding_method", "0", &prefs_common.encoding_method, P_ENUM,
241          &p_send.optmenu_encoding_method,
242          prefs_common_encoding_set_data_from_optmenu,
243          prefs_common_encoding_set_optmenu},
244
245         {"allow_jisx0201_kana", "FALSE", &prefs_common.allow_jisx0201_kana,
246          P_BOOL, NULL, NULL, NULL},
247
248         /* Compose */
249         {"auto_ext_editor", "FALSE", &prefs_common.auto_exteditor, P_BOOL,
250          NULL, NULL, NULL},
251         {"forward_as_attachment", "FALSE", &prefs_common.forward_as_attachment,
252          P_BOOL, NULL, NULL, NULL},
253         {"redirect_keep_from", "FALSE",
254          &prefs_common.redirect_keep_from, P_BOOL,
255          NULL, NULL, NULL},
256         {"undo_level", "50", &prefs_common.undolevels, P_INT,
257          NULL, NULL, NULL},
258
259         {"linewrap_length", "72", &prefs_common.linewrap_len, P_INT,
260          NULL, NULL, NULL},
261         {"linewrap_quotation", "TRUE", &prefs_common.linewrap_quote, P_BOOL,
262          NULL, NULL, NULL},
263         {"linewrap_auto", "TRUE", &prefs_common.autowrap, P_BOOL,
264          NULL, NULL, NULL},
265         {"linewrap_before_sending", "FALSE", &prefs_common.linewrap_at_send, P_BOOL, 
266          NULL, NULL, NULL},
267         {"autosave", "FALSE", &prefs_common.autosave,
268          P_BOOL, NULL, NULL, NULL},
269         {"autosave_length", "50", &prefs_common.autosave_length, P_INT,
270          NULL, NULL, NULL},
271 #if USE_ASPELL
272         {"enable_aspell", "TRUE", &prefs_common.enable_aspell, P_BOOL,
273          NULL, NULL, NULL},
274         {"aspell_path", ASPELL_PATH, &prefs_common.aspell_path, P_STRING,
275          NULL, NULL, NULL},
276         {"dictionary",  "", &prefs_common.dictionary, P_STRING,
277          NULL, NULL, NULL},
278         {"aspell_sugmode", "1", &prefs_common.aspell_sugmode, P_INT,
279          NULL, NULL, NULL},
280         {"use_alternate_dict", "FALSE", &prefs_common.use_alternate, P_BOOL,
281          NULL, NULL, NULL},
282         {"check_while_typing", "TRUE", &prefs_common.check_while_typing, P_BOOL,
283          NULL, NULL, NULL},
284         {"misspelled_color", "16711680", &prefs_common.misspelled_col, P_COLOR,
285          NULL, NULL, NULL},
286 #endif
287         {"reply_with_quote", "TRUE", &prefs_common.reply_with_quote, P_BOOL,
288          NULL, NULL, NULL},
289
290         /* Account autoselection */
291         {"reply_account_autoselect", "TRUE",
292          &prefs_common.reply_account_autosel, P_BOOL,
293          NULL, NULL, NULL},
294         {"forward_account_autoselect", "TRUE",
295          &prefs_common.forward_account_autosel, P_BOOL,
296          NULL, NULL, NULL},
297         {"reedit_account_autoselect", "TRUE",
298          &prefs_common.reedit_account_autosel, P_BOOL,
299          NULL, NULL, NULL},
300
301         {"default_reply_list", "TRUE", &prefs_common.default_reply_list, P_BOOL,
302          NULL, NULL, NULL},
303
304         {"show_ruler", "TRUE", &prefs_common.show_ruler, P_BOOL,
305          NULL, NULL, NULL},
306
307         /* Quote */
308         {"reply_quote_mark", "> ", &prefs_common.quotemark, P_STRING,
309          NULL, NULL, NULL},
310         {"reply_quote_format", "On %d\\n%f wrote:\\n\\n%q",
311          &prefs_common.quotefmt, P_STRING, NULL, NULL, NULL},
312
313         {"forward_quote_mark", "> ", &prefs_common.fw_quotemark, P_STRING,
314          NULL, NULL, NULL},
315         {"forward_quote_format",
316          "\\n\\nBegin forwarded message:\\n\\n"
317          "?d{Date: %d\\n}?f{From: %f\\n}?t{To: %t\\n}?c{Cc: %c\\n}"
318          "?n{Newsgroups: %n\\n}?s{Subject: %s\\n}\\n\\n%M",
319          &prefs_common.fw_quotefmt, P_STRING, NULL, NULL, NULL},
320         {"quote_chars", ">", &prefs_common.quote_chars, P_STRING,
321          NULL, NULL, NULL},
322
323         /* Display */
324         /* Obsolete fonts. For coexisting with Gtk+-1.2 version */
325         {"widget_font",         NULL,
326           &prefs_common.widgetfont_gtk1,        P_STRING, NULL, NULL, NULL},
327         {"message_font",        "-misc-fixed-medium-r-normal--14-*-*-*-*-*-*-*",
328          &prefs_common.textfont_gtk1,           P_STRING, NULL, NULL, NULL},
329         {"small_font",          "-*-helvetica-medium-r-normal--10-*-*-*-*-*-*-*",
330           &prefs_common.smallfont_gtk1,         P_STRING, NULL, NULL, NULL},
331         {"bold_font",           "-*-helvetica-bold-r-normal--12-*-*-*-*-*-*-*",
332           &prefs_common.boldfont_gtk1,          P_STRING, NULL, NULL, NULL},
333         {"normal_font",         "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
334           &prefs_common.normalfont_gtk1,        P_STRING, NULL, NULL, NULL},
335
336         /* new fonts */
337         {"widget_font_gtk2",    NULL,
338           &prefs_common.widgetfont,             P_STRING, NULL, NULL, NULL},
339         {"message_font_gtk2",   "Monospace 9",
340          &prefs_common.textfont,                P_STRING, NULL, NULL, NULL},
341         {"small_font_gtk2",     "Sans 9",
342           &prefs_common.smallfont,              P_STRING, NULL, NULL, NULL},
343         {"bold_font_gtk2",      "Sans Bold 9",
344           &prefs_common.boldfont,               P_STRING, NULL, NULL, NULL},
345         {"normal_font_gtk2",    "Sans 9", 
346           &prefs_common.normalfont,             P_STRING, NULL, NULL, NULL},
347
348         /* image viewer */
349         {"display_image", "TRUE", &prefs_common.display_img, P_BOOL,
350          NULL, NULL, NULL},
351         {"resize_image", "TRUE", &prefs_common.resize_img, P_BOOL,
352          NULL, NULL, NULL},
353         {"inline_image", "TRUE", &prefs_common.inline_img, P_BOOL,
354          NULL, NULL, NULL},
355
356         {"display_folder_unread_num", "TRUE",
357          &prefs_common.display_folder_unread, P_BOOL,
358          NULL, NULL, NULL},
359         {"newsgroup_abbrev_len", "16",
360          &prefs_common.ng_abbrev_len, P_INT,
361          NULL, NULL, NULL},
362
363         {"translate_header", "TRUE", &prefs_common.trans_hdr, P_BOOL,
364          NULL, NULL, NULL},
365
366         /* Display: Summary View */
367         {"enable_swap_from", "FALSE", &prefs_common.swap_from, P_BOOL,
368          NULL, NULL, NULL},
369         {"use_address_book", "TRUE", &prefs_common.use_addr_book, P_BOOL,
370          NULL, NULL, NULL},
371         {"thread_by_subject", "TRUE", &prefs_common.thread_by_subject, P_BOOL,
372          NULL, NULL, NULL},
373         {"date_format", "%y/%m/%d(%a) %H:%M", &prefs_common.date_format,
374          P_STRING, NULL, NULL, NULL},
375
376         {"enable_rules_hint", "TRUE", &prefs_common.enable_rules_hint, P_BOOL,
377          NULL, NULL, NULL},
378         {"enable_hscrollbar", "TRUE", &prefs_common.enable_hscrollbar, P_BOOL,
379          NULL, NULL, NULL},
380         {"bold_unread", "TRUE", &prefs_common.bold_unread, P_BOOL,
381          NULL, NULL, NULL},
382         {"thread_by_subject_max_age", "10", &prefs_common.thread_by_subject_max_age,
383         P_INT, NULL, NULL, NULL },
384
385         {"enable_thread", "TRUE", &prefs_common.enable_thread, P_BOOL,
386          NULL, NULL, NULL},
387         {"toolbar_style", "3", &prefs_common.toolbar_style, P_ENUM,
388          NULL, NULL, NULL},
389         {"show_statusbar", "TRUE", &prefs_common.show_statusbar, P_BOOL,
390          NULL, NULL, NULL},
391         {"show_searchbar", "TRUE", &prefs_common.show_searchbar, P_BOOL,
392          NULL, NULL, NULL},
393
394         {"folderview_vscrollbar_policy", "0",
395          &prefs_common.folderview_vscrollbar_policy, P_ENUM,
396          NULL, NULL, NULL},
397
398         {"summary_col_show_mark", "TRUE",
399          &prefs_common.summary_col_visible[S_COL_MARK], P_BOOL, NULL, NULL, NULL},
400         {"summary_col_show_unread", "TRUE",
401          &prefs_common.summary_col_visible[S_COL_STATUS], P_BOOL, NULL, NULL, NULL},
402         {"summary_col_show_mime", "TRUE",
403          &prefs_common.summary_col_visible[S_COL_MIME], P_BOOL, NULL, NULL, NULL},
404         {"summary_col_show_subject", "TRUE",
405          &prefs_common.summary_col_visible[S_COL_SUBJECT], P_BOOL, NULL, NULL, NULL},
406         {"summary_col_show_from", "TRUE",
407          &prefs_common.summary_col_visible[S_COL_FROM], P_BOOL, NULL, NULL, NULL},
408         {"summary_col_show_date", "TRUE",
409          &prefs_common.summary_col_visible[S_COL_DATE], P_BOOL, NULL, NULL, NULL},
410         {"summary_col_show_size", "TRUE",
411          &prefs_common.summary_col_visible[S_COL_SIZE], P_BOOL, NULL, NULL, NULL},
412         {"summary_col_show_number", "FALSE",
413          &prefs_common.summary_col_visible[S_COL_NUMBER], P_BOOL, NULL, NULL, NULL},
414         {"summary_col_show_score", "FALSE",
415          &prefs_common.summary_col_visible[S_COL_SCORE], P_BOOL, NULL, NULL, NULL},
416         {"summary_col_show_locked", "FALSE",
417          &prefs_common.summary_col_visible[S_COL_LOCKED], P_BOOL, NULL, NULL, NULL},
418
419         {"summary_col_pos_mark", "0",
420           &prefs_common.summary_col_pos[S_COL_MARK], P_INT, NULL, NULL, NULL},
421         {"summary_col_pos_unread", "1",
422           &prefs_common.summary_col_pos[S_COL_STATUS], P_INT, NULL, NULL, NULL},
423         {"summary_col_pos_mime", "2",
424           &prefs_common.summary_col_pos[S_COL_MIME], P_INT, NULL, NULL, NULL},
425         {"summary_col_pos_subject", "3",
426           &prefs_common.summary_col_pos[S_COL_SUBJECT], P_INT, NULL, NULL, NULL},
427         {"summary_col_pos_from", "4",
428           &prefs_common.summary_col_pos[S_COL_FROM], P_INT, NULL, NULL, NULL},
429         {"summary_col_pos_date", "5",
430           &prefs_common.summary_col_pos[S_COL_DATE], P_INT, NULL, NULL, NULL},
431         {"summary_col_pos_size", "6",
432           &prefs_common.summary_col_pos[S_COL_SIZE], P_INT, NULL, NULL, NULL},
433         {"summary_col_pos_number", "7",
434           &prefs_common.summary_col_pos[S_COL_NUMBER], P_INT, NULL, NULL, NULL},
435         {"summary_col_pos_score", "8",
436          &prefs_common.summary_col_pos[S_COL_SCORE], P_INT, NULL, NULL, NULL},
437         {"summary_col_pos_locked", "9",
438          &prefs_common.summary_col_pos[S_COL_LOCKED], P_INT, NULL, NULL, NULL},
439
440         {"summary_col_size_mark", "10",
441          &prefs_common.summary_col_size[S_COL_MARK], P_INT, NULL, NULL, NULL},
442         {"summary_col_size_unread", "13",
443          &prefs_common.summary_col_size[S_COL_STATUS], P_INT, NULL, NULL, NULL},
444         {"summary_col_size_mime", "10",
445          &prefs_common.summary_col_size[S_COL_MIME], P_INT, NULL, NULL, NULL},
446         {"summary_col_size_subject", "200",
447          &prefs_common.summary_col_size[S_COL_SUBJECT], P_INT, NULL, NULL, NULL},
448         {"summary_col_size_from", "120",
449          &prefs_common.summary_col_size[S_COL_FROM], P_INT, NULL, NULL, NULL},
450         {"summary_col_size_date", "118",
451          &prefs_common.summary_col_size[S_COL_DATE], P_INT, NULL, NULL, NULL},
452         {"summary_col_size_size", "45",
453          &prefs_common.summary_col_size[S_COL_SIZE], P_INT, NULL, NULL, NULL},
454         {"summary_col_size_number", "40",
455          &prefs_common.summary_col_size[S_COL_NUMBER], P_INT, NULL, NULL, NULL},
456         {"summary_col_size_score", "40",
457          &prefs_common.summary_col_size[S_COL_SCORE], P_INT, NULL, NULL, NULL},
458         {"summary_col_size_locked", "13",
459          &prefs_common.summary_col_size[S_COL_LOCKED], P_INT, NULL, NULL, NULL},
460
461         /* Widget size */
462         {"folderwin_x", "16", &prefs_common.folderwin_x, P_INT,
463          NULL, NULL, NULL},
464         {"folderwin_y", "16", &prefs_common.folderwin_y, P_INT,
465          NULL, NULL, NULL},
466         {"folderview_width", "179", &prefs_common.folderview_width, P_INT,
467          NULL, NULL, NULL},
468         {"folderview_height", "450", &prefs_common.folderview_height, P_INT,
469          NULL, NULL, NULL},
470         {"folderview_visible", "TRUE", &prefs_common.folderview_visible, P_BOOL,
471          NULL, NULL, NULL},
472
473         {"folder_col_folder", "150", &prefs_common.folder_col_folder, P_INT,
474          NULL, NULL, NULL},
475         {"folder_col_new", "32", &prefs_common.folder_col_new, P_INT,
476          NULL, NULL, NULL},
477         {"folder_col_unread", "32", &prefs_common.folder_col_unread, P_INT,
478          NULL, NULL, NULL},
479         {"folder_col_total", "32", &prefs_common.folder_col_total, P_INT,
480          NULL, NULL, NULL},
481
482         {"summaryview_width", "600", &prefs_common.summaryview_width, P_INT,
483          NULL, NULL, NULL},
484         {"summaryview_height", "157", &prefs_common.summaryview_height, P_INT,
485          NULL, NULL, NULL},
486
487         {"main_messagewin_x", "256", &prefs_common.main_msgwin_x, P_INT,
488          NULL, NULL, NULL},
489         {"main_messagewin_y", "210", &prefs_common.main_msgwin_y, P_INT,
490          NULL, NULL, NULL},
491         {"messageview_width", "600", &prefs_common.msgview_width, P_INT,
492          NULL, NULL, NULL},
493         {"messageview_height", "300", &prefs_common.msgview_height, P_INT,
494          NULL, NULL, NULL},
495         {"messageview_visible", "TRUE", &prefs_common.msgview_visible, P_BOOL,
496          NULL, NULL, NULL},
497
498         {"mainview_x", "64", &prefs_common.mainview_x, P_INT,
499          NULL, NULL, NULL},
500         {"mainview_y", "64", &prefs_common.mainview_y, P_INT,
501          NULL, NULL, NULL},
502         {"mainview_width", "600", &prefs_common.mainview_width, P_INT,
503          NULL, NULL, NULL},
504         {"mainview_height", "600", &prefs_common.mainview_height, P_INT,
505          NULL, NULL, NULL},
506         {"mainwin_x", "64", &prefs_common.mainwin_x, P_INT,
507          NULL, NULL, NULL},
508         {"mainwin_y", "64", &prefs_common.mainwin_y, P_INT,
509          NULL, NULL, NULL},
510         {"mainwin_width", "800", &prefs_common.mainwin_width, P_INT,
511          NULL, NULL, NULL},
512         {"mainwin_height", "600", &prefs_common.mainwin_height, P_INT,
513          NULL, NULL, NULL},
514         {"messagewin_width", "600", &prefs_common.msgwin_width, P_INT,
515          NULL, NULL, NULL},
516         {"messagewin_height", "540", &prefs_common.msgwin_height, P_INT,
517          NULL, NULL, NULL},
518         {"sourcewin_width", "600", &prefs_common.sourcewin_width, P_INT,
519          NULL, NULL, NULL},
520         {"sourcewin_height", "500", &prefs_common.sourcewin_height, P_INT,
521          NULL, NULL, NULL},
522         {"compose_width", "600", &prefs_common.compose_width, P_INT,
523          NULL, NULL, NULL},
524         {"compose_height", "560", &prefs_common.compose_height, P_INT,
525          NULL, NULL, NULL},
526         {"compose_x", "0", &prefs_common.compose_x, P_INT,
527          NULL, NULL, NULL},
528         {"compose_y", "0", &prefs_common.compose_y, P_INT,
529          NULL, NULL, NULL},
530         /* Message */
531         {"enable_color", "TRUE", &prefs_common.enable_color, P_BOOL,
532          NULL, NULL, NULL},
533
534         {"quote_level1_color", "179", &prefs_common.quote_level1_col, P_COLOR,
535          NULL, NULL, NULL},
536         {"quote_level2_color", "179", &prefs_common.quote_level2_col, P_COLOR,
537          NULL, NULL, NULL},
538         {"quote_level3_color", "179", &prefs_common.quote_level3_col, P_COLOR,
539          NULL, NULL, NULL},
540         {"uri_color", "32512", &prefs_common.uri_col, P_COLOR,
541          NULL, NULL, NULL},
542         {"target_folder_color", "14294218", &prefs_common.tgt_folder_col, P_COLOR,
543          NULL, NULL, NULL},
544         {"signature_color", "7960953", &prefs_common.signature_col, P_COLOR,
545          NULL, NULL, NULL},
546         {"recycle_quote_colors", "FALSE", &prefs_common.recycle_quote_colors,
547          P_BOOL, NULL, NULL, NULL},
548
549         {"convert_mb_alnum", "FALSE", &prefs_common.conv_mb_alnum, P_BOOL,
550          &message.chkbtn_mbalnum,
551          prefs_set_data_from_toggle, prefs_set_toggle},
552         {"display_header_pane", "TRUE", &prefs_common.display_header_pane,
553          P_BOOL, &message.chkbtn_disphdrpane,
554          prefs_set_data_from_toggle, prefs_set_toggle},
555         {"display_header", "TRUE", &prefs_common.display_header, P_BOOL,
556          &message.chkbtn_disphdr,
557          prefs_set_data_from_toggle, prefs_set_toggle},
558         {"render_html", "TRUE", &prefs_common.render_html, P_BOOL,
559          &message.chkbtn_html,
560          prefs_set_data_from_toggle, prefs_set_toggle},
561         {"textview_cursor_visible", "FALSE",
562          &prefs_common.textview_cursor_visible, P_BOOL,
563          &message.chkbtn_cursor, prefs_set_data_from_toggle, prefs_set_toggle},
564         {"line_space", "2", &prefs_common.line_space, P_INT,
565          &message.spinbtn_linespc,
566          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
567
568         {"enable_smooth_scroll", "FALSE",
569          &prefs_common.enable_smooth_scroll, P_BOOL,
570          &message.chkbtn_smoothscroll,
571          prefs_set_data_from_toggle, prefs_set_toggle},
572         {"scroll_step", "1", &prefs_common.scroll_step, P_INT,
573          &message.spinbtn_scrollstep,
574          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
575         {"scroll_half_page", "FALSE", &prefs_common.scroll_halfpage, P_BOOL,
576          &message.chkbtn_halfpage,
577          prefs_set_data_from_toggle, prefs_set_toggle},
578
579         {"show_other_header", "FALSE", &prefs_common.show_other_header, P_BOOL,
580          NULL, NULL, NULL},
581
582         {"attach_desc", "TRUE", &prefs_common.attach_desc, P_BOOL,
583          &message.chkbtn_attach_desc,
584          prefs_set_data_from_toggle, prefs_set_toggle},
585         {"attach_save_directory", NULL,
586          &prefs_common.attach_save_dir, P_STRING, NULL, NULL, NULL},
587
588         /* MIME viewer */
589         {"mime_image_viewer", "display '%s'",
590          &prefs_common.mime_image_viewer, P_STRING, NULL, NULL, NULL},
591         {"mime_audio_player", "play '%s'",
592          &prefs_common.mime_audio_player, P_STRING, NULL, NULL, NULL},
593         {"mime_open_command", "gedit '%s'",
594          &prefs_common.mime_open_cmd, P_STRING, NULL, NULL, NULL},
595
596         /* Interface */
597         {"separate_folder", "FALSE", &prefs_common.sep_folder, P_BOOL,
598          NULL, NULL, NULL},
599         {"separate_message", "FALSE", &prefs_common.sep_msg, P_BOOL,
600          NULL, NULL, NULL},
601
602         /* {"emulate_emacs", "FALSE", &prefs_common.emulate_emacs, P_BOOL,
603          NULL, NULL, NULL}, */
604         {"always_show_message_when_selected", "FALSE",
605          &prefs_common.always_show_msg,
606          P_BOOL, &interface.checkbtn_always_show_msg,
607          prefs_set_data_from_toggle, prefs_set_toggle},
608         {"open_unread_on_enter", "FALSE", &prefs_common.open_unread_on_enter,
609          P_BOOL, &interface.checkbtn_openunread,
610          prefs_set_data_from_toggle, prefs_set_toggle},
611         {"mark_as_read_on_new_window", "FALSE",
612          &prefs_common.mark_as_read_on_new_window,
613          P_BOOL, &interface.checkbtn_mark_as_read_on_newwin,
614          prefs_set_data_from_toggle, prefs_set_toggle},
615         {"mark_as_read_delay", "0",
616          &prefs_common.mark_as_read_delay, P_INT, 
617          NULL, NULL, NULL},
618         {"open_inbox_on_inc", "FALSE", &prefs_common.open_inbox_on_inc,
619          P_BOOL, &interface.checkbtn_openinbox,
620          prefs_set_data_from_toggle, prefs_set_toggle},
621         {"immediate_execution", "TRUE", &prefs_common.immediate_exec, P_BOOL,
622          &interface.checkbtn_immedexec,
623          prefs_set_data_from_toggle, prefs_set_toggle},
624         {"nextunreadmsg_dialog", NULL, &prefs_common.next_unread_msg_dialog, P_ENUM,
625          &interface.optmenu_nextunreadmsgdialog,
626          prefs_nextunreadmsgdialog_set_data_from_optmenu,
627          prefs_nextunreadmsgdialog_set_optmenu},
628
629         {"pixmap_theme_path", DEFAULT_PIXMAP_THEME, 
630          &prefs_common.pixmap_theme_path, P_STRING,
631          NULL, NULL, NULL},
632
633         {"hover_timeout", "500", &prefs_common.hover_timeout, P_INT,
634          NULL, NULL, NULL},
635         
636         /* Other */
637         {"uri_open_command", DEFAULT_BROWSER_CMD,
638          &prefs_common.uri_cmd, P_STRING, NULL, NULL, NULL},
639         {"print_command", "lpr %s", &prefs_common.print_cmd, P_STRING,
640          NULL, NULL, NULL},
641         {"ext_editor_command", "gedit %s",
642          &prefs_common.ext_editor_cmd, P_STRING, NULL, NULL, NULL},
643
644         {"add_address_by_click", "FALSE", &prefs_common.add_address_by_click,
645          P_BOOL, &other.checkbtn_addaddrbyclick,
646          prefs_set_data_from_toggle, prefs_set_toggle},
647
648         {"confirm_on_exit", "FALSE", &prefs_common.confirm_on_exit, P_BOOL,
649          &other.checkbtn_confonexit,
650          prefs_set_data_from_toggle, prefs_set_toggle},
651         {"clean_trash_on_exit", "FALSE", &prefs_common.clean_on_exit, P_BOOL,
652          &other.checkbtn_cleanonexit,
653          prefs_set_data_from_toggle, prefs_set_toggle},
654         {"ask_on_cleaning", "TRUE", &prefs_common.ask_on_clean, P_BOOL,
655          &other.checkbtn_askonclean,
656          prefs_set_data_from_toggle, prefs_set_toggle},
657         {"warn_queued_on_exit", "TRUE", &prefs_common.warn_queued_on_exit,
658          P_BOOL, &other.checkbtn_warnqueued,
659          prefs_set_data_from_toggle, prefs_set_toggle},
660 #if 0
661 #ifdef USE_OPENSSL
662         {"ssl_ask_unknown_valid", "TRUE", &prefs_common.ssl_ask_unknown_valid,
663          P_BOOL, &other.checkbtn_ssl_ask_unknown_valid,
664          prefs_set_data_from_toggle, prefs_set_toggle},
665 #endif
666 #endif
667         {"work_offline", "FALSE", &prefs_common.work_offline, P_BOOL,
668          NULL, NULL, NULL},
669         {"summary_quicksearch_type", "0", &prefs_common.summary_quicksearch_type, P_INT,
670          NULL, NULL, NULL},
671         {"summary_quicksearch_sticky", "1", &prefs_common.summary_quicksearch_sticky, P_INT,
672          NULL, NULL, NULL},
673         {"summary_quicksearch_recurse", "1", &prefs_common.summary_quicksearch_recurse, P_INT,
674          NULL, NULL, NULL},
675
676         {"io_timeout_secs", "60", &prefs_common.io_timeout_secs,
677          P_INT, &other.spinbtn_iotimeout,
678          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
679         {"hide_score", "-9999", &prefs_common.kill_score, P_INT,
680          NULL, NULL, NULL},
681         {"important_score", "1", &prefs_common.important_score, P_INT,
682          NULL, NULL, NULL},
683         {"clip_log", "TRUE", &prefs_common.cliplog, P_BOOL,
684          &other.checkbtn_cliplog,
685          prefs_set_data_from_toggle, prefs_set_toggle},
686         {"log_length", "500", &prefs_common.loglength, P_INT,
687          &other.loglength_entry,
688          prefs_set_data_from_entry, prefs_set_entry},
689
690         {"cache_max_mem_usage", "4096", &prefs_common.cache_max_mem_usage, P_INT,
691          NULL, NULL, NULL},
692         {"cache_min_keep_time", "15", &prefs_common.cache_min_keep_time, P_INT,
693          NULL, NULL, NULL},
694
695         {"color_new", "179", &prefs_common.color_new, P_COLOR,
696          NULL, NULL, NULL},
697
698         {"filteringwin_width", "500", &prefs_common.filteringwin_width, P_INT,
699          NULL, NULL, NULL},
700         {"filteringwin_height", "-1", &prefs_common.filteringwin_height, P_INT,
701          NULL, NULL, NULL},
702         {"warn_dnd", "1", &prefs_common.warn_dnd, P_INT,
703          NULL, NULL, NULL},
704
705         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
706 };
707
708 /* widget creating functions */
709 static void prefs_common_create         (void);
710 static void prefs_receive_create        (void);
711 static void prefs_send_create           (void);
712 static void prefs_message_create        (void);
713 static void prefs_interface_create      (void);
714 static void prefs_other_create          (void);
715
716 static void date_format_ok_btn_clicked          (GtkButton      *button,
717                                                  GtkWidget     **widget);
718 static void date_format_cancel_btn_clicked      (GtkButton      *button,
719                                                  GtkWidget     **widget);
720 static gboolean date_format_key_pressed         (GtkWidget      *keywidget,
721                                                  GdkEventKey    *event,
722                                                  GtkWidget     **widget);
723 static gboolean date_format_on_delete           (GtkWidget      *dialogwidget,
724                                                  GdkEventAny    *event,
725                                                  GtkWidget     **widget);
726 static void date_format_entry_on_change         (GtkEditable    *editable,
727                                                  GtkLabel       *example);
728 static void date_format_select_row              (GtkTreeView *list_view,
729                                                  GtkTreePath *path,
730                                                  GtkTreeViewColumn *column,
731                                                  GtkWidget *date_format);
732 static void prefs_keybind_select                (void);
733 static gint prefs_keybind_deleted               (GtkWidget      *widget,
734                                                  GdkEventAny    *event,
735                                                  gpointer        data);
736 static gboolean prefs_keybind_key_pressed       (GtkWidget      *widget,
737                                                  GdkEventKey    *event,
738                                                  gpointer        data);
739 static void prefs_keybind_cancel                (void);
740 static void prefs_keybind_apply_clicked         (GtkWidget      *widget);
741
742 static void prefs_common_apply          (void);
743
744 typedef struct CommonPage
745 {
746         PrefsPage page;
747  
748         GtkWidget *vbox;
749 } CommonPage;
750
751 static CommonPage common_page;
752
753 static void create_widget_func(PrefsPage * _page,
754                                            GtkWindow * window,
755                                            gpointer data)
756 {
757         CommonPage *page = (CommonPage *) _page;
758         GtkWidget *vbox;
759
760         vbox = gtk_vbox_new(FALSE, 6);
761         gtk_widget_show(vbox);
762
763         if (notebook == NULL)
764                 prefs_common_create();
765         gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);
766         gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
767
768         prefs_set_dialog(param);
769
770         page->vbox = vbox;
771
772         page->page.widget = vbox;
773 }
774
775 static void destroy_widget_func(PrefsPage *_page)
776 {
777         CommonPage *page = (CommonPage *) _page;
778
779         gtk_container_remove(GTK_CONTAINER (page->vbox), notebook);
780 }
781
782 static void save_func(PrefsPage * _page)
783 {
784         prefs_common_apply();
785 }
786
787 void prefs_common_init(void) 
788 {
789         static gchar *path[2];
790
791         prefs_common.disphdr_list = NULL;
792             
793         path[0] = _("Common");
794         path[2] = NULL;
795         
796         common_page.page.path = path;
797         common_page.page.weight = 1000.0;
798         common_page.page.create_widget = create_widget_func;
799         common_page.page.destroy_widget = destroy_widget_func;
800         common_page.page.save_page = save_func;
801
802         prefs_gtk_register_page((PrefsPage *) &common_page);
803 }
804
805 PrefsCommon *prefs_common_get(void)
806 {
807         return &prefs_common;
808 }
809
810 /*
811  * Read history list from the specified history file
812  */
813 GList *prefs_common_read_history(const gchar *history) 
814 {
815         FILE *fp;
816         gchar *path;
817         gchar buf[PREFSBUFSIZE];
818         GList *tmp = NULL;
819
820         path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, history,
821                            NULL);
822         if ((fp = fopen(path, "rb")) == NULL) {
823                 if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
824                 g_free(path);
825                 return NULL;
826         }
827         g_free(path);
828         while (fgets(buf, sizeof(buf), fp) != NULL) {
829                 g_strstrip(buf);
830                 if (buf[0] == '\0') continue;
831                 tmp = add_history(tmp, buf);
832         }
833         fclose(fp);
834
835         tmp = g_list_reverse(tmp);
836
837         return tmp;
838 }
839
840 void prefs_common_read_config(void)
841 {
842         gchar *rcpath;
843         
844         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
845         prefs_read_config(param, "Common", rcpath, NULL);
846         g_free(rcpath);
847         
848         prefs_common.mime_open_cmd_history =
849                 prefs_common_read_history(COMMAND_HISTORY);
850         prefs_common.summary_quicksearch_history =
851                 prefs_common_read_history(QUICKSEARCH_HISTORY);
852 }
853
854 /*
855  * Save history list to the specified history file
856  */
857 void prefs_common_save_history(const gchar *history, GList *list)
858 {
859         GList *cur;
860         FILE *fp;
861         gchar *path;
862
863         path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, history,
864                            NULL);
865         if ((fp = fopen(path, "wb")) == NULL) {
866                 FILE_OP_ERROR(path, "fopen");
867                 g_free(path);
868                 return;
869         }
870
871         for (cur = list; cur != NULL; cur = cur->next) {
872                 fputs((gchar *)cur->data, fp);
873                 fputc('\n', fp);
874         }
875
876         fclose(fp);
877         g_free(path);
878 }
879
880 void prefs_common_write_config(void)
881 {
882         prefs_write_config(param, "Common", COMMON_RC);
883
884         prefs_common_save_history(COMMAND_HISTORY, 
885                 prefs_common.mime_open_cmd_history);
886         prefs_common_save_history(QUICKSEARCH_HISTORY, 
887                 prefs_common.summary_quicksearch_history);
888 }
889
890 static void prefs_common_create(void)
891 {
892         gint page = 0;
893
894         debug_print("Creating common preferences window...\n");
895
896         notebook = gtk_notebook_new ();
897         gtk_widget_show(notebook);
898         gtk_container_set_border_width (GTK_CONTAINER (notebook), 2);
899         /* GTK_WIDGET_UNSET_FLAGS (notebook, GTK_CAN_FOCUS); */
900         gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
901         
902         gtk_notebook_popup_enable (GTK_NOTEBOOK (notebook));
903
904         gtk_widget_ref(notebook);
905
906         /* create all widgets on notebook */
907         prefs_receive_create();
908         SET_NOTEBOOK_LABEL(notebook, _("Receive"),   page++);
909         prefs_send_create();
910         SET_NOTEBOOK_LABEL(notebook, _("Send"),      page++);
911         prefs_message_create();
912         SET_NOTEBOOK_LABEL(notebook, _("Message"),   page++);
913         prefs_interface_create();
914         SET_NOTEBOOK_LABEL(notebook, _("Interface"), page++);
915         prefs_other_create();
916         SET_NOTEBOOK_LABEL(notebook, _("Other"),     page++);
917
918         gtk_widget_show_all(notebook);
919 }
920
921 static void prefs_receive_create(void)
922 {
923         GtkWidget *vbox1;
924         GtkWidget *vbox2;
925         GtkWidget *frame_incext;
926         GtkWidget *checkbtn_incext;
927         GtkWidget *hbox;
928         GtkWidget *label_incext;
929         GtkWidget *entry_incext;
930         /* GtkWidget *button_incext; */
931
932         GtkWidget *hbox_autochk;
933         GtkWidget *checkbtn_autochk;
934         GtkWidget *label_autochk1;
935         GtkObject *spinbtn_autochk_adj;
936         GtkWidget *spinbtn_autochk;
937         GtkWidget *label_autochk2;
938         GtkWidget *checkbtn_chkonstartup;
939         GtkWidget *checkbtn_scan_after_inc;
940
941
942         GtkWidget *frame_newmail;
943         GtkWidget *hbox_newmail_notify;
944         GtkWidget *checkbtn_newmail_auto;
945         GtkWidget *checkbtn_newmail_manu;
946         GtkWidget *entry_newmail_notify_cmd;
947         GtkWidget *label_newmail_notify_cmd;
948
949         GtkWidget *hbox_recvdialog;
950         GtkWidget *label_recvdialog;
951         GtkWidget *menu;
952         GtkWidget *menuitem;
953         GtkWidget *optmenu_recvdialog;
954         GtkWidget *checkbtn_no_recv_err_panel;
955         GtkWidget *checkbtn_close_recv_dialog;
956
957         vbox1 = gtk_vbox_new (FALSE, VSPACING);
958         gtk_widget_show (vbox1);
959         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
960         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
961
962         PACK_FRAME(vbox1, frame_incext, _("External program"));
963
964         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
965         gtk_widget_show (vbox2);
966         gtk_container_add (GTK_CONTAINER (frame_incext), vbox2);
967         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
968
969         /* Use of external incorporation program */
970         PACK_CHECK_BUTTON (vbox2, checkbtn_incext,
971                            _("Use external program for incorporation"));
972
973         hbox = gtk_hbox_new (FALSE, 8);
974         gtk_widget_show (hbox);
975         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
976         SET_TOGGLE_SENSITIVITY (checkbtn_incext, hbox);
977
978         label_incext = gtk_label_new (_("Command"));
979         gtk_widget_show (label_incext);
980         gtk_box_pack_start (GTK_BOX (hbox), label_incext, FALSE, FALSE, 0);
981
982         entry_incext = gtk_entry_new ();
983         gtk_widget_show (entry_incext);
984         gtk_box_pack_start (GTK_BOX (hbox), entry_incext, TRUE, TRUE, 0);
985
986 #if 0
987         button_incext = gtk_button_new_with_label ("... ");
988         gtk_widget_show (button_incext);
989         gtk_box_pack_start (GTK_BOX (hbox), button_incext, FALSE, FALSE, 0);
990 #endif
991
992         vbox2 = gtk_vbox_new (FALSE, 0);
993         gtk_widget_show (vbox2);
994         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
995
996         /* Auto-checking */
997         hbox_autochk = gtk_hbox_new (FALSE, 8);
998         gtk_widget_show (hbox_autochk);
999         gtk_box_pack_start (GTK_BOX (vbox2), hbox_autochk, FALSE, FALSE, 0);
1000
1001         PACK_CHECK_BUTTON (hbox_autochk, checkbtn_autochk,
1002                            _("Auto-check new mail"));
1003
1004         label_autochk1 = gtk_label_new (_("every"));
1005         gtk_widget_show (label_autochk1);
1006         gtk_box_pack_start (GTK_BOX (hbox_autochk), label_autochk1, FALSE, FALSE, 0);
1007
1008         spinbtn_autochk_adj = gtk_adjustment_new (5, 1, 100, 1, 10, 10);
1009         spinbtn_autochk = gtk_spin_button_new
1010                 (GTK_ADJUSTMENT (spinbtn_autochk_adj), 1, 0);
1011         gtk_widget_show (spinbtn_autochk);
1012         gtk_box_pack_start (GTK_BOX (hbox_autochk), spinbtn_autochk, FALSE, FALSE, 0);
1013         gtk_widget_set_size_request (spinbtn_autochk, 64, -1);
1014         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_autochk), TRUE);
1015
1016         label_autochk2 = gtk_label_new (_("minute(s)"));
1017         gtk_widget_show (label_autochk2);
1018         gtk_box_pack_start (GTK_BOX (hbox_autochk), label_autochk2, FALSE, FALSE, 0);
1019
1020         SET_TOGGLE_SENSITIVITY(checkbtn_autochk, label_autochk1);
1021         SET_TOGGLE_SENSITIVITY(checkbtn_autochk, spinbtn_autochk);
1022         SET_TOGGLE_SENSITIVITY(checkbtn_autochk, label_autochk2);
1023
1024         PACK_CHECK_BUTTON (vbox2, checkbtn_chkonstartup,
1025                            _("Check new mail on startup"));
1026         PACK_CHECK_BUTTON (vbox2, checkbtn_scan_after_inc,
1027                            _("Update all local folders after incorporation"));
1028
1029
1030         /* receive dialog */
1031         hbox_recvdialog = gtk_hbox_new (FALSE, 8);
1032         gtk_widget_show (hbox_recvdialog);
1033         gtk_box_pack_start (GTK_BOX (vbox2), hbox_recvdialog, FALSE, FALSE, 0);
1034
1035         label_recvdialog = gtk_label_new (_("Show receive dialog"));
1036         gtk_misc_set_alignment(GTK_MISC(label_recvdialog), 0, 0.5);
1037         gtk_widget_show (label_recvdialog);
1038         gtk_box_pack_start (GTK_BOX (hbox_recvdialog), label_recvdialog, FALSE, FALSE, 0);
1039
1040         optmenu_recvdialog = gtk_option_menu_new ();
1041         gtk_widget_show (optmenu_recvdialog);
1042         gtk_box_pack_start (GTK_BOX (hbox_recvdialog), optmenu_recvdialog, FALSE, FALSE, 0);
1043
1044         menu = gtk_menu_new ();
1045         MENUITEM_ADD (menu, menuitem, _("Always"), RECV_DIALOG_ALWAYS);
1046         MENUITEM_ADD (menu, menuitem, _("Only on manual receiving"),
1047                       RECV_DIALOG_MANUAL);
1048         MENUITEM_ADD (menu, menuitem, _("Never"), RECV_DIALOG_NEVER);
1049
1050         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_recvdialog), menu);
1051
1052         PACK_CHECK_BUTTON (vbox2, checkbtn_no_recv_err_panel,
1053                            _("Don't popup error dialog on receive error"));
1054
1055         PACK_CHECK_BUTTON (vbox2, checkbtn_close_recv_dialog,
1056                            _("Close receive dialog when finished"));
1057         
1058         PACK_FRAME(vbox1, frame_newmail, _("Run command when new mail "
1059                                            "arrives"));
1060         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
1061         gtk_widget_show (vbox2);
1062         gtk_container_add (GTK_CONTAINER (frame_newmail), vbox2);
1063         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1064
1065         hbox = gtk_hbox_new (TRUE, 8);
1066         gtk_widget_show (hbox);
1067         PACK_CHECK_BUTTON (hbox, checkbtn_newmail_auto,
1068                            _("after autochecking"));
1069         PACK_CHECK_BUTTON (hbox, checkbtn_newmail_manu,
1070                            _("after manual checking"));
1071         gtk_box_pack_start (GTK_BOX(vbox2), hbox, FALSE, FALSE, 0);
1072         g_signal_connect(G_OBJECT(checkbtn_newmail_auto), "toggled",
1073                          G_CALLBACK(prefs_common_recv_dialog_newmail_notify_toggle_cb),
1074                          NULL);
1075         g_signal_connect(G_OBJECT(checkbtn_newmail_manu), "toggled",
1076                          G_CALLBACK(prefs_common_recv_dialog_newmail_notify_toggle_cb),
1077                          NULL);
1078
1079         hbox_newmail_notify = gtk_hbox_new (FALSE, 8);
1080         gtk_widget_show (hbox);
1081         gtk_box_pack_start (GTK_BOX (vbox2), hbox_newmail_notify, FALSE, 
1082                             FALSE, 0);
1083
1084         label_newmail_notify_cmd = gtk_label_new (_("Command to execute:\n"
1085                                                     "(use %d as number of new "
1086                                                     "mails)"));
1087         gtk_label_set_justify(GTK_LABEL(label_newmail_notify_cmd), 
1088                               GTK_JUSTIFY_RIGHT);
1089         gtk_widget_show (label_newmail_notify_cmd);
1090         gtk_box_pack_start (GTK_BOX (hbox_newmail_notify), 
1091                             label_newmail_notify_cmd, FALSE, FALSE, 0);
1092
1093         entry_newmail_notify_cmd = gtk_entry_new ();
1094         gtk_widget_show (entry_newmail_notify_cmd);
1095         gtk_box_pack_start (GTK_BOX (hbox_newmail_notify), 
1096                             entry_newmail_notify_cmd, TRUE, TRUE, 0);
1097
1098         gtk_widget_set_sensitive(hbox_newmail_notify, 
1099                                  prefs_common.newmail_notify_auto || 
1100                                  prefs_common.newmail_notify_manu);
1101
1102         receive.checkbtn_incext = checkbtn_incext;
1103         receive.entry_incext    = entry_incext;
1104         /* receive.button_incext   = button_incext; */
1105
1106         receive.checkbtn_autochk    = checkbtn_autochk;
1107         receive.spinbtn_autochk     = spinbtn_autochk;
1108         receive.spinbtn_autochk_adj = spinbtn_autochk_adj;
1109
1110         receive.checkbtn_chkonstartup = checkbtn_chkonstartup;
1111         receive.checkbtn_scan_after_inc = checkbtn_scan_after_inc;
1112
1113
1114         receive.checkbtn_newmail_auto  = checkbtn_newmail_auto;
1115         receive.checkbtn_newmail_manu  = checkbtn_newmail_manu;
1116         receive.hbox_newmail_notify    = hbox_newmail_notify;
1117         receive.entry_newmail_notify_cmd = entry_newmail_notify_cmd;
1118         receive.optmenu_recvdialog          = optmenu_recvdialog;
1119         receive.checkbtn_no_recv_err_panel  = checkbtn_no_recv_err_panel;
1120         receive.checkbtn_close_recv_dialog  = checkbtn_close_recv_dialog;
1121 }
1122
1123 static void prefs_send_create(void)
1124 {
1125         GtkWidget *vbox1;
1126         GtkWidget *vbox2;
1127         GtkWidget *hbox1;
1128         GtkWidget *checkbtn_savemsg;
1129         GtkWidget *label_outcharset;
1130         GtkWidget *optmenu_charset;
1131         GtkWidget *optmenu_menu;
1132         GtkWidget *menuitem;
1133         GtkTooltips *charset_tooltip;
1134         GtkWidget *optmenu_encoding;
1135         GtkWidget *label_encoding;
1136         GtkTooltips *encoding_tooltip;
1137         GtkWidget *label_senddialog;
1138         GtkWidget *menu;
1139         GtkWidget *optmenu_senddialog;
1140         GtkWidget *hbox_senddialog;
1141
1142         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1143         gtk_widget_show (vbox1);
1144         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1145         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1146
1147         vbox2 = gtk_vbox_new (FALSE, 0);
1148         gtk_widget_show (vbox2);
1149         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
1150
1151         PACK_CHECK_BUTTON (vbox2, checkbtn_savemsg,
1152                            _("Save sent messages to Sent folder"));
1153
1154         hbox_senddialog = gtk_hbox_new (FALSE, 8);
1155         gtk_box_pack_start (GTK_BOX (vbox1), hbox_senddialog, FALSE, FALSE, 0);
1156
1157         label_senddialog = gtk_label_new (_("Show send dialog"));
1158         gtk_widget_show (label_senddialog);
1159         gtk_box_pack_start (GTK_BOX (hbox_senddialog), label_senddialog, FALSE, FALSE, 0);
1160
1161         optmenu_senddialog = gtk_option_menu_new ();
1162         gtk_widget_show (optmenu_senddialog);
1163         gtk_box_pack_start (GTK_BOX (hbox_senddialog), optmenu_senddialog, FALSE, FALSE, 0);
1164         
1165         menu = gtk_menu_new ();
1166         MENUITEM_ADD (menu, menuitem, _("Always"), SEND_DIALOG_ALWAYS);
1167         MENUITEM_ADD (menu, menuitem, _("Never"), SEND_DIALOG_NEVER);
1168
1169         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_senddialog), menu);
1170
1171         hbox1 = gtk_hbox_new (FALSE, 8);
1172         gtk_widget_show (hbox1);
1173         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
1174
1175         label_outcharset = gtk_label_new (_("Outgoing encoding"));
1176         gtk_widget_show (label_outcharset);
1177         gtk_box_pack_start (GTK_BOX (hbox1), label_outcharset, FALSE, FALSE, 0);
1178
1179         charset_tooltip = gtk_tooltips_new();
1180
1181         optmenu_charset = gtk_option_menu_new ();
1182         gtk_widget_show (optmenu_charset);
1183         gtk_tooltips_set_tip(GTK_TOOLTIPS(charset_tooltip), optmenu_charset,
1184                              _("If `Automatic' is selected, the optimal encoding"
1185                                " for the current locale will be used"),
1186                              NULL);
1187         gtk_box_pack_start (GTK_BOX (hbox1), optmenu_charset, FALSE, FALSE, 0);
1188
1189         optmenu_menu = gtk_menu_new ();
1190
1191 #define SET_MENUITEM(str, data) \
1192 { \
1193         MENUITEM_ADD(optmenu_menu, menuitem, str, data); \
1194 }
1195
1196         SET_MENUITEM(_("Automatic (Recommended)"),       CS_AUTO);
1197         SET_MENUITEM(NULL, NULL);
1198         SET_MENUITEM(_("7bit ascii (US-ASCII)"),         CS_US_ASCII);
1199         SET_MENUITEM(NULL, NULL);
1200         SET_MENUITEM(_("Unicode (UTF-8)"),               CS_UTF_8);
1201         SET_MENUITEM(NULL, NULL);
1202         SET_MENUITEM(_("Western European (ISO-8859-1)"),  CS_ISO_8859_1);
1203         SET_MENUITEM(_("Western European (ISO-8859-15)"), CS_ISO_8859_15);
1204         SET_MENUITEM(NULL, NULL);
1205         SET_MENUITEM(_("Central European (ISO-8859-2)"),  CS_ISO_8859_2);
1206         SET_MENUITEM(NULL, NULL);
1207         SET_MENUITEM(_("Baltic (ISO-8859-13)"),           CS_ISO_8859_13);
1208         SET_MENUITEM(_("Baltic (ISO-8859-4)"),            CS_ISO_8859_4);
1209         SET_MENUITEM(NULL, NULL);
1210         SET_MENUITEM(_("Greek (ISO-8859-7)"),             CS_ISO_8859_7);
1211         SET_MENUITEM(NULL, NULL);
1212         SET_MENUITEM(_("Turkish (ISO-8859-9)"),           CS_ISO_8859_9);
1213         SET_MENUITEM(NULL, NULL);
1214         SET_MENUITEM(_("Cyrillic (ISO-8859-5)"),          CS_ISO_8859_5);
1215         SET_MENUITEM(_("Cyrillic (KOI8-R)"),             CS_KOI8_R);
1216         SET_MENUITEM(_("Cyrillic (KOI8-U)"),             CS_KOI8_U);
1217         SET_MENUITEM(_("Cyrillic (Windows-1251)"),       CS_WINDOWS_1251);
1218         SET_MENUITEM(NULL, NULL);
1219         SET_MENUITEM(_("Japanese (ISO-2022-JP)"),        CS_ISO_2022_JP);
1220 #if 0
1221         SET_MENUITEM(_("Japanese (EUC-JP)"),             CS_EUC_JP);
1222         SET_MENUITEM(_("Japanese (Shift_JIS)"),          CS_SHIFT_JIS);
1223 #endif /* 0 */
1224         SET_MENUITEM(NULL, NULL);
1225         SET_MENUITEM(_("Simplified Chinese (GB2312)"),   CS_GB2312);
1226         SET_MENUITEM(_("Simplified Chinese (GBK)"),      CS_GBK);
1227         SET_MENUITEM(_("Traditional Chinese (Big5)"),    CS_BIG5);
1228 #if 0
1229         SET_MENUITEM(_("Traditional Chinese (EUC-TW)"),  CS_EUC_TW);
1230         SET_MENUITEM(_("Chinese (ISO-2022-CN)"),         CS_ISO_2022_CN);
1231 #endif /* 0 */
1232         SET_MENUITEM(NULL, NULL);
1233         SET_MENUITEM(_("Korean (EUC-KR)"),               CS_EUC_KR);
1234         SET_MENUITEM(NULL, NULL);
1235         SET_MENUITEM(_("Thai (TIS-620)"),                CS_TIS_620);
1236         SET_MENUITEM(_("Thai (Windows-874)"),            CS_WINDOWS_874);
1237
1238         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_charset),
1239                                   optmenu_menu);
1240
1241         hbox1 = gtk_hbox_new (FALSE, 8);
1242         gtk_widget_show (hbox1);
1243         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
1244
1245         hbox1 = gtk_hbox_new (FALSE, 8);
1246         gtk_widget_show (hbox1);
1247         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
1248
1249         label_encoding = gtk_label_new (_("Transfer encoding"));
1250         gtk_widget_show (label_encoding);
1251         gtk_box_pack_start (GTK_BOX (hbox1), label_encoding, FALSE, FALSE, 0);
1252
1253         encoding_tooltip = gtk_tooltips_new();
1254
1255         optmenu_encoding = gtk_option_menu_new ();
1256         gtk_widget_show (optmenu_encoding);
1257         gtk_tooltips_set_tip(GTK_TOOLTIPS(encoding_tooltip), optmenu_encoding,
1258                              _("Specify Content-Transfer-Encoding used when"
1259                                " message body contains non-ASCII characters"),
1260                              NULL);
1261         gtk_box_pack_start (GTK_BOX (hbox1), optmenu_encoding, FALSE, FALSE, 0);
1262
1263         optmenu_menu = gtk_menu_new ();
1264
1265         SET_MENUITEM(_("Automatic"),     CTE_AUTO);
1266         SET_MENUITEM("base64",           CTE_BASE64);
1267         SET_MENUITEM("quoted-printable", CTE_QUOTED_PRINTABLE);
1268         SET_MENUITEM("8bit",             CTE_8BIT);
1269
1270         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_encoding),
1271                                   optmenu_menu);
1272
1273         hbox1 = gtk_hbox_new (FALSE, 8);
1274         gtk_widget_show (hbox1);
1275         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
1276
1277         p_send.checkbtn_savemsg  = checkbtn_savemsg;
1278         p_send.optmenu_senddialog = optmenu_senddialog;
1279
1280         p_send.optmenu_charset = optmenu_charset;
1281         p_send.optmenu_encoding_method = optmenu_encoding;
1282 }
1283
1284 static void prefs_common_recv_dialog_newmail_notify_toggle_cb(GtkWidget *w, gpointer data)
1285 {
1286         gboolean toggled;
1287
1288         toggled = gtk_toggle_button_get_active
1289                         (GTK_TOGGLE_BUTTON(receive.checkbtn_newmail_manu)) ||
1290                   gtk_toggle_button_get_active
1291                         (GTK_TOGGLE_BUTTON(receive.checkbtn_newmail_auto));
1292         gtk_widget_set_sensitive(receive.hbox_newmail_notify, toggled);
1293 }
1294
1295 static void prefs_message_create(void)
1296 {
1297         GtkWidget *vbox1;
1298         GtkWidget *vbox2;
1299         GtkWidget *vbox3;
1300         GtkWidget *hbox1;
1301         GtkWidget *chkbtn_mbalnum;
1302         GtkWidget *chkbtn_disphdrpane;
1303         GtkWidget *chkbtn_disphdr;
1304         GtkWidget *button_edit_disphdr;
1305         GtkWidget *chkbtn_html;
1306         GtkWidget *chkbtn_cursor;
1307         GtkWidget *hbox_linespc;
1308         GtkWidget *label_linespc;
1309         GtkObject *spinbtn_linespc_adj;
1310         GtkWidget *spinbtn_linespc;
1311
1312         GtkWidget *frame_scr;
1313         GtkWidget *vbox_scr;
1314         GtkWidget *chkbtn_smoothscroll;
1315         GtkWidget *hbox_scr;
1316         GtkWidget *label_scr;
1317         GtkObject *spinbtn_scrollstep_adj;
1318         GtkWidget *spinbtn_scrollstep;
1319         GtkWidget *chkbtn_halfpage;
1320
1321         GtkWidget *chkbtn_attach_desc;
1322
1323         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1324         gtk_widget_show (vbox1);
1325         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1326         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1327
1328         vbox2 = gtk_vbox_new (FALSE, 0);
1329         gtk_widget_show (vbox2);
1330         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
1331
1332         PACK_CHECK_BUTTON
1333                 (vbox2, chkbtn_mbalnum,
1334                  _("Display multi-byte alphanumeric as\n"
1335                    "ASCII character (Japanese only)"));
1336         gtk_label_set_justify (GTK_LABEL (GTK_BIN(chkbtn_mbalnum)->child),
1337                                GTK_JUSTIFY_LEFT);
1338
1339         PACK_CHECK_BUTTON(vbox2, chkbtn_disphdrpane,
1340                           _("Display header pane above message view"));
1341
1342         hbox1 = gtk_hbox_new (FALSE, 8);
1343         gtk_widget_show (hbox1);
1344         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
1345
1346         PACK_CHECK_BUTTON(hbox1, chkbtn_disphdr,
1347                           _("Display short headers on message view"));
1348
1349         button_edit_disphdr = gtk_button_new_with_label (_(" Edit... "));
1350         gtk_widget_show (button_edit_disphdr);
1351         gtk_box_pack_end (GTK_BOX (hbox1), button_edit_disphdr,
1352                           FALSE, TRUE, 0);
1353         g_signal_connect (G_OBJECT (button_edit_disphdr), "clicked",
1354                           G_CALLBACK (prefs_display_header_open),
1355                           NULL);
1356
1357         SET_TOGGLE_SENSITIVITY(chkbtn_disphdr, button_edit_disphdr);
1358
1359         PACK_CHECK_BUTTON(vbox2, chkbtn_html,
1360                           _("Render HTML messages as text"));
1361
1362         PACK_CHECK_BUTTON(vbox2, chkbtn_cursor,
1363                           _("Display cursor in message view"));
1364
1365         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
1366
1367         hbox1 = gtk_hbox_new (FALSE, 32);
1368         gtk_widget_show (hbox1);
1369         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, TRUE, 0);
1370
1371         hbox_linespc = gtk_hbox_new (FALSE, 8);
1372         gtk_widget_show (hbox1);
1373         gtk_box_pack_start (GTK_BOX (hbox1), hbox_linespc, FALSE, TRUE, 0);
1374
1375         label_linespc = gtk_label_new (_("Line space"));
1376         gtk_widget_show (label_linespc);
1377         gtk_box_pack_start (GTK_BOX (hbox_linespc), label_linespc,
1378                             FALSE, FALSE, 0);
1379
1380         spinbtn_linespc_adj = gtk_adjustment_new (2, 0, 16, 1, 1, 16);
1381         spinbtn_linespc = gtk_spin_button_new
1382                 (GTK_ADJUSTMENT (spinbtn_linespc_adj), 1, 0);
1383         gtk_widget_show (spinbtn_linespc);
1384         gtk_box_pack_start (GTK_BOX (hbox_linespc), spinbtn_linespc,
1385                             FALSE, FALSE, 0);
1386         gtk_widget_set_size_request (spinbtn_linespc, 64, -1);
1387         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_linespc), TRUE);
1388
1389         label_linespc = gtk_label_new (_("pixel(s)"));
1390         gtk_widget_show (label_linespc);
1391         gtk_box_pack_start (GTK_BOX (hbox_linespc), label_linespc,
1392                             FALSE, FALSE, 0);
1393
1394         PACK_FRAME(vbox1, frame_scr, _("Scroll"));
1395
1396         vbox_scr = gtk_vbox_new (FALSE, 0);
1397         gtk_widget_show (vbox_scr);
1398         gtk_container_add (GTK_CONTAINER (frame_scr), vbox_scr);
1399         gtk_container_set_border_width (GTK_CONTAINER (vbox_scr), 8);
1400
1401         PACK_CHECK_BUTTON(vbox_scr, chkbtn_halfpage, _("Half page"));
1402
1403         hbox1 = gtk_hbox_new (FALSE, 32);
1404         gtk_widget_show (hbox1);
1405         gtk_box_pack_start (GTK_BOX (vbox_scr), hbox1, FALSE, TRUE, 0);
1406
1407         PACK_CHECK_BUTTON(hbox1, chkbtn_smoothscroll, _("Smooth scroll"));
1408
1409         hbox_scr = gtk_hbox_new (FALSE, 8);
1410         gtk_widget_show (hbox_scr);
1411         gtk_box_pack_start (GTK_BOX (hbox1), hbox_scr, FALSE, FALSE, 0);
1412
1413         label_scr = gtk_label_new (_("Step"));
1414         gtk_widget_show (label_scr);
1415         gtk_box_pack_start (GTK_BOX (hbox_scr), label_scr, FALSE, FALSE, 0);
1416
1417         spinbtn_scrollstep_adj = gtk_adjustment_new (1, 1, 100, 1, 10, 10);
1418         spinbtn_scrollstep = gtk_spin_button_new
1419                 (GTK_ADJUSTMENT (spinbtn_scrollstep_adj), 1, 0);
1420         gtk_widget_show (spinbtn_scrollstep);
1421         gtk_box_pack_start (GTK_BOX (hbox_scr), spinbtn_scrollstep,
1422                             FALSE, FALSE, 0);
1423         gtk_widget_set_size_request (spinbtn_scrollstep, 64, -1);
1424         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_scrollstep),
1425                                      TRUE);
1426
1427         label_scr = gtk_label_new (_("pixel(s)"));
1428         gtk_widget_show (label_scr);
1429         gtk_box_pack_start (GTK_BOX (hbox_scr), label_scr, FALSE, FALSE, 0);
1430
1431         SET_TOGGLE_SENSITIVITY (chkbtn_smoothscroll, hbox_scr)
1432
1433         vbox3 = gtk_vbox_new (FALSE, 0);
1434         gtk_widget_show (vbox3);
1435         gtk_box_pack_start (GTK_BOX (vbox1), vbox3, FALSE, FALSE, 0);
1436
1437         PACK_CHECK_BUTTON(vbox3, chkbtn_attach_desc,
1438                           _("Show attachment descriptions (rather than names)"));
1439
1440         message.chkbtn_mbalnum     = chkbtn_mbalnum;
1441         message.chkbtn_disphdrpane = chkbtn_disphdrpane;
1442         message.chkbtn_disphdr     = chkbtn_disphdr;
1443         message.chkbtn_html        = chkbtn_html;
1444         message.chkbtn_cursor      = chkbtn_cursor;
1445         message.spinbtn_linespc    = spinbtn_linespc;
1446
1447         message.chkbtn_smoothscroll    = chkbtn_smoothscroll;
1448         message.spinbtn_scrollstep     = spinbtn_scrollstep;
1449         message.spinbtn_scrollstep_adj = spinbtn_scrollstep_adj;
1450         message.chkbtn_halfpage        = chkbtn_halfpage;
1451
1452         message.chkbtn_attach_desc  = chkbtn_attach_desc;
1453 }
1454
1455 static void prefs_interface_create(void)
1456 {
1457         GtkWidget *vbox1;
1458         GtkWidget *vbox2;
1459         GtkWidget *vbox3;
1460         /* GtkWidget *checkbtn_emacs; */
1461         GtkWidget *checkbtn_always_show_msg;
1462         GtkWidget *checkbtn_openunread;
1463         GtkWidget *checkbtn_mark_as_read_on_newwin;
1464         GtkWidget *checkbtn_openinbox;
1465         GtkWidget *checkbtn_immedexec;
1466         GtkTooltips *immedexec_tooltip;
1467         GtkWidget *hbox1;
1468         GtkWidget *label;
1469         GtkWidget *menu;
1470         GtkWidget *menuitem;
1471
1472         GtkWidget *button_keybind;
1473
1474         GtkWidget *hbox_nextunreadmsgdialog;
1475         GtkWidget *optmenu_nextunreadmsgdialog;
1476
1477         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1478         gtk_widget_show (vbox1);
1479         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1480         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1481
1482         vbox2 = gtk_vbox_new (FALSE, 0);
1483         gtk_widget_show (vbox2);
1484         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
1485
1486         /* PACK_CHECK_BUTTON (vbox2, checkbtn_emacs,
1487                            _("Emulate the behavior of mouse operation of\n"
1488                              "Emacs-based mailer"));
1489         gtk_label_set_justify (GTK_LABEL (GTK_BIN (checkbtn_emacs)->child),
1490                                GTK_JUSTIFY_LEFT);   */
1491
1492         PACK_CHECK_BUTTON
1493                 (vbox2, checkbtn_always_show_msg,
1494                  _("Always open messages in summary when selected"));
1495
1496         PACK_CHECK_BUTTON
1497                 (vbox2, checkbtn_openunread,
1498                  _("Open first unread message when entering a folder"));
1499
1500         PACK_CHECK_BUTTON
1501                 (vbox2, checkbtn_mark_as_read_on_newwin,
1502                  _("Only mark message as read when opened in new window"));
1503
1504         PACK_CHECK_BUTTON
1505                 (vbox2, checkbtn_openinbox,
1506                  _("Go to inbox after receiving new mail"));
1507
1508         vbox3 = gtk_vbox_new (FALSE, 0);
1509         gtk_widget_show (vbox3);
1510         gtk_box_pack_start (GTK_BOX (vbox2), vbox3, FALSE, FALSE, 0);
1511
1512         immedexec_tooltip = gtk_tooltips_new();
1513
1514         PACK_CHECK_BUTTON
1515                 (vbox3, checkbtn_immedexec,
1516                  _("Execute immediately when moving or deleting messages"));
1517         gtk_tooltips_set_tip(GTK_TOOLTIPS(immedexec_tooltip), checkbtn_immedexec,
1518                              _("Messages will be marked until execution"
1519                                " if this is turned off"),
1520                              NULL);
1521
1522         hbox1 = gtk_hbox_new (FALSE, 0);
1523         gtk_widget_show (hbox1);
1524         gtk_box_pack_start (GTK_BOX (vbox3), hbox1, FALSE, FALSE, 0);
1525
1526         /* Next Unread Message Dialog */
1527         hbox_nextunreadmsgdialog = gtk_hbox_new (FALSE, 8);
1528         gtk_widget_show (hbox1);
1529         gtk_box_pack_start (GTK_BOX (vbox1), hbox_nextunreadmsgdialog, FALSE, FALSE, 0);
1530
1531         label = gtk_label_new (_("Show no-unread-message dialog"));
1532         gtk_widget_show (label);
1533         gtk_box_pack_start (GTK_BOX (hbox_nextunreadmsgdialog), label, FALSE, FALSE, 8);
1534
1535         optmenu_nextunreadmsgdialog = gtk_option_menu_new ();
1536         gtk_widget_show (optmenu_nextunreadmsgdialog);
1537         gtk_box_pack_start (GTK_BOX (hbox_nextunreadmsgdialog), optmenu_nextunreadmsgdialog, FALSE, FALSE, 8);
1538         
1539         menu = gtk_menu_new ();
1540         MENUITEM_ADD (menu, menuitem, _("Always"), NEXTUNREADMSGDIALOG_ALWAYS);
1541         MENUITEM_ADD (menu, menuitem, _("Assume 'Yes'"), 
1542                       NEXTUNREADMSGDIALOG_ASSUME_YES);
1543         MENUITEM_ADD (menu, menuitem, _("Assume 'No'"), 
1544                       NEXTUNREADMSGDIALOG_ASSUME_NO);
1545
1546         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu_nextunreadmsgdialog), menu);
1547
1548         hbox1 = gtk_hbox_new (FALSE, 8);
1549         gtk_widget_show (hbox1);
1550         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
1551
1552         button_keybind = gtk_button_new_with_label (_(" Set key bindings... "));
1553         gtk_widget_show (button_keybind);
1554         gtk_box_pack_start (GTK_BOX (hbox1), button_keybind, FALSE, FALSE, 0);
1555         g_signal_connect (G_OBJECT (button_keybind), "clicked",
1556                           G_CALLBACK (prefs_keybind_select), NULL);
1557
1558         /* interface.checkbtn_emacs          = checkbtn_emacs; */
1559         interface.checkbtn_always_show_msg    = checkbtn_always_show_msg;
1560         interface.checkbtn_openunread         = checkbtn_openunread;
1561         interface.checkbtn_mark_as_read_on_newwin
1562                                               = checkbtn_mark_as_read_on_newwin;
1563         interface.checkbtn_openinbox          = checkbtn_openinbox;
1564         interface.checkbtn_immedexec          = checkbtn_immedexec;
1565         interface.optmenu_nextunreadmsgdialog = optmenu_nextunreadmsgdialog;
1566 }
1567
1568 static void prefs_other_create(void)
1569 {
1570         GtkWidget *vbox1;
1571         GtkWidget *hbox1;
1572
1573         GtkWidget *frame_addr;
1574         GtkWidget *vbox_addr;
1575         GtkWidget *checkbtn_addaddrbyclick;
1576         
1577         GtkWidget *frame_cliplog;
1578         GtkWidget *vbox_cliplog;
1579         GtkWidget *hbox_cliplog;
1580         GtkWidget *checkbtn_cliplog;
1581         GtkWidget *loglength_label;
1582         GtkWidget *loglength_entry;
1583         GtkTooltips *loglength_tooltip;
1584
1585         GtkWidget *frame_exit;
1586         GtkWidget *vbox_exit;
1587         GtkWidget *checkbtn_confonexit;
1588         GtkWidget *checkbtn_cleanonexit;
1589         GtkWidget *checkbtn_askonclean;
1590         GtkWidget *checkbtn_warnqueued;
1591
1592         GtkWidget *label_iotimeout;
1593         GtkWidget *spinbtn_iotimeout;
1594         GtkObject *spinbtn_iotimeout_adj;
1595
1596 #if 0
1597 #ifdef USE_OPENSSL
1598         GtkWidget *frame_ssl;
1599         GtkWidget *vbox_ssl;
1600         GtkWidget *hbox_ssl;
1601         GtkWidget *checkbtn_ssl_ask_unknown_valid;
1602 #endif
1603 #endif
1604         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1605         gtk_widget_show (vbox1);
1606         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1607         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1608
1609         PACK_FRAME (vbox1, frame_addr, _("Address book"));
1610
1611         vbox_addr = gtk_vbox_new (FALSE, 0);
1612         gtk_widget_show (vbox_addr);
1613         gtk_container_add (GTK_CONTAINER (frame_addr), vbox_addr);
1614         gtk_container_set_border_width (GTK_CONTAINER (vbox_addr), 8);
1615
1616         PACK_CHECK_BUTTON
1617                 (vbox_addr, checkbtn_addaddrbyclick,
1618                  _("Add address to destination when double-clicked"));
1619
1620         /* Clip Log */
1621         PACK_FRAME (vbox1, frame_cliplog, _("Log Size"));
1622
1623         vbox_cliplog = gtk_vbox_new (FALSE, 0);
1624         gtk_widget_show (vbox_cliplog);
1625         gtk_container_add (GTK_CONTAINER (frame_cliplog), vbox_cliplog);
1626         gtk_container_set_border_width (GTK_CONTAINER (vbox_cliplog), 8);
1627         PACK_CHECK_BUTTON (vbox_cliplog, checkbtn_cliplog,
1628                            _("Clip the log size"));
1629         hbox_cliplog = gtk_hbox_new (FALSE, 3);
1630         gtk_container_add (GTK_CONTAINER (vbox_cliplog), hbox_cliplog);
1631         gtk_widget_show (hbox_cliplog);
1632         
1633         loglength_label = gtk_label_new (_("Log window length"));
1634         gtk_box_pack_start (GTK_BOX (hbox_cliplog), loglength_label,
1635                             FALSE, TRUE, 0);
1636         gtk_widget_show (GTK_WIDGET (loglength_label));
1637         
1638         loglength_tooltip = gtk_tooltips_new();
1639         
1640         loglength_entry = gtk_entry_new ();
1641         gtk_widget_set_size_request (GTK_WIDGET (loglength_entry), 64, -1);
1642         gtk_box_pack_start (GTK_BOX (hbox_cliplog), loglength_entry,
1643                             FALSE, TRUE, 0);
1644         gtk_widget_show (GTK_WIDGET (loglength_entry));
1645         gtk_tooltips_set_tip(GTK_TOOLTIPS(loglength_tooltip), loglength_entry,
1646                              _("0 to stop logging in the log window"),
1647                              NULL);
1648         SET_TOGGLE_SENSITIVITY(checkbtn_cliplog, loglength_entry);
1649
1650 #if 0
1651 #ifdef USE_OPENSSL
1652         /* SSL */
1653         PACK_FRAME (vbox1, frame_ssl, _("Security"));
1654
1655         vbox_ssl = gtk_vbox_new (FALSE, 0);
1656         gtk_widget_show (vbox_ssl);
1657         gtk_container_add (GTK_CONTAINER (frame_ssl), vbox_ssl);
1658         gtk_container_set_border_width (GTK_CONTAINER (vbox_ssl), 8);
1659         PACK_CHECK_BUTTON (vbox_ssl, checkbtn_ssl_ask_unknown_valid, 
1660                            _("Ask before accepting SSL certificates"));
1661         hbox_ssl = gtk_hbox_new (FALSE, 3);
1662         gtk_container_add (GTK_CONTAINER (vbox_ssl), hbox_ssl);
1663         gtk_widget_show (hbox_ssl);
1664 #endif
1665 #endif
1666         
1667         /* On Exit */
1668         PACK_FRAME (vbox1, frame_exit, _("On exit"));
1669
1670         vbox_exit = gtk_vbox_new (FALSE, 0);
1671         gtk_widget_show (vbox_exit);
1672         gtk_container_add (GTK_CONTAINER (frame_exit), vbox_exit);
1673         gtk_container_set_border_width (GTK_CONTAINER (vbox_exit), 8);
1674
1675         PACK_CHECK_BUTTON (vbox_exit, checkbtn_confonexit,
1676                            _("Confirm on exit"));
1677
1678         hbox1 = gtk_hbox_new (FALSE, 32);
1679         gtk_widget_show (hbox1);
1680         gtk_box_pack_start (GTK_BOX (vbox_exit), hbox1, FALSE, FALSE, 0);
1681
1682         PACK_CHECK_BUTTON (hbox1, checkbtn_cleanonexit,
1683                            _("Empty trash on exit"));
1684         PACK_CHECK_BUTTON (hbox1, checkbtn_askonclean,
1685                            _("Ask before emptying"));
1686         SET_TOGGLE_SENSITIVITY (checkbtn_cleanonexit, checkbtn_askonclean);
1687
1688         PACK_CHECK_BUTTON (vbox_exit, checkbtn_warnqueued,
1689                            _("Warn if there are queued messages"));
1690
1691         hbox1 = gtk_hbox_new (FALSE, 8);
1692         gtk_widget_show (hbox1);
1693         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
1694
1695         label_iotimeout = gtk_label_new (_("Socket I/O timeout:"));
1696         gtk_widget_show (label_iotimeout);
1697         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
1698
1699         spinbtn_iotimeout_adj = gtk_adjustment_new (60, 0, 1000, 1, 10, 10);
1700         spinbtn_iotimeout = gtk_spin_button_new
1701                 (GTK_ADJUSTMENT (spinbtn_iotimeout_adj), 1, 0);
1702         gtk_widget_show (spinbtn_iotimeout);
1703         gtk_box_pack_start (GTK_BOX (hbox1), spinbtn_iotimeout,
1704                             FALSE, FALSE, 0);
1705         gtk_widget_set_size_request (spinbtn_iotimeout, 64, -1);
1706         gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_iotimeout), TRUE);
1707
1708         label_iotimeout = gtk_label_new (_("seconds"));
1709         gtk_widget_show (label_iotimeout);
1710         gtk_box_pack_start (GTK_BOX (hbox1), label_iotimeout, FALSE, FALSE, 0);
1711
1712         other.checkbtn_addaddrbyclick = checkbtn_addaddrbyclick;
1713         
1714         other.checkbtn_cliplog     = checkbtn_cliplog;
1715         other.loglength_entry      = loglength_entry;
1716
1717         other.checkbtn_confonexit  = checkbtn_confonexit;
1718         other.checkbtn_cleanonexit = checkbtn_cleanonexit;
1719         other.checkbtn_askonclean  = checkbtn_askonclean;
1720         other.checkbtn_warnqueued  = checkbtn_warnqueued;
1721
1722         other.spinbtn_iotimeout     = spinbtn_iotimeout;
1723         other.spinbtn_iotimeout_adj = spinbtn_iotimeout_adj;
1724         
1725 #if 0
1726 #ifdef USE_OPENSSL
1727         other.checkbtn_ssl_ask_unknown_valid = checkbtn_ssl_ask_unknown_valid;
1728 #endif
1729 #endif
1730 }
1731
1732 static void date_format_ok_btn_clicked(GtkButton *button, GtkWidget **widget)
1733 {
1734         GtkWidget *datefmt_sample = NULL;
1735         gchar *text;
1736
1737         g_return_if_fail(widget != NULL);
1738         g_return_if_fail(*widget != NULL);
1739         g_return_if_fail(display.entry_datefmt != NULL);
1740
1741         datefmt_sample = GTK_WIDGET(g_object_get_data
1742                                     (G_OBJECT(*widget), "datefmt_sample"));
1743         g_return_if_fail(datefmt_sample != NULL);
1744
1745         text = gtk_editable_get_chars(GTK_EDITABLE(datefmt_sample), 0, -1);
1746         g_free(prefs_common.date_format);
1747         prefs_common.date_format = text;
1748         gtk_entry_set_text(GTK_ENTRY(display.entry_datefmt), text);
1749
1750         gtk_widget_destroy(*widget);
1751         *widget = NULL;
1752 }
1753
1754 static void date_format_cancel_btn_clicked(GtkButton *button,
1755                                            GtkWidget **widget)
1756 {
1757         g_return_if_fail(widget != NULL);
1758         g_return_if_fail(*widget != NULL);
1759
1760         gtk_widget_destroy(*widget);
1761         *widget = NULL;
1762 }
1763
1764 static gboolean date_format_key_pressed(GtkWidget *keywidget, GdkEventKey *event,
1765                                         GtkWidget **widget)
1766 {
1767         if (event && event->keyval == GDK_Escape)
1768                 date_format_cancel_btn_clicked(NULL, widget);
1769         return FALSE;
1770 }
1771
1772 static gboolean date_format_on_delete(GtkWidget *dialogwidget,
1773                                       GdkEventAny *event, GtkWidget **widget)
1774 {
1775         g_return_val_if_fail(widget != NULL, FALSE);
1776         g_return_val_if_fail(*widget != NULL, FALSE);
1777
1778         *widget = NULL;
1779         return FALSE;
1780 }
1781
1782 static void date_format_entry_on_change(GtkEditable *editable,
1783                                         GtkLabel *example)
1784 {
1785         time_t cur_time;
1786         struct tm *cal_time;
1787         gchar buffer[100];
1788         gchar *text;
1789
1790         cur_time = time(NULL);
1791         cal_time = localtime(&cur_time);
1792         buffer[0] = 0;
1793         text = gtk_editable_get_chars(editable, 0, -1);
1794         if (text)
1795                 strftime(buffer, sizeof buffer, text, cal_time); 
1796         g_free(text);
1797
1798         text = conv_codeset_strdup(buffer,
1799                                    conv_get_locale_charset_str(),
1800                                    CS_UTF_8);
1801         if (!text)
1802                 text = g_strdup(buffer);
1803
1804         gtk_label_set_text(example, text);
1805
1806         g_free(text);
1807 }
1808
1809 static void date_format_select_row(GtkTreeView *list_view,
1810                                    GtkTreePath *path,
1811                                    GtkTreeViewColumn *column,
1812                                    GtkWidget *date_format)
1813 {
1814         gint cur_pos;
1815         gchar *format;
1816         const gchar *old_format;
1817         gchar *new_format;
1818         GtkWidget *datefmt_sample;
1819         GtkTreeIter iter;
1820         GtkTreeModel *model;
1821         
1822         g_return_if_fail(date_format != NULL);
1823
1824         /* only on double click */
1825         datefmt_sample = GTK_WIDGET(g_object_get_data(G_OBJECT(date_format), 
1826                                                       "datefmt_sample"));
1827
1828         g_return_if_fail(datefmt_sample != NULL);
1829
1830         model = gtk_tree_view_get_model(list_view);
1831
1832         /* get format from list */
1833         if (!gtk_tree_model_get_iter(model, &iter, path))
1834                 return;
1835
1836         gtk_tree_model_get(model, &iter, DATEFMT_FMT, &format, -1);             
1837         
1838         cur_pos = gtk_editable_get_position(GTK_EDITABLE(datefmt_sample));
1839         old_format = gtk_entry_get_text(GTK_ENTRY(datefmt_sample));
1840
1841         /* insert the format into the text entry */
1842         new_format = g_malloc(strlen(old_format) + 3);
1843
1844         strncpy(new_format, old_format, cur_pos);
1845         new_format[cur_pos] = '\0';
1846         strcat(new_format, format);
1847         strcat(new_format, &old_format[cur_pos]);
1848
1849         gtk_entry_set_text(GTK_ENTRY(datefmt_sample), new_format);
1850         gtk_editable_set_position(GTK_EDITABLE(datefmt_sample), cur_pos + 2);
1851
1852         g_free(new_format);
1853 }
1854
1855 static void prefs_keybind_select(void)
1856 {
1857         GtkWidget *window;
1858         GtkWidget *vbox1;
1859         GtkWidget *hbox1;
1860         GtkWidget *label;
1861         GtkWidget *combo;
1862         GtkWidget *confirm_area;
1863         GtkWidget *ok_btn;
1864         GtkWidget *cancel_btn;
1865
1866         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1867         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
1868         gtk_window_set_title (GTK_WINDOW (window), _("Key bindings"));
1869         gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
1870         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
1871         gtk_window_set_resizable(GTK_WINDOW (window), FALSE);
1872         manage_window_set_transient (GTK_WINDOW (window));
1873
1874         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1875         gtk_container_add (GTK_CONTAINER (window), vbox1);
1876         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
1877
1878         hbox1 = gtk_hbox_new (FALSE, 8);
1879         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
1880
1881         label = gtk_label_new
1882                 (_("Select preset:"));
1883         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1884         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1885
1886         hbox1 = gtk_hbox_new (FALSE, 8);
1887         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
1888
1889         combo = gtk_combo_new ();
1890         gtk_box_pack_start (GTK_BOX (hbox1), combo, TRUE, TRUE, 0);
1891         gtkut_combo_set_items (GTK_COMBO (combo),
1892                                _("Default"),
1893                                "Mew / Wanderlust",
1894                                "Mutt",
1895                                _("Old Sylpheed"),
1896                                NULL);
1897         gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO (combo)->entry), FALSE);
1898
1899         hbox1 = gtk_hbox_new (FALSE, 8);
1900         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
1901
1902         label = gtk_label_new
1903                 (_("You can also modify each menu shortcut by pressing\n"
1904                    "any key(s) when placing the mouse pointer on the item."));
1905         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1906         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1907
1908         hbox1 = gtk_hbox_new (FALSE, 8);
1909         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
1910
1911         gtkut_stock_button_set_create (&confirm_area, &ok_btn, GTK_STOCK_OK,
1912                                        &cancel_btn, GTK_STOCK_CANCEL,
1913                                        NULL, NULL);
1914         gtk_box_pack_end (GTK_BOX (hbox1), confirm_area, FALSE, FALSE, 0);
1915         gtk_widget_grab_default (ok_btn);
1916
1917         MANAGE_WINDOW_SIGNALS_CONNECT(window);
1918         g_signal_connect (G_OBJECT (window), "delete_event",
1919                           G_CALLBACK (prefs_keybind_deleted), NULL);
1920         g_signal_connect (G_OBJECT (window), "key_press_event",
1921                           G_CALLBACK (prefs_keybind_key_pressed), NULL);
1922         g_signal_connect (G_OBJECT (ok_btn), "clicked",
1923                           G_CALLBACK (prefs_keybind_apply_clicked),
1924                           NULL);
1925         g_signal_connect (G_OBJECT (cancel_btn), "clicked",
1926                           G_CALLBACK (prefs_keybind_cancel),
1927                           NULL);
1928
1929         gtk_widget_show_all(window);
1930
1931         keybind.window = window;
1932         keybind.combo = combo;
1933 }
1934
1935 static gboolean prefs_keybind_key_pressed(GtkWidget *widget, GdkEventKey *event,
1936                                           gpointer data)
1937 {
1938         if (event && event->keyval == GDK_Escape)
1939                 prefs_keybind_cancel();
1940         return FALSE;
1941 }
1942
1943 static gint prefs_keybind_deleted(GtkWidget *widget, GdkEventAny *event,
1944                                   gpointer data)
1945 {
1946         prefs_keybind_cancel();
1947         return TRUE;
1948 }
1949
1950 static void prefs_keybind_cancel(void)
1951 {
1952         gtk_widget_destroy(keybind.window);
1953         keybind.window = NULL;
1954         keybind.combo = NULL;
1955 }
1956   
1957 struct KeyBind {
1958         const gchar *accel_path;
1959         const gchar *accel_key;
1960 };
1961
1962 static void prefs_keybind_apply(struct KeyBind keybind[], gint num)
1963 {
1964         gint i;
1965         guint key;
1966         GdkModifierType mods;
1967
1968         for (i = 0; i < num; i++) {
1969                 const gchar *accel_key
1970                         = keybind[i].accel_key ? keybind[i].accel_key : "";
1971                 gtk_accelerator_parse(accel_key, &key, &mods);
1972                 gtk_accel_map_change_entry(keybind[i].accel_path,
1973                                            key, mods, TRUE);
1974         }
1975 }
1976
1977 static void prefs_keybind_apply_clicked(GtkWidget *widget)
1978 {
1979         GtkEntry *entry = GTK_ENTRY(GTK_COMBO(keybind.combo)->entry);
1980         const gchar *text;
1981         struct KeyBind *menurc;
1982         gint n_menurc;
1983
1984         static struct KeyBind default_menurc[] = {
1985                 {"<Main>/File/Empty all Trash folders",         ""},
1986                 {"<Main>/File/Save as...",                      "<control>S"},
1987                 {"<Main>/File/Print...",                        ""},
1988                 {"<Main>/File/Exit",                            "<control>Q"},
1989
1990                 {"<Main>/Edit/Copy",                            "<control>C"},
1991                 {"<Main>/Edit/Select all",                      "<control>A"},
1992                 {"<Main>/Edit/Find in current message...",      "<control>F"},
1993                 {"<Main>/Edit/Search folder...",                "<shift><control>F"},
1994
1995                 {"<Main>/View/Show or hide/Message View",       "V"},
1996                 {"<Main>/View/Thread view",                     "<control>T"},
1997                 {"<Main>/View/Go to/Prev message",              "P"},
1998                 {"<Main>/View/Go to/Next message",              "N"},
1999                 {"<Main>/View/Go to/Prev unread message",       "<shift>P"},
2000                 {"<Main>/View/Go to/Next unread message",       "<shift>N"},
2001                 {"<Main>/View/Go to/Other folder...",           "G"},
2002                 {"<Main>/View/Open in new window",              "<control><alt>N"},
2003                 {"<Main>/View/Message source",                  "<control>U"},
2004                 {"<Main>/View/Show all headers",                "<control>H"},
2005                 {"<Main>/View/Update summary",                  "<control><alt>U"},
2006
2007                 {"<Main>/Message/Receive/Get from current account",
2008                                                                 "<control>I"},
2009                 {"<Main>/Message/Receive/Get from all accounts","<shift><control>I"},
2010                 {"<Main>/Message/Compose an email message",     "<control>M"},
2011                 {"<Main>/Message/Reply",                        "<control>R"},
2012                 {"<Main>/Message/Reply to/all",                 "<shift><control>R"},
2013                 {"<Main>/Message/Reply to/sender",              ""},
2014                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
2015                 {"<Main>/Message/Forward",                      "<control><alt>F"},
2016                 /* {"<Main>/Message/Forward as attachment",      ""}, */
2017                 {"<Main>/Message/Move...",                      "<control>O"},
2018                 {"<Main>/Message/Copy...",                      "<shift><control>O"},
2019                 {"<Main>/Message/Delete",                       "<control>D"},
2020                 {"<Main>/Message/Mark/Mark",                    "<shift>asterisk"},
2021                 {"<Main>/Message/Mark/Unmark",                  "U"},
2022                 {"<Main>/Message/Mark/Mark as unread",          "<shift>exclam"},
2023                 {"<Main>/Message/Mark/Mark as read",            ""},
2024
2025                 {"<Main>/Tools/Address book",                   "<shift><control>A"},
2026                 {"<Main>/Tools/Execute",                        "X"},
2027                 {"<Main>/Tools/Log window",                     "<shift><control>L"},
2028
2029                 {"<Compose>/Message/Close",                             "<control>W"},
2030                 {"<Compose>/Edit/Select all",                           "<control>A"},
2031                 {"<Compose>/Edit/Advanced/Move a word backward",        ""},
2032                 {"<Compose>/Edit/Advanced/Move a word forward",         ""},
2033                 {"<Compose>/Edit/Advanced/Move to beginning of line",   ""},
2034                 {"<Compose>/Edit/Advanced/Delete a word backward",      ""},
2035                 {"<Compose>/Edit/Advanced/Delete a word forward",       ""},
2036         };
2037
2038         static struct KeyBind mew_wl_menurc[] = {
2039                 {"<Main>/File/Empty all Trash folders",                 "<shift>D"},
2040                 {"<Main>/File/Save as...",                      "Y"},
2041                 {"<Main>/File/Print...",                        "<shift>numbersign"},
2042                 {"<Main>/File/Exit",                            "<shift>Q"},
2043
2044                 {"<Main>/Edit/Copy",                            "<control>C"},
2045                 {"<Main>/Edit/Select all",                      "<control>A"},
2046                 {"<Main>/Edit/Find in current message...",      "<control>F"},
2047                 {"<Main>/Edit/Search folder...",                "<control>S"},
2048
2049                 {"<Main>/View/Show or hide/Message View",       ""},
2050                 {"<Main>/View/Thread view",                     "<shift>T"},
2051                 {"<Main>/View/Go to/Prev message",              "P"},
2052                 {"<Main>/View/Go to/Next message",              "N"},
2053                 {"<Main>/View/Go to/Prev unread message",       "<shift>P"},
2054                 {"<Main>/View/Go to/Next unread message",       "<shift>N"},
2055                 {"<Main>/View/Go to/Other folder...",           "G"},
2056                 {"<Main>/View/Open in new window",              "<control><alt>N"},
2057                 {"<Main>/View/Message source",                  "<control>U"},
2058                 {"<Main>/View/Show all headers",                "<shift>H"},
2059                 {"<Main>/View/Update summary",                  "<shift>S"},
2060
2061                 {"<Main>/Message/Receive/Get from current account",
2062                                                                 "<control>I"},
2063                 {"<Main>/Message/Receive/Get from all accounts","<shift><control>I"},
2064                 {"<Main>/Message/Compose an email message",     "W"},
2065                 {"<Main>/Message/Reply",                        "<control>R"},
2066                 {"<Main>/Message/Reply to/all",                 "<shift>A"},
2067                 {"<Main>/Message/Reply to/sender",              ""},
2068                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
2069                 {"<Main>/Message/Forward",                      "F"},
2070                 /* {"<Main>/Message/Forward as attachment", "<shift>F"}, */
2071                 {"<Main>/Message/Move...",                      "O"},
2072                 {"<Main>/Message/Copy...",                      "<shift>O"},
2073                 {"<Main>/Message/Delete",                       "D"},
2074                 {"<Main>/Message/Mark/Mark",                    "<shift>asterisk"},
2075                 {"<Main>/Message/Mark/Unmark",                  "U"},
2076                 {"<Main>/Message/Mark/Mark as unread",          "<shift>exclam"},
2077                 {"<Main>/Message/Mark/Mark as read",            "<shift>R"},
2078
2079                 {"<Main>/Tools/Address book",                   "<shift><control>A"},
2080                 {"<Main>/Tools/Execute",                        "X"},
2081                 {"<Main>/Tools/Log window",                     "<shift><control>L"},
2082
2083                 {"<Compose>/Message/Close",                             "<alt>W"},
2084                 {"<Compose>/Edit/Select all",                           ""},
2085                 {"<Compose>/Edit/Advanced/Move a word backward,"        "<alt>B"},
2086                 {"<Compose>/Edit/Advanced/Move a word forward",         "<alt>F"},
2087                 {"<Compose>/Edit/Advanced/Move to beginning of line",   "<control>A"},
2088                 {"<Compose>/Edit/Advanced/Delete a word backward",      "<control>W"},
2089                 {"<Compose>/Edit/Advanced/Delete a word forward",       "<alt>D"},
2090         };
2091
2092         static struct KeyBind mutt_menurc[] = {
2093                 {"<Main>/File/Empty all Trash folders",         ""},
2094                 {"<Main>/File/Save as...",                      "S"},
2095                 {"<Main>/File/Print...",                        "P"},
2096                 {"<Main>/File/Exit",                            "Q"},
2097
2098                 {"<Main>/Edit/Copy",                            "<control>C"},
2099                 {"<Main>/Edit/Select all",                      "<control>A"},
2100                 {"<Main>/Edit/Find in current message...",      "<control>F"},
2101                 {"<Main>/Edit/Search messages...",              "slash"},
2102
2103                 {"<Main>/View/Show or hide/Message view",       "V"},
2104                 {"<Main>/View/Thread view",                     "<control>T"},
2105                 {"<Main>/View/Go to/Prev message",              ""},
2106                 {"<Main>/View/Go to/Next message",              ""},
2107                 {"<Main>/View/Go to/Prev unread message",       ""},
2108                 {"<Main>/View/Go to/Next unread message",       ""},
2109                 {"<Main>/View/Go to/Other folder...",           "C"},
2110                 {"<Main>/View/Open in new window",              "<control><alt>N"},
2111                 {"<Main>/View/Message source",                  "<control>U"},
2112                 {"<Main>/View/Show all headers",                "<control>H"},
2113                 {"<Main>/View/Update summary",                          "<control><alt>U"},
2114
2115                 {"<Main>/Message/Receive/Get from current account",
2116                                                                 "<control>I"},
2117                 {"<Main>/Message/Receive/Get from all accounts","<shift><control>I"},
2118                 {"<Main>/Message/Compose an email message",             "M"},
2119                 {"<Main>/Message/Reply",                        "R"},
2120                 {"<Main>/Message/Reply to/all",                 "G"},
2121                 {"<Main>/Message/Reply to/sender",              ""},
2122                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
2123                 {"<Main>/Message/Forward",                      "F"},
2124                 {"<Main>/Message/Forward as attachment",        ""},
2125                 {"<Main>/Message/Move...",                      "<control>O"},
2126                 {"<Main>/Message/Copy...",                      "<shift>C"},
2127                 {"<Main>/Message/Delete",                       "D"},
2128                 {"<Main>/Message/Mark/Mark",                    "<shift>F"},
2129                 {"<Main>/Message/Mark/Unmark",                  "U"},
2130                 {"<Main>/Message/Mark/Mark as unread",          "<shift>N"},
2131                 {"<Main>/Message/Mark/Mark as read",            ""},
2132
2133                 {"<Main>/Tools/Address book",                   "<shift><control>A"},
2134                 {"<Main>/Tools/Execute",                        "X"},
2135                 {"<Main>/Tools/Log window",                     "<shift><control>L"},
2136
2137                 {"<Compose>/Message/Close",                             "<alt>W"},
2138                 {"<Compose>/Edit/Select all",                           ""},
2139                 {"<Compose>/Edit/Advanced/Move a word backward",        "<alt>B"},
2140                 {"<Compose>/Edit/Advanced/Move a word forward",         "<alt>F"},
2141                 {"<Compose>/Edit/Advanced/Move to beginning of line",   "<control>A"},
2142                 {"<Compose>/Edit/Advanced/Delete a word backward",      "<control>W"},
2143                 {"<Compose>/Edit/Advanced/Delete a word forward",       "<alt>D"},
2144         };
2145
2146         static struct KeyBind old_sylpheed_menurc[] = {
2147                 {"<Main>/File/Empty all Trash folders",         ""},
2148                 {"<Main>/File/Save as...",                      ""},
2149                 {"<Main>/File/Print...",                        "<alt>P"},
2150                 {"<Main>/File/Exit",                            "<alt>Q"},
2151
2152                 {"<Main>/Edit/Copy",                            "<control>C"},
2153                 {"<Main>/Edit/Select all",                      "<control>A"},
2154                 {"<Main>/Edit/Find in current message...",      "<control>F"},
2155                 {"<Main>/Edit/Search folder...",                "<control>S"},
2156
2157                 {"<Main>/View/Show or hide/Message View",       ""},
2158                 {"<Main>/View/Thread view",                     "<control>T"},
2159                 {"<Main>/View/Go to/Prev message",              "P"},
2160                 {"<Main>/View/Go to/Next message",              "N"},
2161                 {"<Main>/View/Go to/Prev unread message",       "<shift>P"},
2162                 {"<Main>/View/Go to/Next unread message",       "<shift>N"},
2163                 {"<Main>/View/Go to/Other folder...",           "<alt>G"},
2164                 {"<Main>/View/Open in new window",              "<shift><control>N"},
2165                 {"<Main>/View/Message source",                  "<control>U"},
2166                 {"<Main>/View/Show all headers",                "<control>H"},
2167                 {"<Main>/View/Update summary",                  "<alt>U"},
2168
2169                 {"<Main>/Message/Receive/Get from current account",
2170                                                                 "<alt>I"},
2171                 {"<Main>/Message/Receive/Get from all accounts","<shift><alt>I"},
2172                 {"<Main>/Message/Compose an email message",     "<alt>N"},
2173                 {"<Main>/Message/Reply",                        "<alt>R"},
2174                 {"<Main>/Message/Reply to/all",                 "<shift><alt>R"},
2175                 {"<Main>/Message/Reply to/sender",              "<control><alt>R"},
2176                 {"<Main>/Message/Reply to/mailing list",        "<control>L"},
2177                 {"<Main>/Message/Forward",                       "<shift><alt>F"},
2178                 /* "(menu-path \"<Main>/Message/Forward as attachment", "<shift><control>F"}, */
2179                 {"<Main>/Message/Move...",                      "<alt>O"},
2180                 {"<Main>/Message/Copy...",                      ""},
2181                 {"<Main>/Message/Delete",                       "<alt>D"},
2182                 {"<Main>/Message/Mark/Mark",                    "<shift>asterisk"},
2183                 {"<Main>/Message/Mark/Unmark",                  "U"},
2184                 {"<Main>/Message/Mark/Mark as unread",          "<shift>exclam"},
2185                 {"<Main>/Message/Mark/Mark as read",            ""},
2186
2187                 {"<Main>/Tools/Address book",                   "<alt>A"},
2188                 {"<Main>/Tools/Execute",                        "<alt>X"},
2189                 {"<Main>/Tools/Log window",                     "<alt>L"},
2190
2191                 {"<Compose>/Message/Close",                             "<alt>W"},
2192                 {"<Compose>/Edit/Select all",                           ""},
2193                 {"<Compose>/Edit/Advanced/Move a word backward",        "<alt>B"},
2194                 {"<Compose>/Edit/Advanced/Move a word forward",         "<alt>F"},
2195                 {"<Compose>/Edit/Advanced/Move to beginning of line",   "<control>A"},
2196                 {"<Compose>/Edit/Advanced/Delete a word backward",      "<control>W"},
2197                 {"<Compose>/Edit/Advanced/Delete a word forward",       "<alt>D"},
2198         };
2199   
2200         text = gtk_entry_get_text(entry);
2201   
2202         if (!strcmp(text, _("Default"))) {
2203                 menurc = default_menurc;
2204                 n_menurc = G_N_ELEMENTS(default_menurc);
2205         } else if (!strcmp(text, "Mew / Wanderlust")) {
2206                 menurc = mew_wl_menurc;
2207                 n_menurc = G_N_ELEMENTS(mew_wl_menurc);
2208         } else if (!strcmp(text, "Mutt")) {
2209                 menurc = mutt_menurc;
2210                 n_menurc = G_N_ELEMENTS(mutt_menurc);
2211         } else if (!strcmp(text, _("Old Sylpheed"))) {
2212                 menurc = old_sylpheed_menurc;
2213                 n_menurc = G_N_ELEMENTS(old_sylpheed_menurc);
2214         } else {
2215                 return;
2216         }
2217
2218         /* prefs_keybind_apply(empty_menurc, G_N_ELEMENTS(empty_menurc)); */
2219         prefs_keybind_apply(menurc, n_menurc);
2220
2221         gtk_widget_destroy(keybind.window);
2222         keybind.window = NULL;
2223         keybind.combo = NULL;
2224 }
2225
2226 static void prefs_common_charset_set_data_from_optmenu(PrefParam *pparam)
2227 {
2228         GtkWidget *menu;
2229         GtkWidget *menuitem;
2230         gchar *charset;
2231
2232         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2233         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2234         charset = g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID);
2235         g_free(*((gchar **)pparam->data));
2236         *((gchar **)pparam->data) = g_strdup(charset);
2237 }
2238
2239 static void prefs_common_charset_set_optmenu(PrefParam *pparam)
2240 {
2241         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2242         gint index;
2243
2244         g_return_if_fail(optmenu != NULL);
2245         g_return_if_fail(*((gchar **)pparam->data) != NULL);
2246
2247         index = menu_find_option_menu_index(optmenu, *((gchar **)pparam->data),
2248                                             (GCompareFunc)strcmp2);
2249         if (index >= 0)
2250                 gtk_option_menu_set_history(optmenu, index);
2251         else {
2252                 gtk_option_menu_set_history(optmenu, 0);
2253                 prefs_common_charset_set_data_from_optmenu(pparam);
2254         }
2255 }
2256
2257 static void prefs_common_encoding_set_data_from_optmenu(PrefParam *pparam)
2258 {
2259         GtkWidget *menu;
2260         GtkWidget *menuitem;
2261
2262         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2263         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2264         *((TransferEncodingMethod *)pparam->data) = GPOINTER_TO_INT
2265                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2266 }
2267
2268 static void prefs_common_encoding_set_optmenu(PrefParam *pparam)
2269 {
2270         TransferEncodingMethod method =
2271                 *((TransferEncodingMethod *)pparam->data);
2272         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2273         gint index;
2274
2275         g_return_if_fail(optmenu != NULL);
2276
2277         index = menu_find_option_menu_index(optmenu, GINT_TO_POINTER(method),
2278                                             NULL);
2279         if (index >= 0)
2280                 gtk_option_menu_set_history(optmenu, index);
2281         else {
2282                 gtk_option_menu_set_history(optmenu, 0);
2283                 prefs_common_encoding_set_data_from_optmenu(pparam);
2284         }
2285 }
2286
2287 static void prefs_common_recv_dialog_set_data_from_optmenu(PrefParam *pparam)
2288 {
2289         GtkWidget *menu;
2290         GtkWidget *menuitem;
2291
2292         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2293         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2294         *((RecvDialogMode *)pparam->data) = GPOINTER_TO_INT
2295                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2296 }
2297
2298 static void prefs_common_recv_dialog_set_optmenu(PrefParam *pparam)
2299 {
2300         RecvDialogMode mode = *((RecvDialogMode *)pparam->data);
2301         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2302         GtkWidget *menu;
2303         GtkWidget *menuitem;
2304         gint index;
2305
2306         index = menu_find_option_menu_index(optmenu, GINT_TO_POINTER(mode),
2307                                             NULL);
2308         if (index >= 0)
2309                 gtk_option_menu_set_history(optmenu, index);
2310         else {
2311                 gtk_option_menu_set_history(optmenu, 0);
2312                 prefs_common_recv_dialog_set_data_from_optmenu(pparam);
2313         }
2314
2315         menu = gtk_option_menu_get_menu(optmenu);
2316         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2317         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2318 }
2319
2320 static void prefs_common_send_dialog_set_data_from_optmenu(PrefParam *pparam)
2321 {
2322         GtkWidget *menu;
2323         GtkWidget *menuitem;
2324
2325         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2326         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2327         *((SendDialogMode *)pparam->data) = GPOINTER_TO_INT
2328                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2329 }
2330
2331 static void prefs_common_send_dialog_set_optmenu(PrefParam *pparam)
2332 {
2333         SendDialogMode mode = *((SendDialogMode *)pparam->data);
2334         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2335         GtkWidget *menu;
2336         GtkWidget *menuitem;
2337
2338         switch (mode) {
2339         case SEND_DIALOG_ALWAYS:
2340                 gtk_option_menu_set_history(optmenu, 0);
2341                 break;
2342         case SEND_DIALOG_NEVER:
2343                 gtk_option_menu_set_history(optmenu, 1);
2344                 break;
2345         default:
2346                 break;
2347         }
2348
2349         menu = gtk_option_menu_get_menu(optmenu);
2350         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2351         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2352 }
2353
2354 static void prefs_common_apply(void)
2355 {
2356         MainWindow *mainwindow;
2357
2358         prefs_set_data_from_dialog(param);
2359         sock_set_io_timeout(prefs_common.io_timeout_secs);
2360         main_window_reflect_prefs_all_real(FALSE);
2361         prefs_common_write_config();
2362
2363         mainwindow = mainwindow_get_mainwindow();
2364         log_window_set_clipping(mainwindow->logwin, prefs_common.cliplog,
2365                                 prefs_common.loglength);
2366         
2367         inc_autocheck_timer_remove();
2368         inc_autocheck_timer_set();
2369 }
2370
2371 static void prefs_nextunreadmsgdialog_set_data_from_optmenu(PrefParam *pparam)
2372 {
2373         GtkWidget *menu;
2374         GtkWidget *menuitem;
2375
2376         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2377         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2378         *((NextUnreadMsgDialogShow *)pparam->data) = GPOINTER_TO_INT
2379                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2380 }
2381
2382 static void prefs_nextunreadmsgdialog_set_optmenu(PrefParam *pparam)
2383 {
2384         NextUnreadMsgDialogShow dialog_show;
2385         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2386         GtkWidget *menu;
2387         GtkWidget *menuitem;
2388
2389         dialog_show = *((NextUnreadMsgDialogShow *)pparam->data);
2390
2391         switch (dialog_show) {
2392         case NEXTUNREADMSGDIALOG_ALWAYS:
2393                 gtk_option_menu_set_history(optmenu, 0);
2394                 break;
2395         case NEXTUNREADMSGDIALOG_ASSUME_YES:
2396                 gtk_option_menu_set_history(optmenu, 1);
2397                 break;
2398         case NEXTUNREADMSGDIALOG_ASSUME_NO:
2399                 gtk_option_menu_set_history(optmenu, 2);
2400                 break;
2401         }
2402
2403         menu = gtk_option_menu_get_menu(optmenu);
2404         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2405         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2406 }
2407
2408 void pref_set_textview_from_pref(GtkTextView *textview, gchar *txt)
2409 {
2410         GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
2411         gchar *o_out, *out = malloc(txt?(strlen(txt)+1):1);
2412         gchar *t = txt;
2413         memset(out, 0, strlen(txt)+1);
2414         o_out = out;
2415         while (*t != '\0') {
2416                 if (*t == '\\' && *(t+1) == 'n') {
2417                         *out++ = '\n';
2418                         t++;
2419                 } else if (*t == '\\') {
2420                         t++;
2421                 } else {
2422                         *out++ = *t;
2423                 }
2424                 t++;
2425         }
2426         *out='\0';
2427
2428         gtk_text_buffer_set_text(buffer, o_out?o_out:"", -1);
2429         g_free(o_out);
2430 }
2431
2432 gchar *pref_get_pref_from_textview(GtkTextView *textview) 
2433 {
2434         GtkTextBuffer *buffer;
2435         GtkTextIter start, end;
2436         gchar *o_out, *out, *tmp, *t;
2437         
2438         buffer = gtk_text_view_get_buffer(textview);
2439         gtk_text_buffer_get_start_iter(buffer, &start);
2440         gtk_text_buffer_get_iter_at_offset(buffer, &end, -1);
2441         tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
2442         t = tmp;
2443         o_out = out = malloc(2*strlen(tmp)+1);
2444         
2445         while (*t != '\0') {
2446                 if (*t == '\n') {
2447                         *out++ = '\\';
2448                         *out++ = 'n';
2449                 } else if (*t == '\\') {
2450                         *out++ = '\\';
2451                         *out++ = '\\';
2452                 } else {
2453                         *out++ = *t;
2454                 }
2455                 t++;
2456         }
2457         *out = '\0';
2458         g_free(tmp);
2459
2460         return o_out;
2461 }