make return receipts work again
[claws.git] / src / mainwindow.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2002 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 #include "defs.h"
21
22 #include <glib.h>
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtkmain.h>
25 #include <gtk/gtkwindow.h>
26 #include <gtk/gtkwidget.h>
27 #include <gtk/gtksignal.h>
28 #include <gtk/gtkvbox.h>
29 #include <gtk/gtkcontainer.h>
30 #include <gtk/gtkstatusbar.h>
31 #include <gtk/gtkprogressbar.h>
32 #include <gtk/gtkhpaned.h>
33 #include <gtk/gtkvpaned.h>
34 #include <gtk/gtkcheckmenuitem.h>
35 #include <gtk/gtkitemfactory.h>
36 #include <gtk/gtkeditable.h>
37 #include <gtk/gtkmenu.h>
38 #include <gtk/gtkmenuitem.h>
39 #include <gtk/gtkhandlebox.h>
40 #include <gtk/gtktoolbar.h>
41 #include <gtk/gtkbutton.h>
42 #include <string.h>
43
44 #include "intl.h"
45 #include "main.h"
46 #include "mainwindow.h"
47 #include "folderview.h"
48 #include "foldersel.h"
49 #include "summaryview.h"
50 #include "summary_search.h"
51 #include "messageview.h"
52 #include "message_search.h"
53 #include "headerview.h"
54 #include "menu.h"
55 #include "stock_pixmap.h"
56 #include "folder.h"
57 #include "inc.h"
58 #include "compose.h"
59 #include "procmsg.h"
60 #include "import.h"
61 #include "export.h"
62 #include "prefs_common.h"
63 #include "prefs_filter.h"
64 #include "prefs_actions.h"
65 #include "prefs_filtering.h"
66 #include "prefs_scoring.h"
67 #include "prefs_account.h"
68 #include "prefs_folder_item.h"
69 #include "prefs_summary_column.h"
70 #include "prefs_template.h"
71 #include "account.h"
72 #include "addressbook.h"
73 #include "logwindow.h"
74 #include "manage_window.h"
75 #include "alertpanel.h"
76 #include "statusbar.h"
77 #include "inputdialog.h"
78 #include "utils.h"
79 #include "gtkutils.h"
80 #include "codeconv.h"
81 #include "about.h"
82 #include "manual.h"
83 #include "version.h"
84 #include "selective_download.h"
85
86 #define AC_LABEL_WIDTH  240
87
88 #define STATUSBAR_PUSH(mainwin, str) \
89 { \
90         gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar), \
91                            mainwin->mainwin_cid, str); \
92         gtkut_widget_wait_for_draw(mainwin->hbox_stat); \
93 }
94
95 #define STATUSBAR_POP(mainwin) \
96 { \
97         gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar), \
98                           mainwin->mainwin_cid); \
99 }
100
101 /* list of all instantiated MainWindow */
102 static GList *mainwin_list = NULL;
103
104 static GdkCursor *watch_cursor;
105
106 static void main_window_menu_callback_block     (MainWindow     *mainwin);
107 static void main_window_menu_callback_unblock   (MainWindow     *mainwin);
108
109 static void main_window_show_cur_account        (MainWindow     *mainwin);
110
111 static void main_window_set_widgets             (MainWindow     *mainwin,
112                                                  SeparateType    type);
113 static void main_window_toolbar_create          (MainWindow     *mainwin,
114                                                  GtkWidget      *container);
115
116 /* callback functions */
117 static void toolbar_inc_cb              (GtkWidget      *widget,
118                                          gpointer        data);
119 static void toolbar_inc_all_cb          (GtkWidget      *widget,
120                                          gpointer        data);
121 static void toolbar_send_cb             (GtkWidget      *widget,
122                                          gpointer        data);
123
124 static void toolbar_compose_news_cb     (GtkWidget      *widget,
125                                          gpointer        data);
126 static void toolbar_compose_mail_cb     (GtkWidget      *widget,
127                                          gpointer        data);
128 static void toolbar_reply_cb            (GtkWidget      *widget,
129                                          gpointer        data);
130 static void toolbar_reply_popup_cb      (GtkWidget      *widget,
131                                          GdkEventButton *event,
132                                          gpointer        data);
133 static void toolbar_reply_popup_closed_cb(GtkMenuShell  *menu_shell,
134                                          gpointer        data);
135 static void toolbar_reply_to_all_cb     (GtkWidget      *widget,
136                                          gpointer        data);
137 static void toolbar_reply_to_all_popup_cb(GtkWidget     *widget,
138                                          GdkEventButton *event,
139                                          gpointer        data);
140 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell   *menu_shell,
141                                          gpointer        data);
142 static void toolbar_reply_to_sender_cb  (GtkWidget      *widget,
143                                          gpointer        data);
144 static void toolbar_reply_to_sender_popup_cb(GtkWidget  *widget,
145                                          GdkEventButton *event,
146                                          gpointer        data);
147 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell        *menu_shell,
148                                          gpointer        data);
149 static void toolbar_forward_cb          (GtkWidget      *widget,
150                                          gpointer        data);
151 static void toolbar_forward_popup_cb    (GtkWidget      *widget,
152                                          GdkEventButton *event,
153                                          gpointer        data);
154 static void toolbar_forward_popup_closed_cb(GtkMenuShell        *menu_shell,
155                                          gpointer        data);
156
157 static void toolbar_delete_cb           (GtkWidget      *widget,
158                                          gpointer        data);
159 static void toolbar_exec_cb             (GtkWidget      *widget,
160                                          gpointer        data);
161
162 static void toolbar_next_unread_cb      (GtkWidget      *widget,
163                                          gpointer        data);
164
165
166 #if 0
167 static void toolbar_account_button_pressed      (GtkWidget      *widget,
168                                                  GdkEventButton *event,
169                                                  gpointer        data);
170 #endif
171 static void ac_label_button_pressed             (GtkWidget      *widget,
172                                                  GdkEventButton *event,
173                                                  gpointer        data);
174 static void ac_menu_popup_closed                (GtkMenuShell   *menu_shell,
175                                                  gpointer        data);
176
177 static gint main_window_close_cb        (GtkWidget      *widget,
178                                          GdkEventAny    *event,
179                                          gpointer        data);
180 static gint folder_window_close_cb      (GtkWidget      *widget,
181                                          GdkEventAny    *event,
182                                          gpointer        data);
183 static gint message_window_close_cb     (GtkWidget      *widget,
184                                          GdkEventAny    *event,
185                                          gpointer        data);
186
187 static void add_mailbox_cb       (MainWindow    *mainwin,
188                                   guint          action,
189                                   GtkWidget     *widget);
190 static void add_mbox_cb          (MainWindow    *mainwin,
191                                   guint          action,
192                                   GtkWidget     *widget);
193 static void update_folderview_cb (MainWindow    *mainwin,
194                                   guint          action,
195                                   GtkWidget     *widget);
196 static void new_folder_cb        (MainWindow    *mainwin,
197                                   guint          action,
198                                   GtkWidget     *widget);
199 static void rename_folder_cb     (MainWindow    *mainwin,
200                                   guint          action,
201                                   GtkWidget     *widget);
202 static void delete_folder_cb     (MainWindow    *mainwin,
203                                   guint          action,
204                                   GtkWidget     *widget);
205 static void import_mbox_cb       (MainWindow    *mainwin,
206                                   guint          action,
207                                   GtkWidget     *widget);
208 static void export_mbox_cb       (MainWindow    *mainwin,
209                                   guint          action,
210                                   GtkWidget     *widget);
211 static void empty_trash_cb       (MainWindow    *mainwin,
212                                   guint          action,
213                                   GtkWidget     *widget);
214
215 static void save_as_cb           (MainWindow    *mainwin,
216                                   guint          action,
217                                   GtkWidget     *widget);
218 static void print_cb             (MainWindow    *mainwin,
219                                   guint          action,
220                                   GtkWidget     *widget);
221 static void app_exit_cb          (MainWindow    *mainwin,
222                                   guint          action,
223                                   GtkWidget     *widget);
224
225 static void search_cb            (MainWindow    *mainwin,
226                                   guint          action,
227                                   GtkWidget     *widget);
228
229 static void toggle_folder_cb     (MainWindow    *mainwin,
230                                   guint          action,
231                                   GtkWidget     *widget);
232 static void toggle_message_cb    (MainWindow    *mainwin,
233                                   guint          action,
234                                   GtkWidget     *widget);
235 static void toggle_toolbar_cb    (MainWindow    *mainwin,
236                                   guint          action,
237                                   GtkWidget     *widget);
238 static void toggle_statusbar_cb  (MainWindow    *mainwin,
239                                   guint          action,
240                                   GtkWidget     *widget);
241 static void separate_widget_cb   (MainWindow    *mainwin,
242                                   guint          action,
243                                   GtkWidget     *widget);
244
245 static void addressbook_open_cb (MainWindow     *mainwin,
246                                  guint           action,
247                                  GtkWidget      *widget);
248 static void log_window_show_cb  (MainWindow     *mainwin,
249                                  guint           action,
250                                  GtkWidget      *widget);
251 static void sel_download_cb     (MainWindow *mainwin, 
252                                  guint action,
253                                  GtkWidget *widget);
254
255 static void inc_mail_cb                 (MainWindow     *mainwin,
256                                          guint           action,
257                                          GtkWidget      *widget);
258 static void inc_all_account_mail_cb     (MainWindow     *mainwin,
259                                          guint           action,
260                                          GtkWidget      *widget);
261 static void inc_cancel_cb               (MainWindow     *mainwin,
262                                          guint           action,
263                                          GtkWidget      *widget);
264
265 static void send_queue_cb               (MainWindow     *mainwin,
266                                          guint           action,
267                                          GtkWidget      *widget);
268
269 static void compose_mail_cb(MainWindow *mainwin, guint action,
270                             GtkWidget *widget);
271 static void compose_news_cb(MainWindow *mainwin, guint action,
272                             GtkWidget *widget);
273 static void reply_cb                    (MainWindow     *mainwin,
274                                          guint           action,
275                                          GtkWidget      *widget);
276
277 static void open_msg_cb                 (MainWindow     *mainwin,
278                                          guint           action,
279                                          GtkWidget      *widget);
280
281 static void view_source_cb              (MainWindow     *mainwin,
282                                          guint           action,
283                                          GtkWidget      *widget);
284
285 static void show_all_header_cb          (MainWindow     *mainwin,
286                                          guint           action,
287                                          GtkWidget      *widget);
288
289 static void reedit_cb                   (MainWindow     *mainwin,
290                                          guint           action,
291                                          GtkWidget      *widget);
292
293 static void move_to_cb                  (MainWindow     *mainwin,
294                                          guint           action,
295                                          GtkWidget      *widget);
296 static void copy_to_cb                  (MainWindow     *mainwin,
297                                          guint           action,
298                                          GtkWidget      *widget);
299 static void delete_cb                   (MainWindow     *mainwin,
300                                          guint           action,
301                                          GtkWidget      *widget);
302
303 static void mark_cb                     (MainWindow     *mainwin,
304                                          guint           action,
305                                          GtkWidget      *widget);
306 static void unmark_cb                   (MainWindow     *mainwin,
307                                          guint           action,
308                                          GtkWidget      *widget);
309
310 static void mark_as_unread_cb           (MainWindow     *mainwin,
311                                          guint           action,
312                                          GtkWidget      *widget);
313 static void mark_as_read_cb             (MainWindow     *mainwin,
314                                          guint           action,
315                                          GtkWidget      *widget);
316 static void mark_all_read_cb            (MainWindow     *mainwin,
317                                          guint           action,
318                                          GtkWidget      *widget);
319 static void add_address_cb              (MainWindow     *mainwin,
320                                          guint           action,
321                                          GtkWidget      *widget);
322
323 static void set_charset_cb              (MainWindow     *mainwin,
324                                          guint           action,
325                                          GtkWidget      *widget);
326
327 static void hide_read_messages   (MainWindow    *mainwin,
328                                   guint          action,
329                                   GtkWidget     *widget);
330
331 static void thread_cb            (MainWindow    *mainwin,
332                                   guint          action,
333                                   GtkWidget     *widget);
334 static void expand_threads_cb    (MainWindow    *mainwin,
335                                   guint          action,
336                                   GtkWidget     *widget);
337 static void collapse_threads_cb  (MainWindow    *mainwin,
338                                   guint          action,
339                                   GtkWidget     *widget);
340
341 static void set_display_item_cb  (MainWindow    *mainwin,
342                                   guint          action,
343                                   GtkWidget     *widget);
344 static void sort_summary_cb      (MainWindow    *mainwin,
345                                   guint          action,
346                                   GtkWidget     *widget);
347 static void sort_summary_type_cb (MainWindow    *mainwin,
348                                   guint          action,
349                                   GtkWidget     *widget);
350 static void attract_by_subject_cb(MainWindow    *mainwin,
351                                   guint          action,
352                                   GtkWidget     *widget);
353
354 static void delete_duplicated_cb (MainWindow    *mainwin,
355                                   guint          action,
356                                   GtkWidget     *widget);
357 static void filter_cb            (MainWindow    *mainwin,
358                                   guint          action,
359                                   GtkWidget     *widget);
360 static void execute_summary_cb   (MainWindow    *mainwin,
361                                   guint          action,
362                                   GtkWidget     *widget);
363 static void update_summary_cb    (MainWindow    *mainwin,
364                                   guint          action,
365                                   GtkWidget     *widget);
366
367 static void prev_cb              (MainWindow    *mainwin,
368                                   guint          action,
369                                   GtkWidget     *widget);
370 static void next_cb              (MainWindow    *mainwin,
371                                   guint          action,
372                                   GtkWidget     *widget);
373
374 static void prev_unread_cb       (MainWindow    *mainwin,
375                                   guint          action,
376                                   GtkWidget     *widget);
377 static void next_unread_cb       (MainWindow    *mainwin,
378                                   guint          action,
379                                   GtkWidget     *widget);
380 static void prev_new_cb          (MainWindow    *mainwin,
381                                   guint          action,
382                                   GtkWidget     *widget);
383 static void next_new_cb          (MainWindow    *mainwin,
384                                   guint          action,
385                                   GtkWidget     *widget);
386 static void prev_marked_cb       (MainWindow    *mainwin,
387                                   guint          action,
388                                   GtkWidget     *widget);
389 static void next_marked_cb       (MainWindow    *mainwin,
390                                   guint          action,
391                                   GtkWidget     *widget);
392 static void prev_labeled_cb      (MainWindow    *mainwin,
393                                   guint          action,
394                                   GtkWidget     *widget);
395 static void next_labeled_cb      (MainWindow    *mainwin,
396                                   guint          action,
397                                   GtkWidget     *widget);
398
399 static void goto_folder_cb       (MainWindow    *mainwin,
400                                   guint          action,
401                                   GtkWidget     *widget);
402
403 static void copy_cb              (MainWindow    *mainwin,
404                                   guint          action,
405                                   GtkWidget     *widget);
406 static void allsel_cb            (MainWindow    *mainwin,
407                                   guint          action,
408                                   GtkWidget     *widget);
409 static void selthread_cb         (MainWindow    *mainwin,
410                                   guint          action,
411                                   GtkWidget     *widget);
412 static void create_filter_cb     (MainWindow    *mainwin,
413                                   guint          action,
414                                   GtkWidget     *widget);
415
416 static void prefs_common_open_cb        (MainWindow     *mainwin,
417                                          guint           action,
418                                          GtkWidget      *widget);
419 static void prefs_filter_open_cb        (MainWindow     *mainwin,
420                                          guint           action,
421                                          GtkWidget      *widget);
422 static void prefs_template_open_cb      (MainWindow     *mainwin,
423                                          guint           action,
424                                          GtkWidget      *widget);
425 static void prefs_actions_open_cb       (MainWindow     *mainwin,
426                                          guint           action,
427                                          GtkWidget      *widget);
428 static void prefs_account_open_cb       (MainWindow     *mainwin,
429                                          guint           action,
430                                          GtkWidget      *widget);
431 static void prefs_scoring_open_cb       (MainWindow     *mainwin,
432                                          guint           action,
433                                          GtkWidget      *widget);
434 static void prefs_filtering_open_cb (MainWindow *mainwin,
435                                          guint           action,
436                                          GtkWidget      *widget);
437
438 static void new_account_cb       (MainWindow    *mainwin,
439                                   guint          action,
440                                   GtkWidget     *widget);
441
442 static void account_menu_cb      (GtkMenuItem   *menuitem,
443                                   gpointer       data);
444
445 static void online_switch_clicked(GtkButton     *btn, 
446                                   gpointer data);
447
448 static void manual_open_cb       (MainWindow    *mainwin,
449                                   guint          action,
450                                   GtkWidget     *widget);
451 static void faq_open_cb          (MainWindow    *mainwin,
452                                   guint          action,
453                                   GtkWidget     *widget);
454
455 static void scan_tree_func       (Folder        *folder,
456                                   FolderItem    *item,
457                                   gpointer       data);
458                                   
459 static void activate_compose_button (MainWindow *mainwin,
460                                 ToolbarStyle      style,
461                                 ComposeButtonType type);
462
463 static void key_pressed (GtkWidget *widget, 
464                                 GdkEventKey *event,
465                                 gpointer data);
466
467 static void set_toolbar_style(MainWindow *mainwin);
468
469 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
470
471 static void addr_harvest_cb      ( MainWindow  *mainwin,
472                                    guint       action,
473                                    GtkWidget   *widget );
474
475 static void addr_harvest_msg_cb  ( MainWindow  *mainwin,
476                                    guint       action,
477                                    GtkWidget   *widget );
478
479 #define  SEPARATE_ACTION 500 
480
481 static GtkItemFactoryEntry mainwin_entries[] =
482 {
483         {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
484         {N_("/_File/_Add mailbox..."),          NULL, add_mailbox_cb, 0, NULL},
485         {N_("/_File/_Add mbox mailbox..."),     NULL, add_mbox_cb, 0, NULL},
486         {N_("/_File/_Rescan folder tree"),      NULL, update_folderview_cb, 0, NULL},
487         {N_("/_File/_Folder"),                  NULL, NULL, 0, "<Branch>"},
488         {N_("/_File/_Folder/Create _new folder..."),
489                                                 NULL, new_folder_cb, 0, NULL},
490         {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
491         {N_("/_File/_Folder/_Delete folder"),   NULL, delete_folder_cb, 0, NULL},
492         {N_("/_File/_Import mbox file..."),     NULL, import_mbox_cb, 0, NULL},
493         {N_("/_File/_Export to mbox file..."),  NULL, export_mbox_cb, 0, NULL},
494         {N_("/_File/Empty _trash"),             "<shift>D", empty_trash_cb, 0, NULL},
495         {N_("/_File/_Work offline"),            "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},                                               
496         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
497         {N_("/_File/_Save as..."),              "<control>S", save_as_cb, 0, NULL},
498         {N_("/_File/_Print..."),                NULL, print_cb, 0, NULL},
499         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
500         /* {N_("/_File/_Close"),                "<alt>W", app_exit_cb, 0, NULL}, */
501         {N_("/_File/E_xit"),                    "<control>Q", app_exit_cb, 0, NULL},
502
503         {N_("/_Edit"),                          NULL, NULL, 0, "<Branch>"},
504         {N_("/_Edit/_Copy"),                    "<control>C", copy_cb, 0, NULL},
505         {N_("/_Edit/Select _all"),              "<control>A", allsel_cb, 0, NULL},
506         {N_("/_Edit/Select thread"),            "<control>Z", selthread_cb, 0, NULL},
507         {N_("/_Edit/---"),                      NULL, NULL, 0, "<Separator>"},
508         {N_("/_Edit/_Find in current message..."),
509                                                 "<control>F", search_cb, 0, NULL},
510         {N_("/_Edit/_Search folder..."),        "<shift><control>F", search_cb, 1, NULL},
511         {N_("/_View"),                          NULL, NULL, 0, "<Branch>"},
512         {N_("/_View/Show or hi_de"),            NULL, NULL, 0, "<Branch>"},
513         {N_("/_View/Show or hi_de/_Folder tree"),
514                                                 NULL, toggle_folder_cb, 0, "<ToggleItem>"},
515         {N_("/_View/Show or hi_de/_Message view"),
516                                                 "V", toggle_message_cb, 0, "<ToggleItem>"},
517         {N_("/_View/Show or hi_de/_Toolbar"),
518                                                 NULL, NULL, 0, "<Branch>"},
519         {N_("/_View/Show or hi_de/_Toolbar/Icon _and text"),
520                                                 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
521         {N_("/_View/Show or hi_de/_Toolbar/_Icon"),
522                                                 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Icon and text"},
523         {N_("/_View/Show or hi_de/_Toolbar/_Text"),
524                                                 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Icon and text"},
525         {N_("/_View/Show or hi_de/_Toolbar/_None"),
526                                                 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Icon and text"},
527         {N_("/_View/Show or hi_de/Status _bar"),
528                                                 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
529         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
530         {N_("/_View/Separate f_older tree"),    NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
531         {N_("/_View/Separate m_essage view"),   NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
532         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
533         {N_("/_View/_Sort"),                    NULL, NULL, 0, "<Branch>"},
534         {N_("/_View/_Sort/by _number"),         NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
535         {N_("/_View/_Sort/by s_ize"),           NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
536         {N_("/_View/_Sort/by _date"),           NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
537         {N_("/_View/_Sort/by _from"),           NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
538         {N_("/_View/_Sort/by _subject"),        NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
539         {N_("/_View/_Sort/by _color label"),
540                                                 NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
541         {N_("/_View/_Sort/by _mark"),           NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
542         {N_("/_View/_Sort/by _unread"),         NULL, sort_summary_cb, SORT_BY_UNREAD, "/View/Sort/by number"},
543         {N_("/_View/_Sort/by a_ttachment"),
544                                                 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
545         {N_("/_View/_Sort/by score"),           NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
546         {N_("/_View/_Sort/by locked"),          NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
547         {N_("/_View/_Sort/D_on't sort"),        NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
548         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
549         {N_("/_View/_Sort/Ascending"),          NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
550         {N_("/_View/_Sort/Descending"),         NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
551         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
552         {N_("/_View/_Sort/_Attract by subject"),
553                                                 NULL, attract_by_subject_cb, 0, NULL},
554         {N_("/_View/Th_read view"),             "<control>T", thread_cb, 0, "<ToggleItem>"},
555         {N_("/_View/E_xpand all threads"),      NULL, expand_threads_cb, 0, NULL},
556         {N_("/_View/Co_llapse all threads"),    NULL, collapse_threads_cb, 0, NULL},
557         {N_("/_View/_Hide read messages"),      NULL, hide_read_messages, 0, "<ToggleItem>"},
558         {N_("/_View/Set display _item..."),     NULL, set_display_item_cb, 0, NULL},
559
560         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
561         {N_("/_View/_Go to"),                   NULL, NULL, 0, "<Branch>"},
562         {N_("/_View/_Go to/_Prev message"),     "P", prev_cb, 0, NULL},
563         {N_("/_View/_Go to/_Next message"),     "N", next_cb, 0, NULL},
564         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
565         {N_("/_View/_Go to/P_rev unread message"),
566                                                 "<shift>P", prev_unread_cb, 0, NULL},
567         {N_("/_View/_Go to/N_ext unread message"),
568                                                 "<shift>N", next_unread_cb, 0, NULL},
569         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
570         {N_("/_View/_Go to/Prev ne_w message"), NULL, prev_new_cb, 0, NULL},
571         {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
572         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
573         {N_("/_View/_Go to/Prev _marked message"),
574                                                 NULL, prev_marked_cb, 0, NULL},
575         {N_("/_View/_Go to/Next m_arked message"),
576                                                 NULL, next_marked_cb, 0, NULL},
577         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
578         {N_("/_View/_Go to/Prev _labeled message"),
579                                                 NULL, prev_labeled_cb, 0, NULL},
580         {N_("/_View/_Go to/Next la_beled message"),
581                                                 NULL, next_labeled_cb, 0, NULL},
582         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
583         {N_("/_View/_Go to/Other _folder..."),  "G", goto_folder_cb, 0, NULL},
584         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
585
586 #define CODESET_SEPARATOR \
587         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"}
588 #define CODESET_ACTION(action) \
589          NULL, set_charset_cb, action, "/View/Code set/Auto detect"
590
591         {N_("/_View/_Code set"),                NULL, NULL, 0, "<Branch>"},
592         {N_("/_View/_Code set/_Auto detect"),
593          NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
594         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"},
595         {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
596          CODESET_ACTION(C_US_ASCII)},
597
598 #if HAVE_LIBJCONV
599         {N_("/_View/_Code set/Unicode (_UTF-8)"),
600          CODESET_ACTION(C_UTF_8)},
601         CODESET_SEPARATOR,
602 #endif
603         {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
604          CODESET_ACTION(C_ISO_8859_1)},
605         {N_("/_View/_Code set/Western European (ISO-8859-15)"),
606          CODESET_ACTION(C_ISO_8859_15)},
607         CODESET_SEPARATOR,
608 #if HAVE_LIBJCONV
609         {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
610          CODESET_ACTION(C_ISO_8859_2)},
611         CODESET_SEPARATOR,
612         {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
613          CODESET_ACTION(C_ISO_8859_13)},
614         {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
615          CODESET_ACTION(C_ISO_8859_4)},
616         CODESET_SEPARATOR,
617         {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
618          CODESET_ACTION(C_ISO_8859_7)},
619         CODESET_SEPARATOR,
620         {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
621          CODESET_ACTION(C_ISO_8859_9)},
622         CODESET_SEPARATOR,
623         {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
624          CODESET_ACTION(C_ISO_8859_5)},
625         {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
626          CODESET_ACTION(C_KOI8_R)},
627         {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
628          CODESET_ACTION(C_WINDOWS_1251)},
629         CODESET_SEPARATOR,
630 #endif
631         {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
632          CODESET_ACTION(C_ISO_2022_JP)},
633 #if HAVE_LIBJCONV
634         {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
635          CODESET_ACTION(C_ISO_2022_JP_2)},
636 #endif
637         {N_("/_View/_Code set/Japanese (_EUC-JP)"),
638          CODESET_ACTION(C_EUC_JP)},
639         {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
640          CODESET_ACTION(C_SHIFT_JIS)},
641 #if HAVE_LIBJCONV
642         CODESET_SEPARATOR,
643         {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
644          CODESET_ACTION(C_GB2312)},
645         {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
646          CODESET_ACTION(C_BIG5)},
647         {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
648          CODESET_ACTION(C_EUC_TW)},
649         {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
650          CODESET_ACTION(C_ISO_2022_CN)},
651         CODESET_SEPARATOR,
652         {N_("/_View/_Code set/Korean (EUC-_KR)"),
653          CODESET_ACTION(C_EUC_KR)},
654         {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
655          CODESET_ACTION(C_ISO_2022_KR)},
656         CODESET_SEPARATOR,
657         {N_("/_View/_Code set/Thai (TIS-620)"),
658          CODESET_ACTION(C_TIS_620)},
659         {N_("/_View/_Code set/Thai (Windows-874)"),
660          CODESET_ACTION(C_WINDOWS_874)},
661 #endif
662
663 #undef CODESET_SEPARATOR
664 #undef CODESET_ACTION
665
666         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
667         {N_("/_View/Open in new _window"),      "<control><alt>N", open_msg_cb, 0, NULL},
668         {N_("/_View/Mess_age source"),          "<control>U", view_source_cb, 0, NULL},
669         {N_("/_View/Show all _header"),         "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
670         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
671         {N_("/_View/_Update summary"),          "<control><alt>U", update_summary_cb,  0, NULL},
672
673         {N_("/_Message"),                       NULL, NULL, 0, "<Branch>"},
674         {N_("/_Message/Get new ma_il"),         "<control>I",   inc_mail_cb, 0, NULL},
675         {N_("/_Message/Get from _all accounts"),
676                                                 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
677         {N_("/_Message/Cancel receivin_g"),     NULL, inc_cancel_cb, 0, NULL},
678         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
679         {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
680         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
681         {N_("/_Message/Compose a_n email message"),     "<control>M", compose_mail_cb, 0, NULL},
682         {N_("/_Message/Compose a news message"),        NULL,   compose_news_cb, 0, NULL},
683         {N_("/_Message/_Reply"),                "<control>R",   reply_cb, COMPOSE_REPLY, NULL},
684         {N_("/_Message/Repl_y to sender"),      "<control><alt>R", reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
685         {N_("/_Message/Follow-up and reply to"), NULL, reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
686         {N_("/_Message/Reply to a_ll"),         "<shift><control>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
687         {N_("/_Message/_Forward"),              "<control><alt>F", reply_cb, COMPOSE_FORWARD, NULL},
688         {N_("/_Message/Redirect"),              NULL, reply_cb, COMPOSE_REDIRECT, NULL},
689         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
690         {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
691         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
692         {N_("/_Message/M_ove..."),              "<control>O", move_to_cb, 0, NULL},
693         {N_("/_Message/_Copy..."),              "<shift><control>O", copy_to_cb, 0, NULL},
694         {N_("/_Message/_Delete"),               "<control>D", delete_cb,  0, NULL},
695         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
696         {N_("/_Message/_Mark"),                 NULL, NULL, 0, "<Branch>"},
697         {N_("/_Message/_Mark/_Mark"),           "<shift>asterisk", mark_cb, 0, NULL},
698         {N_("/_Message/_Mark/_Unmark"),         "U", unmark_cb, 0, NULL},
699         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
700         {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
701         {N_("/_Message/_Mark/Mark as rea_d"),
702                                                 NULL, mark_as_read_cb, 0, NULL},
703         {N_("/_Message/_Mark/Mark all _read"),  NULL, mark_all_read_cb, 0, NULL},
704
705         {N_("/_Tools"),                         NULL, NULL, 0, "<Branch>"},
706         {N_("/_Tools/_Selective download..."),  "<alt>S", sel_download_cb, 0, NULL},
707         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
708         {N_("/_Tools/_Address book..."),        "<shift><control>A", addressbook_open_cb, 0, NULL},
709         {N_("/_Tools/Add sender to address boo_k"),
710                                                 NULL, add_address_cb, 0, NULL},
711         {N_("/_Tools/_Harvest addresses"),      NULL, NULL, 0, "<Branch>"},
712         {N_("/_Tools/_Harvest addresses/from _Folder..."),
713                                                 NULL, addr_harvest_cb, 0, NULL},
714         {N_("/_Tools/_Harvest addresses/from _Messages..."),
715                                                 NULL, addr_harvest_msg_cb, 0, NULL},
716         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
717         {N_("/_Tools/_Filter messages"),                NULL, filter_cb, 0, NULL},
718         {N_("/_Tools/_Create filter rule"),     NULL, NULL, 0, "<Branch>"},
719         {N_("/_Tools/_Create filter rule/_Automatically"),
720                                                 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
721         {N_("/_Tools/_Create filter rule/by _From"),
722                                                 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
723         {N_("/_Tools/_Create filter rule/by _To"),
724                                                 NULL, create_filter_cb, FILTER_BY_TO, NULL},
725         {N_("/_Tools/_Create filter rule/by _Subject"),
726                                                 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
727         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
728         {N_("/_Tools/Actio_ns"),                NULL, NULL, 0, "<Branch>"},
729         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
730         {N_("/_Tools/Delete du_plicated messages"),
731                                                 NULL, delete_duplicated_cb,   0, NULL},
732         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
733         {N_("/_Tools/E_xecute"),                "X", execute_summary_cb, 0, NULL},
734         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
735         {N_("/_Tools/_Log window"),             "<control>L", log_window_show_cb, 0, NULL},
736
737         {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
738         {N_("/_Configuration/_Common preferences..."),
739                                                 NULL, prefs_common_open_cb, 0, NULL},
740         {N_("/_Configuration/_Filter setting..."),
741                                                 NULL, prefs_filter_open_cb, 0, NULL},
742         {N_("/_Configuration/_Scoring..."),
743                                                 NULL, prefs_scoring_open_cb, 0, NULL},
744         {N_("/_Configuration/_Filtering..."),
745                                                 NULL, prefs_filtering_open_cb, 0, NULL},
746         {N_("/_Configuration/_Template..."),    NULL, prefs_template_open_cb, 0, NULL},
747         {N_("/_Configuration/_Actions..."),     NULL, prefs_actions_open_cb, 0, NULL},
748         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
749         {N_("/_Configuration/_Preferences for current account..."),
750                                                 NULL, prefs_account_open_cb, 0, NULL},
751         {N_("/_Configuration/Create _new account..."),
752                                                 NULL, new_account_cb, 0, NULL},
753         {N_("/_Configuration/_Edit accounts..."),
754                                                 NULL, account_edit_open, 0, NULL},
755         {N_("/_Configuration/C_hange current account"),
756                                                 NULL, NULL, 0, "<Branch>"},
757
758         {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
759         {N_("/_Help/_Manual"),                  NULL, NULL, 0, "<Branch>"},
760         {N_("/_Help/_Manual/_English"),         NULL, manual_open_cb, MANUAL_LANG_EN, NULL},
761         {N_("/_Help/_Manual/_German"),          NULL, manual_open_cb, MANUAL_LANG_DE, NULL},
762         {N_("/_Help/_Manual/_Spanish"),         NULL, manual_open_cb, MANUAL_LANG_ES, NULL},
763         {N_("/_Help/_Manual/_French"),          NULL, manual_open_cb, MANUAL_LANG_FR, NULL},
764         {N_("/_Help/_Manual/_Japanese"),        NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
765         {N_("/_Help/_FAQ"),                     NULL, NULL, 0, "<Branch>"},
766         {N_("/_Help/_FAQ/_English"),            NULL, faq_open_cb, MANUAL_LANG_EN, NULL},
767         {N_("/_Help/_FAQ/_German"),             NULL, faq_open_cb, MANUAL_LANG_DE, NULL},
768         {N_("/_Help/_FAQ/_Spanish"),            NULL, faq_open_cb, MANUAL_LANG_ES, NULL},
769         {N_("/_Help/_FAQ/_French"),             NULL, faq_open_cb, MANUAL_LANG_FR, NULL},
770         {N_("/_Help/_FAQ/_Italian"),            NULL, faq_open_cb, MANUAL_LANG_IT, NULL},
771         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
772         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
773 };
774 static GtkItemFactoryEntry reply_popup_entries[] =
775 {
776         {N_("/Reply with _quote"), NULL, reply_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
777         {N_("/_Reply without quote"), NULL, reply_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
778 };
779 static GtkItemFactoryEntry replyall_popup_entries[] =
780 {
781         {N_("/Reply to all with _quote"), "<shift>A", reply_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
782         {N_("/_Reply to all without quote"), "a", reply_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
783 };
784 static GtkItemFactoryEntry replysender_popup_entries[] =
785 {
786         {N_("/Reply to sender with _quote"), NULL, reply_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
787         {N_("/_Reply to sender without quote"), NULL, reply_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
788 };
789 static GtkItemFactoryEntry fwd_popup_entries[] =
790 {
791         {N_("/_Forward message (inline style)"), "f", reply_cb, COMPOSE_FORWARD_INLINE, NULL},
792         {N_("/Forward message as _attachment"), "<shift>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
793 };
794
795 MainWindow *main_window_create(SeparateType type)
796 {
797         MainWindow *mainwin;
798         GtkWidget *window;
799         GtkWidget *vbox;
800         GtkWidget *menubar;
801         GtkWidget *handlebox;
802         GtkWidget *vbox_body;
803         GtkWidget *hbox_stat;
804         GtkWidget *statusbar;
805         GtkWidget *progressbar;
806         GtkWidget *statuslabel;
807         GtkWidget *ac_button;
808         GtkWidget *ac_label;
809         GtkWidget *online_status;
810         GtkWidget *offline_status;
811         GtkWidget *online_switch;
812         GtkWidget *offline_switch;
813
814         FolderView *folderview;
815         SummaryView *summaryview;
816         MessageView *messageview;
817         GdkColormap *colormap;
818         GdkColor color[4];
819         gboolean success[4];
820         guint n_menu_entries;
821         GtkItemFactory *ifactory;
822         GtkWidget *ac_menu;
823         GtkWidget *menuitem;
824         GtkWidget *reply_popup;
825         GtkWidget *replyall_popup;
826         GtkWidget *replysender_popup;
827         GtkWidget *fwd_popup;
828         gint i;
829
830         static GdkGeometry geometry;
831
832         debug_print(_("Creating main window...\n"));
833         mainwin = g_new0(MainWindow, 1);
834
835         /* main window */
836         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
837         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
838         gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
839         gtk_window_set_wmclass(GTK_WINDOW(window), "main_window", "Sylpheed");
840
841         if (!geometry.min_height) {
842                 geometry.min_width = 320;
843                 geometry.min_height = 200;
844         }
845         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
846                                       GDK_HINT_MIN_SIZE);
847
848         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
849                            GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
850         MANAGE_WINDOW_SIGNALS_CONNECT(window);
851         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
852                                 GTK_SIGNAL_FUNC(key_pressed), mainwin);
853
854         gtk_widget_realize(window);
855         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
856         
857
858         gtkut_widget_set_app_icon(window);
859
860         vbox = gtk_vbox_new(FALSE, 0);
861         gtk_widget_show(vbox);
862         gtk_container_add(GTK_CONTAINER(window), vbox);
863
864         /* menu bar */
865         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
866         menubar = menubar_create(window, mainwin_entries, 
867                                  n_menu_entries, "<Main>", mainwin);
868         gtk_widget_show(menubar);
869         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
870         ifactory = gtk_item_factory_from_widget(menubar);
871
872         handlebox = gtk_handle_box_new();
873         gtk_widget_show(handlebox);
874         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
875
876         /* create the popup menus for the reply buttons specials */
877         n_menu_entries = sizeof(reply_popup_entries) /
878                         sizeof(reply_popup_entries[0]);
879         reply_popup = popupmenu_create(window, reply_popup_entries, n_menu_entries,
880                                       "<ReplyPopup>", mainwin);
881         gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
882                            GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), mainwin);
883         n_menu_entries = sizeof(replyall_popup_entries) /
884                         sizeof(replyall_popup_entries[0]);
885         replyall_popup = popupmenu_create(window, replyall_popup_entries, n_menu_entries,
886                                       "<ReplyAllPopup>", mainwin);
887         gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
888                            GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), mainwin);
889         n_menu_entries = sizeof(replysender_popup_entries) /
890                         sizeof(replysender_popup_entries[0]);
891         replysender_popup = popupmenu_create(window, replysender_popup_entries, n_menu_entries,
892                                       "<ReplySenderPopup>", mainwin);
893         gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
894                            GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), mainwin);
895         /* create the popup menu for the forward button */
896         n_menu_entries = sizeof(fwd_popup_entries) /
897                         sizeof(fwd_popup_entries[0]);
898         fwd_popup = popupmenu_create(window, fwd_popup_entries, n_menu_entries,
899                                       "<ForwardPopup>", mainwin);
900         gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
901                            GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), mainwin);
902                            
903         main_window_toolbar_create(mainwin, handlebox);
904
905         /* vbox that contains body */
906         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
907         gtk_widget_show(vbox_body);
908         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
909         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
910
911         hbox_stat = gtk_hbox_new(FALSE, 2);
912         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
913
914         statusbar = statusbar_create();
915         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
916
917         progressbar = gtk_progress_bar_new();
918         gtk_widget_set_usize(progressbar, 120, 1);
919         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
920
921         online_status = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_WORK_ONLINE);
922         offline_status = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_WORK_OFFLINE);
923         online_switch = gtk_button_new ();
924         offline_switch = gtk_button_new ();
925         gtk_container_add (GTK_CONTAINER(online_switch), online_status);
926         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
927         gtk_signal_connect (GTK_OBJECT(online_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
928         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
929         gtk_container_add (GTK_CONTAINER(offline_switch), offline_status);
930         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
931         gtk_signal_connect (GTK_OBJECT(offline_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
932         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
933         
934         statuslabel = gtk_label_new("");
935         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
936
937         ac_button = gtk_button_new();
938         gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
939         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
940         gtk_widget_set_usize(ac_button, -1, 1);
941         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
942         gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
943                            GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
944
945         ac_label = gtk_label_new("");
946         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
947
948         gtk_widget_show_all(hbox_stat);
949
950         gtk_widget_hide(offline_switch);
951         /* create views */
952         mainwin->folderview  = folderview  = folderview_create();
953         mainwin->summaryview = summaryview = summary_create();
954         mainwin->messageview = messageview = messageview_create();
955         mainwin->logwin      = log_window_create();
956
957         folderview->mainwin      = mainwin;
958         folderview->summaryview  = summaryview;
959
960         summaryview->mainwin     = mainwin;
961         summaryview->folderview  = folderview;
962         summaryview->messageview = messageview;
963         summaryview->window      = window;
964
965         messageview->mainwin     = mainwin;
966
967         mainwin->window       = window;
968         mainwin->vbox         = vbox;
969         mainwin->menubar      = menubar;
970         mainwin->menu_factory = ifactory;
971         mainwin->handlebox    = handlebox;
972         mainwin->vbox_body    = vbox_body;
973         mainwin->hbox_stat    = hbox_stat;
974         mainwin->statusbar    = statusbar;
975         mainwin->progressbar  = progressbar;
976         mainwin->statuslabel  = statuslabel;
977         mainwin->ac_button    = ac_button;
978         mainwin->ac_label     = ac_label;
979         
980         mainwin->reply_popup       = reply_popup;
981         mainwin->replyall_popup    = replyall_popup;
982         mainwin->replysender_popup = replysender_popup;
983         mainwin->fwd_popup         = fwd_popup;
984         mainwin->online_switch     = online_switch;
985         mainwin->offline_switch    = offline_switch;
986         
987         /* set context IDs for status bar */
988         mainwin->mainwin_cid = gtk_statusbar_get_context_id
989                 (GTK_STATUSBAR(statusbar), "Main Window");
990         mainwin->folderview_cid = gtk_statusbar_get_context_id
991                 (GTK_STATUSBAR(statusbar), "Folder View");
992         mainwin->summaryview_cid = gtk_statusbar_get_context_id
993                 (GTK_STATUSBAR(statusbar), "Summary View");
994
995         /* allocate colors for summary view and folder view */
996         summaryview->color_marked.red = summaryview->color_marked.green = 0;
997         summaryview->color_marked.blue = (guint16)65535;
998
999         summaryview->color_dim.red = summaryview->color_dim.green =
1000                 summaryview->color_dim.blue = COLOR_DIM;
1001
1002         folderview->color_new.red = (guint16)55000;
1003         folderview->color_new.green = folderview->color_new.blue = 15000;
1004
1005         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1006                                        &folderview->color_op);
1007
1008         summaryview->color_important.red = 0;
1009         summaryview->color_important.green = 0;
1010         summaryview->color_important.blue = (guint16)65535;
1011
1012         color[0] = summaryview->color_marked;
1013         color[1] = summaryview->color_dim;
1014         color[2] = folderview->color_new;
1015         color[3] = folderview->color_op;
1016
1017         colormap = gdk_window_get_colormap(window->window);
1018         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1019         for (i = 0; i < 4; i++) {
1020                 if (success[i] == FALSE)
1021                         g_warning(_("MainWindow: color allocation %d failed\n"), i);
1022         }
1023
1024         debug_print(_("done.\n"));
1025
1026         messageview->visible = TRUE;
1027
1028         main_window_set_widgets(mainwin, type);
1029
1030         /* set menu items */
1031         menuitem = gtk_item_factory_get_item
1032                 (ifactory, "/View/Code set/Auto detect");
1033         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1034
1035         switch (prefs_common.toolbar_style) {
1036         case TOOLBAR_NONE:
1037                 menuitem = gtk_item_factory_get_item
1038                         (ifactory, "/View/Show or hide/Toolbar/None");
1039                 break;
1040         case TOOLBAR_ICON:
1041                 menuitem = gtk_item_factory_get_item
1042                         (ifactory, "/View/Show or hide/Toolbar/Icon");
1043                 break;
1044         case TOOLBAR_TEXT:
1045                 menuitem = gtk_item_factory_get_item
1046                         (ifactory, "/View/Show or hide/Toolbar/Text");
1047                 break;
1048         case TOOLBAR_BOTH:
1049                 menuitem = gtk_item_factory_get_item
1050                         (ifactory, "/View/Show or hide/Toolbar/Icon and text");
1051         }
1052         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1053
1054         gtk_widget_hide(mainwin->hbox_stat);
1055         menuitem = gtk_item_factory_get_item
1056                 (ifactory, "/View/Show or hide/Status bar");
1057         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1058                                        prefs_common.show_statusbar);
1059
1060         /* set account selection menu */
1061         ac_menu = gtk_item_factory_get_widget
1062                 (ifactory, "/Configuration/Change current account");
1063         gtk_signal_connect(GTK_OBJECT(ac_menu), "selection_done",
1064                            GTK_SIGNAL_FUNC(ac_menu_popup_closed), mainwin);
1065         mainwin->ac_menu = ac_menu;
1066
1067         main_window_set_toolbar_sensitive(mainwin);
1068
1069         /* create actions menu */
1070         update_mainwin_actions_menu(ifactory, mainwin);
1071
1072         /* show main window */
1073         gtk_widget_set_uposition(mainwin->window,
1074                                  prefs_common.mainwin_x,
1075                                  prefs_common.mainwin_y);
1076         gtk_widget_set_usize(window, prefs_common.mainwin_width,
1077                              prefs_common.mainwin_height);
1078         gtk_widget_show(mainwin->window);
1079
1080         /* initialize views */
1081         folderview_init(folderview);
1082         summary_init(summaryview);
1083         messageview_init(messageview);
1084         log_window_init(mainwin->logwin);
1085
1086         mainwin->lock_count = 0;
1087         mainwin->menu_lock_count = 0;
1088         mainwin->cursor_count = 0;
1089
1090         if (!watch_cursor)
1091                 watch_cursor = gdk_cursor_new(GDK_WATCH);
1092
1093         mainwin_list = g_list_append(mainwin_list, mainwin);
1094
1095         /* init work_offline */
1096         if (prefs_common.work_offline)
1097                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1098
1099         return mainwin;
1100 }
1101
1102 void main_window_cursor_wait(MainWindow *mainwin)
1103 {
1104
1105         if (mainwin->cursor_count == 0)
1106                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1107
1108         mainwin->cursor_count++;
1109
1110         gdk_flush();
1111 }
1112
1113 void main_window_cursor_normal(MainWindow *mainwin)
1114 {
1115         if (mainwin->cursor_count)
1116                 mainwin->cursor_count--;
1117
1118         if (mainwin->cursor_count == 0)
1119                 gdk_window_set_cursor(mainwin->window->window, NULL);
1120
1121         gdk_flush();
1122 }
1123
1124 /* lock / unlock the user-interface */
1125 void main_window_lock(MainWindow *mainwin)
1126 {
1127         if (mainwin->lock_count == 0)
1128                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1129
1130         mainwin->lock_count++;
1131
1132         main_window_set_menu_sensitive(mainwin);
1133         main_window_set_toolbar_sensitive(mainwin);
1134 }
1135
1136 void main_window_unlock(MainWindow *mainwin)
1137 {
1138         if (mainwin->lock_count)
1139                 mainwin->lock_count--;
1140
1141         main_window_set_menu_sensitive(mainwin);
1142         main_window_set_toolbar_sensitive(mainwin);
1143
1144         if (mainwin->lock_count == 0)
1145                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1146 }
1147
1148 static void main_window_menu_callback_block(MainWindow *mainwin)
1149 {
1150         mainwin->menu_lock_count++;
1151 }
1152
1153 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1154 {
1155         if (mainwin->menu_lock_count)
1156                 mainwin->menu_lock_count--;
1157 }
1158
1159 void main_window_reflect_prefs_all(void)
1160 {
1161         main_window_reflect_prefs_all_real(FALSE);
1162 }
1163
1164 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1165 {
1166         GList *cur;
1167         MainWindow *mainwin;
1168
1169         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1170                 mainwin = (MainWindow *)cur->data;
1171
1172                 main_window_show_cur_account(mainwin);
1173                 main_window_set_menu_sensitive(mainwin);
1174                 main_window_set_toolbar_sensitive(mainwin);
1175
1176                 /* pixmap themes */
1177                 if (pixmap_theme_changed) {
1178                         gtk_container_remove(GTK_CONTAINER(mainwin->handlebox), GTK_WIDGET(mainwin->toolbar));
1179                         mainwin->toolbar = NULL;
1180                         main_window_toolbar_create(mainwin, mainwin->handlebox);
1181                         set_toolbar_style(mainwin);
1182                         activate_compose_button(mainwin, prefs_common.toolbar_style, mainwin->compose_btn_type);
1183                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1184                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1185                         sd_reflect_prefs_pixmap_theme();
1186                 }
1187                 
1188                 if (prefs_common.immediate_exec)
1189                         gtk_widget_hide(mainwin->exec_btn);
1190                 else
1191                         gtk_widget_show(mainwin->exec_btn);
1192
1193                 summary_redisplay_msg(mainwin->summaryview);
1194                 headerview_set_visibility(mainwin->messageview->headerview,
1195                                           prefs_common.display_header_pane);
1196         }
1197 }
1198
1199 void main_window_set_summary_column(void)
1200 {
1201         GList *cur;
1202         MainWindow *mainwin;
1203
1204         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1205                 mainwin = (MainWindow *)cur->data;
1206                 summary_set_column_order(mainwin->summaryview);
1207         }
1208 }
1209
1210 void main_window_set_account_menu(GList *account_list)
1211 {
1212         GList *cur, *cur_ac, *cur_item;
1213         GtkWidget *menuitem;
1214         MainWindow *mainwin;
1215         PrefsAccount *ac_prefs;
1216
1217         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1218                 mainwin = (MainWindow *)cur->data;
1219
1220                 /* destroy all previous menu item */
1221                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1222                 while (cur_item != NULL) {
1223                         GList *next = cur_item->next;
1224                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1225                         cur_item = next;
1226                 }
1227
1228                 for (cur_ac = account_list; cur_ac != NULL;
1229                      cur_ac = cur_ac->next) {
1230                         ac_prefs = (PrefsAccount *)cur_ac->data;
1231
1232                         menuitem = gtk_menu_item_new_with_label
1233                                 (ac_prefs->account_name
1234                                  ? ac_prefs->account_name : _("Untitled"));
1235                         gtk_widget_show(menuitem);
1236                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1237                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
1238                                            GTK_SIGNAL_FUNC(account_menu_cb),
1239                                            ac_prefs);
1240                 }
1241         }
1242 }
1243
1244 static void main_window_show_cur_account(MainWindow *mainwin)
1245 {
1246         gchar *buf;
1247         gchar *ac_name;
1248
1249         ac_name = g_strdup(cur_account
1250                            ? (cur_account->account_name
1251                               ? cur_account->account_name : _("Untitled"))
1252                            : _("none"));
1253
1254         if (cur_account)
1255                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1256         else
1257                 buf = g_strdup(PROG_VERSION);
1258         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1259         g_free(buf);
1260
1261         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1262         gtk_widget_queue_resize(mainwin->ac_button);
1263
1264         g_free(ac_name);
1265 }
1266
1267 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1268 {
1269         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1270         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1271         GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
1272
1273         debug_print(_("Changing window separation type from %d to %d\n"),
1274                     mainwin->type, type);
1275
1276         if (mainwin->type == type) return;
1277
1278         /* remove widgets from those containers */
1279         gtk_widget_ref(folder_wid);
1280         gtk_widget_ref(summary_wid);
1281         gtk_widget_ref(message_wid);
1282         gtkut_container_remove
1283                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1284         gtkut_container_remove
1285                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1286         gtkut_container_remove
1287                 (GTK_CONTAINER(message_wid->parent), message_wid);
1288
1289         /* clean containers */
1290         switch (mainwin->type) {
1291         case SEPARATE_NONE:
1292                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1293                 break;
1294         case SEPARATE_FOLDER:
1295                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1296                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1297                 break;
1298         case SEPARATE_MESSAGE:
1299                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1300                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1301                 break;
1302         case SEPARATE_BOTH:
1303                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1304                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1305                 break;
1306         }
1307
1308         gtk_widget_hide(mainwin->window);
1309         main_window_set_widgets(mainwin, type);
1310         gtk_widget_show(mainwin->window);
1311
1312         gtk_widget_unref(folder_wid);
1313         gtk_widget_unref(summary_wid);
1314         gtk_widget_unref(message_wid);
1315 }
1316
1317 void main_window_toggle_message_view(MainWindow *mainwin)
1318 {
1319         SummaryView *summaryview = mainwin->summaryview;
1320         union CompositeWin *cwin = &mainwin->win;
1321         GtkWidget *vpaned = NULL;
1322         GtkWidget *container = NULL;
1323         GtkWidget *msgwin = NULL;
1324
1325         switch (mainwin->type) {
1326         case SEPARATE_NONE:
1327                 vpaned = cwin->sep_none.vpaned;
1328                 container = cwin->sep_none.hpaned;
1329                 break;
1330         case SEPARATE_FOLDER:
1331                 vpaned = cwin->sep_folder.vpaned;
1332                 container = mainwin->vbox_body;
1333                 break;
1334         case SEPARATE_MESSAGE:
1335                 msgwin = mainwin->win.sep_message.messagewin;
1336                 break;
1337         case SEPARATE_BOTH:
1338                 msgwin = mainwin->win.sep_both.messagewin;
1339                 break;
1340         }
1341
1342         if (msgwin) {
1343                 if (GTK_WIDGET_VISIBLE(msgwin)) {
1344                         gtk_widget_hide(msgwin);
1345                         mainwin->messageview->visible = FALSE;
1346                         summaryview->displayed = NULL;
1347                 } else {
1348                         gtk_widget_show(msgwin);
1349                         mainwin->messageview->visible = TRUE;
1350                 }
1351         } else if (vpaned->parent != NULL) {
1352                 mainwin->messageview->visible = FALSE;
1353                 summaryview->displayed = NULL;
1354                 gtk_widget_ref(vpaned);
1355                 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1356                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1357                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1358                               GTK_ARROW_UP, GTK_SHADOW_OUT);
1359         } else {
1360                 mainwin->messageview->visible = TRUE;
1361                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
1362                 gtk_container_add(GTK_CONTAINER(container), vpaned);
1363                 gtk_widget_unref(vpaned);
1364                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1365                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1366         }
1367
1368         main_window_set_menu_sensitive(mainwin);
1369
1370         gtk_widget_grab_focus(summaryview->ctree);
1371 }
1372
1373 void main_window_get_size(MainWindow *mainwin)
1374 {
1375         GtkAllocation *allocation;
1376
1377         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1378
1379         prefs_common.summaryview_width  = allocation->width;
1380
1381         if ((mainwin->type == SEPARATE_NONE ||
1382              mainwin->type == SEPARATE_FOLDER) &&
1383             messageview_is_visible(mainwin->messageview))
1384                 prefs_common.summaryview_height = allocation->height;
1385
1386         prefs_common.mainview_width     = allocation->width;
1387
1388         allocation = &mainwin->window->allocation;
1389
1390         prefs_common.mainview_height = allocation->height;
1391         prefs_common.mainwin_width   = allocation->width;
1392         prefs_common.mainwin_height  = allocation->height;
1393
1394         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1395
1396         prefs_common.folderview_width  = allocation->width;
1397         prefs_common.folderview_height = allocation->height;
1398 }
1399
1400 void main_window_get_position(MainWindow *mainwin)
1401 {
1402         gint x, y;
1403
1404         gtkut_widget_get_uposition(mainwin->window, &x, &y);
1405
1406         prefs_common.mainview_x = x;
1407         prefs_common.mainview_y = y;
1408         prefs_common.mainwin_x = x;
1409         prefs_common.mainwin_y = y;
1410
1411         debug_print(_("window position: x = %d, y = %d\n"), x, y);
1412 }
1413
1414 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1415 {
1416         GList *list;
1417         guint has_trash;
1418         Folder *folder;
1419
1420         for (has_trash = 0, list = folder_get_list(); list != NULL; list = list->next) {
1421                 folder = FOLDER(list->data);
1422                 if (folder && folder->trash && folder->trash->total > 0)
1423                         has_trash++;
1424         }
1425
1426         if (!has_trash) return;
1427         
1428         if (confirm) {
1429                 if (alertpanel(_("Empty trash"),
1430                                _("Empty all messages in trash?"),
1431                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1432                         return;
1433                 manage_window_focus_in(mainwin->window, NULL, NULL);
1434         }
1435
1436         procmsg_empty_trash();
1437
1438         for (list = folder_get_list(); list != NULL; list = list->next) {
1439                 folder = list->data;
1440                 if (folder && folder->trash) {
1441                         folderview_update_item(folder->trash, TRUE);
1442                 }
1443         }
1444
1445         if (mainwin->summaryview->folder_item &&
1446             mainwin->summaryview->folder_item->stype == F_TRASH)
1447                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1448 }
1449
1450 void main_window_add_mailbox(MainWindow *mainwin)
1451 {
1452         gchar *path;
1453         Folder *folder;
1454
1455         path = input_dialog(_("Add mailbox"),
1456                             _("Input the location of mailbox.\n"
1457                               "If the existing mailbox is specified, it will be\n"
1458                               "scanned automatically."),
1459                             "Mail");
1460         if (!path) return;
1461         if (folder_find_from_path(path)) {
1462                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1463                 g_free(path);
1464                 return;
1465         }
1466         if (!strcmp(path, "Mail"))
1467                 folder = folder_new(F_MH, _("Mailbox"), path);
1468         else
1469                 folder = folder_new(F_MH, g_basename(path), path);
1470         g_free(path);
1471
1472         if (folder->create_tree(folder) < 0) {
1473                 alertpanel_error(_("Creation of the mailbox failed.\n"
1474                                    "Maybe some files already exist, or you don't have the permission to write there."));
1475                 folder_destroy(folder);
1476                 return;
1477         }
1478
1479         folder_add(folder);
1480         folder_set_ui_func(folder, scan_tree_func, mainwin);
1481         folder_scan_tree(folder);
1482         folder_set_ui_func(folder, NULL, NULL);
1483
1484         folderview_set(mainwin->folderview);
1485 }
1486
1487 void main_window_add_mbox(MainWindow *mainwin)
1488 {
1489         gchar *path;
1490         Folder *folder;
1491         FolderItem * item;
1492
1493         path = input_dialog(_("Add mbox mailbox"),
1494                             _("Input the location of mailbox."),
1495                             "mail");
1496
1497         if (!path) return;
1498
1499         if (folder_find_from_path(path)) {
1500                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1501                 g_free(path);
1502                 return;
1503         }
1504
1505         /*
1506         if (!strcmp(path, "Mail"))
1507                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1508                 else
1509         */
1510
1511         folder = folder_new(F_MBOX, g_basename(path), path);
1512         g_free(path);
1513
1514         if (folder->create_tree(folder) < 0) {
1515                 alertpanel_error(_("Creation of the mailbox failed."));
1516                 folder_destroy(folder);
1517                 return;
1518         }
1519
1520         folder_add(folder);
1521
1522         item = folder_item_new(folder->name, NULL);
1523         item->folder = folder;
1524         folder->node = g_node_new(item);
1525
1526         folder->create_folder(folder, item, "inbox");
1527         folder->create_folder(folder, item, "outbox");
1528         folder->create_folder(folder, item, "queue");
1529         folder->create_folder(folder, item, "draft");
1530         folder->create_folder(folder, item, "trash");
1531
1532         folderview_set(mainwin->folderview);
1533 }
1534
1535 typedef enum
1536 {
1537         M_UNLOCKED            = 1 << 0,
1538         M_MSG_EXIST           = 1 << 1,
1539         M_TARGET_EXIST        = 1 << 2,
1540         M_SINGLE_TARGET_EXIST = 1 << 3,
1541         M_EXEC                = 1 << 4,
1542         M_ALLOW_REEDIT        = 1 << 5,
1543         M_HAVE_ACCOUNT        = 1 << 6,
1544         M_THREADED            = 1 << 7,
1545         M_UNTHREADED          = 1 << 8,
1546         M_ALLOW_DELETE        = 1 << 9,
1547         M_INC_ACTIVE          = 1 << 10,
1548         M_NEWS                = 1 << 11,
1549         M_HAVE_NEWS_ACCOUNT   = 1 << 12,
1550         M_HIDE_READ_MSG       = 1 << 13
1551 } SensitiveCond;
1552
1553 static SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1554 {
1555         SensitiveCond state = 0;
1556         SummarySelection selection;
1557         FolderItem *item = mainwin->summaryview->folder_item;
1558         GList *account_list = account_get_list();
1559         
1560         selection = summary_get_selection_type(mainwin->summaryview);
1561
1562         if (mainwin->lock_count == 0)
1563                 state |= M_UNLOCKED;
1564         if (selection != SUMMARY_NONE)
1565                 state |= M_MSG_EXIST;
1566         if (item && item->path && item->parent && !item->no_select) {
1567                 state |= M_EXEC;
1568                 if (item->threaded)
1569                         state |= M_THREADED;
1570                 else
1571                         state |= M_UNTHREADED;  
1572                 /*              if (item->folder->type != F_NEWS) */
1573                 state |= M_ALLOW_DELETE;
1574
1575                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
1576                     || selection != SUMMARY_NONE)
1577                         state |= M_HIDE_READ_MSG;       
1578         }               
1579         if (selection == SUMMARY_SELECTED_SINGLE ||
1580             selection == SUMMARY_SELECTED_MULTIPLE)
1581                 state |= M_TARGET_EXIST;
1582         if (selection == SUMMARY_SELECTED_SINGLE)
1583                 state |= M_SINGLE_TARGET_EXIST;
1584         if (mainwin->summaryview->folder_item &&
1585             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1586                 state |= M_NEWS;
1587         if (selection == SUMMARY_SELECTED_SINGLE &&
1588             (item &&
1589              (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1590               item->stype == F_QUEUE)))
1591                 state |= M_ALLOW_REEDIT;
1592         if (cur_account)
1593                 state |= M_HAVE_ACCOUNT;
1594         
1595         for ( ; account_list != NULL; account_list = account_list->next) {
1596                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
1597                         state |= M_HAVE_NEWS_ACCOUNT;
1598                         break;
1599                 }
1600         }
1601
1602         if (inc_is_active())
1603                 state |= M_INC_ACTIVE;
1604
1605         return state;
1606 }
1607
1608 void main_window_set_toolbar_sensitive(MainWindow *mainwin)
1609 {
1610         SensitiveCond state;
1611         gboolean sensitive;
1612         gint i = 0;
1613
1614         struct {
1615                 GtkWidget *widget;
1616                 SensitiveCond cond;
1617         } entry[11];
1618
1619 #define SET_WIDGET_COND(w, c)   \
1620 {                               \
1621         entry[i].widget = w;    \
1622         entry[i].cond = c;      \
1623         i++;                    \
1624 }
1625
1626         SET_WIDGET_COND(mainwin->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1627         SET_WIDGET_COND(mainwin->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1628         SET_WIDGET_COND(mainwin->compose_news_btn, M_HAVE_ACCOUNT);
1629         SET_WIDGET_COND(mainwin->reply_btn,
1630                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1631         SET_WIDGET_COND(mainwin->replyall_btn,
1632                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1633         SET_WIDGET_COND(mainwin->replysender_btn,
1634                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1635         SET_WIDGET_COND(mainwin->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1636 #if 0
1637         SET_WIDGET_COND(mainwin->prefs_btn, M_UNLOCKED);
1638         SET_WIDGET_COND(mainwin->account_btn, M_UNLOCKED);
1639 #endif
1640         SET_WIDGET_COND(mainwin->next_btn, M_MSG_EXIST);
1641         SET_WIDGET_COND(mainwin->delete_btn,
1642                         M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1643         SET_WIDGET_COND(mainwin->exec_btn, M_MSG_EXIST|M_EXEC|M_UNLOCKED);
1644         SET_WIDGET_COND(NULL, 0);
1645
1646 #undef SET_WIDGET_COND
1647
1648         state = main_window_get_current_state(mainwin);
1649
1650         for (i = 0; entry[i].widget != NULL; i++) {
1651                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1652                 gtk_widget_set_sensitive(entry[i].widget, sensitive);
1653         }
1654
1655         activate_compose_button(mainwin, 
1656                         prefs_common.toolbar_style,
1657                         mainwin->compose_btn_type);
1658 }
1659
1660 void main_window_set_menu_sensitive(MainWindow *mainwin)
1661 {
1662         GtkItemFactory *ifactory = mainwin->menu_factory;
1663         SensitiveCond state;
1664         gboolean sensitive;
1665         GtkWidget *menuitem;
1666         FolderItem *item;
1667         gchar *menu_path;
1668         gint i;
1669
1670         static const struct {
1671                 gchar *const entry;
1672                 SensitiveCond cond;
1673         } entry[] = {
1674                 {"/File/Add mailbox..."        , M_UNLOCKED},
1675                 {"/File/Add mbox mailbox..."   , M_UNLOCKED},
1676                 {"/File/Rescan folder tree"    , M_UNLOCKED},
1677                 {"/File/Folder"                , M_UNLOCKED},
1678                 {"/File/Import mbox file..."   , M_UNLOCKED},
1679                 {"/File/Export to mbox file...", M_UNLOCKED},
1680                 {"/File/Empty trash"           , M_UNLOCKED},
1681                 {"/File/Work offline"          , M_UNLOCKED},
1682                 {"/File/Save as...", M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1683                 {"/File/Print..."  , M_TARGET_EXIST|M_UNLOCKED},
1684                 /* {"/File/Close", M_UNLOCKED}, */
1685                 {"/File/Exit" , M_UNLOCKED},
1686
1687                 {"/Edit/Select thread"             , M_SINGLE_TARGET_EXIST},
1688                 {"/View/Sort"                      , M_EXEC},
1689                 {"/View/Thread view"               , M_EXEC},
1690                 {"/View/Expand all threads"        , M_MSG_EXIST},
1691                 {"/View/Collapse all threads"      , M_MSG_EXIST},
1692                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
1693                 {"/View/Go to/Prev message"        , M_MSG_EXIST},
1694                 {"/View/Go to/Next message"        , M_MSG_EXIST},
1695                 {"/View/Go to/Prev unread message" , M_MSG_EXIST},
1696                 {"/View/Go to/Next unread message" , M_MSG_EXIST},
1697                 {"/View/Go to/Prev new message"    , M_MSG_EXIST},
1698                 {"/View/Go to/Next new message"    , M_MSG_EXIST},
1699                 {"/View/Go to/Prev marked message" , M_MSG_EXIST},
1700                 {"/View/Go to/Next marked message" , M_MSG_EXIST},
1701                 {"/View/Go to/Prev labeled message", M_MSG_EXIST},
1702                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
1703                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
1704                 {"/View/Show all header"           , M_SINGLE_TARGET_EXIST},
1705                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
1706
1707                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1708                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1709                 {"/Message/Cancel receiving"      , M_INC_ACTIVE},
1710                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
1711                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1712                 {"/Message/Reply to sender"       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1713                 {"/Message/Reply to all"          , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1714                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1715                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1716                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1717                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1718                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1719                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1720                 {"/Message/Delete"                , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1721                 {"/Message/Mark"                  , M_TARGET_EXIST},
1722
1723                 {"/Tools/Selective download..."     , M_HAVE_ACCOUNT|M_UNLOCKED},
1724                 {"/Tools/Add sender to address book", M_SINGLE_TARGET_EXIST},
1725                 {"/Tools/Harvest addresses"         , M_UNLOCKED},
1726                 {"/Tools/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1727                 {"/Tools/Create filter rule"        , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1728                 {"/Tools/Actions"                   , M_TARGET_EXIST|M_UNLOCKED},
1729                 {"/Tools/Execute"                   , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1730                 {"/Tools/Delete duplicated messages", M_MSG_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1731
1732                 {"/Configuration", M_UNLOCKED},
1733
1734                 {NULL, 0}
1735         };
1736
1737         state = main_window_get_current_state(mainwin);
1738
1739         for (i = 0; entry[i].entry != NULL; i++) {
1740                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1741                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
1742         }
1743
1744         main_window_menu_callback_block(mainwin);
1745
1746 #define SET_CHECK_MENU_ACTIVE(path, active) \
1747 { \
1748         menuitem = gtk_item_factory_get_widget(ifactory, path); \
1749         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
1750 }
1751
1752         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
1753                               messageview_is_visible(mainwin->messageview));
1754
1755         item = mainwin->summaryview->folder_item;
1756         menu_path = "/View/Sort/Don't sort";
1757         if (item) {
1758                 switch (item->sort_key) {
1759                 case SORT_BY_NUMBER:
1760                         menu_path = "/View/Sort/by number"; break;
1761                 case SORT_BY_SIZE:
1762                         menu_path = "/View/Sort/by size"; break;
1763                 case SORT_BY_DATE:
1764                         menu_path = "/View/Sort/by date"; break;
1765                 case SORT_BY_FROM:
1766                         menu_path = "/View/Sort/by from"; break;
1767                 case SORT_BY_SUBJECT:
1768                         menu_path = "/View/Sort/by subject"; break;
1769                 case SORT_BY_LABEL:
1770                         menu_path = "/View/Sort/by color label"; break;
1771                 case SORT_BY_MARK:
1772                         menu_path = "/View/Sort/by mark"; break;
1773                 case SORT_BY_UNREAD:
1774                         menu_path = "/View/Sort/by unread"; break;
1775                 case SORT_BY_MIME:
1776                         menu_path = "/View/Sort/by attachment"; break;
1777                 case SORT_BY_SCORE:
1778                         menu_path = "/View/Sort/by score"; break;
1779                 case SORT_BY_LOCKED:
1780                         menu_path = "/View/Sort/by locked"; break;
1781                 case SORT_BY_NONE:
1782                 default:
1783                         menu_path = "/View/Sort/Don't sort"; break;
1784                 }
1785         }
1786         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
1787
1788         if (!item || item->sort_type == SORT_ASCENDING) {
1789                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
1790         } else {
1791                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
1792         }
1793
1794         if (item && item->sort_key != SORT_BY_NONE) {
1795                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
1796                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
1797         } else {
1798                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
1799                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
1800         }
1801
1802         SET_CHECK_MENU_ACTIVE("/View/Show all header",
1803                               mainwin->messageview->textview->show_all_headers);
1804         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
1805
1806 #undef SET_CHECK_MENU_ACTIVE
1807
1808         main_window_menu_callback_unblock(mainwin);
1809 }
1810
1811 void main_window_popup(MainWindow *mainwin)
1812 {
1813         gint x, y;
1814         gint sx, sy;
1815         GtkWidget *widget;
1816
1817         gdk_window_get_origin(mainwin->window->window, &x, &y);
1818         sx = gdk_screen_width();
1819         sy = gdk_screen_height();
1820         x %= sx; if (x < 0) x = 0;
1821         y %= sy; if (y < 0) y = 0;
1822         gdk_window_move(mainwin->window->window, x, y);
1823         gdk_window_raise(mainwin->window->window);
1824         gdk_window_show(mainwin->window->window);
1825
1826         debug_print("window position: x = %d, y = %d\n", x, y);
1827
1828         switch (mainwin->type) {
1829         case SEPARATE_FOLDER:
1830                 widget = mainwin->win.sep_folder.folderwin;
1831                 gdk_window_get_origin(widget->window, &x, &y);
1832                 x %= sx; if (x < 0) x = 0;
1833                 y %= sy; if (y < 0) y = 0;
1834                 gdk_window_move(widget->window, x, y);
1835                 gdk_window_raise(widget->window);
1836                 break;
1837         case SEPARATE_MESSAGE:
1838                 widget = mainwin->win.sep_message.messagewin;
1839                 gdk_window_get_origin(widget->window, &x, &y);
1840                 x %= sx; if (x < 0) x = 0;
1841                 y %= sy; if (y < 0) y = 0;
1842                 gdk_window_move(widget->window, x, y);
1843                 gdk_window_raise(widget->window);
1844                 break;
1845         case SEPARATE_BOTH:
1846                 widget = mainwin->win.sep_both.folderwin;
1847                 gdk_window_get_origin(widget->window, &x, &y);
1848                 x %= sx; if (x < 0) x = 0;
1849                 y %= sy; if (y < 0) y = 0;
1850                 gdk_window_move(widget->window, x, y);
1851                 gdk_window_raise(widget->window);
1852                 widget = mainwin->win.sep_both.messagewin;
1853                 gdk_window_get_origin(widget->window, &x, &y);
1854                 x %= sx; if (x < 0) x = 0;
1855                 y %= sy; if (y < 0) y = 0;
1856                 gdk_window_move(widget->window, x, y);
1857                 gdk_window_raise(widget->window);
1858                 break;
1859         default:
1860                 break;
1861         }
1862 }
1863
1864 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1865 {
1866         GtkWidget *folderwin = NULL;
1867         GtkWidget *messagewin = NULL;
1868         GtkWidget *hpaned;
1869         GtkWidget *vpaned;
1870         GtkWidget *vbox_body = mainwin->vbox_body;
1871         GtkItemFactory *ifactory = mainwin->menu_factory;
1872         GtkWidget *menuitem;
1873
1874         debug_print(_("Setting widgets..."));
1875
1876         /* create separated window(s) if needed */
1877         if (type & SEPARATE_FOLDER) {
1878                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1879                 gtk_window_set_title(GTK_WINDOW(folderwin),
1880                                      _("Sylpheed - Folder View"));
1881                 gtk_window_set_wmclass(GTK_WINDOW(folderwin),
1882                                        "folder_view", "Sylpheed");
1883                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1884                                       TRUE, TRUE, FALSE);
1885                 gtk_widget_set_usize(folderwin, -1,
1886                                      prefs_common.mainview_height);
1887                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1888                                                BORDER_WIDTH);
1889                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1890                                    GTK_SIGNAL_FUNC(folder_window_close_cb),
1891                                    mainwin);
1892         }
1893         if (type & SEPARATE_MESSAGE) {
1894                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1895                 gtk_window_set_title(GTK_WINDOW(messagewin),
1896                                      _("Sylpheed - Message View"));
1897                 gtk_window_set_wmclass(GTK_WINDOW(messagewin),
1898                                        "message_view", "Sylpheed");
1899                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1900                                       TRUE, TRUE, FALSE);
1901                 gtk_widget_set_usize
1902                         (messagewin, prefs_common.mainview_width,
1903                          prefs_common.mainview_height
1904                          - prefs_common.summaryview_height
1905                          + DEFAULT_HEADERVIEW_HEIGHT);
1906                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1907                                                BORDER_WIDTH);
1908                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1909                                    GTK_SIGNAL_FUNC(message_window_close_cb),
1910                                    mainwin);
1911         }
1912
1913         switch (type) {
1914         case SEPARATE_NONE:
1915                 hpaned = gtk_hpaned_new();
1916                 gtk_widget_show(hpaned);
1917                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1918                 gtk_paned_add1(GTK_PANED(hpaned),
1919                                GTK_WIDGET_PTR(mainwin->folderview));
1920
1921                 vpaned = gtk_vpaned_new();
1922                 if (messageview_is_visible(mainwin->messageview)) {
1923                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1924                         gtk_paned_add1(GTK_PANED(vpaned),
1925                                        GTK_WIDGET_PTR(mainwin->summaryview));
1926                 } else {
1927                         gtk_paned_add2(GTK_PANED(hpaned),
1928                                        GTK_WIDGET_PTR(mainwin->summaryview));
1929                         gtk_widget_ref(vpaned);
1930                 }
1931                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1932                                      prefs_common.summaryview_width,
1933                                      prefs_common.summaryview_height);
1934                 gtk_paned_add2(GTK_PANED(vpaned),
1935                                GTK_WIDGET_PTR(mainwin->messageview));
1936                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1937                                      prefs_common.mainview_width, -1);
1938                 gtk_widget_set_usize(mainwin->window,
1939                                      prefs_common.folderview_width +
1940                                      prefs_common.mainview_width,
1941                                      prefs_common.mainwin_height);
1942                 gtk_widget_show_all(vpaned);
1943
1944                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1945                  * lose track of its visibility state */
1946                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1947                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1948
1949                 mainwin->win.sep_none.hpaned = hpaned;
1950                 mainwin->win.sep_none.vpaned = vpaned;
1951                 break;
1952         case SEPARATE_FOLDER:
1953                 vpaned = gtk_vpaned_new();
1954                 if (messageview_is_visible(mainwin->messageview)) {
1955                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1956                                            TRUE, TRUE, 0);
1957                         gtk_paned_add1(GTK_PANED(vpaned),
1958                                        GTK_WIDGET_PTR(mainwin->summaryview));
1959                 } else {
1960                         gtk_box_pack_start(GTK_BOX(vbox_body),
1961                                            GTK_WIDGET_PTR(mainwin->summaryview),
1962                                            TRUE, TRUE, 0);
1963                         gtk_widget_ref(vpaned);
1964                 }
1965                 gtk_paned_add2(GTK_PANED(vpaned),
1966                                GTK_WIDGET_PTR(mainwin->messageview));
1967                 gtk_widget_show_all(vpaned);
1968                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1969                                      prefs_common.summaryview_width,
1970                                      prefs_common.summaryview_height);
1971                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1972                                      prefs_common.mainview_width, -1);
1973                 gtk_widget_set_usize(mainwin->window,
1974                                      prefs_common.mainview_width,
1975                                      prefs_common.mainview_height);
1976
1977                 gtk_container_add(GTK_CONTAINER(folderwin),
1978                                   GTK_WIDGET_PTR(mainwin->folderview));
1979
1980                 mainwin->win.sep_folder.folderwin = folderwin;
1981                 mainwin->win.sep_folder.vpaned    = vpaned;
1982
1983                 gtk_widget_show_all(folderwin);
1984                 break;
1985         case SEPARATE_MESSAGE:
1986                 hpaned = gtk_hpaned_new();
1987                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1988
1989                 gtk_paned_add1(GTK_PANED(hpaned),
1990                                GTK_WIDGET_PTR(mainwin->folderview));
1991                 gtk_paned_add2(GTK_PANED(hpaned),
1992                                GTK_WIDGET_PTR(mainwin->summaryview));
1993                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1994                                      prefs_common.summaryview_width,
1995                                      prefs_common.summaryview_height);
1996                 gtk_widget_set_usize(mainwin->window,
1997                                      prefs_common.folderview_width +
1998                                      prefs_common.mainview_width,
1999                                      prefs_common.mainwin_height);
2000                 gtk_widget_show_all(hpaned);
2001                 gtk_container_add(GTK_CONTAINER(messagewin),
2002                                   GTK_WIDGET_PTR(mainwin->messageview));
2003
2004                 mainwin->win.sep_message.messagewin = messagewin;
2005                 mainwin->win.sep_message.hpaned     = hpaned;
2006
2007                 gtk_widget_show_all(messagewin);
2008                 
2009                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
2010                  * lose track of its visibility state */
2011                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
2012                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
2013                 break;
2014         case SEPARATE_BOTH:
2015                 gtk_box_pack_start(GTK_BOX(vbox_body),
2016                                    GTK_WIDGET_PTR(mainwin->summaryview),
2017                                    TRUE, TRUE, 0);
2018                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
2019                                      prefs_common.summaryview_width,
2020                                      prefs_common.summaryview_height);
2021                 gtk_widget_set_usize(mainwin->window,
2022                                      prefs_common.mainview_width,
2023                                      prefs_common.mainwin_height);
2024                 gtk_container_add(GTK_CONTAINER(folderwin),
2025                                   GTK_WIDGET_PTR(mainwin->folderview));
2026                 gtk_container_add(GTK_CONTAINER(messagewin),
2027                                   GTK_WIDGET_PTR(mainwin->messageview));
2028
2029                 mainwin->win.sep_both.folderwin = folderwin;
2030                 mainwin->win.sep_both.messagewin = messagewin;
2031
2032                 gtk_widget_show_all(folderwin);
2033                 gtk_widget_show_all(messagewin);
2034                 
2035                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
2036                  * lose track of its visibility state */
2037                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
2038                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
2039                 break;
2040         }
2041
2042         mainwin->type = type;
2043
2044         mainwin->messageview->visible = TRUE;
2045
2046         /* toggle menu state */
2047         menuitem = gtk_item_factory_get_item
2048                 (ifactory, "/View/Show or hide/Folder tree");
2049         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2050         menuitem = gtk_item_factory_get_item
2051                 (ifactory, "/View/Show or hide/Message view");
2052         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2053
2054         menuitem = gtk_item_factory_get_item
2055                 (ifactory, "/View/Separate folder tree");
2056         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2057                                        ((type & SEPARATE_FOLDER) != 0));
2058         menuitem = gtk_item_factory_get_item
2059                 (ifactory, "/View/Separate message view");
2060         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2061                                        ((type & SEPARATE_MESSAGE) != 0));
2062
2063         debug_print(_("done.\n"));
2064 }
2065
2066 static void main_window_toolbar_create(MainWindow *mainwin,
2067                                        GtkWidget *container)
2068 {
2069         GtkWidget *toolbar;
2070         GtkWidget *icon_wid;
2071         GtkWidget *get_btn;
2072         GtkWidget *getall_btn;
2073         GtkWidget *compose_mail_btn;
2074         GtkWidget *compose_news_btn;
2075         GtkWidget *reply_btn;
2076         GtkWidget *replyall_btn;
2077         GtkWidget *replysender_btn;
2078         GtkWidget *fwd_btn;
2079         GtkWidget *send_btn;
2080 #if 0
2081         GtkWidget *prefs_btn;
2082         GtkWidget *account_btn;
2083 #endif
2084         GtkWidget *next_btn;
2085         GtkWidget *delete_btn;
2086         GtkWidget *exec_btn;
2087         
2088         toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
2089                                   GTK_TOOLBAR_BOTH);
2090         gtk_container_add(GTK_CONTAINER(container), toolbar);
2091         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2092         gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
2093         gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
2094                                     GTK_TOOLBAR_SPACE_LINE);
2095
2096         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_RECEIVE);
2097         get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2098                                           _("Get"),
2099                                           _("Get new mail from current account"),
2100                                           "Get",
2101                                           icon_wid, toolbar_inc_cb, mainwin);
2102         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_RECEIVE_ALL);
2103         getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2104                                              _("Get all"),
2105                                              _("Get new mail from all accounts"),
2106                                              "Get all",
2107                                              icon_wid,
2108                                              toolbar_inc_all_cb,
2109                                              mainwin);
2110
2111         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2112
2113         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
2114         send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2115                                            _("Send"),
2116                                            _("Send queued message(s)"),
2117                                            "Send",
2118                                            icon_wid,
2119                                            toolbar_send_cb,
2120                                            mainwin);
2121
2122         /* insert compose mail button widget */                                    
2123         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_COMPOSE);
2124         compose_mail_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2125                                               _("Email"),
2126                                               _("Compose an email message"),
2127                                               "New",
2128                                               icon_wid,
2129                                               toolbar_compose_mail_cb,
2130                                               mainwin);
2131
2132         /* insert compose news button widget */
2133         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
2134         compose_news_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2135                                               _("News"),
2136                                               _("Compose a news message"),
2137                                               "New",
2138                                               icon_wid,
2139                                               toolbar_compose_news_cb,
2140                                               mainwin);
2141
2142         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2143         
2144         /* reply button */
2145         
2146         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_REPLY);
2147         reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2148                                             _("Reply"),
2149                                             _("Reply to the message - Right button: more options"),
2150                                             "Reply",
2151                                             icon_wid,
2152                                             toolbar_reply_cb,
2153                                             mainwin);
2154
2155         /* replyall button */
2156
2157         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_REPLY_TO_ALL);
2158         replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2159                                                _("All"),
2160                                                _("Reply to all - Right button: more options"),
2161                                                "Reply to all",
2162                                                icon_wid,
2163                                                toolbar_reply_to_all_cb,
2164                                                mainwin);
2165
2166         /* reply to sender button */
2167         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR);
2168         replysender_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2169                                                   _("Sender"),
2170                                                   _("Reply to sender - Right button: more options"),
2171                                                   "Reply to sender",
2172                                                   icon_wid,
2173                                                   toolbar_reply_to_sender_cb,
2174                                                   mainwin);
2175
2176         /* forward button */
2177         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_FORWARD);
2178         fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2179                                           _("Forward"),
2180                                           _("Forward the message - Right button: more options"),
2181                                           "Fwd",
2182                                           icon_wid,
2183                                           toolbar_forward_cb,
2184                                           mainwin);
2185
2186         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2187
2188         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_CLOSE);
2189         delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2190                                           _("Delete"),
2191                                           _("Delete the message"),
2192                                           "Delete",
2193                                           icon_wid,
2194                                           toolbar_delete_cb,
2195                                           mainwin);
2196
2197         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EXEC);
2198         exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2199                                            _("Execute"),
2200                                            _("Execute marked process"),
2201                                            "Execute",
2202                                            icon_wid,
2203                                            toolbar_exec_cb,
2204                                            mainwin);
2205
2206         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_DOWN_ARROW);
2207         next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2208                                            _("Next"),
2209                                            _("Next unread message"),
2210                                            "Next unread",
2211                                            icon_wid,
2212                                            toolbar_next_unread_cb,
2213                                            mainwin);
2214
2215 #if 0
2216         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2217
2218         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_PREFERENCES);
2219         prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2220                                             _("Prefs"),
2221                                             _("Common preferences"),
2222                                             "Prefs",
2223                                             icon_wid,
2224                                             toolbar_prefs_cb,
2225                                             mainwin);
2226         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_PROPERTIES);
2227         account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2228                                               _("Account"),
2229                                               _("Account setting"),
2230                                               "Account",
2231                                               icon_wid,
2232                                               toolbar_account_cb,
2233                                               mainwin);
2234         gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
2235                            GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
2236                            mainwin);
2237 #endif
2238
2239         gtk_signal_connect(GTK_OBJECT(reply_btn), "button_press_event",
2240                 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
2241                 mainwin);
2242         
2243         gtk_signal_connect(GTK_OBJECT(replyall_btn), "button_press_event",
2244                 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
2245                 mainwin);
2246         
2247         gtk_signal_connect(GTK_OBJECT(replysender_btn), "button_press_event",
2248                 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
2249                 mainwin);
2250         
2251         gtk_signal_connect(GTK_OBJECT(fwd_btn), "button_press_event",
2252                 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
2253                 mainwin);
2254         
2255
2256         mainwin->toolbar                = toolbar;
2257         mainwin->get_btn                = get_btn;
2258         mainwin->getall_btn             = getall_btn;
2259         mainwin->compose_mail_btn       = compose_mail_btn;
2260         mainwin->compose_news_btn       = compose_news_btn;
2261         mainwin->reply_btn              = reply_btn;
2262         mainwin->replyall_btn           = replyall_btn;
2263         mainwin->replysender_btn        = replysender_btn;
2264         mainwin->fwd_btn                = fwd_btn;
2265         mainwin->send_btn               = send_btn;
2266         #if 0
2267         mainwin->prefs_btn              = prefs_btn;
2268         mainwin->account_btn            = account_btn;
2269         #endif
2270         mainwin->next_btn               = next_btn;
2271         mainwin->delete_btn             = delete_btn;
2272         mainwin->exec_btn               = exec_btn;
2273
2274         gtk_widget_show_all(toolbar);
2275 }
2276
2277 /* callback functions */
2278 static void toolbar_reply_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2279 {
2280         MainWindow *mainwindow = (MainWindow *) data;
2281         
2282         if (!event) return;
2283
2284         if (event->button == 3) {
2285                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2286                 gtk_menu_popup(GTK_MENU(mainwindow->reply_popup), NULL, NULL,
2287                        menu_button_position, widget,
2288                        event->button, event->time);
2289         }
2290 }
2291
2292 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2293 {
2294         MainWindow *mainwin = (MainWindow *)data;
2295
2296         gtk_button_set_relief(GTK_BUTTON(mainwin->reply_btn), GTK_RELIEF_NONE);
2297         manage_window_focus_in(mainwin->window, NULL, NULL);
2298 }
2299
2300 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2301 {
2302         MainWindow *mainwindow = (MainWindow *) data;
2303         
2304         if (!event) return;
2305
2306         if (event->button == 3) {
2307                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2308                 gtk_menu_popup(GTK_MENU(mainwindow->replyall_popup), NULL, NULL,
2309                        menu_button_position, widget,
2310                        event->button, event->time);
2311         }
2312 }
2313
2314 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2315 {
2316         MainWindow *mainwin = (MainWindow *)data;
2317
2318         gtk_button_set_relief(GTK_BUTTON(mainwin->replyall_btn), GTK_RELIEF_NONE);
2319         manage_window_focus_in(mainwin->window, NULL, NULL);
2320 }
2321
2322 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2323 {
2324         MainWindow *mainwindow = (MainWindow *) data;
2325
2326         if (!event) return;
2327
2328         if (event->button == 3) {
2329                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2330                 gtk_menu_popup(GTK_MENU(mainwindow->replysender_popup), NULL, NULL,
2331                        menu_button_position, widget,
2332                        event->button, event->time);
2333         }
2334 }
2335
2336 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2337 {
2338         MainWindow *mainwin = (MainWindow *)data;
2339
2340         gtk_button_set_relief(GTK_BUTTON(mainwin->replysender_btn), GTK_RELIEF_NONE);
2341         manage_window_focus_in(mainwin->window, NULL, NULL);
2342 }
2343
2344 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2345 {
2346         MainWindow *mainwindow = (MainWindow *) data;
2347         
2348         if (!event) return;
2349
2350         if (event->button == 3) {
2351                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2352                 gtk_menu_popup(GTK_MENU(mainwindow->fwd_popup), NULL, NULL,
2353                        menu_button_position, widget,
2354                        event->button, event->time);
2355         }
2356 }
2357
2358 static void toolbar_forward_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2359 {
2360         MainWindow *mainwin = (MainWindow *)data;
2361
2362         gtk_button_set_relief(GTK_BUTTON(mainwin->fwd_btn), GTK_RELIEF_NONE);
2363         manage_window_focus_in(mainwin->window, NULL, NULL);
2364 }
2365
2366 static void toolbar_inc_cb      (GtkWidget      *widget,
2367                                  gpointer        data)
2368 {
2369         MainWindow *mainwin = (MainWindow *)data;
2370
2371         inc_mail_cb(mainwin, 0, NULL);
2372 }
2373
2374 static void toolbar_inc_all_cb  (GtkWidget      *widget,
2375                                  gpointer        data)
2376 {
2377         MainWindow *mainwin = (MainWindow *)data;
2378
2379         inc_all_account_mail_cb(mainwin, 0, NULL);
2380 }
2381
2382 static void toolbar_send_cb     (GtkWidget      *widget,
2383                                  gpointer        data)
2384 {
2385         MainWindow *mainwin = (MainWindow *)data;
2386
2387         send_queue_cb(mainwin, 0, NULL);
2388 }
2389
2390 static void toolbar_compose_news_cb     (GtkWidget      *widget,
2391                                  gpointer        data)
2392 {
2393         MainWindow *mainwin = (MainWindow *)data;
2394
2395         compose_news_cb(mainwin, 0, NULL);
2396 }
2397
2398 static void toolbar_compose_mail_cb     (GtkWidget      *widget,
2399                                  gpointer        data)
2400 {
2401         MainWindow *mainwin = (MainWindow *)data;
2402
2403         compose_mail_cb(mainwin, 0, NULL);
2404 }
2405
2406 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
2407 {
2408         MainWindow *mainwin = (MainWindow *)data;
2409
2410         reply_cb(mainwin, 
2411                  prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE 
2412                  : COMPOSE_REPLY_WITHOUT_QUOTE,
2413                  NULL);
2414 }
2415
2416 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
2417 {
2418         MainWindow *mainwin = (MainWindow *)data;
2419
2420         reply_cb(mainwin, 
2421                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
2422                  : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, 
2423                  NULL);
2424 }
2425
2426
2427 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
2428 {
2429         MainWindow *mainwin = (MainWindow *)data;
2430
2431         reply_cb(mainwin, 
2432                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
2433                  : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, 
2434                  NULL);
2435 }
2436
2437 static void toolbar_forward_cb  (GtkWidget      *widget,
2438                                  gpointer        data)
2439 {
2440         MainWindow *mainwin = (MainWindow *)data;
2441
2442         if (prefs_common.forward_as_attachment)
2443                 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
2444         else
2445                 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
2446 }
2447
2448 static void toolbar_delete_cb   (GtkWidget      *widget,
2449                                  gpointer        data)
2450 {
2451         MainWindow *mainwin = (MainWindow *)data;
2452
2453         summary_delete(mainwin->summaryview);
2454 }
2455
2456 static void toolbar_exec_cb     (GtkWidget      *widget,
2457                                  gpointer        data)
2458 {
2459         MainWindow *mainwin = (MainWindow *)data;
2460
2461         summary_execute(mainwin->summaryview);
2462 }
2463
2464 static void toolbar_next_unread_cb      (GtkWidget      *widget,
2465                                          gpointer        data)
2466 {
2467         MainWindow *mainwin = (MainWindow *)data;
2468
2469         next_unread_cb(mainwin, 0, NULL);
2470 }
2471
2472 #if 0
2473 static void toolbar_account_button_pressed(GtkWidget *widget,
2474                                            GdkEventButton *event,
2475                                            gpointer data)
2476 {
2477         MainWindow *mainwin = (MainWindow *)data;
2478
2479         if (!event) return;
2480         if (event->button != 3) return;
2481
2482         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2483         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2484                             widget);
2485
2486         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2487                        menu_button_position, widget,
2488                        event->button, event->time);
2489 }
2490 #endif
2491
2492 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2493                                     gpointer data)
2494 {
2495         MainWindow *mainwin = (MainWindow *)data;
2496
2497         if (!event) return;
2498
2499         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2500         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2501                             widget);
2502
2503         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2504                        menu_button_position, widget,
2505                        event->button, event->time);
2506 }
2507
2508 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
2509 {
2510         MainWindow *mainwin = (MainWindow *)data;
2511         GtkWidget *button;
2512
2513         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
2514         if (!button) return;
2515         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
2516         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
2517         manage_window_focus_in(mainwin->window, NULL, NULL);
2518 }
2519
2520 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2521                                  gpointer data)
2522 {
2523         MainWindow *mainwin = (MainWindow *)data;
2524
2525         if (mainwin->lock_count == 0)
2526                 app_exit_cb(data, 0, widget);
2527
2528         return TRUE;
2529 }
2530
2531 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2532                                    gpointer data)
2533 {
2534         MainWindow *mainwin = (MainWindow *)data;
2535         GtkWidget *menuitem;
2536
2537         menuitem = gtk_item_factory_get_item
2538                 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
2539         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2540
2541         return TRUE;
2542 }
2543
2544 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2545                                     gpointer data)
2546 {
2547         MainWindow *mainwin = (MainWindow *)data;
2548         GtkWidget *menuitem;
2549
2550         menuitem = gtk_item_factory_get_item
2551                 (mainwin->menu_factory, "/View/Show or hide/Message view");
2552         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2553
2554         return TRUE;
2555 }
2556
2557 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2558                            GtkWidget *widget)
2559 {
2560         main_window_add_mailbox(mainwin);
2561 }
2562
2563 static void add_mbox_cb(MainWindow *mainwin, guint action,
2564                         GtkWidget *widget)
2565 {
2566         main_window_add_mbox(mainwin);
2567 }
2568
2569 static void update_folderview_cb(MainWindow *mainwin, guint action,
2570                                  GtkWidget *widget)
2571 {
2572         summary_show(mainwin->summaryview, NULL, FALSE);
2573         folderview_rescan_all();
2574 }
2575
2576 static void new_folder_cb(MainWindow *mainwin, guint action,
2577                           GtkWidget *widget)
2578 {
2579         folderview_new_folder(mainwin->folderview);
2580 }
2581
2582 static void rename_folder_cb(MainWindow *mainwin, guint action,
2583                              GtkWidget *widget)
2584 {
2585         folderview_rename_folder(mainwin->folderview);
2586 }
2587
2588 static void delete_folder_cb(MainWindow *mainwin, guint action,
2589                              GtkWidget *widget)
2590 {
2591         folderview_delete_folder(mainwin->folderview);
2592 }
2593
2594 static void import_mbox_cb(MainWindow *mainwin, guint action,
2595                            GtkWidget *widget)
2596 {
2597         import_mbox(mainwin->summaryview->folder_item);
2598 }
2599
2600 static void export_mbox_cb(MainWindow *mainwin, guint action,
2601                            GtkWidget *widget)
2602 {
2603         export_mbox(mainwin->summaryview->folder_item);
2604 }
2605
2606 static void empty_trash_cb(MainWindow *mainwin, guint action,
2607                            GtkWidget *widget)
2608 {
2609         main_window_empty_trash(mainwin, TRUE);
2610 }
2611
2612 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2613 {
2614         summary_save_as(mainwin->summaryview);
2615 }
2616
2617 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2618 {
2619         summary_print(mainwin->summaryview);
2620 }
2621
2622 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2623 {
2624         if (prefs_common.confirm_on_exit) {
2625                 if (alertpanel(_("Exit"), _("Exit this program?"),
2626                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2627                         return;
2628                 manage_window_focus_in(mainwin->window, NULL, NULL);
2629         }
2630
2631         app_will_exit(widget, mainwin);
2632 }
2633
2634 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2635 {
2636         if (action == 1)
2637                 summary_search(mainwin->summaryview);
2638         else
2639                 message_search(mainwin->messageview);
2640 }
2641
2642 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2643                              GtkWidget *widget)
2644 {
2645         gboolean active;
2646
2647         active = GTK_CHECK_MENU_ITEM(widget)->active;
2648
2649         switch (mainwin->type) {
2650         case SEPARATE_NONE:
2651         case SEPARATE_MESSAGE:
2652 #if 0
2653                 if (active)
2654                         gtk_widget_show(GTK_WIDGET_PTR(mainwin->folderview));
2655                 else
2656                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->folderview));
2657 #endif
2658                 break;
2659         case SEPARATE_FOLDER:
2660                 debug_print("separate folder\n");
2661                 if (active)
2662                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2663                 else
2664                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2665                 break;
2666         case SEPARATE_BOTH:
2667                 if (active)
2668                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2669                 else
2670                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2671                 break;
2672         }
2673 }
2674
2675 static void toggle_message_cb(MainWindow *mainwin, guint action,
2676                               GtkWidget *widget)
2677 {
2678         gboolean active;
2679
2680         active = GTK_CHECK_MENU_ITEM(widget)->active;
2681
2682         if (active != messageview_is_visible(mainwin->messageview))
2683                 summary_toggle_view(mainwin->summaryview);
2684 }
2685
2686 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2687                               GtkWidget *widget)
2688 {
2689         switch ((ToolbarStyle)action) {
2690         case TOOLBAR_NONE:
2691                 gtk_widget_hide(mainwin->handlebox);
2692         case TOOLBAR_ICON:
2693                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2694                                       GTK_TOOLBAR_ICONS);
2695                 break;
2696         case TOOLBAR_TEXT:
2697                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2698                                       GTK_TOOLBAR_TEXT);
2699                 break;
2700         case TOOLBAR_BOTH:
2701                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2702                                       GTK_TOOLBAR_BOTH);
2703                 break;
2704         }
2705
2706         if (action != TOOLBAR_NONE) {
2707                 gtk_widget_show(mainwin->handlebox);
2708                 gtk_widget_queue_resize(mainwin->handlebox);
2709         }
2710
2711         mainwin->toolbar_style = (ToolbarStyle)action;
2712         prefs_common.toolbar_style = (ToolbarStyle)action;
2713 }
2714
2715 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2716                                 GtkWidget *widget)
2717 {
2718         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2719                 gtk_widget_show(mainwin->hbox_stat);
2720                 prefs_common.show_statusbar = TRUE;
2721         } else {
2722                 gtk_widget_hide(mainwin->hbox_stat);
2723                 prefs_common.show_statusbar = FALSE;
2724         }
2725 }
2726
2727 static void separate_widget_cb(MainWindow *mainwin, guint action,
2728                                GtkWidget *widget)
2729 {
2730         SeparateType type;
2731
2732         if (GTK_CHECK_MENU_ITEM(widget)->active)
2733                 type = mainwin->type | action;
2734         else
2735                 type = mainwin->type & ~action;
2736
2737         main_window_separation_change(mainwin, type);
2738
2739         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2740         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2741 }
2742
2743 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2744 {
2745         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2746                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
2747         } else {
2748                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);           
2749         }
2750 }
2751
2752 static void online_switch_clicked (GtkButton *btn, gpointer data) 
2753 {
2754         MainWindow *mainwin;
2755         GtkItemFactory *ifactory;
2756         GtkCheckMenuItem *menuitem;
2757
2758         mainwin = (MainWindow *) data;
2759         
2760         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2761         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
2762         
2763         g_return_if_fail(mainwin != NULL);
2764         g_return_if_fail(menuitem != NULL);
2765         
2766         if (btn == GTK_BUTTON(mainwin->online_switch)) {
2767                 /* go offline */
2768                 gtk_widget_hide (mainwin->online_switch);
2769                 gtk_widget_show (mainwin->offline_switch);
2770                 menuitem->active = TRUE;
2771                 prefs_common.work_offline = TRUE;
2772                 inc_autocheck_timer_remove();           
2773         } else {
2774                 /*go online */
2775                 gtk_widget_hide (mainwin->offline_switch);
2776                 gtk_widget_show (mainwin->online_switch);
2777                 menuitem->active = FALSE;
2778                 prefs_common.work_offline = FALSE;
2779                 inc_autocheck_timer_set();
2780         }
2781 }
2782
2783 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2784                                 GtkWidget *widget)
2785 {
2786         addressbook_open(NULL);
2787 }
2788
2789 static void log_window_show_cb(MainWindow *mainwin, guint action,
2790                                GtkWidget *widget)
2791 {
2792         log_window_show(mainwin->logwin);
2793 }
2794
2795 static void sel_download_cb(MainWindow *mainwin, guint action,
2796                                GtkWidget *widget)
2797 {
2798         selective_download(mainwin);
2799 }
2800
2801 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2802 {
2803         inc_mail(mainwin, prefs_common.newmail_notify_manu);
2804 }
2805
2806 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
2807                                     GtkWidget *widget)
2808 {
2809         inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
2810 }
2811
2812 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2813 {
2814         inc_cancel_all();
2815 }
2816
2817 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2818 {
2819         GList *list;
2820
2821         if (prefs_common.work_offline)
2822                 if (alertpanel(_("Offline warning"), 
2823                                _("You're working offline. Override?"),
2824                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
2825                 return;
2826
2827         for (list = folder_get_list(); list != NULL; list = list->next) {
2828                 Folder *folder = list->data;
2829
2830                 if (folder->queue) {
2831                         if (procmsg_send_queue
2832                                 (folder->queue, prefs_common.savemsg) < 0)
2833                                 alertpanel_error(_("Some errors occurred while sending queued messages."));
2834                         statusbar_pop_all();
2835                         folder_item_scan(folder->queue);
2836                         folderview_update_item(folder->queue, TRUE);
2837                 }
2838         }
2839 }
2840
2841 static void compose_mail_cb(MainWindow *mainwin, guint action,
2842                             GtkWidget *widget)
2843 {
2844         PrefsAccount * ac;
2845         GList * list;
2846         GList * cur;
2847
2848         if (mainwin->summaryview->folder_item) {
2849                 ac = mainwin->summaryview->folder_item->folder->account;
2850                 if (ac && ac->protocol != A_NNTP) {
2851                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2852                         return;
2853                 }
2854         }
2855
2856         if(cur_account && (cur_account->protocol != A_NNTP)) {
2857                 compose_new_with_folderitem(cur_account, mainwin->summaryview->folder_item);
2858                 return;
2859         }
2860
2861         list = account_get_list();
2862         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2863                 ac = (PrefsAccount *) cur->data;
2864                 if (ac->protocol != A_NNTP) {
2865                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2866                         return;
2867                 }
2868         }
2869 }
2870
2871 static void compose_news_cb(MainWindow *mainwin, guint action,
2872                             GtkWidget *widget)
2873 {
2874         PrefsAccount * ac = NULL;
2875         GList * list;
2876         GList * cur;
2877
2878         if (mainwin->summaryview->folder_item) {
2879                 ac = mainwin->summaryview->folder_item->folder->account;
2880                 if (ac && ac->protocol == A_NNTP) {
2881                         compose_new_with_recipient
2882                                 (ac, mainwin->summaryview->folder_item->path);
2883                         return;
2884                 }
2885         }
2886
2887         list = account_get_list();
2888         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2889                 ac = (PrefsAccount *) cur->data;
2890                 if (ac->protocol == A_NNTP) {
2891                         compose_new(ac);
2892                         return;
2893                 }
2894         }
2895 }
2896
2897 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2898 {
2899         summary_reply(mainwin->summaryview, (ComposeMode)action);
2900 }
2901
2902 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2903 {
2904         summary_move_to(mainwin->summaryview);
2905 }
2906
2907 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2908 {
2909         summary_copy_to(mainwin->summaryview);
2910 }
2911
2912 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2913 {
2914         summary_delete(mainwin->summaryview);
2915 }
2916
2917 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2918 {
2919         summary_open_msg(mainwin->summaryview);
2920 }
2921
2922 static void view_source_cb(MainWindow *mainwin, guint action,
2923                            GtkWidget *widget)
2924 {
2925         summary_view_source(mainwin->summaryview);
2926 }
2927
2928 static void show_all_header_cb(MainWindow *mainwin, guint action,
2929                                GtkWidget *widget)
2930 {
2931         if (mainwin->menu_lock_count) return;
2932         summary_display_msg_selected(mainwin->summaryview,
2933                                      GTK_CHECK_MENU_ITEM(widget)->active);
2934 }
2935
2936 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2937 {
2938         summary_reedit(mainwin->summaryview);
2939 }
2940
2941 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2942 {
2943         summary_mark(mainwin->summaryview);
2944 }
2945
2946 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2947 {
2948         summary_unmark(mainwin->summaryview);
2949 }
2950
2951 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2952                               GtkWidget *widget)
2953 {
2954         summary_mark_as_unread(mainwin->summaryview);
2955 }
2956
2957 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2958                             GtkWidget *widget)
2959 {
2960         summary_mark_as_read(mainwin->summaryview);
2961 }
2962
2963 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2964                              GtkWidget *widget)
2965 {
2966         summary_mark_all_read(mainwin->summaryview);
2967 }
2968
2969 static void add_address_cb(MainWindow *mainwin, guint action,
2970                            GtkWidget *widget)
2971 {
2972         summary_add_address(mainwin->summaryview);
2973 }
2974
2975 static void set_charset_cb(MainWindow *mainwin, guint action,
2976                            GtkWidget *widget)
2977 {
2978         const gchar *str;
2979
2980         str = conv_get_charset_str((CharSet)action);
2981         g_free(prefs_common.force_charset);
2982         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2983
2984         summary_redisplay_msg(mainwin->summaryview);
2985
2986         debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
2987 }
2988
2989 static void hide_read_messages (MainWindow *mainwin, guint action,
2990                                 GtkWidget *widget)
2991 {
2992         if (!mainwin->summaryview->folder_item
2993             || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
2994                 return;
2995         summary_toggle_show_read_messages(mainwin->summaryview);
2996 }
2997
2998 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2999 {
3000         if (mainwin->menu_lock_count) return;
3001         if (!mainwin->summaryview->folder_item) return;
3002
3003         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3004                 summary_thread_build(mainwin->summaryview);
3005                 mainwin->summaryview->folder_item->threaded = TRUE;
3006         } else {
3007                 summary_unthread(mainwin->summaryview);
3008                 mainwin->summaryview->folder_item->threaded = FALSE;
3009         }
3010 }
3011
3012 static void expand_threads_cb(MainWindow *mainwin, guint action,
3013                               GtkWidget *widget)
3014 {
3015         summary_expand_threads(mainwin->summaryview);
3016 }
3017
3018 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3019                                 GtkWidget *widget)
3020 {
3021         summary_collapse_threads(mainwin->summaryview);
3022 }
3023
3024 static void set_display_item_cb(MainWindow *mainwin, guint action,
3025                                 GtkWidget *widget)
3026 {
3027         prefs_summary_column_open();
3028 }
3029
3030 static void sort_summary_cb(MainWindow *mainwin, guint action,
3031                             GtkWidget *widget)
3032 {
3033         FolderItem *item = mainwin->summaryview->folder_item;
3034         GtkWidget *menuitem;
3035
3036         if (mainwin->menu_lock_count) return;
3037         if (item) {
3038                 menuitem = gtk_item_factory_get_item
3039                         (mainwin->menu_factory, "/View/Sort/Ascending");
3040                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3041                              GTK_CHECK_MENU_ITEM(menuitem)->active
3042                              ? SORT_ASCENDING : SORT_DESCENDING);
3043         }
3044 }
3045
3046 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3047                                  GtkWidget *widget)
3048 {
3049         FolderItem *item = mainwin->summaryview->folder_item;
3050
3051         if (mainwin->menu_lock_count) return;
3052         if (item)
3053                 summary_sort(mainwin->summaryview,
3054                              item->sort_key, (FolderSortType)action);
3055 }
3056
3057 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3058                                   GtkWidget *widget)
3059 {
3060         summary_attract_by_subject(mainwin->summaryview);
3061 }
3062
3063 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3064                                  GtkWidget *widget)
3065 {
3066         summary_delete_duplicated(mainwin->summaryview);
3067 }
3068
3069 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3070 {
3071         summary_filter(mainwin->summaryview);
3072 }
3073
3074 static void execute_summary_cb(MainWindow *mainwin, guint action,
3075                                GtkWidget *widget)
3076 {
3077         summary_execute(mainwin->summaryview);
3078 }
3079
3080 static void update_summary_cb(MainWindow *mainwin, guint action,
3081                               GtkWidget *widget)
3082 {
3083         FolderItem *fitem;
3084         FolderView *folderview = mainwin->folderview;
3085
3086         if (!mainwin->summaryview->folder_item) return;
3087         if (!folderview->opened) return;
3088
3089         folder_update_op_count();
3090
3091         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3092                                             folderview->opened);
3093         if (!fitem) return;
3094
3095         folder_item_scan(fitem);
3096         summary_show(mainwin->summaryview, fitem, TRUE);
3097 }
3098
3099 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3100 {
3101         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3102 }
3103
3104 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3105 {
3106         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3107 }
3108
3109 static void prev_unread_cb(MainWindow *mainwin, guint action,
3110                            GtkWidget *widget)
3111 {
3112         summary_select_prev_unread(mainwin->summaryview);
3113 }
3114
3115 static void next_unread_cb(MainWindow *mainwin, guint action,
3116                            GtkWidget *widget)
3117 {
3118         summary_select_next_unread(mainwin->summaryview);
3119 }
3120
3121 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3122 {
3123         summary_select_prev_new(mainwin->summaryview);
3124 }
3125
3126 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3127 {
3128         summary_select_next_new(mainwin->summaryview);
3129 }
3130
3131 static void prev_marked_cb(MainWindow *mainwin, guint action,
3132                            GtkWidget *widget)
3133 {
3134         summary_select_prev_marked(mainwin->summaryview);
3135 }
3136
3137 static void next_marked_cb(MainWindow *mainwin, guint action,
3138                            GtkWidget *widget)
3139 {
3140         summary_select_next_marked(mainwin->summaryview);
3141 }
3142
3143 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3144                             GtkWidget *widget)
3145 {
3146         summary_select_prev_labeled(mainwin->summaryview);
3147 }
3148
3149 static void next_labeled_cb(MainWindow *mainwin, guint action,
3150                             GtkWidget *widget)
3151 {
3152         summary_select_next_labeled(mainwin->summaryview);
3153 }
3154
3155 static void goto_folder_cb(MainWindow *mainwin, guint action,
3156                            GtkWidget *widget)
3157 {
3158         FolderItem *to_folder;
3159
3160         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
3161
3162         if (to_folder)
3163                 folderview_select(mainwin->folderview, to_folder);
3164 }
3165
3166 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3167 {
3168         messageview_copy_clipboard(mainwin->messageview);
3169 }
3170
3171 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3172 {
3173         MessageView *msgview = mainwin->messageview;
3174
3175         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
3176                 summary_select_all(mainwin->summaryview);
3177         else if (messageview_is_visible(msgview) &&
3178                  (GTK_WIDGET_HAS_FOCUS(msgview->textview->text) ||
3179                   GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3180                 messageview_select_all(mainwin->messageview);
3181 }
3182
3183 static void selthread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3184 {
3185         if (messageview_is_visible(mainwin->summaryview->messageview))
3186                 summary_select_thread(mainwin->summaryview);
3187 }
3188
3189 static void create_filter_cb(MainWindow *mainwin, guint action,
3190                              GtkWidget *widget)
3191 {
3192         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action);
3193 }
3194
3195 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
3196                                  GtkWidget *widget)
3197 {
3198         prefs_common_open();
3199 }
3200
3201 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
3202                                  GtkWidget *widget)
3203 {
3204         prefs_filter_open(NULL, NULL);
3205 }
3206
3207 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
3208                                   GtkWidget *widget)
3209 {
3210         prefs_scoring_open(NULL);
3211 }
3212
3213 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
3214                                     GtkWidget *widget)
3215 {
3216         prefs_filtering_open(NULL, NULL, NULL);
3217 }
3218
3219 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
3220                                    GtkWidget *widget)
3221 {
3222         prefs_template_open();
3223 }
3224
3225 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
3226                                   GtkWidget *widget)
3227 {
3228         prefs_actions_open(mainwin);
3229 }
3230
3231 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
3232                                   GtkWidget *widget)
3233 {
3234         if (!cur_account) {
3235                 new_account_cb(mainwin, 0, widget);
3236         } else {
3237                 gboolean prev_default = cur_account->is_default;
3238
3239                 prefs_account_open(cur_account);
3240                 if (!prev_default && cur_account->is_default)
3241                         account_set_as_default(cur_account);
3242                 account_save_config_all();
3243                 account_set_menu();
3244                 main_window_reflect_prefs_all();
3245         }
3246 }
3247
3248 static void new_account_cb(MainWindow *mainwin, guint action,
3249                            GtkWidget *widget)
3250 {
3251         account_edit_open();
3252         if (!compose_get_compose_list()) account_add();
3253 }
3254
3255 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
3256 {
3257         cur_account = (PrefsAccount *)data;
3258         main_window_reflect_prefs_all();
3259 }
3260
3261 static void manual_open_cb(MainWindow *mainwin, guint action,
3262                            GtkWidget *widget)
3263 {
3264         manual_open((ManualLang)action);
3265 }
3266
3267 static void faq_open_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3268 {
3269         faq_open((ManualLang)action);
3270 }
3271
3272 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
3273 {
3274         MainWindow *mainwin = (MainWindow *)data;
3275         gchar *str;
3276