fc23b73b1c8d9abb4f29477dace9ed9433803ccc
[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         SET_CHECK_MENU_ACTIVE("/View/Hide quotes", prefs_common.hide_quotes);
2278
2279 #undef SET_CHECK_MENU_ACTIVE
2280
2281         main_window_menu_callback_unblock(mainwin);
2282 }
2283
2284 void main_create_mailing_list_menu (MainWindow *mainwin, MsgInfo *msginfo)
2285 {
2286         GtkItemFactory *ifactory;
2287         gint is_menu = 0;
2288         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2289         
2290         if (msginfo) 
2291                 is_menu = mailing_list_create_submenu (ifactory, msginfo);
2292         if (is_menu)
2293                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2294                                 (ifactory,"/Message/Mailing-List"), TRUE);
2295         else
2296                 gtk_widget_set_sensitive (gtk_item_factory_get_item
2297                                 (ifactory,"/Message/Mailing-List"), FALSE);
2298 }
2299
2300 static gint mailing_list_create_submenu (GtkItemFactory *ifactory, MsgInfo *msginfo)
2301 {
2302         gint menu_nb = 0;
2303         GtkWidget *menuitem;
2304
2305         /* Mailing list post */
2306         if (msginfo && !strcmp2 (msginfo->list_post, "NO")) {
2307                 msginfo->list_post = g_strdup (_("No posting allowed"));
2308         }
2309         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Post");
2310                 
2311         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_post);
2312  
2313         /* Mailing list help */
2314         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Help");
2315         
2316         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_help);
2317
2318         /* Mailing list subscribe */
2319         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Subscribe");
2320         
2321         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_subscribe);
2322                 
2323         /* Mailing list unsubscribe */
2324         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Unsubscribe");
2325         
2326         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_unsubscribe);
2327         
2328         /* Mailing list view archive */
2329         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/View archive");
2330         
2331         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_archive);
2332         
2333         /* Mailing list contact owner */
2334         menuitem = gtk_item_factory_get_item (ifactory, "/Message/Mailing-List/Contact owner");
2335         
2336         menu_nb += mailing_list_populate_submenu (menuitem, msginfo->list_owner);
2337         
2338         return menu_nb;
2339 }
2340
2341 static gint mailing_list_populate_submenu (GtkWidget *menuitem, const gchar * list_header)
2342 {
2343         GtkWidget *item, *menu;
2344         const gchar *url_pt ;
2345         gchar url_decoded[BUFFSIZE];
2346         GList *amenu, *alist;
2347         gint menu_nb = 0;
2348         
2349         menu = GTK_WIDGET(GTK_MENU_ITEM(menuitem)->submenu);
2350         
2351         /* First delete old submenu */
2352         /* FIXME: we can optimize this, and only change/add/delete necessary items */
2353         for (amenu = (GTK_MENU_SHELL(menu)->children) ; amenu; ) {
2354                 alist = amenu->next;
2355                 item = GTK_WIDGET (amenu->data);
2356                 gtk_widget_destroy (item);
2357                 amenu = alist;
2358         }
2359         if (list_header) {
2360                 for (url_pt = list_header; url_pt && *url_pt;) {
2361                         get_url_part (&url_pt, url_decoded, BUFFSIZE);
2362                         item = NULL;
2363                         if (!g_strncasecmp(url_decoded, "mailto:", 7)) {
2364                                 item = gtk_menu_item_new_with_label ((url_decoded));
2365                                 gtk_signal_connect (GTK_OBJECT(item), "activate",
2366                                                 GTK_SIGNAL_FUNC(mailing_list_compose), NULL);
2367                         }
2368                         else if (!g_strncasecmp (url_decoded, "http:", 5) ||
2369                                  !g_strncasecmp (url_decoded, "https:",6)) {
2370
2371                                 item = gtk_menu_item_new_with_label ((url_decoded));
2372                                 gtk_signal_connect (GTK_OBJECT(item), "activate",
2373                                                 GTK_SIGNAL_FUNC(mailing_list_open_uri), NULL);
2374                         } 
2375                         if (item) {
2376                                 gtk_menu_append (GTK_MENU(menu), item);
2377                                 gtk_widget_show (item);
2378                                 menu_nb++;
2379                         }
2380                 }
2381         }
2382         if (menu_nb)
2383                 gtk_widget_set_sensitive (menuitem, TRUE);
2384         else
2385                 gtk_widget_set_sensitive (menuitem, FALSE);
2386                 
2387
2388         return menu_nb;
2389 }
2390
2391 static void get_url_part (const gchar **buffer, gchar *url_decoded, gint maxlen)
2392 {
2393         gchar tmp[BUFFSIZE];
2394         const gchar *buf;
2395         gint i = 0;
2396         buf = *buffer;
2397         
2398         if (buf == 0x00) {
2399                 *url_decoded = '\0';
2400                 *buffer = NULL;
2401                 return;
2402         }
2403         /* Ignore spaces, comments  and tabs () */
2404         for (;*buf == ' ' || *buf == '(' || *buf == '\t'; buf++)
2405                 if (*buf == '(')
2406                         for (;*buf != ')' && *buf != 0x00; buf++);
2407         
2408         /* First non space and non comment must be a < */
2409         if (*buf =='<' ) {
2410                 buf++;
2411                 for (i = 0; *buf != '>' && *buf != 0x00 && i<maxlen; tmp[i++] = *(buf++));
2412                 buf++;
2413         }
2414         else  {
2415                 *buffer = NULL;
2416                 *url_decoded = '\0';
2417                 return;
2418         }
2419         
2420         tmp[i]       = 0x00;
2421         *url_decoded = '\0';
2422         *buffer = NULL;
2423         
2424         if (i == maxlen) {
2425                 return;
2426         }
2427         decode_uri (url_decoded, (const gchar *)tmp);
2428
2429         /* Prepare the work for the next url in the list */
2430         /* after the closing bracket >, ignore space, comments and tabs */
2431         for (;buf && *buf && (*buf == ' ' || *buf == '(' || *buf == '\t'); buf++)
2432                 if (*buf == '(')
2433                         for (;*buf != ')' && *buf != 0x00; buf++);
2434                         
2435         if (!buf || !*buf) {
2436                 *buffer = NULL;
2437                 return;
2438         }
2439
2440         /* now first non space, non comment must be a comma */
2441         if (*buf != ',')
2442                 for (;*buf != 0x00; buf++);
2443         else
2444                 buf++;
2445         *buffer = buf;
2446 }
2447         
2448 static void mailing_list_compose (GtkWidget *w, gpointer *data)
2449 {
2450         gchar *mailto;
2451
2452         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2453         compose_new(NULL, mailto+7, NULL);
2454 }
2455  
2456  static void mailing_list_open_uri (GtkWidget *w, gpointer *data)
2457 {
2458  
2459         gchar *mailto;
2460  
2461         gtk_label_get (GTK_LABEL (GTK_BIN (w)->child), (gchar **) &mailto);
2462         open_uri (mailto, prefs_common.uri_cmd);
2463
2464         
2465 void main_window_popup(MainWindow *mainwin)
2466 {
2467         gtkut_window_popup(mainwin->window);
2468
2469         switch (mainwin->type) {
2470         case SEPARATE_FOLDER:
2471                 gtkut_window_popup(mainwin->win.sep_folder.folderwin);
2472                 break;
2473         case SEPARATE_MESSAGE:
2474                 gtkut_window_popup(mainwin->win.sep_message.messagewin);
2475                 break;
2476         case SEPARATE_BOTH:
2477                 gtkut_window_popup(mainwin->win.sep_both.folderwin);
2478                 gtkut_window_popup(mainwin->win.sep_both.messagewin);
2479                 break;
2480         default:
2481                 break;
2482         }
2483 }
2484
2485 void main_window_show(MainWindow *mainwin)
2486 {
2487         gtk_widget_show(mainwin->window);
2488         gtk_widget_show(mainwin->vbox_body);
2489
2490         gtk_widget_set_uposition(mainwin->window,
2491                                  prefs_common.mainwin_x,
2492                                  prefs_common.mainwin_y);
2493
2494         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2495                              prefs_common.folderview_width,
2496                              prefs_common.folderview_height);
2497         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2498                              prefs_common.summaryview_width,
2499                              prefs_common.summaryview_height);
2500         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2501                              prefs_common.msgview_width,
2502                              prefs_common.msgview_height);
2503
2504         if (mainwin->type & SEPARATE_FOLDER) {
2505                 GtkWidget *folderwin;
2506
2507                 folderwin = main_window_get_folder_window(mainwin);
2508                 gtk_widget_show(folderwin);
2509                 gtk_widget_set_uposition(folderwin, prefs_common.folderwin_x,
2510                                          prefs_common.folderwin_y);
2511         }
2512
2513         if (mainwin->type & SEPARATE_MESSAGE) {
2514                 GtkWidget *messagewin;
2515
2516                 messagewin = main_window_get_message_window(mainwin);
2517                 gtk_widget_show(messagewin);
2518                 gtk_widget_set_uposition(messagewin, prefs_common.main_msgwin_x,
2519                                          prefs_common.main_msgwin_y);
2520         }
2521 }
2522
2523 void main_window_hide(MainWindow *mainwin)
2524 {
2525         main_window_get_size(mainwin);
2526         main_window_get_position(mainwin);
2527
2528         gtk_widget_hide(mainwin->window);
2529         gtk_widget_hide(mainwin->vbox_body);
2530
2531         if (mainwin->type & SEPARATE_FOLDER) {
2532                 gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2533         }
2534
2535         if (mainwin->type & SEPARATE_MESSAGE) {
2536                 gtk_widget_hide(mainwin->win.sep_message.messagewin);
2537         }
2538 }
2539
2540 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
2541 {
2542         GtkWidget *folderwin = NULL;
2543         GtkWidget *messagewin = NULL;
2544         GtkWidget *hpaned;
2545         GtkWidget *vpaned;
2546         GtkWidget *vbox_body = mainwin->vbox_body;
2547         GtkItemFactory *ifactory = mainwin->menu_factory;
2548         GtkWidget *menuitem;
2549         GtkItemFactory *msgview_ifactory;
2550
2551         debug_print("Setting widgets... ");
2552
2553         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->folderview),
2554                                     prefs_common.folderview_width,
2555                                     prefs_common.folderview_height);
2556         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->summaryview),
2557                                     prefs_common.summaryview_width,
2558                                     prefs_common.summaryview_height);
2559         gtk_widget_set_size_request(GTK_WIDGET_PTR(mainwin->messageview),
2560                                     prefs_common.msgview_width,
2561                                     prefs_common.msgview_height);
2562
2563         /* create separated window(s) if needed */
2564         if (type & SEPARATE_FOLDER) {
2565                 static GdkGeometry folderwin_geometry;
2566                 
2567                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2568                 gtk_window_set_title(GTK_WINDOW(folderwin),
2569                                      _("Sylpheed-Claws - Folder View"));
2570
2571                 gtk_window_move(GTK_WINDOW(folderwin),
2572                                 prefs_common.folderwin_x,
2573                                 prefs_common.folderwin_y);
2574
2575                 if (!folderwin_geometry.min_height) {
2576                         folderwin_geometry.min_width = 320;
2577                         folderwin_geometry.min_height = 200;
2578                 }
2579                 gtk_window_set_geometry_hints(GTK_WINDOW(folderwin), NULL,
2580                                               &folderwin_geometry, GDK_HINT_MIN_SIZE);
2581                                 
2582                 gtk_widget_set_size_request(folderwin,
2583                                             prefs_common.folderview_width,
2584                                             prefs_common.folderview_height);
2585
2586                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
2587                                                BORDER_WIDTH);
2588
2589                 g_signal_connect(G_OBJECT(folderwin), "delete_event",
2590                                  G_CALLBACK(folder_window_close_cb),
2591                                    mainwin);
2592                 gtk_container_add(GTK_CONTAINER(folderwin),
2593                                   GTK_WIDGET_PTR(mainwin->folderview));
2594                 gtk_widget_realize(folderwin);
2595
2596                 if (prefs_common.folderview_visible)
2597                         gtk_widget_show(folderwin);
2598         }
2599
2600         if (type & SEPARATE_MESSAGE) {
2601                 static GdkGeometry msgwin_geometry;
2602                 
2603                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2604                 gtk_window_set_title(GTK_WINDOW(messagewin),
2605                                      _("Sylpheed-Claws - Message View"));
2606                                      
2607                 gtk_window_move(GTK_WINDOW(messagewin), 
2608                                 prefs_common.main_msgwin_x,
2609                                 prefs_common.main_msgwin_y);
2610
2611                 if (!msgwin_geometry.min_height) {
2612                         msgwin_geometry.min_width = 320;
2613                         msgwin_geometry.min_height = 200;
2614                 }
2615                 gtk_window_set_geometry_hints(GTK_WINDOW(messagewin), NULL,
2616                                               &msgwin_geometry, GDK_HINT_MIN_SIZE);
2617                 
2618                 gtk_widget_set_size_request(messagewin, 
2619                                             prefs_common.msgwin_width,
2620                                             prefs_common.msgwin_height);
2621
2622                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
2623                                                BORDER_WIDTH);
2624                 g_signal_connect(G_OBJECT(messagewin), "delete_event",
2625                                  G_CALLBACK(message_window_close_cb),
2626                                  mainwin);
2627                 if (messageview_is_visible(mainwin->messageview))
2628                         gtk_widget_show(messagewin);
2629         } else {
2630                 mainwin->messageview->statusbar = mainwin->statusbar;
2631                 mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2632         }
2633
2634         switch (type) {
2635         case SEPARATE_NONE:
2636                 hpaned = gtk_hpaned_new();
2637                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2638                 gtk_paned_add1(GTK_PANED(hpaned),
2639                                GTK_WIDGET_PTR(mainwin->folderview));
2640                 gtk_widget_show(hpaned);
2641                 gtk_widget_queue_resize(hpaned);
2642
2643                 vpaned = gtk_vpaned_new();
2644                 if (messageview_is_visible(mainwin->messageview)) {
2645                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
2646                         gtk_paned_add1(GTK_PANED(vpaned),
2647                                        GTK_WIDGET_PTR(mainwin->summaryview));
2648                 } else {
2649                         gtk_paned_add2(GTK_PANED(hpaned),
2650                                        GTK_WIDGET_PTR(mainwin->summaryview));
2651                         gtk_widget_ref(vpaned);
2652                 }
2653                 gtk_paned_add2(GTK_PANED(vpaned),
2654                                GTK_WIDGET_PTR(mainwin->messageview));
2655                 gtk_widget_show(vpaned);
2656                 gtk_widget_queue_resize(vpaned);
2657
2658                 mainwin->win.sep_none.hpaned = hpaned;
2659                 mainwin->win.sep_none.vpaned = vpaned;
2660                 
2661                 /* remove headerview if not in prefs */
2662                 headerview_set_visibility(mainwin->messageview->headerview,
2663                                           prefs_common.display_header_pane);
2664                 break;
2665         case SEPARATE_FOLDER:
2666                 vpaned = gtk_vpaned_new();
2667                 if (messageview_is_visible(mainwin->messageview)) {
2668                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
2669                                            TRUE, TRUE, 0);
2670                         gtk_paned_add1(GTK_PANED(vpaned),
2671                                        GTK_WIDGET_PTR(mainwin->summaryview));
2672                 } else {
2673                         gtk_box_pack_start(GTK_BOX(vbox_body),
2674                                            GTK_WIDGET_PTR(mainwin->summaryview),
2675                                            TRUE, TRUE, 0);
2676                         gtk_widget_ref(vpaned);
2677                 }
2678                 gtk_paned_add2(GTK_PANED(vpaned),
2679                                GTK_WIDGET_PTR(mainwin->messageview));
2680                 gtk_widget_show(vpaned);
2681                 gtk_widget_queue_resize(vpaned);
2682
2683                 mainwin->win.sep_folder.folderwin = folderwin;
2684                 mainwin->win.sep_folder.vpaned    = vpaned;
2685
2686                 /* remove headerview if not in prefs */
2687                 headerview_set_visibility(mainwin->messageview->headerview,
2688                                           prefs_common.display_header_pane);
2689                 
2690                 break;
2691         case SEPARATE_MESSAGE:
2692                 hpaned = gtk_hpaned_new();
2693                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
2694                 gtk_paned_add1(GTK_PANED(hpaned),
2695                                GTK_WIDGET_PTR(mainwin->folderview));
2696                 gtk_paned_add2(GTK_PANED(hpaned),
2697                                GTK_WIDGET_PTR(mainwin->summaryview));
2698                 gtk_widget_show(hpaned);
2699                 gtk_widget_queue_resize(hpaned);
2700                 messageview_add_toolbar(mainwin->messageview, messagewin);
2701                 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
2702                 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
2703
2704                 mainwin->win.sep_message.messagewin = messagewin;
2705                 mainwin->win.sep_message.hpaned     = hpaned;
2706
2707                 gtk_widget_realize(messagewin);
2708                 gtk_widget_show_all(GTK_WIDGET_PTR(mainwin->messageview));
2709                 gtk_widget_show_all(messagewin);
2710                 toolbar_set_style(mainwin->messageview->toolbar->toolbar, 
2711                                   mainwin->messageview->handlebox, 
2712                                   prefs_common.toolbar_style);
2713
2714                 /* remove headerview if not in prefs */
2715                 headerview_set_visibility(mainwin->messageview->headerview,
2716                                           prefs_common.display_header_pane);
2717
2718                 break;
2719         case SEPARATE_BOTH:
2720                 messageview_add_toolbar(mainwin->messageview, messagewin);
2721                 msgview_ifactory = gtk_item_factory_from_widget(mainwin->messageview->menubar);
2722                 menu_set_sensitive(msgview_ifactory, "/File/Close", FALSE);
2723
2724                 gtk_box_pack_start(GTK_BOX(vbox_body),
2725                                    GTK_WIDGET_PTR(mainwin->summaryview),
2726                                    TRUE, TRUE, 0);
2727                 
2728                 mainwin->win.sep_both.folderwin = folderwin;
2729                 mainwin->win.sep_both.messagewin = messagewin;
2730                 
2731                 gtk_widget_realize(messagewin);
2732                 gtk_widget_show_all(GTK_WIDGET_PTR(mainwin->messageview));
2733                 gtk_widget_show_all(messagewin);
2734                 toolbar_set_style(mainwin->messageview->toolbar->toolbar, 
2735                                   mainwin->messageview->handlebox, 
2736                                   prefs_common.toolbar_style);          
2737
2738                 /* remove headerview if not in prefs */
2739                 headerview_set_visibility(mainwin->messageview->headerview,
2740                                           prefs_common.display_header_pane);
2741
2742                 break;
2743         }
2744
2745         if (messageview_is_visible(mainwin->messageview))
2746                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2747                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
2748         else
2749                 gtk_arrow_set(GTK_ARROW(mainwin->summaryview->toggle_arrow),
2750                               GTK_ARROW_UP, GTK_SHADOW_OUT);
2751
2752         gtk_window_move(GTK_WINDOW(mainwin->window),
2753                         prefs_common.mainwin_x,
2754                         prefs_common.mainwin_y);
2755
2756         gtk_widget_queue_resize(vbox_body);
2757         gtk_widget_queue_resize(mainwin->vbox);
2758         gtk_widget_queue_resize(mainwin->window);
2759         /* CLAWS: previous "gtk_widget_show_all" makes noticeview
2760          * and mimeview icon list/ctree lose track of their visibility states */
2761         if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
2762                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
2763         if (!noticeview_is_visible(mainwin->messageview->mimeview->siginfoview)) 
2764                 gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->mimeview->siginfoview));
2765         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mainwin->messageview->mimeview->mime_toggle)))
2766                 gtk_widget_hide(mainwin->messageview->mimeview->icon_mainbox);
2767         else 
2768                 gtk_widget_hide(mainwin->messageview->mimeview->ctree_mainbox);
2769
2770         mainwin->type = type;
2771
2772
2773         /* toggle menu state */
2774         menuitem = gtk_item_factory_get_item
2775                 (ifactory, "/View/Show or hide/Folder tree");
2776         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2777                                        (type & SEPARATE_FOLDER) == 0 ? TRUE :
2778                                        prefs_common.folderview_visible);
2779         gtk_widget_set_sensitive(menuitem, ((type & SEPARATE_FOLDER) != 0));
2780         menuitem = gtk_item_factory_get_item
2781                 (ifactory, "/View/Show or hide/Message view");
2782         gtk_check_menu_item_set_active
2783                 (GTK_CHECK_MENU_ITEM(menuitem),
2784                  messageview_is_visible(mainwin->messageview));
2785
2786         menuitem = gtk_item_factory_get_item
2787                 (ifactory, "/View/Separate folder tree");
2788         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2789                                        ((type & SEPARATE_FOLDER) != 0));
2790         menuitem = gtk_item_factory_get_item
2791                 (ifactory, "/View/Separate message view");
2792         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2793                                        ((type & SEPARATE_MESSAGE) != 0));
2794
2795         if (folderwin) {
2796                 g_signal_connect
2797                         (G_OBJECT(folderwin), "size_allocate",
2798                          G_CALLBACK(folder_window_size_allocate_cb),
2799                          mainwin);
2800         }
2801         if (messagewin) {
2802                 g_signal_connect
2803                         (G_OBJECT(messagewin), "size_allocate",
2804                          G_CALLBACK(message_window_size_allocate_cb),
2805                          mainwin);
2806         }
2807
2808         debug_print("done.\n");
2809 }
2810
2811 void main_window_destroy_all(void)
2812 {
2813         while (mainwin_list != NULL) {
2814                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
2815                 
2816                 /* free toolbar stuff */
2817                 toolbar_clear_list(TOOLBAR_MAIN);
2818                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2819                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
2820
2821                 mainwin->folderview->mainwin = NULL;
2822                 mainwin->summaryview->mainwin = NULL;
2823                 mainwin->messageview->mainwin = NULL;
2824
2825                 g_free(mainwin->toolbar);
2826                 g_free(mainwin);
2827                 
2828                 mainwin_list = g_list_remove(mainwin_list, mainwin);
2829         }
2830         g_list_free(mainwin_list);
2831         mainwin_list = NULL;
2832 }
2833
2834 static void toolbar_child_attached(GtkWidget *widget, GtkWidget *child,
2835                                    gpointer data)
2836 {
2837         gtk_widget_set_size_request(child, 1, -1);
2838 }
2839
2840 static void toolbar_child_detached(GtkWidget *widget, GtkWidget *child,
2841                                    gpointer data)
2842 {
2843         gtk_widget_set_size_request(child, -1, -1);
2844 }
2845
2846 static gboolean ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2847                                     gpointer data)
2848 {
2849         MainWindow *mainwin = (MainWindow *)data;
2850
2851         if (!event) return FALSE;
2852
2853         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2854         g_object_set_data(G_OBJECT(mainwin->ac_menu), "menu_button",
2855                           widget);
2856
2857         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2858                        menu_button_position, widget,
2859                        event->button, event->time);
2860
2861         return TRUE;
2862 }
2863
2864 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2865                                  gpointer data)
2866 {
2867         MainWindow *mainwin = (MainWindow *)data;
2868
2869         if (mainwin->lock_count == 0)
2870                 app_exit_cb(data, 0, widget);
2871
2872         return TRUE;
2873 }
2874
2875 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2876                                    gpointer data)
2877 {
2878         MainWindow *mainwin = (MainWindow *)data;
2879         GtkWidget *menuitem;
2880
2881         menuitem = gtk_item_factory_get_item
2882                 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
2883         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2884
2885         return TRUE;
2886 }
2887
2888 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2889                                     gpointer data)
2890 {
2891         MainWindow *mainwin = (MainWindow *)data;
2892         GtkWidget *menuitem;
2893
2894         menuitem = gtk_item_factory_get_item
2895                 (mainwin->menu_factory, "/View/Show or hide/Message view");
2896         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2897
2898         mainwin->messageview->statusbar = mainwin->statusbar;
2899         mainwin->messageview->statusbar_cid = mainwin->messageview_cid;
2900
2901         return TRUE;
2902 }
2903
2904 static void main_window_size_allocate_cb(GtkWidget *widget,
2905                                          GtkAllocation *allocation,
2906                                          gpointer data)
2907 {
2908         MainWindow *mainwin = (MainWindow *)data;
2909
2910         main_window_get_size(mainwin);
2911 }
2912
2913 static void folder_window_size_allocate_cb(GtkWidget *widget,
2914                                            GtkAllocation *allocation,
2915                                            gpointer data)
2916 {
2917         MainWindow *mainwin = (MainWindow *)data;
2918
2919         main_window_get_size(mainwin);
2920 }
2921
2922 static void message_window_size_allocate_cb(GtkWidget *widget,
2923                                             GtkAllocation *allocation,
2924                                             gpointer data)
2925 {
2926         MainWindow *mainwin = (MainWindow *)data;
2927
2928         main_window_get_size(mainwin);
2929 }
2930
2931 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2932                            GtkWidget *widget)
2933 {
2934         main_window_add_mailbox(mainwin);
2935 }
2936
2937 static void update_folderview_cb(MainWindow *mainwin, guint action,
2938                                  GtkWidget *widget)
2939 {
2940         summary_show(mainwin->summaryview, NULL);
2941         folderview_check_new_all();
2942 }
2943
2944 static void foldersort_cb(MainWindow *mainwin, guint action,
2945                            GtkWidget *widget)
2946 {
2947         foldersort_open();
2948 }
2949
2950 static void import_mbox_cb(MainWindow *mainwin, guint action,
2951                            GtkWidget *widget)
2952 {
2953         /* only notify if import has failed */
2954         if (import_mbox(mainwin->summaryview->folder_item) == -1) {
2955                 alertpanel_error(_("Mbox import has failed."));
2956         }
2957 }
2958
2959 static void export_mbox_cb(MainWindow *mainwin, guint action,
2960                            GtkWidget *widget)
2961 {
2962         /* only notify if export has failed */
2963         if (export_mbox(mainwin->summaryview->folder_item) == -1) {
2964                 alertpanel_error(_("Export to mbox has failed."));
2965         }
2966 }
2967
2968 static void export_list_mbox_cb(MainWindow *mainwin, guint action,
2969                                 GtkWidget *widget)
2970 {
2971         /* only notify if export has failed */
2972         if (summaryview_export_mbox_list(mainwin->summaryview) == -1) {
2973                 alertpanel_error(_("Export to mbox has failed."));
2974         }
2975 }
2976
2977 static void empty_trash_cb(MainWindow *mainwin, guint action,
2978                            GtkWidget *widget)
2979 {
2980         main_window_empty_trash(mainwin, TRUE);
2981 }
2982
2983 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2984 {
2985         summary_save_as(mainwin->summaryview);
2986 }
2987
2988 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2989 {
2990         summary_print(mainwin->summaryview);
2991 }
2992
2993 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2994 {
2995         if (prefs_common.confirm_on_exit) {
2996                 if (alertpanel(_("Exit"), _("Exit Sylpheed-Claws?"),
2997                                GTK_STOCK_CANCEL, GTK_STOCK_QUIT,  NULL)
2998                     != G_ALERTALTERNATE)
2999                         return;
3000                 manage_window_focus_in(mainwin->window, NULL, NULL);
3001         }
3002
3003         app_will_exit(widget, mainwin);
3004 }
3005
3006 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3007 {
3008         if (action == 1)
3009                 summary_search(mainwin->summaryview);
3010         else
3011                 message_search(mainwin->messageview);
3012 }
3013
3014 static void mainwindow_quicksearch(MainWindow *mainwin, guint action, GtkWidget *widget)
3015 {
3016         prefs_common.show_searchbar = TRUE;
3017         summaryview_activate_quicksearch(mainwin->summaryview);
3018 }
3019
3020 static void toggle_folder_cb(MainWindow *mainwin, guint action,
3021                              GtkWidget *widget)
3022 {
3023         gboolean active;
3024
3025         active = GTK_CHECK_MENU_ITEM(widget)->active;
3026
3027         switch (mainwin->type) {
3028         case SEPARATE_NONE:
3029         case SEPARATE_MESSAGE:
3030                 break;
3031         case SEPARATE_FOLDER:
3032                 debug_print("separate folder\n");
3033                 if (active)
3034                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
3035                 else
3036                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
3037                 break;
3038         case SEPARATE_BOTH:
3039                 if (active)
3040                         gtk_widget_show(mainwin->win.sep_both.folderwin);
3041                 else
3042                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
3043                 break;
3044         }
3045
3046         prefs_common.folderview_visible = active;
3047 }
3048
3049 static void toggle_message_cb(MainWindow *mainwin, guint action,
3050                               GtkWidget *widget)
3051 {
3052         gboolean active;
3053
3054         active = GTK_CHECK_MENU_ITEM(widget)->active;
3055
3056         if (active != messageview_is_visible(mainwin->messageview))
3057                 summary_toggle_view(mainwin->summaryview);
3058 }
3059
3060 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
3061                               GtkWidget *widget)
3062 {
3063         toolbar_toggle(action, mainwin);
3064 }
3065
3066 void main_window_reply_cb(MainWindow *mainwin, guint action,
3067                           GtkWidget *widget)
3068 {
3069         MessageView *msgview = (MessageView*)mainwin->messageview;
3070         GSList *msginfo_list = NULL;
3071
3072         g_return_if_fail(msgview != NULL);
3073
3074         msginfo_list = summary_get_selection(mainwin->summaryview);
3075         g_return_if_fail(msginfo_list != NULL);
3076         compose_reply_from_messageview(msgview, msginfo_list, action);
3077         g_slist_free(msginfo_list);
3078 }
3079
3080
3081 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
3082                                 GtkWidget *widget)
3083 {
3084         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3085                 gtk_widget_show(mainwin->hbox_stat);
3086                 prefs_common.show_statusbar = TRUE;
3087         } else {
3088                 gtk_widget_hide(mainwin->hbox_stat);
3089                 prefs_common.show_statusbar = FALSE;
3090         }
3091 }
3092
3093 static void separate_widget_cb(MainWindow *mainwin, guint action,
3094                                GtkWidget *widget)
3095 {
3096         SeparateType type;
3097
3098         if (GTK_CHECK_MENU_ITEM(widget)->active)
3099                 type = mainwin->type | action;
3100         else
3101                 type = mainwin->type & ~action;
3102
3103         main_window_separation_change(mainwin, type);
3104
3105         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
3106         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
3107 }
3108
3109 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline,
3110                                         gboolean ask_sync)
3111 {
3112         offline_ask_sync = ask_sync;
3113         if (offline)
3114                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
3115         else
3116                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
3117         offline_ask_sync = TRUE;
3118 }
3119
3120 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
3121 {
3122         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active, TRUE);
3123 }
3124
3125 static void mainwindow_check_synchronise(MainWindow *mainwin, gboolean ask)
3126 {
3127         GList *folderlist = folder_get_list();
3128         gboolean found = FALSE;
3129
3130         /* see if there are synchronised folders */
3131         for (; folderlist; folderlist = folderlist->next) {
3132                 Folder *folder = (Folder *)folderlist->data;
3133                 if (folder_want_synchronise(folder)) {
3134                         found = TRUE;
3135                         break;
3136                 }
3137         }
3138         
3139         if (!found)
3140                 return;
3141                 
3142         if (offline_ask_sync && ask && alertpanel(_("Folder synchronisation"),
3143                         _("Do you want to synchronise your folders now?"),
3144                         GTK_STOCK_CANCEL, _("+_Synchronise"), NULL) != G_ALERTALTERNATE)
3145                 return;
3146
3147         folder_synchronise(NULL);
3148 }
3149
3150 static void online_switch_clicked (GtkButton *btn, gpointer data) 
3151 {
3152         MainWindow *mainwin;
3153         GtkItemFactory *ifactory;
3154         GtkCheckMenuItem *menuitem;
3155
3156         mainwin = (MainWindow *) data;
3157         
3158         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
3159         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
3160         
3161         g_return_if_fail(mainwin != NULL);
3162         g_return_if_fail(menuitem != NULL);
3163         
3164         if (btn == GTK_BUTTON(mainwin->online_switch)) {
3165                 /* go offline */
3166                 if (prefs_common.work_offline)
3167                         return;
3168                 mainwindow_check_synchronise(mainwin, TRUE);
3169                 gtk_widget_hide (mainwin->online_switch);
3170                 gtk_widget_show (mainwin->offline_switch);
3171                 menuitem->active = TRUE;
3172                 prefs_common.work_offline = TRUE;
3173                 inc_autocheck_timer_remove();           
3174                 imap_disconnect_all();
3175         } else {
3176                 /*go online */
3177                 if (!prefs_common.work_offline)
3178                         return;
3179                 gtk_widget_hide (mainwin->offline_switch);
3180                 gtk_widget_show (mainwin->online_switch);
3181                 menuitem->active = FALSE;
3182                 prefs_common.work_offline = FALSE;
3183                 inc_autocheck_timer_set();
3184                 refresh_resolvers();
3185         }
3186 }
3187
3188 static void addressbook_open_cb(MainWindow *mainwin, guint action,
3189                                 GtkWidget *widget)
3190 {
3191         addressbook_open(NULL);
3192 }
3193
3194 static void log_window_show_cb(MainWindow *mainwin, guint action,
3195                                GtkWidget *widget)
3196 {
3197         log_window_show(mainwin->logwin);
3198 }
3199
3200 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3201 {
3202         inc_cancel_all();
3203 }
3204
3205 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3206 {
3207         summary_move_to(mainwin->summaryview);
3208 }
3209
3210 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3211 {
3212         summary_copy_to(mainwin->summaryview);
3213 }
3214
3215 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3216 {
3217         summary_delete(mainwin->summaryview);
3218 }
3219
3220 static void delete_trash_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3221 {
3222         summary_delete_trash(mainwin->summaryview);
3223 }
3224
3225 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3226 {
3227         summary_cancel(mainwin->summaryview);
3228 }
3229
3230 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3231 {
3232         summary_open_msg(mainwin->summaryview);
3233 }
3234
3235 static void view_source_cb(MainWindow *mainwin, guint action,
3236                            GtkWidget *widget)
3237 {
3238         summary_view_source(mainwin->summaryview);
3239 }
3240
3241 static void show_all_header_cb(MainWindow *mainwin, guint action,
3242                                GtkWidget *widget)
3243 {
3244         if (mainwin->menu_lock_count) return;
3245         mainwin->summaryview->messageview->all_headers = 
3246                         GTK_CHECK_MENU_ITEM(widget)->active;
3247         summary_display_msg_selected(mainwin->summaryview,
3248                                      GTK_CHECK_MENU_ITEM(widget)->active);
3249 }
3250
3251 static void hide_quotes_cb(MainWindow *mainwin, guint action,
3252                                GtkWidget *widget)
3253 {
3254         if (mainwin->menu_lock_count) return;
3255         prefs_common.hide_quotes = 
3256                         GTK_CHECK_MENU_ITEM(widget)->active;
3257         summary_display_msg_selected(mainwin->summaryview,
3258                                      GTK_CHECK_MENU_ITEM(widget)->active);
3259 }
3260
3261 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3262 {
3263         summary_mark(mainwin->summaryview);
3264 }
3265
3266 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3267 {
3268         summary_unmark(mainwin->summaryview);
3269 }
3270
3271 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3272                               GtkWidget *widget)
3273 {
3274         summary_mark_as_unread(mainwin->summaryview);
3275 }
3276
3277 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3278                             GtkWidget *widget)
3279 {
3280         summary_mark_as_read(mainwin->summaryview);
3281 }
3282
3283 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3284                              GtkWidget *widget)
3285 {
3286         summary_mark_all_read(mainwin->summaryview);
3287 }
3288
3289 static void mark_as_spam_cb(MainWindow *mainwin, guint action,
3290                              GtkWidget *widget)
3291 {
3292         summary_mark_as_spam(mainwin->summaryview, action, NULL);
3293 }
3294
3295 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3296 {
3297         summary_reedit(mainwin->summaryview);
3298 }
3299
3300 static void add_address_cb(MainWindow *mainwin, guint action,
3301                            GtkWidget *widget)
3302 {
3303         summary_add_address(mainwin->summaryview);
3304 }
3305
3306 static void set_charset_cb(MainWindow *mainwin, guint action,
3307                            GtkWidget *widget)
3308 {
3309         const gchar *str;
3310
3311         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3312                 str = conv_get_charset_str((CharSet)action);
3313                 
3314                 g_free(mainwin->messageview->forced_charset);
3315                 mainwin->messageview->forced_charset = str ? g_strdup(str) : NULL;
3316                 procmime_force_charset(str);
3317                 
3318                 summary_redisplay_msg(mainwin->summaryview);
3319                 
3320                 debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3321         }
3322 }
3323
3324 static void set_decode_cb(MainWindow *mainwin, guint action,
3325                            GtkWidget *widget)
3326 {
3327         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3328                 mainwin->messageview->forced_encoding = (EncodingType)action;
3329                 
3330                 summary_redisplay_msg(mainwin->summaryview);
3331                 
3332                 debug_print("forced encoding: %d\n", action);
3333         }
3334 }
3335
3336 static void hide_read_messages (MainWindow *mainwin, guint action,
3337                                 GtkWidget *widget)
3338 {
3339         if (!mainwin->summaryview->folder_item
3340             || g_object_get_data(G_OBJECT(widget), "dont_toggle"))
3341                 return;
3342         summary_toggle_show_read_messages(mainwin->summaryview);
3343 }
3344
3345 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3346 {
3347         gboolean threaded = FALSE;
3348         if (mainwin->menu_lock_count) return;
3349         if (!mainwin->summaryview->folder_item) return;
3350
3351         threaded = GTK_CHECK_MENU_ITEM(widget)->active;
3352
3353         mainwin->summaryview->folder_item->threaded = threaded; 
3354
3355         mainwin->summaryview->threaded = threaded;
3356
3357         summary_show(mainwin->summaryview, 
3358                         mainwin->summaryview->folder_item);
3359 }
3360
3361 static void expand_threads_cb(MainWindow *mainwin, guint action,
3362                               GtkWidget *widget)
3363 {
3364         summary_expand_threads(mainwin->summaryview);
3365 }
3366
3367 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3368                                 GtkWidget *widget)
3369 {
3370         summary_collapse_threads(mainwin->summaryview);
3371 }
3372
3373 static void set_summary_display_item_cb(MainWindow *mainwin, guint action,
3374                                 GtkWidget *widget)
3375 {
3376         prefs_summary_column_open();
3377 }
3378
3379 static void set_folder_display_item_cb(MainWindow *mainwin, guint action,
3380                                 GtkWidget *widget)
3381 {
3382         prefs_folder_column_open();
3383 }
3384
3385 static void sort_summary_cb(MainWindow *mainwin, guint action,
3386                             GtkWidget *widget)
3387 {
3388         FolderItem *item = mainwin->summaryview->folder_item;
3389         GtkWidget *menuitem;
3390
3391         if (mainwin->menu_lock_count) return;
3392
3393         if (GTK_CHECK_MENU_ITEM(widget)->active && item) {
3394                 menuitem = gtk_item_factory_get_item
3395                         (mainwin->menu_factory, "/View/Sort/Ascending");
3396                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3397                              GTK_CHECK_MENU_ITEM(menuitem)->active
3398                              ? SORT_ASCENDING : SORT_DESCENDING);
3399                 item->sort_key = action;
3400         }
3401 }
3402
3403 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3404                                  GtkWidget *widget)
3405 {
3406         FolderItem *item = mainwin->summaryview->folder_item;
3407
3408         if (mainwin->menu_lock_count) return;
3409
3410         if (GTK_CHECK_MENU_ITEM(widget)->active && item)
3411                 summary_sort(mainwin->summaryview,
3412                              item->sort_key, (FolderSortType)action);
3413 }
3414
3415 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3416                                   GtkWidget *widget)
3417 {
3418         summary_attract_by_subject(mainwin->summaryview);
3419 }
3420
3421 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3422                                  GtkWidget *widget)
3423 {
3424         FolderItem *item;
3425
3426         item = folderview_get_selected_item(mainwin->folderview);
3427         if (item) {
3428                 main_window_cursor_wait(mainwin);
3429                 STATUSBAR_PUSH(mainwin, _("Deleting duplicated messages..."));
3430
3431                 folderutils_delete_duplicates(item, prefs_common.immediate_exec ?
3432                                               DELETE_DUPLICATES_REMOVE : DELETE_DUPLICATES_SETFLAG);
3433
3434                 STATUSBAR_POP(mainwin);
3435                 main_window_cursor_normal(mainwin);
3436         }
3437 }
3438
3439 struct DelDupsData
3440 {
3441         guint   dups;
3442         guint   folders;
3443 };
3444
3445 static void deldup_all(FolderItem *item, gpointer _data)
3446 {
3447         struct DelDupsData *data = _data;
3448         gint result;
3449         
3450         result = folderutils_delete_duplicates(item, DELETE_DUPLICATES_REMOVE);
3451         if (result >= 0) {
3452                 data->dups += result;
3453                 data->folders += 1;
3454         }
3455 }
3456
3457 static void delete_duplicated_all_cb(MainWindow *mainwin, guint action,
3458                                  GtkWidget *widget)
3459 {
3460         struct DelDupsData data = {0, 0};
3461
3462         folder_func_to_all_folders(deldup_all, &data);
3463         alertpanel_notice(ngettext("Deleted %d duplicate message in %d folders.\n",
3464                                    "Deleted %d duplicate messages in %d folders.\n",
3465                                    data.dups),
3466                           data.dups, data.folders);
3467 }
3468
3469 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3470 {
3471         summary_filter(mainwin->summaryview, (gboolean)action);
3472 }
3473
3474 static void execute_summary_cb(MainWindow *mainwin, guint action,
3475                                GtkWidget *widget)
3476 {
3477         summary_execute(mainwin->summaryview);
3478 }
3479
3480 static void update_summary_cb(MainWindow *mainwin, guint action,
3481                               GtkWidget *widget)
3482 {
3483         FolderItem *fitem;
3484         FolderView *folderview = mainwin->folderview;
3485
3486         if (!mainwin->summaryview->folder_item) return;
3487         if (!folderview->opened) return;
3488
3489         folder_update_op_count();
3490
3491         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3492                                             folderview->opened);
3493         if (!fitem) return;
3494
3495         folder_item_scan(fitem);
3496         summary_show(mainwin->summaryview, fitem);
3497 }
3498
3499 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3500 {
3501         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3502 }
3503
3504 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3505 {
3506         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3507 }
3508
3509 static void prev_unread_cb(MainWindow *mainwin, guint action,
3510                            GtkWidget *widget)
3511 {
3512         summary_select_prev_unread(mainwin->summaryview);
3513 }
3514
3515 static void next_unread_cb(MainWindow *mainwin, guint action,
3516                            GtkWidget *widget)
3517 {
3518         summary_select_next_unread(mainwin->summaryview);
3519 }
3520
3521 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3522 {
3523         summary_select_prev_new(mainwin->summaryview);
3524 }
3525
3526 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3527 {
3528         summary_select_next_new(mainwin->summaryview);
3529 }
3530
3531 static void prev_marked_cb(MainWindow *mainwin, guint action,
3532                            GtkWidget *widget)
3533 {
3534         summary_select_prev_marked(mainwin->summaryview);
3535 }
3536
3537 static void next_marked_cb(MainWindow *mainwin, guint action,
3538                            GtkWidget *widget)
3539 {
3540         summary_select_next_marked(mainwin->summaryview);
3541 }
3542
3543 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3544                             GtkWidget *widget)
3545 {
3546         summary_select_prev_labeled(mainwin->summaryview);
3547 }
3548
3549 static void next_labeled_cb(MainWindow *mainwin, guint action,
3550                             GtkWidget *widget)
3551 {
3552         summary_select_next_labeled(mainwin->summaryview);
3553 }
3554
3555 static void last_read_cb(MainWindow *mainwin, guint action,
3556                             GtkWidget *widget)
3557 {
3558         summary_select_last_read(mainwin->summaryview);
3559 }
3560
3561 static void parent_cb(MainWindow *mainwin, guint action,
3562                             GtkWidget *widget)
3563 {
3564         summary_select_parent(mainwin->summaryview);
3565 }
3566
3567 static void goto_folder_cb(MainWindow *mainwin, guint action,
3568                            GtkWidget *widget)
3569 {
3570         FolderItem *to_folder;
3571
3572         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
3573
3574         if (to_folder)
3575                 folderview_select(mainwin->folderview, to_folder);
3576 }
3577
3578 static void goto_unread_folder_cb(MainWindow *mainwin, guint action,
3579                            GtkWidget *widget)
3580 {
3581         folderview_select_next_unread(mainwin->folderview);
3582 }
3583
3584 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3585 {
3586         messageview_copy_clipboard(mainwin->messageview);
3587 }
3588
3589 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3590 {
3591         MessageView *msgview = mainwin->messageview;
3592
3593         if (messageview_is_visible(msgview) &&
3594                  (GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3595                 messageview_select_all(mainwin->messageview);
3596         else
3597                 summary_select_all(mainwin->summaryview);
3598 }
3599
3600 static void select_thread_cb(MainWindow *mainwin, guint action,
3601                              GtkWidget *widget)
3602 {
3603         summary_select_thread(mainwin->summaryview);
3604 }
3605
3606 static void create_filter_cb(MainWindow *mainwin, guint action,
3607                              GtkWidget *widget)
3608 {
3609         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 0);
3610 }
3611
3612 static void create_processing_cb(MainWindow *mainwin, guint action,
3613                              GtkWidget *widget)
3614 {
3615         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action, 1);
3616 }
3617
3618 static void prefs_pre_processing_open_cb(MainWindow *mainwin, guint action,
3619                                          GtkWidget *widget)
3620 {
3621         prefs_filtering_open(&pre_global_processing,
3622                              _("Processing rules to apply before folder rules"),
3623                              MANUAL_ANCHOR_PROCESSING,
3624                              NULL, NULL, FALSE);
3625 }
3626
3627 static void prefs_post_processing_open_cb(MainWindow *mainwin, guint action,
3628                                           GtkWidget *widget)
3629 {
3630         prefs_filtering_open(&post_global_processing,
3631                              _("Processing rules to apply after folder rules"),
3632                              MANUAL_ANCHOR_PROCESSING,
3633                              NULL, NULL, FALSE);
3634 }
3635
3636 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
3637                                     GtkWidget *widget)
3638 {
3639         prefs_filtering_open(&filtering_rules,
3640                              _("Filtering configuration"),
3641                              MANUAL_ANCHOR_FILTERING,
3642                              NULL, NULL, TRUE);
3643 }
3644
3645 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
3646                                    GtkWidget *widget)
3647 {
3648         prefs_template_open();
3649 }
3650
3651 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
3652                                   GtkWidget *widget)
3653 {
3654         prefs_actions_open(mainwin);
3655 }
3656 #ifdef USE_OPENSSL
3657 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
3658                                   GtkWidget *widget)
3659 {
3660         ssl_manager_open(mainwin);
3661 }
3662 #endif
3663 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
3664                                   GtkWidget *widget)
3665 {
3666         if (!cur_account) {
3667                 new_account_cb(mainwin, 0, widget);
3668         } else {
3669                 account_open(cur_account);
3670         }
3671 }
3672
3673 static void new_account_cb(MainWindow *mainwin, guint action,
3674                            GtkWidget *widget)
3675 {
3676         account_edit_open();
3677         if (!compose_get_compose_list()) account_add();
3678 }
3679
3680 static void account_selector_menu_cb(GtkMenuItem *menuitem, gpointer data)
3681 {
3682         FolderItem *item = NULL;
3683         cur_account = (PrefsAccount *)data;
3684         
3685         if (!mainwindow_get_mainwindow())
3686                 return;
3687         main_window_show_cur_account(mainwindow_get_mainwindow());
3688         toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
3689         main_window_set_menu_sensitive(mainwindow_get_mainwindow());
3690         toolbar_main_set_sensitive(mainwindow_get_mainwindow());
3691         item = folderview_get_selected_item(
3692                         mainwindow_get_mainwindow()->folderview);
3693         if (item) {
3694                 toolbar_set_compose_button
3695                         (mainwindow_get_mainwindow()->toolbar,
3696                          FOLDER_TYPE(item->folder) == F_NEWS ? 
3697                          COMPOSEBUTTON_NEWS : COMPOSEBUTTON_MAIL);
3698         }
3699 }
3700
3701 static void account_receive_menu_cb(GtkMenuItem *menuitem, gpointer data)
3702 {
3703         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3704         PrefsAccount *account = (PrefsAccount *)data;
3705
3706         inc_account_mail(mainwin, account);
3707 }
3708
3709 static void account_compose_menu_cb(GtkMenuItem *menuitem, gpointer data)
3710 {
3711         MainWindow *mainwin = (MainWindow *)mainwin_list->data;
3712         PrefsAccount *account = (PrefsAccount *)data;
3713         FolderItem *item = mainwin->summaryview->folder_item;   
3714
3715         compose_new_with_folderitem(account, item);
3716 }
3717
3718 static void prefs_open_cb(GtkMenuItem *menuitem, gpointer data)
3719 {
3720         prefs_gtk_open();
3721 }
3722
3723 static void plugins_open_cb(GtkMenuItem *menuitem, gpointer data)
3724 {
3725         pluginwindow_create();
3726 }
3727
3728 static void manual_open_cb(MainWindow *mainwin, guint action,
3729                            GtkWidget *widget)
3730 {
3731         manual_open((ManualType)action, NULL);
3732 }
3733
3734 static void legend_open_cb(GtkMenuItem *menuitem, gpointer data)
3735 {
3736         legend_show();
3737 }
3738
3739 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
3740 {
3741         MainWindow *mainwin = (MainWindow *)data;
3742         gchar *str;
3743
3744         if (item->path)
3745                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
3746                                       LOCAL_FOLDER(folder)->rootpath,
3747                                       G_DIR_SEPARATOR,
3748                                       item->path);
3749         else
3750                 str = g_strdup_printf(_("Scanning folder %s ..."),
3751                                       LOCAL_FOLDER(folder)->rootpath);
3752
3753         STATUSBAR_PUSH(mainwin, str);
3754         STATUSBAR_POP(mainwin);
3755         g_free(str);
3756 }
3757
3758 static gboolean mainwindow_focus_in_event(GtkWidget *widget, GdkEventFocus *focus,
3759                                           gpointer data)
3760 {
3761         SummaryView *summary;
3762
3763         g_return_val_if_fail(data, FALSE);
3764         if (!g_list_find(mainwin_list, data))
3765                 return TRUE;
3766         summary = ((MainWindow *)data)->summaryview;
3767         g_return_val_if_fail(summary, FALSE);
3768
3769         if (GTK_CLIST(summary->ctree)->selection && 
3770             g_list_length(GTK_CLIST(summary->ctree)->selection) > 1)
3771                 return FALSE;
3772
3773         return FALSE;
3774 }
3775
3776 #define BREAK_ON_MODIFIER_KEY() \
3777         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
3778
3779 gboolean mainwindow_key_pressed (GtkWidget *widget, GdkEventKey *event,
3780                                     gpointer data)
3781 {
3782         MainWindow *mainwin = (MainWindow*) data;
3783         
3784         if (!mainwin || !event) 
3785                 return FALSE;
3786
3787         if (quicksearch_has_focus(mainwin->summaryview->quicksearch))
3788         {
3789                 lastkey = event->keyval;
3790                 return FALSE;
3791         }
3792
3793         switch (event->keyval) {
3794         case GDK_Q:             /* Quit */
3795                 BREAK_ON_MODIFIER_KEY();
3796
3797                 app_exit_cb(mainwin, 0, NULL);
3798                 return FALSE;
3799         case GDK_space:
3800                 if (mainwin->folderview && mainwin->summaryview
3801                     && ((!mainwin->summaryview->displayed
3802                         && !mainwin->summaryview->selected) 
3803                         || (mainwin->summaryview->folder_item
3804                             && mainwin->summaryview->folder_item->total_msgs == 0))) {
3805                         g_signal_stop_emission_by_name(G_OBJECT(widget), 
3806                                        "key_press_event");
3807                         folderview_select_next_unread(mainwin->folderview);
3808                 }
3809                 break;
3810         default:
3811                 break;
3812         }
3813         return FALSE;
3814 }
3815
3816 #undef BREAK_ON_MODIFIER_KEY
3817
3818 /*
3819  * Harvest addresses for selected folder.
3820  */
3821 static void addr_harvest_cb( MainWindow *mainwin,
3822                             guint action,
3823                             GtkWidget *widget )
3824 {
3825         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
3826 }
3827
3828 /*
3829  * Harvest addresses for selected messages in summary view.
3830  */
3831 static void addr_harvest_msg_cb( MainWindow *mainwin,
3832                             guint action,
3833                             GtkWidget *widget )
3834 {
3835         summary_harvest_address( mainwin->summaryview );
3836 }
3837
3838 /*!
3839  *\brief        get a MainWindow
3840  *
3841  *\return       MainWindow * The first mainwindow in the mainwin_list
3842  */
3843 MainWindow *mainwindow_get_mainwindow(void)
3844 {
3845         if (mainwin_list && mainwin_list->data)
3846                 return (MainWindow *)(mainwin_list->data);
3847         else
3848                 return NULL;
3849 }
3850
3851 gboolean mainwindow_progressindicator_hook(gpointer source, gpointer userdata)
3852 {
3853         ProgressData *data = (ProgressData *) source;
3854         MainWindow *mainwin = (MainWindow *) userdata;
3855
3856         switch (data->cmd) {
3857         case PROGRESS_COMMAND_START:
3858         case PROGRESS_COMMAND_STOP:
3859                 gtk_progress_bar_set_fraction
3860                         (GTK_PROGRESS_BAR(mainwin->progressbar), 0.0);
3861                 break;
3862         case PROGRESS_COMMAND_SET_PERCENTAGE:
3863                 gtk_progress_bar_set_fraction
3864