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