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