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