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