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