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