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