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