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