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