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