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