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