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