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