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