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