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