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