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