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