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