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