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