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