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