2007-05-03 [colin] 2.9.1cvs42
[claws.git] / src / mainwindow.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include "defs.h"
21
22 #include <glib.h>
23 #include <glib/gi18n.h>
24 #include <gdk/gdkkeysyms.h>
25 #include <gtk/gtkmain.h>
26 #include <gtk/gtkwindow.h>
27 #include <gtk/gtkwidget.h>
28 #include <gtk/gtksignal.h>
29 #include <gtk/gtkvbox.h>
30 #include <gtk/gtkcontainer.h>
31 #include <gtk/gtkstatusbar.h>
32 #include <gtk/gtkprogressbar.h>
33 #include <gtk/gtkhpaned.h>
34 #include <gtk/gtkvpaned.h>
35 #include <gtk/gtkcheckmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkeditable.h>
38 #include <gtk/gtkmenu.h>
39 #include <gtk/gtkmenuitem.h>
40 #include <gtk/gtkhandlebox.h>
41 #include <gtk/gtktoolbar.h>
42 #include <gtk/gtkbutton.h>
43 #include <gtk/gtktooltips.h>
44 #include <string.h>
45
46 #include "main.h"
47 #include "mainwindow.h"
48 #include "folderview.h"
49 #include "foldersel.h"
50 #include "summaryview.h"
51 #include "summary_search.h"
52 #include "messageview.h"
53 #include "message_search.h"
54 #include "headerview.h"
55 #include "menu.h"
56 #include "stock_pixmap.h"
57 #include "folder.h"
58 #include "inc.h"
59 #include "log.h"
60 #include "compose.h"
61 #include "procmsg.h"
62 #include "import.h"
63 #include "export.h"
64 #include "prefs_common.h"
65 #include "prefs_actions.h"
66 #include "prefs_filtering.h"
67 #include "prefs_account.h"
68 #include "prefs_summary_column.h"
69 #include "prefs_folder_column.h"
70 #include "prefs_template.h"
71 #include "action.h"
72 #include "account.h"
73 #include "addressbook.h"
74 #include "logwindow.h"
75 #include "manage_window.h"
76 #include "alertpanel.h"
77 #include "statusbar.h"
78 #include "inputdialog.h"
79 #include "utils.h"
80 #include "gtkutils.h"
81 #include "codeconv.h"
82 #include "about.h"
83 #include "manual.h"
84 #include "version.h"
85 #include "ssl_manager.h"
86 #include "sslcertwindow.h"
87 #include "prefs_gtk.h"
88 #include "pluginwindow.h"
89 #include "hooks.h"
90 #include "progressindicator.h"
91 #include "localfolder.h"
92 #include "filtering.h"
93 #include "folderutils.h"
94 #include "foldersort.h"
95 #include "icon_legend.h"
96 #include "colorlabel.h"
97 #include "textview.h"
98 #include "imap.h"
99 #include "socket.h"
100
101 #define AC_LABEL_WIDTH  240
102
103 /* list of all instantiated MainWindow */
104 static GList *mainwin_list = NULL;
105
106 static GdkCursor *watch_cursor = NULL;
107 static GdkCursor *hand_cursor = NULL;
108
109 static gint iconified_count = 0;
110
111 static void main_window_menu_callback_block     (MainWindow     *mainwin);
112 static void main_window_menu_callback_unblock   (MainWindow     *mainwin);
113
114 static void main_window_show_cur_account        (MainWindow     *mainwin);
115
116 static void main_window_separation_change       (MainWindow     *mainwin,
117                                                  LayoutType      layout_mode);
118
119 static void main_window_set_widgets             (MainWindow     *mainwin,
120                                                  LayoutType      layout_mode);
121
122 static void toolbar_child_attached              (GtkWidget      *widget,
123                                                  GtkWidget      *child,
124                                                  gpointer        data);
125 static void toolbar_child_detached              (GtkWidget      *widget,
126                                                  GtkWidget      *child,
127                                                  gpointer        data);
128
129 static gboolean ac_label_button_pressed         (GtkWidget      *widget,
130                                                  GdkEventButton *event,
131                                                  gpointer        data);
132
133 static gint main_window_close_cb                (GtkWidget      *widget,
134                                                  GdkEventAny    *event,
135                                                  gpointer        data);
136
137 static void main_window_size_allocate_cb        (GtkWidget      *widget,
138                                                  GtkAllocation  *allocation,
139                                                  gpointer        data);
140 static void folder_window_size_allocate_cb      (GtkWidget      *widget,
141                                                  GtkAllocation  *allocation,
142                                                  gpointer        data);
143 static void message_window_size_allocate_cb     (GtkWidget      *widget,
144                                                  GtkAllocation  *allocation,
145                                                  gpointer        data);
146
147 static void update_folderview_cb (MainWindow    *mainwin,
148                                   guint          action,
149                                   GtkWidget     *widget);
150 static void add_mailbox_cb       (MainWindow    *mainwin,
151                                   guint          action,
152                                   GtkWidget     *widget);
153 static void foldersort_cb        (MainWindow    *mainwin,
154                                   guint          action,
155                                   GtkWidget     *widget);
156 static void import_mbox_cb       (MainWindow    *mainwin,
157                                   guint          action,
158                                   GtkWidget     *widget);
159 static void export_mbox_cb       (MainWindow    *mainwin,
160                                   guint          action,
161                                   GtkWidget     *widget);
162 static void export_list_mbox_cb  (MainWindow    *mainwin, 
163                                   guint          action,
164                                   GtkWidget     *widget);
165 static void empty_trash_cb       (MainWindow    *mainwin,
166                                   guint          action,
167                                   GtkWidget     *widget);
168
169 static void save_as_cb           (MainWindow    *mainwin,
170                                   guint          action,
171                                   GtkWidget     *widget);
172 static void print_cb             (MainWindow    *mainwin,
173                                   guint          action,
174                                   GtkWidget     *widget);
175 static void app_exit_cb          (MainWindow    *mainwin,
176                                   guint          action,
177                                   GtkWidget     *widget);
178
179 static void search_cb            (MainWindow    *mainwin,
180                                   guint          action,
181                                   GtkWidget     *widget);
182
183 static void toggle_message_cb    (MainWindow    *mainwin,
184                                   guint          action,
185                                   GtkWidget     *widget);
186 static void toggle_toolbar_cb    (MainWindow    *mainwin,
187                                   guint          action,
188                                   GtkWidget     *widget);
189 static void toggle_statusbar_cb  (MainWindow    *mainwin,
190                                   guint          action,
191                                   GtkWidget     *widget);
192 static void set_layout_cb        (MainWindow    *mainwin,
193                                   guint          action,
194                                   GtkWidget     *widget);
195
196 static void addressbook_open_cb (MainWindow     *mainwin,
197                                  guint           action,
198                                  GtkWidget      *widget);
199 static void log_window_show_cb  (MainWindow     *mainwin,
200                                  guint           action,
201                                  GtkWidget      *widget);
202 static void filtering_debug_window_show_cb      (MainWindow     *mainwin,
203                                  guint           action,
204                                  GtkWidget      *widget);
205
206 static void inc_cancel_cb               (MainWindow     *mainwin,
207                                          guint           action,
208                                          GtkWidget      *widget);
209
210 static void open_msg_cb                 (MainWindow     *mainwin,
211                                          guint           action,
212                                          GtkWidget      *widget);
213
214 static void view_source_cb              (MainWindow     *mainwin,
215                                          guint           action,
216                                          GtkWidget      *widget);
217
218 static void show_all_header_cb          (MainWindow     *mainwin,
219                                          guint           action,
220                                          GtkWidget      *widget);
221
222 static void hide_quotes_cb(MainWindow   *mainwin,
223                                          guint           action,
224                                          GtkWidget      *widget);
225
226 static void move_to_cb                  (MainWindow     *mainwin,
227                                          guint           action,
228                                          GtkWidget      *widget);
229 static void copy_to_cb                  (MainWindow     *mainwin,
230                                          guint           action,
231                                          GtkWidget      *widget);
232 static void delete_cb                   (MainWindow     *mainwin,
233                                          guint           action,
234                                          GtkWidget      *widget);
235 static void delete_trash_cb                     (MainWindow     *mainwin,
236                                          guint           action,
237                                          GtkWidget      *widget);
238
239 static void cancel_cb                   (MainWindow     *mainwin,
240                                          guint           action,
241                                          GtkWidget      *widget);
242
243 static void mark_cb                     (MainWindow     *mainwin,
244                                          guint           action,
245                                          GtkWidget      *widget);
246 static void unmark_cb                   (MainWindow     *mainwin,
247                                          guint           action,
248                                          GtkWidget      *widget);
249
250 static void mark_as_unread_cb           (MainWindow     *mainwin,
251                                          guint           action,
252                                          GtkWidget      *widget);
253 static void mark_as_read_cb             (MainWindow     *mainwin,
254                                          guint           action,
255                                          GtkWidget      *widget);
256 static void mark_all_read_cb            (MainWindow     *mainwin,
257                                          guint           action,
258                                          GtkWidget      *widget);
259 static void mark_as_spam_cb             (MainWindow     *mainwin, 
260                                          guint           action,
261                                          GtkWidget      *widget);
262
263 static void ignore_thread_cb            (MainWindow     *mainwin, 
264                                          guint           action,
265                                          GtkWidget      *widget);
266 static void unignore_thread_cb          (MainWindow     *mainwin, 
267                                          guint           action,
268                                          GtkWidget      *widget);
269 static void lock_msgs_cb                (MainWindow     *mainwin, 
270                                          guint           action,
271                                          GtkWidget      *widget);
272 static void unlock_msgs_cb              (MainWindow     *mainwin, 
273                                          guint           action,
274                                          GtkWidget      *widget);
275
276 static void reedit_cb                   (MainWindow     *mainwin,
277                                          guint           action,
278                                          GtkWidget      *widget);
279
280 static void add_address_cb              (MainWindow     *mainwin,
281                                          guint           action,
282                                          GtkWidget      *widget);
283
284 static void set_charset_cb              (MainWindow     *mainwin,
285                                          guint           action,
286                                          GtkWidget      *widget);
287
288 static void set_decode_cb               (MainWindow     *mainwin,
289                                          guint           action,
290                                          GtkWidget      *widget);
291
292 static void hide_read_messages   (MainWindow    *mainwin,
293                                   guint          action,
294                                   GtkWidget     *widget);
295
296 static void thread_cb            (MainWindow    *mainwin,
297                                   guint          action,
298                                   GtkWidget     *widget);
299 static void expand_threads_cb    (MainWindow    *mainwin,
300                                   guint          action,
301                                   GtkWidget     *widget);
302 static void collapse_threads_cb  (MainWindow    *mainwin,
303                                   guint          action,
304                                   GtkWidget     *widget);
305
306 static void set_summary_display_item_cb  (MainWindow    *mainwin,
307                                   guint          action,
308                                   GtkWidget     *widget);
309 static void set_folder_display_item_cb   (MainWindow    *mainwin,
310                                   guint          action,
311                                   GtkWidget     *widget);
312 static void sort_summary_cb      (MainWindow    *mainwin,
313                                   guint          action,
314                                   GtkWidget     *widget);
315 static void sort_summary_type_cb (MainWindow    *mainwin,
316                                   guint          action,
317                                   GtkWidget     *widget);
318 static void attract_by_subject_cb(MainWindow    *mainwin,
319                                   guint          action,
320                                   GtkWidget     *widget);
321
322 static void delete_duplicated_cb (MainWindow    *mainwin,
323                                   guint          action,
324                                   GtkWidget     *widget);
325 static void delete_duplicated_all_cb (MainWindow        *mainwin,
326                                   guint          action,
327                                   GtkWidget     *widget);
328 static void filter_cb            (MainWindow    *mainwin,
329                                   guint          action,
330                                   GtkWidget     *widget);
331 static void execute_summary_cb   (MainWindow    *mainwin,
332                                   guint          action,
333                                   GtkWidget     *widget);
334 static void update_summary_cb    (MainWindow    *mainwin,
335                                   guint          action,
336                                   GtkWidget     *widget);
337
338 static void prev_cb              (MainWindow    *mainwin,
339                                   guint          action,
340                                   GtkWidget     *widget);
341 static void next_cb              (MainWindow    *mainwin,
342                                   guint          action,
343                                   GtkWidget     *widget);
344 static void next_unread_cb       (MainWindow    *mainwin,
345                                   guint          action,
346                                   GtkWidget     *widget);
347 static void prev_unread_cb       (MainWindow    *mainwin,
348                                   guint          action,
349                                   GtkWidget     *widget);
350
351 static void prev_new_cb          (MainWindow    *mainwin,
352                                   guint          action,
353                                   GtkWidget     *widget);
354 static void next_new_cb          (MainWindow    *mainwin,
355                                   guint          action,
356                                   GtkWidget     *widget);
357 static void prev_marked_cb       (MainWindow    *mainwin,
358                                   guint          action,
359                                   GtkWidget     *widget);
360 static void next_marked_cb       (MainWindow    *mainwin,
361                                   guint          action,
362                                   GtkWidget     *widget);
363 static void prev_labeled_cb      (MainWindow    *mainwin,
364                                   guint          action,
365                                   GtkWidget     *widget);
366 static void next_labeled_cb      (MainWindow    *mainwin,
367                                   guint          action,
368                                   GtkWidget     *widget);
369 static void last_read_cb         (MainWindow    *mainwin,
370                                   guint          action,
371                                   GtkWidget     *widget);
372 static void parent_cb            (MainWindow    *mainwin,
373                                   guint          action,
374                                   GtkWidget     *widget);
375
376 static void goto_folder_cb       (MainWindow    *mainwin,
377                                   guint          action,
378                                   GtkWidget     *widget);
379 static void goto_unread_folder_cb(MainWindow    *mainwin,
380                                   guint          action,
381                                   GtkWidget     *widget);
382
383 static void copy_cb              (MainWindow    *mainwin,
384                                   guint          action,
385                                   GtkWidget     *widget);
386 static void allsel_cb            (MainWindow    *mainwin,
387                                   guint          action,
388                                   GtkWidget     *widget);
389 static void select_thread_cb     (MainWindow    *mainwin,
390                                   guint          action,
391                                   GtkWidget     *widget);
392 static void delete_thread_cb     (MainWindow    *mainwin,
393                                   guint          action,
394                                   GtkWidget     *widget);
395
396 static void create_filter_cb     (MainWindow    *mainwin,
397                                   guint          action,
398                                   GtkWidget     *widget);
399 static void create_processing_cb (MainWindow    *mainwin,
400                                   guint          action,
401                                   GtkWidget     *widget);
402 static void open_urls_cb         (MainWindow    *mainwin,
403                                   guint          action,
404                                   GtkWidget     *widget);
405
406 static void prefs_template_open_cb      (MainWindow     *mainwin,
407                                          guint           action,
408                                          GtkWidget      *widget);
409 static void prefs_actions_open_cb       (MainWindow     *mainwin,
410                                          guint           action,
411                                          GtkWidget      *widget);
412 static void prefs_account_open_cb       (MainWindow     *mainwin,
413                                          guint           action,
414                                          GtkWidget      *widget);
415
416 static void prefs_pre_processing_open_cb  (MainWindow   *mainwin,
417                                            guint         action,
418                                            GtkWidget    *widget);
419
420 static void prefs_post_processing_open_cb (MainWindow   *mainwin,
421                                            guint         action,
422                                            GtkWidget    *widget);
423
424 static void prefs_filtering_open_cb     (MainWindow     *mainwin,
425                                          guint           action,
426                                          GtkWidget      *widget);
427 #ifdef USE_OPENSSL
428 static void ssl_manager_open_cb         (MainWindow     *mainwin,
429                                          guint           action,
430                                          GtkWidget      *widget);
431 #endif
432 static void new_account_cb       (MainWindow    *mainwin,
433                                   guint          action,
434                                   GtkWidget     *widget);
435
436 static void account_selector_menu_cb     (GtkMenuItem   *menuitem,
437                                           gpointer       data);
438 static void account_receive_menu_cb      (GtkMenuItem   *menuitem,
439                                           gpointer       data);
440 static void account_compose_menu_cb      (GtkMenuItem   *menuitem,
441                                           gpointer       data);
442
443 static void prefs_open_cb       (GtkMenuItem    *menuitem,
444                                  gpointer        data);
445 static void plugins_open_cb     (GtkMenuItem    *menuitem,
446                                  gpointer        data);
447
448 static void online_switch_clicked(GtkButton     *btn, 
449                                   gpointer data);
450
451 static void manual_open_cb       (MainWindow    *mainwin,
452                                   guint          action,
453                                   GtkWidget     *widget);
454
455 static void legend_open_cb       (GtkMenuItem   *menuitem,
456                                   gpointer       data);
457
458 static void scan_tree_func       (Folder        *folder,
459                                   FolderItem    *item,
460                                   gpointer       data);
461                                   
462 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
463
464 static void addr_harvest_cb      ( MainWindow  *mainwin,
465                                    guint       action,
466                                    GtkWidget   *widget );
467
468 static void addr_harvest_msg_cb  ( MainWindow  *mainwin,
469                                    guint       action,
470                                    GtkWidget   *widget );
471 static void sync_cb              ( MainWindow *mainwin, 
472                                    guint action, 
473                                    GtkWidget *widget );
474
475 static gboolean mainwindow_focus_in_event       (GtkWidget      *widget, 
476                                                  GdkEventFocus  *focus,
477                                                  gpointer        data);
478 static gboolean mainwindow_visibility_event_cb  (GtkWidget      *widget, 
479                                                  GdkEventVisibility     *state,
480                                                  gpointer        data);
481 static gboolean mainwindow_state_event_cb       (GtkWidget      *widget, 
482                                                  GdkEventWindowState    *state,
483                                                  gpointer        data);
484 static void main_window_reply_cb                        (MainWindow     *mainwin, 
485                                                  guint           action,
486                                                  GtkWidget      *widget);
487 static gboolean mainwindow_progressindicator_hook       (gpointer        source,
488                                                  gpointer        userdata);
489
490 static gint mailing_list_create_submenu(GtkItemFactory *ifactory,
491                                        MsgInfo *msginfo);
492
493 static gint mailing_list_populate_submenu(GtkWidget *menu, const gchar * list_header);
494         
495 static void get_url_part(const gchar **buf, gchar *url_decoded, gint maxlen);
496
497 static void mailing_list_compose(GtkWidget *w, gpointer *data);
498  
499 static void mailing_list_open_uri(GtkWidget *w, gpointer *data);
500 #define  SEPARATE_ACTION 500 
501 static void mainwindow_quicksearch              (MainWindow     *mainwin, 
502                                                  guint           action, 
503                                                  GtkWidget      *widget);
504 static gboolean any_folder_want_synchronise(void);
505
506 static GtkItemFactoryEntry mainwin_entries[] =
507 {
508         {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
509         {N_("/_File/_Add mailbox"),             NULL, NULL, 0, "<Branch>"},
510         {N_("/_File/_Add mailbox/MH..."),       NULL, add_mailbox_cb, 0, NULL},
511         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
512         {N_("/_File/Change folder order..."),   NULL, foldersort_cb,  0, NULL},
513         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
514         {N_("/_File/_Import mbox file..."),     NULL, import_mbox_cb, 0, NULL},
515         {N_("/_File/_Export to mbox file..."),  NULL, export_mbox_cb, 0, NULL},
516         {N_("/_File/Exp_ort selected to mbox file..."), 
517                                                 NULL, export_list_mbox_cb, 0, NULL},
518         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
519         {N_("/_File/Empty all _Trash folders"), "<shift>D", empty_trash_cb, 0, NULL},
520         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
521         {N_("/_File/_Save as..."),              "<control>S", save_as_cb, 0, NULL},
522         {N_("/_File/_Print..."),                "<control>P", print_cb, 0, NULL},
523         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
524         {N_("/_File/_Work offline"),            "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},
525         {N_("/_File/Synchronise folders"),      "<control><shift>S", sync_cb, 0, NULL},
526         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
527         /* {N_("/_File/_Close"),                "<alt>W", app_exit_cb, 0, NULL}, */
528         {N_("/_File/E_xit"),                    "<control>Q", app_exit_cb, 0, NULL},
529
530         {N_("/_Edit"),                          NULL, NULL, 0, "<Branch>"},
531         {N_("/_Edit/_Copy"),                    "<control>C", copy_cb, 0, NULL},
532         {N_("/_Edit/Select _all"),              "<control>A", allsel_cb, 0, NULL},
533         {N_("/_Edit/Select _thread"),           NULL, select_thread_cb, 0, NULL},
534         {N_("/_Edit/_Delete thread"),           NULL, delete_thread_cb, 0, NULL},
535         {N_("/_Edit/---"),                      NULL, NULL, 0, "<Separator>"},
536         {N_("/_Edit/_Find in current message..."),
537                                                 "<control>F", search_cb, 0, NULL},
538         {N_("/_Edit/_Search folder..."),        "<shift><control>F", search_cb, 1, NULL},
539         {N_("/_Edit/_Quick search"),            "slash", mainwindow_quicksearch, 0, NULL},
540         {N_("/_View"),                          NULL, NULL, 0, "<Branch>"},
541         {N_("/_View/Show or hi_de"),            NULL, NULL, 0, "<Branch>"},
542         {N_("/_View/Show or hi_de/_Message view"),
543                                                 "V", toggle_message_cb, 0, "<ToggleItem>"},
544         {N_("/_View/Show or hi_de/_Toolbar"),
545                                                 NULL, NULL, 0, "<Branch>"},
546         {N_("/_View/Show or hi_de/_Toolbar/Text _below icons"),
547                                                 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
548         {N_("/_View/Show or hi_de/_Toolbar/Text be_side icons"),
549                                                 NULL, toggle_toolbar_cb, TOOLBAR_BOTH_HORIZ, "/View/Show or hide/Toolbar/Text below icons"},
550         {N_("/_View/Show or hi_de/_Toolbar/_Icons only"),
551                                                 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Text below icons"},
552         {N_("/_View/Show or hi_de/_Toolbar/_Text only"),
553                                                 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Text below icons"},
554         {N_("/_View/Show or hi_de/_Toolbar/_Hide"),
555                                                 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Text below icons"},
556         {N_("/_View/Show or hi_de/Status _bar"),
557                                                 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
558         {N_("/_View/Set displayed _columns"),   NULL, NULL, 0, "<Branch>"},
559         {N_("/_View/Set displayed _columns/in _Folder list..."),        NULL, set_folder_display_item_cb, 0, NULL},
560         {N_("/_View/Set displayed _columns/in _Message list..."),NULL, set_summary_display_item_cb, 0, NULL},
561
562         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
563         {N_("/_View/La_yout"),                  NULL, NULL, 0, "<Branch>"},
564         {N_("/_View/Layout/_Standard"),         NULL, set_layout_cb, NORMAL_LAYOUT, "<RadioItem>"},
565         {N_("/_View/Layout/_Three columns"),    NULL, set_layout_cb, VERTICAL_LAYOUT, "/View/Layout/Standard"},
566         {N_("/_View/Layout/_Wide message"),     NULL, set_layout_cb, WIDE_LAYOUT, "/View/Layout/Standard"},
567         {N_("/_View/Layout/W_ide message list"),NULL, set_layout_cb, WIDE_MSGLIST_LAYOUT, "/View/Layout/Standard"},
568         {N_("/_View/Layout/S_mall screen"),     NULL, set_layout_cb, SMALL_LAYOUT, "/View/Layout/Standard"},
569         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
570         {N_("/_View/_Sort"),                    NULL, NULL, 0, "<Branch>"},
571         {N_("/_View/_Sort/by _number"),         NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
572         {N_("/_View/_Sort/by S_ize"),           NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
573         {N_("/_View/_Sort/by _Date"),           NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
574         {N_("/_View/_Sort/by _From"),           NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
575         {N_("/_View/_Sort/by _To"),             NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
576         {N_("/_View/_Sort/by S_ubject"),        NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
577         {N_("/_View/_Sort/by _color label"),
578                                                 NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
579         {N_("/_View/_Sort/by _mark"),           NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
580         {N_("/_View/_Sort/by _status"),         NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
581         {N_("/_View/_Sort/by a_ttachment"),
582                                                 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
583         {N_("/_View/_Sort/by score"),           NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
584         {N_("/_View/_Sort/by locked"),          NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
585         {N_("/_View/_Sort/D_on't sort"),        NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
586         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
587         {N_("/_View/_Sort/Ascending"),          NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
588         {N_("/_View/_Sort/Descending"),         NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
589         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
590         {N_("/_View/_Sort/_Attract by subject"),
591                                                 NULL, attract_by_subject_cb, 0, NULL},
592         {N_("/_View/Th_read view"),             "<control>T", thread_cb, 0, "<ToggleItem>"},
593         {N_("/_View/E_xpand all threads"),      NULL, expand_threads_cb, 0, NULL},
594         {N_("/_View/Co_llapse all threads"),    NULL, collapse_threads_cb, 0, NULL},
595         {N_("/_View/_Hide read messages"),      NULL, hide_read_messages, 0, "<ToggleItem>"},
596
597         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
598         {N_("/_View/_Go to"),                   NULL, NULL, 0, "<Branch>"},
599         {N_("/_View/_Go to/_Previous message"), "P", prev_cb, 0, NULL},
600         {N_("/_View/_Go to/_Next message"),     "N", next_cb, 0, NULL},
601         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
602         {N_("/_View/_Go to/P_revious unread message"),
603                                                 "<shift>P", prev_unread_cb, 0, NULL},
604         {N_("/_View/_Go to/N_ext unread message"),
605                                                 "<shift>N", next_unread_cb, 0, NULL},
606         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
607         {N_("/_View/_Go to/Previous ne_w message"),     NULL, prev_new_cb, 0, NULL},
608         {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
609         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
610         {N_("/_View/_Go to/Previous _marked message"),
611                                                 NULL, prev_marked_cb, 0, NULL},
612         {N_("/_View/_Go to/Next m_arked message"),
613                                                 NULL, next_marked_cb, 0, NULL},
614         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
615         {N_("/_View/_Go to/Previous _labeled message"),
616                                                 NULL, prev_labeled_cb, 0, NULL},
617         {N_("/_View/_Go to/Next la_beled message"),
618                                                 NULL, next_labeled_cb, 0, NULL},
619         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
620         {N_("/_View/_Go to/Last read message"),
621                                                 NULL, last_read_cb, 0, NULL},
622         {N_("/_View/_Go to/Parent message"),
623                                                 "<control>Up", parent_cb, 0, NULL},
624         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
625         {N_("/_View/_Go to/Next unread _folder"),       "<shift>G", goto_unread_folder_cb, 0, NULL},
626         {N_("/_View/_Go to/_Other folder..."),  "G", goto_folder_cb, 0, NULL},
627         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
628
629 #define ENC_SEPARATOR \
630         {N_("/_View/Character _encoding/---"),          NULL, NULL, 0, "<Separator>"}
631 #define ENC_ACTION(action) \
632          NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
633
634         {N_("/_View/Character _encoding"),              NULL, NULL, 0, "<Branch>"},
635         {N_("/_View/Character _encoding/_Auto detect"),
636          NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
637         {N_("/_View/Character _encoding/---"),          NULL, NULL, 0, "<Separator>"},
638         {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
639          ENC_ACTION(C_US_ASCII)},
640         {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
641          ENC_ACTION(C_UTF_8)},
642         ENC_SEPARATOR,
643
644         {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
645          ENC_ACTION(C_ISO_8859_1)},
646         {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
647          ENC_ACTION(C_ISO_8859_15)},
648         {N_("/_View/Character _encoding/Western European (Windows-1252)"),
649          ENC_ACTION(C_WINDOWS_1252)},
650         ENC_SEPARATOR,
651
652         {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
653          ENC_ACTION(C_ISO_8859_2)},
654         ENC_SEPARATOR,
655
656         {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
657          ENC_ACTION(C_ISO_8859_13)},
658         {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
659          ENC_ACTION(C_ISO_8859_4)},
660         ENC_SEPARATOR,
661
662         {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
663          ENC_ACTION(C_ISO_8859_7)},
664         ENC_SEPARATOR,
665
666         {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
667          ENC_ACTION(C_ISO_8859_8)},
668         {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
669          ENC_ACTION(C_CP1255)},
670         ENC_SEPARATOR,
671
672         {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
673          ENC_ACTION(C_ISO_8859_6)},
674         {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
675          ENC_ACTION(C_CP1256)},
676         ENC_SEPARATOR,
677
678         {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
679          ENC_ACTION(C_ISO_8859_9)},
680         ENC_SEPARATOR,
681
682         {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
683          ENC_ACTION(C_ISO_8859_5)},
684         {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
685          ENC_ACTION(C_KOI8_R)},
686         {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
687          ENC_ACTION(C_KOI8_U)},
688         {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
689          ENC_ACTION(C_CP1251)},
690         ENC_SEPARATOR,
691
692         {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
693          ENC_ACTION(C_ISO_2022_JP)},
694         {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
695          ENC_ACTION(C_ISO_2022_JP_2)},
696         {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
697          ENC_ACTION(C_EUC_JP)},
698         {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
699          ENC_ACTION(C_SHIFT_JIS)},
700         ENC_SEPARATOR,
701
702         {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
703          ENC_ACTION(C_GB2312)},
704         {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
705          ENC_ACTION(C_GBK)},
706         {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
707          ENC_ACTION(C_BIG5)},
708         {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
709          ENC_ACTION(C_EUC_TW)},
710         {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
711          ENC_ACTION(C_ISO_2022_CN)},
712         ENC_SEPARATOR,
713
714         {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
715          ENC_ACTION(C_EUC_KR)},
716         {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
717          ENC_ACTION(C_ISO_2022_KR)},
718         ENC_SEPARATOR,
719
720         {N_("/_View/Character _encoding/Thai (TIS-620)"),
721          ENC_ACTION(C_TIS_620)},
722         {N_("/_View/Character _encoding/Thai (Windows-874)"),
723          ENC_ACTION(C_WINDOWS_874)},
724
725 #undef ENC_SEPARATOR
726 #undef ENC_ACTION
727
728 #define DEC_SEPARATOR \
729         {N_("/_View/Decode/---"),               NULL, NULL, 0, "<Separator>"}
730 #define DEC_ACTION(action) \
731          NULL, set_decode_cb, action, "/View/Decode/Auto detect"
732         {N_("/_View/Decode"),           NULL, NULL, 0, "<Branch>"},
733         {N_("/_View/Decode/_Auto detect"),
734          NULL, set_decode_cb, 0, "<RadioItem>"},
735         {N_("/_View/Decode/---"),               NULL, NULL, 0, "<Separator>"},
736         {N_("/_View/Decode/_8bit"),             DEC_ACTION(ENC_8BIT)},
737         {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
738         {N_("/_View/Decode/_Base64"),           DEC_ACTION(ENC_BASE64)},
739         {N_("/_View/Decode/_Uuencode"),         DEC_ACTION(ENC_X_UUENCODE)},
740
741 #undef DEC_SEPARATOR
742 #undef DEC_ACTION
743
744         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
745         {N_("/_View/Open in new _window"),      "<control><alt>N", open_msg_cb, 0, NULL},
746         {N_("/_View/Mess_age source"),          "<control>U", view_source_cb, 0, NULL},
747         {N_("/_View/All headers"),              "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
748         {N_("/_View/Quotes"),                   NULL, NULL, 0, "<Branch>"},
749         {N_("/_View/Quotes/_Fold all"),         "<control><shift>Q", hide_quotes_cb, 1, "<ToggleItem>"},
750         {N_("/_View/Quotes/Fold from level _2"),NULL, hide_quotes_cb, 2, "<ToggleItem>"},
751         {N_("/_View/Quotes/Fold from level _3"),NULL, hide_quotes_cb, 3, "<ToggleItem>"},
752         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
753         {N_("/_View/_Update summary"),          "<control><alt>U", update_summary_cb,  0, NULL},
754
755         {N_("/_Message"),                       NULL, NULL, 0, "<Branch>"},
756         {N_("/_Message/Recei_ve"),              NULL, NULL, 0, "<Branch>"},
757         {N_("/_Message/Recei_ve/Get from _current account"),
758                                                 "<control>I",   inc_mail_cb, 0, NULL},
759         {N_("/_Message/Recei_ve/Get from _all accounts"),
760                                                 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
761         {N_("/_Message/Recei_ve/Cancel receivin_g"),
762                                                 NULL, inc_cancel_cb, 0, NULL},
763         {N_("/_Message/Recei_ve/---"),          NULL, NULL, 0, "<Separator>"},
764         {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
765         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
766         {N_("/_Message/Compose a_n email message"),     "<control>M", compose_mail_cb, 0, NULL},
767         {N_("/_Message/Compose a news message"),        NULL,   compose_news_cb, 0, NULL},
768         {N_("/_Message/_Reply"),                "<control>R",   main_window_reply_cb, COMPOSE_REPLY, NULL},
769         {N_("/_Message/Repl_y to"),             NULL, NULL, 0, "<Branch>"},
770         {N_("/_Message/Repl_y to/_all"),        "<shift><control>R", main_window_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
771         {N_("/_Message/Repl_y to/_sender"),     NULL, main_window_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
772         {N_("/_Message/Repl_y to/mailing _list"),
773                                                 "<control>L", main_window_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
774         {N_("/_Message/Follow-up and reply to"),NULL, main_window_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
775         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
776         {N_("/_Message/_Forward"),              "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
777         {N_("/_Message/For_ward as attachment"),        NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
778         {N_("/_Message/Redirect"),              NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
779
780         {N_("/_Message/Mailing-_List"),                 NULL, NULL, 0, "<Branch>"},
781         {N_("/_Message/Mailing-_List/Post"),            NULL, NULL, 0, "<Branch>"},
782         {N_("/_Message/Mailing-_List/Help"),            NULL, NULL, 0, "<Branch>"},
783         {N_("/_Message/Mailing-_List/Subscribe"),       NULL, NULL, 0, "<Branch>"},
784         {N_("/_Message/Mailing-_List/Unsubscribe"),     NULL, NULL, 0, "<Branch>"},
785         {N_("/_Message/Mailing-_List/View archive"),    NULL, NULL, 0, "<Branch>"},
786         {N_("/_Message/Mailing-_List/Contact owner"),   NULL, NULL, 0, "<Branch>"},
787         
788         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
789         {N_("/_Message/M_ove..."),              "<control>O", move_to_cb, 0, NULL},
790         {N_("/_Message/_Copy..."),              "<shift><control>O", copy_to_cb, 0, NULL},
791         {N_("/_Message/Move to _trash"),        "<control>D", delete_trash_cb,  0, NULL},
792         {N_("/_Message/_Delete..."),            NULL, delete_cb,  0, NULL},
793         {N_("/_Message/Cancel a news message"), "", cancel_cb,  0, NULL},
794         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
795         {N_("/_Message/_Mark"),                 NULL, NULL, 0, "<Branch>"},
796         {N_("/_Message/_Mark/_Mark"),           "<shift>asterisk", mark_cb, 0, NULL},
797         {N_("/_Message/_Mark/_Unmark"),         "U", unmark_cb, 0, NULL},
798         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
799         {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
800         {N_("/_Message/_Mark/Mark as rea_d"),   NULL, mark_as_read_cb, 0, NULL},
801         {N_("/_Message/_Mark/Mark all _read"),  NULL, mark_all_read_cb, 0, NULL},
802         {N_("/_Message/_Mark/Ignore thread"),   NULL, ignore_thread_cb, 0, NULL},
803         {N_("/_Message/_Mark/Unignore thread"), NULL, unignore_thread_cb, 0, NULL},
804         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
805         {N_("/_Message/_Mark/Mark as _spam"),   NULL, mark_as_spam_cb, 1, NULL},
806         {N_("/_Message/_Mark/Mark as _ham"),    NULL, mark_as_spam_cb, 0, NULL},
807         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
808         {N_("/_Message/_Mark/Lock"),            NULL, lock_msgs_cb, 0, NULL},
809         {N_("/_Message/_Mark/Unlock"),          NULL, unlock_msgs_cb, 0, NULL},
810         {N_("/_Message/Color la_bel"),          NULL, NULL,            0, NULL},
811         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
812         {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
813
814         {N_("/_Tools"),                         NULL, NULL, 0, "<Branch>"},
815         {N_("/_Tools/_Address book..."),        "<shift><control>A", addressbook_open_cb, 0, NULL},
816         {N_("/_Tools/Add sender to address boo_k"),
817                                                 NULL, add_address_cb, 0, NULL},
818         {N_("/_Tools/_Harvest addresses"),      NULL, NULL, 0, "<Branch>"},
819         {N_("/_Tools/_Harvest addresses/from _Folder..."),
820                                                 NULL, addr_harvest_cb, 0, NULL},
821         {N_("/_Tools/_Harvest addresses/from _Messages..."),
822                                                 NULL, addr_harvest_msg_cb, 0, NULL},
823         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
824         {N_("/_Tools/_Filter all messages in folder"),
825                                                 NULL, filter_cb, 0, NULL},
826         {N_("/_Tools/Filter _selected messages"),
827                                                 NULL, filter_cb, 1, NULL},
828         {N_("/_Tools/_Create filter rule"),     NULL, NULL, 0, "<Branch>"},
829         {N_("/_Tools/_Create filter rule/_Automatically"),
830                                                 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
831         {N_("/_Tools/_Create filter rule/by _From"),
832                                                 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
833         {N_("/_Tools/_Create filter rule/by _To"),
834                                                 NULL, create_filter_cb, FILTER_BY_TO, NULL},
835         {N_("/_Tools/_Create filter rule/by _Subject"),
836                                                 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
837         {N_("/_Tools/C_reate processing rule"), NULL, NULL, 0, "<Branch>"},
838         {N_("/_Tools/C_reate processing rule/_Automatically"),
839                                                 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
840         {N_("/_Tools/C_reate processing rule/by _From"),
841                                                 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
842         {N_("/_Tools/C_reate processing rule/by _To"),
843                                                 NULL, create_processing_cb, FILTER_BY_TO, NULL},
844         {N_("/_Tools/C_reate processing rule/by _Subject"),
845                                                 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
846         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
847         {N_("/_Tools/List _URLs..."),           "<shift><control>U", open_urls_cb, 0, NULL},
848         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
849         {N_("/_Tools/Actio_ns"),                NULL, NULL, 0, "<Branch>"},
850         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
851         {N_("/_Tools/Ch_eck for new messages in all folders"),
852                                                 NULL, update_folderview_cb, 0, NULL},
853         {N_("/_Tools/Delete du_plicated messages"),
854                                                 NULL, NULL, 0, "<Branch>"},
855         {N_("/_Tools/Delete du_plicated messages/In selected folder"),
856                                                 NULL, delete_duplicated_cb,   0, NULL},
857         {N_("/_Tools/Delete du_plicated messages/In all folders"),
858                                                 NULL, delete_duplicated_all_cb,   0, NULL},
859         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
860         {N_("/_Tools/E_xecute"),                "X", execute_summary_cb, 0, NULL},
861 #ifdef USE_OPENSSL
862         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
863         {N_("/_Tools/SSL cer_tificates..."),    
864                                                 NULL, ssl_manager_open_cb, 0, NULL},
865 #endif
866         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
867         {N_("/_Tools/Filtering Log"),           NULL, filtering_debug_window_show_cb, 0, NULL},
868         {N_("/_Tools/Protocol _Log"),           "<shift><control>L", log_window_show_cb, 0, NULL},
869
870         {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
871         {N_("/_Configuration/C_hange current account"),
872                                                 NULL, NULL, 0, "<Branch>"},
873         {N_("/_Configuration/_Preferences for current account..."),
874                                                 NULL, prefs_account_open_cb, 0, NULL},
875         {N_("/_Configuration/Create _new account..."),
876                                                 NULL, new_account_cb, 0, NULL},
877         {N_("/_Configuration/_Edit accounts..."),
878                                                 NULL, account_edit_open, 0, NULL},
879         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
880         {N_("/_Configuration/P_references..."),
881                                                 NULL, prefs_open_cb, 0, NULL},
882         {N_("/_Configuration/Pre-pr_ocessing..."),
883                                                 NULL, prefs_pre_processing_open_cb, 0, NULL},
884         {N_("/_Configuration/Post-pro_cessing..."),
885                                                 NULL, prefs_post_processing_open_cb, 0, NULL},
886         {N_("/_Configuration/_Filtering..."),
887                                                 NULL, prefs_filtering_open_cb, 0, NULL},
888         {N_("/_Configuration/_Templates..."),   NULL, prefs_template_open_cb, 0, NULL},
889         {N_("/_Configuration/_Actions..."),     NULL, prefs_actions_open_cb, 0, NULL},
890         {N_("/_Configuration/Plu_gins..."),     NULL, plugins_open_cb, 0, NULL},
891
892         {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
893         {N_("/_Help/_Manual"),                  NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
894         {N_("/_Help/_Online User-contributed FAQ"),     
895                                                 NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
896         {N_("/_Help/Icon _Legend"),             NULL, legend_open_cb, 0, NULL},
897         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
898         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
899 };
900
901 static gboolean offline_ask_sync = TRUE;
902 static guint lastkey;
903 static gboolean is_obscured = FALSE;
904
905 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
906                                             GObject *arg1,
907                                             guint value,
908                                             GdkModifierType mod,
909                                             gpointer user_data) 
910 {
911         MainWindow *mainwin = (MainWindow *)user_data;
912
913         if (mainwin->summaryview &&
914             mainwin->summaryview->quicksearch &&
915             quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
916             (mod == 0 || mod == GDK_SHIFT_MASK)) {
917                 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
918                 return TRUE;
919         }
920         return FALSE;
921 }
922
923 #define N_COLOR_LABELS colorlabel_get_color_count()
924
925 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
926                                                           gpointer data)
927 {
928         MainWindow *mainwin;
929         GtkMenuShell *menu;
930         GtkCheckMenuItem **items;
931         gint n;
932         GList *cur;
933         GSList *sel;
934
935         mainwin = (MainWindow *)data;
936         g_return_if_fail(mainwin != NULL);
937
938         sel = summary_get_selection(mainwin->summaryview);
939         if (!sel) return;
940
941         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
942         g_return_if_fail(menu != NULL);
943
944         Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
945
946         /* NOTE: don't return prematurely because we set the "dont_toggle"
947          * state for check menu items */
948         g_object_set_data(G_OBJECT(menu), "dont_toggle",
949                           GINT_TO_POINTER(1));
950
951         /* clear items. get item pointers. */
952         for (n = 0, cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
953                 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
954                         gtk_check_menu_item_set_active
955                                 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
956                         items[n] = GTK_CHECK_MENU_ITEM(cur->data);
957                         n++;
958                 }
959         }
960
961         if (n == (N_COLOR_LABELS + 1)) {
962                 /* iterate all messages and set the state of the appropriate
963                  * items */
964                 for (; sel != NULL; sel = sel->next) {
965                         MsgInfo *msginfo;
966                         gint clabel;
967
968                         msginfo = (MsgInfo *)sel->data;
969                         if (msginfo) {
970                                 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
971                                 if (!items[clabel]->active)
972                                         gtk_check_menu_item_set_active
973                                                 (items[clabel], TRUE);
974                         }
975                 }
976         } else
977                 g_warning("invalid number of color elements (%d)\n", n);
978
979         /* reset "dont_toggle" state */
980         g_object_set_data(G_OBJECT(menu), "dont_toggle",
981                           GINT_TO_POINTER(0));
982 }
983
984 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
985                                                      gpointer data)
986 {
987         guint color = GPOINTER_TO_UINT(data);
988         MainWindow *mainwin;
989
990         mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
991         g_return_if_fail(mainwin != NULL);
992
993         /* "dont_toggle" state set? */
994         if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
995                                 "dont_toggle"))
996                 return;
997
998         summary_set_colorlabel(mainwin->summaryview, color, NULL);
999 }
1000
1001 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
1002 {
1003         GtkWidget *label_menuitem;
1004         GtkWidget *menu;
1005         GtkWidget *item;
1006         gint i;
1007
1008         label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
1009                                                    "/Message/Color label");
1010         g_signal_connect(G_OBJECT(label_menuitem), "activate",
1011                          G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
1012                            mainwin);
1013         gtk_widget_show(label_menuitem);
1014
1015         menu = gtk_menu_new();
1016
1017         /* create sub items. for the menu item activation callback we pass the
1018          * index of label_colors[] as data parameter. for the None color we
1019          * pass an invalid (high) value. also we attach a data pointer so we
1020          * can always get back the Mainwindow pointer. */
1021
1022         item = gtk_check_menu_item_new_with_label(_("None"));
1023         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1024         g_signal_connect(G_OBJECT(item), "activate",
1025                          G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1026                            GUINT_TO_POINTER(0));
1027         g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
1028         gtk_widget_show(item);
1029
1030         gtk_widget_add_accelerator(item, "activate", 
1031                                    mainwin->menu_factory->accel_group, 
1032                                    GDK_0, GDK_CONTROL_MASK,
1033                                    GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1034
1035         item = gtk_menu_item_new();
1036         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1037         gtk_widget_show(item);
1038
1039         /* create pixmap/label menu items */
1040         for (i = 0; i < N_COLOR_LABELS; i++) {
1041                 item = colorlabel_create_check_color_menu_item(
1042                         i, refresh, MAINWIN_COLORMENU);
1043                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1044                 g_signal_connect(G_OBJECT(item), "activate",
1045                                  G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1046                                  GUINT_TO_POINTER(i + 1));
1047                 g_object_set_data(G_OBJECT(item), "mainwin",
1048                                   mainwin);
1049                 gtk_widget_show(item);
1050                 if (i < 9)
1051                         gtk_widget_add_accelerator(item, "activate", 
1052                                    mainwin->menu_factory->accel_group, 
1053                                    GDK_1+i, GDK_CONTROL_MASK,
1054                                    GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1055         }
1056         gtk_widget_show(menu);
1057         gtk_menu_item_set_submenu(GTK_MENU_ITEM(label_menuitem), menu);
1058         mainwin->colorlabel_menu = menu;
1059 }
1060
1061 static gboolean warning_icon_pressed(GtkWidget *widget, GdkEventButton *evt,
1062                                     MainWindow *mainwindow)
1063 {
1064         if (evt && evt->button == 1) {
1065                 log_window_show_error(mainwindow->logwin);
1066                 gtk_widget_hide(mainwindow->warning_btn);
1067         }
1068         return FALSE;
1069 }
1070
1071 static gboolean warning_visi_notify(GtkWidget *widget,
1072                                        GdkEventVisibility *event,
1073                                        MainWindow *mainwindow)
1074 {
1075         gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1076         return FALSE;
1077 }
1078
1079 static gboolean warning_leave_notify(GtkWidget *widget,
1080                                       GdkEventCrossing *event,
1081                                       MainWindow *mainwindow)
1082 {
1083         gdk_window_set_cursor(mainwindow->warning_btn->window, NULL);
1084         return FALSE;
1085 }
1086
1087 static gboolean warning_enter_notify(GtkWidget *widget,
1088                                       GdkEventCrossing *event,
1089                                       MainWindow *mainwindow)
1090 {
1091         gdk_window_set_cursor(mainwindow->warning_btn->window, hand_cursor);
1092         return FALSE;
1093 }
1094
1095 void mainwindow_show_error(void)
1096 {
1097         MainWindow *mainwin = mainwindow_get_mainwindow();
1098         gtk_widget_show(mainwin->warning_btn);
1099 }
1100
1101 void mainwindow_clear_error(MainWindow *mainwin)
1102 {
1103         gtk_widget_hide(mainwin->warning_btn);
1104 }
1105
1106 MainWindow *main_window_create()
1107 {
1108         MainWindow *mainwin;
1109         GtkWidget *window;
1110         GtkWidget *vbox;
1111         GtkWidget *menubar;
1112         GtkWidget *handlebox;
1113         GtkWidget *vbox_body;
1114         GtkWidget *hbox_stat;
1115         GtkWidget *statusbar;
1116         GtkWidget *progressbar;
1117         GtkWidget *statuslabel;
1118         GtkWidget *ac_button;
1119         GtkWidget *ac_label;
1120         GtkWidget *online_pixmap;
1121         GtkWidget *offline_pixmap;
1122         GtkWidget *online_switch;
1123         GtkWidget *offline_switch;
1124         GtkTooltips *tips;
1125         GtkWidget *warning_icon;
1126         GtkWidget *warning_btn;
1127
1128         FolderView *folderview;
1129         SummaryView *summaryview;
1130         MessageView *messageview;
1131         GdkColormap *colormap;
1132         GdkColor color[4];
1133         gboolean success[4];
1134         GtkItemFactory *ifactory;
1135         GtkWidget *ac_menu;
1136         GtkWidget *menuitem;
1137         gint i;
1138         guint n_menu_entries;
1139
1140         static GdkGeometry geometry;
1141
1142         debug_print("Creating main window...\n");
1143         mainwin = g_new0(MainWindow, 1);
1144
1145         /* main window */
1146         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "mainwindow");
1147         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
1148         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
1149
1150         if (!geometry.min_height) {
1151                 geometry.min_width = 320;
1152                 geometry.min_height = 200;
1153         }
1154         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1155                                       GDK_HINT_MIN_SIZE);
1156
1157         g_signal_connect(G_OBJECT(window), "delete_event",
1158                          G_CALLBACK(main_window_close_cb), mainwin);
1159         MANAGE_WINDOW_SIGNALS_CONNECT(window);
1160         g_signal_connect(G_OBJECT(window), "focus_in_event",
1161                          G_CALLBACK(mainwindow_focus_in_event),
1162                          mainwin);
1163         g_signal_connect(G_OBJECT(window), "key_press_event",
1164                          G_CALLBACK(mainwindow_key_pressed), mainwin);
1165
1166         gtk_widget_realize(window);
1167         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1168         
1169
1170         gtkut_widget_set_app_icon(window);
1171
1172         vbox = gtk_vbox_new(FALSE, 0);
1173         gtk_widget_show(vbox);
1174         gtk_container_add(GTK_CONTAINER(window), vbox);
1175
1176         /* menu bar */
1177         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1178         menubar = menubar_create(window, mainwin_entries, 
1179                                  n_menu_entries, "<Main>", mainwin);
1180         gtk_widget_show(menubar);
1181         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1182         ifactory = gtk_item_factory_from_widget(menubar);
1183
1184 /*      gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1185         main_create_mailing_list_menu (mainwin, NULL); */
1186
1187         menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
1188
1189         if (prefs_common.toolbar_detachable) {
1190                 handlebox = gtk_handle_box_new();
1191                 gtk_widget_show(handlebox);
1192                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1193                 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1194                                  G_CALLBACK(toolbar_child_attached), mainwin);
1195                 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1196                                  G_CALLBACK(toolbar_child_detached), mainwin);
1197         } else {
1198                 handlebox = gtk_hbox_new(FALSE, 0);
1199                 gtk_widget_show(handlebox);
1200                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1201         }
1202         /* link window to mainwin->window to avoid gdk warnings */
1203         mainwin->window       = window;
1204         
1205         /* create toolbar */
1206         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
1207                                           handlebox, 
1208                                           (gpointer)mainwin);
1209         toolbar_set_learn_button
1210                 (mainwin->toolbar,
1211                  LEARN_SPAM);
1212
1213         /* vbox that contains body */
1214         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1215         gtk_widget_show(vbox_body);
1216         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1217         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1218
1219         hbox_stat = gtk_hbox_new(FALSE, 2);
1220         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1221
1222         tips = gtk_tooltips_new();
1223
1224         warning_icon = gtk_image_new_from_stock
1225                         (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1226         warning_btn = gtk_event_box_new();
1227         gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1228         
1229         mainwin->warning_btn      = warning_btn;
1230         
1231         g_signal_connect(G_OBJECT(warning_btn), "button-press-event", 
1232                          G_CALLBACK(warning_icon_pressed),
1233                          (gpointer) mainwin);
1234         g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
1235                          G_CALLBACK(warning_visi_notify), mainwin);
1236         g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1237                          G_CALLBACK(warning_visi_notify), mainwin);
1238         g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1239                          G_CALLBACK(warning_leave_notify), mainwin);
1240         g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1241                          G_CALLBACK(warning_enter_notify), mainwin);
1242
1243         gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1244
1245         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn, 
1246                              _("Some error(s) happened. Click here to view log."), NULL);
1247         gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1248
1249         statusbar = statusbar_create();
1250         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1251
1252         progressbar = gtk_progress_bar_new();
1253         gtk_widget_set_size_request(progressbar, 120, 1);
1254         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1255
1256         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1257         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1258         online_switch = gtk_button_new ();
1259         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch, 
1260                              _("You are online. Click the icon to go offline"), NULL);
1261         offline_switch = gtk_button_new ();
1262         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch, 
1263                              _("You are offline. Click the icon to go online"),
1264                              NULL);
1265         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1266         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1267         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1268         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1269         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1270         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1271         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1272         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1273         
1274         statuslabel = gtk_label_new("");
1275         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1276
1277         ac_button = gtk_button_new();
1278         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
1279                              ac_button, _("Select account"), NULL);
1280         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1281         gtk_widget_set_size_request(ac_button, -1, 0);
1282         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1283         g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1284                          G_CALLBACK(ac_label_button_pressed), mainwin);
1285
1286         ac_label = gtk_label_new("");
1287         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1288
1289         gtk_widget_show_all(hbox_stat);
1290
1291         gtk_widget_hide(offline_switch);
1292         gtk_widget_hide(warning_btn);
1293
1294         /* create views */
1295         mainwin->folderview  = folderview  = folderview_create();
1296         mainwin->summaryview = summaryview = summary_create();
1297         mainwin->messageview = messageview = messageview_create(mainwin);
1298
1299         /* init log instances data before creating log views */
1300         set_log_title(LOG_PROTOCOL, _("Protocol log"));
1301         set_log_prefs(LOG_PROTOCOL,
1302                         &prefs_common.logwin_width,
1303                         &prefs_common.logwin_height);
1304         set_log_title(LOG_DEBUG_FILTERING, _("Filtering/processing debug log"));
1305         set_log_prefs(LOG_DEBUG_FILTERING,
1306                         &prefs_common.filtering_debugwin_width,
1307                         &prefs_common.filtering_debugwin_height);
1308
1309         /* setup log windows */
1310         mainwin->logwin = log_window_create(LOG_PROTOCOL);
1311         log_window_init(mainwin->logwin);
1312
1313         mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
1314         log_window_set_clipping(mainwin->logwin,
1315                                 prefs_common.cliplog,
1316                                 prefs_common.loglength);
1317
1318         log_window_init(mainwin->filtering_debugwin);
1319         log_window_set_clipping(mainwin->filtering_debugwin,
1320                                 prefs_common.filtering_debug_cliplog,
1321                                 prefs_common.filtering_debug_loglength);
1322         if (prefs_common.enable_filtering_debug)
1323                 log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
1324         else
1325                 log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
1326
1327         folderview->mainwin      = mainwin;
1328         folderview->summaryview  = summaryview;
1329
1330         summaryview->mainwin     = mainwin;
1331         summaryview->folderview  = folderview;
1332         summaryview->messageview = messageview;
1333         summaryview->window      = window;
1334
1335         messageview->statusbar   = statusbar;
1336         mainwin->vbox           = vbox;
1337         mainwin->menubar        = menubar;
1338         mainwin->menu_factory   = ifactory;
1339         mainwin->handlebox      = handlebox;
1340         mainwin->vbox_body      = vbox_body;
1341         mainwin->hbox_stat      = hbox_stat;
1342         mainwin->statusbar      = statusbar;
1343         mainwin->progressbar    = progressbar;
1344         mainwin->statuslabel    = statuslabel;
1345         mainwin->online_switch  = online_switch;
1346         mainwin->online_pixmap  = online_pixmap;
1347         mainwin->offline_pixmap = offline_pixmap;
1348         mainwin->ac_button      = ac_button;
1349         mainwin->ac_label       = ac_label;
1350         mainwin->offline_switch    = offline_switch;
1351         
1352         /* set context IDs for status bar */
1353         mainwin->mainwin_cid = gtk_statusbar_get_context_id
1354                 (GTK_STATUSBAR(statusbar), "Main Window");
1355         mainwin->folderview_cid = gtk_statusbar_get_context_id
1356                 (GTK_STATUSBAR(statusbar), "Folder View");
1357         mainwin->summaryview_cid = gtk_statusbar_get_context_id
1358                 (GTK_STATUSBAR(statusbar), "Summary View");
1359         mainwin->messageview_cid = gtk_statusbar_get_context_id
1360                 (GTK_STATUSBAR(statusbar), "Message View");
1361
1362         messageview->statusbar_cid = mainwin->messageview_cid;
1363
1364         /* allocate colors for summary view and folder view */
1365         summaryview->color_marked.red = summaryview->color_marked.green = 0;
1366         summaryview->color_marked.blue = (guint16)65535;
1367
1368         summaryview->color_dim.red = summaryview->color_dim.green =
1369                 summaryview->color_dim.blue = COLOR_DIM;
1370
1371         gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1372                                        &folderview->color_new);
1373
1374         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1375                                        &folderview->color_op);
1376
1377         summaryview->color_important.red = 0;
1378         summaryview->color_important.green = 0;
1379         summaryview->color_important.blue = (guint16)65535;
1380
1381         color[0] = summaryview->color_marked;
1382         color[1] = summaryview->color_dim;
1383         color[2] = folderview->color_new;
1384         color[3] = folderview->color_op;
1385
1386         colormap = gdk_drawable_get_colormap(window->window);
1387         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1388         for (i = 0; i < 4; i++) {
1389                 if (success[i] == FALSE)
1390                         g_warning("MainWindow: color allocation %d failed\n", i);
1391         }
1392
1393         debug_print("done.\n");
1394
1395         messageview->visible = prefs_common.msgview_visible;
1396
1397         main_window_set_widgets(mainwin, prefs_common.layout_mode);
1398
1399         g_signal_connect(G_OBJECT(window), "size_allocate",
1400                          G_CALLBACK(main_window_size_allocate_cb),
1401                          mainwin);
1402
1403         /* set menu items */
1404         menuitem = gtk_item_factory_get_item
1405                 (ifactory, "/View/Character encoding/Auto detect");
1406         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1407
1408         switch (prefs_common.toolbar_style) {
1409         case TOOLBAR_NONE:
1410                 menuitem = gtk_item_factory_get_item
1411                         (ifactory, "/View/Show or hide/Toolbar/Hide");
1412                 break;
1413         case TOOLBAR_ICON:
1414                 menuitem = gtk_item_factory_get_item
1415                         (ifactory, "/View/Show or hide/Toolbar/Icons only");
1416                 break;
1417         case TOOLBAR_TEXT:
1418                 menuitem = gtk_item_factory_get_item
1419                         (ifactory, "/View/Show or hide/Toolbar/Text only");
1420                 break;
1421         case TOOLBAR_BOTH:
1422                 menuitem = gtk_item_factory_get_item
1423                         (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1424                 break;
1425         case TOOLBAR_BOTH_HORIZ:
1426                 menuitem = gtk_item_factory_get_item
1427                         (ifactory,
1428                          "/View/Show or hide/Toolbar/Text beside icons");
1429         }
1430         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1431
1432         gtk_widget_hide(mainwin->hbox_stat);
1433         menuitem = gtk_item_factory_get_item
1434                 (ifactory, "/View/Show or hide/Status bar");
1435         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1436                                        prefs_common.show_statusbar);
1437         
1438         /* set account selection menu */
1439         ac_menu = gtk_item_factory_get_widget
1440                 (ifactory, "/Configuration/Change current account");
1441         mainwin->ac_menu = ac_menu;
1442
1443         toolbar_main_set_sensitive(mainwin);
1444
1445         /* create actions menu */
1446         main_window_update_actions_menu(mainwin);
1447
1448         main_create_mailing_list_menu (mainwin, NULL);
1449
1450         /* attach accel groups to main window */
1451 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
1452         gtk_window_add_accel_group                                      \
1453                 (GTK_WINDOW(win),                                       \
1454                  gtk_item_factory_from_widget(menu)->accel_group);      \
1455         g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1456                         "accel_activate",                               \
1457                         G_CALLBACK(main_window_accel_activate), mainwin);
1458                          
1459         
1460         ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1461         
1462         /* connect the accelerators for equivalent 
1463            menu items in different menus             */
1464         menu_connect_identical_items();
1465
1466         gtk_window_iconify(GTK_WINDOW(mainwin->window));
1467
1468         g_signal_connect(G_OBJECT(window), "window_state_event",
1469                          G_CALLBACK(mainwindow_state_event_cb), mainwin);
1470         g_signal_connect(G_OBJECT(window), "visibility_notify_event",
1471                          G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
1472         gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
1473
1474         if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
1475             prefs_common.layout_mode == SMALL_LAYOUT) {
1476                 summary_relayout(mainwin->summaryview); 
1477         }
1478         summary_update_unread(mainwin->summaryview, NULL);
1479         
1480         gtk_widget_show(mainwin->window);
1481
1482         /* initialize views */
1483         folderview_init(folderview);
1484         summary_init(summaryview);
1485         messageview_init(messageview);
1486 #ifdef USE_OPENSSL
1487         sslcertwindow_register_hook();
1488 #endif
1489         mainwin->lock_count = 0;
1490         mainwin->menu_lock_count = 0;
1491         mainwin->cursor_count = 0;
1492
1493         mainwin->progressindicator_hook =
1494                 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1495
1496         if (!watch_cursor)
1497                 watch_cursor = gdk_cursor_new(GDK_WATCH);
1498         if (!hand_cursor)
1499                 hand_cursor = gdk_cursor_new(GDK_HAND2);
1500
1501         mainwin_list = g_list_append(mainwin_list, mainwin);
1502
1503         /* init work_offline */
1504         if (prefs_common.work_offline)
1505                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1506
1507         mainwindow_colorlabel_menu_create(mainwin, FALSE);
1508         
1509         return mainwin;
1510 }
1511
1512 void main_window_destroy(MainWindow *mainwin)
1513 {
1514         /* TODO : destroy other component */
1515         messageview_destroy(mainwin->messageview);
1516         mainwin->messageview = NULL;    
1517 }
1518
1519 void main_window_update_actions_menu(MainWindow *mainwin)
1520 {
1521         GtkItemFactory *ifactory;
1522
1523         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1524         action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1525 }
1526
1527 void main_window_cursor_wait(MainWindow *mainwin)
1528 {
1529
1530         if (mainwin->cursor_count == 0) {
1531                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1532                 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1533         }
1534         
1535         mainwin->cursor_count++;
1536
1537         gdk_flush();
1538 }
1539
1540 void main_window_cursor_normal(MainWindow *mainwin)
1541 {
1542         if (mainwin->cursor_count)
1543                 mainwin->cursor_count--;
1544
1545         if (mainwin->cursor_count == 0) {
1546                 gdk_window_set_cursor(mainwin->window->window, NULL);
1547                 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1548         }
1549         gdk_flush();
1550 }
1551
1552 /* lock / unlock the user-interface */
1553 void main_window_lock(MainWindow *mainwin)
1554 {
1555         if (mainwin->lock_count == 0)
1556                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1557
1558         mainwin->lock_count++;
1559
1560         main_window_set_menu_sensitive(mainwin);
1561         toolbar_main_set_sensitive(mainwin);
1562 }
1563
1564 void main_window_unlock(MainWindow *mainwin)
1565 {
1566         if (mainwin->lock_count)
1567                 mainwin->lock_count--;
1568
1569         main_window_set_menu_sensitive(mainwin);
1570         toolbar_main_set_sensitive(mainwin);
1571
1572         if (mainwin->lock_count == 0)
1573                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1574 }
1575
1576 static void main_window_menu_callback_block(MainWindow *mainwin)
1577 {
1578         mainwin->menu_lock_count++;
1579 }
1580
1581 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1582 {
1583         if (mainwin->menu_lock_count)
1584                 mainwin->menu_lock_count--;
1585 }
1586
1587 static guint prefs_tag = 0;
1588
1589 void main_window_reflect_prefs_all(void)
1590 {
1591         main_window_reflect_prefs_all_real(FALSE);
1592 }
1593
1594 static gboolean reflect_prefs_timeout_cb(gpointer data) 
1595 {
1596         gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1597         GList *cur;
1598         MainWindow *mainwin;
1599         GtkWidget *pixmap;
1600
1601         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1602                 mainwin = (MainWindow *)cur->data;
1603
1604                 main_window_show_cur_account(mainwin);
1605                 main_window_set_menu_sensitive(mainwin);
1606                 toolbar_main_set_sensitive(mainwin);
1607
1608                 /* pixmap themes */
1609                 if (pixmap_theme_changed) {
1610                         toolbar_update(TOOLBAR_MAIN, mainwin);
1611                         messageview_reflect_prefs_pixmap_theme();
1612                         compose_reflect_prefs_pixmap_theme();
1613                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1614                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1615
1616                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1617                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
1618                                              mainwin->online_pixmap);
1619                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1620                         gtk_widget_show(pixmap);
1621                         mainwin->online_pixmap = pixmap;
1622                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1623                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
1624                                              mainwin->offline_pixmap);
1625                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1626                         gtk_widget_show(pixmap);
1627                         mainwin->offline_pixmap = pixmap;
1628                 }
1629                 
1630                 headerview_set_font(mainwin->messageview->headerview);
1631                 headerview_set_visibility(mainwin->messageview->headerview,
1632                                           prefs_common.display_header_pane);
1633                 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1634                 folderview_reflect_prefs();
1635                 summary_reflect_prefs();
1636                 summary_redisplay_msg(mainwin->summaryview);
1637         }
1638         prefs_tag = 0;
1639         return FALSE;
1640 }
1641
1642 void main_window_reflect_prefs_all_now(void)
1643 {
1644         reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1645 }
1646
1647 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1648 {
1649         GtkMenuShell *menu;
1650         GList *cur;
1651
1652         /* re-create colorlabel submenu */
1653         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1654         g_return_if_fail(menu != NULL);
1655
1656         /* clear items. get item pointers. */
1657         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1658                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1659         }
1660         mainwindow_colorlabel_menu_create(mainwin, TRUE);
1661         summary_reflect_prefs_custom_colors(mainwin->summaryview);
1662
1663 }
1664
1665 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1666 {
1667         if (prefs_tag == 0 || pixmap_theme_changed) {
1668                 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb, 
1669                                                 GINT_TO_POINTER(pixmap_theme_changed));
1670         }
1671 }
1672
1673 void main_window_set_summary_column(void)
1674 {
1675         GList *cur;
1676         MainWindow *mainwin;
1677
1678         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1679                 mainwin = (MainWindow *)cur->data;
1680                 summary_set_column_order(mainwin->summaryview);
1681         }
1682 }
1683
1684 void main_window_set_folder_column(void)
1685 {
1686         GList *cur;
1687         MainWindow *mainwin;
1688
1689         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1690                 mainwin = (MainWindow *)cur->data;
1691                 folderview_set_column_order(mainwin->folderview);
1692         }
1693 }
1694
1695 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1696                                                   GList *account_list)
1697 {
1698         GList *cur_ac, *cur_item;
1699         GtkWidget *menuitem;
1700         PrefsAccount *ac_prefs;
1701
1702         /* destroy all previous menu item */
1703         cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1704         while (cur_item != NULL) {
1705                 GList *next = cur_item->next;
1706                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1707                 cur_item = next;
1708         }
1709
1710         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1711                 ac_prefs = (PrefsAccount *)cur_ac->data;
1712
1713                 menuitem = gtk_menu_item_new_with_label
1714                         (ac_prefs->account_name
1715                          ? ac_prefs->account_name : _("Untitled"));
1716                 gtk_widget_show(menuitem);
1717                 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1718                 g_signal_connect(G_OBJECT(menuitem), "activate",
1719                                  G_CALLBACK(account_selector_menu_cb),
1720                                  ac_prefs);
1721         }
1722 }
1723
1724 static void main_window_set_account_receive_menu(MainWindow *mainwin,
1725                                                  GList *account_list)
1726 {
1727         GList *cur_ac, *cur_item;
1728         GtkWidget *menu;
1729         GtkWidget *menuitem;
1730         PrefsAccount *ac_prefs;
1731
1732         menu = gtk_item_factory_get_widget(mainwin->menu_factory,
1733                                            "/Message/Receive");
1734
1735         /* search for separator */
1736         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
1737              cur_item = cur_item->next) {
1738                 if (GTK_BIN(cur_item->data)->child == NULL) {
1739                         cur_item = cur_item->next;
1740                         break;
1741                 }
1742         }
1743
1744         /* destroy all previous menu item */
1745         while (cur_item != NULL) {
1746                 GList *next = cur_item->next;
1747                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1748                 cur_item = next;
1749         }
1750
1751         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1752                 ac_prefs = (PrefsAccount *)cur_ac->data;
1753
1754                 menuitem = gtk_menu_item_new_with_label
1755                         (ac_prefs->account_name ? ac_prefs->account_name
1756                          : _("Untitled"));
1757                 gtk_widget_show(menuitem);
1758                 gtk_menu_append(GTK_MENU(menu), menuitem);
1759                 g_signal_connect(G_OBJECT(menuitem), "activate",
1760                                  G_CALLBACK(account_receive_menu_cb),
1761                                  ac_prefs);
1762         }
1763 }
1764
1765 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
1766                                                        GList *account_list)
1767 {
1768         GList *cur_ac, *cur_item;
1769         GtkWidget *menuitem;
1770         PrefsAccount *ac_prefs;
1771         GtkWidget *menu = NULL;
1772
1773         if (mainwin->toolbar->getall_btn == NULL
1774         ||  mainwin->toolbar->getall_combo == NULL) /* button doesn't exist */
1775                 return;
1776
1777         menu = mainwin->toolbar->getall_combo->menu;
1778
1779         /* destroy all previous menu item */
1780         cur_item = GTK_MENU_SHELL(menu)->children;
1781         while (cur_item != NULL) {
1782                 GList *next = cur_item->next;
1783                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1784                 cur_item = next;
1785         }
1786
1787         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1788                 ac_prefs = (PrefsAccount *)cur_ac->data;
1789
1790                 menuitem = gtk_menu_item_new_with_label
1791                         (ac_prefs->account_name
1792                          ? ac_prefs->account_name : _("Untitled"));
1793                 gtk_widget_show(menuitem);
1794                 gtk_menu_append(GTK_MENU(menu), menuitem);
1795                 g_signal_connect(G_OBJECT(menuitem), "activate",
1796                                  G_CALLBACK(account_receive_menu_cb),
1797                                  ac_prefs);
1798         }
1799 }
1800
1801 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
1802                                                        GList *account_list)
1803 {
1804         GList *cur_ac, *cur_item;
1805         GtkWidget *menuitem;
1806         PrefsAccount *ac_prefs;
1807         GtkWidget *menu = NULL;
1808
1809         if (mainwin->toolbar->compose_mail_btn == NULL
1810         ||  mainwin->toolbar->compose_combo == NULL) /* button doesn't exist */
1811                 return;
1812
1813         menu = mainwin->toolbar->compose_combo->menu;
1814
1815         /* destroy all previous menu item */
1816         cur_item = GTK_MENU_SHELL(menu)->children;
1817         while (cur_item != NULL) {
1818                 GList *next = cur_item->next;
1819                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1820                 cur_item = next;
1821         }
1822
1823         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1824                 ac_prefs = (PrefsAccount *)cur_ac->data;
1825
1826                 menuitem = gtk_menu_item_new_with_label
1827                         (ac_prefs->account_name
1828                          ? ac_prefs->account_name : _("Untitled"));
1829                 gtk_widget_show(menuitem);
1830                 gtk_menu_append(GTK_MENU(menu), menuitem);
1831                 g_signal_connect(G_OBJECT(menuitem), "activate",
1832                                  G_CALLBACK(account_compose_menu_cb),
1833                                  ac_prefs);
1834         }
1835 }
1836
1837 void main_window_set_account_menu(GList *account_list)
1838 {
1839         GList *cur;
1840         MainWindow *mainwin;
1841
1842         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1843                 mainwin = (MainWindow *)cur->data;
1844                 main_window_set_account_selector_menu(mainwin, account_list);
1845                 main_window_set_account_receive_menu(mainwin, account_list);
1846                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1847                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1848         }
1849         hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
1850 }
1851
1852 void main_window_set_account_menu_only_toolbar(GList *account_list)
1853 {
1854         GList *cur;
1855         MainWindow *mainwin;
1856
1857         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1858                 mainwin = (MainWindow *)cur->data;
1859                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1860                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1861         }
1862 }
1863
1864 static void main_window_show_cur_account(MainWindow *mainwin)
1865 {
1866         gchar *buf;
1867         gchar *ac_name;
1868
1869         ac_name = g_strdup(cur_account
1870                            ? (cur_account->account_name
1871                               ? cur_account->account_name : _("Untitled"))
1872                            : _("none"));
1873
1874         if (cur_account)
1875                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1876         else
1877                 buf = g_strdup(PROG_VERSION);
1878         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1879         g_free(buf);
1880
1881         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1882         gtk_widget_queue_resize(mainwin->ac_button);
1883
1884         g_free(ac_name);
1885 }
1886
1887 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
1888 {
1889         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1890         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1891         GtkWidget *message_wid = mainwin->messageview->vbox;
1892
1893         if (layout_mode == prefs_common.layout_mode) 
1894                 return;
1895
1896         debug_print("Changing window separation type from %d to %d\n",
1897                     prefs_common.layout_mode, layout_mode);
1898
1899         /* remove widgets from those containers */
1900         gtk_widget_ref(folder_wid);
1901         gtk_widget_ref(summary_wid);
1902         gtk_widget_ref(message_wid);
1903         gtkut_container_remove
1904                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1905         gtkut_container_remove
1906                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1907         gtkut_container_remove
1908                 (GTK_CONTAINER(message_wid->parent), message_wid);
1909
1910         gtk_widget_hide(mainwin->window);
1911         main_window_set_widgets(mainwin, layout_mode);
1912         gtk_widget_show(mainwin->window);
1913
1914         gtk_widget_unref(folder_wid);
1915         gtk_widget_unref(summary_wid);
1916         gtk_widget_unref(message_wid);
1917 }
1918
1919 void mainwindow_reset_paned(GtkPaned *paned)
1920 {
1921                 gint min, max, mid;
1922
1923                 if (gtk_paned_get_child1(GTK_PANED(paned)))
1924                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
1925                 if (gtk_paned_get_child2(GTK_PANED(paned)))
1926                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
1927
1928 GTK_EVENTS_FLUSH();
1929                 g_object_get (G_OBJECT(paned),
1930                                 "min-position",
1931                                 &min, NULL);
1932                 g_object_get (G_OBJECT(paned),
1933                                 "max-position",
1934                                 &max, NULL);
1935                 mid = (min+max)/2;
1936                 gtk_paned_set_position(GTK_PANED(paned), mid);
1937 }
1938
1939 static void mainwin_paned_show_first(GtkPaned *paned)
1940 {
1941                 gint max;
1942                 g_object_get (G_OBJECT(paned),
1943                                 "max-position",
1944                                 &max, NULL);
1945
1946                 if (gtk_paned_get_child1(GTK_PANED(paned)))
1947                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
1948                 if (gtk_paned_get_child2(GTK_PANED(paned)))
1949                         gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned)));
1950                 gtk_paned_set_position(GTK_PANED(paned), max);
1951 }
1952
1953 static void mainwin_paned_show_last(GtkPaned *paned)
1954 {
1955                 gint min;
1956                 g_object_get (G_OBJECT(paned),
1957                                 "min-position",
1958                                 &min, NULL);
1959
1960                 if (gtk_paned_get_child1(GTK_PANED(paned)))
1961                         gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
1962                 if (gtk_paned_get_child2(GTK_PANED(paned)))
1963                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
1964                 gtk_paned_set_position(GTK_PANED(paned), min);
1965 }
1966
1967 void main_window_toggle_message_view(MainWindow *mainwin)
1968 {
1969         SummaryView *summaryview = mainwin->summaryview;
1970         GtkWidget *ppaned = NULL;
1971         GtkWidget *container = NULL;
1972         
1973         switch (prefs_common.layout_mode) {
1974         case NORMAL_LAYOUT:
1975         case VERTICAL_LAYOUT:
1976         case SMALL_LAYOUT:
1977                 ppaned = mainwin->vpaned;
1978                 container = mainwin->hpaned;
1979                 if (ppaned->parent != NULL) {
1980                         mainwin->messageview->visible = FALSE;
1981                         summaryview->displayed = NULL;
1982                         gtk_widget_ref(ppaned);
1983                         gtkut_container_remove(GTK_CONTAINER(container), ppaned);
1984                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1985                 } else {
1986                         mainwin->messageview->visible = TRUE;
1987                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
1988                         gtk_container_add(GTK_CONTAINER(container), ppaned);
1989                         gtk_widget_unref(ppaned);
1990                 }
1991                 break;
1992         case WIDE_LAYOUT:
1993                 ppaned = mainwin->hpaned;
1994                 container = mainwin->vpaned;
1995                 if (mainwin->messageview->vbox->parent != NULL) {
1996                         mainwin->messageview->visible = FALSE;
1997                         summaryview->displayed = NULL;
1998                         gtk_widget_ref(mainwin->messageview->vbox);
1999                         gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
2000                 } else {
2001                         mainwin->messageview->visible = TRUE;
2002                         gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
2003                         gtk_widget_unref(mainwin->messageview->vbox);
2004                 }
2005                 break;
2006         case WIDE_MSGLIST_LAYOUT:
2007                 g_warning("can't hide messageview in this wide msglist layout");
2008                 break;
2009         }
2010
2011         if (messageview_is_visible(mainwin->messageview))
2012                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2013                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2014         else
2015                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2016                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2017
2018         if (mainwin->messageview->visible == FALSE)
2019                 messageview_clear(mainwin->messageview);
2020
2021         main_window_set_menu_sensitive(mainwin);
2022
2023         prefs_common.msgview_visible = mainwin->messageview->visible;
2024
2025         if (messageview_is_visible(mainwin->messageview)) {
2026                 gtk_widget_queue_resize(mainwin->hpaned);
2027                 gtk_widget_queue_resize(mainwin->vpaned);
2028         }
2029         summary_grab_focus(summaryview);
2030 }
2031
2032 void main_window_get_size(MainWindow *mainwin)
2033 {
2034         GtkAllocation *allocation;
2035
2036         if (mainwin_list == NULL || mainwin->messageview == NULL) {
2037                 debug_print("called after messageview "
2038                             "has been deallocated!\n");
2039                 return;
2040         }
2041
2042         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
2043
2044         if (allocation->width > 1 && allocation->height > 1) {
2045                 prefs_common.summaryview_width = allocation->width;
2046
2047                 if (messageview_is_visible(mainwin->messageview))
2048                         prefs_common.summaryview_height = allocation->height;
2049
2050                 prefs_common.mainview_width = allocation->width;
2051         }
2052
2053         allocation = &mainwin->window->allocation;
2054         if (allocation->width > 1 && allocation->height > 1) {
2055                 prefs_common.mainview_height = allocation->height;
2056                 prefs_common.mainwin_width   = allocation->width;
2057                 prefs_common.mainwin_height  = allocation->height;
2058         }
2059
2060         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
2061         if (allocation->width > 1 && allocation->height > 1) {
2062                 prefs_common.folderview_width  = allocation->width;
2063                 prefs_common.folderview_height = allocation->height;
2064         }
2065
2066         allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
2067         if (allocation->width > 1 && allocation->height > 1) {
2068                 prefs_common.msgview_width = allocation->width;
2069                 prefs_common.msgview_height = allocation->height;
2070         }
2071
2072 /*      debug_print("summaryview size: %d x %d\n",
2073                     prefs_common.summaryview_width,
2074                     prefs_common.summaryview_height);
2075         debug_print("folderview size: %d x %d\n",
2076                     prefs_common.folderview_width,
2077                     prefs_common.folderview_height);
2078         debug_print("messageview size: %d x %d\n",
2079                     prefs_common.msgview_width,
2080                     prefs_common.msgview_height); */
2081 }
2082
2083 void main_window_get_position(MainWindow *mainwin)
2084 {
2085         gint x, y;
2086
2087         gtkut_widget_get_uposition(mainwin->window, &x, &y);
2088
2089         prefs_common.mainview_x = x;
2090         prefs_common.mainview_y = y;
2091         prefs_common.mainwin_x = x;
2092         prefs_common.mainwin_y = y;
2093
2094         debug_print("main window position: %d, %d\n", x, y);
2095 }
2096
2097 void main_window_progress_on(MainWindow *mainwin)
2098 {
2099         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2100 }
2101
2102 void main_window_progress_off(MainWindow *mainwin)
2103 {
2104         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2105         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2106 }
2107
2108 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
2109 {
2110         gchar buf[32];
2111
2112         g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
2113         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
2114         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
2115                                 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
2116 }
2117
2118 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2119 {
2120         if (confirm && procmsg_have_trashed_mails_fast()) {
2121                 if (alertpanel(_("Empty trash"),
2122                                _("Delete all messages in trash folders?"),
2123                                GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
2124                     != G_ALERTALTERNATE)
2125                         return;
2126                 manage_window_focus_in(mainwin->window, NULL, NULL);
2127         }
2128
2129         procmsg_empty_all_trash();
2130
2131         if (mainwin->summaryview->folder_item &&
2132             mainwin->summaryview->folder_item->stype == F_TRASH)
2133                 gtk_widget_grab_focus(mainwin->folderview->ctree);
2134 }
2135
2136 void main_window_add_mailbox(MainWindow *mainwin)
2137 {
2138         gchar *path;
2139         Folder *folder;
2140
2141         path = input_dialog(_("Add mailbox"),
2142                             _("Input the location of mailbox.\n"
2143                               "If an existing mailbox is specified, it will be\n"
2144                               "scanned automatically."),
2145                             "Mail");
2146         if (!path) return;
2147         if (folder_find_from_path(path)) {
2148                 alertpanel_error(_("The mailbox '%s' already exists."), path);
2149                 g_free(path);
2150                 return;
2151         }
2152         folder = folder_new(folder_get_class_from_string("mh"), 
2153                             !strcmp(path, "Mail") ? _("Mailbox") : 
2154                             g_path_get_basename(path), path);
2155         g_free(path);
2156
2157         if (folder->klass->create_tree(folder) < 0) {
2158                 alertpanel_error(_("Creation of the mailbox failed.\n"
2159                                    "Maybe some files already exist, or you don't have the permission to write there."));
2160                 folder_destroy(folder);
2161                 return;
2162         }
2163
2164         folder_add(folder);
2165         folder_set_ui_func(folder, scan_tree_func, mainwin);
2166         folder_scan_tree(folder, TRUE);
2167         folder_set_ui_func(folder, NULL, NULL);
2168 }
2169
2170 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2171 {
2172         SensitiveCond state = 0;
2173         SummarySelection selection;
2174         FolderItem *item = mainwin->summaryview->folder_item;
2175         GList *account_list = account_get_list();
2176         
2177         selection = summary_get_selection_type(mainwin->summaryview);
2178
2179         if (mainwin->lock_count == 0)
2180                 state |= M_UNLOCKED;
2181         if (selection != SUMMARY_NONE)
2182                 state |= M_MSG_EXIST;
2183         if (item && item->path && folder_item_parent(item) && !item->no_select) {
2184                 state |= M_EXEC;
2185                 /*              if (item->folder->type != F_NEWS) */
2186                 state |= M_ALLOW_DELETE;
2187
2188                 if (prefs_common.immediate_exec == 0
2189                     && mainwin->lock_count == 0)
2190                         state |= M_DELAY_EXEC;
2191
2192                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2193                     || selection != SUMMARY_NONE)
2194                         state |= M_HIDE_READ_MSG;
2195         }               
2196         if (mainwin->summaryview->threaded)
2197                 state |= M_THREADED;
2198         else
2199                 state |= M_UNTHREADED;  
2200         if (selection == SUMMARY_SELECTED_SINGLE ||
2201             selection == SUMMARY_SELECTED_MULTIPLE)
2202                 state |= M_TARGET_EXIST;
2203         if (selection == SUMMARY_SELECTED_SINGLE)
2204                 state |= M_SINGLE_TARGET_EXIST;
2205         if (mainwin->summaryview->folder_item &&
2206             mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2207                 state |= M_NEWS;
2208         else
2209                 state |= M_NOT_NEWS;
2210         if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2211                 state |= M_ACTIONS_EXIST;
2212
2213         if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2214                 state |= M_HAVE_QUEUED_MAILS;
2215
2216         if (selection == SUMMARY_SELECTED_SINGLE &&
2217             (item &&
2218              (folder_has_parent_of_type(item, F_DRAFT) ||
2219               folder_has_parent_of_type(item, F_OUTBOX) ||
2220               folder_has_parent_of_type(item, F_QUEUE))))
2221                 state |= M_ALLOW_REEDIT;
2222         if (cur_account)
2223                 state |= M_HAVE_ACCOUNT;
2224         
2225         if (any_folder_want_synchronise())
2226                 state |= M_WANT_SYNC;
2227
2228         for ( ; account_list != NULL; account_list = account_list->next) {
2229                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2230                         state |= M_HAVE_NEWS_ACCOUNT;
2231                         break;
2232                 }
2233         }
2234         
2235         if (procmsg_spam_can_learn() &&
2236             (mainwin->summaryview->folder_item &&
2237              mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2238              mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2239                 state |= M_CAN_LEARN_SPAM;
2240         }
2241
2242         if (inc_is_active())
2243                 state |= M_INC_ACTIVE;
2244         if (imap_cancel_all_enabled())
2245                 state |= M_INC_ACTIVE;
2246
2247         if (mainwin->summaryview->deleted > 0 ||
2248             mainwin->summaryview->moved > 0 ||
2249             mainwin->summaryview->copied > 0)
2250                 state |= M_DELAY_EXEC;
2251
2252         return state;
2253 }
2254
2255
2256
2257 void main_window_set_menu_sensitive(MainWindow *mainwin)
2258 {
2259         GtkItemFactory *ifactory = mainwin->menu_factory;
2260         SensitiveCond state;
2261         gboolean sensitive;
2262         GtkWidget *menu;
2263         GtkWidget *menuitem;
2264         SummaryView *summaryview;
2265         gchar *menu_path;
2266         gint i;
2267         GList *cur_item;
2268
2269         static const struct {
2270                 gchar *const entry;
2271                 SensitiveCond cond;
2272         } entry[] = {
2273                 {"/File/Save as...", M_TARGET_EXIST},
2274                 {"/File/Print..."  , M_TARGET_EXIST},
2275                 {"/File/Synchronise folders", M_WANT_SYNC},
2276                 {"/File/Exit"      , M_UNLOCKED},
2277
2278                 {"/Edit/Select thread"             , M_TARGET_EXIST},
2279                 {"/Edit/Delete thread"             , M_TARGET_EXIST},
2280                 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2281
2282                 {"/View/Set displayed columns/in Folder list..."
2283                                                    , M_UNLOCKED}, 
2284                 {"/View/Sort"                      , M_EXEC},
2285                 {"/View/Thread view"               , M_EXEC},
2286                 {"/View/Expand all threads"        , M_MSG_EXIST},
2287                 {"/View/Collapse all threads"      , M_MSG_EXIST},
2288                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
2289                 {"/View/Go to/Previous message"        , M_MSG_EXIST},
2290                 {"/View/Go to/Next message"        , M_MSG_EXIST},
2291                 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2292                 {"/View/Go to/Previous new message"    , M_MSG_EXIST},
2293                 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2294                 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2295                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2296                 {"/View/Go to/Last read message"   , M_SINGLE_TARGET_EXIST},
2297                 {"/View/Go to/Parent message"      , M_SINGLE_TARGET_EXIST},
2298                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
2299                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
2300                 {"/View/All headers"               , M_SINGLE_TARGET_EXIST},
2301                 {"/View/Quotes"                    , M_SINGLE_TARGET_EXIST},
2302
2303                 {"/Message/Receive/Get from current account"
2304                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2305                 {"/Message/Receive/Get from all accounts"
2306                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2307                 {"/Message/Receive/Cancel receiving"
2308                                                  , M_INC_ACTIVE},
2309                 {"/Message/Send queued messages"  , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2310                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2311                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2312                 {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2313                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2314                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2315                 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2316                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2317                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE},
2318                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC},
2319                 {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2320                 {"/Message/Delete..."             , M_TARGET_EXIST|M_ALLOW_DELETE},
2321                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2322                 {"/Message/Mark"                  , M_TARGET_EXIST},
2323                 {"/Message/Mark/Mark as spam"     , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2324                 {"/Message/Mark/Mark as ham"      , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2325                 {"/Message/Mark/Ignore thread"    , M_TARGET_EXIST},
2326                 {"/Message/Mark/Unignore thread"  , M_TARGET_EXIST},
2327                 {"/Message/Mark/Lock"             , M_TARGET_EXIST},
2328                 {"/Message/Mark/Unlock"           , M_TARGET_EXIST},
2329                 {"/Message/Color label"           , M_TARGET_EXIST},
2330                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2331
2332                 {"/Tools/Add sender to address book"   , M_SINGLE_TARGET_EXIST},
2333                 {"/Tools/Harvest addresses"            , M_MSG_EXIST},
2334                 {"/Tools/Harvest addresses/from Messages..."
2335                                                        , M_TARGET_EXIST},
2336                 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2337                 {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
2338                 {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2339                 {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2340                 {"/Tools/List URLs..."                 , M_TARGET_EXIST},
2341                 {"/Tools/Actions"                      , M_TARGET_EXIST|M_ACTIONS_EXIST},
2342                 {"/Tools/Execute"                      , M_DELAY_EXEC},
2343                 {"/Tools/Delete duplicated messages/In selected folder"   , M_MSG_EXIST|M_ALLOW_DELETE},
2344
2345                 {"/Configuration", M_UNLOCKED},
2346                 {"/Configuration/Preferences for current account...", M_UNLOCKED},
2347                 {"/Configuration/Create new account...", M_UNLOCKED},
2348                 {"/Configuration/Edit accounts...", M_UNLOCKED},
2349
2350                 {NULL, 0}
2351         };
2352
2353         state = main_window_get_current_state(mainwin);
2354
2355         for (i = 0; entry[i].entry != NULL; i++) {
2356                 sensitive = ((entry[i].cond & state) == entry[i].cond);
2357                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2358         }
2359
2360         menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2361
2362         /* search for separator */
2363         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2364              cur_item = cur_item->next) {
2365                 if (GTK_BIN(cur_item->data)->child == NULL) {
2366                         cur_item = cur_item->next;
2367                         break;
2368                 }
2369         }
2370
2371         for (; cur_item != NULL; cur_item = cur_item->next) {
2372                 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2373                                          (M_UNLOCKED & state) != 0);
2374         }
2375
2376         main_window_menu_callback_block(mainwin);
2377
2378 #define SET_CHECK_MENU_ACTIVE(path, active) \
2379 { \
2380         menuitem = gtk_item_factory_get_widget(ifactory, path); \
2381         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2382 }
2383
2384         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2385                               messageview_is_visible(mainwin->messageview));
2386
2387         summaryview = mainwin->summaryview;
2388         menu_path = "/View/Sort/Don't sort";
2389
2390         switch (summaryview->sort_key) {
2391         case SORT_BY_NUMBER:
2392                 menu_path = "/View/Sort/by number"; break;
2393         case SORT_BY_SIZE:
2394                 menu_path = "/View/Sort/by Size"; break;
2395         case SORT_BY_DATE:
2396                 menu_path = "/View/Sort/by Date"; break;
2397         case SORT_BY_FROM:
2398                 menu_path = "/View/Sort/by From"; break;
2399         case SORT_BY_TO:
2400                 menu_path = "/View/Sort/by To"; break;
2401         case SORT_BY_SUBJECT:
2402                 menu_path = "/View/Sort/by Subject"; break;
2403         case SORT_BY_LABEL:
2404                 menu_path = "/View/Sort/by color label"; break;
2405         case SORT_BY_MARK:
2406                 menu_path = "/View/Sort/by mark"; break;
2407         case SORT_BY_STATUS:
2408                 menu_path = "/View/Sort/by status"; break;
2409         case SORT_BY_MIME:
2410                 menu_path = "/View/Sort/by attachment"; break;
2411         case SORT_BY_SCORE:
2412                 menu_path = "/View/Sort/by score"; break;
2413         case SORT_BY_LOCKED:
2414                 menu_path = "/View/Sort/by locked"; break;
2415         case SORT_BY_NONE:
2416         default:
2417                 menu_path = "/View/Sort/Don't sort"; break;
2418         }
2419         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2420
2421         if (summaryview->sort_type == SORT_ASCENDING) {
2422                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2423         } else {
2424                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2425         }
2426
2427         if (summaryview->sort_key != SORT_BY_NONE) {
2428                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2429                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2430         } else {
2431                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2432                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2433         }
2434
2435         if (mainwin->messageview 
2436         &&  mainwin->messageview->mimeview
2437         &&  mainwin->messageview->mimeview->textview)
2438                 SET_CHECK_MENU_ACTIVE("/View/All headers",
2439                               mainwin->messageview->mimeview->textview->show_all_headers);
2440         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2441         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2442         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2443         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2444         if (prefs_common.hide_quotes == 1)
2445                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2446         if (prefs_common.hide_quotes == 2)
2447                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2448         if (prefs_common.hide_quotes == 3)
2449                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2450
2451 #undef SET_CHECK_MENU_ACTIVE
2452
2453         main_window_menu_callback_unblock(mainwin);
2454 }
2455
2456 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2457 {
2458         GtkItemFactory *ifactory;
2459         gint is_menu = 0;
2460         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2461         
2462         if (msginfo) 
2463                 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2464         if (is_menu)
2465                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2466                                 (ifactory,"/Message/Mailing-List"), TRUE);
2467         else
2468                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2469                                 (ifactory,"/Message/Mailing-List"), FALSE);
2470 }
2471
2472 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2473 {
2474         gint menu_nb = 0;
2475         GtkWidget *menuitem;
2476         
2477         if (!msginfo || !msginfo->extradata) {
2478                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2479                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2480                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2481                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2482                 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2483                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2484                 return 0;
2485         }
2486                 
2487         /* Mailing list post */
2488         if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2489                 g_free(msginfo->extradata->list_post);
2490                 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2491         }
2492         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2493                 
2494         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2495  
2496         /* Mailing list help */
2497         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2498         
2499         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2500
2501         /* Mailing list subscribe */
2502         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2503         
2504         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2505                 
2506         /* Mailing list unsubscribe */
2507         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2508         
2509         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2510         
2511         /* Mailing list view archive */
2512         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2513         
2514         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2515         
2516         /* Mailing list contact owner */
2517         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2518         
2519         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2520         
2521         return menu_nb;
2522 }
2523
2524 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2525 {
2526         GtkWidget *item, *menu;
2527         const gchar *url_pt ;
2528         gchar url_decoded[BUFFSIZE];
2529         GList *amenu, *alist;
2530         gint menu_nb = 0;
2531         
2532         menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2533         
2534         /* First delete old submenu */
2535         /* FIXME: we can optimize this, and only change/add/delete necessary items */
2536         for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2537                 alist = amenu->next;
2538                 item = GTK_WIDGET (amenu->data);
2539                 gtk_widget_destroy (item);
2540                 amenu = alist;
2541         }
2542         if (list_header) {
2543                 for (url_pt = list_header; url_pt && *url_pt;) {
2544                         get_url_part (&url_pt, url_decoded, BUFFSIZE);
2545                         item = NULL;
2546                         if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2547                                 item = gtk_menu_item_new_with_label ((url_decoded));
2548                                 g_signal_connect(G_OBJECT(item), "activate",
2549                                                  G_CALLBACK(mailing_list_compose),
2550                                                  NULL);
2551                         }
2552                         else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2553                                  !g_strncasecmp (url_decoded, "https:",6)) {
2554
2555                                 item = gtk_menu_item_new_with_label ((url_decoded));
2556                                 g_signal_connect(G_OBJECT(item), "activate",
2557                                                  G_CALLBACK(mailing_list_open_uri),
2558                                                  NULL);
2559                         } 
2560                         if (item) {
2561                                 gtk_menu_append (GTK_MENU(menu), item);
2562                                 gtk_widget_show (item);
2563                                 menu_nb++;
2564                         }
2565                 }
2566         }
2567         if (menu_nb)
2568                 gtk_widget_set_sensitive (menuitem, TRUE);
2569         else
2570                 gtk_widget_set_sensitive (menuitem, FALSE);
2571                 
2572
2573         return menu_nb;
2574 }
2575
2576 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2577 {
2578         gchar tmp[BUFFSIZE];
2579         const gchar *buf;
2580         gint i = 0;
2581         buf = *buffer;
2582         gboolean with_plus = TRUE;
2583
2584         if (buf == 0x00) {
2585                 *url_decoded = '\0';
2586                 *buffer = NULL;
2587                 return;
2588         }
2589         /* Ignore spaces, comments  and tabs () */
2590         for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2591                 if (*buf == '(')
2592                         for (;*buf != ')' && *buf != 0x00; buf++);
2593         
2594         /* First non space and non comment must be a < */
2595         if (*buf =='<' ) {
2596                 buf++;
2597                 if (!strncmp(buf, "mailto:", strlen("mailto:")))
2598                         with_plus = FALSE;
2599                 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2600                 buf++;
2601         }
2602         else  {
2603                 *buffer = NULL;
2604                 *url_decoded = '\0';
2605                 return;
2606         }
2607         
2608         tmp[i]       = 0x00;
2609         *url_decoded = '\0';
2610         *buffer = NULL;
2611         
2612         if (i == maxlen) {
2613                 return;
2614         }
2615         decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
2616
2617         /* Prepare the work for the next url in the list */
2618         /* after the closing bracket >, ignore space, comments and tabs */
2619         for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2620                 if (*buf == '(')
2621                         for (;*buf != ')' && *buf != 0x00; buf++);
2622                         
2623         if (!buf || !*buf) {
2624                 *buffer = NULL;
2625                 return;
2626         }
2627
2628         /* now first non space, non comment must be a comma */
2629         if (*buf != ',')
2630                 for (;*buf != 0x00; buf++);
2631         else
2632                 buf++;
2633         *buffer = buf;
2634 }
2635         
2636 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2637 {
2638         gchar *mailto;
2639
2640         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2641         compose_new(NULL, mailto+7, NULL);
2642 }
2643  
2644  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2645 {
2646  
2647         gchar *mailto;
2648  
2649         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2650         open_uri (mailto, prefs_common.uri_cmd);
2651
2652         
2653 void main_window_popup(MainWindow *mainwin)
2654 {
2655         if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
2656                 main_window_show(mainwin);
2657
2658         gtkut_window_popup(mainwin->window);
2659         if (prefs_common.layout_mode == SMALL_LAYOUT) {
2660                 if (mainwin->in_folder) {
2661                         mainwindow_enter_folder(mainwin);
2662                 } else {
2663                         mainwindow_exit_folder(mainwin);
2664                 }
2665         }
2666 }
2667
2668 void main_window_show(MainWindow *mainwin)
2669 {
2670         gtk_widget_show(mainwin->window);
2671         gtk_widget_show(mainwin->vbox_body);
2672
2673         gtk_widget_set_uposition(mainwin->window,
2674                                  prefs_common.mainwin_x,
2675                                  prefs_common.mainwin_y);
2676
2677         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2678                              prefs_common.folderview_width,
2679                              prefs_common.folderview_height);
2680         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2681                              prefs_common.summaryview_width,
2682                              prefs_common.summaryview_height);
2683         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2684                              prefs_common.msgview_width,
2685                              prefs_common.msgview_height);
2686 }
2687
2688 void main_window_hide(MainWindow *mainwin)
2689 {
2690         main_window_get_size(mainwin);
2691         main_window_get_position(mainwin);
2692
2693         gtk_widget_hide(mainwin->window);
2694         gtk_widget_hide(mainwin->vbox_body);
2695 }
2696
2697 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
2698 {
2699         GtkWidget *folderwin = NULL;
2700         GtkWidget *messagewin = NULL;
2701         GtkWidget *hpaned;
2702         GtkWidget *vpaned;
2703         GtkWidget *vbox_body = mainwin->vbox_body;
2704         GtkItemFactory *ifactory = mainwin->menu_factory;
2705         GtkWidget *menuitem;
2706         gboolean first_set = (mainwin->hpaned == NULL);
2707         debug_print("Setting widgets... ");
2708
2709         if (layout_mode == SMALL_LAYOUT && first_set) {
2710                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2711                                     prefs_common.folderview_width,
2712                                     prefs_common.folderview_height);
2713                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2714                                     0,0);
2715                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2716                                     0,0);
2717         } else {
2718                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2719                                     prefs_common.folderview_width,
2720                                     prefs_common.folderview_height);
2721                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2722                                     prefs_common.summaryview_width,
2723                                     prefs_common.summaryview_height);
2724                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2725                                     prefs_common.msgview_width,
2726                                     prefs_common.msgview_height);
2727         }
2728
2729         mainwin->messageview->statusbar = mainwin->statusbar;
2730         mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2731
2732         /* clean top-most container */
2733         if (mainwin->hpaned) {
2734                 if (mainwin->hpaned->parent == mainwin->vpaned)
2735                         gtk_widget_destroy(mainwin->vpaned);
2736                 else
2737                         gtk_widget_destroy(mainwin->hpaned);
2738         }
2739
2740         menu_set_sensitive(ifactory, "/View/Show or hide/Message view", 
2741                 (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
2742         switch (layout_mode) {
2743         case VERTICAL_LAYOUT:
2744         case NORMAL_LAYOUT:
2745         case SMALL_LAYOUT:
2746                 hpaned = gtk_hpaned_new();
2747                 if (layout_mode == VERTICAL_LAYOUT)
2748                         vpaned = gtk_hpaned_new();
2749                 else
2750                         vpaned = gtk_vpaned_new();
2751                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2752                 gtk_paned_add1(GTK_PANED(hpaned),
2753                                GTK_WIDGET_PTR(mainwin->folderview));
2754                 gtk_widget_show(hpaned);
2755                 gtk_widget_queue_resize(hpaned);
2756
2757                 if (messageview_is_visible(mainwin->messageview)) {
2758                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
2759                         gtk_paned_add1(GTK_PANED(vpaned),
2760                                        GTK_WIDGET_PTR(mainwin->summaryview));
2761                 } else {
2762                         gtk_paned_add2(GTK_PANED(hpaned),
2763                                        GTK_WIDGET_PTR(mainwin->summaryview));
2764                         gtk_widget_ref(vpaned);
2765                 }
2766                 gtk_paned_add2(GTK_PANED(vpaned),
2767                                GTK_WIDGET_PTR(mainwin->messageview));
2768                 gtk_widget_show(vpaned);
2769                 if (layout_mode == SMALL_LAYOUT && first_set) {
2770                         mainwin_paned_show_first(GTK_PANED(hpaned));
2771                 }
2772                 gtk_widget_queue_resize(vpaned);
2773                 break;
2774         case WIDE_LAYOUT:
2775                 vpaned = gtk_vpaned_new();
2776                 hpaned = gtk_hpaned_new();
2777                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
2778                 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
2779
2780                 gtk_paned_add1(GTK_PANED(hpaned),
2781                                GTK_WIDGET_PTR(mainwin->folderview));
2782                 gtk_paned_add2(GTK_PANED(hpaned),
2783                                GTK_WIDGET_PTR(mainwin->summaryview));
2784
2785                 gtk_widget_show(hpaned);
2786                 gtk_widget_queue_resize(hpaned);
2787
2788                 if (messageview_is_visible(mainwin->messageview)) {
2789                         gtk_paned_add2(GTK_PANED(vpaned),
2790                                GTK_WIDGET_PTR(mainwin->messageview));   
2791                 } else {
2792                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
2793                 }
2794                 gtk_widget_show(vpaned);
2795                 gtk_widget_queue_resize(vpaned);
2796                 break;
2797         case WIDE_MSGLIST_LAYOUT:
2798                 vpaned = gtk_vpaned_new();
2799                 hpaned = gtk_hpaned_new();
2800                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
2801
2802                 gtk_paned_add1(GTK_PANED(vpaned),
2803                                GTK_WIDGET_PTR(mainwin->summaryview));
2804                 gtk_paned_add1(GTK_PANED(hpaned),
2805                                GTK_WIDGET_PTR(mainwin->folderview));
2806
2807                 gtk_widget_show(hpaned);
2808                 gtk_widget_queue_resize(hpaned);
2809
2810                 if (messageview_is_visible(mainwin->messageview)) {
2811                         gtk_paned_add2(GTK_PANED(hpaned),
2812                                GTK_WIDGET_PTR(mainwin->messageview));   
2813                 } else {
2814                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
2815                 }
2816                 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
2817
2818                 gtk_widget_show(vpaned);
2819                 gtk_widget_queue_resize(vpaned);
2820                 break;
2821         default:
2822                 g_warning("Unknown layout");
2823                 return;
2824         }
2825
2826         mainwin->hpaned = hpaned;
2827         mainwin->vpaned = vpaned;
2828
2829         if (layout_mode == SMALL_LAYOUT) {
2830                 if (mainwin->messageview->visible)
2831                         main_window_toggle_message_view(mainwin);
2832         } 
2833
2834         if (layout_mode == SMALL_LAYOUT && first_set) {
2835                 gtk_widget_realize(mainwin->window);
2836                 gtk_widget_realize(mainwin->folderview->ctree);
2837                 gtk_widget_realize(mainwin->summaryview->hbox);
2838                 gtk_widget_realize(mainwin->summaryview->hbox_l);
2839                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2840                                     prefs_common.folderview_width,
2841                                     prefs_common.folderview_height);
2842                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2843                                     0,0);
2844                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2845                                     0,0);
2846                 gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
2847                                 prefs_common.mainwin_width,
2848                                 prefs_common.mainwin_height);
2849                 gtk_paned_set_position(GTK_PANED(mainwin->hpaned), 800);
2850         } 
2851         /* remove headerview if not in prefs */
2852         headerview_set_visibility(mainwin->messageview->headerview,
2853                                   prefs_common.display_header_pane);
2854
2855         if (messageview_is_visible(mainwin->messageview))
2856                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2857                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2858         else
2859                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2860                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2861
2862         gtk_window_move(GTK_WINDOW(mainwin->window),
2863                         prefs_common.mainwin_x,
2864                         prefs_common.mainwin_y);
2865
2866         gtk_widget_queue_resize(vbox_body);
2867         gtk_widget_queue_resize(mainwin->vbox);
2868         gtk_widget_queue_resize(mainwin->window);
2869         /* CLAWS: previous "gtk_widget_show_all" makes noticeview
2870          * and mimeview icon list/ctree lose track of their visibility states */
2871         if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
2872                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
2873         if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview)) 
2874                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
2875         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
2876                 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
2877         else 
2878                 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
2879
2880         prefs_common.layout_mode = layout_mode;
2881
2882         menuitem = gtk_item_factory_get_item
2883                 (ifactory, "/View/Show or hide/Message view");
2884         gtk_check_menu_item_set_active
2885                 (GTK_CHECK_MENU_ITEM(menuitem),
2886                  messageview_is_visible(mainwin->messageview));
2887
2888 #define SET_CHECK_MENU_ACTIVE(path, active) \
2889 { \
2890         menuitem = gtk_item_factory_get_widget(ifactory, path); \
2891         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2892 }
2893
2894         switch (prefs_common.layout_mode) {
2895         case NORMAL_LAYOUT:
2896                 SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
2897                 break;
2898         case VERTICAL_LAYOUT:
2899                 SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
2900                 break;
2901         case WIDE_LAYOUT:
2902                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
2903                 break;
2904         case WIDE_MSGLIST_LAYOUT:
2905                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
2906                 break;
2907         case SMALL_LAYOUT:
2908                 SET_CHECK_MENU_ACTIVE("/View/Layout/Small screen", TRUE);
2909                 break;
2910         }
2911 #undef SET_CHECK_MENU_ACTIVE
2912
2913         if (folderwin) {
2914                 g_signal_connect
2915                         (G_OBJECT(folderwin), "size_allocate",
2916                          G_CALLBACK(folder_window_size_allocate_cb),
2917                          mainwin);
2918         }
2919         if (messagewin) {
2920                 g_signal_connect
2921                         (G_OBJECT(messagewin), "size_allocate",
2922                          G_CALLBACK(message_window_size_allocate_cb),
2923                          mainwin);
2924         }
2925
2926         debug_print("done.\n");
2927 }
2928
2929 void main_window_destroy_all(void)
2930 {
2931         while (mainwin_list != NULL) {
2932                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
2933                 
2934                 /* free toolbar stuff */
2935                 toolbar_clear_list(TOOLBAR_MAIN);
2936                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2937                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
2938
2939                 mainwin->folderview->mainwin = NULL;
2940                 mainwin->summaryview->mainwin = NULL;
2941                 mainwin->messageview->mainwin = NULL;
2942
2943                 g_free(mainwin->toolbar);
2944                 g_free(mainwin);
2945                 
2946                 mainwin_list = g_list_remove(mainwin_list, mainwin);
2947         }
2948         g_list_free(mainwin_list);
2949         mainwin_list = NULL;
2950 }
2951
2952 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
2953                                    gpointer data)
2954 {
2955         gtk_widget_set_size_request(child, 1, -1);
2956 }
2957
2958 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
2959                                    gpointer data)
2960 {
2961         gtk_widget_set_size_request(child, -1, -1);
2962 }
2963
2964 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2965                                     gpointer data)
2966 {
2967         MainWindow *mainwin = (MainWindow *)data;
2968
2969         if (!event) return FALSE;
2970
2971         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2972         g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
2973                           widget);
2974
2975         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2976                        menu_button_position, widget,
2977                        event->button, event->time);
2978
2979         return TRUE;
2980 }
2981
2982 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2983                                  gpointer data)
2984 {
2985         MainWindow *mainwin = (MainWindow *)data;
2986         gboolean close_allowed = TRUE;
2987
2988         hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
2989
2990         if (close_allowed && mainwin->lock_count == 0)
2991                 app_exit_cb(data, 0, widget);
2992
2993         return TRUE;
2994 }
2995
2996 static void main_window_size_allocate_cb(GtkWidget *widget,
2997                                          GtkAllocation *allocation,
2998                                          gpointer data)
2999 {
3000         MainWindow *mainwin = (MainWindow *)data;
3001         main_window_get_size(mainwin);
3002 }
3003
3004 static void folder_window_size_allocate_cb(GtkWidget *widget,
3005                                            GtkAllocation *allocation,
3006                                            gpointer data)
3007 {
3008         MainWindow *mainwin = (MainWindow *)data;
3009
3010         main_window_get_size(mainwin);
3011 }
3012
3013 static void message_window_size_allocate_cb(GtkWidget *widget,
3014                                             GtkAllocation *allocation,
3015                                             gpointer data)
3016 {
3017         MainWindow *mainwin = (MainWindow *)data;
3018
3019         main_window_get_size(mainwin);
3020 }
3021
3022 static void add_mailbox_cb(MainWindow *mainwin, guint action,
3023                            GtkWidget *widget)
3024 {
3025         main_window_add_mailbox(mainwin);
3026 }
3027
3028 static void update_folderview_cb(MainWindow *mainwin, guint action,
3029                                  GtkWidget *widget)
3030 {
3031         summary_show(mainwin->summaryview, NULL);
3032         folderview_check_new_all();
3033 }
3034
3035 static void foldersort_cb(MainWindow *mainwin, guint action,
3036                            GtkWidget *widget)
3037 {
3038         foldersort_open();
3039 }
3040
3041 static void import_mbox_cb(MainWindow *mainwin, guint action,
3042                            GtkWidget *widget)
3043 {
3044         /* only notify if import has failed */
3045         if (import_mbox(mainwin->summaryview->folder_item) == -1) {
3046                 alertpanel_error(_("Mbox import has failed."));
3047         }
3048 }
3049
3050 static void export_mbox_cb(MainWindow *mainwin, guint action,
3051                            GtkWidget *widget)
3052 {
3053         /* only notify if export has failed */
3054         if (export_mbox(mainwin->summaryview->folder_item) == -1) {
3055                 alertpanel_error(_("Export to mbox has failed."));
3056         }
3057 }
3058
3059 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
3060                                 GtkWidget *widget)
3061 {
3062         /* only notify if export has failed */
3063         if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
3064                 alertpanel_error(_("Export to mbox has failed."));
3065         }
3066 }
3067
3068 static void empty_trash_cb(MainWindow *mainwin, guint action,
3069                            GtkWidget *widget)
3070 {
3071         main_window_empty_trash(mainwin, TRUE);
3072 }
3073
3074 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3075 {
3076         summary_save_as(mainwin->summaryview);
3077 }
3078
3079 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3080 {
3081         summary_print(mainwin->summaryview);
3082 }
3083
3084 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3085 {
3086         if (prefs_common.confirm_on_exit) {
3087                 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
3088                                GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
3089                     != G_ALERTALTERNATE)
3090                         return;
3091                 manage_window_focus_in(mainwin->window, NULL, NULL);
3092         }
3093
3094         app_will_exit(widget, mainwin);
3095 }
3096
3097 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3098 {
3099         if (action == 1)
3100                 summary_search(mainwin->summaryview);
3101         else
3102                 message_search(mainwin->messageview);
3103 }
3104
3105 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3106 {
3107         summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
3108 }
3109
3110 static void toggle_message_cb(MainWindow *mainwin, guint action,
3111                               GtkWidget *widget)
3112 {
3113         gboolean active;
3114
3115         active = GTK_CHECK_MENU_ITEM(widget)->active;
3116
3117         if (active != messageview_is_visible(mainwin->messageview))
3118                 summary_toggle_view(mainwin->summaryview);
3119 }
3120
3121 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3122                               GtkWidget *widget)
3123 {
3124         toolbar_toggle(action, mainwin);
3125 }
3126
3127 static void main_window_reply_cb(MainWindow *mainwin, guint action,
3128                           GtkWidget *widget)
3129 {
3130         MessageView *msgview = (MessageView*)mainwin->messageview;
3131         GSList *msginfo_list = NULL;
3132
3133         g_return_if_fail(msgview != NULL);
3134
3135         msginfo_list = summary_get_selection(mainwin->summaryview);
3136         g_return_if_fail(msginfo_list != NULL);
3137         compose_reply_from_messageview(msgview, msginfo_list, action);
3138         g_slist_free(msginfo_list);
3139 }
3140
3141
3142 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3143                                 GtkWidget *widget)
3144 {
3145         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3146                 gtk_widget_show(mainwin->hbox_stat);
3147                 prefs_common.show_statusbar = TRUE;
3148         } else {
3149                 gtk_widget_hide(mainwin->hbox_stat);
3150                 prefs_common.show_statusbar = FALSE;
3151         }
3152 }
3153
3154 static void set_layout_cb(MainWindow *mainwin, guint action,
3155                                GtkWidget *widget)
3156 {
3157         LayoutType layout_mode = action;
3158         LayoutType old_layout_mode = prefs_common.layout_mode;
3159         if (mainwin->menu_lock_count) {
3160                 return;
3161         }
3162         if (!GTK_CHECK_MENU_ITEM(widget)->active) {
3163                 return;
3164         }
3165         
3166         if (layout_mode == prefs_common.layout_mode) {
3167                 return;
3168         }
3169         
3170         if (!mainwin->messageview->visible && layout_mode != SMALL_LAYOUT)
3171                 main_window_toggle_message_view(mainwin);
3172         else if (mainwin->messageview->visible && layout_mode == SMALL_LAYOUT)
3173                 main_window_toggle_message_view(mainwin);
3174
3175         main_window_separation_change(mainwin, layout_mode);
3176         mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
3177         if (old_layout_mode == SMALL_LAYOUT && layout_mode != SMALL_LAYOUT) {
3178                 mainwindow_reset_paned(GTK_PANED(mainwin->hpaned));
3179         }
3180         if (old_layout_mode != SMALL_LAYOUT && layout_mode == SMALL_LAYOUT) {
3181                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
3182                 mainwindow_exit_folder(mainwin);
3183         }
3184         summary_relayout(mainwin->summaryview); 
3185         summary_update_unread(mainwin->summaryview, NULL);
3186 }
3187
3188 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3189                                         gboolean ask_sync)
3190 {
3191         offline_ask_sync = ask_sync;
3192         if (offline)
3193                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3194         else
3195                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3196         offline_ask_sync = TRUE;
3197 }
3198
3199 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3200 {
3201         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3202 }
3203
3204 static gboolean any_folder_want_synchronise(void)
3205 {
3206         GList *folderlist = folder_get_list();
3207
3208         /* see if there are synchronised folders */
3209         for (; folderlist; folderlist = folderlist->next) {
3210                 Folder *folder = (Folder *)folderlist->data;
3211                 if (folder_want_synchronise(folder)) {
3212                         return TRUE;
3213                 }
3214         }
3215         
3216         return FALSE;
3217 }
3218
3219 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3220 {
3221         
3222         if (!any_folder_want_synchronise())
3223                 return;
3224
3225         if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3226                         _("Do you want to synchronise your folders now?"),
3227                         GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3228                 return;
3229         
3230         if (offline_ask_sync)
3231                 folder_synchronise(NULL);
3232 }
3233
3234 static void online_switch_clicked (GtkButton *btn, gpointer data) 
3235 {
3236         MainWindow *mainwin;
3237         GtkItemFactory *ifactory;
3238         GtkCheckMenuItem *menuitem;
3239
3240         mainwin = (MainWindow *) data;
3241         
3242         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3243         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3244         
3245         g_return_if_fail(mainwin != NULL);
3246         g_return_if_fail(menuitem != NULL);
3247         
3248         if (btn == GTK_BUTTON(mainwin->online_switch)) {
3249                 gtk_widget_hide (mainwin->online_switch);
3250                 gtk_widget_show (mainwin->offline_switch);
3251                 menuitem->active = TRUE;
3252                 inc_autocheck_timer_remove();
3253                         
3254                 /* go offline */
3255                 if (prefs_common.work_offline)
3256                         return;
3257                 mainwindow_check_synchronise(mainwin, TRUE);
3258                 prefs_common.work_offline = TRUE;
3259                 imap_disconnect_all();
3260                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3261         } else {
3262                 /*go online */
3263                 if (!prefs_common.work_offline)
3264                         return;
3265                 gtk_widget_hide (mainwin->offline_switch);
3266                 gtk_widget_show (mainwin->online_switch);
3267                 menuitem->active = FALSE;
3268                 prefs_common.work_offline = FALSE;
3269                 inc_autocheck_timer_set();
3270                 refresh_resolvers();
3271                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3272         }
3273 }
3274
3275 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3276                                 GtkWidget *widget)
3277 {
3278         addressbook_open(NULL);
3279 }
3280
3281 static void log_window_show_cb(MainWindow *mainwin, guint action,
3282                                GtkWidget *widget)
3283 {
3284         log_window_show(mainwin->logwin);
3285 }
3286
3287 static void filtering_debug_window_show_cb(MainWindow *mainwin, guint action,
3288                                GtkWidget *widget)
3289 {
3290         log_window_show(mainwin->filtering_debugwin);
3291 }
3292
3293 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3294 {
3295         inc_cancel_all();
3296         imap_cancel_all();
3297 }
3298
3299 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3300 {
3301         summary_move_to(mainwin->summaryview);
3302 }
3303
3304 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3305 {
3306         summary_copy_to(mainwin->summaryview);
3307 }
3308
3309 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3310 {
3311         summary_delete(mainwin->summaryview);
3312 }
3313
3314 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3315 {
3316         summary_delete_trash(mainwin->summaryview);
3317 }
3318
3319 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3320 {
3321         summary_cancel(mainwin->summaryview);
3322 }
3323
3324 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3325 {
3326         summary_open_msg(mainwin->summaryview);
3327 }
3328
3329 static void view_source_cb(MainWindow *mainwin, guint action,
3330                            GtkWidget *widget)
3331 {
3332         summary_view_source(mainwin->summaryview);
3333 }
3334
3335 static void show_all_header_cb(MainWindow *mainwin, guint action,
3336                                GtkWidget *widget)
3337 {
3338         if (mainwin->menu_lock_count) return;
3339         mainwin->summaryview->messageview->all_headers = 
3340                         GTK_CHECK_MENU_ITEM(widget)->active;
3341         summary_display_msg_selected(mainwin->summaryview,
3342                                      GTK_CHECK_MENU_ITEM(widget)->active);
3343 }
3344
3345 #define SET_CHECK_MENU_ACTIVE(path, active) \
3346 { \
3347         menuitem = gtk_item_factory_get_widget(ifactory, path); \
3348         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3349 }
3350
3351 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3352                                GtkWidget *widget)
3353 {
3354         GtkWidget *menuitem;
3355         GtkItemFactory *ifactory = mainwin->menu_factory;
3356
3357         if (mainwin->menu_lock_count) return;
3358
3359         prefs_common.hide_quotes = 
3360                         GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3361
3362         mainwin->menu_lock_count++;
3363         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3364         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3365         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3366         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3367         mainwin->menu_lock_count--;
3368
3369         summary_redisplay_msg(mainwin->summaryview);
3370 }
3371
3372 #undef SET_CHECK_MENU_ACTIVE
3373 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3374 {
3375         summary_mark(mainwin->summaryview);
3376 }
3377
3378 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3379 {
3380         summary_unmark(mainwin->summaryview);
3381 }
3382
3383 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3384                               GtkWidget *widget)
3385 {
3386         summary_mark_as_unread(mainwin->summaryview);
3387 }
3388
3389 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3390                             GtkWidget *widget)
3391 {
3392         summary_mark_as_read(mainwin->summaryview);
3393 }
3394
3395 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3396                              GtkWidget *widget)
3397 {
3398         summary_mark_all_read(mainwin->summaryview);
3399 }
3400
3401 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3402                              GtkWidget *widget)
3403 {
3404         summary_mark_as_spam(mainwin->summaryview, action, NULL);
3405 }
3406
3407 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3408                             GtkWidget *widget)
3409 {
3410         summary_ignore_thread(mainwin->summaryview);
3411 }
3412
3413 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3414                             GtkWidget *widget)
3415 {
3416         summary_unignore_thread(mainwin->summaryview);
3417 }
3418
3419 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3420                             GtkWidget *widget)
3421 {
3422         summary_msgs_lock(mainwin->summaryview);
3423 }
3424
3425 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3426                             GtkWidget *widget)
3427 {
3428         summary_msgs_unlock(mainwin->summaryview);
3429 }
3430
3431
3432 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3433 {
3434         summary_reedit(mainwin->summaryview);
3435 }
3436
3437 static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3438 {
3439         if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
3440                 summary_display_msg_selected(mainwin->summaryview, 
3441                         mainwin->messageview->mimeview->textview->show_all_headers);
3442         }
3443         messageview_list_urls(mainwin->messageview);
3444 }
3445
3446 static void add_address_cb(MainWindow *mainwin, guint action,
3447                            GtkWidget *widget)
3448 {
3449         summary_add_address(mainwin->summaryview);
3450 }
3451
3452 static void set_charset_cb(MainWindow *mainwin, guint action,
3453                            GtkWidget *widget)
3454 {
3455         const gchar *str;
3456
3457         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3458                 str = conv_get_charset_str((CharSet)action);
3459                 
3460                 g_free(mainwin->messageview->forced_charset);
3461                 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3462                 procmime_force_charset(str);
3463                 
3464                 summary_redisplay_msg(mainwin->summaryview);
3465                 
3466                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3467         }
3468 }
3469
3470 static void set_decode_cb(MainWindow *mainwin, guint action,
3471                            GtkWidget *widget)
3472 {
3473         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3474                 mainwin->messageview->forced_encoding = (EncodingType)action;
3475                 
3476                 summary_redisplay_msg(mainwin->summaryview);
3477                 
3478                 debug_print("forced encoding: %d\n", action);
3479         }
3480 }
3481
3482 static void hide_read_messages (MainWindow *mainwin, guint action,
3483                                 GtkWidget *widget)
3484 {
3485         if (!mainwin->summaryview->folder_item
3486             || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3487                 return;
3488         summary_toggle_show_read_messages(mainwin->summaryview);
3489 }
3490
3491 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3492 {
3493         gboolean threaded = FALSE;
3494         if (mainwin->menu_lock_count) return;
3495         if (!mainwin->summaryview->folder_item) return;
3496
3497         threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3498
3499         mainwin->summaryview->folder_item->threaded = threaded; 
3500
3501         mainwin->summaryview->threaded = threaded;
3502
3503         summary_show(mainwin->summaryview, 
3504                         mainwin->summaryview->folder_item);
3505 }
3506
3507 static void expand_threads_cb(MainWindow *mainwin, guint action,
3508                               GtkWidget *widget)
3509 {
3510         summary_expand_threads(mainwin->summaryview);
3511 }
3512
3513 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3514                                 GtkWidget *widget)
3515 {
3516         summary_collapse_threads(mainwin->summaryview);
3517 }
3518
3519 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3520                                 GtkWidget *widget)
3521 {
3522         prefs_summary_column_open();
3523 }
3524
3525 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3526                                 GtkWidget *widget)
3527 {
3528         prefs_folder_column_open();
3529 }
3530
3531 static void sort_summary_cb(MainWindow *mainwin, guint action,
3532                             GtkWidget *widget)
3533 {
3534         FolderItem *item = mainwin->summaryview->folder_item;
3535         GtkWidget *menuitem;
3536
3537         if (mainwin->menu_lock_count) return;
3538
3539         if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3540                 menuitem = gtk_item_factory_get_item
3541                         (mainwin->menu_factory, "/View/Sort/Ascending");
3542                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3543                              GTK_CHECK_MENU_ITEM(menuitem)->active
3544                              ? SORT_ASCENDING : SORT_DESCENDING);
3545                 item->sort_key = action;
3546         }
3547 }
3548
3549 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3550                                  GtkWidget *widget)
3551 {
3552         FolderItem *item = mainwin->summaryview->folder_item;
3553
3554         if (mainwin->menu_lock_count) return;
3555
3556         if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3557                 summary_sort(mainwin->summaryview,
3558                              item->sort_key, (FolderSortType)action);
3559 }
3560
3561 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3562                                   GtkWidget *widget)
3563 {
3564         summary_attract_by_subject(mainwin->summaryview);
3565 }
3566
3567 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3568                                  GtkWidget *widget)
3569 {
3570         FolderItem *item;
3571
3572         item = folderview_get_selected_item(mainwin->folderview);
3573         if (item) {
3574                 main_window_cursor_wait(mainwin);
3575                 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3576
3577                 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3578                                               DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3579
3580                 STATUSBAR_POP(mainwin);
3581                 main_window_cursor_normal(mainwin);
3582         }
3583 }
3584
3585 struct DelDupsData
3586 {
3587         guint   dups;
3588         guint   folders;
3589 };
3590
3591 static void deldup_all(FolderItem *item, gpointer _data)
3592 {
3593         struct DelDupsData *data = _data;
3594         gint result;
3595         
3596         result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3597         if (result >= 0) {
3598                 data->dups += result;
3599                 data->folders += 1;
3600         }
3601 }
3602
3603 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3604                                  GtkWidget *widget)
3605 {
3606         struct DelDupsData data = {0, 0};
3607
3608         main_window_cursor_wait(mainwin);
3609         folder_func_to_all_folders(deldup_all, &data);
3610         main_window_cursor_normal(mainwin);
3611         
3612         alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3613                                    "Deleted %d duplicate messages in %d folders.\n",
3614                                    data.dups),
3615                           data.dups, data.folders);
3616 }
3617
3618 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3619 {
3620         summary_filter(mainwin->summaryview, (gboolean)action);
3621 }
3622
3623 static void execute_summary_cb(MainWindow *mainwin, guint action,
3624                                GtkWidget *widget)
3625 {
3626         summary_execute(mainwin->summaryview);
3627 }
3628
3629 static void update_summary_cb(MainWindow *mainwin, guint action,
3630                               GtkWidget *widget)
3631 {
3632         FolderItem *fitem;
3633         FolderView *folderview = mainwin->folderview;
3634
3635         if (!mainwin->summaryview->folder_item) return;
3636         if (!folderview->opened) return;
3637
3638         folder_update_op_count();
3639
3640         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3641                                             folderview->opened);
3642         if (!fitem) return;
3643
3644         folder_item_scan(fitem);
3645         summary_show(mainwin->summaryview, fitem);
3646 }
3647
3648 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3649 {
3650         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3651 }
3652
3653 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3654 {
3655         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3656 }
3657
3658 static void prev_unread_cb(MainWindow *mainwin, guint action,
3659                            GtkWidget *widget)
3660 {
3661         summary_select_prev_unread(mainwin->summaryview);
3662 }
3663
3664 static void next_unread_cb(MainWindow *mainwin, guint action,
3665                            GtkWidget *widget)
3666 {
3667         summary_select_next_unread(mainwin->summaryview);
3668 }
3669
3670 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3671 {
3672         summary_select_prev_new(mainwin->summaryview);
3673 }
3674
3675 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3676 {
3677         summary_select_next_new(mainwin->summaryview);
3678 }
3679
3680 static void prev_marked_cb(MainWindow *mainwin, guint action,
3681                            GtkWidget *widget)
3682 {
3683         summary_select_prev_marked(mainwin->summaryview);
3684 }
3685
3686 static void next_marked_cb(MainWindow *mainwin, guint action,
3687                            GtkWidget *widget)
3688 {
3689         summary_select_next_marked(mainwin->summaryview);
3690 }
3691
3692 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3693                             GtkWidget *widget)
3694 {
3695         summary_select_prev_labeled(mainwin->summaryview);
3696 }
3697
3698 static void next_labeled_cb(MainWindow *mainwin, guint action,
3699                             GtkWidget *widget)
3700 {
3701         summary_select_next_labeled(mainwin->summaryview);
3702 }
3703
3704 static void last_read_cb(MainWindow *mainwin, guint action,
3705                             GtkWidget *widget)
3706 {
3707         summary_select_last_read(mainwin->summaryview);
3708 }
3709
3710 static void parent_cb(MainWindow *mainwin, guint action,
3711                             GtkWidget *widget)
3712 {
3713         summary_select_parent(mainwin->summaryview);
3714 }
3715
3716 static void goto_folder_cb(MainWindow *mainwin, guint action,
3717                            GtkWidget *widget)
3718 {
3719         FolderItem *to_folder;
3720
3721         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
3722
3723         if (to_folder)
3724                 folderview_select(mainwin->folderview, to_folder);
3725 }
3726
3727 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
3728                            GtkWidget *widget)
3729 {
3730         folderview_select_next_unread(mainwin->folderview, FALSE);
3731 }
3732
3733 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3734 {
3735         messageview_copy_clipboard(mainwin->messageview);
3736 }
3737
3738 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3739 {
3740         MessageView *msgview = mainwin->messageview;
3741
3742         if (messageview_is_visible(msgview) &&
3743                  (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3744                 messageview_select_all(mainwin->messageview);
3745         else
3746                 summary_select_all(mainwin->summaryview);
3747 }
3748
3749 static void select_thread_cb(MainWindow *mainwin, guint action,
3750                              GtkWidget *widget)
3751 {
3752         summary_select_thread(mainwin->summaryview, FALSE);
3753 }
3754
3755 static void delete_thread_cb(MainWindow *mainwin, guint action,
3756                              GtkWidget *widget)
3757 {
3758         summary_select_thread(mainwin->summaryview, TRUE);
3759 }
3760
3761 static void create_filter_cb(MainWindow *mainwin, guint action,
3762                              GtkWidget *widget)
3763 {
3764         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
3765 }
3766
3767 static void create_processing_cb(MainWindow *mainwin, guint action,
3768                              GtkWidget *widget)
3769 {
3770         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
3771 }
3772
3773 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
3774                                          GtkWidget *widget)
3775 {
3776         prefs_filtering_open(&pre_global_processing,
3777                              _("Processing rules to apply before folder rules"),
3778                              MANUAL_ANCHOR_PROCESSING,
3779                              NULL, NULL, FALSE);
3780 }
3781
3782 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
3783                                           GtkWidget *widget)
3784 {
3785         prefs_filtering_open(&post_global_processing,
3786                              _("Processing rules to apply after folder rules"),
3787                              MANUAL_ANCHOR_PROCESSING,
3788                              NULL, NULL, FALSE);
3789 }
3790
3791 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
3792                                     GtkWidget *widget)
3793 {
3794         prefs_filtering_open(&filtering_rules,
3795                              _("Filtering configuration"),
3796                              MANUAL_ANCHOR_FILTERING,
3797                              NULL, NULL, TRUE);
3798 }
3799
3800 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
3801                                    GtkWidget *widget)
3802 {
3803         prefs_template_open();
3804 }
3805
3806 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
3807                                   GtkWidget *widget)
3808 {
3809         prefs_actions_open(mainwin);
3810 }
3811 #ifdef USE_OPENSSL
3812 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
3813                                   GtkWidget *widget)
3814 {
3815         ssl_manager_open(mainwin);
3816 }
3817 #endif
3818 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
3819                                   GtkWidget *widget)
3820 {
3821         if (!cur_account) {
3822                 new_account_cb(mainwin, 0, widget);
3823         } else {
3824                 account_open(cur_account);
3825         }
3826 }
3827
3828 static void new_account_cb(MainWindow *mainwin, guint action,
3829                            GtkWidget *widget)
3830 {
3831         account_edit_open();
3832         if (!compose_get_compose_list()) account_add();
3833 }
3834
3835 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
3836 {
3837         FolderItem *item = NULL;
3838         cur_account = (PrefsAccount *)data;
3839         
3840         if (!mainwindow_get_mainwindow())
3841                 return;
3842         main_window_show_cur_account(mainwindow_get_mainwindow());
3843         toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
3844         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
3845         toolbar_main_set_sensitive(mainwindow_get_mainwindow());
3846         item = folderview_get_selected_item(
3847                         mainwindow_get_mainwindow()->folderview);
3848         if (item) {
3849                 toolbar_set_compose_button
3850                         (mainwindow_get_mainwindow()->toolbar,
3851                          FOLDER_TYPE(item->folder) == F_NEWS ? 
3852                          COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
3853         }
3854 }
3855
3856 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
3857 {
3858         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3859         PrefsAccount *account = (PrefsAccount *)data;
3860
3861         inc_account_mail(mainwin, account);
3862 }
3863
3864 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
3865 {
3866         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3867         PrefsAccount *account = (PrefsAccount *)data;
3868         FolderItem *item = mainwin->summaryview->folder_item;   
3869
3870         compose_new_with_folderitem(account, item, NULL);
3871 }
3872
3873 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
3874 {
3875         prefs_gtk_open();
3876 }
3877
3878 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
3879 {
3880         pluginwindow_create();
3881 }
3882
3883 static void manual_open_cb(MainWindow *mainwin, guint action,
3884                            GtkWidget *widget)
3885 {
3886         manual_open((ManualType)action, NULL);
3887 }
3888
3889 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
3890 {
3891         legend_show();
3892 }
3893
3894 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
3895 {
3896         MainWindow *mainwin = (MainWindow *)data;
3897         gchar *str;
3898
3899         if (item->path)
3900                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
3901                                       LOCAL_FOLDER(folder)->rootpath,
3902                                       G_DIR_SEPARATOR,
3903                                       item->path);
3904         else
3905                 str = g_strdup_printf(_("Scanning folder %s ..."),
3906                                       LOCAL_FOLDER(folder)->rootpath);
3907
3908         STATUSBAR_PUSH(mainwin, str);
3909         STATUSBAR_POP(mainwin);
3910         g_free(str);
3911 }
3912
3913 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
3914                                           gpointer data)
3915 {
3916         SummaryView *summary;
3917
3918         g_return_val_if_fail(data, FALSE);
3919         if (!g_list_find(mainwin_list, data))
3920                 return TRUE;
3921         summary = ((MainWindow *)data)->summaryview;
3922         g_return_val_if_fail(summary, FALSE);
3923
3924         if (GTK_CLIST(summary->ctree)->selection && 
3925             g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
3926                 return FALSE;
3927
3928         return FALSE;
3929 }
3930
3931 static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
3932                                           gpointer data)
3933 {
3934         is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
3935         return FALSE;
3936 }
3937
3938 static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
3939                                           gpointer data)
3940 {
3941         if (!claws_is_starting()
3942                 && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
3943                 && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
3944
3945                 if (iconified_count > 0)
3946                         hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
3947                 iconified_count++;
3948         }
3949         if (state->new_window_state == 0)
3950                 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
3951         return FALSE;
3952 }
3953
3954 gboolean mainwindow_is_obscured(void)
3955 {
3956         return is_obscured;
3957 }
3958
3959 #define BREAK_ON_MODIFIER_KEY() \
3960         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
3961
3962 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
3963                                     gpointer data)
3964 {
3965         MainWindow *mainwin = (MainWindow*) data;
3966         
3967         if (!mainwin || !event) 
3968                 return FALSE;
3969
3970         if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
3971         {
3972                 lastkey = event->keyval;
3973                 return FALSE;
3974         }
3975
3976         switch (event->keyval) {
3977         case GDK_Q:             /* Quit */
3978                 BREAK_ON_MODIFIER_KEY();
3979
3980                 app_exit_cb(mainwin, 0, NULL);
3981                 return FALSE;
3982         case GDK_space:
3983                 if (mainwin->folderview && mainwin->summaryview
3984                     && ((!mainwin->summaryview->displayed
3985                         && !mainwin->summaryview->selected) 
3986                         || (mainwin->summaryview->folder_item
3987                             && mainwin->summaryview->folder_item->total_msgs == 0))) {
3988                         g_signal_stop_emission_by_name(G_OBJECT(widget), 
3989                                        "key_press_event");
3990                         folderview_select_next_unread(mainwin->folderview, TRUE);
3991                 }
3992                 break;
3993 #ifdef MAEMO
3994         case GDK_F6:
3995                 if (maemo_mainwindow_is_fullscreen(widget)) {
3996                         gtk_window_unfullscreen(GTK_WINDOW(widget));
3997                 } else {
3998                         gtk_window_fullscreen(GTK_WINDOW(widget));
3999                 }
4000                 break;
4001 #endif
4002         default:
4003                 break;
4004         }
4005         return FALSE;
4006 }
4007
4008 #undef BREAK_ON_MODIFIER_KEY
4009
4010 /*
4011  * Harvest addresses for selected folder.
4012  */
4013 static void addr_harvest_cb( MainWindow *mainwin,
4014                             guint action,
4015                             GtkWidget *widget )
4016 {
4017         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
4018 }
4019
4020 /*
4021  * Harvest addresses for selected messages in summary view.
4022  */
4023 static void addr_harvest_msg_cb( MainWindow *mainwin,
4024                             guint action,
4025                             GtkWidget *widget )
4026 {
4027         summary_harvest_address( mainwin->summaryview );
4028 }
4029
4030 /*!
4031  *\brief        get a MainWindow
4032  *
4033  *\return       MainWindow * The first mainwindow in the mainwin_list
4034  */
4035 MainWindow *mainwindow_get_mainwindow(void)
4036 {
4037         if (mainwin_list && mainwin_list->data)
4038                 return (MainWindow *)(mainwin_list->data);
4039         else
4040                 return NULL;
4041 }
4042
4043 static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
4044 {
4045         ProgressData *data = (ProgressData *) source;
4046         MainWindow *mainwin = (MainWindow *) userdata;
4047
4048         switch (data->cmd) {
4049         case PROGRESS_COMMAND_START:
4050         case PROGRESS_COMMAND_STOP:
4051                 gtk_progress_bar_set_fraction
4052                         (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
4053                 break;
4054         case PROGRESS_COMMAND_SET_PERCENTAGE:
4055                 gtk_progress_bar_set_fraction
4056                         (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
4057                 break;          
4058         }
4059         while (gtk_events_pending()) gtk_main_iteration ();
4060
4061         return FALSE;
4062 }
4063
4064 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4065 {
4066         mainwindow_check_synchronise(mainwin, FALSE);
4067 }
4068
4069 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
4070 {
4071         summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
4072 }
4073
4074 void mainwindow_jump_to(const gchar *target)
4075 {
4076         gchar *tmp = NULL;
4077         gchar *p = NULL;
4078         FolderItem *item = NULL;
4079         gchar *msg = NULL;
4080         MainWindow *mainwin = mainwindow_get_mainwindow();
4081         
4082         if (!target)
4083                 return;
4084                 
4085         if (!mainwin) {
4086                 printf("not initialized\n");
4087                 return;
4088         }
4089
4090         tmp = g_strdup(target);
4091         
4092         if ((p = strstr(tmp, "\r")) != NULL)
4093                 *p = '\0';
4094         if ((p = strstr(tmp, "\n")) != NULL)
4095                 *p = '\0';
4096
4097         if ((item = folder_find_item_from_identifier(tmp))) {
4098                 printf("selecting folder '%s'\n", tmp);
4099                 folderview_select(mainwin->folderview, item);
4100                 main_window_popup(mainwin);
4101                 g_free(tmp);
4102                 return;
4103         }
4104         
4105         msg = strrchr(tmp, G_DIR_SEPARATOR);
4106         if (msg) {
4107                 *msg++ = '\0';
4108                 if ((item = folder_find_item_from_identifier(tmp))) {
4109                         printf("selecting folder '%s'\n", tmp);
4110                         folderview_select(mainwin->folderview, item);
4111                 } else {
4112                         printf("'%s' not found\n", tmp);
4113                 }
4114                 if (item && msg && atoi(msg)) {
4115                         printf("selecting message %d\n", atoi(msg));
4116                         summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
4117                         summary_display_msg_selected(mainwin->summaryview, FALSE);
4118                         main_window_popup(mainwin);
4119                         g_free(tmp);
4120                         return;
4121                 } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
4122                         MsgInfo *msginfo = NULL;
4123                         msg++;
4124                         msg[strlen(msg)-1] = '\0';
4125                         msginfo = folder_item_get_msginfo_by_msgid(item, msg);
4126                         if (msginfo) {
4127                                 printf("selecting message %s\n", msg);
4128                                 summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
4129                                 summary_display_msg_selected(mainwin->summaryview, FALSE);
4130                                 main_window_popup(mainwin);
4131                                 g_free(tmp);
4132                                 procmsg_msginfo_free(msginfo);
4133                                 return;
4134                         } else {
4135                                 printf("'%s' not found\n", msg);
4136                         }
4137                 } else {
4138                         printf("'%s' not found\n", msg);
4139                 }
4140         } else {
4141                 printf("'%s' not found\n", tmp);
4142         }
4143         
4144         g_free(tmp);
4145 }
4146
4147 void mainwindow_exit_folder(MainWindow *mainwin) {
4148         if (prefs_common.layout_mode == SMALL_LAYOUT) {
4149                 folderview_close_opened(mainwin->folderview);
4150                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
4151         }
4152         mainwin->in_folder = FALSE;
4153 }
4154
4155 void mainwindow_enter_folder(MainWindow *mainwin) {
4156         if (prefs_common.layout_mode == SMALL_LAYOUT) {
4157                 mainwin_paned_show_last(GTK_PANED(mainwin->hpaned));
4158         }
4159         mainwin->in_folder = TRUE;
4160 }
4161
4162 #ifdef MAEMO
4163 gboolean maemo_mainwindow_is_fullscreen(GtkWidget *widget)
4164 {
4165         gint w, h;
4166         gtk_window_get_size(GTK_WINDOW(widget), &w, &h); 
4167         return (w == 800);
4168 }
4169
4170 void maemo_window_full_screen_if_needed (GtkWindow *window)
4171 {
4172         if (maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window)) {
4173                 gtk_window_fullscreen(GTK_WINDOW(window));
4174         }
4175 }
4176
4177 void maemo_connect_key_press_to_mainwindow (GtkWindow *window)
4178 {
4179         g_signal_connect(G_OBJECT(window), "key_press_event",
4180                          G_CALLBACK(mainwindow_key_pressed), mainwindow_get_mainwindow());
4181 }
4182 #endif