507cb6a27fe91ce89213198f31ef916b4474427d
[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 debug window"),  NULL, filtering_debug_window_show_cb, 0, NULL},
868         {N_("/_Tools/_Log window"),             "<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 debug enabled\n"));
1324         else
1325                 log_message(LOG_DEBUG_FILTERING, _("filtering debug 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 the 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
2245         if (mainwin->summaryview->deleted > 0 ||
2246             mainwin->summaryview->moved > 0 ||
2247             mainwin->summaryview->copied > 0)
2248                 state |= M_DELAY_EXEC;
2249
2250         return state;
2251 }
2252
2253
2254
2255 void main_window_set_menu_sensitive(MainWindow *mainwin)
2256 {
2257         GtkItemFactory *ifactory = mainwin->menu_factory;
2258         SensitiveCond state;
2259         gboolean sensitive;
2260         GtkWidget *menu;
2261         GtkWidget *menuitem;
2262         SummaryView *summaryview;
2263         gchar *menu_path;
2264         gint i;
2265         GList *cur_item;
2266
2267         static const struct {
2268                 gchar *const entry;
2269                 SensitiveCond cond;
2270         } entry[] = {
2271                 {"/File/Save as...", M_TARGET_EXIST},
2272                 {"/File/Print..."  , M_TARGET_EXIST},
2273                 {"/File/Synchronise folders", M_WANT_SYNC},
2274                 {"/File/Exit"      , M_UNLOCKED},
2275
2276                 {"/Edit/Select thread"             , M_SINGLE_TARGET_EXIST},
2277                 {"/Edit/Delete thread"             , M_SINGLE_TARGET_EXIST},
2278                 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2279
2280                 {"/View/Set displayed columns/in Folder list..."
2281                                                    , M_UNLOCKED}, 
2282                 {"/View/Sort"                      , M_EXEC},
2283                 {"/View/Thread view"               , M_EXEC},
2284                 {"/View/Expand all threads"        , M_MSG_EXIST},
2285                 {"/View/Collapse all threads"      , M_MSG_EXIST},
2286                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
2287                 {"/View/Go to/Previous message"        , M_MSG_EXIST},
2288                 {"/View/Go to/Next message"        , M_MSG_EXIST},
2289                 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2290                 {"/View/Go to/Previous new message"    , M_MSG_EXIST},
2291                 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2292                 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2293                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2294                 {"/View/Go to/Last read message"   , M_SINGLE_TARGET_EXIST},
2295                 {"/View/Go to/Parent message"      , M_SINGLE_TARGET_EXIST},
2296                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
2297                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
2298                 {"/View/All headers"               , M_SINGLE_TARGET_EXIST},
2299                 {"/View/Quotes"                    , M_SINGLE_TARGET_EXIST},
2300
2301                 {"/Message/Receive/Get from current account"
2302                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2303                 {"/Message/Receive/Get from all accounts"
2304                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2305                 {"/Message/Receive/Cancel receiving"
2306                                                  , M_INC_ACTIVE},
2307                 {"/Message/Send queued messages"  , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2308                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2309                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2310                 {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2311                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2312                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2313                 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2314                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2315                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE},
2316                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC},
2317                 {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2318                 {"/Message/Delete..."             , M_TARGET_EXIST|M_ALLOW_DELETE},
2319                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2320                 {"/Message/Mark"                  , M_TARGET_EXIST},
2321                 {"/Message/Mark/Mark as spam"     , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2322                 {"/Message/Mark/Mark as ham"      , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2323                 {"/Message/Mark/Ignore thread"    , M_TARGET_EXIST},
2324                 {"/Message/Mark/Unignore thread"  , M_TARGET_EXIST},
2325                 {"/Message/Mark/Lock"             , M_TARGET_EXIST},
2326                 {"/Message/Mark/Unlock"           , M_TARGET_EXIST},
2327                 {"/Message/Color label"           , M_TARGET_EXIST},
2328                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2329
2330                 {"/Tools/Add sender to address book"   , M_SINGLE_TARGET_EXIST},
2331                 {"/Tools/Harvest addresses"            , M_MSG_EXIST},
2332                 {"/Tools/Harvest addresses/from Messages..."
2333                                                        , M_TARGET_EXIST},
2334                 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2335                 {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
2336                 {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2337                 {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2338                 {"/Tools/List URLs..."                 , M_TARGET_EXIST},
2339                 {"/Tools/Actions"                      , M_TARGET_EXIST|M_ACTIONS_EXIST},
2340                 {"/Tools/Execute"                      , M_DELAY_EXEC},
2341                 {"/Tools/Delete duplicated messages/In selected folder"   , M_MSG_EXIST|M_ALLOW_DELETE},
2342
2343                 {"/Configuration", M_UNLOCKED},
2344                 {"/Configuration/Preferences for current account...", M_UNLOCKED},
2345                 {"/Configuration/Create new account...", M_UNLOCKED},
2346                 {"/Configuration/Edit accounts...", M_UNLOCKED},
2347
2348                 {NULL, 0}
2349         };
2350
2351         state = main_window_get_current_state(mainwin);
2352
2353         for (i = 0; entry[i].entry != NULL; i++) {
2354                 sensitive = ((entry[i].cond & state) == entry[i].cond);
2355                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2356         }
2357
2358         menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2359
2360         /* search for separator */
2361         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2362              cur_item = cur_item->next) {
2363                 if (GTK_BIN(cur_item->data)->child == NULL) {
2364                         cur_item = cur_item->next;
2365                         break;
2366                 }
2367         }
2368
2369         for (; cur_item != NULL; cur_item = cur_item->next) {
2370                 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2371                                          (M_UNLOCKED & state) != 0);
2372         }
2373
2374         main_window_menu_callback_block(mainwin);
2375
2376 #define SET_CHECK_MENU_ACTIVE(path, active) \
2377 { \
2378         menuitem = gtk_item_factory_get_widget(ifactory, path); \
2379         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2380 }
2381
2382         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2383                               messageview_is_visible(mainwin->messageview));
2384
2385         summaryview = mainwin->summaryview;
2386         menu_path = "/View/Sort/Don't sort";
2387
2388         switch (summaryview->sort_key) {
2389         case SORT_BY_NUMBER:
2390                 menu_path = "/View/Sort/by number"; break;
2391         case SORT_BY_SIZE:
2392                 menu_path = "/View/Sort/by Size"; break;
2393         case SORT_BY_DATE:
2394                 menu_path = "/View/Sort/by Date"; break;
2395         case SORT_BY_FROM:
2396                 menu_path = "/View/Sort/by From"; break;
2397         case SORT_BY_TO:
2398                 menu_path = "/View/Sort/by To"; break;
2399         case SORT_BY_SUBJECT:
2400                 menu_path = "/View/Sort/by Subject"; break;
2401         case SORT_BY_LABEL:
2402                 menu_path = "/View/Sort/by color label"; break;
2403         case SORT_BY_MARK:
2404                 menu_path = "/View/Sort/by mark"; break;
2405         case SORT_BY_STATUS:
2406                 menu_path = "/View/Sort/by status"; break;
2407         case SORT_BY_MIME:
2408                 menu_path = "/View/Sort/by attachment"; break;
2409         case SORT_BY_SCORE:
2410                 menu_path = "/View/Sort/by score"; break;
2411         case SORT_BY_LOCKED:
2412                 menu_path = "/View/Sort/by locked"; break;
2413         case SORT_BY_NONE:
2414         default:
2415                 menu_path = "/View/Sort/Don't sort"; break;
2416         }
2417         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2418
2419         if (summaryview->sort_type == SORT_ASCENDING) {
2420                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2421         } else {
2422                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2423         }
2424
2425         if (summaryview->sort_key != SORT_BY_NONE) {
2426                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2427                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2428         } else {
2429                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2430                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2431         }
2432
2433         if (mainwin->messageview 
2434         &&  mainwin->messageview->mimeview
2435         &&  mainwin->messageview->mimeview->textview)
2436                 SET_CHECK_MENU_ACTIVE("/View/All headers",
2437                               mainwin->messageview->mimeview->textview->show_all_headers);
2438         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2439         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2440         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2441         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2442         if (prefs_common.hide_quotes == 1)
2443                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2444         if (prefs_common.hide_quotes == 2)
2445                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2446         if (prefs_common.hide_quotes == 3)
2447                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2448
2449 #undef SET_CHECK_MENU_ACTIVE
2450
2451         main_window_menu_callback_unblock(mainwin);
2452 }
2453
2454 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2455 {
2456         GtkItemFactory *ifactory;
2457         gint is_menu = 0;
2458         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2459         
2460         if (msginfo) 
2461                 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2462         if (is_menu)
2463                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2464                                 (ifactory,"/Message/Mailing-List"), TRUE);
2465         else
2466                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2467                                 (ifactory,"/Message/Mailing-List"), FALSE);
2468 }
2469
2470 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2471 {
2472         gint menu_nb = 0;
2473         GtkWidget *menuitem;
2474         
2475         if (!msginfo || !msginfo->extradata) {
2476                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2477                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2478                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2479                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2480                 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2481                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2482                 return 0;
2483         }
2484                 
2485         /* Mailing list post */
2486         if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2487                 g_free(msginfo->extradata->list_post);
2488                 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2489         }
2490         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2491                 
2492         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2493  
2494         /* Mailing list help */
2495         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2496         
2497         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2498
2499         /* Mailing list subscribe */
2500         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2501         
2502         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2503                 
2504         /* Mailing list unsubscribe */
2505         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2506         
2507         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2508         
2509         /* Mailing list view archive */
2510         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2511         
2512         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2513         
2514         /* Mailing list contact owner */
2515         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2516         
2517         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2518         
2519         return menu_nb;
2520 }
2521
2522 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2523 {
2524         GtkWidget *item, *menu;
2525         const gchar *url_pt ;
2526         gchar url_decoded[BUFFSIZE];
2527         GList *amenu, *alist;
2528         gint menu_nb = 0;
2529         
2530         menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2531         
2532         /* First delete old submenu */
2533         /* FIXME: we can optimize this, and only change/add/delete necessary items */
2534         for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2535                 alist = amenu->next;
2536                 item = GTK_WIDGET (amenu->data);
2537                 gtk_widget_destroy (item);
2538                 amenu = alist;
2539         }
2540         if (list_header) {
2541                 for (url_pt = list_header; url_pt && *url_pt;) {
2542                         get_url_part (&url_pt, url_decoded, BUFFSIZE);
2543                         item = NULL;
2544                         if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2545                                 item = gtk_menu_item_new_with_label ((url_decoded));
2546                                 g_signal_connect(G_OBJECT(item), "activate",
2547                                                  G_CALLBACK(mailing_list_compose),
2548                                                  NULL);
2549                         }
2550                         else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2551                                  !g_strncasecmp (url_decoded, "https:",6)) {
2552
2553                                 item = gtk_menu_item_new_with_label ((url_decoded));
2554                                 g_signal_connect(G_OBJECT(item), "activate",
2555                                                  G_CALLBACK(mailing_list_open_uri),
2556                                                  NULL);
2557                         } 
2558                         if (item) {
2559                                 gtk_menu_append (GTK_MENU(menu), item);
2560                                 gtk_widget_show (item);
2561                                 menu_nb++;
2562                         }
2563                 }
2564         }
2565         if (menu_nb)
2566                 gtk_widget_set_sensitive (menuitem, TRUE);
2567         else
2568                 gtk_widget_set_sensitive (menuitem, FALSE);
2569                 
2570
2571         return menu_nb;
2572 }
2573
2574 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2575 {
2576         gchar tmp[BUFFSIZE];
2577         const gchar *buf;
2578         gint i = 0;
2579         buf = *buffer;
2580         gboolean with_plus = TRUE;
2581
2582         if (buf == 0x00) {
2583                 *url_decoded = '\0';
2584                 *buffer = NULL;
2585                 return;
2586         }
2587         /* Ignore spaces, comments  and tabs () */
2588         for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2589                 if (*buf == '(')
2590                         for (;*buf != ')' && *buf != 0x00; buf++);
2591         
2592         /* First non space and non comment must be a < */
2593         if (*buf =='<' ) {
2594                 buf++;
2595                 if (!strncmp(buf, "mailto:", strlen("mailto:")))
2596                         with_plus = FALSE;
2597                 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2598                 buf++;
2599         }
2600         else  {
2601                 *buffer = NULL;
2602                 *url_decoded = '\0';
2603                 return;
2604         }
2605         
2606         tmp[i]       = 0x00;
2607         *url_decoded = '\0';
2608         *buffer = NULL;
2609         
2610         if (i == maxlen) {
2611                 return;
2612         }
2613         decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
2614
2615         /* Prepare the work for the next url in the list */
2616         /* after the closing bracket >, ignore space, comments and tabs */
2617         for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2618                 if (*buf == '(')
2619                         for (;*buf != ')' && *buf != 0x00; buf++);
2620                         
2621         if (!buf || !*buf) {
2622                 *buffer = NULL;
2623                 return;
2624         }
2625
2626         /* now first non space, non comment must be a comma */
2627         if (*buf != ',')
2628                 for (;*buf != 0x00; buf++);
2629         else
2630                 buf++;
2631         *buffer = buf;
2632 }
2633         
2634 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2635 {
2636         gchar *mailto;
2637
2638         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2639         compose_new(NULL, mailto+7, NULL);
2640 }
2641  
2642  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2643 {
2644  
2645         gchar *mailto;
2646  
2647         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2648         open_uri (mailto, prefs_common.uri_cmd);
2649
2650         
2651 void main_window_popup(MainWindow *mainwin)
2652 {
2653         if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
2654                 main_window_show(mainwin);
2655
2656         gtkut_window_popup(mainwin->window);
2657         if (prefs_common.layout_mode == SMALL_LAYOUT) {
2658                 if (mainwin->in_folder) {
2659                         mainwindow_enter_folder(mainwin);
2660                 } else {
2661                         mainwindow_exit_folder(mainwin);
2662                 }
2663         }
2664 }
2665
2666 void main_window_show(MainWindow *mainwin)
2667 {
2668         gtk_widget_show(mainwin->window);
2669         gtk_widget_show(mainwin->vbox_body);
2670
2671         gtk_widget_set_uposition(mainwin->window,
2672                                  prefs_common.mainwin_x,
2673                                  prefs_common.mainwin_y);
2674
2675         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2676                              prefs_common.folderview_width,
2677                              prefs_common.folderview_height);
2678         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2679                              prefs_common.summaryview_width,
2680                              prefs_common.summaryview_height);
2681         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2682                              prefs_common.msgview_width,
2683                              prefs_common.msgview_height);
2684 }
2685
2686 void main_window_hide(MainWindow *mainwin)
2687 {
2688         main_window_get_size(mainwin);
2689         main_window_get_position(mainwin);
2690
2691         gtk_widget_hide(mainwin->window);
2692         gtk_widget_hide(mainwin->vbox_body);
2693 }
2694
2695 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
2696 {
2697         GtkWidget *folderwin = NULL;
2698         GtkWidget *messagewin = NULL;
2699         GtkWidget *hpaned;
2700         GtkWidget *vpaned;
2701         GtkWidget *vbox_body = mainwin->vbox_body;
2702         GtkItemFactory *ifactory = mainwin->menu_factory;
2703         GtkWidget *menuitem;
2704         gboolean first_set = (mainwin->hpaned == NULL);
2705         debug_print("Setting widgets... ");
2706
2707         if (layout_mode == SMALL_LAYOUT && first_set) {
2708                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2709                                     prefs_common.folderview_width,
2710                                     prefs_common.folderview_height);
2711                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2712                                     0,0);
2713                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2714                                     0,0);
2715         } else {
2716                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2717                                     prefs_common.folderview_width,
2718                                     prefs_common.folderview_height);
2719                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2720                                     prefs_common.summaryview_width,
2721                                     prefs_common.summaryview_height);
2722                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2723                                     prefs_common.msgview_width,
2724                                     prefs_common.msgview_height);
2725         }
2726
2727         mainwin->messageview->statusbar = mainwin->statusbar;
2728         mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2729
2730         /* clean top-most container */
2731         if (mainwin->hpaned) {
2732                 if (mainwin->hpaned->parent == mainwin->vpaned)
2733                         gtk_widget_destroy(mainwin->vpaned);
2734                 else
2735                         gtk_widget_destroy(mainwin->hpaned);
2736         }
2737
2738         menu_set_sensitive(ifactory, "/View/Show or hide/Message view", 
2739                 (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
2740         switch (layout_mode) {
2741         case VERTICAL_LAYOUT:
2742         case NORMAL_LAYOUT:
2743         case SMALL_LAYOUT:
2744                 hpaned = gtk_hpaned_new();
2745                 if (layout_mode == VERTICAL_LAYOUT)
2746                         vpaned = gtk_hpaned_new();
2747                 else
2748                         vpaned = gtk_vpaned_new();
2749                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2750                 gtk_paned_add1(GTK_PANED(hpaned),
2751                                GTK_WIDGET_PTR(mainwin->folderview));
2752                 gtk_widget_show(hpaned);
2753                 gtk_widget_queue_resize(hpaned);
2754
2755                 if (messageview_is_visible(mainwin->messageview)) {
2756                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
2757                         gtk_paned_add1(GTK_PANED(vpaned),
2758                                        GTK_WIDGET_PTR(mainwin->summaryview));
2759                 } else {
2760                         gtk_paned_add2(GTK_PANED(hpaned),
2761                                        GTK_WIDGET_PTR(mainwin->summaryview));
2762                         gtk_widget_ref(vpaned);
2763                 }
2764                 gtk_paned_add2(GTK_PANED(vpaned),
2765                                GTK_WIDGET_PTR(mainwin->messageview));
2766                 gtk_widget_show(vpaned);
2767                 if (layout_mode == SMALL_LAYOUT && first_set) {
2768                         mainwin_paned_show_first(GTK_PANED(hpaned));
2769                 }
2770                 gtk_widget_queue_resize(vpaned);
2771                 break;
2772         case WIDE_LAYOUT:
2773                 vpaned = gtk_vpaned_new();
2774                 hpaned = gtk_hpaned_new();
2775                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
2776                 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
2777
2778                 gtk_paned_add1(GTK_PANED(hpaned),
2779                                GTK_WIDGET_PTR(mainwin->folderview));
2780                 gtk_paned_add2(GTK_PANED(hpaned),
2781                                GTK_WIDGET_PTR(mainwin->summaryview));
2782
2783                 gtk_widget_show(hpaned);
2784                 gtk_widget_queue_resize(hpaned);
2785
2786                 if (messageview_is_visible(mainwin->messageview)) {
2787                         gtk_paned_add2(GTK_PANED(vpaned),
2788                                GTK_WIDGET_PTR(mainwin->messageview));   
2789                 } else {
2790                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
2791                 }
2792                 gtk_widget_show(vpaned);
2793                 gtk_widget_queue_resize(vpaned);
2794                 break;
2795         case WIDE_MSGLIST_LAYOUT:
2796                 vpaned = gtk_vpaned_new();
2797                 hpaned = gtk_hpaned_new();
2798                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
2799
2800                 gtk_paned_add1(GTK_PANED(vpaned),
2801                                GTK_WIDGET_PTR(mainwin->summaryview));
2802                 gtk_paned_add1(GTK_PANED(hpaned),
2803                                GTK_WIDGET_PTR(mainwin->folderview));
2804
2805                 gtk_widget_show(hpaned);
2806                 gtk_widget_queue_resize(hpaned);
2807
2808                 if (messageview_is_visible(mainwin->messageview)) {
2809                         gtk_paned_add2(GTK_PANED(hpaned),
2810                                GTK_WIDGET_PTR(mainwin->messageview));   
2811                 } else {
2812                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
2813                 }
2814                 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
2815
2816                 gtk_widget_show(vpaned);
2817                 gtk_widget_queue_resize(vpaned);
2818                 break;
2819         default:
2820                 g_warning("Unknown layout");
2821                 return;
2822         }
2823
2824         mainwin->hpaned = hpaned;
2825         mainwin->vpaned = vpaned;
2826
2827         if (layout_mode == SMALL_LAYOUT) {
2828                 if (mainwin->messageview->visible)
2829                         main_window_toggle_message_view(mainwin);
2830         } 
2831
2832         if (layout_mode == SMALL_LAYOUT && first_set) {
2833                 gtk_widget_realize(mainwin->window);
2834                 gtk_widget_realize(mainwin->folderview->ctree);
2835                 gtk_widget_realize(mainwin->summaryview->hbox);
2836                 gtk_widget_realize(mainwin->summaryview->hbox_l);
2837                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2838                                     prefs_common.folderview_width,
2839                                     prefs_common.folderview_height);
2840                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2841                                     0,0);
2842                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2843                                     0,0);
2844                 gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
2845                                 prefs_common.mainwin_width,
2846                                 prefs_common.mainwin_height);
2847                 gtk_paned_set_position(GTK_PANED(mainwin->hpaned), 800);
2848         } 
2849         /* remove headerview if not in prefs */
2850         headerview_set_visibility(mainwin->messageview->headerview,
2851                                   prefs_common.display_header_pane);
2852
2853         if (messageview_is_visible(mainwin->messageview))
2854                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2855                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2856         else
2857                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2858                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2859
2860         gtk_window_move(GTK_WINDOW(mainwin->window),
2861                         prefs_common.mainwin_x,
2862                         prefs_common.mainwin_y);
2863
2864         gtk_widget_queue_resize(vbox_body);
2865         gtk_widget_queue_resize(mainwin->vbox);
2866         gtk_widget_queue_resize(mainwin->window);
2867         /* CLAWS: previous "gtk_widget_show_all" makes noticeview
2868          * and mimeview icon list/ctree lose track of their visibility states */
2869         if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
2870                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
2871         if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview)) 
2872                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
2873         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
2874                 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
2875         else 
2876                 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
2877
2878         prefs_common.layout_mode = layout_mode;
2879
2880         menuitem = gtk_item_factory_get_item
2881                 (ifactory, "/View/Show or hide/Message view");
2882         gtk_check_menu_item_set_active
2883                 (GTK_CHECK_MENU_ITEM(menuitem),
2884                  messageview_is_visible(mainwin->messageview));
2885
2886 #define SET_CHECK_MENU_ACTIVE(path, active) \
2887 { \
2888         menuitem = gtk_item_factory_get_widget(ifactory, path); \
2889         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2890 }
2891
2892         switch (prefs_common.layout_mode) {
2893         case NORMAL_LAYOUT:
2894                 SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
2895                 break;
2896         case VERTICAL_LAYOUT:
2897                 SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
2898                 break;
2899         case WIDE_LAYOUT:
2900                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
2901                 break;
2902         case WIDE_MSGLIST_LAYOUT:
2903                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
2904                 break;
2905         case SMALL_LAYOUT:
2906                 SET_CHECK_MENU_ACTIVE("/View/Layout/Small screen", TRUE);
2907                 break;
2908         }
2909 #undef SET_CHECK_MENU_ACTIVE
2910
2911         if (folderwin) {
2912                 g_signal_connect
2913                         (G_OBJECT(folderwin), "size_allocate",
2914                          G_CALLBACK(folder_window_size_allocate_cb),
2915                          mainwin);
2916         }
2917         if (messagewin) {
2918                 g_signal_connect
2919                         (G_OBJECT(messagewin), "size_allocate",
2920                          G_CALLBACK(message_window_size_allocate_cb),
2921                          mainwin);
2922         }
2923
2924         debug_print("done.\n");
2925 }
2926
2927 void main_window_destroy_all(void)
2928 {
2929         while (mainwin_list != NULL) {
2930                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
2931                 
2932                 /* free toolbar stuff */
2933                 toolbar_clear_list(TOOLBAR_MAIN);
2934                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2935                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
2936
2937                 mainwin->folderview->mainwin = NULL;
2938                 mainwin->summaryview->mainwin = NULL;
2939                 mainwin->messageview->mainwin = NULL;
2940
2941                 g_free(mainwin->toolbar);
2942                 g_free(mainwin);
2943                 
2944                 mainwin_list = g_list_remove(mainwin_list, mainwin);
2945         }
2946         g_list_free(mainwin_list);
2947         mainwin_list = NULL;
2948 }
2949
2950 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
2951                                    gpointer data)
2952 {
2953         gtk_widget_set_size_request(child, 1, -1);
2954 }
2955
2956 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
2957                                    gpointer data)
2958 {
2959         gtk_widget_set_size_request(child, -1, -1);
2960 }
2961
2962 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2963                                     gpointer data)
2964 {
2965         MainWindow *mainwin = (MainWindow *)data;
2966
2967         if (!event) return FALSE;
2968
2969         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2970         g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
2971                           widget);
2972
2973         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2974                        menu_button_position, widget,
2975                        event->button, event->time);
2976
2977         return TRUE;
2978 }
2979
2980 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2981                                  gpointer data)
2982 {
2983         MainWindow *mainwin = (MainWindow *)data;
2984         gboolean close_allowed = TRUE;
2985
2986         hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
2987
2988         if (close_allowed && mainwin->lock_count == 0)
2989                 app_exit_cb(data, 0, widget);
2990
2991         return TRUE;
2992 }
2993
2994 static void main_window_size_allocate_cb(GtkWidget *widget,
2995                                          GtkAllocation *allocation,
2996                                          gpointer data)
2997 {
2998         MainWindow *mainwin = (MainWindow *)data;
2999         main_window_get_size(mainwin);
3000 }
3001
3002 static void folder_window_size_allocate_cb(GtkWidget *widget,
3003                                            GtkAllocation *allocation,
3004                                            gpointer data)
3005 {
3006         MainWindow *mainwin = (MainWindow *)data;
3007
3008         main_window_get_size(mainwin);
3009 }
3010
3011 static void message_window_size_allocate_cb(GtkWidget *widget,
3012                                             GtkAllocation *allocation,
3013                                             gpointer data)
3014 {
3015         MainWindow *mainwin = (MainWindow *)data;
3016
3017         main_window_get_size(mainwin);
3018 }
3019
3020 static void add_mailbox_cb(MainWindow *mainwin, guint action,
3021                            GtkWidget *widget)
3022 {
3023         main_window_add_mailbox(mainwin);
3024 }
3025
3026 static void update_folderview_cb(MainWindow *mainwin, guint action,
3027                                  GtkWidget *widget)
3028 {
3029         summary_show(mainwin->summaryview, NULL);
3030         folderview_check_new_all();
3031 }
3032
3033 static void foldersort_cb(MainWindow *mainwin, guint action,
3034                            GtkWidget *widget)
3035 {
3036         foldersort_open();
3037 }
3038
3039 static void import_mbox_cb(MainWindow *mainwin, guint action,
3040                            GtkWidget *widget)
3041 {
3042         /* only notify if import has failed */
3043         if (import_mbox(mainwin->summaryview->folder_item) == -1) {
3044                 alertpanel_error(_("Mbox import has failed."));
3045         }
3046 }
3047
3048 static void export_mbox_cb(MainWindow *mainwin, guint action,
3049                            GtkWidget *widget)
3050 {
3051         /* only notify if export has failed */
3052         if (export_mbox(mainwin->summaryview->folder_item) == -1) {
3053                 alertpanel_error(_("Export to mbox has failed."));
3054         }
3055 }
3056
3057 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
3058                                 GtkWidget *widget)
3059 {
3060         /* only notify if export has failed */
3061         if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
3062                 alertpanel_error(_("Export to mbox has failed."));
3063         }
3064 }
3065
3066 static void empty_trash_cb(MainWindow *mainwin, guint action,
3067                            GtkWidget *widget)
3068 {
3069         main_window_empty_trash(mainwin, TRUE);
3070 }
3071
3072 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3073 {
3074         summary_save_as(mainwin->summaryview);
3075 }
3076
3077 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3078 {
3079         summary_print(mainwin->summaryview);
3080 }
3081
3082 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3083 {
3084         if (prefs_common.confirm_on_exit) {
3085                 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
3086                                GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
3087                     != G_ALERTALTERNATE)
3088                         return;
3089                 manage_window_focus_in(mainwin->window, NULL, NULL);
3090         }
3091
3092         app_will_exit(widget, mainwin);
3093 }
3094
3095 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3096 {
3097         if (action == 1)
3098                 summary_search(mainwin->summaryview);
3099         else
3100                 message_search(mainwin->messageview);
3101 }
3102
3103 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3104 {
3105         summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
3106 }
3107
3108 static void toggle_message_cb(MainWindow *mainwin, guint action,
3109                               GtkWidget *widget)
3110 {
3111         gboolean active;
3112
3113         active = GTK_CHECK_MENU_ITEM(widget)->active;
3114
3115         if (active != messageview_is_visible(mainwin->messageview))
3116                 summary_toggle_view(mainwin->summaryview);
3117 }
3118
3119 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3120                               GtkWidget *widget)
3121 {
3122         toolbar_toggle(action, mainwin);
3123 }
3124
3125 static void main_window_reply_cb(MainWindow *mainwin, guint action,
3126                           GtkWidget *widget)
3127 {
3128         MessageView *msgview = (MessageView*)mainwin->messageview;
3129         GSList *msginfo_list = NULL;
3130
3131         g_return_if_fail(msgview != NULL);
3132
3133         msginfo_list = summary_get_selection(mainwin->summaryview);
3134         g_return_if_fail(msginfo_list != NULL);
3135         compose_reply_from_messageview(msgview, msginfo_list, action);
3136         g_slist_free(msginfo_list);
3137 }
3138
3139
3140 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3141                                 GtkWidget *widget)
3142 {
3143         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3144                 gtk_widget_show(mainwin->hbox_stat);
3145                 prefs_common.show_statusbar = TRUE;
3146         } else {
3147                 gtk_widget_hide(mainwin->hbox_stat);
3148                 prefs_common.show_statusbar = FALSE;
3149         }
3150 }
3151
3152 static void set_layout_cb(MainWindow *mainwin, guint action,
3153                                GtkWidget *widget)
3154 {
3155         LayoutType layout_mode = action;
3156         LayoutType old_layout_mode = prefs_common.layout_mode;
3157         if (mainwin->menu_lock_count) {
3158                 return;
3159         }
3160         if (!GTK_CHECK_MENU_ITEM(widget)->active) {
3161                 return;
3162         }
3163         
3164         if (layout_mode == prefs_common.layout_mode) {
3165                 return;
3166         }
3167         
3168         if (!mainwin->messageview->visible && layout_mode != SMALL_LAYOUT)
3169                 main_window_toggle_message_view(mainwin);
3170         else if (mainwin->messageview->visible && layout_mode == SMALL_LAYOUT)
3171                 main_window_toggle_message_view(mainwin);
3172
3173         main_window_separation_change(mainwin, layout_mode);
3174         mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
3175         if (old_layout_mode == SMALL_LAYOUT && layout_mode != SMALL_LAYOUT) {
3176                 mainwindow_reset_paned(GTK_PANED(mainwin->hpaned));
3177         }
3178         if (old_layout_mode != SMALL_LAYOUT && layout_mode == SMALL_LAYOUT) {
3179                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
3180                 mainwindow_exit_folder(mainwin);
3181         }
3182         summary_relayout(mainwin->summaryview); 
3183         summary_update_unread(mainwin->summaryview, NULL);
3184 }
3185
3186 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3187                                         gboolean ask_sync)
3188 {
3189         offline_ask_sync = ask_sync;
3190         if (offline)
3191                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3192         else
3193                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3194         offline_ask_sync = TRUE;
3195 }
3196
3197 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3198 {
3199         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3200 }
3201
3202 static gboolean any_folder_want_synchronise(void)
3203 {
3204         GList *folderlist = folder_get_list();
3205
3206         /* see if there are synchronised folders */
3207         for (; folderlist; folderlist = folderlist->next) {
3208                 Folder *folder = (Folder *)folderlist->data;
3209                 if (folder_want_synchronise(folder)) {
3210                         return TRUE;
3211                 }
3212         }
3213         
3214         return FALSE;
3215 }
3216
3217 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3218 {
3219         
3220         if (!any_folder_want_synchronise())
3221                 return;
3222
3223         if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3224                         _("Do you want to synchronise your folders now?"),
3225                         GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3226                 return;
3227         
3228         if (offline_ask_sync)
3229                 folder_synchronise(NULL);
3230 }
3231
3232 static void online_switch_clicked (GtkButton *btn, gpointer data) 
3233 {
3234         MainWindow *mainwin;
3235         GtkItemFactory *ifactory;
3236         GtkCheckMenuItem *menuitem;
3237
3238         mainwin = (MainWindow *) data;
3239         
3240         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3241         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3242         
3243         g_return_if_fail(mainwin != NULL);
3244         g_return_if_fail(menuitem != NULL);
3245         
3246         if (btn == GTK_BUTTON(mainwin->online_switch)) {
3247                 gtk_widget_hide (mainwin->online_switch);
3248                 gtk_widget_show (mainwin->offline_switch);
3249                 menuitem->active = TRUE;
3250                 inc_autocheck_timer_remove();
3251                         
3252                 /* go offline */
3253                 if (prefs_common.work_offline)
3254                         return;
3255                 mainwindow_check_synchronise(mainwin, TRUE);
3256                 prefs_common.work_offline = TRUE;
3257                 imap_disconnect_all();
3258                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3259         } else {
3260                 /*go online */
3261                 if (!prefs_common.work_offline)
3262                         return;
3263                 gtk_widget_hide (mainwin->offline_switch);
3264                 gtk_widget_show (mainwin->online_switch);
3265                 menuitem->active = FALSE;
3266                 prefs_common.work_offline = FALSE;
3267                 inc_autocheck_timer_set();
3268                 refresh_resolvers();
3269                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3270         }
3271 }
3272
3273 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3274                                 GtkWidget *widget)
3275 {
3276         addressbook_open(NULL);
3277 }
3278
3279 static void log_window_show_cb(MainWindow *mainwin, guint action,
3280                                GtkWidget *widget)
3281 {
3282         log_window_show(mainwin->logwin);
3283 }
3284
3285 static void filtering_debug_window_show_cb(MainWindow *mainwin, guint action,
3286                                GtkWidget *widget)
3287 {
3288         log_window_show(mainwin->filtering_debugwin);
3289 }
3290
3291 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3292 {
3293         inc_cancel_all();
3294 }
3295
3296 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3297 {
3298         summary_move_to(mainwin->summaryview);
3299 }
3300
3301 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3302 {
3303         summary_copy_to(mainwin->summaryview);
3304 }
3305
3306 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3307 {
3308         summary_delete(mainwin->summaryview);
3309 }
3310
3311 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3312 {
3313         summary_delete_trash(mainwin->summaryview);
3314 }
3315
3316 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3317 {
3318         summary_cancel(mainwin->summaryview);
3319 }
3320
3321 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3322 {
3323         summary_open_msg(mainwin->summaryview);
3324 }
3325
3326 static void view_source_cb(MainWindow *mainwin, guint action,
3327                            GtkWidget *widget)
3328 {
3329         summary_view_source(mainwin->summaryview);
3330 }
3331
3332 static void show_all_header_cb(MainWindow *mainwin, guint action,
3333                                GtkWidget *widget)
3334 {
3335         if (mainwin->menu_lock_count) return;
3336         mainwin->summaryview->messageview->all_headers = 
3337                         GTK_CHECK_MENU_ITEM(widget)->active;
3338         summary_display_msg_selected(mainwin->summaryview,
3339                                      GTK_CHECK_MENU_ITEM(widget)->active);
3340 }
3341
3342 #define SET_CHECK_MENU_ACTIVE(path, active) \
3343 { \
3344         menuitem = gtk_item_factory_get_widget(ifactory, path); \
3345         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3346 }
3347
3348 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3349                                GtkWidget *widget)
3350 {
3351         GtkWidget *menuitem;
3352         GtkItemFactory *ifactory = mainwin->menu_factory;
3353
3354         if (mainwin->menu_lock_count) return;
3355
3356         prefs_common.hide_quotes = 
3357                         GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3358
3359         mainwin->menu_lock_count++;
3360         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3361         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3362         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3363         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3364         mainwin->menu_lock_count--;
3365
3366         summary_redisplay_msg(mainwin->summaryview);
3367 }
3368
3369 #undef SET_CHECK_MENU_ACTIVE
3370 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3371 {
3372         summary_mark(mainwin->summaryview);
3373 }
3374
3375 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3376 {
3377         summary_unmark(mainwin->summaryview);
3378 }
3379
3380 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3381                               GtkWidget *widget)
3382 {
3383         summary_mark_as_unread(mainwin->summaryview);
3384 }
3385
3386 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3387                             GtkWidget *widget)
3388 {
3389         summary_mark_as_read(mainwin->summaryview);
3390 }
3391
3392 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3393                              GtkWidget *widget)
3394 {
3395         summary_mark_all_read(mainwin->summaryview);
3396 }
3397
3398 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3399                              GtkWidget *widget)
3400 {
3401         summary_mark_as_spam(mainwin->summaryview, action, NULL);
3402 }
3403
3404 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3405                             GtkWidget *widget)
3406 {
3407         summary_ignore_thread(mainwin->summaryview);
3408 }
3409
3410 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3411                             GtkWidget *widget)
3412 {
3413         summary_unignore_thread(mainwin->summaryview);
3414 }
3415
3416 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3417                             GtkWidget *widget)
3418 {
3419         summary_msgs_lock(mainwin->summaryview);
3420 }
3421
3422 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3423                             GtkWidget *widget)
3424 {
3425         summary_msgs_unlock(mainwin->summaryview);
3426 }
3427
3428
3429 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3430 {
3431         summary_reedit(mainwin->summaryview);
3432 }
3433
3434 static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3435 {
3436         if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
3437                 summary_display_msg_selected(mainwin->summaryview, 
3438                         mainwin->messageview->mimeview->textview->show_all_headers);
3439         }
3440         messageview_list_urls(mainwin->messageview);
3441 }
3442
3443 static void add_address_cb(MainWindow *mainwin, guint action,
3444                            GtkWidget *widget)
3445 {
3446         summary_add_address(mainwin->summaryview);
3447 }
3448
3449 static void set_charset_cb(MainWindow *mainwin, guint action,
3450                            GtkWidget *widget)
3451 {
3452         const gchar *str;
3453
3454         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3455                 str = conv_get_charset_str((CharSet)action);
3456                 
3457                 g_free(mainwin->messageview->forced_charset);
3458                 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3459                 procmime_force_charset(str);
3460                 
3461                 summary_redisplay_msg(mainwin->summaryview);
3462                 
3463                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3464         }
3465 }
3466
3467 static void set_decode_cb(MainWindow *mainwin, guint action,
3468                            GtkWidget *widget)
3469 {
3470         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3471                 mainwin->messageview->forced_encoding = (EncodingType)action;
3472                 
3473                 summary_redisplay_msg(mainwin->summaryview);
3474                 
3475                 debug_print("forced encoding: %d\n", action);
3476         }
3477 }
3478
3479 static void hide_read_messages (MainWindow *mainwin, guint action,
3480                                 GtkWidget *widget)
3481 {
3482         if (!mainwin->summaryview->folder_item
3483             || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3484                 return;
3485         summary_toggle_show_read_messages(mainwin->summaryview);
3486 }
3487
3488 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3489 {
3490         gboolean threaded = FALSE;
3491         if (mainwin->menu_lock_count) return;
3492         if (!mainwin->summaryview->folder_item) return;
3493
3494         threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3495
3496         mainwin->summaryview->folder_item->threaded = threaded; 
3497
3498         mainwin->summaryview->threaded = threaded;
3499
3500         summary_show(mainwin->summaryview, 
3501                         mainwin->summaryview->folder_item);
3502 }
3503
3504 static void expand_threads_cb(MainWindow *mainwin, guint action,
3505                               GtkWidget *widget)
3506 {
3507         summary_expand_threads(mainwin->summaryview);
3508 }
3509
3510 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3511                                 GtkWidget *widget)
3512 {
3513         summary_collapse_threads(mainwin->summaryview);
3514 }
3515
3516 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3517                                 GtkWidget *widget)
3518 {
3519         prefs_summary_column_open();
3520 }
3521
3522 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3523                                 GtkWidget *widget)
3524 {
3525         prefs_folder_column_open();
3526 }
3527
3528 static void sort_summary_cb(MainWindow *mainwin, guint action,
3529                             GtkWidget *widget)
3530 {
3531         FolderItem *item = mainwin->summaryview->folder_item;
3532         GtkWidget *menuitem;
3533
3534         if (mainwin->menu_lock_count) return;
3535
3536         if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3537                 menuitem = gtk_item_factory_get_item
3538                         (mainwin->menu_factory, "/View/Sort/Ascending");
3539                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3540                              GTK_CHECK_MENU_ITEM(menuitem)->active
3541                              ? SORT_ASCENDING : SORT_DESCENDING);
3542                 item->sort_key = action;
3543         }
3544 }
3545
3546 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3547                                  GtkWidget *widget)
3548 {
3549         FolderItem *item = mainwin->summaryview->folder_item;
3550
3551         if (mainwin->menu_lock_count) return;
3552
3553         if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3554                 summary_sort(mainwin->summaryview,
3555                              item->sort_key, (FolderSortType)action);
3556 }
3557
3558 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3559                                   GtkWidget *widget)
3560 {
3561         summary_attract_by_subject(mainwin->summaryview);
3562 }
3563
3564 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3565                                  GtkWidget *widget)
3566 {
3567         FolderItem *item;
3568
3569         item = folderview_get_selected_item(mainwin->folderview);
3570         if (item) {
3571                 main_window_cursor_wait(mainwin);
3572                 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3573
3574                 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3575                                               DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3576
3577                 STATUSBAR_POP(mainwin);
3578                 main_window_cursor_normal(mainwin);
3579         }
3580 }
3581
3582 struct DelDupsData
3583 {
3584         guint   dups;
3585         guint   folders;
3586 };
3587
3588 static void deldup_all(FolderItem *item, gpointer _data)
3589 {
3590         struct DelDupsData *data = _data;
3591         gint result;
3592         
3593         result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3594         if (result >= 0) {
3595                 data->dups += result;
3596                 data->folders += 1;
3597         }
3598 }
3599
3600 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3601                                  GtkWidget *widget)
3602 {
3603         struct DelDupsData data = {0, 0};
3604
3605         main_window_cursor_wait(mainwin);
3606         folder_func_to_all_folders(deldup_all, &data);
3607         main_window_cursor_normal(mainwin);
3608         
3609         alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3610                                    "Deleted %d duplicate messages in %d folders.\n",
3611                                    data.dups),
3612                           data.dups, data.folders);
3613 }
3614
3615 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3616 {
3617         summary_filter(mainwin->summaryview, (gboolean)action);
3618 }
3619
3620 static void execute_summary_cb(MainWindow *mainwin, guint action,
3621                                GtkWidget *widget)
3622 {
3623         summary_execute(mainwin->summaryview);
3624 }
3625
3626 static void update_summary_cb(MainWindow *mainwin, guint action,
3627                               GtkWidget *widget)
3628 {
3629         FolderItem *fitem;
3630         FolderView *folderview = mainwin->folderview;
3631
3632         if (!mainwin->summaryview->folder_item) return;
3633         if (!folderview->opened) return;
3634
3635         folder_update_op_count();
3636
3637         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3638                                             folderview->opened);
3639         if (!fitem) return;
3640
3641         folder_item_scan(fitem);
3642         summary_show(mainwin->summaryview, fitem);
3643 }
3644
3645 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3646 {
3647         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3648 }
3649
3650 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3651 {
3652         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3653 }
3654
3655 static void prev_unread_cb(MainWindow *mainwin, guint action,
3656                            GtkWidget *widget)
3657 {
3658         summary_select_prev_unread(mainwin->summaryview);
3659 }
3660
3661 static void next_unread_cb(MainWindow *mainwin, guint action,
3662                            GtkWidget *widget)
3663 {
3664         summary_select_next_unread(mainwin->summaryview);
3665 }
3666
3667 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3668 {
3669         summary_select_prev_new(mainwin->summaryview);
3670 }
3671
3672 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3673 {
3674         summary_select_next_new(mainwin->summaryview);
3675 }
3676
3677 static void prev_marked_cb(MainWindow *mainwin, guint action,
3678                            GtkWidget *widget)
3679 {
3680         summary_select_prev_marked(mainwin->summaryview);
3681 }
3682
3683 static void next_marked_cb(MainWindow *mainwin, guint action,
3684                            GtkWidget *widget)
3685 {
3686         summary_select_next_marked(mainwin->summaryview);
3687 }
3688
3689 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3690                             GtkWidget *widget)
3691 {
3692         summary_select_prev_labeled(mainwin->summaryview);
3693 }
3694
3695 static void next_labeled_cb(MainWindow *mainwin, guint action,
3696                             GtkWidget *widget)
3697 {
3698         summary_select_next_labeled(mainwin->summaryview);
3699 }
3700
3701 static void last_read_cb(MainWindow *mainwin, guint action,
3702                             GtkWidget *widget)
3703 {
3704         summary_select_last_read(mainwin->summaryview);
3705 }
3706
3707 static void parent_cb(MainWindow *mainwin, guint action,
3708                             GtkWidget *widget)
3709 {
3710         summary_select_parent(mainwin->summaryview);
3711 }
3712
3713 static void goto_folder_cb(MainWindow *mainwin, guint action,
3714                            GtkWidget *widget)
3715 {
3716         FolderItem *to_folder;
3717
3718         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
3719
3720         if (to_folder)
3721                 folderview_select(mainwin->folderview, to_folder);
3722 }
3723
3724 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
3725                            GtkWidget *widget)
3726 {
3727         folderview_select_next_unread(mainwin->folderview, FALSE);
3728 }
3729
3730 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3731 {
3732         messageview_copy_clipboard(mainwin->messageview);
3733 }
3734
3735 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3736 {
3737         MessageView *msgview = mainwin->messageview;
3738
3739         if (messageview_is_visible(msgview) &&
3740                  (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3741                 messageview_select_all(mainwin->messageview);
3742         else
3743                 summary_select_all(mainwin->summaryview);
3744 }
3745
3746 static void select_thread_cb(MainWindow *mainwin, guint action,
3747                              GtkWidget *widget)
3748 {
3749         summary_select_thread(mainwin->summaryview, FALSE);
3750 }
3751
3752 static void delete_thread_cb(MainWindow *mainwin, guint action,
3753                              GtkWidget *widget)
3754 {
3755         summary_select_thread(mainwin->summaryview, TRUE);
3756 }
3757
3758 static void create_filter_cb(MainWindow *mainwin, guint action,
3759                              GtkWidget *widget)
3760 {
3761         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
3762 }
3763
3764 static void create_processing_cb(MainWindow *mainwin, guint action,
3765                              GtkWidget *widget)
3766 {
3767         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
3768 }
3769
3770 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
3771                                          GtkWidget *widget)
3772 {
3773         prefs_filtering_open(&pre_global_processing,
3774                              _("Processing rules to apply before folder rules"),
3775                              MANUAL_ANCHOR_PROCESSING,
3776                              NULL, NULL, FALSE);
3777 }
3778
3779 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
3780                                           GtkWidget *widget)
3781 {
3782         prefs_filtering_open(&post_global_processing,
3783                              _("Processing rules to apply after folder rules"),
3784                              MANUAL_ANCHOR_PROCESSING,
3785                              NULL, NULL, FALSE);
3786 }
3787
3788 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
3789                                     GtkWidget *widget)
3790 {
3791         prefs_filtering_open(&filtering_rules,
3792                              _("Filtering configuration"),
3793                              MANUAL_ANCHOR_FILTERING,
3794                              NULL, NULL, TRUE);
3795 }
3796
3797 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
3798                                    GtkWidget *widget)
3799 {
3800         prefs_template_open();
3801 }
3802
3803 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
3804                                   GtkWidget *widget)
3805 {
3806         prefs_actions_open(mainwin);
3807 }
3808 #ifdef USE_OPENSSL
3809 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
3810                                   GtkWidget *widget)
3811 {
3812         ssl_manager_open(mainwin);
3813 }
3814 #endif
3815 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
3816                                   GtkWidget *widget)
3817 {
3818         if (!cur_account) {
3819                 new_account_cb(mainwin, 0, widget);
3820         } else {
3821                 account_open(cur_account);
3822         }
3823 }
3824
3825 static void new_account_cb(MainWindow *mainwin, guint action,
3826                            GtkWidget *widget)
3827 {
3828         account_edit_open();
3829         if (!compose_get_compose_list()) account_add();
3830 }
3831
3832 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
3833 {
3834         FolderItem *item = NULL;
3835         cur_account = (PrefsAccount *)data;
3836         
3837         if (!mainwindow_get_mainwindow())
3838                 return;
3839         main_window_show_cur_account(mainwindow_get_mainwindow());
3840         toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
3841         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
3842         toolbar_main_set_sensitive(mainwindow_get_mainwindow());
3843         item = folderview_get_selected_item(
3844                         mainwindow_get_mainwindow()->folderview);
3845         if (item) {
3846                 toolbar_set_compose_button
3847                         (mainwindow_get_mainwindow()->toolbar,
3848                          FOLDER_TYPE(item->folder) == F_NEWS ? 
3849                          COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
3850         }
3851 }
3852
3853 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
3854 {
3855         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3856         PrefsAccount *account = (PrefsAccount *)data;
3857
3858         inc_account_mail(mainwin, account);
3859 }
3860
3861 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
3862 {
3863         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3864         PrefsAccount *account = (PrefsAccount *)data;
3865         FolderItem *item = mainwin->summaryview->folder_item;   
3866
3867         compose_new_with_folderitem(account, item, NULL);
3868 }
3869
3870 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
3871 {
3872         prefs_gtk_open();
3873 }
3874
3875 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
3876 {
3877         pluginwindow_create();
3878 }
3879
3880 static void manual_open_cb(MainWindow *mainwin, guint action,
3881                            GtkWidget *widget)
3882 {
3883         manual_open((ManualType)action, NULL);
3884 }
3885
3886 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
3887 {
3888         legend_show();
3889 }
3890
3891 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
3892 {
3893         MainWindow *mainwin = (MainWindow *)data;
3894         gchar *str;
3895
3896         if (item->path)
3897                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
3898                                       LOCAL_FOLDER(folder)->rootpath,
3899                                       G_DIR_SEPARATOR,
3900                                       item->path);
3901         else
3902                 str = g_strdup_printf(_("Scanning folder %s ..."),
3903                                       LOCAL_FOLDER(folder)->rootpath);
3904
3905         STATUSBAR_PUSH(mainwin, str);
3906         STATUSBAR_POP(mainwin);
3907         g_free(str);
3908 }
3909
3910 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
3911                                           gpointer data)
3912 {
3913         SummaryView *summary;
3914
3915         g_return_val_if_fail(data, FALSE);
3916         if (!g_list_find(mainwin_list, data))
3917                 return TRUE;
3918         summary = ((MainWindow *)data)->summaryview;
3919         g_return_val_if_fail(summary, FALSE);
3920
3921         if (GTK_CLIST(summary->ctree)->selection && 
3922             g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
3923                 return FALSE;
3924
3925         return FALSE;
3926 }
3927
3928 static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
3929                                           gpointer data)
3930 {
3931         is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
3932         return FALSE;
3933 }
3934
3935 static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
3936                                           gpointer data)
3937 {
3938         if (!claws_is_starting()
3939                 && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
3940                 && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
3941
3942                 if (iconified_count > 0)
3943                         hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
3944                 iconified_count++;
3945         }
3946         if (state->new_window_state == 0)
3947                 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
3948         return FALSE;
3949 }
3950
3951 gboolean mainwindow_is_obscured(void)
3952 {
3953         return is_obscured;
3954 }
3955
3956 #define BREAK_ON_MODIFIER_KEY() \
3957         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
3958
3959 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
3960                                     gpointer data)
3961 {
3962         MainWindow *mainwin = (MainWindow*) data;
3963         
3964         if (!mainwin || !event) 
3965                 return FALSE;
3966
3967         if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
3968         {
3969                 lastkey = event->keyval;
3970                 return FALSE;
3971         }
3972
3973         switch (event->keyval) {
3974         case GDK_Q:             /* Quit */
3975                 BREAK_ON_MODIFIER_KEY();
3976
3977                 app_exit_cb(mainwin, 0, NULL);
3978                 return FALSE;
3979         case GDK_space:
3980                 if (mainwin->folderview && mainwin->summaryview
3981                     && ((!mainwin->summaryview->displayed
3982                         && !mainwin->summaryview->selected) 
3983                         || (mainwin->summaryview->folder_item
3984                             && mainwin->summaryview->folder_item->total_msgs == 0))) {
3985                         g_signal_stop_emission_by_name(G_OBJECT(widget), 
3986                                        "key_press_event");
3987                         folderview_select_next_unread(mainwin->folderview, TRUE);
3988                 }
3989                 break;
3990 #ifdef MAEMO
3991         case GDK_F6:
3992                 if (maemo_mainwindow_is_fullscreen(widget)) {
3993                         gtk_window_unfullscreen(GTK_WINDOW(widget));
3994                 } else {
3995                         gtk_window_fullscreen(GTK_WINDOW(widget));
3996                 }
3997                 break;
3998 #endif
3999         default:
4000                 break;
4001         }
4002         return FALSE;
4003 }
4004
4005 #undef BREAK_ON_MODIFIER_KEY
4006
4007 /*
4008  * Harvest addresses for selected folder.
4009  */
4010 static void addr_harvest_cb( MainWindow *mainwin,
4011                             guint action,
4012                             GtkWidget *widget )
4013 {
4014         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
4015 }
4016
4017 /*
4018  * Harvest addresses for selected messages in summary view.
4019  */
4020 static void addr_harvest_msg_cb( MainWindow *mainwin,
4021                             guint action,
4022                             GtkWidget *widget )
4023 {
4024         summary_harvest_address( mainwin->summaryview );
4025 }
4026
4027 /*!
4028  *\brief        get a MainWindow
4029  *
4030  *\return       MainWindow * The first mainwindow in the mainwin_list
4031  */
4032 MainWindow *mainwindow_get_mainwindow(void)
4033 {
4034         if (mainwin_list && mainwin_list->data)
4035                 return (MainWindow *)(mainwin_list->data);
4036         else
4037                 return NULL;
4038 }
4039
4040 static gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
4041 {
4042         ProgressData *data = (ProgressData *) source;
4043         MainWindow *mainwin = (MainWindow *) userdata;
4044
4045         switch (data->cmd) {
4046         case PROGRESS_COMMAND_START:
4047         case PROGRESS_COMMAND_STOP:
4048                 gtk_progress_bar_set_fraction
4049                         (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
4050                 break;
4051         case PROGRESS_COMMAND_SET_PERCENTAGE:
4052                 gtk_progress_bar_set_fraction
4053                         (GTK_PROGRESS_BAR(mainwin->progressbar), data->value);
4054                 break;          
4055         }
4056         while (gtk_events_pending()) gtk_main_iteration ();
4057
4058         return FALSE;
4059 }
4060
4061 static void sync_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
4062 {
4063         mainwindow_check_synchronise(mainwin, FALSE);
4064 }
4065
4066 void mainwindow_learn (MainWindow *mainwin, gboolean is_spam)
4067 {
4068         summary_mark_as_spam(mainwin->summaryview, is_spam, NULL);
4069 }
4070
4071 void mainwindow_jump_to(const gchar *target)
4072 {
4073         gchar *tmp = NULL;
4074         gchar *p = NULL;
4075         FolderItem *item = NULL;
4076         gchar *msg = NULL;
4077         MainWindow *mainwin = mainwindow_get_mainwindow();
4078         
4079         if (!target)
4080                 return;
4081                 
4082         if (!mainwin) {
4083                 printf("not initialized\n");
4084                 return;
4085         }
4086
4087         tmp = g_strdup(target);
4088         
4089         if ((p = strstr(tmp, "\r")) != NULL)
4090                 *p = '\0';
4091         if ((p = strstr(tmp, "\n")) != NULL)
4092                 *p = '\0';
4093
4094         if ((item = folder_find_item_from_identifier(tmp))) {
4095                 printf("selecting folder '%s'\n", tmp);
4096                 folderview_select(mainwin->folderview, item);
4097                 main_window_popup(mainwin);
4098                 g_free(tmp);
4099                 return;
4100         }
4101         
4102         msg = strrchr(tmp, G_DIR_SEPARATOR);
4103         if (msg) {
4104                 *msg++ = '\0';
4105                 if ((item = folder_find_item_from_identifier(tmp))) {
4106                         printf("selecting folder '%s'\n", tmp);
4107                         folderview_select(mainwin->folderview, item);
4108                 } else {
4109                         printf("'%s' not found\n", tmp);
4110                 }
4111                 if (item && msg && atoi(msg)) {
4112                         printf("selecting message %d\n", atoi(msg));
4113                         summary_select_by_msgnum(mainwin->summaryview, atoi(msg));
4114                         summary_display_msg_selected(mainwin->summaryview, FALSE);
4115                         main_window_popup(mainwin);
4116                         g_free(tmp);
4117                         return;
4118                 } else if (item && msg[0] == '<' && msg[strlen(msg)-1] == '>') {
4119                         MsgInfo *msginfo = NULL;
4120                         msg++;
4121                         msg[strlen(msg)-1] = '\0';
4122                         msginfo = folder_item_get_msginfo_by_msgid(item, msg);
4123                         if (msginfo) {
4124                                 printf("selecting message %s\n", msg);
4125                                 summary_select_by_msgnum(mainwin->summaryview, msginfo->msgnum);
4126                                 summary_display_msg_selected(mainwin->summaryview, FALSE);
4127                                 main_window_popup(mainwin);
4128                                 g_free(tmp);
4129                                 procmsg_msginfo_free(msginfo);
4130                                 return;
4131                         } else {
4132                                 printf("'%s' not found\n", msg);
4133                         }
4134                 } else {
4135                         printf("'%s' not found\n", msg);
4136                 }
4137         } else {
4138                 printf("'%s' not found\n", tmp);
4139         }
4140         
4141         g_free(tmp);
4142 }
4143
4144 void mainwindow_exit_folder(MainWindow *mainwin) {
4145         if (prefs_common.layout_mode == SMALL_LAYOUT) {
4146                 folderview_close_opened(mainwin->folderview);
4147                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
4148                 mainwin->in_folder = FALSE;
4149         }
4150 }
4151
4152 void mainwindow_enter_folder(MainWindow *mainwin) {
4153         if (prefs_common.layout_mode == SMALL_LAYOUT) {
4154                 mainwin_paned_show_last(GTK_PANED(mainwin->hpaned));
4155                 mainwin->in_folder = TRUE;
4156         }
4157 }
4158
4159 #ifdef MAEMO
4160 gboolean maemo_mainwindow_is_fullscreen(GtkWidget *widget)
4161 {
4162         gint w, h;
4163         gtk_window_get_size(GTK_WINDOW(widget), &w, &h); 
4164         return (w == 800);
4165 }
4166
4167 void maemo_window_full_screen_if_needed (GtkWindow *window)
4168 {
4169         if (maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window)) {
4170                 gtk_window_fullscreen(GTK_WINDOW(window));
4171         }
4172 }
4173
4174 void maemo_connect_key_press_to_mainwindow (GtkWindow *window)
4175 {
4176         g_signal_connect(G_OBJECT(window), "key_press_event",
4177                          G_CALLBACK(mainwindow_key_pressed), mainwindow_get_mainwindow());
4178 }
4179 #endif