a025a84fdaa06d514bb53e9d2392006f93a16d64
[claws.git] / src / mainwindow.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include "defs.h"
21
22 #include <glib.h>
23 #include <glib/gi18n.h>
24 #include <gdk/gdkkeysyms.h>
25 #include <gtk/gtkmain.h>
26 #include <gtk/gtkwindow.h>
27 #include <gtk/gtkwidget.h>
28 #include <gtk/gtksignal.h>
29 #include <gtk/gtkvbox.h>
30 #include <gtk/gtkcontainer.h>
31 #include <gtk/gtkstatusbar.h>
32 #include <gtk/gtkprogressbar.h>
33 #include <gtk/gtkhpaned.h>
34 #include <gtk/gtkvpaned.h>
35 #include <gtk/gtkcheckmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkeditable.h>
38 #include <gtk/gtkmenu.h>
39 #include <gtk/gtkmenuitem.h>
40 #include <gtk/gtkhandlebox.h>
41 #include <gtk/gtktoolbar.h>
42 #include <gtk/gtkbutton.h>
43 #include <gtk/gtktooltips.h>
44 #include <string.h>
45
46 #include "main.h"
47 #include "mainwindow.h"
48 #include "folderview.h"
49 #include "foldersel.h"
50 #include "summaryview.h"
51 #include "summary_search.h"
52 #include "messageview.h"
53 #include "message_search.h"
54 #include "headerview.h"
55 #include "menu.h"
56 #include "stock_pixmap.h"
57 #include "folder.h"
58 #include "inc.h"
59 #include "log.h"
60 #include "compose.h"
61 #include "procmsg.h"
62 #include "import.h"
63 #include "export.h"
64 #include "edittags.h"
65 #include "prefs_common.h"
66 #include "prefs_actions.h"
67 #include "prefs_filtering.h"
68 #include "prefs_account.h"
69 #include "prefs_summary_column.h"
70 #include "prefs_folder_column.h"
71 #include "prefs_template.h"
72 #include "action.h"
73 #include "account.h"
74 #include "addressbook.h"
75 #include "logwindow.h"
76 #include "manage_window.h"
77 #include "alertpanel.h"
78 #include "statusbar.h"
79 #include "inputdialog.h"
80 #include "utils.h"
81 #include "gtkutils.h"
82 #include "codeconv.h"
83 #include "about.h"
84 #include "manual.h"
85 #include "version.h"
86 #include "ssl_manager.h"
87 #include "sslcertwindow.h"
88 #include "prefs_gtk.h"
89 #include "pluginwindow.h"
90 #include "hooks.h"
91 #include "progressindicator.h"
92 #include "localfolder.h"
93 #include "filtering.h"
94 #include "folderutils.h"
95 #include "foldersort.h"
96 #include "icon_legend.h"
97 #include "colorlabel.h"
98 #include "tags.h"
99 #include "textview.h"
100 #include "imap.h"
101 #include "socket.h"
102
103 #define AC_LABEL_WIDTH  240
104
105 /* list of all instantiated MainWindow */
106 static GList *mainwin_list = NULL;
107
108 static GdkCursor *watch_cursor = NULL;
109 static GdkCursor *hand_cursor = NULL;
110
111 static gint iconified_count = 0;
112
113 static void main_window_menu_callback_block     (MainWindow     *mainwin);
114 static void main_window_menu_callback_unblock   (MainWindow     *mainwin);
115
116 static void main_window_show_cur_account        (MainWindow     *mainwin);
117
118 static void main_window_separation_change       (MainWindow     *mainwin,
119                                                  LayoutType      layout_mode);
120
121 static void main_window_set_widgets             (MainWindow     *mainwin,
122                                                  LayoutType      layout_mode);
123
124 static void toolbar_child_attached              (GtkWidget      *widget,
125                                                  GtkWidget      *child,
126                                                  gpointer        data);
127 static void toolbar_child_detached              (GtkWidget      *widget,
128                                                  GtkWidget      *child,
129                                                  gpointer        data);
130
131 static gboolean ac_label_button_pressed         (GtkWidget      *widget,
132                                                  GdkEventButton *event,
133                                                  gpointer        data);
134
135 static gint main_window_close_cb                (GtkWidget      *widget,
136                                                  GdkEventAny    *event,
137                                                  gpointer        data);
138
139 static void main_window_size_allocate_cb        (GtkWidget      *widget,
140                                                  GtkAllocation  *allocation,
141                                                  gpointer        data);
142 static void folder_window_size_allocate_cb      (GtkWidget      *widget,
143                                                  GtkAllocation  *allocation,
144                                                  gpointer        data);
145 static void message_window_size_allocate_cb     (GtkWidget      *widget,
146                                                  GtkAllocation  *allocation,
147                                                  gpointer        data);
148
149 static void update_folderview_cb (MainWindow    *mainwin,
150                                   guint          action,
151                                   GtkWidget     *widget);
152 static void add_mailbox_cb       (MainWindow    *mainwin,
153                                   guint          action,
154                                   GtkWidget     *widget);
155 static void foldersort_cb        (MainWindow    *mainwin,
156                                   guint          action,
157                                   GtkWidget     *widget);
158 static void import_mbox_cb       (MainWindow    *mainwin,
159                                   guint          action,
160                                   GtkWidget     *widget);
161 static void export_mbox_cb       (MainWindow    *mainwin,
162                                   guint          action,
163                                   GtkWidget     *widget);
164 static void export_list_mbox_cb  (MainWindow    *mainwin, 
165                                   guint          action,
166                                   GtkWidget     *widget);
167 static void empty_trash_cb       (MainWindow    *mainwin,
168                                   guint          action,
169                                   GtkWidget     *widget);
170
171 static void save_as_cb           (MainWindow    *mainwin,
172                                   guint          action,
173                                   GtkWidget     *widget);
174 static void print_cb             (MainWindow    *mainwin,
175                                   guint          action,
176                                   GtkWidget     *widget);
177 static void app_exit_cb          (MainWindow    *mainwin,
178                                   guint          action,
179                                   GtkWidget     *widget);
180
181 static void search_cb            (MainWindow    *mainwin,
182                                   guint          action,
183                                   GtkWidget     *widget);
184
185 static void toggle_message_cb    (MainWindow    *mainwin,
186                                   guint          action,
187                                   GtkWidget     *widget);
188 static void toggle_toolbar_cb    (MainWindow    *mainwin,
189                                   guint          action,
190                                   GtkWidget     *widget);
191 static void toggle_statusbar_cb  (MainWindow    *mainwin,
192                                   guint          action,
193                                   GtkWidget     *widget);
194 static void set_layout_cb        (MainWindow    *mainwin,
195                                   guint          action,
196                                   GtkWidget     *widget);
197
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         {N_("/_View/La_yout"),                  NULL, NULL, 0, "<Branch>"},
569         {N_("/_View/Layout/_Standard"),         NULL, set_layout_cb, NORMAL_LAYOUT, "<RadioItem>"},
570         {N_("/_View/Layout/_Three columns"),    NULL, set_layout_cb, VERTICAL_LAYOUT, "/View/Layout/Standard"},
571         {N_("/_View/Layout/_Wide message"),     NULL, set_layout_cb, WIDE_LAYOUT, "/View/Layout/Standard"},
572         {N_("/_View/Layout/W_ide message list"),NULL, set_layout_cb, WIDE_MSGLIST_LAYOUT, "/View/Layout/Standard"},
573         {N_("/_View/Layout/S_mall screen"),     NULL, set_layout_cb, SMALL_LAYOUT, "/View/Layout/Standard"},
574         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
575         {N_("/_View/_Sort"),                    NULL, NULL, 0, "<Branch>"},
576         {N_("/_View/_Sort/by _number"),         NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
577         {N_("/_View/_Sort/by S_ize"),           NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
578         {N_("/_View/_Sort/by _Date"),           NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
579         {N_("/_View/_Sort/by Thread date"),     NULL, sort_summary_cb, SORT_BY_THREAD_DATE, "/View/Sort/by number"},
580         {N_("/_View/_Sort/by _From"),           NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
581         {N_("/_View/_Sort/by _To"),             NULL, sort_summary_cb, SORT_BY_TO, "/View/Sort/by number"},
582         {N_("/_View/_Sort/by S_ubject"),        NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
583         {N_("/_View/_Sort/by _color label"),
584                                                 NULL, sort_summary_cb, SORT_BY_TAGS, "/View/Sort/by number"},
585         {N_("/_View/_Sort/by tag"),
586                                                 NULL, sort_summary_cb, SORT_BY_LABEL, "/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
1326         if (!geometry.min_height) {
1327                 geometry.min_width = 320;
1328                 geometry.min_height = 200;
1329         }
1330         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
1331                                       GDK_HINT_MIN_SIZE);
1332
1333         g_signal_connect(G_OBJECT(window), "delete_event",
1334                          G_CALLBACK(main_window_close_cb), mainwin);
1335         MANAGE_WINDOW_SIGNALS_CONNECT(window);
1336         g_signal_connect(G_OBJECT(window), "focus_in_event",
1337                          G_CALLBACK(mainwindow_focus_in_event),
1338                          mainwin);
1339         g_signal_connect(G_OBJECT(window), "key_press_event",
1340                          G_CALLBACK(mainwindow_key_pressed), mainwin);
1341
1342         gtk_widget_realize(window);
1343         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
1344         
1345
1346         gtkut_widget_set_app_icon(window);
1347
1348         vbox = gtk_vbox_new(FALSE, 0);
1349         gtk_widget_show(vbox);
1350         gtk_container_add(GTK_CONTAINER(window), vbox);
1351
1352         /* menu bar */
1353         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
1354         menubar = menubar_create(window, mainwin_entries, 
1355                                  n_menu_entries, "<Main>", mainwin);
1356         gtk_widget_show(menubar);
1357         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
1358         ifactory = gtk_item_factory_from_widget(menubar);
1359
1360 /*      gtk_widget_show(gtk_item_factory_get_item(ifactory,"/Message/Mailing-List"));
1361         main_create_mailing_list_menu (mainwin, NULL); */
1362
1363         menu_set_sensitive(ifactory, "/Help/Manual", manual_available(MANUAL_MANUAL_LOCAL));
1364
1365         if (prefs_common.toolbar_detachable) {
1366                 handlebox = gtk_handle_box_new();
1367                 gtk_widget_show(handlebox);
1368                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1369                 g_signal_connect(G_OBJECT(handlebox), "child_attached",
1370                                  G_CALLBACK(toolbar_child_attached), mainwin);
1371                 g_signal_connect(G_OBJECT(handlebox), "child_detached",
1372                                  G_CALLBACK(toolbar_child_detached), mainwin);
1373         } else {
1374                 handlebox = gtk_hbox_new(FALSE, 0);
1375                 gtk_widget_show(handlebox);
1376                 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
1377         }
1378         /* link window to mainwin->window to avoid gdk warnings */
1379         mainwin->window       = window;
1380         
1381         /* create toolbar */
1382         mainwin->toolbar = toolbar_create(TOOLBAR_MAIN, 
1383                                           handlebox, 
1384                                           (gpointer)mainwin);
1385         toolbar_set_learn_button
1386                 (mainwin->toolbar,
1387                  LEARN_SPAM);
1388
1389         /* vbox that contains body */
1390         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
1391         gtk_widget_show(vbox_body);
1392         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
1393         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
1394
1395         hbox_stat = gtk_hbox_new(FALSE, 2);
1396         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
1397
1398         tips = gtk_tooltips_new();
1399
1400         warning_icon = gtk_image_new_from_stock
1401                         (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1402         warning_btn = gtk_event_box_new();
1403         gtk_event_box_set_visible_window(GTK_EVENT_BOX(warning_btn), FALSE);
1404         
1405         mainwin->warning_btn      = warning_btn;
1406         
1407         g_signal_connect(G_OBJECT(warning_btn), "button-press-event", 
1408                          G_CALLBACK(warning_icon_pressed),
1409                          (gpointer) mainwin);
1410         g_signal_connect(G_OBJECT(warning_btn), "visibility-notify-event",
1411                          G_CALLBACK(warning_visi_notify), mainwin);
1412         g_signal_connect(G_OBJECT(warning_btn), "motion-notify-event",
1413                          G_CALLBACK(warning_visi_notify), mainwin);
1414         g_signal_connect(G_OBJECT(warning_btn), "leave-notify-event",
1415                          G_CALLBACK(warning_leave_notify), mainwin);
1416         g_signal_connect(G_OBJECT(warning_btn), "enter-notify-event",
1417                          G_CALLBACK(warning_enter_notify), mainwin);
1418
1419         gtk_container_add (GTK_CONTAINER(warning_btn), warning_icon);
1420
1421         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),warning_btn, 
1422                              _("Some error(s) happened. Click here to view log."), NULL);
1423         gtk_box_pack_start(GTK_BOX(hbox_stat), warning_btn, FALSE, FALSE, 0);
1424
1425         statusbar = statusbar_create();
1426         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
1427
1428         progressbar = gtk_progress_bar_new();
1429         gtk_widget_set_size_request(progressbar, 120, 1);
1430         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
1431
1432         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_ONLINE);
1433         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_OFFLINE);
1434         online_switch = gtk_button_new ();
1435         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),online_switch, 
1436                              _("You are online. Click the icon to go offline"), NULL);
1437         offline_switch = gtk_button_new ();
1438         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),offline_switch, 
1439                              _("You are offline. Click the icon to go online"),
1440                              NULL);
1441         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
1442         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
1443         g_signal_connect (G_OBJECT(online_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1444         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
1445         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
1446         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
1447         g_signal_connect (G_OBJECT(offline_switch), "clicked", G_CALLBACK(online_switch_clicked), mainwin);
1448         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
1449         
1450         statuslabel = gtk_label_new("");
1451         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
1452
1453         ac_button = gtk_button_new();
1454         gtk_tooltips_set_tip(GTK_TOOLTIPS(tips),
1455                              ac_button, _("Select account"), NULL);
1456         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
1457         gtk_widget_set_size_request(ac_button, -1, 0);
1458         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
1459         g_signal_connect(G_OBJECT(ac_button), "button_press_event",
1460                          G_CALLBACK(ac_label_button_pressed), mainwin);
1461
1462         ac_label = gtk_label_new("");
1463         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
1464
1465         gtk_widget_show_all(hbox_stat);
1466
1467         gtk_widget_hide(offline_switch);
1468         gtk_widget_hide(warning_btn);
1469
1470         /* create views */
1471         mainwin->folderview  = folderview  = folderview_create();
1472         mainwin->summaryview = summaryview = summary_create();
1473         mainwin->messageview = messageview = messageview_create(mainwin);
1474
1475         /* init log instances data before creating log views */
1476         set_log_title(LOG_PROTOCOL, _("Network log"));
1477         set_log_prefs(LOG_PROTOCOL,
1478                         &prefs_common.logwin_width,
1479                         &prefs_common.logwin_height);
1480         set_log_title(LOG_DEBUG_FILTERING, _("Filtering/processing debug log"));
1481         set_log_prefs(LOG_DEBUG_FILTERING,
1482                         &prefs_common.filtering_debugwin_width,
1483                         &prefs_common.filtering_debugwin_height);
1484
1485         /* setup log windows */
1486         mainwin->logwin = log_window_create(LOG_PROTOCOL);
1487         log_window_init(mainwin->logwin);
1488
1489         mainwin->filtering_debugwin = log_window_create(LOG_DEBUG_FILTERING);
1490         log_window_set_clipping(mainwin->logwin,
1491                                 prefs_common.cliplog,
1492                                 prefs_common.loglength);
1493
1494         log_window_init(mainwin->filtering_debugwin);
1495         log_window_set_clipping(mainwin->filtering_debugwin,
1496                                 prefs_common.filtering_debug_cliplog,
1497                                 prefs_common.filtering_debug_loglength);
1498         if (prefs_common.enable_filtering_debug)
1499                 log_message(LOG_DEBUG_FILTERING, _("filtering log enabled\n"));
1500         else
1501                 log_message(LOG_DEBUG_FILTERING, _("filtering log disabled\n"));
1502
1503         folderview->mainwin      = mainwin;
1504         folderview->summaryview  = summaryview;
1505
1506         summaryview->mainwin     = mainwin;
1507         summaryview->folderview  = folderview;
1508         summaryview->messageview = messageview;
1509         summaryview->window      = window;
1510
1511         messageview->statusbar   = statusbar;
1512         mainwin->vbox           = vbox;
1513         mainwin->menubar        = menubar;
1514         mainwin->menu_factory   = ifactory;
1515         mainwin->handlebox      = handlebox;
1516         mainwin->vbox_body      = vbox_body;
1517         mainwin->hbox_stat      = hbox_stat;
1518         mainwin->statusbar      = statusbar;
1519         mainwin->progressbar    = progressbar;
1520         mainwin->statuslabel    = statuslabel;
1521         mainwin->online_switch  = online_switch;
1522         mainwin->online_pixmap  = online_pixmap;
1523         mainwin->offline_pixmap = offline_pixmap;
1524         mainwin->ac_button      = ac_button;
1525         mainwin->ac_label       = ac_label;
1526         mainwin->offline_switch    = offline_switch;
1527         
1528         /* set context IDs for status bar */
1529         mainwin->mainwin_cid = gtk_statusbar_get_context_id
1530                 (GTK_STATUSBAR(statusbar), "Main Window");
1531         mainwin->folderview_cid = gtk_statusbar_get_context_id
1532                 (GTK_STATUSBAR(statusbar), "Folder View");
1533         mainwin->summaryview_cid = gtk_statusbar_get_context_id
1534                 (GTK_STATUSBAR(statusbar), "Summary View");
1535         mainwin->messageview_cid = gtk_statusbar_get_context_id
1536                 (GTK_STATUSBAR(statusbar), "Message View");
1537
1538         messageview->statusbar_cid = mainwin->messageview_cid;
1539
1540         /* allocate colors for summary view and folder view */
1541         summaryview->color_marked.red = summaryview->color_marked.green = 0;
1542         summaryview->color_marked.blue = (guint16)65535;
1543
1544         summaryview->color_dim.red = summaryview->color_dim.green =
1545                 summaryview->color_dim.blue = COLOR_DIM;
1546
1547         gtkut_convert_int_to_gdk_color(prefs_common.color_new,
1548                                        &folderview->color_new);
1549
1550         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1551                                        &folderview->color_op);
1552
1553         summaryview->color_important.red = 0;
1554         summaryview->color_important.green = 0;
1555         summaryview->color_important.blue = (guint16)65535;
1556
1557         color[0] = summaryview->color_marked;
1558         color[1] = summaryview->color_dim;
1559         color[2] = folderview->color_new;
1560         color[3] = folderview->color_op;
1561
1562         colormap = gdk_drawable_get_colormap(window->window);
1563         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1564         for (i = 0; i < 4; i++) {
1565                 if (success[i] == FALSE)
1566                         g_warning("MainWindow: color allocation %d failed\n", i);
1567         }
1568
1569         debug_print("done.\n");
1570
1571         messageview->visible = prefs_common.msgview_visible;
1572
1573         main_window_set_widgets(mainwin, prefs_common.layout_mode);
1574
1575         g_signal_connect(G_OBJECT(window), "size_allocate",
1576                          G_CALLBACK(main_window_size_allocate_cb),
1577                          mainwin);
1578
1579         /* set menu items */
1580         menuitem = gtk_item_factory_get_item
1581                 (ifactory, "/View/Character encoding/Auto detect");
1582         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1583
1584         switch (prefs_common.toolbar_style) {
1585         case TOOLBAR_NONE:
1586                 menuitem = gtk_item_factory_get_item
1587                         (ifactory, "/View/Show or hide/Toolbar/Hide");
1588                 break;
1589         case TOOLBAR_ICON:
1590                 menuitem = gtk_item_factory_get_item
1591                         (ifactory, "/View/Show or hide/Toolbar/Icons only");
1592                 break;
1593         case TOOLBAR_TEXT:
1594                 menuitem = gtk_item_factory_get_item
1595                         (ifactory, "/View/Show or hide/Toolbar/Text only");
1596                 break;
1597         case TOOLBAR_BOTH:
1598                 menuitem = gtk_item_factory_get_item
1599                         (ifactory, "/View/Show or hide/Toolbar/Text below icons");
1600                 break;
1601         case TOOLBAR_BOTH_HORIZ:
1602                 menuitem = gtk_item_factory_get_item
1603                         (ifactory,
1604                          "/View/Show or hide/Toolbar/Text beside icons");
1605         }
1606         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1607
1608         gtk_widget_hide(mainwin->hbox_stat);
1609         menuitem = gtk_item_factory_get_item
1610                 (ifactory, "/View/Show or hide/Status bar");
1611         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1612                                        prefs_common.show_statusbar);
1613         
1614         /* set account selection menu */
1615         ac_menu = gtk_item_factory_get_widget
1616                 (ifactory, "/Configuration/Change current account");
1617         mainwin->ac_menu = ac_menu;
1618
1619         toolbar_main_set_sensitive(mainwin);
1620
1621         /* create actions menu */
1622         main_window_update_actions_menu(mainwin);
1623
1624         main_create_mailing_list_menu (mainwin, NULL);
1625
1626         /* attach accel groups to main window */
1627 #define ADD_MENU_ACCEL_GROUP_TO_WINDOW(menu,win)                        \
1628         gtk_window_add_accel_group                                      \
1629                 (GTK_WINDOW(win),                                       \
1630                  gtk_item_factory_from_widget(menu)->accel_group);      \
1631         g_signal_connect(G_OBJECT(gtk_item_factory_from_widget(menu)->accel_group), \
1632                         "accel_activate",                               \
1633                         G_CALLBACK(main_window_accel_activate), mainwin);
1634                          
1635         
1636         ADD_MENU_ACCEL_GROUP_TO_WINDOW(summaryview->popupmenu, mainwin->window);
1637         
1638         /* connect the accelerators for equivalent 
1639            menu items in different menus             */
1640         menu_connect_identical_items();
1641
1642         gtk_window_iconify(GTK_WINDOW(mainwin->window));
1643
1644         g_signal_connect(G_OBJECT(window), "window_state_event",
1645                          G_CALLBACK(mainwindow_state_event_cb), mainwin);
1646         g_signal_connect(G_OBJECT(window), "visibility_notify_event",
1647                          G_CALLBACK(mainwindow_visibility_event_cb), mainwin);
1648         gtk_widget_add_events(GTK_WIDGET(window), GDK_VISIBILITY_NOTIFY_MASK);
1649
1650         if (prefs_common.layout_mode == VERTICAL_LAYOUT ||
1651             prefs_common.layout_mode == SMALL_LAYOUT) {
1652                 summary_relayout(mainwin->summaryview); 
1653         }
1654         summary_update_unread(mainwin->summaryview, NULL);
1655         
1656         gtk_widget_show(mainwin->window);
1657
1658         /* initialize views */
1659         folderview_init(folderview);
1660         summary_init(summaryview);
1661         messageview_init(messageview);
1662 #ifdef USE_OPENSSL
1663         sslcertwindow_register_hook();
1664 #endif
1665         mainwin->lock_count = 0;
1666         mainwin->menu_lock_count = 0;
1667         mainwin->cursor_count = 0;
1668
1669         mainwin->progressindicator_hook =
1670                 hooks_register_hook(PROGRESSINDICATOR_HOOKLIST, mainwindow_progressindicator_hook, mainwin);
1671
1672         if (!watch_cursor)
1673                 watch_cursor = gdk_cursor_new(GDK_WATCH);
1674         if (!hand_cursor)
1675                 hand_cursor = gdk_cursor_new(GDK_HAND2);
1676
1677         mainwin_list = g_list_append(mainwin_list, mainwin);
1678
1679         /* init work_offline */
1680         if (prefs_common.work_offline)
1681                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1682
1683         mainwindow_colorlabel_menu_create(mainwin, FALSE);
1684         mainwindow_tags_menu_create(mainwin, FALSE);
1685         
1686         return mainwin;
1687 }
1688
1689 void main_window_destroy(MainWindow *mainwin)
1690 {
1691         /* TODO : destroy other component */
1692         messageview_destroy(mainwin->messageview);
1693         mainwin->messageview = NULL;    
1694 }
1695
1696 void main_window_update_actions_menu(MainWindow *mainwin)
1697 {
1698         GtkItemFactory *ifactory;
1699
1700         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1701         action_update_mainwin_menu(ifactory, "/Tools/Actions", mainwin);
1702 }
1703
1704 void main_window_cursor_wait(MainWindow *mainwin)
1705 {
1706
1707         if (mainwin->cursor_count == 0) {
1708                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1709                 textview_cursor_wait(mainwin->messageview->mimeview->textview);
1710         }
1711         
1712         mainwin->cursor_count++;
1713
1714         gdk_flush();
1715 }
1716
1717 void main_window_cursor_normal(MainWindow *mainwin)
1718 {
1719         if (mainwin->cursor_count)
1720                 mainwin->cursor_count--;
1721
1722         if (mainwin->cursor_count == 0) {
1723                 gdk_window_set_cursor(mainwin->window->window, NULL);
1724                 textview_cursor_normal(mainwin->messageview->mimeview->textview);
1725         }
1726         gdk_flush();
1727 }
1728
1729 /* lock / unlock the user-interface */
1730 void main_window_lock(MainWindow *mainwin)
1731 {
1732         if (mainwin->lock_count == 0)
1733                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1734
1735         mainwin->lock_count++;
1736
1737         main_window_set_menu_sensitive(mainwin);
1738         toolbar_main_set_sensitive(mainwin);
1739 }
1740
1741 void main_window_unlock(MainWindow *mainwin)
1742 {
1743         if (mainwin->lock_count)
1744                 mainwin->lock_count--;
1745
1746         main_window_set_menu_sensitive(mainwin);
1747         toolbar_main_set_sensitive(mainwin);
1748
1749         if (mainwin->lock_count == 0)
1750                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1751 }
1752
1753 static void main_window_menu_callback_block(MainWindow *mainwin)
1754 {
1755         mainwin->menu_lock_count++;
1756 }
1757
1758 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1759 {
1760         if (mainwin->menu_lock_count)
1761                 mainwin->menu_lock_count--;
1762 }
1763
1764 static guint prefs_tag = 0;
1765
1766 void main_window_reflect_prefs_all(void)
1767 {
1768         main_window_reflect_prefs_all_real(FALSE);
1769 }
1770
1771 static gboolean reflect_prefs_timeout_cb(gpointer data) 
1772 {
1773         gboolean pixmap_theme_changed = GPOINTER_TO_INT(data);
1774         GList *cur;
1775         MainWindow *mainwin;
1776         GtkWidget *pixmap;
1777
1778         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1779                 mainwin = (MainWindow *)cur->data;
1780
1781                 main_window_show_cur_account(mainwin);
1782                 main_window_set_menu_sensitive(mainwin);
1783                 toolbar_main_set_sensitive(mainwin);
1784
1785                 /* pixmap themes */
1786                 if (pixmap_theme_changed) {
1787                         toolbar_update(TOOLBAR_MAIN, mainwin);
1788                         messageview_reflect_prefs_pixmap_theme();
1789                         compose_reflect_prefs_pixmap_theme();
1790                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1791                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1792
1793                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_ONLINE);
1794                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
1795                                              mainwin->online_pixmap);
1796                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1797                         gtk_widget_show(pixmap);
1798                         mainwin->online_pixmap = pixmap;
1799                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_OFFLINE);
1800                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
1801                                              mainwin->offline_pixmap);
1802                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1803                         gtk_widget_show(pixmap);
1804                         mainwin->offline_pixmap = pixmap;
1805                 }
1806                 
1807                 headerview_set_font(mainwin->messageview->headerview);
1808                 headerview_set_visibility(mainwin->messageview->headerview,
1809                                           prefs_common.display_header_pane);
1810                 textview_reflect_prefs(mainwin->messageview->mimeview->textview);
1811                 folderview_reflect_prefs();
1812                 summary_reflect_prefs();
1813                 summary_redisplay_msg(mainwin->summaryview);
1814         }
1815         prefs_tag = 0;
1816         return FALSE;
1817 }
1818
1819 void main_window_reflect_prefs_all_now(void)
1820 {
1821         reflect_prefs_timeout_cb(GINT_TO_POINTER(FALSE));
1822 }
1823
1824 void main_window_reflect_prefs_custom_colors(MainWindow *mainwin)
1825 {
1826         GtkMenuShell *menu;
1827         GList *cur;
1828
1829         /* re-create colorlabel submenu */
1830         menu = GTK_MENU_SHELL(mainwin->colorlabel_menu);
1831         g_return_if_fail(menu != NULL);
1832
1833         /* clear items. get item pointers. */
1834         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1835                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1836         }
1837         mainwindow_colorlabel_menu_create(mainwin, TRUE);
1838         summary_reflect_prefs_custom_colors(mainwin->summaryview);
1839
1840 }
1841
1842 void main_window_reflect_tags_changes(MainWindow *mainwin)
1843 {
1844         GtkMenuShell *menu;
1845         GList *cur;
1846
1847         /* re-create tags submenu */
1848         menu = GTK_MENU_SHELL(mainwin->tags_menu);
1849         g_return_if_fail(menu != NULL);
1850
1851         /* clear items. get item pointers. */
1852         for (cur = menu->children; cur != NULL && cur->data != NULL; cur = cur->next) {
1853                 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(cur->data));
1854         }
1855         mainwindow_tags_menu_create(mainwin, TRUE);
1856         summary_reflect_tags_changes(mainwin->summaryview);
1857
1858 }
1859
1860 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1861 {
1862         if (prefs_tag == 0 || pixmap_theme_changed) {
1863                 prefs_tag = g_timeout_add(500, reflect_prefs_timeout_cb, 
1864                                                 GINT_TO_POINTER(pixmap_theme_changed));
1865         }
1866 }
1867
1868 void main_window_set_summary_column(void)
1869 {
1870         GList *cur;
1871         MainWindow *mainwin;
1872
1873         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1874                 mainwin = (MainWindow *)cur->data;
1875                 summary_set_column_order(mainwin->summaryview);
1876         }
1877 }
1878
1879 void main_window_set_folder_column(void)
1880 {
1881         GList *cur;
1882         MainWindow *mainwin;
1883
1884         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1885                 mainwin = (MainWindow *)cur->data;
1886                 folderview_set_column_order(mainwin->folderview);
1887         }
1888 }
1889
1890 static void main_window_set_account_selector_menu(MainWindow *mainwin,
1891                                                   GList *account_list)
1892 {
1893         GList *cur_ac, *cur_item;
1894         GtkWidget *menuitem;
1895         PrefsAccount *ac_prefs;
1896
1897         /* destroy all previous menu item */
1898         cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1899         while (cur_item != NULL) {
1900                 GList *next = cur_item->next;
1901                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1902                 cur_item = next;
1903         }
1904
1905         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1906                 ac_prefs = (PrefsAccount *)cur_ac->data;
1907
1908                 menuitem = gtk_menu_item_new_with_label
1909                         (ac_prefs->account_name
1910                          ? ac_prefs->account_name : _("Untitled"));
1911                 gtk_widget_show(menuitem);
1912                 gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1913                 g_signal_connect(G_OBJECT(menuitem), "activate",
1914                                  G_CALLBACK(account_selector_menu_cb),
1915                                  ac_prefs);
1916         }
1917 }
1918
1919 static void main_window_set_account_receive_menu(MainWindow *mainwin,
1920                                                  GList *account_list)
1921 {
1922         GList *cur_ac, *cur_item;
1923         GtkWidget *menu;
1924         GtkWidget *menuitem;
1925         PrefsAccount *ac_prefs;
1926
1927         menu = gtk_item_factory_get_widget(mainwin->menu_factory,
1928                                            "/Message/Receive");
1929
1930         /* search for separator */
1931         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
1932              cur_item = cur_item->next) {
1933                 if (GTK_BIN(cur_item->data)->child == NULL) {
1934                         cur_item = cur_item->next;
1935                         break;
1936                 }
1937         }
1938
1939         /* destroy all previous menu item */
1940         while (cur_item != NULL) {
1941                 GList *next = cur_item->next;
1942                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1943                 cur_item = next;
1944         }
1945
1946         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1947                 ac_prefs = (PrefsAccount *)cur_ac->data;
1948
1949                 menuitem = gtk_menu_item_new_with_label
1950                         (ac_prefs->account_name ? ac_prefs->account_name
1951                          : _("Untitled"));
1952                 gtk_widget_show(menuitem);
1953                 gtk_menu_append(GTK_MENU(menu), menuitem);
1954                 g_signal_connect(G_OBJECT(menuitem), "activate",
1955                                  G_CALLBACK(account_receive_menu_cb),
1956                                  ac_prefs);
1957         }
1958 }
1959
1960 static void main_window_set_toolbar_combo_receive_menu(MainWindow *mainwin,
1961                                                        GList *account_list)
1962 {
1963         GList *cur_ac, *cur_item;
1964         GtkWidget *menuitem;
1965         PrefsAccount *ac_prefs;
1966         GtkWidget *menu = NULL;
1967
1968         if (mainwin->toolbar->getall_btn == NULL
1969         ||  mainwin->toolbar->getall_combo == NULL) /* button doesn't exist */
1970                 return;
1971
1972         menu = mainwin->toolbar->getall_combo->menu;
1973
1974         /* destroy all previous menu item */
1975         cur_item = GTK_MENU_SHELL(menu)->children;
1976         while (cur_item != NULL) {
1977                 GList *next = cur_item->next;
1978                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1979                 cur_item = next;
1980         }
1981
1982         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
1983                 ac_prefs = (PrefsAccount *)cur_ac->data;
1984
1985                 menuitem = gtk_menu_item_new_with_label
1986                         (ac_prefs->account_name
1987                          ? ac_prefs->account_name : _("Untitled"));
1988                 gtk_widget_show(menuitem);
1989                 gtk_menu_append(GTK_MENU(menu), menuitem);
1990                 g_signal_connect(G_OBJECT(menuitem), "activate",
1991                                  G_CALLBACK(account_receive_menu_cb),
1992                                  ac_prefs);
1993         }
1994 }
1995
1996 static void main_window_set_toolbar_combo_compose_menu(MainWindow *mainwin,
1997                                                        GList *account_list)
1998 {
1999         GList *cur_ac, *cur_item;
2000         GtkWidget *menuitem;
2001         PrefsAccount *ac_prefs;
2002         GtkWidget *menu = NULL;
2003
2004         if (mainwin->toolbar->compose_mail_btn == NULL
2005         ||  mainwin->toolbar->compose_combo == NULL) /* button doesn't exist */
2006                 return;
2007
2008         menu = mainwin->toolbar->compose_combo->menu;
2009
2010         /* destroy all previous menu item */
2011         cur_item = GTK_MENU_SHELL(menu)->children;
2012         while (cur_item != NULL) {
2013                 GList *next = cur_item->next;
2014                 gtk_widget_destroy(GTK_WIDGET(cur_item->data));
2015                 cur_item = next;
2016         }
2017
2018         for (cur_ac = account_list; cur_ac != NULL; cur_ac = cur_ac->next) {
2019                 ac_prefs = (PrefsAccount *)cur_ac->data;
2020
2021                 menuitem = gtk_menu_item_new_with_label
2022                         (ac_prefs->account_name
2023                          ? ac_prefs->account_name : _("Untitled"));
2024                 gtk_widget_show(menuitem);
2025                 gtk_menu_append(GTK_MENU(menu), menuitem);
2026                 g_signal_connect(G_OBJECT(menuitem), "activate",
2027                                  G_CALLBACK(account_compose_menu_cb),
2028                                  ac_prefs);
2029         }
2030 }
2031
2032 void main_window_set_account_menu(GList *account_list)
2033 {
2034         GList *cur;
2035         MainWindow *mainwin;
2036
2037         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2038                 mainwin = (MainWindow *)cur->data;
2039                 main_window_set_account_selector_menu(mainwin, account_list);
2040                 main_window_set_account_receive_menu(mainwin, account_list);
2041                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2042                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2043         }
2044         hooks_invoke(ACCOUNT_LIST_CHANGED_HOOKLIST, NULL);
2045 }
2046
2047 void main_window_set_account_menu_only_toolbar(GList *account_list)
2048 {
2049         GList *cur;
2050         MainWindow *mainwin;
2051
2052         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
2053                 mainwin = (MainWindow *)cur->data;
2054                 main_window_set_toolbar_combo_receive_menu(mainwin, account_list);
2055                 main_window_set_toolbar_combo_compose_menu(mainwin, account_list);
2056         }
2057 }
2058
2059 static void main_window_show_cur_account(MainWindow *mainwin)
2060 {
2061         gchar *buf;
2062         gchar *ac_name;
2063
2064         ac_name = g_strdup(cur_account
2065                            ? (cur_account->account_name
2066                               ? cur_account->account_name : _("Untitled"))
2067                            : _("none"));
2068
2069         if (cur_account)
2070                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
2071         else
2072                 buf = g_strdup(PROG_VERSION);
2073         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
2074         g_free(buf);
2075
2076         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
2077         gtk_widget_queue_resize(mainwin->ac_button);
2078
2079         g_free(ac_name);
2080 }
2081
2082 static void main_window_separation_change(MainWindow *mainwin, LayoutType layout_mode)
2083 {
2084         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
2085         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
2086         GtkWidget *message_wid = mainwin->messageview->vbox;
2087
2088         if (layout_mode == prefs_common.layout_mode) 
2089                 return;
2090
2091         debug_print("Changing window separation type from %d to %d\n",
2092                     prefs_common.layout_mode, layout_mode);
2093
2094         /* remove widgets from those containers */
2095         gtk_widget_ref(folder_wid);
2096         gtk_widget_ref(summary_wid);
2097         gtk_widget_ref(message_wid);
2098         gtkut_container_remove
2099                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
2100         gtkut_container_remove
2101                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
2102         gtkut_container_remove
2103                 (GTK_CONTAINER(message_wid->parent), message_wid);
2104
2105         gtk_widget_hide(mainwin->window);
2106         main_window_set_widgets(mainwin, layout_mode);
2107         gtk_widget_show(mainwin->window);
2108
2109         gtk_widget_unref(folder_wid);
2110         gtk_widget_unref(summary_wid);
2111         gtk_widget_unref(message_wid);
2112 }
2113
2114 void mainwindow_reset_paned(GtkPaned *paned)
2115 {
2116                 gint min, max, mid;
2117
2118                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2119                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2120                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2121                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2122
2123 GTK_EVENTS_FLUSH();
2124                 g_object_get (G_OBJECT(paned),
2125                                 "min-position",
2126                                 &min, NULL);
2127                 g_object_get (G_OBJECT(paned),
2128                                 "max-position",
2129                                 &max, NULL);
2130                 mid = (min+max)/2;
2131                 gtk_paned_set_position(GTK_PANED(paned), mid);
2132 }
2133
2134 static void mainwin_paned_show_first(GtkPaned *paned)
2135 {
2136                 gint max;
2137                 g_object_get (G_OBJECT(paned),
2138                                 "max-position",
2139                                 &max, NULL);
2140
2141                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2142                         gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned)));
2143                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2144                         gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned)));
2145                 gtk_paned_set_position(GTK_PANED(paned), max);
2146 }
2147
2148 static void mainwin_paned_show_last(GtkPaned *paned)
2149 {
2150                 gint min;
2151                 g_object_get (G_OBJECT(paned),
2152                                 "min-position",
2153                                 &min, NULL);
2154
2155                 if (gtk_paned_get_child1(GTK_PANED(paned)))
2156                         gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned)));
2157                 if (gtk_paned_get_child2(GTK_PANED(paned)))
2158                         gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned)));
2159                 gtk_paned_set_position(GTK_PANED(paned), min);
2160 }
2161
2162 void main_window_toggle_message_view(MainWindow *mainwin)
2163 {
2164         SummaryView *summaryview = mainwin->summaryview;
2165         GtkWidget *ppaned = NULL;
2166         GtkWidget *container = NULL;
2167         
2168         switch (prefs_common.layout_mode) {
2169         case NORMAL_LAYOUT:
2170         case VERTICAL_LAYOUT:
2171         case SMALL_LAYOUT:
2172                 ppaned = mainwin->vpaned;
2173                 container = mainwin->hpaned;
2174                 if (ppaned->parent != NULL) {
2175                         mainwin->messageview->visible = FALSE;
2176                         summaryview->displayed = NULL;
2177                         gtk_widget_ref(ppaned);
2178                         gtkut_container_remove(GTK_CONTAINER(container), ppaned);
2179                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
2180                 } else {
2181                         mainwin->messageview->visible = TRUE;
2182                         gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), ppaned);
2183                         gtk_container_add(GTK_CONTAINER(container), ppaned);
2184                         gtk_widget_unref(ppaned);
2185                 }
2186                 break;
2187         case WIDE_LAYOUT:
2188                 ppaned = mainwin->hpaned;
2189                 container = mainwin->vpaned;
2190                 if (mainwin->messageview->vbox->parent != NULL) {
2191                         mainwin->messageview->visible = FALSE;
2192                         summaryview->displayed = NULL;
2193                         gtk_widget_ref(mainwin->messageview->vbox);
2194                         gtkut_container_remove(GTK_CONTAINER(container), mainwin->messageview->vbox);
2195                 } else {
2196                         mainwin->messageview->visible = TRUE;
2197                         gtk_container_add(GTK_CONTAINER(container), mainwin->messageview->vbox);
2198                         gtk_widget_unref(mainwin->messageview->vbox);
2199                 }
2200                 break;
2201         case WIDE_MSGLIST_LAYOUT:
2202                 g_warning("can't hide messageview in this wide msglist layout");
2203                 break;
2204         }
2205
2206         if (messageview_is_visible(mainwin->messageview))
2207                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2208                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2209         else
2210                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2211                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2212
2213         if (mainwin->messageview->visible == FALSE)
2214                 messageview_clear(mainwin->messageview);
2215
2216         main_window_set_menu_sensitive(mainwin);
2217
2218         prefs_common.msgview_visible = mainwin->messageview->visible;
2219
2220         if (messageview_is_visible(mainwin->messageview)) {
2221                 gtk_widget_queue_resize(mainwin->hpaned);
2222                 gtk_widget_queue_resize(mainwin->vpaned);
2223         }
2224         summary_grab_focus(summaryview);
2225 }
2226
2227 void main_window_get_size(MainWindow *mainwin)
2228 {
2229         GtkAllocation *allocation;
2230
2231         if (mainwin_list == NULL || mainwin->messageview == NULL) {
2232                 debug_print("called after messageview "
2233                             "has been deallocated!\n");
2234                 return;
2235         }
2236
2237         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
2238
2239         if (allocation->width > 1 && allocation->height > 1) {
2240                 prefs_common.summaryview_width = allocation->width;
2241
2242                 if (messageview_is_visible(mainwin->messageview))
2243                         prefs_common.summaryview_height = allocation->height;
2244
2245                 prefs_common.mainview_width = allocation->width;
2246         }
2247
2248         allocation = &mainwin->window->allocation;
2249         if (allocation->width > 1 && allocation->height > 1) {
2250                 prefs_common.mainview_height = allocation->height;
2251                 prefs_common.mainwin_width   = allocation->width;
2252                 prefs_common.mainwin_height  = allocation->height;
2253         }
2254
2255         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
2256         if (allocation->width > 1 && allocation->height > 1) {
2257                 prefs_common.folderview_width  = allocation->width;
2258                 prefs_common.folderview_height = allocation->height;
2259         }
2260
2261         allocation = &(GTK_WIDGET_PTR(mainwin->messageview)->allocation);
2262         if (allocation->width > 1 && allocation->height > 1) {
2263                 prefs_common.msgview_width = allocation->width;
2264                 prefs_common.msgview_height = allocation->height;
2265         }
2266
2267 /*      debug_print("summaryview size: %d x %d\n",
2268                     prefs_common.summaryview_width,
2269                     prefs_common.summaryview_height);
2270         debug_print("folderview size: %d x %d\n",
2271                     prefs_common.folderview_width,
2272                     prefs_common.folderview_height);
2273         debug_print("messageview size: %d x %d\n",
2274                     prefs_common.msgview_width,
2275                     prefs_common.msgview_height); */
2276 }
2277
2278 void main_window_get_position(MainWindow *mainwin)
2279 {
2280         gint x, y;
2281
2282         gtkut_widget_get_uposition(mainwin->window, &x, &y);
2283
2284         prefs_common.mainview_x = x;
2285         prefs_common.mainview_y = y;
2286         prefs_common.mainwin_x = x;
2287         prefs_common.mainwin_y = y;
2288
2289         debug_print("main window position: %d, %d\n", x, y);
2290 }
2291
2292 void main_window_progress_on(MainWindow *mainwin)
2293 {
2294         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2295 }
2296
2297 void main_window_progress_off(MainWindow *mainwin)
2298 {
2299         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
2300         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), "");
2301 }
2302
2303 void main_window_progress_set(MainWindow *mainwin, gint cur, gint total)
2304 {
2305         gchar buf[32];
2306
2307         g_snprintf(buf, sizeof(buf), "%d / %d", cur, total);
2308         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(mainwin->progressbar), buf);
2309         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(mainwin->progressbar),
2310                                 (total == 0) ? 0 : (gfloat)cur / (gfloat)total);
2311 }
2312
2313 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
2314 {
2315         if (confirm && procmsg_have_trashed_mails_fast()) {
2316                 if (alertpanel(_("Empty trash"),
2317                                _("Delete all messages in trash folders?"),
2318                                GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL)
2319                     != G_ALERTALTERNATE)
2320                         return;
2321                 manage_window_focus_in(mainwin->window, NULL, NULL);
2322         }
2323
2324         procmsg_empty_all_trash();
2325
2326         if (mainwin->summaryview->folder_item &&
2327             mainwin->summaryview->folder_item->stype == F_TRASH)
2328                 gtk_widget_grab_focus(mainwin->folderview->ctree);
2329 }
2330
2331 void main_window_add_mailbox(MainWindow *mainwin)
2332 {
2333         gchar *path;
2334         Folder *folder;
2335
2336         path = input_dialog(_("Add mailbox"),
2337                             _("Input the location of mailbox.\n"
2338                               "If an existing mailbox is specified, it will be\n"
2339                               "scanned automatically."),
2340                             "Mail");
2341         if (!path) return;
2342         if (folder_find_from_path(path)) {
2343                 alertpanel_error(_("The mailbox '%s' already exists."), path);
2344                 g_free(path);
2345                 return;
2346         }
2347         folder = folder_new(folder_get_class_from_string("mh"), 
2348                             !strcmp(path, "Mail") ? _("Mailbox") : 
2349                             g_path_get_basename(path), path);
2350         g_free(path);
2351
2352         if (folder->klass->create_tree(folder) < 0) {
2353                 alertpanel_error(_("Creation of the mailbox failed.\n"
2354                                    "Maybe some files already exist, or you don't have the permission to write there."));
2355                 folder_destroy(folder);
2356                 return;
2357         }
2358
2359         folder_add(folder);
2360         folder_set_ui_func(folder, scan_tree_func, mainwin);
2361         folder_scan_tree(folder, TRUE);
2362         folder_set_ui_func(folder, NULL, NULL);
2363 }
2364
2365 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
2366 {
2367         SensitiveCond state = 0;
2368         SummarySelection selection;
2369         FolderItem *item = mainwin->summaryview->folder_item;
2370         GList *account_list = account_get_list();
2371         GSList *tmp;
2372         
2373         selection = summary_get_selection_type(mainwin->summaryview);
2374
2375         if (mainwin->lock_count == 0)
2376                 state |= M_UNLOCKED;
2377         if (selection != SUMMARY_NONE)
2378                 state |= M_MSG_EXIST;
2379         if (item && item->path && folder_item_parent(item) && !item->no_select) {
2380                 state |= M_EXEC;
2381                 /*              if (item->folder->type != F_NEWS) */
2382                 state |= M_ALLOW_DELETE;
2383
2384                 if (prefs_common.immediate_exec == 0
2385                     && mainwin->lock_count == 0)
2386                         state |= M_DELAY_EXEC;
2387
2388                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
2389                     || selection != SUMMARY_NONE)
2390                         state |= M_HIDE_READ_MSG;
2391         }               
2392         if (mainwin->summaryview->threaded)
2393                 state |= M_THREADED;
2394         else
2395                 state |= M_UNTHREADED;  
2396         if (selection == SUMMARY_SELECTED_SINGLE ||
2397             selection == SUMMARY_SELECTED_MULTIPLE)
2398                 state |= M_TARGET_EXIST;
2399         if (selection == SUMMARY_SELECTED_SINGLE)
2400                 state |= M_SINGLE_TARGET_EXIST;
2401         if (mainwin->summaryview->folder_item &&
2402             mainwin->summaryview->folder_item->folder->klass->type == F_NEWS)
2403                 state |= M_NEWS;
2404         else
2405                 state |= M_NOT_NEWS;
2406         if (prefs_common.actions_list && g_slist_length(prefs_common.actions_list))
2407                 state |= M_ACTIONS_EXIST;
2408
2409         tmp = tags_get_list();
2410         if (tmp && g_slist_length(tmp))
2411                 state |= M_TAGS_EXIST;
2412         g_slist_free(tmp);
2413
2414         if (procmsg_have_queued_mails_fast() && !procmsg_is_sending())
2415                 state |= M_HAVE_QUEUED_MAILS;
2416
2417         if (selection == SUMMARY_SELECTED_SINGLE &&
2418             (item &&
2419              (folder_has_parent_of_type(item, F_DRAFT) ||
2420               folder_has_parent_of_type(item, F_OUTBOX) ||
2421               folder_has_parent_of_type(item, F_QUEUE))))
2422                 state |= M_ALLOW_REEDIT;
2423         if (cur_account)
2424                 state |= M_HAVE_ACCOUNT;
2425         
2426         if (any_folder_want_synchronise())
2427                 state |= M_WANT_SYNC;
2428
2429         for ( ; account_list != NULL; account_list = account_list->next) {
2430                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
2431                         state |= M_HAVE_NEWS_ACCOUNT;
2432                         break;
2433                 }
2434         }
2435         
2436         if (procmsg_spam_can_learn() &&
2437             (mainwin->summaryview->folder_item &&
2438              mainwin->summaryview->folder_item->folder->klass->type != F_UNKNOWN &&
2439              mainwin->summaryview->folder_item->folder->klass->type != F_NEWS)) {
2440                 state |= M_CAN_LEARN_SPAM;
2441         }
2442
2443         if (inc_is_active())
2444                 state |= M_INC_ACTIVE;
2445         if (imap_cancel_all_enabled())
2446                 state |= M_INC_ACTIVE;
2447
2448         if (mainwin->summaryview->deleted > 0 ||
2449             mainwin->summaryview->moved > 0 ||
2450             mainwin->summaryview->copied > 0)
2451                 state |= M_DELAY_EXEC;
2452
2453         return state;
2454 }
2455
2456
2457
2458 void main_window_set_menu_sensitive(MainWindow *mainwin)
2459 {
2460         GtkItemFactory *ifactory = mainwin->menu_factory;
2461         SensitiveCond state;
2462         gboolean sensitive;
2463         GtkWidget *menu;
2464         GtkWidget *menuitem;
2465         SummaryView *summaryview;
2466         gchar *menu_path;
2467         gint i;
2468         GList *cur_item;
2469
2470         static const struct {
2471                 gchar *const entry;
2472                 SensitiveCond cond;
2473         } entry[] = {
2474                 {"/File/Save as...", M_TARGET_EXIST},
2475                 {"/File/Print..."  , M_TARGET_EXIST},
2476                 {"/File/Synchronise folders", M_WANT_SYNC},
2477                 {"/File/Exit"      , M_UNLOCKED},
2478
2479                 {"/Edit/Select thread"             , M_TARGET_EXIST},
2480                 {"/Edit/Delete thread"             , M_TARGET_EXIST},
2481                 {"/Edit/Find in current message...", M_SINGLE_TARGET_EXIST},
2482
2483                 {"/View/Set displayed columns/in Folder list..."
2484                                                    , M_UNLOCKED}, 
2485                 {"/View/Sort"                      , M_EXEC},
2486                 {"/View/Thread view"               , M_EXEC},
2487                 {"/View/Expand all threads"        , M_MSG_EXIST},
2488                 {"/View/Collapse all threads"      , M_MSG_EXIST},
2489                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
2490                 {"/View/Go to/Previous message"        , M_MSG_EXIST},
2491                 {"/View/Go to/Next message"        , M_MSG_EXIST},
2492                 {"/View/Go to/Previous unread message" , M_MSG_EXIST},
2493                 {"/View/Go to/Previous new message"    , M_MSG_EXIST},
2494                 {"/View/Go to/Previous marked message" , M_MSG_EXIST},
2495                 {"/View/Go to/Previous labeled message", M_MSG_EXIST},
2496                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
2497                 {"/View/Go to/Last read message"   , M_SINGLE_TARGET_EXIST},
2498                 {"/View/Go to/Parent message"      , M_SINGLE_TARGET_EXIST},
2499                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
2500                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
2501                 {"/View/All headers"               , M_SINGLE_TARGET_EXIST},
2502                 {"/View/Quotes"                    , M_SINGLE_TARGET_EXIST},
2503
2504                 {"/Message/Receive/Get from current account"
2505                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2506                 {"/Message/Receive/Get from all accounts"
2507                                                  , M_HAVE_ACCOUNT|M_UNLOCKED},
2508                 {"/Message/Receive/Cancel receiving"
2509                                                  , M_INC_ACTIVE},
2510                 {"/Message/Send queued messages"  , M_HAVE_ACCOUNT|M_HAVE_QUEUED_MAILS},
2511                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
2512                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2513                 {"/Message/Reply to"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2514                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_TARGET_EXIST|M_NEWS},
2515                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2516                 {"/Message/Forward as attachment" , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2517                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_TARGET_EXIST},
2518                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE},
2519                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC},
2520                 {"/Message/Move to trash"         , M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS},
2521                 {"/Message/Delete..."             , M_TARGET_EXIST|M_ALLOW_DELETE},
2522                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_NEWS},
2523                 {"/Message/Mark"                  , M_TARGET_EXIST},
2524                 {"/Message/Mark/Mark as spam"     , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2525                 {"/Message/Mark/Mark as ham"      , M_TARGET_EXIST|M_CAN_LEARN_SPAM},
2526                 {"/Message/Mark/Ignore thread"    , M_TARGET_EXIST},
2527                 {"/Message/Mark/Unignore thread"  , M_TARGET_EXIST},
2528                 {"/Message/Mark/Lock"             , M_TARGET_EXIST},
2529                 {"/Message/Mark/Unlock"           , M_TARGET_EXIST},
2530                 {"/Message/Color label"           , M_TARGET_EXIST},
2531                 {"/Message/Tags"                  , M_TARGET_EXIST},
2532                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
2533
2534                 {"/Tools/Add sender to address book"   , M_SINGLE_TARGET_EXIST},
2535                 {"/Tools/Harvest addresses"            , M_MSG_EXIST},
2536                 {"/Tools/Harvest addresses/from Messages..."
2537                                                        , M_TARGET_EXIST},
2538                 {"/Tools/Filter all messages in folder", M_MSG_EXIST|M_EXEC},
2539                 {"/Tools/Filter selected messages"     , M_TARGET_EXIST|M_EXEC},
2540                 {"/Tools/Create filter rule"           , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2541                 {"/Tools/Create processing rule"       , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
2542                 {"/Tools/List URLs..."                 , M_TARGET_EXIST},
2543                 {"/Tools/Actions"                      , M_TARGET_EXIST|M_ACTIONS_EXIST},
2544                 {"/Tools/Execute"                      , M_DELAY_EXEC},
2545                 {"/Tools/Delete duplicated messages/In selected folder"   , M_MSG_EXIST|M_ALLOW_DELETE},
2546
2547                 {"/Configuration", M_UNLOCKED},
2548                 {"/Configuration/Preferences for current account...", M_UNLOCKED},
2549                 {"/Configuration/Create new account...", M_UNLOCKED},
2550                 {"/Configuration/Edit accounts...", M_UNLOCKED},
2551
2552                 {NULL, 0}
2553         };
2554
2555         state = main_window_get_current_state(mainwin);
2556
2557         for (i = 0; entry[i].entry != NULL; i++) {
2558                 sensitive = ((entry[i].cond & state) == entry[i].cond);
2559                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
2560         }
2561
2562         menu = gtk_item_factory_get_widget(ifactory, "/Message/Receive");
2563
2564         /* search for separator */
2565         for (cur_item = GTK_MENU_SHELL(menu)->children; cur_item != NULL;
2566              cur_item = cur_item->next) {
2567                 if (GTK_BIN(cur_item->data)->child == NULL) {
2568                         cur_item = cur_item->next;
2569                         break;
2570                 }
2571         }
2572
2573         for (; cur_item != NULL; cur_item = cur_item->next) {
2574                 gtk_widget_set_sensitive(GTK_WIDGET(cur_item->data),
2575                                          (M_UNLOCKED & state) != 0);
2576         }
2577
2578         main_window_menu_callback_block(mainwin);
2579
2580 #define SET_CHECK_MENU_ACTIVE(path, active) \
2581 { \
2582         menuitem = gtk_item_factory_get_widget(ifactory, path); \
2583         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
2584 }
2585
2586         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
2587                               messageview_is_visible(mainwin->messageview));
2588
2589         summaryview = mainwin->summaryview;
2590         menu_path = "/View/Sort/Don't sort";
2591
2592         switch (summaryview->sort_key) {
2593         case SORT_BY_NUMBER:
2594                 menu_path = "/View/Sort/by number"; break;
2595         case SORT_BY_SIZE:
2596                 menu_path = "/View/Sort/by Size"; break;
2597         case SORT_BY_DATE:
2598                 menu_path = "/View/Sort/by Date"; break;
2599         case SORT_BY_THREAD_DATE:
2600                 menu_path = "/View/Sort/by Thread date"; break;
2601         case SORT_BY_FROM:
2602                 menu_path = "/View/Sort/by From"; break;
2603         case SORT_BY_TO:
2604                 menu_path = "/View/Sort/by To"; break;
2605         case SORT_BY_SUBJECT:
2606                 menu_path = "/View/Sort/by Subject"; break;
2607         case SORT_BY_LABEL:
2608                 menu_path = "/View/Sort/by color label"; break;
2609         case SORT_BY_MARK:
2610                 menu_path = "/View/Sort/by mark"; break;
2611         case SORT_BY_STATUS:
2612                 menu_path = "/View/Sort/by status"; break;
2613         case SORT_BY_MIME:
2614                 menu_path = "/View/Sort/by attachment"; break;
2615         case SORT_BY_SCORE:
2616                 menu_path = "/View/Sort/by score"; break;
2617         case SORT_BY_LOCKED:
2618                 menu_path = "/View/Sort/by locked"; break;
2619         case SORT_BY_TAGS:
2620                 menu_path = "/View/Sort/by tag"; break;
2621         case SORT_BY_NONE:
2622         default:
2623                 menu_path = "/View/Sort/Don't sort"; break;
2624         }
2625         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
2626
2627         if (summaryview->sort_type == SORT_ASCENDING) {
2628                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
2629         } else {
2630                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
2631         }
2632
2633         if (summaryview->sort_key != SORT_BY_NONE) {
2634                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
2635                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
2636         } else {
2637                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
2638                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
2639         }
2640
2641         if (mainwin->messageview 
2642         &&  mainwin->messageview->mimeview
2643         &&  mainwin->messageview->mimeview->textview)
2644                 SET_CHECK_MENU_ACTIVE("/View/All headers",
2645                               mainwin->messageview->mimeview->textview->show_all_headers);
2646         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
2647         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
2648         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
2649         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
2650         if (prefs_common.hide_quotes == 1)
2651                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", TRUE);
2652         if (prefs_common.hide_quotes == 2)
2653                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", TRUE);
2654         if (prefs_common.hide_quotes == 3)
2655                 SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", TRUE);
2656
2657 #undef SET_CHECK_MENU_ACTIVE
2658
2659         main_window_menu_callback_unblock(mainwin);
2660 }
2661
2662 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2663 {
2664         GtkItemFactory *ifactory;
2665         gint is_menu = 0;
2666         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2667         
2668         if (msginfo) 
2669                 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2670         if (is_menu)
2671                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2672                                 (ifactory,"/Message/Mailing-List"), TRUE);
2673         else
2674                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2675                                 (ifactory,"/Message/Mailing-List"), FALSE);
2676 }
2677
2678 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2679 {
2680         gint menu_nb = 0;
2681         GtkWidget *menuitem;
2682         
2683         if (!msginfo || !msginfo->extradata) {
2684                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Post", FALSE);
2685                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Help", FALSE);
2686                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Subscribe", FALSE);
2687                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Unsubscribe", FALSE);
2688                 menu_set_sensitive(ifactory, "/Message/Mailing-List/View archive", FALSE);
2689                 menu_set_sensitive(ifactory, "/Message/Mailing-List/Contact owner", FALSE);
2690                 return 0;
2691         }
2692                 
2693         /* Mailing list post */
2694         if (!strcmp2 (msginfo->extradata->list_post, "NO")) {
2695                 g_free(msginfo->extradata->list_post);
2696                 msginfo->extradata->list_post = g_strdup (_("No posting allowed"));
2697         }
2698         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2699                 
2700         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_post);
2701  
2702         /* Mailing list help */
2703         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2704         
2705         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_help);
2706
2707         /* Mailing list subscribe */
2708         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2709         
2710         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_subscribe);
2711                 
2712         /* Mailing list unsubscribe */
2713         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2714         
2715         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_unsubscribe);
2716         
2717         /* Mailing list view archive */
2718         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2719         
2720         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_archive);
2721         
2722         /* Mailing list contact owner */
2723         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2724         
2725         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->extradata->list_owner);
2726         
2727         return menu_nb;
2728 }
2729
2730 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2731 {
2732         GtkWidget *item, *menu;
2733         const gchar *url_pt ;
2734         gchar url_decoded[BUFFSIZE];
2735         GList *amenu, *alist;
2736         gint menu_nb = 0;
2737         
2738         menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2739         
2740         /* First delete old submenu */
2741         /* FIXME: we can optimize this, and only change/add/delete necessary items */
2742         for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2743                 alist = amenu->next;
2744                 item = GTK_WIDGET (amenu->data);
2745                 gtk_widget_destroy (item);
2746                 amenu = alist;
2747         }
2748         if (list_header) {
2749                 for (url_pt = list_header; url_pt && *url_pt;) {
2750                         get_url_part (&url_pt, url_decoded, BUFFSIZE);
2751                         item = NULL;
2752                         if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2753                                 item = gtk_menu_item_new_with_label ((url_decoded));
2754                                 g_signal_connect(G_OBJECT(item), "activate",
2755                                                  G_CALLBACK(mailing_list_compose),
2756                                                  NULL);
2757                         }
2758                         else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2759                                  !g_strncasecmp (url_decoded, "https:",6)) {
2760
2761                                 item = gtk_menu_item_new_with_label ((url_decoded));
2762                                 g_signal_connect(G_OBJECT(item), "activate",
2763                                                  G_CALLBACK(mailing_list_open_uri),
2764                                                  NULL);
2765                         } 
2766                         if (item) {
2767                                 gtk_menu_append (GTK_MENU(menu), item);
2768                                 gtk_widget_show (item);
2769                                 menu_nb++;
2770                         }
2771                 }
2772         }
2773         if (menu_nb)
2774                 gtk_widget_set_sensitive (menuitem, TRUE);
2775         else
2776                 gtk_widget_set_sensitive (menuitem, FALSE);
2777                 
2778
2779         return menu_nb;
2780 }
2781
2782 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2783 {
2784         gchar tmp[BUFFSIZE];
2785         const gchar *buf;
2786         gint i = 0;
2787         buf = *buffer;
2788         gboolean with_plus = TRUE;
2789
2790         if (buf == 0x00) {
2791                 *url_decoded = '\0';
2792                 *buffer = NULL;
2793                 return;
2794         }
2795         /* Ignore spaces, comments  and tabs () */
2796         for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2797                 if (*buf == '(')
2798                         for (;*buf != ')' && *buf != 0x00; buf++);
2799         
2800         /* First non space and non comment must be a < */
2801         if (*buf =='<' ) {
2802                 buf++;
2803                 if (!strncmp(buf, "mailto:", strlen("mailto:")))
2804                         with_plus = FALSE;
2805                 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2806                 buf++;
2807         }
2808         else  {
2809                 *buffer = NULL;
2810                 *url_decoded = '\0';
2811                 return;
2812         }
2813         
2814         tmp[i]       = 0x00;
2815         *url_decoded = '\0';
2816         *buffer = NULL;
2817         
2818         if (i == maxlen) {
2819                 return;
2820         }
2821         decode_uri_with_plus (url_decoded, (const gchar *)tmp, with_plus);
2822
2823         /* Prepare the work for the next url in the list */
2824         /* after the closing bracket >, ignore space, comments and tabs */
2825         for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2826                 if (*buf == '(')
2827                         for (;*buf != ')' && *buf != 0x00; buf++);
2828                         
2829         if (!buf || !*buf) {
2830                 *buffer = NULL;
2831                 return;
2832         }
2833
2834         /* now first non space, non comment must be a comma */
2835         if (*buf != ',')
2836                 for (;*buf != 0x00; buf++);
2837         else
2838                 buf++;
2839         *buffer = buf;
2840 }
2841         
2842 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2843 {
2844         gchar *mailto;
2845
2846         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2847         compose_new(NULL, mailto+7, NULL);
2848 }
2849  
2850  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2851 {
2852  
2853         gchar *mailto;
2854  
2855         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2856         open_uri (mailto, prefs_common.uri_cmd);
2857
2858         
2859 void main_window_popup(MainWindow *mainwin)
2860 {
2861         if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(mainwin->window)))
2862                 main_window_show(mainwin);
2863
2864         gtkut_window_popup(mainwin->window);
2865         if (prefs_common.layout_mode == SMALL_LAYOUT) {
2866                 if (mainwin->in_folder) {
2867                         mainwindow_enter_folder(mainwin);
2868                 } else {
2869                         mainwindow_exit_folder(mainwin);
2870                 }
2871         }
2872 }
2873
2874 void main_window_show(MainWindow *mainwin)
2875 {
2876         gtk_widget_show(mainwin->window);
2877         gtk_widget_show(mainwin->vbox_body);
2878
2879         gtk_widget_set_uposition(mainwin->window,
2880                                  prefs_common.mainwin_x,
2881                                  prefs_common.mainwin_y);
2882
2883         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2884                              prefs_common.folderview_width,
2885                              prefs_common.folderview_height);
2886         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2887                              prefs_common.summaryview_width,
2888                              prefs_common.summaryview_height);
2889         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2890                              prefs_common.msgview_width,
2891                              prefs_common.msgview_height);
2892 }
2893
2894 void main_window_hide(MainWindow *mainwin)
2895 {
2896         main_window_get_size(mainwin);
2897         main_window_get_position(mainwin);
2898
2899         gtk_widget_hide(mainwin->window);
2900         gtk_widget_hide(mainwin->vbox_body);
2901 }
2902
2903 static void main_window_set_widgets(MainWindow *mainwin, LayoutType layout_mode)
2904 {
2905         GtkWidget *folderwin = NULL;
2906         GtkWidget *messagewin = NULL;
2907         GtkWidget *hpaned;
2908         GtkWidget *vpaned;
2909         GtkWidget *vbox_body = mainwin->vbox_body;
2910         GtkItemFactory *ifactory = mainwin->menu_factory;
2911         GtkWidget *menuitem;
2912         gboolean first_set = (mainwin->hpaned == NULL);
2913         debug_print("Setting widgets... ");
2914
2915         if (layout_mode == SMALL_LAYOUT && first_set) {
2916                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2917                                     prefs_common.folderview_width,
2918                                     prefs_common.folderview_height);
2919                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2920                                     0,0);
2921                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2922                                     0,0);
2923         } else {
2924                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2925                                     prefs_common.folderview_width,
2926                                     prefs_common.folderview_height);
2927                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2928                                     prefs_common.summaryview_width,
2929                                     prefs_common.summaryview_height);
2930                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2931                                     prefs_common.msgview_width,
2932                                     prefs_common.msgview_height);
2933         }
2934
2935         mainwin->messageview->statusbar = mainwin->statusbar;
2936         mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2937
2938         /* clean top-most container */
2939         if (mainwin->hpaned) {
2940                 if (mainwin->hpaned->parent == mainwin->vpaned)
2941                         gtk_widget_destroy(mainwin->vpaned);
2942                 else
2943                         gtk_widget_destroy(mainwin->hpaned);
2944         }
2945
2946         menu_set_sensitive(ifactory, "/View/Show or hide/Message view", 
2947                 (layout_mode != WIDE_MSGLIST_LAYOUT && layout_mode != SMALL_LAYOUT));
2948         switch (layout_mode) {
2949         case VERTICAL_LAYOUT:
2950         case NORMAL_LAYOUT:
2951         case SMALL_LAYOUT:
2952                 hpaned = gtk_hpaned_new();
2953                 if (layout_mode == VERTICAL_LAYOUT)
2954                         vpaned = gtk_hpaned_new();
2955                 else
2956                         vpaned = gtk_vpaned_new();
2957                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2958                 gtk_paned_add1(GTK_PANED(hpaned),
2959                                GTK_WIDGET_PTR(mainwin->folderview));
2960                 gtk_widget_show(hpaned);
2961                 gtk_widget_queue_resize(hpaned);
2962
2963                 if (messageview_is_visible(mainwin->messageview)) {
2964                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
2965                         gtk_paned_add1(GTK_PANED(vpaned),
2966                                        GTK_WIDGET_PTR(mainwin->summaryview));
2967                 } else {
2968                         gtk_paned_add2(GTK_PANED(hpaned),
2969                                        GTK_WIDGET_PTR(mainwin->summaryview));
2970                         gtk_widget_ref(vpaned);
2971                 }
2972                 gtk_paned_add2(GTK_PANED(vpaned),
2973                                GTK_WIDGET_PTR(mainwin->messageview));
2974                 gtk_widget_show(vpaned);
2975                 if (layout_mode == SMALL_LAYOUT && first_set) {
2976                         mainwin_paned_show_first(GTK_PANED(hpaned));
2977                 }
2978                 gtk_widget_queue_resize(vpaned);
2979                 break;
2980         case WIDE_LAYOUT:
2981                 vpaned = gtk_vpaned_new();
2982                 hpaned = gtk_hpaned_new();
2983                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
2984                 gtk_paned_add1(GTK_PANED(vpaned), hpaned);
2985
2986                 gtk_paned_add1(GTK_PANED(hpaned),
2987                                GTK_WIDGET_PTR(mainwin->folderview));
2988                 gtk_paned_add2(GTK_PANED(hpaned),
2989                                GTK_WIDGET_PTR(mainwin->summaryview));
2990
2991                 gtk_widget_show(hpaned);
2992                 gtk_widget_queue_resize(hpaned);
2993
2994                 if (messageview_is_visible(mainwin->messageview)) {
2995                         gtk_paned_add2(GTK_PANED(vpaned),
2996                                GTK_WIDGET_PTR(mainwin->messageview));   
2997                 } else {
2998                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
2999                 }
3000                 gtk_widget_show(vpaned);
3001                 gtk_widget_queue_resize(vpaned);
3002                 break;
3003         case WIDE_MSGLIST_LAYOUT:
3004                 vpaned = gtk_vpaned_new();
3005                 hpaned = gtk_hpaned_new();
3006                 gtk_box_pack_start(GTK_BOX(vbox_body), vpaned, TRUE, TRUE, 0);
3007
3008                 gtk_paned_add1(GTK_PANED(vpaned),
3009                                GTK_WIDGET_PTR(mainwin->summaryview));
3010                 gtk_paned_add1(GTK_PANED(hpaned),
3011                                GTK_WIDGET_PTR(mainwin->folderview));
3012
3013                 gtk_widget_show(hpaned);
3014                 gtk_widget_queue_resize(hpaned);
3015
3016                 if (messageview_is_visible(mainwin->messageview)) {
3017                         gtk_paned_add2(GTK_PANED(hpaned),
3018                                GTK_WIDGET_PTR(mainwin->messageview));   
3019                 } else {
3020                         gtk_widget_ref(GTK_WIDGET_PTR(mainwin->messageview));
3021                 }
3022                 gtk_paned_add2(GTK_PANED(vpaned), hpaned);
3023
3024                 gtk_widget_show(vpaned);
3025                 gtk_widget_queue_resize(vpaned);
3026                 break;
3027         default:
3028                 g_warning("Unknown layout");
3029                 return;
3030         }
3031
3032         mainwin->hpaned = hpaned;
3033         mainwin->vpaned = vpaned;
3034
3035         if (layout_mode == SMALL_LAYOUT) {
3036                 if (mainwin->messageview->visible)
3037                         main_window_toggle_message_view(mainwin);
3038         } 
3039
3040         if (layout_mode == SMALL_LAYOUT && first_set) {
3041                 gtk_widget_realize(mainwin->window);
3042                 gtk_widget_realize(mainwin->folderview->ctree);
3043                 gtk_widget_realize(mainwin->summaryview->hbox);
3044                 gtk_widget_realize(mainwin->summaryview->hbox_l);
3045                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
3046                                     prefs_common.folderview_width,
3047                                     prefs_common.folderview_height);
3048                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
3049                                     0,0);
3050                 gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
3051                                     0,0);
3052                 gtk_widget_set_size_request(GTK_WIDGET(mainwin->window),
3053                                 prefs_common.mainwin_width,
3054                                 prefs_common.mainwin_height);
3055                 gtk_paned_set_position(GTK_PANED(mainwin->hpaned), 800);
3056         } 
3057         /* remove headerview if not in prefs */
3058         headerview_set_visibility(mainwin->messageview->headerview,
3059                                   prefs_common.display_header_pane);
3060
3061         if (messageview_is_visible(mainwin->messageview))
3062                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3063                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
3064         else
3065                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
3066                               GTK_ARROW_UP, GTK_SHADOW_OUT);
3067
3068         gtk_window_move(GTK_WINDOW(mainwin->window),
3069                         prefs_common.mainwin_x,
3070                         prefs_common.mainwin_y);
3071
3072         gtk_widget_queue_resize(vbox_body);
3073         gtk_widget_queue_resize(mainwin->vbox);
3074         gtk_widget_queue_resize(mainwin->window);
3075         /* CLAWS: previous "gtk_widget_show_all" makes noticeview
3076          * and mimeview icon list/ctree lose track of their visibility states */
3077         if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
3078                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
3079         if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview)) 
3080                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
3081         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
3082                 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
3083         else 
3084                 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
3085
3086         prefs_common.layout_mode = layout_mode;
3087
3088         menuitem = gtk_item_factory_get_item
3089                 (ifactory, "/View/Show or hide/Message view");
3090         gtk_check_menu_item_set_active
3091                 (GTK_CHECK_MENU_ITEM(menuitem),
3092                  messageview_is_visible(mainwin->messageview));
3093
3094 #define SET_CHECK_MENU_ACTIVE(path, active) \
3095 { \
3096         menuitem = gtk_item_factory_get_widget(ifactory, path); \
3097         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3098 }
3099
3100         switch (prefs_common.layout_mode) {
3101         case NORMAL_LAYOUT:
3102                 SET_CHECK_MENU_ACTIVE("/View/Layout/Standard", TRUE);
3103                 break;
3104         case VERTICAL_LAYOUT:
3105                 SET_CHECK_MENU_ACTIVE("/View/Layout/Three columns", TRUE);
3106                 break;
3107         case WIDE_LAYOUT:
3108                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message", TRUE);
3109                 break;
3110         case WIDE_MSGLIST_LAYOUT:
3111                 SET_CHECK_MENU_ACTIVE("/View/Layout/Wide message list", TRUE);
3112                 break;
3113         case SMALL_LAYOUT:
3114                 SET_CHECK_MENU_ACTIVE("/View/Layout/Small screen", TRUE);
3115                 break;
3116         }
3117 #undef SET_CHECK_MENU_ACTIVE
3118
3119         if (folderwin) {
3120                 g_signal_connect
3121                         (G_OBJECT(folderwin), "size_allocate",
3122                          G_CALLBACK(folder_window_size_allocate_cb),
3123                          mainwin);
3124         }
3125         if (messagewin) {
3126                 g_signal_connect
3127                         (G_OBJECT(messagewin), "size_allocate",
3128                          G_CALLBACK(message_window_size_allocate_cb),
3129                          mainwin);
3130         }
3131
3132         debug_print("done.\n");
3133 }
3134
3135 void main_window_destroy_all(void)
3136 {
3137         while (mainwin_list != NULL) {
3138                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
3139                 
3140                 /* free toolbar stuff */
3141                 toolbar_clear_list(TOOLBAR_MAIN);
3142                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
3143                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
3144
3145                 mainwin->folderview->mainwin = NULL;
3146                 mainwin->summaryview->mainwin = NULL;
3147                 mainwin->messageview->mainwin = NULL;
3148
3149                 g_free(mainwin->toolbar);
3150                 g_free(mainwin);
3151                 
3152                 mainwin_list = g_list_remove(mainwin_list, mainwin);
3153         }
3154         g_list_free(mainwin_list);
3155         mainwin_list = NULL;
3156 }
3157
3158 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
3159                                    gpointer data)
3160 {
3161         gtk_widget_set_size_request(child, 1, -1);
3162 }
3163
3164 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
3165                                    gpointer data)
3166 {
3167         gtk_widget_set_size_request(child, -1, -1);
3168 }
3169
3170 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
3171                                     gpointer data)
3172 {
3173         MainWindow *mainwin = (MainWindow *)data;
3174
3175         if (!event) return FALSE;
3176
3177         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
3178         g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
3179                           widget);
3180
3181         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
3182                        menu_button_position, widget,
3183                        event->button, event->time);
3184
3185         return TRUE;
3186 }
3187
3188 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
3189                                  gpointer data)
3190 {
3191         MainWindow *mainwin = (MainWindow *)data;
3192         gboolean close_allowed = TRUE;
3193
3194         hooks_invoke(MAIN_WINDOW_CLOSE, &close_allowed);
3195
3196         if (close_allowed && mainwin->lock_count == 0)
3197                 app_exit_cb(data, 0, widget);
3198
3199         return TRUE;
3200 }
3201
3202 static void main_window_size_allocate_cb(GtkWidget *widget,
3203                                          GtkAllocation *allocation,
3204                                          gpointer data)
3205 {
3206         MainWindow *mainwin = (MainWindow *)data;
3207         main_window_get_size(mainwin);
3208 }
3209
3210 static void folder_window_size_allocate_cb(GtkWidget *widget,
3211                                            GtkAllocation *allocation,
3212                                            gpointer data)
3213 {
3214         MainWindow *mainwin = (MainWindow *)data;
3215
3216         main_window_get_size(mainwin);
3217 }
3218
3219 static void message_window_size_allocate_cb(GtkWidget *widget,
3220                                             GtkAllocation *allocation,
3221                                             gpointer data)
3222 {
3223         MainWindow *mainwin = (MainWindow *)data;
3224
3225         main_window_get_size(mainwin);
3226 }
3227
3228 static void add_mailbox_cb(MainWindow *mainwin, guint action,
3229                            GtkWidget *widget)
3230 {
3231         main_window_add_mailbox(mainwin);
3232 }
3233
3234 static void update_folderview_cb(MainWindow *mainwin, guint action,
3235                                  GtkWidget *widget)
3236 {
3237         summary_show(mainwin->summaryview, NULL);
3238         folderview_check_new_all();
3239 }
3240
3241 static void foldersort_cb(MainWindow *mainwin, guint action,
3242                            GtkWidget *widget)
3243 {
3244         foldersort_open();
3245 }
3246
3247 static void import_mbox_cb(MainWindow *mainwin, guint action,
3248                            GtkWidget *widget)
3249 {
3250         /* only notify if import has failed */
3251         if (import_mbox(mainwin->summaryview->folder_item) == -1) {
3252                 alertpanel_error(_("Mbox import has failed."));
3253         }
3254 }
3255
3256 static void export_mbox_cb(MainWindow *mainwin, guint action,
3257                            GtkWidget *widget)
3258 {
3259         /* only notify if export has failed */
3260         if (export_mbox(mainwin->summaryview->folder_item) == -1) {
3261                 alertpanel_error(_("Export to mbox has failed."));
3262         }
3263 }
3264
3265 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
3266                                 GtkWidget *widget)
3267 {
3268         /* only notify if export has failed */
3269         if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
3270                 alertpanel_error(_("Export to mbox has failed."));
3271         }
3272 }
3273
3274 static void empty_trash_cb(MainWindow *mainwin, guint action,
3275                            GtkWidget *widget)
3276 {
3277         main_window_empty_trash(mainwin, TRUE);
3278 }
3279
3280 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3281 {
3282         summary_save_as(mainwin->summaryview);
3283 }
3284
3285 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3286 {
3287         summary_print(mainwin->summaryview);
3288 }
3289
3290 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3291 {
3292         if (prefs_common.confirm_on_exit) {
3293                 if (alertpanel(_("Exit"), _("Exit Claws Mail?"),
3294                                GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
3295                     != G_ALERTALTERNATE)
3296                         return;
3297                 manage_window_focus_in(mainwin->window, NULL, NULL);
3298         }
3299
3300         app_will_exit(widget, mainwin);
3301 }
3302
3303 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3304 {
3305         if (action == 1)
3306                 summary_search(mainwin->summaryview);
3307         else
3308                 message_search(mainwin->messageview);
3309 }
3310
3311 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3312 {
3313         summaryview_activate_quicksearch(mainwin->summaryview, TRUE);
3314 }
3315
3316 static void toggle_message_cb(MainWindow *mainwin, guint action,
3317                               GtkWidget *widget)
3318 {
3319         gboolean active;
3320
3321         active = GTK_CHECK_MENU_ITEM(widget)->active;
3322
3323         if (active != messageview_is_visible(mainwin->messageview))
3324                 summary_toggle_view(mainwin->summaryview);
3325 }
3326
3327 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3328                               GtkWidget *widget)
3329 {
3330         toolbar_toggle(action, mainwin);
3331 }
3332
3333 static void main_window_reply_cb(MainWindow *mainwin, guint action,
3334                           GtkWidget *widget)
3335 {
3336         MessageView *msgview = (MessageView*)mainwin->messageview;
3337         GSList *msginfo_list = NULL;
3338
3339         g_return_if_fail(msgview != NULL);
3340
3341         msginfo_list = summary_get_selection(mainwin->summaryview);
3342         g_return_if_fail(msginfo_list != NULL);
3343         compose_reply_from_messageview(msgview, msginfo_list, action);
3344         g_slist_free(msginfo_list);
3345 }
3346
3347
3348 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3349                                 GtkWidget *widget)
3350 {
3351         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3352                 gtk_widget_show(mainwin->hbox_stat);
3353                 prefs_common.show_statusbar = TRUE;
3354         } else {
3355                 gtk_widget_hide(mainwin->hbox_stat);
3356                 prefs_common.show_statusbar = FALSE;
3357         }
3358 }
3359
3360 static void set_layout_cb(MainWindow *mainwin, guint action,
3361                                GtkWidget *widget)
3362 {
3363         LayoutType layout_mode = action;
3364         LayoutType old_layout_mode = prefs_common.layout_mode;
3365         if (mainwin->menu_lock_count) {
3366                 return;
3367         }
3368         if (!GTK_CHECK_MENU_ITEM(widget)->active) {
3369                 return;
3370         }
3371         
3372         if (layout_mode == prefs_common.layout_mode) {
3373                 return;
3374         }
3375         
3376         if (!mainwin->messageview->visible && layout_mode != SMALL_LAYOUT)
3377                 main_window_toggle_message_view(mainwin);
3378         else if (mainwin->messageview->visible && layout_mode == SMALL_LAYOUT)
3379                 main_window_toggle_message_view(mainwin);
3380
3381         main_window_separation_change(mainwin, layout_mode);
3382         mainwindow_reset_paned(GTK_PANED(mainwin->vpaned));
3383         if (old_layout_mode == SMALL_LAYOUT && layout_mode != SMALL_LAYOUT) {
3384                 mainwindow_reset_paned(GTK_PANED(mainwin->hpaned));
3385         }
3386         if (old_layout_mode != SMALL_LAYOUT && layout_mode == SMALL_LAYOUT) {
3387                 mainwin_paned_show_first(GTK_PANED(mainwin->hpaned));
3388                 mainwindow_exit_folder(mainwin);
3389         }
3390         summary_relayout(mainwin->summaryview); 
3391         summary_update_unread(mainwin->summaryview, NULL);
3392 }
3393
3394 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3395                                         gboolean ask_sync)
3396 {
3397         offline_ask_sync = ask_sync;
3398         if (offline)
3399                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3400         else
3401                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3402         offline_ask_sync = TRUE;
3403 }
3404
3405 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3406 {
3407         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3408 }
3409
3410 static gboolean any_folder_want_synchronise(void)
3411 {
3412         GList *folderlist = folder_get_list();
3413
3414         /* see if there are synchronised folders */
3415         for (; folderlist; folderlist = folderlist->next) {
3416                 Folder *folder = (Folder *)folderlist->data;
3417                 if (folder_want_synchronise(folder)) {
3418                         return TRUE;
3419                 }
3420         }
3421         
3422         return FALSE;
3423 }
3424
3425 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3426 {
3427         
3428         if (!any_folder_want_synchronise())
3429                 return;
3430
3431         if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3432                         _("Do you want to synchronise your folders now?"),
3433                         GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3434                 return;
3435         
3436         if (offline_ask_sync)
3437                 folder_synchronise(NULL);
3438 }
3439
3440 static void online_switch_clicked (GtkButton *btn, gpointer data) 
3441 {
3442         MainWindow *mainwin;
3443         GtkItemFactory *ifactory;
3444         GtkCheckMenuItem *menuitem;
3445
3446         mainwin = (MainWindow *) data;
3447         
3448         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3449         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3450         
3451         g_return_if_fail(mainwin != NULL);
3452         g_return_if_fail(menuitem != NULL);
3453         
3454         if (btn == GTK_BUTTON(mainwin->online_switch)) {
3455                 gtk_widget_hide (mainwin->online_switch);
3456                 gtk_widget_show (mainwin->offline_switch);
3457                 menuitem->active = TRUE;
3458                 inc_autocheck_timer_remove();
3459                         
3460                 /* go offline */
3461                 if (prefs_common.work_offline)
3462                         return;
3463                 mainwindow_check_synchronise(mainwin, TRUE);
3464                 prefs_common.work_offline = TRUE;
3465                 imap_disconnect_all();
3466                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3467         } else {
3468                 /*go online */
3469                 if (!prefs_common.work_offline)
3470                         return;
3471                 gtk_widget_hide (mainwin->offline_switch);
3472                 gtk_widget_show (mainwin->online_switch);
3473                 menuitem->active = FALSE;
3474                 prefs_common.work_offline = FALSE;
3475                 inc_autocheck_timer_set();
3476                 refresh_resolvers();
3477                 hooks_invoke(OFFLINE_SWITCH_HOOKLIST, NULL);
3478         }
3479 }
3480
3481 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3482                                 GtkWidget *widget)
3483 {
3484         addressbook_open(NULL);
3485 }
3486
3487 static void log_window_show_cb(MainWindow *mainwin, guint action,
3488                                GtkWidget *widget)
3489 {
3490         log_window_show(mainwin->logwin);
3491 }
3492
3493 static void filtering_debug_window_show_cb(MainWindow *mainwin, guint action,
3494                                GtkWidget *widget)
3495 {
3496         log_window_show(mainwin->filtering_debugwin);
3497 }
3498
3499 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3500 {
3501         inc_cancel_all();
3502         imap_cancel_all();
3503 }
3504
3505 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3506 {
3507         summary_move_to(mainwin->summaryview);
3508 }
3509
3510 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3511 {
3512         summary_copy_to(mainwin->summaryview);
3513 }
3514
3515 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3516 {
3517         summary_delete(mainwin->summaryview);
3518 }
3519
3520 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3521 {
3522         summary_delete_trash(mainwin->summaryview);
3523 }
3524
3525 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3526 {
3527         summary_cancel(mainwin->summaryview);
3528 }
3529
3530 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3531 {
3532         summary_open_msg(mainwin->summaryview);
3533 }
3534
3535 static void view_source_cb(MainWindow *mainwin, guint action,
3536                            GtkWidget *widget)
3537 {
3538         summary_view_source(mainwin->summaryview);
3539 }
3540
3541 static void show_all_header_cb(MainWindow *mainwin, guint action,
3542                                GtkWidget *widget)
3543 {
3544         if (mainwin->menu_lock_count) return;
3545         mainwin->summaryview->messageview->all_headers = 
3546                         GTK_CHECK_MENU_ITEM(widget)->active;
3547         summary_display_msg_selected(mainwin->summaryview,
3548                                      GTK_CHECK_MENU_ITEM(widget)->active);
3549 }
3550
3551 #define SET_CHECK_MENU_ACTIVE(path, active) \
3552 { \
3553         menuitem = gtk_item_factory_get_widget(ifactory, path); \
3554         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
3555 }
3556
3557 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3558                                GtkWidget *widget)
3559 {
3560         GtkWidget *menuitem;
3561         GtkItemFactory *ifactory = mainwin->menu_factory;
3562
3563         if (mainwin->menu_lock_count) return;
3564
3565         prefs_common.hide_quotes = 
3566                         GTK_CHECK_MENU_ITEM(widget)->active ? action : 0;
3567
3568         mainwin->menu_lock_count++;
3569         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold all", FALSE);
3570         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 2", FALSE);
3571         SET_CHECK_MENU_ACTIVE("/View/Quotes/Fold from level 3", FALSE);
3572         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), prefs_common.hide_quotes > 0);
3573         mainwin->menu_lock_count--;
3574
3575         summary_redisplay_msg(mainwin->summaryview);
3576 }
3577
3578 #undef SET_CHECK_MENU_ACTIVE
3579 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3580 {
3581         summary_mark(mainwin->summaryview);
3582 }
3583
3584 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3585 {
3586         summary_unmark(mainwin->summaryview);
3587 }
3588
3589 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3590                               GtkWidget *widget)
3591 {
3592         summary_mark_as_unread(mainwin->summaryview);
3593 }
3594
3595 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3596                             GtkWidget *widget)
3597 {
3598         summary_mark_as_read(mainwin->summaryview);
3599 }
3600
3601 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3602                              GtkWidget *widget)
3603 {
3604         summary_mark_all_read(mainwin->summaryview);
3605 }
3606
3607 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3608                              GtkWidget *widget)
3609 {
3610         summary_mark_as_spam(mainwin->summaryview, action, NULL);
3611 }
3612
3613 static void ignore_thread_cb(MainWindow *mainwin, guint action,
3614                             GtkWidget *widget)
3615 {
3616         summary_ignore_thread(mainwin->summaryview);
3617 }
3618
3619 static void unignore_thread_cb(MainWindow *mainwin, guint action,
3620                             GtkWidget *widget)
3621 {
3622         summary_unignore_thread(mainwin->summaryview);
3623 }
3624
3625 static void lock_msgs_cb(MainWindow *mainwin, guint action,
3626                             GtkWidget *widget)
3627 {
3628         summary_msgs_lock(mainwin->summaryview);
3629 }
3630
3631 static void unlock_msgs_cb(MainWindow *mainwin, guint action,
3632                             GtkWidget *widget)
3633 {
3634         summary_msgs_unlock(mainwin->summaryview);
3635 }
3636
3637
3638 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3639 {
3640         summary_reedit(mainwin->summaryview);
3641 }
3642
3643 static void open_urls_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3644 {
3645         if (!mainwin->summaryview->displayed && mainwin->summaryview->selected) {
3646                 summary_display_msg_selected(mainwin->summaryview, 
3647                         mainwin->messageview->mimeview->textview->show_all_headers);
3648         }
3649         messageview_list_urls(mainwin->messageview);
3650 }
3651
3652 static void add_address_cb(MainWindow *mainwin, guint action,
3653                            GtkWidget *widget)
3654 {
3655         summary_add_address(mainwin->summaryview);
3656 }
3657
3658 static void set_charset_cb(MainWindow *mainwin, guint action,
3659                            GtkWidget *widget)
3660 {
3661         const gchar *str;
3662
3663         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3664                 str = conv_get_charset_str((CharSet)action);
3665                 
3666                 g_free(mainwin->messageview->forced_charset);
3667                 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3668                 procmime_force_charset(str);
3669                 
3670                 summary_redisplay_msg(mainwin->summaryview);
3671                 
3672                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3673         }
3674 }
3675
3676 static void set_decode_cb(MainWindow *mainwin, guint action,
3677                            GtkWidget *widget)
3678 {
3679         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3680                 mainwin->messageview->forced_encoding = (EncodingType)action;
3681                 
3682                 summary_redisplay_msg(mainwin->summaryview);
3683                 
3684                 debug_print("forced encoding: %d\n", action);
3685         }
3686 }
3687
3688 static void hide_read_messages (MainWindow *mainwin, guint action,
3689                                 GtkWidget *widget)
3690 {
3691         if (!mainwin->summaryview->folder_item
3692             || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3693                 return;
3694         summary_toggle_show_read_messages(mainwin->summaryview);
3695 }
3696
3697 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3698 {
3699         gboolean threaded = FALSE;
3700         if (mainwin->menu_lock_count) return;
3701         if (!mainwin->summaryview->folder_item) return;
3702
3703         threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3704
3705         mainwin->summaryview->folder_item->threaded = threaded; 
3706
3707         mainwin->summaryview->threaded = threaded;
3708
3709         summary_show(mainwin->summaryview, 
3710                         mainwin->summaryview->folder_item);
3711 }
3712
3713 static void expand_threads_cb(MainWindow *mainwin, guint action,
3714                               GtkWidget *widget)
3715 {
3716         summary_expand_threads(mainwin->summaryview);
3717 }
3718
3719 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3720                                 GtkWidget *widget)
3721 {
3722         summary_collapse_threads(mainwin->summaryview);
3723 }
3724
3725 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3726                                 GtkWidget *widget)
3727 {
3728         prefs_summary_column_open();
3729 }
3730
3731 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3732                                 GtkWidget *widget)
3733 {
3734         prefs_folder_column_open();
3735 }
3736
3737 static void sort_summary_cb(MainWindow *mainwin, guint action,
3738                             GtkWidget *widget)
3739 {
3740         FolderItem *item = mainwin->summaryview->folder_item;
3741         GtkWidget *menuitem;
3742
3743         if (mainwin->menu_lock_count) return;
3744
3745         if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3746                 menuitem = gtk_item_factory_get_item
3747                         (mainwin->menu_factory, "/View/Sort/Ascending");
3748                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3749                              GTK_CHECK_MENU_ITEM(menuitem)->active
3750                              ? SORT_ASCENDING : SORT_DESCENDING);
3751                 item->sort_key = action;
3752         }
3753 }
3754
3755 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3756                                  GtkWidget *widget)
3757 {
3758         FolderItem *item = mainwin->summaryview->folder_item;
3759
3760         if (mainwin->menu_lock_count) return;
3761
3762         if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3763                 summary_sort(mainwin->summaryview,
3764                              item->sort_key, (FolderSortType)action);
3765 }
3766
3767 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3768                                   GtkWidget *widget)
3769 {
3770         summary_attract_by_subject(mainwin->summaryview);
3771 }
3772
3773 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3774                                  GtkWidget *widget)
3775 {
3776         FolderItem *item;
3777
3778         item = folderview_get_selected_item(mainwin->folderview);
3779         if (item) {
3780                 main_window_cursor_wait(mainwin);
3781                 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3782
3783                 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3784                                               DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3785
3786                 STATUSBAR_POP(mainwin);
3787                 main_window_cursor_normal(mainwin);
3788         }
3789 }
3790
3791 struct DelDupsData
3792 {
3793         guint   dups;
3794         guint   folders;
3795 };
3796
3797 static void deldup_all(FolderItem *item, gpointer _data)
3798 {
3799         struct DelDupsData *data = _data;
3800         gint result;
3801         
3802         result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3803         if (result >= 0) {
3804               &nbs