853bcc3e8d26b9f8229c89b6bede9d25207e58af
[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/---"),                      NULL, NULL, 0, "<Separator>"},
569         {N_("/_View/_Sort"),                    NULL, NULL, 0, "<Branch>"},
570         {N_("/_View/_Sort/by _number"),         NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
571         {N_("/_View/_Sort/by S_ize"),           NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
572         {N_("/_View/_Sort/by _Date"),           NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
573         {N_("/_View/_Sort/by _From"),           NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
574         {N_("/_View/_Sort/by _To"),             NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
575         {N_("/_View/_Sort/by S_ubject"),        NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
576         {N_("/_View/_Sort/by _color label"),
577                                                 NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
578         {N_("/_View/_Sort/by _mark"),           NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
579         {N_("/_View/_Sort/by _status"),         NULL, sort_summary_cb, SORT_BY_STATUS, "/View/Sort/by number"},
580         {N_("/_View/_Sort/by a_ttachment"),
581                                                 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
582         {N_("/_View/_Sort/by score"),           NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
583         {N_("/_View/_Sort/by locked"),          NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
584         {N_("/_View/_Sort/D_on't sort"),        NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
585         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
586         {N_("/_View/_Sort/Ascending"),          NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
587         {N_("/_View/_Sort/Descending"),         NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
588         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
589         {N_("/_View/_Sort/_Attract by subject"),
590                                                 NULL, attract_by_subject_cb, 0, NULL},
591         {N_("/_View/Th_read view"),             "<control>T", thread_cb, 0, "<ToggleItem>"},
592         {N_("/_View/E_xpand all threads"),      NULL, expand_threads_cb, 0, NULL},
593         {N_("/_View/Co_llapse all threads"),    NULL, collapse_threads_cb, 0, NULL},
594         {N_("/_View/_Hide read messages"),      NULL, hide_read_messages, 0, "<ToggleItem>"},
595
596         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
597         {N_("/_View/_Go to"),                   NULL, NULL, 0, "<Branch>"},
598         {N_("/_View/_Go to/_Previous message"), "P", prev_cb, 0, NULL},
599         {N_("/_View/_Go to/_Next message"),     "N", next_cb, 0, NULL},
600         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
601         {N_("/_View/_Go to/P_revious unread message"),
602                                                 "<shift>P", prev_unread_cb, 0, NULL},
603         {N_("/_View/_Go to/N_ext unread message"),
604                                                 "<shift>N", next_unread_cb, 0, NULL},
605         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
606         {N_("/_View/_Go to/Previous ne_w message"),     NULL, prev_new_cb, 0, NULL},
607         {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
608         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
609         {N_("/_View/_Go to/Previous _marked message"),
610                                                 NULL, prev_marked_cb, 0, NULL},
611         {N_("/_View/_Go to/Next m_arked message"),
612                                                 NULL, next_marked_cb, 0, NULL},
613         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
614         {N_("/_View/_Go to/Previous _labeled message"),
615                                                 NULL, prev_labeled_cb, 0, NULL},
616         {N_("/_View/_Go to/Next la_beled message"),
617                                                 NULL, next_labeled_cb, 0, NULL},
618         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
619         {N_("/_View/_Go to/Last read message"),
620                                                 NULL, last_read_cb, 0, NULL},
621         {N_("/_View/_Go to/Parent message"),
622                                                 "<control>Up", parent_cb, 0, NULL},
623         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
624         {N_("/_View/_Go to/Next unread _folder"),       "<shift>G", goto_unread_folder_cb, 0, NULL},
625         {N_("/_View/_Go to/_Other folder..."),  "G", goto_folder_cb, 0, NULL},
626         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
627
628 #define ENC_SEPARATOR \
629         {N_("/_View/Character _encoding/---"),          NULL, NULL, 0, "<Separator>"}
630 #define ENC_ACTION(action) \
631          NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
632
633         {N_("/_View/Character _encoding"),              NULL, NULL, 0, "<Branch>"},
634         {N_("/_View/Character _encoding/_Auto detect"),
635          NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
636         {N_("/_View/Character _encoding/---"),          NULL, NULL, 0, "<Separator>"},
637         {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
638          ENC_ACTION(C_US_ASCII)},
639         {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
640          ENC_ACTION(C_UTF_8)},
641         ENC_SEPARATOR,
642
643         {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
644          ENC_ACTION(C_ISO_8859_1)},
645         {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
646          ENC_ACTION(C_ISO_8859_15)},
647         {N_("/_View/Character _encoding/Western European (Windows-1252)"),
648          ENC_ACTION(C_WINDOWS_1252)},
649         ENC_SEPARATOR,
650
651         {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
652          ENC_ACTION(C_ISO_8859_2)},
653         ENC_SEPARATOR,
654
655         {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
656          ENC_ACTION(C_ISO_8859_13)},
657         {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
658          ENC_ACTION(C_ISO_8859_4)},
659         ENC_SEPARATOR,
660
661         {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
662          ENC_ACTION(C_ISO_8859_7)},
663         ENC_SEPARATOR,
664
665         {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
666          ENC_ACTION(C_ISO_8859_8)},
667         {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
668          ENC_ACTION(C_CP1255)},
669         ENC_SEPARATOR,
670
671         {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
672          ENC_ACTION(C_ISO_8859_6)},
673         {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
674          ENC_ACTION(C_CP1256)},
675         ENC_SEPARATOR,
676
677         {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
678          ENC_ACTION(C_ISO_8859_9)},
679         ENC_SEPARATOR,
680
681         {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
682          ENC_ACTION(C_ISO_8859_5)},
683         {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
684          ENC_ACTION(C_KOI8_R)},
685         {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
686          ENC_ACTION(C_KOI8_U)},
687         {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
688          ENC_ACTION(C_CP1251)},
689         ENC_SEPARATOR,
690
691         {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
692          ENC_ACTION(C_ISO_2022_JP)},
693         {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
694          ENC_ACTION(C_ISO_2022_JP_2)},
695         {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
696          ENC_ACTION(C_EUC_JP)},
697         {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
698          ENC_ACTION(C_SHIFT_JIS)},
699         ENC_SEPARATOR,
700
701         {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
702          ENC_ACTION(C_GB2312)},
703         {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
704          ENC_ACTION(C_GBK)},
705         {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
706          ENC_ACTION(C_BIG5)},
707         {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
708          ENC_ACTION(C_EUC_TW)},
709         {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
710          ENC_ACTION(C_ISO_2022_CN)},
711         ENC_SEPARATOR,
712
713         {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
714          ENC_ACTION(C_EUC_KR)},
715         {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
716          ENC_ACTION(C_ISO_2022_KR)},
717         ENC_SEPARATOR,
718
719         {N_("/_View/Character _encoding/Thai (TIS-620)"),
720          ENC_ACTION(C_TIS_620)},
721         {N_("/_View/Character _encoding/Thai (Windows-874)"),
722          ENC_ACTION(C_WINDOWS_874)},
723
724 #undef ENC_SEPARATOR
725 #undef ENC_ACTION
726
727 #define DEC_SEPARATOR \
728         {N_("/_View/Decode/---"),               NULL, NULL, 0, "<Separator>"}
729 #define DEC_ACTION(action) \
730          NULL, set_decode_cb, action, "/View/Decode/Auto detect"
731         {N_("/_View/Decode"),           NULL, NULL, 0, "<Branch>"},
732         {N_("/_View/Decode/_Auto detect"),
733          NULL, set_decode_cb, 0, "<RadioItem>"},
734         {N_("/_View/Decode/---"),               NULL, NULL, 0, "<Separator>"},
735         {N_("/_View/Decode/_8bit"),             DEC_ACTION(ENC_8BIT)},
736         {N_("/_View/Decode/_Quoted printable"), DEC_ACTION(ENC_QUOTED_PRINTABLE)},
737         {N_("/_View/Decode/_Base64"),           DEC_ACTION(ENC_BASE64)},
738         {N_("/_View/Decode/_Uuencode"),         DEC_ACTION(ENC_X_UUENCODE)},
739
740 #undef DEC_SEPARATOR
741 #undef DEC_ACTION
742
743         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
744         {N_("/_View/Open in new _window"),      "<control><alt>N", open_msg_cb, 0, NULL},
745         {N_("/_View/Mess_age source"),          "<control>U", view_source_cb, 0, NULL},
746         {N_("/_View/All headers"),              "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
747         {N_("/_View/Quotes"),                   NULL, NULL, 0, "<Branch>"},
748         {N_("/_View/Quotes/_Fold all"),         "<control><shift>Q", hide_quotes_cb, 1, "<ToggleItem>"},
749         {N_("/_View/Quotes/Fold from level _2"),NULL, hide_quotes_cb, 2, "<ToggleItem>"},
750         {N_("/_View/Quotes/Fold from level _3"),NULL, hide_quotes_cb, 3, "<ToggleItem>"},
751         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
752         {N_("/_View/_Update summary"),          "<control><alt>U", update_summary_cb,  0, NULL},
753
754         {N_("/_Message"),                       NULL, NULL, 0, "<Branch>"},
755         {N_("/_Message/Recei_ve"),              NULL, NULL, 0, "<Branch>"},
756         {N_("/_Message/Recei_ve/Get from _current account"),
757                                                 "<control>I",   inc_mail_cb, 0, NULL},
758         {N_("/_Message/Recei_ve/Get from _all accounts"),
759                                                 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
760         {N_("/_Message/Recei_ve/Cancel receivin_g"),
761                                                 NULL, inc_cancel_cb, 0, NULL},
762         {N_("/_Message/Recei_ve/---"),          NULL, NULL, 0, "<Separator>"},
763         {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
764         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
765         {N_("/_Message/Compose a_n email message"),     "<control>M", compose_mail_cb, 0, NULL},
766         {N_("/_Message/Compose a news message"),        NULL,   compose_news_cb, 0, NULL},
767         {N_("/_Message/_Reply"),                "<control>R",   main_window_reply_cb, COMPOSE_REPLY, NULL},
768         {N_("/_Message/Repl_y to"),             NULL, NULL, 0, "<Branch>"},
769         {N_("/_Message/Repl_y to/_all"),        "<shift><control>R", main_window_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
770         {N_("/_Message/Repl_y to/_sender"),     NULL, main_window_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
771         {N_("/_Message/Repl_y to/mailing _list"),
772                                                 "<control>L", main_window_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
773         {N_("/_Message/Follow-up and reply to"),NULL, main_window_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
774         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
775         {N_("/_Message/_Forward"),              "<control><alt>F", main_window_reply_cb, COMPOSE_FORWARD_INLINE, NULL},
776         {N_("/_Message/For_ward as attachment"),        NULL, main_window_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
777         {N_("/_Message/Redirect"),              NULL, main_window_reply_cb, COMPOSE_REDIRECT, NULL},
778
779         {N_("/_Message/Mailing-_List"),                 NULL, NULL, 0, "<Branch>"},
780         {N_("/_Message/Mailing-_List/Post"),            NULL, NULL, 0, "<Branch>"},
781         {N_("/_Message/Mailing-_List/Help"),            NULL, NULL, 0, "<Branch>"},
782         {N_("/_Message/Mailing-_List/Subscribe"),       NULL, NULL, 0, "<Branch>"},
783         {N_("/_Message/Mailing-_List/Unsubscribe"),     NULL, NULL, 0, "<Branch>"},
784         {N_("/_Message/Mailing-_List/View archive"),    NULL, NULL, 0, "<Branch>"},
785         {N_("/_Message/Mailing-_List/Contact owner"),   NULL, NULL, 0, "<Branch>"},
786         
787         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
788         {N_("/_Message/M_ove..."),              "<control>O", move_to_cb, 0, NULL},
789         {N_("/_Message/_Copy..."),              "<shift><control>O", copy_to_cb, 0, NULL},
790         {N_("/_Message/Move to _trash"),        "<control>D", delete_trash_cb,  0, NULL},
791         {N_("/_Message/_Delete..."),            NULL, delete_cb,  0, NULL},
792         {N_("/_Message/Cancel a news message"), "", cancel_cb,  0, NULL},
793         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
794         {N_("/_Message/_Mark"),                 NULL, NULL, 0, "<Branch>"},
795         {N_("/_Message/_Mark/_Mark"),           "<shift>asterisk", mark_cb, 0, NULL},
796         {N_("/_Message/_Mark/_Unmark"),         "U", unmark_cb, 0, NULL},
797         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
798         {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
799         {N_("/_Message/_Mark/Mark as rea_d"),   NULL, mark_as_read_cb, 0, NULL},
800         {N_("/_Message/_Mark/Mark all _read"),  NULL, mark_all_read_cb, 0, NULL},
801         {N_("/_Message/_Mark/Ignore thread"),   NULL, ignore_thread_cb, 0, NULL},
802         {N_("/_Message/_Mark/Unignore thread"), NULL, unignore_thread_cb, 0, NULL},
803         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
804         {N_("/_Message/_Mark/Mark as _spam"),   NULL, mark_as_spam_cb, 1, NULL},
805         {N_("/_Message/_Mark/Mark as _ham"),    NULL, mark_as_spam_cb, 0, NULL},
806         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
807         {N_("/_Message/_Mark/Lock"),            NULL, lock_msgs_cb, 0, NULL},
808         {N_("/_Message/_Mark/Unlock"),          NULL, unlock_msgs_cb, 0, NULL},
809         {N_("/_Message/Color la_bel"),          NULL, NULL,            0, NULL},
810         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
811         {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
812
813         {N_("/_Tools"),                         NULL, NULL, 0, "<Branch>"},
814         {N_("/_Tools/_Address book..."),        "<shift><control>A", addressbook_open_cb, 0, NULL},
815         {N_("/_Tools/Add sender to address boo_k"),
816                                                 NULL, add_address_cb, 0, NULL},
817         {N_("/_Tools/_Harvest addresses"),      NULL, NULL, 0, "<Branch>"},
818         {N_("/_Tools/_Harvest addresses/from _Folder..."),
819                                                 NULL, addr_harvest_cb, 0, NULL},
820         {N_("/_Tools/_Harvest addresses/from _Messages..."),
821                                                 NULL, addr_harvest_msg_cb, 0, NULL},
822         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
823         {N_("/_Tools/_Filter all messages in folder"),
824                                                 NULL, filter_cb, 0, NULL},
825         {N_("/_Tools/Filter _selected messages"),
826                                                 NULL, filter_cb, 1, NULL},
827         {N_("/_Tools/_Create filter rule"),     NULL, NULL, 0, "<Branch>"},
828         {N_("/_Tools/_Create filter rule/_Automatically"),
829                                                 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
830         {N_("/_Tools/_Create filter rule/by _From"),
831                                                 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
832         {N_("/_Tools/_Create filter rule/by _To"),
833                                                 NULL, create_filter_cb, FILTER_BY_TO, NULL},
834         {N_("/_Tools/_Create filter rule/by _Subject"),
835                                                 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
836         {N_("/_Tools/C_reate processing rule"), NULL, NULL, 0, "<Branch>"},
837         {N_("/_Tools/C_reate processing rule/_Automatically"),
838                                                 NULL, create_processing_cb, FILTER_BY_AUTO, NULL},
839         {N_("/_Tools/C_reate processing rule/by _From"),
840                                                 NULL, create_processing_cb, FILTER_BY_FROM, NULL},
841         {N_("/_Tools/C_reate processing rule/by _To"),
842                                                 NULL, create_processing_cb, FILTER_BY_TO, NULL},
843         {N_("/_Tools/C_reate processing rule/by _Subject"),
844                                                 NULL, create_processing_cb, FILTER_BY_SUBJECT, NULL},
845         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
846         {N_("/_Tools/List _URLs..."),           "<shift><control>U", open_urls_cb, 0, NULL},
847         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
848         {N_("/_Tools/Actio_ns"),                NULL, NULL, 0, "<Branch>"},
849         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
850         {N_("/_Tools/Ch_eck for new messages in all folders"),
851                                                 NULL, update_folderview_cb, 0, NULL},
852         {N_("/_Tools/Delete du_plicated messages"),
853                                                 NULL, NULL, 0, "<Branch>"},
854         {N_("/_Tools/Delete du_plicated messages/In selected folder"),
855                                                 NULL, delete_duplicated_cb,   0, NULL},
856         {N_("/_Tools/Delete du_plicated messages/In all folders"),
857                                                 NULL, delete_duplicated_all_cb,   0, NULL},
858         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
859         {N_("/_Tools/E_xecute"),                "X", execute_summary_cb, 0, NULL},
860 #ifdef USE_OPENSSL
861         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
862         {N_("/_Tools/SSL cer_tificates..."),    
863                                                 NULL, ssl_manager_open_cb, 0, NULL},
864 #endif
865         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
866         {N_("/_Tools/Filtering debug window"),  NULL, filtering_debug_window_show_cb, 0, NULL},
867         {N_("/_Tools/_Log window"),             "<shift><control>L", log_window_show_cb, 0, NULL},
868
869         {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
870         {N_("/_Configuration/C_hange current account"),
871                                                 NULL, NULL, 0, "<Branch>"},
872         {N_("/_Configuration/_Preferences for current account..."),
873                                                 NULL, prefs_account_open_cb, 0, NULL},
874         {N_("/_Configuration/Create _new account..."),
875                                                 NULL, new_account_cb, 0, NULL},
876         {N_("/_Configuration/_Edit accounts..."),
877                                                 NULL, account_edit_open, 0, NULL},
878         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
879         {N_("/_Configuration/P_references..."),
880                                                 NULL, prefs_open_cb, 0, NULL},
881         {N_("/_Configuration/Pre-pr_ocessing..."),
882                                                 NULL, prefs_pre_processing_open_cb, 0, NULL},
883         {N_("/_Configuration/Post-pro_cessing..."),
884                                                 NULL, prefs_post_processing_open_cb, 0, NULL},
885         {N_("/_Configuration/_Filtering..."),
886                                                 NULL, prefs_filtering_open_cb, 0, NULL},
887         {N_("/_Configuration/_Templates..."),   NULL, prefs_template_open_cb, 0, NULL},
888         {N_("/_Configuration/_Actions..."),     NULL, prefs_actions_open_cb, 0, NULL},
889         {N_("/_Configuration/Plu_gins..."),     NULL, plugins_open_cb, 0, NULL},
890
891         {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
892         {N_("/_Help/_Manual"),                  NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
893         {N_("/_Help/_Online User-contributed FAQ"),     
894                                                 NULL, manual_open_cb, MANUAL_FAQ_CLAWS, NULL},
895         {N_("/_Help/Icon _Legend"),             NULL, legend_open_cb, 0, NULL},
896         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
897         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
898 };
899
900 static gboolean offline_ask_sync = TRUE;
901 static guint lastkey;
902 static gboolean is_obscured = FALSE;
903
904 static gboolean main_window_accel_activate (GtkAccelGroup *accelgroup,
905                                             GObject *arg1,
906                                             guint value,
907                                             GdkModifierType mod,
908                                             gpointer user_data) 
909 {
910         MainWindow *mainwin = (MainWindow *)user_data;
911
912         if (mainwin->summaryview &&
913             mainwin->summaryview->quicksearch &&
914             quicksearch_has_focus(mainwin->summaryview->quicksearch) &&
915             (mod == 0 || mod == GDK_SHIFT_MASK)) {
916                 quicksearch_pass_key(mainwin->summaryview->quicksearch, lastkey, mod);
917                 return TRUE;
918         }
919         return FALSE;
920 }
921
922 #define N_COLOR_LABELS colorlabel_get_color_count()
923
924 static void mainwindow_colorlabel_menu_item_activate_item_cb(GtkMenuItem *menu_item,
925                                                           gpointer data)
926 {
927         MainWindow *mainwin;
928         GtkMenuShell *menu;
929         GtkCheckMenuItem **items;
930         gint n;
931         GList *cur;
932         GSList *sel;
933
934         mainwin = (MainWindow *)data;
935         g_return_if_fail(mainwin != NULL);
936
937         sel = summary_get_selection(mainwin->summaryview);
938         if (!sel) return;
939
940         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
941         g_return_if_fail(menu != NULL);
942
943         Xalloca(items, (N_COLOR_LABELS + 1) * sizeof(GtkWidget *), return);
944
945         /* NOTE: don't return prematurely because we set the "dont_toggle"
946          * state for check menu items */
947         g_object_set_data(G_OBJECT(menu), "dont_toggle",
948                           GINT_TO_POINTER(1));
949
950         /* clear items. get item pointers. */
951         for (n = 0, cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
952                 if (GTK_IS_CHECK_MENU_ITEM(cur->data)) {
953                         gtk_check_menu_item_set_active
954                                 (GTK_CHECK_MENU_ITEM(cur->data), FALSE);
955                         items[n] = GTK_CHECK_MENU_ITEM(cur->data);
956                         n++;
957                 }
958         }
959
960         if (n == (N_COLOR_LABELS + 1)) {
961                 /* iterate all messages and set the state of the appropriate
962                  * items */
963                 for (; sel != NULL; sel = sel->next) {
964                         MsgInfo *msginfo;
965                         gint clabel;
966
967                         msginfo = (MsgInfo *)sel->data;
968                         if (msginfo) {
969                                 clabel = MSG_GET_COLORLABEL_VALUE(msginfo->flags);
970                                 if (!items[clabel]->active)
971                                         gtk_check_menu_item_set_active
972                                                 (items[clabel], TRUE);
973                         }
974                 }
975         } else
976                 g_warning("invalid number of color elements (%d)\n", n);
977
978         /* reset "dont_toggle" state */
979         g_object_set_data(G_OBJECT(menu), "dont_toggle",
980                           GINT_TO_POINTER(0));
981 }
982
983 static void mainwindow_colorlabel_menu_item_activate_cb(GtkWidget *widget,
984                                                      gpointer data)
985 {
986         guint color = GPOINTER_TO_UINT(data);
987         MainWindow *mainwin;
988
989         mainwin = g_object_get_data(G_OBJECT(widget), "mainwin");
990         g_return_if_fail(mainwin != NULL);
991
992         /* "dont_toggle" state set? */
993         if (g_object_get_data(G_OBJECT(mainwin->colorlabel_menu),
994                                 "dont_toggle"))
995                 return;
996
997         summary_set_colorlabel(mainwin->summaryview, color, NULL);
998 }
999
1000 static void mainwindow_colorlabel_menu_create(MainWindow *mainwin, gboolean refresh)
1001 {
1002         GtkWidget *label_menuitem;
1003         GtkWidget *menu;
1004         GtkWidget *item;
1005         gint i;
1006
1007         label_menuitem = gtk_item_factory_get_item(mainwin->menu_factory,
1008                                                    "/Message/Color label");
1009         g_signal_connect(G_OBJECT(label_menuitem), "activate",
1010                          G_CALLBACK(mainwindow_colorlabel_menu_item_activate_item_cb),
1011                            mainwin);
1012         gtk_widget_show(label_menuitem);
1013
1014         menu = gtk_menu_new();
1015
1016         /* create sub items. for the menu item activation callback we pass the
1017          * index of label_colors[] as data parameter. for the None color we
1018          * pass an invalid (high) value. also we attach a data pointer so we
1019          * can always get back the Mainwindow pointer. */
1020
1021         item = gtk_check_menu_item_new_with_label(_("None"));
1022         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1023         g_signal_connect(G_OBJECT(item), "activate",
1024                          G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1025                            GUINT_TO_POINTER(0));
1026         g_object_set_data(G_OBJECT(item), "mainwin", mainwin);
1027         gtk_widget_show(item);
1028
1029         gtk_widget_add_accelerator(item, "activate", 
1030                                    mainwin->menu_factory->accel_group, 
1031                                    GDK_0, GDK_CONTROL_MASK,
1032                                    GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1033
1034         item = gtk_menu_item_new();
1035         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1036         gtk_widget_show(item);
1037
1038         /* create pixmap/label menu items */
1039         for (i = 0; i < N_COLOR_LABELS; i++) {
1040                 item = colorlabel_create_check_color_menu_item(
1041                         i, refresh, MAINWIN_COLORMENU);
1042                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
1043                 g_signal_connect(G_OBJECT(item), "activate",
1044                                  G_CALLBACK(mainwindow_colorlabel_menu_item_activate_cb),
1045                                  GUINT_TO_POINTER(i + 1));
1046                 g_object_set_data(G_OBJECT(item), "mainwin",
1047                                   mainwin);
1048                 gtk_widget_show(item);
1049                 if (i < 9)
1050                         gtk_widget_add_accelerator(item, "activate", 
1051                                    mainwin->menu_factory->accel_group, 
1052                                    GDK_1+i, GDK_CONTROL_MASK,
1053                                    GTK_ACCEL_LOCKED | GTK_ACCEL_VISIBLE);
1054         }
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                 summary_relayout(mainwin->summaryview); 
1476
1477         gtk_widget_show(mainwin->window);
1478
1479         /* initialize views */
1480         folderview_init(folderview);
1481         summary_init(summaryview);
1482         messageview_init(messageview);
1483 #ifdef USE_OPENSSL
1484         sslcertwindow_register_hook();
1485 #endif
1486         mainwin->lock_count = 0;
1487         mainwin->menu_lock_count = 0;
1488         mainwin->cursor_count = 0;
1489
1490         mainwin->progressindicator_hook =
1491                 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1492
1493         if (!watch_cursor)
1494                 watch_cursor = gdk_cursor_new(GDK_WATCH);
1495         if (!hand_cursor)
1496                 hand_cursor = gdk_cursor_new(GDK_HAND2);
1497
1498         mainwin_list = g_list_append(mainwin_list, mainwin);
1499
1500         /* init work_offline */
1501         if (prefs_common.work_offline)
1502                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1503
1504         mainwindow_colorlabel_menu_create(mainwin, FALSE);
1505         
1506         return mainwin;
1507 }
1508
1509 void main_window_destroy(MainWindow *mainwin)
1510 {
1511         /* TODO : destroy other component */
1512         messageview_destroy(mainwin->messageview);
1513         mainwin->messageview = NULL;    
1514 }
1515
1516 void main_window_update_actions_menu(MainWindow *mainwin)
1517 {
1518         GtkItemFactory *ifactory;
1519
1520         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1521         action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1522 }
1523
1524 void main_window_cursor_wait(MainWindow *mainwin)
1525 {
1526
1527         if (mainwin->cursor_count == 0) {
1528                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1529                 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1530         }
1531         
1532         mainwin->cursor_count++;
1533
1534         gdk_flush();
1535 }
1536
1537 void main_window_cursor_normal(MainWindow *mainwin)
1538 {
1539         if (mainwin->cursor_count)
1540                 mainwin->cursor_count--;
1541
1542         if (mainwin->cursor_count == 0) {
1543                 gdk_window_set_cursor(mainwin->window->window, NULL);
1544                 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1545         }
1546         gdk_flush();
1547 }
1548
1549 /* lock / unlock the user-interface */
1550 void main_window_lock(MainWindow *mainwin)
1551 {
1552         if (mainwin->lock_count == 0)
1553                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1554
1555         mainwin->lock_count++;
1556
1557         main_window_set_menu_sensitive(mainwin);
1558         toolbar_main_set_sensitive(mainwin);
1559 }
1560
1561 void main_window_unlock(MainWindow *mainwin)
1562 {
1563         if (mainwin->lock_count)
1564                 mainwin->lock_count--;
1565
1566         main_window_set_menu_sensitive(mainwin);
1567         toolbar_main_set_sensitive(mainwin);
1568
1569         if (mainwin->lock_count == 0)
1570                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1571 }
1572
1573 static void main_window_menu_callback_block(MainWindow *mainwin)
1574 {
1575         mainwin->menu_lock_count++;
1576 }
1577
1578 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1579 {
1580         if (mainwin->menu_lock_count)
1581                 mainwin->menu_lock_count--;
1582 }
1583
1584 static guint prefs_tag = 0;
1585
1586 void main_window_reflect_prefs_all(void)
1587 {
1588         main_window_reflect_prefs_all_real(FALSE);
1589 }
1590
1591 static gboolean reflect_prefs_timeout_cb(gpointer data) 
1592 {
1593         gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1594         GList *cur;
1595         MainWindow *mainwin;
1596         GtkWidget *pixmap;
1597
1598         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1599                 mainwin = (MainWindow *)cur->data;
1600
1601                 main_window_show_cur_account(mainwin);
1602                 main_window_set_menu_sensitive(mainwin);
1603                 toolbar_main_set_sensitive(mainwin);
1604
1605                 /* pixmap themes */
1606                 if (pixmap_theme_changed) {
1607                         toolbar_update(TOOLBAR_MAIN, mainwin);
1608                         messageview_reflect_prefs_pixmap_theme();
1609                         compose_reflect_prefs_pixmap_theme();
1610                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1611                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1612
1613                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1614                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
1615                                              mainwin->online_pixmap);
1616                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1617                         gtk_widget_show(pixmap);
1618                         mainwin->online_pixmap = pixmap;
1619                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1620                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
1621                                              mainwin->offline_pixmap);
1622                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1623                         gtk_widget_show(pixmap);
1624                         mainwin->offline_pixmap = pixmap;
1625                 }
1626                 
1627                 headerview_set_font(mainwin->messageview->headerview);
1628                 headerview_set_visibility(mainwin->messageview->headerview,
1629                                           prefs_common.display_header_pane);
1630                 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1631                 folderview_reflect_prefs();
1632                 summary_reflect_prefs();
1633                 summary_redisplay_msg(mainwin->summaryview);
1634         }
1635         prefs_tag = 0;
1636         return FALSE;
1637 }
1638
1639 void main_window_reflect_prefs_all_now(void)
1640 {
1641         reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1642 }
1643
1644 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1645 {
1646         GtkMenuShell *menu;
1647         GList *cur;
1648
1649         /* re-create colorlabel submenu */
1650         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1651         g_return_if_fail(menu != NULL);
1652
1653         /* clear items. get item pointers. */
1654         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1655                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1656         }
1657         mainwindow_colorlabel_menu_create(mainwin, TRUE);
1658         summary_reflect_prefs_custom_colors(mainwin->summaryview);
1659
1660 }
1661
1662 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1663 {
1664         if (prefs_tag == 0 || pixmap_theme_changed) {
1665                 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb, 
1666                                                 GINT_TO_POINTER(pixmap_theme_changed));
1667         }
1668 }
1669
1670 void main_window_set_summary_column(void)
1671 {
1672         GList *cur;
1673         MainWindow *mainwin;
1674
1675         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1676                 mainwin = (MainWindow *)cur->data;
1677                 summary_set_column_order(mainwin->summaryview);
1678         }
1679 }
1680
1681 void main_window_set_folder_column(void)
1682 {
1683         GList *cur;
1684         MainWindow *mainwin;
1685
1686         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1687                 mainwin = (MainWindow *)cur->data;
1688                 folderview_set_column_order(mainwin->folderview);
1689         }
1690 }
1691
1692 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1693                                                   GList *account_list)
1694 {
1695         GList *cur_ac, *cur_item;
1696         GtkWidget *menuitem;
1697         PrefsAccount *ac_prefs;
1698
1699         /* destroy all previous menu item */
1700         cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1701         while (cur_item != NULL) {
1702                 GList *next = cur_item->next;
1703                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1704                 cur_item = next;
1705         }
1706
1707         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1708                 ac_prefs = (PrefsAccount *)cur_ac->data;
1709
1710                 menuitem = gtk_menu_item_new_with_label
1711                         (ac_prefs->account_name
1712                          ? ac_prefs->account_name : _("Untitled"));
1713                 gtk_widget_show(menuitem);
1714                 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1715                 g_signal_connect(G_OBJECT(menuitem), "activate",
1716                                  G_CALLBACK(account_selector_menu_cb),
1717                                  ac_prefs);
1718         }
1719 }
1720
1721 static void main_window_set_account_receive_menu(MainWindow *mainwin,
1722                                                  GList *account_list)
1723 {
1724         GList *cur_ac, *cur_item;
1725         GtkWidget *menu;
1726         GtkWidget *menuitem;
1727         PrefsAccount *ac_prefs;
1728
1729         menu = gtk_item_factory_get_widget(mainwin->menu_factory,
1730                                            "/Message/Receive");
1731
1732         /* search for separator */
1733         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
1734              cur_item = cur_item->next) {
1735                 if (GTK_BIN(cur_item->data)->child == NULL) {
1736                         cur_item = cur_item->next;
1737                         break;
1738                 }
1739         }
1740
1741         /* destroy all previous menu item */
1742         while (cur_item != NULL) {
1743                 GList *next = cur_item->next;
1744                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1745                 cur_item = next;
1746         }
1747
1748         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1749                 ac_prefs = (PrefsAccount *)cur_ac->data;
1750
1751                 menuitem = gtk_menu_item_new_with_label
1752                         (ac_prefs->account_name ? ac_prefs->account_name
1753                          : _("Untitled"));
1754                 gtk_widget_show(menuitem);
1755                 gtk_menu_append(GTK_MENU(menu), menuitem);
1756                 g_signal_connect(G_OBJECT(menuitem), "activate",
1757                                  G_CALLBACK(account_receive_menu_cb),
1758                                  ac_prefs);
1759         }
1760 }
1761
1762 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
1763                                                        GList *account_list)
1764 {
1765         GList *cur_ac, *cur_item;
1766         GtkWidget *menuitem;
1767         PrefsAccount *ac_prefs;
1768         GtkWidget *menu = NULL;
1769
1770         if (mainwin->toolbar->getall_btn == NULL
1771         ||  mainwin->toolbar->getall_combo == NULL) /* button doesn't exist */
1772                 return;
1773
1774         menu = mainwin->toolbar->getall_combo->menu;
1775
1776         /* destroy all previous menu item */
1777         cur_item = GTK_MENU_SHELL(menu)->children;
1778         while (cur_item != NULL) {
1779                 GList *next = cur_item->next;
1780                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1781                 cur_item = next;
1782         }
1783
1784         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1785                 ac_prefs = (PrefsAccount *)cur_ac->data;
1786
1787                 menuitem = gtk_menu_item_new_with_label
1788                         (ac_prefs->account_name
1789                          ? ac_prefs->account_name : _("Untitled"));
1790                 gtk_widget_show(menuitem);
1791                 gtk_menu_append(GTK_MENU(menu), menuitem);
1792                 g_signal_connect(G_OBJECT(menuitem), "activate",
1793                                  G_CALLBACK(account_receive_menu_cb),
1794                                  ac_prefs);
1795         }
1796 }
1797
1798 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
1799                                                        GList *account_list)
1800 {
1801         GList *cur_ac, *cur_item;
1802         GtkWidget *menuitem;
1803         PrefsAccount *ac_prefs;
1804         GtkWidget *menu = NULL;
1805
1806         if (mainwin->toolbar->compose_mail_btn == NULL
1807         ||  mainwin->toolbar->compose_combo == NULL) /* button doesn't exist */
1808                 return;
1809
1810         menu = mainwin->toolbar->compose_combo->menu;
1811
1812         /* destroy all previous menu item */
1813         cur_item = GTK_MENU_SHELL(menu)->children;
1814         while (cur_item != NULL) {
1815                 GList *next = cur_item->next;
1816                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1817                 cur_item = next;
1818         }
1819
1820         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1821                 ac_prefs = (PrefsAccount *)cur_ac->data;
1822
1823                 menuitem = gtk_menu_item_new_with_label
1824                         (ac_prefs->account_name
1825                          ? ac_prefs->account_name : _("Untitled"));
1826                 gtk_widget_show(menuitem);
1827                 gtk_menu_append(GTK_MENU(menu), menuitem);
1828                 g_signal_connect(G_OBJECT(menuitem), "activate",
1829                                  G_CALLBACK(account_compose_menu_cb),
1830                                  ac_prefs);
1831         }
1832 }
1833
1834 void main_window_set_account_menu(GList *account_list)
1835 {
1836         GList *cur;
1837         MainWindow *mainwin;
1838
1839         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1840                 mainwin = (MainWindow *)cur->data;
1841                 main_window_set_account_selector_menu(mainwin, account_list);
1842                 main_window_set_account_receive_menu(mainwin, account_list);
1843                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1844                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1845         }
1846         hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
1847 }
1848
1849 void main_window_set_account_menu_only_toolbar(GList *account_list)
1850 {
1851         GList *cur;
1852         MainWindow *mainwin;
1853
1854         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1855                 mainwin = (MainWindow *)cur->data;
1856                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
1857                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
1858         }
1859 }
1860
1861 static void main_window_show_cur_account(MainWindow *mainwin)
1862 {
1863         gchar *buf;
1864         gchar *ac_name;
1865
1866         ac_name = g_strdup(cur_account
1867                            ? (cur_account->account_name
1868                               ? cur_account->account_name : _("Untitled"))
1869                            : _("none"));
1870
1871         if (cur_account)
1872                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1873         else
1874                 buf = g_strdup(PROG_VERSION);
1875         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1876         g_free(buf);
1877
1878         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1879         gtk_widget_queue_resize(mainwin->ac_button);
1880
1881         g_free(ac_name);
1882 }
1883
1884 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
1885 {
1886         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1887         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1888         GtkWidget *message_wid = mainwin->messageview->vbox;
1889
1890         if (layout_mode == prefs_common.layout_mode) 
1891                 return;
1892
1893         debug_print("Changing window separation type from %d to %d\n",
1894                     prefs_common.layout_mode, layout_mode);
1895
1896         /* remove widgets from those containers */
1897         gtk_widget_ref(folder_wid);
1898         gtk_widget_ref(summary_wid);
1899         gtk_widget_ref(message_wid);
1900         gtkut_container_remove
1901                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1902         gtkut_container_remove
1903                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1904         gtkut_container_remove
1905                 (GTK_CONTAINER(message_wid->parent), message_wid);
1906
1907         gtk_widget_hide(mainwin->window);
1908         main_window_set_widgets(mainwin, layout_mode);
1909         gtk_widget_show(mainwin->window);
1910
1911         gtk_widget_unref(folder_wid);
1912         gtk_widget_unref(summary_wid);
1913         gtk_widget_unref(message_wid);
1914 }
1915
1916 static void mainwin_reset_paned(GtkPaned *paned)
1917 {
1918                 gint min, max, mid;
1919                 g_object_get (G_OBJECT(paned),
1920                                 "min-position",
1921                                 &min, NULL);
1922                 g_object_get (G_OBJECT(paned),
1923                                 "max-position",
1924                                 &max, NULL);
1925                 mid = (min+max)/2;
1926
1927                 gtk_paned_set_position(GTK_PANED(paned), mid);
1928 }
1929
1930 void main_window_toggle_message_view(MainWindow *mainwin)
1931 {
1932         SummaryView *summaryview = mainwin->summaryview;
1933         GtkWidget *ppaned = NULL;
1934         GtkWidget *container = NULL;
1935         
1936         switch (prefs_common.layout_mode) {
1937         case NORMAL_LAYOUT:
1938         case VERTICAL_LAYOUT:
1939                 ppaned = mainwin->vpaned;
1940                 container = mainwin->hpaned;
1941                 if (ppaned->parent != NULL) {
1942                         mainwin->messageview->visible = FALSE;
1943                         summaryview->displayed = NULL;
1944                         gtk_widget_ref(ppaned);
1945                         gtkut_container_remove(GTK_CONTAINER(container), ppaned);
1946                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1947                 } else {
1948                         mainwin->messageview->visible = TRUE;
1949                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
1950                         gtk_container_add(GTK_CONTAINER(container), ppaned);
1951                         gtk_widget_unref(ppaned);
1952                 }
1953                 break;
1954         case WIDE_LAYOUT:
1955                 ppaned = mainwin->hpaned;
1956                 container = mainwin->vpaned;
1957                 if (mainwin->messageview->vbox->parent != NULL) {
1958                         mainwin->messageview->visible = FALSE;
1959                         summaryview->displayed = NULL;
1960                         gtk_widget_ref(mainwin->messageview->vbox);
1961                         gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
1962                 } else {
1963                         mainwin->messageview->visible = TRUE;
1964                         gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
1965                         gtk_widget_unref(mainwin->messageview->vbox);
1966                 }
1967                 break;
1968         case WIDE_MSGLIST_LAYOUT:
1969                 g_warning("can't hide messageview in this wide msglist layout");
1970                 break;
1971         }
1972
1973         if (messageview_is_visible(mainwin->messageview))
1974                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1975                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1976         else
1977                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
1978                               GTK_ARROW_UP, GTK_SHADOW_OUT);
1979
1980         if (mainwin->messageview->visible == FALSE)
1981                 messageview_clear(mainwin->messageview);
1982
1983         main_window_set_menu_sensitive(mainwin);
1984
1985         prefs_common.msgview_visible = mainwin->messageview->visible;
1986
1987         if (messageview_is_visible(mainwin->messageview)) {
1988                 gtk_widget_queue_resize(mainwin->hpaned);
1989                 gtk_widget_queue_resize(mainwin->vpaned);
1990         }
1991         summary_grab_focus(summaryview);
1992 }
1993
1994 void main_window_get_size(MainWindow *mainwin)
1995 {
1996         GtkAllocation *allocation;
1997
1998         if (mainwin_list == NULL || mainwin->messageview == NULL) {
1999                 debug_print("called after messageview "
2000                             "has been deallocated!\n");
2001                 return;
2002         }
2003
2004         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
2005
2006         if (allocation->width > 1 && allocation->height > 1) {
2007                 prefs_common.summaryview_width = allocation->width;
2008
2009                 if (messageview_is_visible(mainwin->messageview))
2010                         prefs_common.summaryview_height = allocation->height;
2011
2012                 prefs_common.mainview_width = allocation->width;
2013         }
2014
2015         allocation = &mainwin->window->allocation;
2016         if (allocation->width > 1 && allocation->height > 1) {
2017                 prefs_common.mainview_height = allocation->height;
2018                 prefs_common.mainwin_width   = allocation->width;
2019                 prefs_common.mainwin_height  = allocation->height;
2020         }
2021
2022         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
2023         if (allocation->width > 1 && allocation->height > 1) {
2024                 prefs_common.folderview_width  = allocation->width;
2025                 prefs_common.folderview_height = allocation->height;
2026         }
2027
2028         allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
2029         if (allocation->width > 1 && allocation->height > 1) {
2030                 prefs_common.msgview_width = allocation->width;
2031                 prefs_common.msgview_height = allocation->height;
2032         }
2033
2034 /*      debug_print("summaryview size: %d x %d\n",
2035                     prefs_common.summaryview_width,
2036                     prefs_common.summaryview_height);
2037         debug_print("folderview size: %d x %d\n",
2038                     prefs_common.folderview_width,
2039                     prefs_common.folderview_height);
2040         debug_print("messageview size: %d x %d\n",
2041                     prefs_common.msgview_width,
2042                     prefs_common.msgview_height); */
2043 }
2044
2045 void main_window_get_position(MainWindow *mainwin)
2046 {
2047         gint x, y;
2048
2049         gtkut_widget_get_uposition(mainwin->window, &x, &y);
2050
2051         prefs_common.mainview_x = x;
2052         prefs_common.mainview_y = y;
2053         prefs_common.mainwin_x = x;
2054         prefs_common.mainwin_y = y;
2055
2056         debug_print("main window position: %d, %d\n", x, y);
2057 }
2058
2059 void main_window_progress_on(MainWindow *mainwin)
2060 {
2061         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2062 }
2063
2064 void main_window_progress_off(MainWindow *mainwin)
2065 {
2066         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2067         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2068 }
2069
2070 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
2071 {
2072         gchar buf[32];
2073
2074         g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
2075         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
2076         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
2077                                 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
2078 }
2079
2080 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2081 {
2082         if (confirm && procmsg_have_trashed_mails_fast()) {
2083                 if (alertpanel(_("Empty trash"),
2084                                _("Delete all messages in trash folders?"),
2085                                GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
2086                     != G_ALERTALTERNATE)
2087                         return;
2088                 manage_window_focus_in(mainwin->window, NULL, NULL);
2089         }
2090
2091         procmsg_empty_all_trash();
2092
2093         if (mainwin->summaryview->folder_item &&
2094             mainwin->summaryview->folder_item->stype == F_TRASH)
2095                 gtk_widget_grab_focus(mainwin->folderview->ctree);
2096 }
2097
2098 void main_window_add_mailbox(MainWindow *mainwin)
2099 {
2100         gchar *path;
2101         Folder *folder;
2102
2103         path = input_dialog(_("Add mailbox"),
2104                             _("Input the location of mailbox.\n"
2105                               "If the existing mailbox is specified, it will be\n"
2106                               "scanned automatically."),
2107                             "Mail");
2108         if (!path) return;
2109         if (folder_find_from_path(path)) {
2110                 alertpanel_error(_("The mailbox '%s' already exists."), path);
2111                 g_free(path);
2112                 return;
2113         }
2114         folder = folder_new(folder_get_class_from_string("mh"), 
2115                             !strcmp(path, "Mail") ? _("Mailbox") : 
2116                             g_path_get_basename(path), path);
2117         g_free(path);
2118
2119         if (folder->klass->create_tree(folder) < 0) {
2120                 alertpanel_error(_("Creation of the mailbox failed.\n"
2121                                    "Maybe some files already exist, or you don't have the permission to write there."));
2122                 folder_destroy(folder);
2123                 return;
2124         }
2125
2126         folder_add(folder);
2127         folder_set_ui_func(folder, scan_tree_func, mainwin);
2128         folder_scan_tree(folder, TRUE);
2129         folder_set_ui_func(folder, NULL, NULL);
2130 }
2131
2132 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2133 {
2134         SensitiveCond state = 0;
2135         SummarySelection selection;
2136         FolderItem *item = mainwin->summaryview->folder_item;
2137         GList *account_list = account_get_list();
2138         
2139         selection = summary_get_selection_type(mainwin->summaryview);
2140
2141         if (mainwin->lock_count == 0)
2142                 state |= M_UNLOCKED;
2143         if (selection != SUMMARY_NONE)
2144                 state |= M_MSG_EXIST;
2145         if (item && item->path && folder_item_parent(item) && !item->no_select) {
2146                 state |= M_EXEC;
2147                 /*              if (item->folder->type != F_NEWS) */
2148                 state |= M_ALLOW_DELETE;
2149
2150                 if (prefs_common.immediate_exec == 0
2151                     && mainwin->lock_count == 0)
2152                         state |= M_DELAY_EXEC;
2153
2154                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2155                     || selection != SUMMARY_NONE)
2156                         state |= M_HIDE_READ_MSG;
2157         }               
2158         if (mainwin->summaryview->threaded)
2159                 state |= M_THREADED;
2160         else
2161                 state |= M_UNTHREADED;  
2162         if (selection == SUMMARY_SELECTED_SINGLE ||
2163             selection == SUMMARY_SELECTED_MULTIPLE)
2164                 state |= M_TARGET_EXIST;
2165         if (selection == SUMMARY_SELECTED_SINGLE)
2166                 state |= M_SINGLE_TARGET_EXIST;
2167         if (mainwin->summaryview->folder_item &&
2168             mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2169                 state |= M_NEWS;
2170         else
2171                 state |= M_NOT_NEWS;
2172         if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2173                 state |= M_ACTIONS_EXIST;
2174
2175         if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2176                 state |= M_HAVE_QUEUED_MAILS;
2177
2178         if (selection == SUMMARY_SELECTED_SINGLE &&
2179             (item &&
2180              (folder_has_parent_of_type(item, F_DRAFT) ||
2181               folder_has_parent_of_type(item, F_OUTBOX) ||
2182               folder_has_parent_of_type(item, F_QUEUE))))
2183                 state |= M_ALLOW_REEDIT;
2184         if (cur_account)
2185                 state |= M_HAVE_ACCOUNT;
2186         
2187         if (any_folder_want_synchronise())
2188                 state |= M_WANT_SYNC;
2189
2190         for ( ; account_list != NULL; account_list = account_list->next) {
2191                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2192                         state |= M_HAVE_NEWS_ACCOUNT;
2193                         break;
2194                 }
2195         }
2196         
2197         if (procmsg_spam_can_learn() &&
2198             (mainwin->summaryview->folder_item &&
2199              mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2200              mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2201                 state |= M_CAN_LEARN_SPAM;
2202         }
2203
2204         if (inc_is_active())
2205                 state |= M_INC_ACTIVE;
2206
2207         if (mainwin->summaryview->deleted > 0 ||
2208             mainwin->summaryview->moved > 0 ||
2209             mainwin->summaryview->copied > 0)
2210                 state |= M_DELAY_EXEC;
2211
2212         return state;
2213 }
2214
2215
2216
2217 void main_window_set_menu_sensitive(MainWindow *mainwin)
2218 {
2219         GtkItemFactory *ifactory = mainwin->menu_factory;
2220         SensitiveCond state;
2221         gboolean sensitive;
2222         GtkWidget *menu;
2223         GtkWidget *menuitem;
2224         SummaryView *summaryview;
2225         gchar *menu_path;
2226         gint i;
2227         GList *cur_item;
2228
2229         static const struct {
2230                 gchar *const entry;
2231                 SensitiveCond cond;
2232         } entry[] = {
2233                 {"/File/Save as...", M_TARGET_EXIST},
2234                 {"/File/Print..."  , M_TARGET_EXIST},
2235                 {"/File/Synchronise folders", M_WANT_SYNC},
2236                 {"/File/Exit"      , M_UNLOCKED},
2237
2238                 {"/Edit/Select thread"             , M_SINGLE_TARGET_EXIST},
2239                 {"/Edit/Delete thread"             , M_SINGLE_TARGET_EXIST},
2240                 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2241
2242                 {"/View/Set displayed columns/in Folder list..."
2243                                                    , M_UNLOCKED}, 
2244                 {"/View/Sort"                      , M_EXEC},
2245                 {"/View/Thread view"               , M_EXEC},
2246                 {"/View/Expand all threads"        , M_MSG_EXIST},
2247                 {"/View/Collapse all threads"      , M_MSG_EXIST},
2248                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
2249                 {"/View/Go to/Previous message"        , M_MSG_EXIST},
2250                 {"/View/Go to/Next message"        , M_MSG_EXIST},
2251                 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2252                 {"/View/Go to/Previous new message"    , M_MSG_EXIST},
2253                 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2254                 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2255                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2256                 {"/View/Go to/Last read message"   , M_SINGLE_TARGET_EXIST},
2257                 {"/View/Go to/Parent message"      , M_SINGLE_TARGET_EXIST},
2258                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
2259                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
2260                 {"/View/All headers"               , M_SINGLE_TARGET_EXIST},
2261                 {"/View/Quotes"                    , M_SINGLE_TARGET_EXIST},
2262
2263                 {"/Message/Receive/Get from current account"
2264                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2265                 {"/Message/Receive/Get from all accounts"
2266                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2267                 {"/Message/Receive/Cancel receiving"
2268                                                  , M_INC_ACTIVE},
2269                 {"/Message/Send queued messages"  , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2270                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2271                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2272                 {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2273                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2274                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2275                 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2276                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2277                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE},
2278                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC},
2279                 {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2280                 {"/Message/Delete..."             , M_TARGET_EXIST|M_ALLOW_DELETE},
2281                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2282                 {"/Message/Mark"                  , M_TARGET_EXIST},
2283                 {"/Message/Mark/Mark as spam"     , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2284                 {"/Message/Mark/Mark as ham"      , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2285                 {"/Message/Mark/Ignore thread"    , M_TARGET_EXIST},
2286                 {"/Message/Mark/Unignore thread"  , M_TARGET_EXIST},
2287                 {"/Message/Mark/Lock"             , M_TARGET_EXIST},
2288                 {"/Message/Mark/Unlock"           , M_TARGET_EXIST},
2289                 {"/Message/Color label"           , M_TARGET_EXIST},
2290                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2291
2292                 {"/Tools/Add sender to address book"   , M_SINGLE_TARGET_EXIST},
2293                 {"/Tools/Harvest addresses"            , M_MSG_EXIST},
2294                 {"/Tools/Harvest addresses/from Messages..."
2295                                                        , M_TARGET_EXIST},
2296                 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2297                 {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
2298                 {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2299                 {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2300                 {"/Tools/List URLs..."                 , M_TARGET_EXIST},
2301                 {"/Tools/Actions"                      , M_TARGET_EXIST|M_ACTIONS_EXIST},
2302                 {"/Tools/Execute"                      , M_DELAY_EXEC},
2303                 {"/Tools/Delete duplicated messages/In selected folder"   , M_MSG_EXIST|M_ALLOW_DELETE},
2304
2305                 {"/Configuration", M_UNLOCKED},
2306
2307                 {NULL, 0}
2308         };
2309
2310         state = main_window_get_current_state(mainwin);
2311
2312         for (i = 0; entry[i].entry != NULL; i++) {
2313                 sensitive = ((entry[i].cond & state) == entry[i].cond);
2314                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2315         }
2316
2317         menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2318
2319         /* search for separator */
2320         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2321              cur_item = cur_item->next) {
2322                 if (GTK_BIN(cur_item->data)->child == NULL) {
2323                         cur_item = cur_item->next;
2324                         break;
2325                 }
2326         }
2327
2328         for (; cur_item != NULL; cur_item = cur_item->next) {
2329                 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2330                                          (M_UNLOCKED & state) != 0);
2331         }
2332
2333         main_window_menu_callback_block(mainwin);
2334
2335 #define SET_CHECK_MENU_ACTIVE(path, active) \
2336 { \
2337         menuitem = gtk_item_factory_get_widget(ifactory, path); \
2338         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2339 }
2340
2341         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2342                               messageview_is_visible(mainwin->messageview));
2343
2344         summaryview = mainwin->summaryview;
2345         menu_path = "/View/Sort/Don't sort";
2346
2347         switch (summaryview->sort_key) {
2348         case SORT_BY_NUMBER:
2349                 menu_path = "/View/Sort/by number"; break;
2350         case SORT_BY_SIZE:
2351                 menu_path = "/View/Sort/by Size"; break;
2352         case SORT_BY_DATE:
2353                 menu_path = "/View/Sort/by Date"; break;
2354         case SORT_BY_FROM:
2355                 menu_path = "/View/Sort/by From"; break;
2356         case SORT_BY_TO:
2357                 menu_path = "/View/Sort/by To"; break;
2358         case SORT_BY_SUBJECT:
2359                 menu_path = "/View/Sort/by Subject"; break;
2360         case SORT_BY_LABEL:
2361                 menu_path = "/View/Sort/by color label"; break;
2362         case SORT_BY_MARK:
2363                 menu_path = "/View/Sort/by mark"; break;
2364         case SORT_BY_STATUS:
2365                 menu_path = "/View/Sort/by status"; break;
2366         case SORT_BY_MIME:
2367                 menu_path = "/View/Sort/by attachment"; break;
2368         case SORT_BY_SCORE:
2369                 menu_path = "/View/Sort/by score"; break;
2370         case SORT_BY_LOCKED:
2371                 menu_path = "/View/Sort/by locked"; break;
2372         case SORT_BY_NONE:
2373         default:
2374                 menu_path = "/View/Sort/Don't sort"; break;
2375         }
2376         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2377
2378         if (summaryview->sort_type == SORT_ASCENDING) {
2379                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2380         } else {
2381                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2382         }
2383
2384         if (summaryview->sort_key != SORT_BY_NONE) {
2385                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2386                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2387         } else {
2388                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2389                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2390         }
2391
2392         if (mainwin->messageview 
2393         &&  mainwin->messageview->mimeview
2394         &&  mainwin->messageview->mimeview->textview)
2395                 SET_CHECK_MENU_ACTIVE("/View/All headers",
2396                               mainwin->messageview->mimeview->textview->show_all_headers);
2397         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2398         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2399         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2400         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2401         if (prefs_common.hide_quotes == 1)
2402                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2403         if (prefs_common.hide_quotes == 2)
2404                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2405         if (prefs_common.hide_quotes == 3)
2406                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2407
2408 #undef SET_CHECK_MENU_ACTIVE
2409
2410         main_window_menu_callback_unblock(mainwin);
2411 }
2412
2413 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2414 {
2415         GtkItemFactory *ifactory;
2416         gint is_menu = 0;
2417         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2418         
2419         if (msginfo) 
2420                 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2421         if (is_menu)
2422                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2423                                 (ifactory,"/Message/Mailing-List"), TRUE);
2424         else
2425                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2426                                 (ifactory,"/Message/Mailing-List"), FALSE);
2427 }
2428
2429 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2430 {
2431         gint menu_nb = 0;
2432         GtkWidget *menuitem;
2433         
2434         if (!msginfo || !msginfo->extradata) {
2435                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2436                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2437                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2438                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2439                 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2440                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2441                 return 0;
2442         }
2443                 
2444         /* Mailing list post */
2445         if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2446                 g_free(msginfo->extradata->list_post);
2447                 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2448         }
2449         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2450                 
2451         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2452  
2453         /* Mailing list help */
2454         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2455         
2456         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2457
2458         /* Mailing list subscribe */
2459         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2460         
2461         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2462                 
2463         /* Mailing list unsubscribe */
2464         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2465         
2466         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2467         
2468         /* Mailing list view archive */
2469         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2470         
2471         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2472         
2473         /* Mailing list contact owner */
2474         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2475         
2476         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2477         
2478         return menu_nb;
2479 }
2480
2481 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2482 {
2483         GtkWidget *item, *menu;
2484         const gchar *url_pt ;
2485         gchar url_decoded[BUFFSIZE];
2486         GList *amenu, *alist;
2487         gint menu_nb = 0;
2488         
2489         menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2490         
2491         /* First delete old submenu */
2492         /* FIXME: we can optimize this, and only change/add/delete necessary items */
2493         for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2494                 alist = amenu->next;
2495                 item = GTK_WIDGET (amenu->data);
2496                 gtk_widget_destroy (item);
2497                 amenu = alist;
2498         }
2499         if (list_header) {
2500                 for (url_pt = list_header; url_pt && *url_pt;) {
2501                         get_url_part (&url_pt, url_decoded, BUFFSIZE);
2502                         item = NULL;
2503                         if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2504                                 item = gtk_menu_item_new_with_label ((url_decoded));
2505                                 g_signal_connect(G_OBJECT(item), "activate",
2506                                                  G_CALLBACK(mailing_list_compose),
2507                                                  NULL);
2508                         }
2509                         else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2510                                  !g_strncasecmp (url_decoded, "https:",6)) {
2511
2512                                 item = gtk_menu_item_new_with_label ((url_decoded));
2513                                 g_signal_connect(G_OBJECT(item), "activate",
2514                                                  G_CALLBACK(mailing_list_open_uri),
2515                                                  NULL);
2516                         } 
2517                         if (item) {
2518                                 gtk_menu_append (GTK_MENU(menu), item);
2519                                 gtk_widget_show (item);
2520                                 menu_nb++;
2521                         }
2522                 }
2523         }
2524         if (menu_nb)
2525                 gtk_widget_set_sensitive (menuitem, TRUE);
2526         else
2527                 gtk_widget_set_sensitive (menuitem, FALSE);
2528                 
2529
2530         return menu_nb;
2531 }
2532
2533 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2534 {
2535         gchar tmp[BUFFSIZE];
2536         const gchar *buf;
2537         gint i = 0;
2538         buf = *buffer;
2539         gboolean with_plus = TRUE;
2540
2541         if (buf == 0x00) {
2542                 *url_decoded = '\0';
2543                 *buffer = NULL;
2544                 return;
2545         }
2546         /* Ignore spaces, comments  and tabs () */
2547         for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2548                 if (*buf == '(')
2549                         for (;*buf != ')' && *buf != 0x00; buf++);
2550         
2551         /* First non space and non comment must be a < */
2552         if (*buf =='<' ) {
2553                 buf++;
2554                 if (!strncmp(buf, "mailto:", strlen("mailto:")))
2555                         with_plus = FALSE;
2556                 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2557                 buf++;
2558         }
2559         else  {
2560                 *buffer = NULL;
2561                 *url_decoded = '\0';
2562                 return;
2563         }
2564         
2565         tmp[i]       = 0x00;
2566         *url_decoded = '\0';
2567         *buffer = NULL;
2568         
2569         if (i == maxlen) {
2570                 return;
2571         }
2572         decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
2573
2574         /* Prepare the work for the next url in the list */
2575         /* after the closing bracket >, ignore space, comments and tabs */
2576         for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2577                 if (*buf == '(')
2578                         for (;*buf != ')' && *buf != 0x00; buf++);
2579                         
2580         if (!buf || !*buf) {
2581                 *buffer = NULL;
2582                 return;
2583         }
2584
2585         /* now first non space, non comment must be a comma */
2586         if (*buf != ',')
2587                 for (;*buf != 0x00; buf++);
2588         else
2589                 buf++;
2590         *buffer = buf;
2591 }
2592         
2593 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2594 {
2595         gchar *mailto;
2596
2597         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2598         compose_new(NULL, mailto+7, NULL);
2599 }
2600  
2601  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2602 {
2603  
2604         gchar *mailto;
2605  
2606         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2607         open_uri (mailto, prefs_common.uri_cmd);
2608
2609         
2610 void main_window_popup(MainWindow *mainwin)
2611 {
2612         if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
2613                 main_window_show(mainwin);
2614
2615         gtkut_window_popup(mainwin->window);
2616 }
2617
2618 void main_window_show(MainWindow *mainwin)
2619 {
2620         gtk_widget_show(mainwin->window);
2621         gtk_widget_show(mainwin->vbox_body);
2622
2623         gtk_widget_set_uposition(mainwin->window,
2624                                  prefs_common.mainwin_x,
2625                                  prefs_common.mainwin_y);
2626
2627         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2628                              prefs_common.folderview_width,
2629                              prefs_common.folderview_height);
2630         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2631                              prefs_common.summaryview_width,
2632                              prefs_common.summaryview_height);
2633         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2634                              prefs_common.msgview_width,
2635                              prefs_common.msgview_height);
2636 }
2637
2638 void main_window_hide(MainWindow *mainwin)
2639 {
2640         main_window_get_size(mainwin);
2641         main_window_get_position(mainwin);
2642
2643         gtk_widget_hide(mainwin->window);
2644         gtk_widget_hide(mainwin->vbox_body);
2645 }
2646
2647 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
2648 {
2649         GtkWidget *folderwin = NULL;
2650         GtkWidget *messagewin = NULL;
2651         GtkWidget *hpaned;
2652         GtkWidget *vpaned;
2653         GtkWidget *vbox_body = mainwin->vbox_body;
2654         GtkItemFactory *ifactory = mainwin->menu_factory;
2655         GtkWidget *menuitem;
2656
2657         debug_print("Setting widgets... ");
2658
2659         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2660                                     prefs_common.folderview_width,
2661                                     prefs_common.folderview_height);
2662         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2663                                     prefs_common.summaryview_width,
2664                                     prefs_common.summaryview_height);
2665         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2666                                     prefs_common.msgview_width,
2667                                     prefs_common.msgview_height);
2668
2669         mainwin->messageview->statusbar = mainwin->statusbar;
2670         mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2671
2672         /* clean top-most container */
2673         if (mainwin->hpaned) {
2674                 if (mainwin->hpaned->parent == mainwin->vpaned)
2675                         gtk_widget_destroy(mainwin->vpaned);
2676                 else
2677                         gtk_widget_destroy(mainwin->hpaned);
2678         }
2679
2680         menu_set_sensitive(ifactory, "/View/Show or hide/Message view", (layout_mode != WIDE_MSGLIST_LAYOUT));
2681         switch (layout_mode) {
2682         case VERTICAL_LAYOUT:
2683         case NORMAL_LAYOUT:
2684                 hpaned = gtk_hpaned_new();
2685                 if (layout_mode == VERTICAL_LAYOUT)
2686                         vpaned = gtk_hpaned_new();
2687                 else
2688                         vpaned = gtk_vpaned_new();
2689                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2690                 gtk_paned_add1(GTK_PANED(hpaned),
2691                                GTK_WIDGET_PTR(mainwin->folderview));
2692                 gtk_widget_show(hpaned);
2693                 gtk_widget_queue_resize(hpaned);
2694
2695                 if (messageview_is_visible(mainwin->messageview)) {
2696                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
2697                         gtk_paned_add1(GTK_PANED(vpaned),
2698                                        GTK_WIDGET_PTR(mainwin->summaryview));
2699                 } else {
2700                         gtk_paned_add2(GTK_PANED(hpaned),
2701                                        GTK_WIDGET_PTR(mainwin->summaryview));
2702                         gtk_widget_ref(vpaned);
2703                 }
2704                 gtk_paned_add2(GTK_PANED(vpaned),
2705                                GTK_WIDGET_PTR(mainwin->messageview));
2706                 gtk_widget_show(vpaned);
2707                 gtk_widget_queue_resize(vpaned);
2708                 break;
2709         case WIDE_LAYOUT:
2710                 vpaned = gtk_vpaned_new();
2711                 hpaned = gtk_hpaned_new();
2712                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
2713                 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
2714
2715                 gtk_paned_add1(GTK_PANED(hpaned),
2716                                GTK_WIDGET_PTR(mainwin->folderview));
2717                 gtk_paned_add2(GTK_PANED(hpaned),
2718                                GTK_WIDGET_PTR(mainwin->summaryview));
2719
2720                 gtk_widget_show(hpaned);
2721                 gtk_widget_queue_resize(hpaned);
2722
2723                 if (messageview_is_visible(mainwin->messageview)) {
2724                         gtk_paned_add2(GTK_PANED(vpaned),
2725                                GTK_WIDGET_PTR(mainwin->messageview));   
2726                 } else {
2727                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
2728                 }
2729                 gtk_widget_show(vpaned);
2730                 gtk_widget_queue_resize(vpaned);
2731                 break;
2732         case WIDE_MSGLIST_LAYOUT:
2733                 vpaned = gtk_vpaned_new();
2734                 hpaned = gtk_hpaned_new();
2735                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
2736
2737                 gtk_paned_add1(GTK_PANED(vpaned),
2738                                GTK_WIDGET_PTR(mainwin->summaryview));
2739                 gtk_paned_add1(GTK_PANED(hpaned),
2740                                GTK_WIDGET_PTR(mainwin->folderview));
2741
2742                 gtk_widget_show(hpaned);
2743                 gtk_widget_queue_resize(hpaned);
2744
2745                 if (messageview_is_visible(mainwin->messageview)) {
2746                         gtk_paned_add2(GTK_PANED(hpaned),
2747                                GTK_WIDGET_PTR(mainwin->messageview));   
2748                 } else {
2749                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
2750                 }
2751                 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
2752
2753                 gtk_widget_show(vpaned);
2754                 gtk_widget_queue_resize(vpaned);
2755                 break;
2756         default:
2757                 g_warning("Unknown layout");
2758                 return;
2759         }
2760
2761         mainwin->hpaned = hpaned;
2762         mainwin->vpaned = vpaned;
2763
2764         /* remove headerview if not in prefs */
2765         headerview_set_visibility(mainwin->messageview->headerview,
2766                                   prefs_common.display_header_pane);
2767
2768         if (messageview_is_visible(mainwin->messageview))
2769                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2770                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2771         else
2772                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2773                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2774
2775         gtk_window_move(GTK_WINDOW(mainwin->window),
2776                         prefs_common.mainwin_x,
2777                         prefs_common.mainwin_y);
2778
2779         gtk_widget_queue_resize(vbox_body);
2780         gtk_widget_queue_resize(mainwin->vbox);
2781         gtk_widget_queue_resize(mainwin->window);
2782         /* CLAWS: previous "gtk_widget_show_all" makes noticeview
2783          * and mimeview icon list/ctree lose track of their visibility states */
2784         if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
2785                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
2786         if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview)) 
2787                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
2788         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
2789                 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
2790         else 
2791                 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
2792
2793         prefs_common.layout_mode = layout_mode;
2794
2795         menuitem = gtk_item_factory_get_item
2796                 (ifactory, "/View/Show or hide/Message view");
2797         gtk_check_menu_item_set_active
2798                 (GTK_CHECK_MENU_ITEM(menuitem),
2799                  messageview_is_visible(mainwin->messageview));
2800
2801 #define SET_CHECK_MENU_ACTIVE(path, active) \
2802 { \
2803         menuitem = gtk_item_factory_get_widget(ifactory, path); \
2804         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2805 }
2806
2807         switch (prefs_common.layout_mode) {
2808         case NORMAL_LAYOUT:
2809                 SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
2810                 break;
2811         case VERTICAL_LAYOUT:
2812                 SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
2813                 break;
2814         case WIDE_LAYOUT:
2815                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
2816                 break;
2817         case WIDE_MSGLIST_LAYOUT:
2818                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
2819                 break;
2820         }
2821 #undef SET_CHECK_MENU_ACTIVE
2822
2823         if (folderwin) {
2824                 g_signal_connect
2825                         (G_OBJECT(folderwin), "size_allocate",
2826                          G_CALLBACK(folder_window_size_allocate_cb),
2827                          mainwin);
2828         }
2829         if (messagewin) {
2830                 g_signal_connect
2831                         (G_OBJECT(messagewin), "size_allocate",
2832                          G_CALLBACK(message_window_size_allocate_cb),
2833                          mainwin);
2834         }
2835
2836         debug_print("done.\n");
2837 }
2838
2839 void main_window_destroy_all(void)
2840 {
2841         while (mainwin_list != NULL) {
2842                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
2843                 
2844                 /* free toolbar stuff */
2845                 toolbar_clear_list(TOOLBAR_MAIN);
2846                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2847                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
2848
2849                 mainwin->folderview->mainwin = NULL;
2850                 mainwin->summaryview->mainwin = NULL;
2851                 mainwin->messageview->mainwin = NULL;
2852
2853                 g_free(mainwin->toolbar);
2854                 g_free(mainwin);
2855                 
2856                 mainwin_list = g_list_remove(mainwin_list, mainwin);
2857         }
2858         g_list_free(mainwin_list);
2859         mainwin_list = NULL;
2860 }
2861
2862 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
2863                                    gpointer data)
2864 {
2865         gtk_widget_set_size_request(child, 1, -1);
2866 }
2867
2868 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
2869                                    gpointer data)
2870 {
2871         gtk_widget_set_size_request(child, -1, -1);
2872 }
2873
2874 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2875                                     gpointer data)
2876 {
2877         MainWindow *mainwin = (MainWindow *)data;
2878
2879         if (!event) return FALSE;
2880
2881         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2882         g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
2883                           widget);
2884
2885         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2886                        menu_button_position, widget,
2887                        event->button, event->time);
2888
2889         return TRUE;
2890 }
2891
2892 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2893                                  gpointer data)
2894 {
2895         MainWindow *mainwin = (MainWindow *)data;
2896         gboolean close_allowed = TRUE;
2897
2898         hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
2899
2900         if (close_allowed && mainwin->lock_count == 0)
2901                 app_exit_cb(data, 0, widget);
2902
2903         return TRUE;
2904 }
2905
2906 static void main_window_size_allocate_cb(GtkWidget *widget,
2907                                          GtkAllocation *allocation,
2908                                          gpointer data)
2909 {
2910         MainWindow *mainwin = (MainWindow *)data;
2911
2912         main_window_get_size(mainwin);
2913 }
2914
2915 static void folder_window_size_allocate_cb(GtkWidget *widget,
2916                                            GtkAllocation *allocation,
2917                                            gpointer data)
2918 {
2919         MainWindow *mainwin = (MainWindow *)data;
2920
2921         main_window_get_size(mainwin);
2922 }
2923
2924 static void message_window_size_allocate_cb(GtkWidget *widget,
2925                                             GtkAllocation *allocation,
2926                                             gpointer data)
2927 {
2928         MainWindow *mainwin = (MainWindow *)data;
2929
2930         main_window_get_size(mainwin);
2931 }
2932
2933 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2934                            GtkWidget *widget)
2935 {
2936         main_window_add_mailbox(mainwin);
2937 }
2938
2939 static void update_folderview_cb(MainWindow *mainwin, guint action,
2940                                  GtkWidget *widget)
2941 {
2942         summary_show(mainwin->summaryview, NULL);
2943         folderview_check_new_all();
2944 }
2945
2946 static void foldersort_cb(MainWindow *mainwin, guint action,
2947                            GtkWidget *widget)
2948 {
2949         foldersort_open();
2950 }
2951
2952 static void import_mbox_cb(MainWindow *mainwin, guint action,
2953                            GtkWidget *widget)
2954 {
2955         /* only notify if import has failed */
2956         if (import_mbox(mainwin->summaryview->folder_item) == -1) {
2957                 alertpanel_error(_("Mbox import has failed."));
2958         }
2959 }
2960
2961 static void export_mbox_cb(MainWindow *mainwin, guint action,
2962                            GtkWidget *widget)
2963 {
2964         /* only notify if export has failed */
2965         if (export_mbox(mainwin->summaryview->folder_item) == -1) {
2966                 alertpanel_error(_("Export to mbox has failed."));
2967         }
2968 }
2969
2970 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
2971                                 GtkWidget *widget)
2972 {
2973         /* only notify if export has failed */
2974         if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
2975                 alertpanel_error(_("Export to mbox has failed."));
2976         }
2977 }
2978
2979 static void empty_trash_cb(MainWindow *mainwin, guint action,
2980                            GtkWidget *widget)
2981 {
2982         main_window_empty_trash(mainwin, TRUE);
2983 }
2984
2985 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2986 {
2987         summary_save_as(mainwin->summaryview);
2988 }
2989
2990 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2991 {
2992         summary_print(mainwin->summaryview);
2993 }
2994
2995 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2996 {
2997         if (prefs_common.confirm_on_exit) {
2998                 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
2999                                GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
3000                     != G_ALERTALTERNATE)
3001                         return;
3002                 manage_window_focus_in(mainwin->window, NULL, NULL);
3003         }
3004
3005         app_will_exit(widget, mainwin);
3006 }
3007
3008 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3009 {
3010         if (action == 1)
3011                 summary_search(mainwin->summaryview);
3012         else
3013                 message_search(mainwin->messageview);
3014 }
3015
3016 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3017 {
3018         summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
3019 }
3020
3021 static void toggle_message_cb(MainWindow *mainwin, guint action,
3022                               GtkWidget *widget)
3023 {
3024         gboolean active;
3025
3026         active = GTK_CHECK_MENU_ITEM(widget)->active;
3027
3028         if (active != messageview_is_visible(mainwin->messageview))
3029                 summary_toggle_view(mainwin->summaryview);
3030 }
3031
3032 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3033                               GtkWidget *widget)
3034 {
3035         toolbar_toggle(action, mainwin);
3036 }
3037
3038 static void main_window_reply_cb(MainWindow *mainwin, guint action,
3039                           GtkWidget *widget)
3040 {
3041         MessageView *msgview = (MessageView*)mainwin->messageview;
3042         GSList *msginfo_list = NULL;
3043
3044         g_return_if_fail(msgview != NULL);
3045
3046         msginfo_list = summary_get_selection(mainwin->summaryview);
3047         g_return_if_fail(msginfo_list != NULL);
3048         compose_reply_from_messageview(msgview, msginfo_list, action);
3049         g_slist_free(msginfo_list);
3050 }
3051
3052
3053 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3054                                 GtkWidget *widget)
3055 {
3056         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3057                 gtk_widget_show(mainwin->hbox_stat);
3058                 prefs_common.show_statusbar = TRUE;
3059         } else {
3060                 gtk_widget_hide(mainwin->hbox_stat);
3061                 prefs_common.show_statusbar = FALSE;
3062         }
3063 }
3064
3065 static void set_layout_cb(MainWindow *mainwin, guint action,
3066                                GtkWidget *widget)
3067 {
3068         LayoutType layout_mode = action;
3069
3070         if (mainwin->menu_lock_count) {
3071                 return;
3072         }
3073         if (!GTK_CHECK_MENU_ITEM(widget)->active) {
3074                 return;
3075         }
3076         
3077         if (layout_mode == prefs_common.layout_mode) {
3078                 return;
3079         }
3080         
3081         if (!mainwin->messageview->visible)
3082                 main_window_toggle_message_view(mainwin);
3083
3084         main_window_separation_change(mainwin, layout_mode);
3085
3086         mainwin_reset_paned(GTK_PANED(mainwin->vpaned));
3087         summary_relayout(mainwin->summaryview); 
3088 }
3089
3090 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3091                                         gboolean ask_sync)
3092 {
3093         offline_ask_sync = ask_sync;
3094         if (offline)
3095                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3096         else
3097                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3098         offline_ask_sync = TRUE;
3099 }
3100
3101 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3102 {
3103         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3104 }
3105
3106 static gboolean any_folder_want_synchronise(void)
3107 {
3108         GList *folderlist = folder_get_list();
3109
3110         /* see if there are synchronised folders */
3111         for (; folderlist; folderlist = folderlist->next) {
3112                 Folder *folder = (Folder *)folderlist->data;
3113                 if (folder_want_synchronise(folder)) {
3114                         return TRUE;
3115                 }
3116         }
3117         
3118         return FALSE;
3119 }
3120
3121 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3122 {
3123         
3124         if (!any_folder_want_synchronise())
3125                 return;
3126
3127         if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3128                         _("Do you want to synchronise your folders now?"),
3129                         GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3130                 return;
3131
3132         folder_synchronise(NULL);
3133 }
3134
3135 static void online_switch_clicked (GtkButton *btn, gpointer data) 
3136 {
3137         MainWindow *mainwin;
3138         GtkItemFactory *ifactory;
3139         GtkCheckMenuItem *menuitem;
3140
3141         mainwin = (MainWindow *) data;
3142         
3143         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3144         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3145         
3146         g_return_if_fail(mainwin != NULL);
3147         g_return_if_fail(menuitem != NULL);
3148         
3149         if (btn == GTK_BUTTON(mainwin->online_switch)) {
3150                 gtk_widget_hide (mainwin->online_switch);
3151                 gtk_widget_show (mainwin->offline_switch);
3152                 menuitem->active = TRUE;
3153                 inc_autocheck_timer_remove();
3154                         
3155                 /* go offline */
3156                 if (prefs_common.work_offline)
3157                         return;
3158                 mainwindow_check_synchronise(mainwin, TRUE);
3159                 prefs_common.work_offline = TRUE;
3160                 imap_disconnect_all();
3161                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3162         } else {
3163                 /*go online */
3164                 if (!prefs_common.work_offline)
3165                         return;
3166                 gtk_widget_hide (mainwin->offline_switch);
3167                 gtk_widget_show (mainwin->online_switch);
3168                 menuitem->active = FALSE;
3169                 prefs_common.work_offline = FALSE;
3170                 inc_autocheck_timer_set();
3171                 refresh_resolvers();
3172                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3173         }
3174 }
3175
3176 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3177                                 GtkWidget *widget)
3178 {
3179         addressbook_open(NULL);
3180 }
3181
3182 static void log_window_show_cb(MainWindow *mainwin, guint action,
3183                                GtkWidget *widget)
3184 {
3185         log_window_show(mainwin->logwin);
3186 }
3187
3188 static void filtering_debug_window_show_cb(MainWindow *mainwin, guint action,
3189                                GtkWidget *widget)
3190 {
3191         log_window_show(mainwin->filtering_debugwin);
3192 }
3193
3194 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3195 {
3196         inc_cancel_all();
3197 }
3198
3199 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3200 {
3201         summary_move_to(mainwin->summaryview);
3202 }
3203
3204 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3205 {
3206         summary_copy_to(mainwin->summaryview);
3207 }
3208
3209 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3210 {
3211         summary_delete(mainwin->summaryview);
3212 }
3213
3214 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3215 {
3216         summary_delete_trash(mainwin->summaryview);
3217 }
3218
3219 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3220 {
3221         summary_cancel(mainwin->summaryview);
3222 }
3223
3224 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3225 {
3226         summary_open_msg(mainwin->summaryview);
3227 }
3228
3229 static void view_source_cb(MainWindow *mainwin, guint action,
3230                            GtkWidget *widget)
3231 {
3232         summary_view_source(mainwin->summaryview);
3233 }
3234
3235 static void show_all_header_cb(MainWindow *mainwin, guint action,
3236                                GtkWidget *widget)
3237 {
3238         if (mainwin->menu_lock_count) return;
3239         mainwin->summaryview->messageview->all_headers = 
3240                         GTK_CHECK_MENU_ITEM(widget)->active;
3241         summary_display_msg_selected(mainwin->summaryview,
3242                                      GTK_CHECK_MENU_ITEM(widget)->active);
3243 }
3244
3245 #define SET_CHECK_MENU_ACTIVE(path, active) \
3246 { \
3247         menuitem = gtk_item_factory_get_widget(ifactory, path); \
3248         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3249 }
3250
3251 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3252                                GtkWidget *widget)
3253 {
3254         GtkWidget *menuitem;
3255         GtkItemFactory *ifactory = mainwin->menu_factory;
3256
3257         if (mainwin->menu_lock_count) return;
3258
3259         prefs_common.hide_quotes = 
3260                         GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3261
3262         mainwin->menu_lock_count++;
3263         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3264         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3265         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3266         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3267         mainwin->menu_lock_count--;
3268
3269         summary_redisplay_msg(mainwin->summaryview);
3270 }
3271
3272 #undef SET_CHECK_MENU_ACTIVE
3273 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3274 {
3275         summary_mark(mainwin->summaryview);
3276 }
3277
3278 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3279 {
3280         summary_unmark(mainwin->summaryview);
3281 }
3282
3283 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3284                               GtkWidget *widget)
3285 {
3286         summary_mark_as_unread(mainwin->summaryview);
3287 }
3288
3289 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3290                             GtkWidget *widget)
3291 {
3292         summary_mark_as_read(mainwin->summaryview);
3293 }
3294
3295 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3296                              GtkWidget *widget)
3297 {
3298         summary_mark_all_read(mainwin->summaryview);
3299 }
3300
3301 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3302                              GtkWidget *widget)
3303 {
3304         summary_mark_as_spam(mainwin->summaryview, action, NULL);
3305 }
3306
3307 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3308                             GtkWidget *widget)
3309 {
3310         summary_ignore_thread(mainwin->summaryview);
3311 }
3312
3313 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3314                             GtkWidget *widget)
3315 {
3316         summary_unignore_thread(mainwin->summaryview);
3317 }
3318
3319 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3320                             GtkWidget *widget)
3321 {
3322         summary_msgs_lock(mainwin->summaryview);
3323 }
3324
3325 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3326                             GtkWidget *widget)
3327 {
3328         summary_msgs_unlock(mainwin->summaryview);
3329 }
3330
3331
3332 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3333 {
3334         summary_reedit(mainwin->summaryview);
3335 }
3336
3337 static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3338 {
3339         if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
3340                 summary_display_msg_selected(mainwin->summaryview, 
3341                         mainwin->messageview->mimeview->textview->show_all_headers);
3342         }
3343         messageview_list_urls(mainwin->messageview);
3344 }
3345
3346 static void add_address_cb(MainWindow *mainwin, guint action,
3347                            GtkWidget *widget)
3348 {
3349         summary_add_address(mainwin->summaryview);
3350 }
3351
3352 static void set_charset_cb(MainWindow *mainwin, guint action,
3353                            GtkWidget *widget)
3354 {
3355         const gchar *str;
3356
3357         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3358                 str = conv_get_charset_str((CharSet)action);
3359                 
3360                 g_free(mainwin->messageview->forced_charset);
3361                 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3362                 procmime_force_charset(str);
3363                 
3364                 summary_redisplay_msg(mainwin->summaryview);
3365                 
3366                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3367         }
3368 }
3369
3370 static void set_decode_cb(MainWindow *mainwin, guint action,
3371                            GtkWidget *widget)
3372 {
3373         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3374                 mainwin->messageview->forced_encoding = (EncodingType)action;
3375                 
3376                 summary_redisplay_msg(mainwin->summaryview);
3377                 
3378                 debug_print("forced encoding: %d\n", action);
3379         }
3380 }
3381
3382 static void hide_read_messages (MainWindow *mainwin, guint action,
3383                                 GtkWidget *widget)
3384 {
3385         if (!mainwin->summaryview->folder_item
3386             || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3387                 return;
3388         summary_toggle_show_read_messages(mainwin->summaryview);
3389 }
3390
3391 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3392 {
3393         gboolean threaded = FALSE;
3394         if (mainwin->menu_lock_count) return;
3395         if (!mainwin->summaryview->folder_item) return;
3396
3397         threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3398
3399         mainwin->summaryview->folder_item->threaded = threaded; 
3400
3401         mainwin->summaryview->threaded = threaded;
3402
3403         summary_show(mainwin->summaryview, 
3404                         mainwin->summaryview->folder_item);
3405 }
3406
3407 static void expand_threads_cb(MainWindow *mainwin, guint action,
3408                               GtkWidget *widget)
3409 {
3410         summary_expand_threads(mainwin->summaryview);
3411 }
3412
3413 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3414                                 GtkWidget *widget)
3415 {
3416         summary_collapse_threads(mainwin->summaryview);
3417 }
3418
3419 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3420                                 GtkWidget *widget)
3421 {
3422         prefs_summary_column_open();
3423 }
3424
3425 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3426                                 GtkWidget *widget)
3427 {
3428         prefs_folder_column_open();
3429 }
3430
3431 static void sort_summary_cb(MainWindow *mainwin, guint action,
3432                             GtkWidget *widget)
3433 {
3434         FolderItem *item = mainwin->summaryview->folder_item;
3435         GtkWidget *menuitem;
3436
3437         if (mainwin->menu_lock_count) return;
3438
3439         if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3440                 menuitem = gtk_item_factory_get_item
3441                         (mainwin->menu_factory, "/View/Sort/Ascending");
3442                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3443                              GTK_CHECK_MENU_ITEM(menuitem)->active
3444                              ? SORT_ASCENDING : SORT_DESCENDING);
3445                 item->sort_key = action;
3446         }
3447 }
3448
3449 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3450                                  GtkWidget *widget)
3451 {
3452         FolderItem *item = mainwin->summaryview->folder_item;
3453
3454         if (mainwin->menu_lock_count) return;
3455
3456         if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3457                 summary_sort(mainwin->summaryview,
3458                              item->sort_key, (FolderSortType)action);
3459 }
3460
3461 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3462                                   GtkWidget *widget)
3463 {
3464         summary_attract_by_subject(mainwin->summaryview);
3465 }
3466
3467 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3468                                  GtkWidget *widget)
3469 {
3470         FolderItem *item;
3471
3472         item = folderview_get_selected_item(mainwin->folderview);
3473         if (item) {
3474                 main_window_cursor_wait(mainwin);
3475                 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3476
3477                 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3478                                               DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3479
3480                 STATUSBAR_POP(mainwin);
3481                 main_window_cursor_normal(mainwin);
3482         }
3483 }
3484
3485 struct DelDupsData
3486 {
3487         guint   dups;
3488         guint   folders;
3489 };
3490
3491 static void deldup_all(FolderItem *item, gpointer _data)
3492 {
3493         struct DelDupsData *data = _data;
3494         gint result;
3495         
3496         result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3497         if (result >= 0) {
3498                 data->dups += result;
3499                 data->folders += 1;
3500         }
3501 }
3502
3503 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3504                                  GtkWidget *widget)
3505 {
3506         struct DelDupsData data = {0, 0};
3507
3508         main_window_cursor_wait(mainwin);
3509         folder_func_to_all_folders(deldup_all, &data);
3510         main_window_cursor_normal(mainwin);
3511         
3512         alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3513                                    "Deleted %d duplicate messages in %d folders.\n",
3514                                    data.dups),
3515                           data.dups, data.folders);
3516 }
3517
3518 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3519 {
3520         summary_filter(mainwin->summaryview, (gboolean)action);
3521 }
3522
3523 static void execute_summary_cb(MainWindow *mainwin, guint action,
3524                                GtkWidget *widget)
3525 {
3526         summary_execute(mainwin->summaryview);
3527 }
3528
3529 static void update_summary_cb(MainWindow *mainwin, guint action,
3530                               GtkWidget *widget)
3531 {
3532         FolderItem *fitem;
3533         FolderView *folderview = mainwin->folderview;
3534
3535         if (!mainwin->summaryview->folder_item) return;
3536         if (!folderview->opened) return;
3537
3538         folder_update_op_count();
3539
3540         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3541                                             folderview->opened);
3542         if (!fitem) return;
3543
3544         folder_item_scan(fitem);
3545         summary_show(mainwin->summaryview, fitem);
3546 }
3547
3548 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3549 {
3550         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3551 }
3552
3553 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3554 {
3555         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3556 }
3557
3558 static void prev_unread_cb(MainWindow *mainwin, guint action,
3559                            GtkWidget *widget)
3560 {
3561         summary_select_prev_unread(mainwin->summaryview);
3562 }
3563
3564 static void next_unread_cb(MainWindow *mainwin, guint action,
3565                            GtkWidget *widget)
3566 {
3567         summary_select_next_unread(mainwin->summaryview);
3568 }
3569
3570 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3571 {
3572         summary_select_prev_new(mainwin->summaryview);
3573 }
3574
3575 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3576 {
3577         summary_select_next_new(mainwin->summaryview);
3578 }
3579
3580 static void prev_marked_cb(MainWindow *mainwin, guint action,
3581                            GtkWidget *widget)
3582 {
3583         summary_select_prev_marked(mainwin->summaryview);
3584 }
3585
3586 static void next_marked_cb(MainWindow *mainwin, guint action,
3587                            GtkWidget *widget)
3588 {
3589         summary_select_next_marked(mainwin->summaryview);
3590 }
3591
3592 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3593                             GtkWidget *widget)
3594 {
3595         summary_select_prev_labeled(mainwin->summaryview);
3596 }
3597
3598 static void next_labeled_cb(MainWindow *mainwin, guint action,
3599                             GtkWidget *widget)
3600 {
3601         summary_select_next_labeled(mainwin->summaryview);
3602 }
3603
3604 static void last_read_cb(MainWindow *mainwin, guint action,
3605                             GtkWidget *widget)
3606 {
3607         summary_select_last_read(mainwin->summaryview);
3608 }
3609
3610 static void parent_cb(MainWindow *mainwin, guint action,
3611                             GtkWidget *widget)
3612 {
3613         summary_select_parent(mainwin->summaryview);
3614 }
3615
3616 static void goto_folder_cb(MainWindow *mainwin, guint action,
3617                            GtkWidget *widget)
3618 {
3619         FolderItem *to_folder;
3620
3621         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
3622
3623         if (to_folder)
3624                 folderview_select(mainwin->folderview, to_folder);
3625 }
3626
3627 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
3628                            GtkWidget *widget)
3629 {
3630         folderview_select_next_unread(mainwin->folderview, FALSE);
3631 }
3632
3633 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3634 {
3635         messageview_copy_clipboard(mainwin->messageview);
3636 }
3637
3638 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3639 {
3640         MessageView *msgview = mainwin->messageview;
3641
3642         if (messageview_is_visible(msgview) &&
3643                  (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3644                 messageview_select_all(mainwin->messageview);
3645         else
3646                 summary_select_all(mainwin->summaryview);
3647 }
3648
3649 static void select_thread_cb(MainWindow *mainwin, guint action,
3650                              GtkWidget *widget)
3651 {
3652         summary_select_thread(mainwin->summaryview, FALSE);
3653 }
3654
3655 static void delete_thread_cb(MainWindow *mainwin, guint action,
3656                              GtkWidget *widget)
3657 {
3658         summary_select_thread(mainwin->summaryview, TRUE);
3659 }
3660
3661 static void create_filter_cb(MainWindow *mainwin, guint action,
3662                              GtkWidget *widget)
3663 {
3664         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
3665 }
3666
3667 static void create_processing_cb(MainWindow *mainwin, guint action,
3668                              GtkWidget *widget)
3669 {
3670         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
3671 }
3672
3673 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
3674                                          GtkWidget *widget)
3675 {
3676         prefs_filtering_open(&pre_global_processing,
3677                              _("Processing rules to apply before folder rules"),
3678                              MANUAL_ANCHOR_PROCESSING,
3679                              NULL, NULL, FALSE);
3680 }
3681
3682 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
3683                                           GtkWidget *widget)
3684 {
3685         prefs_filtering_open(&post_global_processing,
3686                              _("Processing rules to apply after folder rules"),
3687                              MANUAL_ANCHOR_PROCESSING,
3688                              NULL, NULL, FALSE);
3689 }
3690
3691 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
3692                                     GtkWidget *widget)
3693 {
3694         prefs_filtering_open(&filtering_rules,
3695                              _("Filtering configuration"),
3696                              MANUAL_ANCHOR_FILTERING,
3697                              NULL, NULL, TRUE);
3698 }
3699
3700 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
3701                                    GtkWidget *widget)
3702 {
3703         prefs_template_open();
3704 }
3705
3706 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
3707                                   GtkWidget *widget)
3708 {
3709         prefs_actions_open(mainwin);
3710 }
3711 #ifdef USE_OPENSSL
3712 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
3713                                   GtkWidget *widget)
3714 {
3715         ssl_manager_open(mainwin);
3716 }
3717 #endif
3718 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
3719                                   GtkWidget *widget)
3720 {
3721         if (!cur_account) {
3722                 new_account_cb(mainwin, 0, widget);
3723         } else {
3724                 account_open(cur_account);
3725         }
3726 }
3727
3728 static void new_account_cb(MainWindow *mainwin, guint action,
3729                            GtkWidget *widget)
3730 {
3731         account_edit_open();
3732         if (!compose_get_compose_list()) account_add();
3733 }
3734
3735 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
3736 {
3737         FolderItem *item = NULL;
3738         cur_account = (PrefsAccount *)data;
3739         
3740         if (!mainwindow_get_mainwindow())
3741                 return;
3742         main_window_show_cur_account(mainwindow_get_mainwindow());
3743         toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
3744         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
3745         toolbar_main_set_sensitive(mainwindow_get_mainwindow());
3746         item = folderview_get_selected_item(
3747                         mainwindow_get_mainwindow()->folderview);
3748         if (item) {
3749                 toolbar_set_compose_button
3750                         (mainwindow_get_mainwindow()->toolbar,
3751                          FOLDER_TYPE(item->folder) == F_NEWS ? 
3752                          COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
3753         }
3754 }
3755
3756 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
3757 {
3758         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3759         PrefsAccount *account = (PrefsAccount *)data;
3760
3761         inc_account_mail(mainwin, account);
3762 }
3763
3764 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
3765 {
3766         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3767         PrefsAccount *account = (PrefsAccount *)data;
3768         FolderItem *item = mainwin->summaryview->folder_item;   
3769
3770         compose_new_with_folderitem(account, item, NULL);
3771 }
3772
3773 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
3774 {
3775         prefs_gtk_open();
3776 }
3777
3778 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
3779 {
3780         pluginwindow_create();
3781 }
3782
3783 static void manual_open_cb(MainWindow *mainwin, guint action,
3784                            GtkWidget *widget)
3785 {
3786         manual_open((ManualType)action, NULL);
3787 }
3788
3789 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
3790 {
3791         legend_show();
3792 }
3793
3794 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
3795 {
3796         MainWindow *mainwin = (MainWindow *)data;
3797         gchar *str;
3798
3799         if (item->path)
3800                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
3801                                       LOCAL_FOLDER(folder)->rootpath,
3802                                       G_DIR_SEPARATOR,
3803                                       item->path);
3804         else
3805                 str = g_strdup_printf(_("Scanning folder %s ..."),
3806                                       LOCAL_FOLDER(folder)->rootpath);
3807
3808         STATUSBAR_PUSH(mainwin, str);
3809         STATUSBAR_POP(mainwin);
3810         g_free(str);
3811 }
3812
3813 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
3814                                           gpointer data)
3815 {
3816         SummaryView *summary;
3817
3818         g_return_val_if_fail(data, FALSE);
3819         if (!g_list_find(mainwin_list, data))
3820                 return TRUE;
3821         summary = ((MainWindow *)data)->summaryview;
3822         g_return_val_if_fail(summary, FALSE);
3823
3824         if (GTK_CLIST(summary->ctree)->selection && 
3825             g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
3826                 return FALSE;
3827
3828         return FALSE;
3829 }
3830
3831 static gboolean mainwindow_visibility_event_cb(GtkWidget *widget, GdkEventVisibility *event,
3832                                           gpointer data)
3833 {
3834         is_obscured = (event->state == GDK_VISIBILITY_FULLY_OBSCURED);
3835         return FALSE;
3836 }
3837
3838 static gboolean mainwindow_state_event_cb(GtkWidget *widget, GdkEventWindowState *state,
3839                                           gpointer data)
3840 {
3841         if (!claws_is_starting()
3842                 && state->changed_mask&GDK_WINDOW_STATE_ICONIFIED
3843                 && state->new_window_state&GDK_WINDOW_STATE_ICONIFIED) {
3844
3845                 if (iconified_count > 0)
3846                         hooks_invoke(MAIN_WINDOW_GOT_ICONIFIED, NULL);
3847                 iconified_count++;
3848         }
3849         if (state->new_window_state == 0)
3850                 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(widget), FALSE);
3851         return FALSE;
3852 }
3853
3854 gboolean mainwindow_is_obscured(void)
3855 {
3856         return is_obscured;
3857 }
3858
3859 #define BREAK_ON_MODIFIER_KEY() \
3860         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
3861
3862 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
3863                                     gpointer data)
3864 {
3865         MainWindow *mainwin = (MainWindow*) data;
3866         
3867         if