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