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