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