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