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