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