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