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