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