fixed typo that broke forwarding
[claws.git] / src / mainwindow.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 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 <gtk/gtkmain.h>
24 #include <gtk/gtkwindow.h>
25 #include <gtk/gtkwidget.h>
26 #include <gtk/gtksignal.h>
27 #include <gtk/gtkvbox.h>
28 #include <gtk/gtkcontainer.h>
29 #include <gtk/gtkstatusbar.h>
30 #include <gtk/gtkhpaned.h>
31 #include <gtk/gtkvpaned.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkitemfactory.h>
34 #include <gtk/gtkeditable.h>
35 #include <gtk/gtkmenu.h>
36 #include <gtk/gtkmenuitem.h>
37 #include <gtk/gtkhandlebox.h>
38 #include <gtk/gtktoolbar.h>
39 #include <gtk/gtkbutton.h>
40 #include <string.h>
41
42 #include "intl.h"
43 #include "main.h"
44 #include "mainwindow.h"
45 #include "folderview.h"
46 #include "foldersel.h"
47 #include "summaryview.h"
48 #include "summary_search.h"
49 #include "messageview.h"
50 #include "headerview.h"
51 #include "menu.h"
52 #include "folder.h"
53 #include "inc.h"
54 #include "compose.h"
55 #include "procmsg.h"
56 #include "import.h"
57 #include "export.h"
58 #include "prefs_common.h"
59 #include "prefs_filter.h"
60 #include "prefs_filtering.h"
61 #include "prefs_scoring.h"
62 #include "prefs_account.h"
63 #include "prefs_folder_item.h"
64 #include "account.h"
65 #include "addressbook.h"
66 #include "headerwindow.h"
67 #include "logwindow.h"
68 #include "manage_window.h"
69 #include "alertpanel.h"
70 #include "statusbar.h"
71 #include "inputdialog.h"
72 #include "utils.h"
73 #include "gtkutils.h"
74 #include "codeconv.h"
75 #include "about.h"
76 #include "manual.h"
77
78 #define AC_LABEL_WIDTH  240
79
80 #define STATUSBAR_PUSH(mainwin, str) \
81 { \
82         gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar), \
83                            mainwin->mainwin_cid, str); \
84         gtkut_widget_wait_for_draw(mainwin->hbox_stat); \
85 }
86
87 #define STATUSBAR_POP(mainwin) \
88 { \
89         gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar), \
90                           mainwin->mainwin_cid); \
91 }
92
93 /* list of all instantiated MainWindow */
94 static GList *mainwin_list = NULL;
95
96 static GdkCursor *watch_cursor;
97
98 static void main_window_show_cur_account        (MainWindow     *mainwin);
99
100 static void main_window_set_widgets             (MainWindow     *mainwin,
101                                                  SeparateType    type);
102 static void main_window_toolbar_create          (MainWindow     *mainwin,
103                                                  GtkWidget      *container);
104
105 /* callback functions */
106 static void toolbar_inc_cb              (GtkWidget      *widget,
107                                          gpointer        data);
108 static void toolbar_inc_all_cb          (GtkWidget      *widget,
109                                          gpointer        data);
110 static void toolbar_send_cb             (GtkWidget      *widget,
111                                          gpointer        data);
112
113 static void toolbar_compose_cb          (GtkWidget      *widget,
114                                          gpointer        data);
115 static void toolbar_reply_cb            (GtkWidget      *widget,
116                                          gpointer        data);
117 static void toolbar_reply_to_all_cb     (GtkWidget      *widget,
118                                          gpointer        data);
119 static void toolbar_reply_to_sender_cb  (GtkWidget      *widget,
120                                          gpointer        data);
121 static void toolbar_forward_cb          (GtkWidget      *widget,
122                                          gpointer        data);
123
124 static void toolbar_delete_cb           (GtkWidget      *widget,
125                                          gpointer        data);
126 static void toolbar_exec_cb             (GtkWidget      *widget,
127                                          gpointer        data);
128
129 static void toolbar_next_unread_cb      (GtkWidget      *widget,
130                                          gpointer        data);
131
132 static void toolbar_prefs_cb            (GtkWidget      *widget,
133                                          gpointer        data);
134 static void toolbar_account_cb          (GtkWidget      *widget,
135                                          gpointer        data);
136
137 static void toolbar_account_button_pressed      (GtkWidget      *widget,
138                                                  GdkEventButton *event,
139                                                  gpointer        data);
140 static void ac_label_button_pressed             (GtkWidget      *widget,
141                                                  GdkEventButton *event,
142                                                  gpointer        data);
143
144 static gint main_window_close_cb (GtkWidget     *widget,
145                                   GdkEventAny   *event,
146                                   gpointer       data);
147
148 static void add_mailbox_cb       (MainWindow    *mainwin,
149                                   guint          action,
150                                   GtkWidget     *widget);
151 static void add_mbox_cb          (MainWindow    *mainwin,
152                                   guint          action,
153                                   GtkWidget     *widget);
154 static void update_folderview_cb (MainWindow    *mainwin,
155                                   guint          action,
156                                   GtkWidget     *widget);
157 static void new_folder_cb        (MainWindow    *mainwin,
158                                   guint          action,
159                                   GtkWidget     *widget);
160 static void rename_folder_cb     (MainWindow    *mainwin,
161                                   guint          action,
162                                   GtkWidget     *widget);
163 static void delete_folder_cb     (MainWindow    *mainwin,
164                                   guint          action,
165                                   GtkWidget     *widget);
166 static void import_mbox_cb       (MainWindow    *mainwin,
167                                   guint          action,
168                                   GtkWidget     *widget);
169 static void export_mbox_cb       (MainWindow    *mainwin,
170                                   guint          action,
171                                   GtkWidget     *widget);
172 static void empty_trash_cb       (MainWindow    *mainwin,
173                                   guint          action,
174                                   GtkWidget     *widget);
175
176 static void save_as_cb           (MainWindow    *mainwin,
177                                   guint          action,
178                                   GtkWidget     *widget);
179 static void print_cb             (MainWindow    *mainwin,
180                                   guint          action,
181                                   GtkWidget     *widget);
182 static void app_exit_cb          (MainWindow    *mainwin,
183                                   guint          action,
184                                   GtkWidget     *widget);
185
186 static void toggle_folder_cb     (MainWindow    *mainwin,
187                                   guint          action,
188                                   GtkWidget     *widget);
189 static void toggle_message_cb    (MainWindow    *mainwin,
190                                   guint          action,
191                                   GtkWidget     *widget);
192 static void toggle_toolbar_cb    (MainWindow    *mainwin,
193                                   guint          action,
194                                   GtkWidget     *widget);
195 static void toggle_statusbar_cb  (MainWindow    *mainwin,
196                                   guint          action,
197                                   GtkWidget     *widget);
198 static void separate_widget_cb(GtkCheckMenuItem *checkitem, guint action);
199
200 static void addressbook_open_cb (MainWindow     *mainwin,
201                                  guint           action,
202                                  GtkWidget      *widget);
203 static void log_window_show_cb  (MainWindow     *mainwin,
204                                  guint           action,
205                                  GtkWidget      *widget);
206
207 static void inc_mail_cb                 (MainWindow     *mainwin,
208                                          guint           action,
209                                          GtkWidget      *widget);
210 static void inc_all_account_mail_cb     (MainWindow     *mainwin,
211                                          guint           action,
212                                          GtkWidget      *widget);
213
214 static void send_queue_cb               (MainWindow     *mainwin,
215                                          guint           action,
216                                          GtkWidget      *widget);
217
218 static void compose_cb                  (MainWindow     *mainwin,
219                                          guint           action,
220                                          GtkWidget      *widget);
221 static void reply_cb                    (MainWindow     *mainwin,
222                                          guint           action,
223                                          GtkWidget      *widget);
224
225 static void open_msg_cb                 (MainWindow     *mainwin,
226                                          guint           action,
227                                          GtkWidget      *widget);
228
229 static void view_source_cb              (MainWindow     *mainwin,
230                                          guint           action,
231                                          GtkWidget      *widget);
232
233 static void reedit_cb                   (MainWindow     *mainwin,
234                                          guint           action,
235                                          GtkWidget      *widget);
236
237 static void move_to_cb                  (MainWindow     *mainwin,
238                                          guint           action,
239                                          GtkWidget      *widget);
240 static void copy_to_cb                  (MainWindow     *mainwin,
241                                          guint           action,
242                                          GtkWidget      *widget);
243 static void delete_cb                   (MainWindow     *mainwin,
244                                          guint           action,
245                                          GtkWidget      *widget);
246
247 static void mark_cb                     (MainWindow     *mainwin,
248                                          guint           action,
249                                          GtkWidget      *widget);
250 static void unmark_cb                   (MainWindow     *mainwin,
251                                          guint           action,
252                                          GtkWidget      *widget);
253
254 static void mark_as_unread_cb           (MainWindow     *mainwin,
255                                          guint           action,
256                                          GtkWidget      *widget);
257 static void mark_as_read_cb             (MainWindow     *mainwin,
258                                          guint           action,
259                                          GtkWidget      *widget);
260
261 static void set_charset_cb              (MainWindow     *mainwin,
262                                          guint           action,
263                                          GtkWidget      *widget);
264
265 static void thread_cb            (MainWindow    *mainwin,
266                                   guint          action,
267                                   GtkWidget     *widget);
268 static void set_display_item_cb  (MainWindow    *mainwin,
269                                   guint          action,
270                                   GtkWidget     *widget);
271 static void sort_summary_cb      (MainWindow    *mainwin,
272                                   guint          action,
273                                   GtkWidget     *widget);
274 static void attract_by_subject_cb(MainWindow    *mainwin,
275                                   guint          action,
276                                   GtkWidget     *widget);
277
278 static void delete_duplicated_cb (MainWindow    *mainwin,
279                                   guint          action,
280                                   GtkWidget     *widget);
281 static void filter_cb            (MainWindow    *mainwin,
282                                   guint          action,
283                                   GtkWidget     *widget);
284 static void execute_summary_cb   (MainWindow    *mainwin,
285                                   guint          action,
286                                   GtkWidget     *widget);
287 static void update_summary_cb    (MainWindow    *mainwin,
288                                   guint          action,
289                                   GtkWidget     *widget);
290
291 static void prev_cb              (MainWindow    *mainwin,
292                                   guint          action,
293                                   GtkWidget     *widget);
294 static void next_cb              (MainWindow    *mainwin,
295                                   guint          action,
296                                   GtkWidget     *widget);
297
298 static void next_unread_cb       (MainWindow    *mainwin,
299                                   guint          action,
300                                   GtkWidget     *widget);
301
302 static void next_marked_cb       (MainWindow    *mainwin,
303                                   guint          action,
304                                   GtkWidget     *widget);
305
306 static void prev_marked_cb       (MainWindow    *mainwin,
307                                   guint          action,
308                                   GtkWidget     *widget);
309
310 static void goto_folder_cb       (MainWindow    *mainwin,
311                                   guint          action,
312                                   GtkWidget     *widget);
313
314 static void copy_cb              (MainWindow    *mainwin,
315                                   guint          action,
316                                   GtkWidget     *widget);
317 static void allsel_cb            (MainWindow    *mainwin,
318                                   guint          action,
319                                   GtkWidget     *widget);
320
321 static void prefs_common_open_cb (MainWindow    *mainwin,
322                                   guint          action,
323                                   GtkWidget     *widget);
324 static void prefs_filter_open_cb (MainWindow    *mainwin,
325                                   guint          action,
326                                   GtkWidget     *widget);
327 static void prefs_scoring_open_cb (MainWindow   *mainwin,
328                                   guint          action,
329                                   GtkWidget     *widget);
330 static void prefs_filtering_open_cb (MainWindow *mainwin,
331                                   guint          action,
332                                   GtkWidget     *widget);
333 static void prefs_account_open_cb(MainWindow    *mainwin,
334                                   guint          action,
335                                   GtkWidget     *widget);
336 static void new_account_cb       (MainWindow    *mainwin,
337                                   guint          action,
338                                   GtkWidget     *widget);
339
340 static void account_menu_cb      (GtkMenuItem   *menuitem,
341                                   gpointer       data);
342
343 static void manual_open_cb       (MainWindow    *mainwin,
344                                   guint          action,
345                                   GtkWidget     *widget);
346
347 static void scan_tree_func       (Folder        *folder,
348                                   FolderItem    *item,
349                                   gpointer       data);
350
351 #define  SEPARATE_ACTION  667
352
353 static GtkItemFactoryEntry mainwin_entries[] =
354 {
355         {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
356         {N_("/_File/_Add mailbox..."),          NULL, add_mailbox_cb, 0, NULL},
357         {N_("/_File/_Add mbox mailbox..."),     NULL, add_mbox_cb, 0, NULL},
358         {N_("/_File/_Update folder tree"),      NULL, update_folderview_cb, 0, NULL},
359         {N_("/_File/_Folder"),                  NULL, NULL, 0, "<Branch>"},
360         {N_("/_File/_Folder/Create _new folder..."),
361                                                 NULL, new_folder_cb, 0, NULL},
362         {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
363         {N_("/_File/_Folder/_Delete folder"),   NULL, delete_folder_cb, 0, NULL},
364         {N_("/_File/_Import mbox file..."),     NULL, import_mbox_cb, 0, NULL},
365         {N_("/_File/_Export to mbox file..."),  NULL, export_mbox_cb, 0, NULL},
366         {N_("/_File/Empty _trash"),             NULL, empty_trash_cb, 0, NULL},
367         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
368         {N_("/_File/_Save as..."),              NULL, save_as_cb, 0, NULL},
369         {N_("/_File/_Print..."),                "<alt>P", print_cb, 0, NULL},
370         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
371         {N_("/_File/_Close"),                   "<alt>W", app_exit_cb, 0, NULL},
372         {N_("/_File/E_xit"),                    "<alt>Q", app_exit_cb, 0, NULL},
373
374         {N_("/_Edit"),                          NULL, NULL, 0, "<Branch>"},
375         {N_("/_Edit/_Copy"),                    "<control>C", copy_cb, 0, NULL},
376         {N_("/_Edit/Select _all"),              "<control>A", allsel_cb, 0, NULL},
377         {N_("/_Edit/---"),                      NULL, NULL, 0, "<Separator>"},
378         {N_("/_Edit/_Search"),                  "<control>S", summary_search_cb, 0, NULL},
379
380         {N_("/_View"),                          NULL, NULL, 0, "<Branch>"},
381         {N_("/_View/_Folder tree"),             NULL, toggle_folder_cb, 0, "<ToggleItem>"},
382         {N_("/_View/_Message view"),            NULL, toggle_message_cb, 0, "<ToggleItem>"},
383         {N_("/_View/_Toolbar"),                 NULL, NULL, 0, "<Branch>"},
384         {N_("/_View/_Toolbar/Icon _and text"),  NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
385         {N_("/_View/_Toolbar/_Icon"),           NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Toolbar/Icon and text"},
386         {N_("/_View/_Toolbar/_Text"),           NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Toolbar/Icon and text"},
387         {N_("/_View/_Toolbar/_None"),           NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Toolbar/Icon and text"},
388         {N_("/_View/_Status bar"),              NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
389         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
390         {N_("/_View/Separate f_older tree"),    NULL, NULL, SEPARATE_ACTION + SEPARATE_FOLDER, "<ToggleItem>"},
391         {N_("/_View/Separate m_essage view"),   NULL, NULL, SEPARATE_ACTION + SEPARATE_MESSAGE, "<ToggleItem>"},
392         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
393         {N_("/_View/_Code set"),                NULL, NULL, 0, "<Branch>"},
394         {N_("/_View/_Code set/_Auto detect"),
395          NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
396
397 #define CODESET_SEPARATOR \
398         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"}
399 #define CODESET_ACTION(action) \
400          NULL, set_charset_cb, action, "/View/Code set/Auto detect"
401
402         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"},
403         {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
404          CODESET_ACTION(C_US_ASCII)},
405
406 #if HAVE_LIBJCONV
407         {N_("/_View/_Code set/Unicode (_UTF-8)"),
408          CODESET_ACTION(C_UTF_8)},
409         CODESET_SEPARATOR,
410 #endif
411         {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
412          CODESET_ACTION(C_ISO_8859_1)},
413         CODESET_SEPARATOR,
414 #if HAVE_LIBJCONV
415         {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
416          CODESET_ACTION(C_ISO_8859_2)},
417         CODESET_SEPARATOR,
418         {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
419          CODESET_ACTION(C_ISO_8859_13)},
420         {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
421          CODESET_ACTION(C_ISO_8859_4)},
422         CODESET_SEPARATOR,
423         {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
424          CODESET_ACTION(C_ISO_8859_7)},
425         CODESET_SEPARATOR,
426         {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
427          CODESET_ACTION(C_ISO_8859_9)},
428         CODESET_SEPARATOR,
429         {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
430          CODESET_ACTION(C_ISO_8859_5)},
431         {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
432          CODESET_ACTION(C_KOI8_R)},
433         {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
434          CODESET_ACTION(C_CP1251)},
435         CODESET_SEPARATOR,
436 #endif
437         {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
438          CODESET_ACTION(C_ISO_2022_JP)},
439 #if HAVE_LIBJCONV
440         {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
441          CODESET_ACTION(C_ISO_2022_JP_2)},
442 #endif
443         {N_("/_View/_Code set/Japanese (_EUC-JP)"),
444          CODESET_ACTION(C_EUC_JP)},
445         {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
446          CODESET_ACTION(C_SHIFT_JIS)},
447 #if HAVE_LIBJCONV
448         CODESET_SEPARATOR,
449         {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
450          CODESET_ACTION(C_GB2312)},
451         {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
452          CODESET_ACTION(C_BIG5)},
453         {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
454          CODESET_ACTION(C_EUC_TW)},
455         {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
456          CODESET_ACTION(C_ISO_2022_CN)},
457         CODESET_SEPARATOR,
458         {N_("/_View/_Code set/Korean (EUC-_KR)"),
459          CODESET_ACTION(C_EUC_KR)},
460         {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
461          CODESET_ACTION(C_ISO_2022_KR)},
462 #endif
463
464 #undef CODESET_SEPARATOR
465 #undef CODESET_ACTION
466
467         {N_("/_Message"),                       NULL, NULL, 0, "<Branch>"},
468         {N_("/_Message/Get new ma_il"),         "<alt>I",       inc_mail_cb, 0, NULL},
469         {N_("/_Message/Get from _all accounts"),
470                                                 "<shift><alt>I", inc_all_account_mail_cb, 0, NULL},
471         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
472         {N_("/_Message/Send queued messa_ges"),
473                                                 NULL, send_queue_cb, 0, NULL},
474         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
475         {N_("/_Message/Compose _new message"),  "<alt>N",       compose_cb, 0, NULL},
476         {N_("/_Message/_Reply"),                "<alt>R",       reply_cb, COMPOSE_REPLY, NULL},
477         {N_("/_Message/Repl_y to sender"),      "<control><alt>R", reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
478         {N_("/_Message/Reply to a_ll"),         "<shift><alt>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
479         {N_("/_Message/_Forward"),              "<control>F", reply_cb, COMPOSE_FORWARD, NULL},
480         {N_("/_Message/Forward as a_ttachment"),
481                                                 "<shift><control>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
482         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
483         {N_("/_Message/M_ove..."),              "<alt>O", move_to_cb, 0, NULL},
484         {N_("/_Message/_Copy..."),              NULL, copy_to_cb, 0, NULL},
485         {N_("/_Message/_Delete"),               "<alt>D", delete_cb,  0, NULL},
486         {N_("/_Message/_Mark"),                 NULL, NULL, 0, "<Branch>"},
487         {N_("/_Message/_Mark/_Mark"),           NULL, mark_cb,   0, NULL},
488         {N_("/_Message/_Mark/_Unmark"),         NULL, unmark_cb, 0, NULL},
489         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
490         {N_("/_Message/_Mark/Mark as unr_ead"), NULL, mark_as_unread_cb, 0, NULL},
491         {N_("/_Message/_Mark/Mark as rea_d"),
492                                                 NULL, mark_as_read_cb, 0, NULL},
493         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
494         {N_("/_Message/Open in new _window"),   "<shift><control>N", open_msg_cb, 0, NULL},
495         {N_("/_Message/View _source"),          "<control>U", view_source_cb, 0, NULL},
496         {N_("/_Message/Show all _header"),      "<control>H", header_window_show_cb, 0, NULL},
497         {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
498
499         {N_("/_Summary"),                       NULL, NULL, 0, "<Branch>"},
500         {N_("/_Summary/_Delete duplicated messages"),
501                                                 NULL, delete_duplicated_cb,   0, NULL},
502         {N_("/_Summary/_Filter messages"),      NULL, filter_cb, 0, NULL},
503         {N_("/_Summary/E_xecute"),              "<alt>X", execute_summary_cb, 0, NULL},
504         {N_("/_Summary/_Update"),               "<alt>U", update_summary_cb,  0, NULL},
505         {N_("/_Summary/---"),                   NULL, NULL, 0, "<Separator>"},
506         {N_("/_Summary/_Prev message"),         NULL, prev_cb, 0, NULL},
507         {N_("/_Summary/_Next message"),         NULL, next_cb, 0, NULL},
508         {N_("/_Summary/N_ext unread message"),  NULL, next_unread_cb, 0, NULL},
509         {N_("/_Summary/Prev marked message"),   NULL, prev_marked_cb, 0, NULL},
510         {N_("/_Summary/Next marked message"),   NULL, next_marked_cb, 0, NULL},
511         {N_("/_Summary/---"),                   NULL, NULL, 0, "<Separator>"},
512         {N_("/_Summary/_Go to other folder"),   "<alt>G", goto_folder_cb, 0, NULL},
513         {N_("/_Summary/---"),                   NULL, NULL, 0, "<Separator>"},
514         {N_("/_Summary/_Sort"),                 NULL, NULL, 0, "<Branch>"},
515         {N_("/_Summary/_Sort/Sort by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, NULL},
516         {N_("/_Summary/_Sort/Sort by s_ize"),   NULL, sort_summary_cb, SORT_BY_SIZE, NULL},
517         {N_("/_Summary/_Sort/Sort by _date"),   NULL, sort_summary_cb, SORT_BY_DATE, NULL},
518         {N_("/_Summary/_Sort/Sort by _from"),   NULL, sort_summary_cb, SORT_BY_FROM, NULL},
519         {N_("/_Summary/_Sort/Sort by _subject"),NULL, sort_summary_cb, SORT_BY_SUBJECT, NULL},
520         {N_("/_Summary/_Sort/Sort by sco_re"),  NULL, sort_summary_cb, SORT_BY_SCORE, NULL},
521         {N_("/_Summary/_Sort/---"),             NULL, NULL, 0, "<Separator>"},
522         {N_("/_Summary/_Sort/_Attract by subject"),
523                                                 NULL, attract_by_subject_cb, 0, NULL},
524         {N_("/_Summary/_Thread view"),          "<control>T",        thread_cb, 0, NULL},
525         {N_("/_Summary/Unt_hread view"),        "<shift><control>T", thread_cb, 1, NULL},
526         {N_("/_Summary/Set display _item..."),  NULL, set_display_item_cb, 0, NULL},
527
528         {N_("/_Tool"),                          NULL, NULL, 0, "<Branch>"},
529         {N_("/_Tool/_Address book"),            "<alt>A", addressbook_open_cb, 0, NULL},
530         {N_("/_Tool/_Log window"),              "<alt>L", log_window_show_cb, 0, NULL},
531
532         {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
533         {N_("/_Configuration/_Common preferences..."),
534                                                 NULL, prefs_common_open_cb, 0, NULL},
535         {N_("/_Configuration/_Filter setting..."),
536                                                 NULL, prefs_filter_open_cb, 0, NULL},
537         {N_("/_Configuration/_Scoring ..."),
538                                                 NULL, prefs_scoring_open_cb, 0, NULL},
539         {N_("/_Configuration/_Filtering ..."),
540                                                 NULL, prefs_filtering_open_cb, 0, NULL},
541         {N_("/_Configuration/_Preferences per account..."),
542                                                 NULL, prefs_account_open_cb, 0, NULL},
543         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
544         {N_("/_Configuration/Create _new account..."),
545                                                 NULL, new_account_cb, 0, NULL},
546         {N_("/_Configuration/_Edit accounts..."),
547                                                 NULL, account_edit_open, 0, NULL},
548         {N_("/_Configuration/C_hange current account"),
549                                                 NULL, NULL, 0, "<Branch>"},
550
551         {N_("/_Help"),                          NULL, NULL, 0, "<LastBranch>"},
552         {N_("/_Help/_Manual"),                  NULL, NULL, 0, "<Branch>"},
553         {N_("/_Help/_Manual/_English"),         NULL, NULL, MANUAL_LANG_EN, NULL},
554         {N_("/_Help/_Manual/_Japanese"),        NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
555         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
556         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
557 };
558
559 MainWindow *main_window_create(SeparateType type)
560 {
561         MainWindow *mainwin;
562         GtkWidget *window;
563         GtkWidget *vbox;
564         GtkWidget *menubar;
565         GtkWidget *handlebox;
566         GtkWidget *vbox_body;
567         GtkWidget *hbox_stat;
568         GtkWidget *statusbar;
569         GtkWidget *ac_button;
570         GtkWidget *ac_label;
571
572         FolderView *folderview;
573         SummaryView *summaryview;
574         MessageView *messageview;
575         GdkColormap *colormap;
576         GdkColor color[5];
577         gboolean success[5];
578         guint n_menu_entries;
579         GtkItemFactory *ifactory;
580         GtkWidget *ac_menu;
581         GtkWidget *menuitem;
582         gint i;
583
584         debug_print(_("Creating main window...\n"));
585         mainwin = g_new0(MainWindow, 1);
586
587         /* main window */
588         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
589         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
590         gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
591         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
592                            GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
593         gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
594                            GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
595         gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
596                            GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
597         gtk_widget_realize(window);
598
599         vbox = gtk_vbox_new(FALSE, 0);
600         gtk_widget_show(vbox);
601         gtk_container_add(GTK_CONTAINER(window), vbox);
602
603         /* menu bar */
604         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
605         menubar = menubar_create(window, mainwin_entries, 
606                                  n_menu_entries, "<Main>", mainwin);
607         gtk_widget_show(menubar);
608         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
609
610         handlebox = gtk_handle_box_new();
611         gtk_widget_show(handlebox);
612         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
613
614         main_window_toolbar_create(mainwin, handlebox);
615
616         /* vbox that contains body */
617         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
618         gtk_widget_show(vbox_body);
619         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
620         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
621
622         hbox_stat = gtk_hbox_new(FALSE, 2);
623         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
624
625         statusbar = statusbar_create();
626         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
627
628         ac_button = gtk_button_new();
629         gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
630         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
631         gtk_widget_set_usize(ac_button, -1, 1);
632         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
633         gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
634                            GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
635
636         ac_label = gtk_label_new("");
637         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
638
639         gtk_widget_show_all(hbox_stat);
640
641         /* create views */
642         mainwin->folderview  = folderview  = folderview_create();
643         mainwin->summaryview = summaryview = summary_create();
644         mainwin->messageview = messageview = messageview_create();
645         mainwin->headerwin   = header_window_create();
646         mainwin->logwin      = log_window_create();
647
648         folderview->mainwin      = mainwin;
649         folderview->summaryview  = summaryview;
650
651         summaryview->mainwin     = mainwin;
652         summaryview->folderview  = folderview;
653         summaryview->messageview = messageview;
654         summaryview->headerwin   = mainwin->headerwin;
655         summaryview->window      = window;
656
657         messageview->mainwin     = mainwin;
658
659         mainwin->window    = window;
660         mainwin->vbox      = vbox;
661         mainwin->menubar   = menubar;
662         mainwin->handlebox = handlebox;
663         mainwin->vbox_body = vbox_body;
664         mainwin->hbox_stat = hbox_stat;
665         mainwin->statusbar = statusbar;
666         mainwin->ac_button = ac_button;
667         mainwin->ac_label  = ac_label;
668
669         /* set context IDs for status bar */
670         mainwin->mainwin_cid = gtk_statusbar_get_context_id
671                 (GTK_STATUSBAR(statusbar), "Main Window");
672         mainwin->folderview_cid = gtk_statusbar_get_context_id
673                 (GTK_STATUSBAR(statusbar), "Folder View");
674         mainwin->summaryview_cid = gtk_statusbar_get_context_id
675                 (GTK_STATUSBAR(statusbar), "Summary View");
676
677         /* allocate colors for summary view and folder view */
678         summaryview->color_marked.red = summaryview->color_marked.green = 0;
679         summaryview->color_marked.blue = (guint16)65535;
680
681         summaryview->color_dim.red = summaryview->color_dim.green =
682                 summaryview->color_dim.blue = COLOR_DIM;
683
684         summaryview->color_normal.red = summaryview->color_normal.green =
685                 summaryview->color_normal.blue = 0;
686
687         folderview->color_new.red = (guint16)55000;
688         folderview->color_new.green = folderview->color_new.blue = 15000;
689
690         folderview->color_normal.red = folderview->color_normal.green =
691                 folderview->color_normal.blue = 0;
692
693         summaryview->color_important.red = 0;
694         summaryview->color_marked.green = 0;
695         summaryview->color_important.blue = (guint16)65535;
696
697         color[0] = summaryview->color_marked;
698         color[1] = summaryview->color_dim;
699         color[2] = summaryview->color_normal;
700         color[3] = folderview->color_new;
701         color[4] = folderview->color_normal;
702
703         colormap = gdk_window_get_colormap(window->window);
704         gdk_colormap_alloc_colors(colormap, color, 5, FALSE, TRUE, success);
705         for (i = 0; i < 5; i++) {
706                 if (success[i] == FALSE)
707                         g_warning(_("MainWindow: color allocation %d failed\n"), i);
708         }
709
710         debug_print(_("done.\n"));
711
712         main_window_set_widgets(mainwin, type);
713
714         /* set menu items */
715         ifactory = gtk_item_factory_from_widget(menubar);
716         menuitem = gtk_item_factory_get_item
717                 (ifactory, "/View/Code set/Auto detect");
718         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
719
720         switch (prefs_common.toolbar_style) {
721         case TOOLBAR_NONE:
722                 menuitem = gtk_item_factory_get_item
723                         (ifactory, "/View/Toolbar/None");
724                 break;
725         case TOOLBAR_ICON:
726                 menuitem = gtk_item_factory_get_item
727                         (ifactory, "/View/Toolbar/Icon");
728                 break;
729         case TOOLBAR_TEXT:
730                 menuitem = gtk_item_factory_get_item
731                         (ifactory, "/View/Toolbar/Text");
732                 break;
733         case TOOLBAR_BOTH:
734                 menuitem = gtk_item_factory_get_item
735                         (ifactory, "/View/Toolbar/Icon and text");
736         }
737         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
738
739         gtk_widget_hide(mainwin->hbox_stat);
740         menuitem = gtk_item_factory_get_item(ifactory, "/View/Status bar");
741         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
742                                        prefs_common.show_statusbar);
743
744         /* set the check of the SEPARATE_xxx menu items. we also need the main window
745          * as a property and pass the action type to the callback */
746         menuitem = gtk_item_factory_get_widget_by_action(ifactory, SEPARATE_ACTION + SEPARATE_FOLDER);
747         g_assert(menuitem);
748         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), type & SEPARATE_FOLDER);
749         gtk_object_set_data(GTK_OBJECT(menuitem), "mainwindow", mainwin);
750         gtk_signal_connect(GTK_OBJECT(menuitem), "toggled", GTK_SIGNAL_FUNC(separate_widget_cb), 
751                                            GUINT_TO_POINTER(SEPARATE_FOLDER));
752
753         menuitem = gtk_item_factory_get_widget_by_action(ifactory, SEPARATE_ACTION + SEPARATE_MESSAGE);
754         g_assert(menuitem);
755         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), type & SEPARATE_MESSAGE);
756         gtk_object_set_data(GTK_OBJECT(menuitem), "mainwindow", mainwin);
757         gtk_signal_connect(GTK_OBJECT(menuitem), "toggled", GTK_SIGNAL_FUNC(separate_widget_cb), 
758                                            GUINT_TO_POINTER(SEPARATE_MESSAGE));
759
760         /*
761         menu_set_sensitive(ifactory, "/Summary/Thread view",
762                            prefs_common.enable_thread ? FALSE : TRUE);
763         menu_set_sensitive(ifactory, "/Summary/Unthread view",
764                            prefs_common.enable_thread ? TRUE : FALSE);
765         */
766         main_window_set_thread_option(mainwin);
767
768         menu_set_sensitive(ifactory, "/Help/Manual/English", FALSE);
769
770         /* set account selection menu */
771         ac_menu = gtk_item_factory_get_widget
772                 (ifactory, "/Configuration/Change current account");
773         mainwin->ac_menu = ac_menu;
774
775         main_window_set_toolbar_sensitive(mainwin, FALSE);
776
777         /* show main window */
778         gtk_widget_set_uposition(mainwin->window,
779                                  prefs_common.mainwin_x,
780                                  prefs_common.mainwin_y);
781         gtk_widget_set_usize(window, prefs_common.mainwin_width,
782                              prefs_common.mainwin_height);
783         gtk_widget_show(mainwin->window);
784
785         /* initialize views */
786         folderview_init(folderview);
787         summary_init(summaryview);
788         messageview_init(messageview);
789         header_window_init(mainwin->headerwin);
790         log_window_init(mainwin->logwin);
791
792         mainwin->cursor_count = 0;
793
794         if (!watch_cursor)
795                 watch_cursor = gdk_cursor_new(GDK_WATCH);
796
797         mainwin_list = g_list_append(mainwin_list, mainwin);
798
799         return mainwin;
800 }
801
802 void main_window_cursor_wait(MainWindow *mainwin)
803 {
804         if (mainwin->cursor_count == 0)
805                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
806
807         mainwin->cursor_count++;
808
809         gdk_flush();
810 }
811
812 void main_window_cursor_normal(MainWindow *mainwin)
813 {
814         if (mainwin->cursor_count)
815                 mainwin->cursor_count--;
816
817         if (mainwin->cursor_count == 0)
818                 gdk_window_set_cursor(mainwin->window->window, NULL);
819
820         gdk_flush();
821 }
822
823 void main_window_reflect_prefs_all(void)
824 {
825         GList *cur;
826         MainWindow *mainwin;
827
828         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
829                 mainwin = (MainWindow *)cur->data;
830
831                 main_window_show_cur_account(mainwin);
832                 if (cur_account) {
833                         gtk_widget_set_sensitive(mainwin->get_btn,    TRUE);
834                         gtk_widget_set_sensitive(mainwin->getall_btn, TRUE);
835                 } else {
836                         gtk_widget_set_sensitive(mainwin->get_btn,    FALSE);
837                         gtk_widget_set_sensitive(mainwin->getall_btn, FALSE);
838                 }
839
840                 if (prefs_common.immediate_exec)
841                         gtk_widget_hide(mainwin->exec_btn);
842                 else
843                         gtk_widget_show(mainwin->exec_btn);
844
845                 summary_change_display_item(mainwin->summaryview);
846                 summary_redisplay_msg(mainwin->summaryview);
847                 headerview_set_visibility(mainwin->messageview->headerview,
848                                           prefs_common.display_header_pane);
849         }
850 }
851
852 void main_window_set_account_menu(GList *account_list)
853 {
854         GList *cur, *cur_ac, *cur_item;
855         GtkWidget *menuitem;
856         MainWindow *mainwin;
857         PrefsAccount *ac_prefs;
858
859         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
860                 mainwin = (MainWindow *)cur->data;
861
862                 /* destroy all previous menu item */
863                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
864                 while (cur_item != NULL) {
865                         GList *next = cur_item->next;
866                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
867                         cur_item = next;
868                 }
869
870                 for (cur_ac = account_list; cur_ac != NULL;
871                      cur_ac = cur_ac->next) {
872                         ac_prefs = (PrefsAccount *)cur_ac->data;
873
874                         menuitem = gtk_menu_item_new_with_label
875                                 (ac_prefs->account_name
876                                  ? ac_prefs->account_name : _("Untitled"));
877                         gtk_widget_show(menuitem);
878                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
879                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
880                                            GTK_SIGNAL_FUNC(account_menu_cb),
881                                            ac_prefs);
882                 }
883         }
884 }
885
886 static void main_window_show_cur_account(MainWindow *mainwin)
887 {
888         gchar *buf;
889         gchar *ac_name;
890
891         ac_name = g_strdup(cur_account
892                            ? (cur_account->account_name
893                               ? cur_account->account_name : _("Untitled"))
894                            : _("none"));
895
896         if (cur_account)
897                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
898         else
899                 buf = g_strdup(PROG_VERSION);
900         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
901         g_free(buf);
902
903         buf = g_strdup_printf(_("Current account: %s"), ac_name);
904         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), buf);
905         gtk_widget_queue_resize(mainwin->ac_button);
906         g_free(buf);
907
908         g_free(ac_name);
909 }
910
911 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
912 {
913         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
914         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
915         GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
916
917         if (mainwin->type == type) return;
918
919         /* remove widgets from those containers */
920         gtk_widget_ref(folder_wid);
921         gtk_widget_ref(summary_wid);
922         gtk_widget_ref(message_wid);
923         gtk_container_remove
924                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
925         gtk_container_remove
926                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
927         gtk_container_remove
928                 (GTK_CONTAINER(message_wid->parent), message_wid);
929
930         /* clean containers */
931         switch (mainwin->type) {
932         case SEPARATE_NONE:
933                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
934                 break;
935         case SEPARATE_FOLDER:
936                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
937                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
938                 break;
939         case SEPARATE_MESSAGE:
940                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
941                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
942                 break;
943         case SEPARATE_BOTH:
944                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
945                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
946                 break;
947         }
948
949         gtk_widget_hide(mainwin->window);
950         main_window_set_widgets(mainwin, type);
951         gtk_widget_show(mainwin->window);
952
953         gtk_widget_unref(folder_wid);
954         gtk_widget_unref(summary_wid);
955         gtk_widget_unref(message_wid);
956 }
957
958 void main_window_get_size(MainWindow *mainwin)
959 {
960         GtkAllocation *allocation;
961
962         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
963
964         prefs_common.summaryview_width  = allocation->width;
965
966         if (mainwin->summaryview->msg_is_toggled_on)
967                 prefs_common.summaryview_height = allocation->height;
968
969         prefs_common.mainview_width     = allocation->width;
970
971         allocation = &mainwin->window->allocation;
972
973         prefs_common.mainview_height = allocation->height;
974         prefs_common.mainwin_width   = allocation->width;
975         prefs_common.mainwin_height  = allocation->height;
976
977         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
978
979         prefs_common.folderview_width  = allocation->width;
980         prefs_common.folderview_height = allocation->height;
981 }
982
983 void main_window_get_position(MainWindow *mainwin)
984 {
985         gint x, y;
986
987         gtkut_widget_get_uposition(mainwin->window, &x, &y);
988
989         prefs_common.mainview_x = x;
990         prefs_common.mainview_y = y;
991         prefs_common.mainwin_x = x;
992         prefs_common.mainwin_y = y;
993
994         debug_print(_("window position: x = %d, y = %d\n"), x, y);
995 }
996
997 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
998 {
999         GList *list;
1000
1001         if (confirm) {
1002                 if (alertpanel(_("Empty trash"),
1003                                _("Empty all messages in trash?"),
1004                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1005                         return;
1006                 manage_window_focus_in(mainwin->window, NULL, NULL);
1007         }
1008
1009         procmsg_empty_trash();
1010
1011         for (list = folder_get_list(); list != NULL; list = list->next) {
1012                 Folder *folder;
1013
1014                 folder = list->data;
1015                 if (folder->trash) {
1016                         folder_item_scan(folder->trash);
1017                         folderview_update_item(folder->trash, TRUE);
1018                 }
1019         }
1020
1021         if (mainwin->summaryview->folder_item &&
1022             mainwin->summaryview->folder_item->stype == F_TRASH)
1023                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1024 }
1025
1026 void main_window_add_mailbox(MainWindow *mainwin)
1027 {
1028         gchar *path;
1029         Folder *folder;
1030
1031         path = input_dialog(_("Add mailbox"),
1032                             _("Input the location of mailbox.\n"
1033                               "If the existing mailbox is specified, it will be\n"
1034                               "scanned automatically."),
1035                             "Mail");
1036         if (!path) return;
1037         if (folder_find_from_path(path)) {
1038                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1039                 g_free(path);
1040                 return;
1041         }
1042
1043         if (!strcmp(path, "Mail"))
1044                 folder = folder_new(F_MH, _("Mailbox"), path);
1045         else
1046                 folder = folder_new(F_MH, g_basename(path), path);
1047
1048         g_free(path);
1049
1050         if (folder->create_tree(folder) < 0) {
1051                 alertpanel_error(_("Creation of the mailbox failed.\n"
1052                                    "Maybe some files already exist, or you don't have the permission to write there."));
1053                 folder_destroy(folder);
1054                 return;
1055         }
1056
1057         folder_add(folder);
1058         folder_set_ui_func(folder, scan_tree_func, mainwin);
1059         folder->scan_tree(folder);
1060         folder_set_ui_func(folder, NULL, NULL);
1061
1062         folderview_set(mainwin->folderview);
1063 }
1064
1065 void main_window_add_mbox(MainWindow *mainwin)
1066 {
1067         gchar *path;
1068         Folder *folder;
1069         FolderItem * item;
1070
1071         path = input_dialog(_("Add mbox mailbox"),
1072                             _("Input the location of mailbox."),
1073                             "mail");
1074
1075         if (!path) return;
1076
1077         if (folder_find_from_path(path)) {
1078                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1079                 g_free(path);
1080                 return;
1081         }
1082
1083         /*
1084         if (!strcmp(path, "Mail"))
1085                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1086                 else
1087         */
1088
1089         folder = folder_new(F_MBOX, g_basename(path), path);
1090         g_free(path);
1091
1092         if (folder->create_tree(folder) < 0) {
1093                 alertpanel_error(_("Creation of the mailbox failed."));
1094                 folder_destroy(folder);
1095                 return;
1096         }
1097
1098         folder_add(folder);
1099
1100         item = folder_item_new(folder->name, NULL);
1101         item->folder = folder;
1102         folder->node = g_node_new(item);
1103
1104         folder->create_folder(folder, item, "inbox");
1105         folder->create_folder(folder, item, "outbox");
1106         folder->create_folder(folder, item, "queue");
1107         folder->create_folder(folder, item, "draft");
1108         folder->create_folder(folder, item, "trash");
1109
1110         folderview_set(mainwin->folderview);
1111 }
1112
1113 void main_window_set_toolbar_sensitive(MainWindow *mainwin, gboolean sensitive)
1114 {
1115         gtk_widget_set_sensitive(mainwin->reply_btn,       sensitive);
1116         gtk_widget_set_sensitive(mainwin->replyall_btn,    sensitive);
1117         gtk_widget_set_sensitive(mainwin->replysender_btn, sensitive);
1118         gtk_widget_set_sensitive(mainwin->fwd_btn,         sensitive);
1119         gtk_widget_set_sensitive(mainwin->exec_btn,        sensitive);
1120         gtk_widget_set_sensitive(mainwin->next_btn,        sensitive);
1121
1122         if (!mainwin->summaryview->folder_item ||
1123             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1124                 gtk_widget_set_sensitive(mainwin->delete_btn, FALSE);
1125         else
1126                 gtk_widget_set_sensitive(mainwin->delete_btn, sensitive);
1127 }
1128
1129 void main_window_set_menu_sensitive(MainWindow *mainwin, gint selection)
1130 {
1131         GtkItemFactory *ifactory;
1132         gboolean sens;
1133         gboolean exec;
1134
1135         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1136
1137         if (selection == SUMMARY_SELECTED_SINGLE)
1138                 sens = TRUE;
1139         else
1140                 sens = FALSE;
1141         if (!mainwin->summaryview->folder_item ||
1142             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1143                 exec = FALSE;
1144         else
1145                 exec = TRUE;
1146
1147         menu_set_sensitive(ifactory, "/File/Save as...", sens);
1148         menu_set_sensitive(ifactory, "/Message/Reply", sens);
1149         menu_set_sensitive(ifactory, "/Message/Reply to sender", sens);
1150         menu_set_sensitive(ifactory, "/Message/Reply to all", sens);
1151         menu_set_sensitive(ifactory, "/Message/Forward", sens);
1152         menu_set_sensitive(ifactory, "/Message/Forward as attachment", sens);
1153         menu_set_sensitive(ifactory, "/Message/Open in new window", sens);
1154         menu_set_sensitive(ifactory, "/Message/Show all header", sens);
1155         menu_set_sensitive(ifactory, "/Message/View source", sens);
1156         if (sens && (!mainwin->summaryview->folder_item ||
1157                      mainwin->summaryview->folder_item->stype != F_DRAFT))
1158                 sens = FALSE;
1159         menu_set_sensitive(ifactory, "/Message/Re-edit", sens);
1160
1161         if (selection == SUMMARY_SELECTED_SINGLE ||
1162             selection == SUMMARY_SELECTED_MULTIPLE)
1163                 sens = TRUE;
1164         else
1165                 sens = FALSE;
1166
1167         menu_set_sensitive(ifactory, "/File/Print..."  , sens);
1168         menu_set_sensitive(ifactory, "/Message/Move...", sens && exec);
1169         menu_set_sensitive(ifactory, "/Message/Copy...", sens && exec);
1170         menu_set_sensitive(ifactory, "/Message/Delete" , sens && exec);
1171         menu_set_sensitive(ifactory, "/Message/Mark"   , sens);
1172
1173         if (selection != SUMMARY_NONE)
1174                 sens = TRUE;
1175         else
1176                 sens = FALSE;
1177
1178         menu_set_sensitive(ifactory, "/Summary/Delete duplicated messages", sens && exec);
1179         menu_set_sensitive(ifactory, "/Summary/Filter messages", sens && exec);
1180         menu_set_sensitive(ifactory, "/Summary/Execute", sens);
1181         menu_set_sensitive(ifactory, "/Summary/Prev message", sens);
1182         menu_set_sensitive(ifactory, "/Summary/Next message", sens);
1183         menu_set_sensitive(ifactory, "/Summary/Next unread message", sens);
1184         menu_set_sensitive(ifactory, "/Summary/Sort", sens);
1185 }
1186
1187 void main_window_popup(MainWindow *mainwin)
1188 {
1189         gint x, y;
1190         gint sx, sy;
1191         GtkWidget *widget;
1192
1193         gdk_window_get_origin(mainwin->window->window, &x, &y);
1194         sx = gdk_screen_width();
1195         sy = gdk_screen_height();
1196         x %= sx; if (x < 0) x += sx;
1197         y %= sy; if (y < 0) y += sy;
1198         gdk_window_move(mainwin->window->window, x, y);
1199         gdk_window_raise(mainwin->window->window);
1200
1201         debug_print("window position: x = %d, y = %d\n", x, y);
1202
1203         switch (mainwin->type) {
1204         case SEPARATE_FOLDER:
1205                 widget = mainwin->win.sep_folder.folderwin;
1206                 gdk_window_get_origin(widget->window, &x, &y);
1207                 x %= sx; if (x < 0) x += sx;
1208                 y %= sy; if (y < 0) y += sy;
1209                 gdk_window_move(widget->window, x, y);
1210                 gdk_window_raise(widget->window);
1211                 break;
1212         case SEPARATE_MESSAGE:
1213                 widget = mainwin->win.sep_message.messagewin;
1214                 gdk_window_get_origin(widget->window, &x, &y);
1215                 x %= sx; if (x < 0) x += sx;
1216                 y %= sy; if (y < 0) y += sy;
1217                 gdk_window_move(widget->window, x, y);
1218                 gdk_window_raise(widget->window);
1219                 break;
1220         case SEPARATE_BOTH:
1221                 widget = mainwin->win.sep_both.folderwin;
1222                 gdk_window_get_origin(widget->window, &x, &y);
1223                 x %= sx; if (x < 0) x += sx;
1224                 y %= sy; if (y < 0) y += sy;
1225                 gdk_window_move(widget->window, x, y);
1226                 gdk_window_raise(widget->window);
1227                 widget = mainwin->win.sep_both.messagewin;
1228                 gdk_window_get_origin(widget->window, &x, &y);
1229                 x %= sx; if (x < 0) x += sx;
1230                 y %= sy; if (y < 0) y += sy;
1231                 gdk_window_move(widget->window, x, y);
1232                 gdk_window_raise(widget->window);
1233                 break;
1234         default:
1235         }
1236 }
1237
1238 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1239 {
1240         GtkWidget *folderwin = NULL;
1241         GtkWidget *messagewin = NULL;
1242         GtkWidget *hpaned;
1243         GtkWidget *vpaned;
1244         GtkWidget *vbox_body = mainwin->vbox_body;
1245
1246         debug_print(_("Setting widgets..."));
1247
1248         /* create separated window(s) if needed */
1249         if (type & SEPARATE_FOLDER) {
1250                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1251                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1252                                       TRUE, TRUE, FALSE);
1253                 gtk_widget_set_usize(folderwin, -1,
1254                                      prefs_common.mainview_height);
1255                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1256                                                BORDER_WIDTH);
1257                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1258                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1259                                    NULL);
1260         }
1261         if (type & SEPARATE_MESSAGE) {
1262                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1263                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1264                                       TRUE, TRUE, FALSE);
1265                 gtk_widget_set_usize
1266                         (messagewin, prefs_common.mainview_width,
1267                          prefs_common.mainview_height
1268                          - prefs_common.summaryview_height
1269                          + DEFAULT_HEADERVIEW_HEIGHT);
1270                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1271                                                BORDER_WIDTH);
1272                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1273                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1274                                    NULL);
1275         }
1276
1277         switch (type) {
1278         case SEPARATE_NONE:
1279                 hpaned = gtk_hpaned_new();
1280                 gtk_widget_show(hpaned);
1281                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1282                 gtk_paned_add1(GTK_PANED(hpaned),
1283                                GTK_WIDGET_PTR(mainwin->folderview));
1284
1285                 vpaned = gtk_vpaned_new();
1286                 if (mainwin->summaryview->msg_is_toggled_on) {
1287                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1288                         gtk_paned_add1(GTK_PANED(vpaned),
1289                                        GTK_WIDGET_PTR(mainwin->summaryview));
1290                 } else {
1291                         gtk_paned_add2(GTK_PANED(hpaned),
1292                                        GTK_WIDGET_PTR(mainwin->summaryview));
1293                         gtk_widget_ref(vpaned);
1294                 }
1295                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1296                                      prefs_common.summaryview_width,
1297                                      prefs_common.summaryview_height);
1298                 gtk_paned_add2(GTK_PANED(vpaned),
1299                                GTK_WIDGET_PTR(mainwin->messageview));
1300                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1301                                      prefs_common.mainview_width, -1);
1302                 gtk_widget_set_usize(mainwin->window,
1303                                      prefs_common.folderview_width +
1304                                      prefs_common.mainview_width,
1305                                      prefs_common.mainwin_height);
1306                 gtk_widget_show_all(vpaned);
1307
1308                 mainwin->win.sep_none.hpaned = hpaned;
1309                 mainwin->win.sep_none.vpaned = vpaned;
1310                 break;
1311         case SEPARATE_FOLDER:
1312                 vpaned = gtk_vpaned_new();
1313                 if (mainwin->summaryview->msg_is_toggled_on) {
1314                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1315                                            TRUE, TRUE, 0);
1316                         gtk_paned_add1(GTK_PANED(vpaned),
1317                                        GTK_WIDGET_PTR(mainwin->summaryview));
1318                 } else {
1319                         gtk_box_pack_start(GTK_BOX(vbox_body),
1320                                            GTK_WIDGET_PTR(mainwin->summaryview),
1321                                            TRUE, TRUE, 0);
1322                         gtk_widget_ref(vpaned);
1323                 }
1324                 gtk_paned_add2(GTK_PANED(vpaned),
1325                                GTK_WIDGET_PTR(mainwin->messageview));
1326                 gtk_widget_show_all(vpaned);
1327                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1328                                      prefs_common.summaryview_width,
1329                                      prefs_common.summaryview_height);
1330                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1331                                      prefs_common.mainview_width, -1);
1332                 gtk_widget_set_usize(mainwin->window,
1333                                      prefs_common.mainview_width,
1334                                      prefs_common.mainview_height);
1335
1336                 gtk_container_add(GTK_CONTAINER(folderwin),
1337                                   GTK_WIDGET_PTR(mainwin->folderview));
1338
1339                 mainwin->win.sep_folder.folderwin = folderwin;
1340                 mainwin->win.sep_folder.vpaned    = vpaned;
1341
1342                 gtk_widget_show_all(folderwin);
1343                 break;
1344         case SEPARATE_MESSAGE:
1345                 hpaned = gtk_hpaned_new();
1346                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1347
1348                 gtk_paned_add1(GTK_PANED(hpaned),
1349                                GTK_WIDGET_PTR(mainwin->folderview));
1350                 gtk_paned_add2(GTK_PANED(hpaned),
1351                                GTK_WIDGET_PTR(mainwin->summaryview));
1352                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1353                                      prefs_common.summaryview_width,
1354                                      prefs_common.summaryview_height);
1355                 gtk_widget_set_usize(mainwin->window,
1356                                      prefs_common.folderview_width +
1357                                      prefs_common.mainview_width,
1358                                      prefs_common.mainwin_height);
1359                 gtk_widget_show_all(hpaned);
1360                 gtk_container_add(GTK_CONTAINER(messagewin),
1361                                   GTK_WIDGET_PTR(mainwin->messageview));
1362
1363                 mainwin->win.sep_message.messagewin = messagewin;
1364                 mainwin->win.sep_message.hpaned     = hpaned;
1365
1366                 gtk_widget_show_all(messagewin);
1367                 break;
1368         case SEPARATE_BOTH:
1369                 gtk_box_pack_start(GTK_BOX(vbox_body),
1370                                    GTK_WIDGET_PTR(mainwin->summaryview),
1371                                    TRUE, TRUE, 0);
1372                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1373                                      prefs_common.summaryview_width,
1374                                      prefs_common.summaryview_height);
1375                 gtk_widget_set_usize(mainwin->window,
1376                                      prefs_common.mainview_width,
1377                                      prefs_common.mainwin_height);
1378                 gtk_container_add(GTK_CONTAINER(folderwin),
1379                                   GTK_WIDGET_PTR(mainwin->folderview));
1380                 gtk_container_add(GTK_CONTAINER(messagewin),
1381                                   GTK_WIDGET_PTR(mainwin->messageview));
1382
1383                 mainwin->win.sep_both.folderwin = folderwin;
1384                 mainwin->win.sep_both.messagewin = messagewin;
1385
1386                 gtk_widget_show_all(folderwin);
1387                 gtk_widget_show_all(messagewin);
1388                 break;
1389         }
1390
1391         mainwin->type = type;
1392
1393         debug_print(_("done.\n"));
1394 }
1395
1396 #include "pixmaps/stock_mail_receive.xpm"
1397 #include "pixmaps/stock_mail_receive_all.xpm"
1398 #include "pixmaps/stock_mail_compose.xpm"
1399 #include "pixmaps/stock_mail_reply.xpm"
1400 #include "pixmaps/stock_mail_reply_to_all.xpm"
1401 #include "pixmaps/stock_mail_reply_to_author.xpm"
1402 #include "pixmaps/stock_mail_forward.xpm"
1403 #include "pixmaps/stock_mail_send.xpm"
1404 #include "pixmaps/stock_preferences.xpm"
1405 #include "pixmaps/stock_properties.xpm"
1406 #include "pixmaps/stock_down_arrow.xpm"
1407 #include "pixmaps/stock_close.xpm"
1408 #include "pixmaps/stock_exec.xpm"
1409
1410 #define CREATE_TOOLBAR_ICON(xpm_d) \
1411 { \
1412         icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1413                                             &container->style->white, \
1414                                             xpm_d); \
1415         icon_wid = gtk_pixmap_new(icon, mask); \
1416 }
1417
1418 static void main_window_toolbar_create(MainWindow *mainwin,
1419                                        GtkWidget *container)
1420 {
1421         GtkWidget *toolbar;
1422         GdkPixmap *icon;
1423         GdkBitmap *mask;
1424         GtkWidget *icon_wid;
1425         GtkWidget *get_btn;
1426         GtkWidget *getall_btn;
1427         GtkWidget *compose_btn;
1428         GtkWidget *reply_btn;
1429         GtkWidget *replyall_btn;
1430         GtkWidget *replysender_btn;
1431         GtkWidget *fwd_btn;
1432         GtkWidget *send_btn;
1433         /*
1434         GtkWidget *prefs_btn;
1435         GtkWidget *account_btn;
1436         */
1437         GtkWidget *next_btn;
1438         GtkWidget *delete_btn;
1439         GtkWidget *exec_btn;
1440
1441         toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1442                                   GTK_TOOLBAR_BOTH);
1443         gtk_container_add(GTK_CONTAINER(container), toolbar);
1444         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1445         gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1446         gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1447                                     GTK_TOOLBAR_SPACE_LINE);
1448
1449         CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1450         get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1451                                           _("Get"),
1452                                           _("Incorporate new mail"),
1453                                           "Get",
1454                                           icon_wid, toolbar_inc_cb, mainwin);
1455         CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1456         getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1457                                              _("Get all"),
1458                                              _("Incorporate new mail of all accounts"),
1459                                              "Get all",
1460                                              icon_wid,
1461                                              toolbar_inc_all_cb,
1462                                              mainwin);
1463
1464         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1465
1466         CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1467         send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1468                                            _("Send"),
1469                                            _("Send queued message(s)"),
1470                                            "Send",
1471                                            icon_wid,
1472                                            toolbar_send_cb,
1473                                            mainwin);
1474
1475         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1476
1477         CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1478         compose_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1479                                               _("Compose"),
1480                                               _("Compose new message"),
1481                                               "New",
1482                                               icon_wid,
1483                                               toolbar_compose_cb,
1484                                               mainwin);
1485         CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1486         reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1487                                             _("Reply"),
1488                                             _("Reply to the message"),
1489                                             "Reply",
1490                                             icon_wid,
1491                                             toolbar_reply_cb,
1492                                             mainwin);
1493         CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1494         replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1495                                                _("Reply all"),
1496                                                _("Reply to all"),
1497                                                "Reply to all",
1498                                                icon_wid,
1499                                                toolbar_reply_to_all_cb,
1500                                                mainwin);
1501         CREATE_TOOLBAR_ICON(stock_mail_reply_to_author_xpm);
1502         replysender_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1503                                                   _("Reply sender"),
1504                                                   _("Reply to sender"),
1505                                                   "Reply to sender",
1506                                                   icon_wid,
1507                                                   toolbar_reply_to_sender_cb,
1508                                                   mainwin);
1509         CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1510         fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1511                                           _("Forward"),
1512                                           _("Forward the message"),
1513                                           "Fwd",
1514                                           icon_wid,
1515                                           toolbar_forward_cb,
1516                                           mainwin);
1517
1518         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1519
1520         CREATE_TOOLBAR_ICON(stock_close_xpm);
1521         delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1522                                           _("Delete"),
1523                                           _("Delete the message"),
1524                                           "Delete",
1525                                           icon_wid,
1526                                           toolbar_delete_cb,
1527                                           mainwin);
1528
1529         CREATE_TOOLBAR_ICON(stock_exec_xpm);
1530         exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1531                                            _("Execute"),
1532                                            _("Execute marked process"),
1533                                            "Execute",
1534                                            icon_wid,
1535                                            toolbar_exec_cb,
1536                                            mainwin);
1537
1538         CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1539         next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1540                                            _("Next"),
1541                                            _("Next unread message"),
1542                                            "Next unread",
1543                                            icon_wid,
1544                                            toolbar_next_unread_cb,
1545                                            mainwin);
1546
1547         /*
1548         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1549
1550         CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1551         prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1552                                             _("Prefs"),
1553                                             _("Common preference"),
1554                                             "Prefs",
1555                                             icon_wid,
1556                                             toolbar_prefs_cb,
1557                                             mainwin);
1558         CREATE_TOOLBAR_ICON(stock_properties_xpm);
1559         account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1560                                               _("Account"),
1561                                               _("Account setting"),
1562                                               "Account",
1563                                               icon_wid,
1564                                               toolbar_account_cb,
1565                                               mainwin);
1566         gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1567                            GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1568                            mainwin);
1569         */
1570
1571         mainwin->toolbar         = toolbar;
1572         mainwin->get_btn         = get_btn;
1573         mainwin->getall_btn      = getall_btn;
1574         mainwin->compose_btn     = compose_btn;
1575         mainwin->reply_btn       = reply_btn;
1576         mainwin->replyall_btn    = replyall_btn;
1577         mainwin->replysender_btn = replysender_btn;
1578         mainwin->fwd_btn         = fwd_btn;
1579         mainwin->send_btn        = send_btn;
1580         /*
1581         mainwin->prefs_btn       = prefs_btn;
1582         mainwin->account_btn     = account_btn;
1583         */
1584         mainwin->next_btn        = next_btn;
1585         mainwin->delete_btn      = delete_btn;
1586         mainwin->exec_btn        = exec_btn;
1587
1588         gtk_widget_show_all(toolbar);
1589 }
1590
1591 /* callback functions */
1592
1593 static void toolbar_inc_cb      (GtkWidget      *widget,
1594                                  gpointer        data)
1595 {
1596         MainWindow *mainwin = (MainWindow *)data;
1597
1598         inc_mail_cb(mainwin, 0, NULL);
1599 }
1600
1601 static void toolbar_inc_all_cb  (GtkWidget      *widget,
1602                                  gpointer        data)
1603 {
1604         MainWindow *mainwin = (MainWindow *)data;
1605
1606         inc_all_account_mail_cb(mainwin, 0, NULL);
1607 }
1608
1609 static void toolbar_send_cb     (GtkWidget      *widget,
1610                                  gpointer        data)
1611 {
1612         MainWindow *mainwin = (MainWindow *)data;
1613
1614         send_queue_cb(mainwin, 0, NULL);
1615 }
1616
1617 static void toolbar_compose_cb  (GtkWidget      *widget,
1618                                  gpointer        data)
1619 {
1620         MainWindow *mainwin = (MainWindow *)data;
1621
1622         compose_cb(mainwin, 0, NULL);
1623 }
1624
1625 static void toolbar_reply_cb    (GtkWidget      *widget,
1626                                  gpointer        data)
1627 {
1628         MainWindow *mainwin = (MainWindow *)data;
1629
1630         reply_cb(mainwin, COMPOSE_REPLY, NULL);
1631 }
1632
1633 static void toolbar_reply_to_all_cb     (GtkWidget      *widget,
1634                                          gpointer        data)
1635 {
1636         MainWindow *mainwin = (MainWindow *)data;
1637
1638         reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
1639 }
1640
1641 static void toolbar_reply_to_sender_cb  (GtkWidget      *widget,
1642                                          gpointer        data)
1643 {
1644         MainWindow *mainwin = (MainWindow *)data;
1645
1646         reply_cb(mainwin, COMPOSE_REPLY_TO_SENDER, NULL);
1647 }
1648
1649 static void toolbar_forward_cb  (GtkWidget      *widget,
1650                                  gpointer        data)
1651 {
1652         MainWindow *mainwin = (MainWindow *)data;
1653
1654         reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1655 }
1656
1657 static void toolbar_delete_cb   (GtkWidget      *widget,
1658                                  gpointer        data)
1659 {
1660         MainWindow *mainwin = (MainWindow *)data;
1661
1662         summary_delete(mainwin->summaryview);
1663 }
1664
1665 static void toolbar_exec_cb     (GtkWidget      *widget,
1666                                  gpointer        data)
1667 {
1668         MainWindow *mainwin = (MainWindow *)data;
1669
1670         summary_execute(mainwin->summaryview);
1671 }
1672
1673 static void toolbar_next_unread_cb      (GtkWidget      *widget,
1674                                          gpointer        data)
1675 {
1676         MainWindow *mainwin = (MainWindow *)data;
1677
1678         next_unread_cb(mainwin, 0, NULL);
1679 }
1680
1681 static void toolbar_prefs_cb    (GtkWidget      *widget,
1682                                  gpointer        data)
1683 {
1684         prefs_common_open();
1685 }
1686
1687 static void toolbar_account_cb  (GtkWidget      *widget,
1688                                  gpointer        data)
1689 {
1690         MainWindow *mainwin = (MainWindow *)data;
1691
1692         prefs_account_open_cb(mainwin, 0, NULL);
1693 }
1694
1695 static void toolbar_account_button_pressed(GtkWidget *widget,
1696                                            GdkEventButton *event,
1697                                            gpointer data)
1698 {
1699         MainWindow *mainwin = (MainWindow *)data;
1700
1701         if (!event) return;
1702         if (event->button != 3) return;
1703
1704         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1705                        event->button, event->time);
1706 }
1707
1708 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1709                                     gpointer data)
1710 {
1711         MainWindow *mainwin = (MainWindow *)data;
1712
1713         if (!event) return;
1714
1715         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1716                        event->button, event->time);
1717 }
1718
1719 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1720                                  gpointer data)
1721 {
1722         app_exit_cb(data, 0, widget);
1723
1724         return TRUE;
1725 }
1726
1727 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1728                            GtkWidget *widget)
1729 {
1730         main_window_add_mailbox(mainwin);
1731 }
1732
1733 static void add_mbox_cb(MainWindow *mainwin, guint action,
1734                         GtkWidget *widget)
1735 {
1736         main_window_add_mbox(mainwin);
1737 }
1738
1739 static void update_folderview_cb(MainWindow *mainwin, guint action,
1740                                  GtkWidget *widget)
1741 {
1742         summary_show(mainwin->summaryview, NULL, FALSE);
1743         folderview_update_all();
1744 }
1745
1746 static void new_folder_cb(MainWindow *mainwin, guint action,
1747                           GtkWidget *widget)
1748 {
1749         folderview_new_folder(mainwin->folderview);
1750 }
1751
1752 static void rename_folder_cb(MainWindow *mainwin, guint action,
1753                              GtkWidget *widget)
1754 {
1755         folderview_rename_folder(mainwin->folderview);
1756 }
1757
1758 static void delete_folder_cb(MainWindow *mainwin, guint action,
1759                              GtkWidget *widget)
1760 {
1761         folderview_delete_folder(mainwin->folderview);
1762 }
1763
1764 static void import_mbox_cb(MainWindow *mainwin, guint action,
1765                            GtkWidget *widget)
1766 {
1767         import_mbox(mainwin->summaryview->folder_item);
1768 }
1769
1770 static void export_mbox_cb(MainWindow *mainwin, guint action,
1771                            GtkWidget *widget)
1772 {
1773         export_mbox(mainwin->summaryview->folder_item);
1774 }
1775
1776 static void empty_trash_cb(MainWindow *mainwin, guint action,
1777                            GtkWidget *widget)
1778 {
1779         main_window_empty_trash(mainwin, TRUE);
1780 }
1781
1782 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1783 {
1784         summary_save_as(mainwin->summaryview);
1785 }
1786
1787 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1788 {
1789         summary_print(mainwin->summaryview);
1790 }
1791
1792 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1793 {
1794         if (prefs_common.confirm_on_exit) {
1795                 if (alertpanel(_("Exit"), _("Exit this program?"),
1796                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
1797                         return;
1798                 manage_window_focus_in(mainwin->window, NULL, NULL);
1799         }
1800
1801         app_will_exit(widget, mainwin);
1802 }
1803
1804 static void toggle_folder_cb(MainWindow *mainwin, guint action,
1805                              GtkWidget *widget)
1806 {
1807         switch (mainwin->type) {
1808         case SEPARATE_NONE:
1809         case SEPARATE_MESSAGE:
1810                 break;
1811         case SEPARATE_FOLDER:
1812                 if (GTK_CHECK_MENU_ITEM(widget)->active)
1813                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
1814                 else
1815                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
1816                 break;
1817         case SEPARATE_BOTH:
1818                 if (GTK_CHECK_MENU_ITEM(widget)->active)
1819                         gtk_widget_show(mainwin->win.sep_both.folderwin);
1820                 else
1821                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
1822                 break;
1823         }
1824 }
1825
1826 static void toggle_message_cb(MainWindow *mainwin, guint action,
1827                               GtkWidget *widget)
1828 {
1829         switch (mainwin->type) {
1830         case SEPARATE_NONE:
1831         case SEPARATE_FOLDER:
1832                 break;
1833         case SEPARATE_MESSAGE:
1834                 if (GTK_CHECK_MENU_ITEM(widget)->active)
1835                         gtk_widget_show(mainwin->win.sep_message.messagewin);
1836                 else
1837                         gtk_widget_hide(mainwin->win.sep_message.messagewin);
1838                 break;
1839         case SEPARATE_BOTH:
1840                 if (GTK_CHECK_MENU_ITEM(widget)->active)
1841                         gtk_widget_show(mainwin->win.sep_both.messagewin);
1842                 else
1843                         gtk_widget_hide(mainwin->win.sep_both.messagewin);
1844                 break;
1845         }
1846 }
1847
1848 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
1849                               GtkWidget *widget)
1850 {
1851         switch ((ToolbarStyle)action) {
1852         case TOOLBAR_NONE:
1853                 gtk_widget_hide(mainwin->handlebox);
1854         case TOOLBAR_ICON:
1855                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1856                                       GTK_TOOLBAR_ICONS);
1857                 break;
1858         case TOOLBAR_TEXT:
1859                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1860                                       GTK_TOOLBAR_TEXT);
1861                 break;
1862         case TOOLBAR_BOTH:
1863                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1864                                       GTK_TOOLBAR_BOTH);
1865                 break;
1866         }
1867
1868         if (action != TOOLBAR_NONE) {
1869                 gtk_widget_show(mainwin->handlebox);
1870                 gtk_widget_queue_resize(mainwin->handlebox);
1871         }
1872
1873         mainwin->toolbar_style = (ToolbarStyle)action;
1874         prefs_common.toolbar_style = (ToolbarStyle)action;
1875 }
1876
1877 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
1878                                 GtkWidget *widget)
1879 {
1880         if (GTK_CHECK_MENU_ITEM(widget)->active) {
1881                 gtk_widget_show(mainwin->hbox_stat);
1882                 prefs_common.show_statusbar = TRUE;
1883         } else {
1884                 gtk_widget_hide(mainwin->hbox_stat);
1885                 prefs_common.show_statusbar = FALSE;
1886         }
1887 }
1888
1889 static void separate_widget_cb(GtkCheckMenuItem *checkitem, guint action)
1890 {
1891         MainWindow *mainwin;
1892         SeparateType type;
1893
1894         mainwin = (MainWindow *) gtk_object_get_data(GTK_OBJECT(checkitem), "mainwindow");
1895         g_return_if_fail(mainwin != NULL);
1896
1897         type = mainwin->type ^ action;
1898         main_window_separation_change(mainwin, type);
1899
1900         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
1901         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
1902 }
1903
1904 static void addressbook_open_cb(MainWindow *mainwin, guint action,
1905                                 GtkWidget *widget)
1906 {
1907         addressbook_open(NULL);
1908 }
1909
1910 static void log_window_show_cb(MainWindow *mainwin, guint action,
1911                                GtkWidget *widget)
1912 {
1913         log_window_show(mainwin->logwin);
1914 }
1915
1916 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1917 {
1918         inc_mail(mainwin);
1919 }
1920
1921 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
1922                                     GtkWidget *widget)
1923 {
1924         inc_all_account_mail(mainwin);
1925 }
1926
1927 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1928 {
1929         GList *list;
1930
1931         if (procmsg_send_queue() < 0)
1932                 alertpanel_error(_("Sending queued message failed."));
1933
1934         statusbar_pop_all();
1935
1936         for (list = folder_get_list(); list != NULL; list = list->next) {
1937                 Folder *folder;
1938
1939                 folder = list->data;
1940                 if (folder->queue) {
1941                         folder_item_scan(folder->queue);
1942                         folderview_update_item(folder->queue, TRUE);
1943                 }
1944         }
1945 }
1946
1947 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1948 {
1949         if (mainwin->summaryview->folder_item) {
1950                 if (mainwin->summaryview->folder_item->folder->account != NULL
1951                     && mainwin->summaryview->folder_item->folder->account->protocol == A_NNTP)
1952                         compose_new_with_recipient(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item->path);
1953                 else
1954                         compose_new(mainwin->summaryview->folder_item->folder->account);
1955         }
1956         else
1957                 compose_new(NULL);
1958 }
1959
1960 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1961 {
1962         MsgInfo *msginfo;
1963
1964         msginfo = gtk_ctree_node_get_row_data
1965                 (GTK_CTREE(mainwin->summaryview->ctree),
1966                  mainwin->summaryview->selected);
1967
1968         if (!msginfo) return;
1969
1970         switch (action) {
1971         case COMPOSE_REPLY:
1972                 compose_reply(msginfo, prefs_common.reply_with_quote,
1973                               FALSE, FALSE);
1974                 break;
1975         case COMPOSE_REPLY_TO_SENDER:
1976                 compose_reply(msginfo, prefs_common.reply_with_quote,
1977                               FALSE, TRUE);
1978                 break;
1979         case COMPOSE_REPLY_TO_ALL:
1980                 compose_reply(msginfo, prefs_common.reply_with_quote,
1981                               TRUE, FALSE);
1982                 break;
1983         case COMPOSE_FORWARD:
1984                 compose_forward(NULL, msginfo, FALSE);
1985                 break;
1986         case COMPOSE_FORWARD_AS_ATTACH:
1987                 compose_forward(NULL, msginfo, TRUE);
1988                 break;
1989         default:
1990                 g_warning("reply_cb(): invalid action type: %d\n", action);
1991         }
1992
1993         summary_set_marks_selected(mainwin->summaryview);
1994 }
1995
1996 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1997 {
1998         summary_move_to(mainwin->summaryview);
1999 }
2000
2001 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2002 {
2003         summary_copy_to(mainwin->summaryview);
2004 }
2005
2006 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2007 {
2008         summary_delete(mainwin->summaryview);
2009 }
2010
2011 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2012 {
2013         summary_open_msg(mainwin->summaryview);
2014 }
2015
2016 static void view_source_cb(MainWindow *mainwin, guint action,
2017                            GtkWidget *widget)
2018 {
2019         summary_view_source(mainwin->summaryview);
2020 }
2021
2022 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2023 {
2024         summary_reedit(mainwin->summaryview);
2025 }
2026
2027 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2028 {
2029         summary_mark(mainwin->summaryview);
2030 }
2031
2032 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2033 {
2034         summary_unmark(mainwin->summaryview);
2035 }
2036
2037 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2038                               GtkWidget *widget)
2039 {
2040         summary_mark_as_unread(mainwin->summaryview);
2041 }
2042
2043 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2044                             GtkWidget *widget)
2045 {
2046         summary_mark_as_read(mainwin->summaryview);
2047 }
2048
2049 static void set_charset_cb(MainWindow *mainwin, guint action,
2050                            GtkWidget *widget)
2051 {
2052         const gchar *str;
2053
2054         str = conv_get_charset_str((CharSet)action);
2055         g_free(prefs_common.force_charset);
2056         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2057
2058         summary_redisplay_msg(mainwin->summaryview);
2059
2060         debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
2061 }
2062
2063 void main_window_set_thread_option(MainWindow *mainwin)
2064 {
2065         GtkItemFactory *ifactory;
2066         gboolean no_item = FALSE;
2067
2068         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2069
2070         if (mainwin->summaryview == NULL)
2071                 no_item = TRUE;
2072         else if (mainwin->summaryview->folder_item == NULL)
2073                 no_item = TRUE;
2074
2075         if (no_item) {
2076                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
2077                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
2078         }
2079         else {
2080                 if (mainwin->summaryview->folder_item->prefs->enable_thread) {
2081                         menu_set_sensitive(ifactory,
2082                                            "/Summary/Thread view",   FALSE);
2083                         menu_set_sensitive(ifactory,
2084                                            "/Summary/Unthread view", TRUE);
2085                         summary_thread_build(mainwin->summaryview);
2086                 }
2087                 else {
2088                         menu_set_sensitive(ifactory,
2089                                            "/Summary/Thread view",   TRUE);
2090                         menu_set_sensitive(ifactory,
2091                                            "/Summary/Unthread view", FALSE);
2092                         summary_unthread(mainwin->summaryview);
2093                 }
2094                 prefs_folder_item_save_config(mainwin->summaryview->folder_item);
2095         }
2096 }
2097
2098 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2099 {
2100         mainwin->summaryview->folder_item->prefs->enable_thread =
2101                 !mainwin->summaryview->folder_item->prefs->enable_thread;
2102         main_window_set_thread_option(mainwin);
2103
2104         /*
2105         if (0 == action) {
2106                 summary_thread_build(mainwin->summaryview);
2107                 mainwin->summaryview->folder_item->prefs->enable_thread =
2108                         TRUE;
2109                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
2110                 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
2111         } else {
2112                 summary_unthread(mainwin->summaryview);
2113                 mainwin->summaryview->folder_item->prefs->enable_thread =
2114                         FALSE;
2115                 menu_set_sensitive(ifactory, "/Summary/Thread view",   TRUE);
2116                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
2117         }
2118         */
2119 }
2120
2121 static void set_display_item_cb(MainWindow *mainwin, guint action,
2122                                 GtkWidget *widget)
2123 {
2124         prefs_summary_display_item_set();
2125 }
2126
2127 static void sort_summary_cb(MainWindow *mainwin, guint action,
2128                             GtkWidget *widget)
2129 {
2130         summary_sort(mainwin->summaryview, (SummarySortType)action);
2131 }
2132
2133 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2134                                   GtkWidget *widget)
2135 {
2136         summary_attract_by_subject(mainwin->summaryview);
2137 }
2138
2139 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2140                                  GtkWidget *widget)
2141 {
2142         summary_delete_duplicated(mainwin->summaryview);
2143 }
2144
2145 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2146 {
2147         summary_filter(mainwin->summaryview);
2148 }
2149
2150 static void execute_summary_cb(MainWindow *mainwin, guint action,
2151                                GtkWidget *widget)
2152 {
2153         summary_execute(mainwin->summaryview);
2154 }
2155
2156 static void update_summary_cb(MainWindow *mainwin, guint action,
2157                               GtkWidget *widget)
2158 {
2159         FolderItem *fitem;
2160         FolderView *folderview = mainwin->folderview;
2161
2162         if (!mainwin->summaryview->folder_item) return;
2163         if (!folderview->opened) return;
2164
2165         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2166                                             folderview->opened);
2167         if (!fitem) return;
2168
2169         summary_show(mainwin->summaryview, fitem, TRUE);
2170 }
2171
2172 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2173 {
2174         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2175 }
2176
2177 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2178 {
2179         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2180 }
2181
2182 static void next_unread_cb(MainWindow *mainwin, guint action,
2183                            GtkWidget *widget)
2184 {
2185         summary_select_next_unread(mainwin->summaryview);
2186 }
2187
2188 static void next_marked_cb(MainWindow *mainwin, guint action,
2189                            GtkWidget *widget)
2190 {
2191         summary_select_next_marked(mainwin->summaryview);
2192 }
2193
2194 static void prev_marked_cb(MainWindow *mainwin, guint action,
2195                            GtkWidget *widget)
2196 {
2197         summary_select_prev_marked(mainwin->summaryview);
2198 }
2199
2200 static void goto_folder_cb(MainWindow *mainwin, guint action,
2201                            GtkWidget *widget)
2202 {
2203         FolderItem *to_folder;
2204
2205         to_folder = foldersel_folder_sel(NULL);
2206
2207         if (to_folder)
2208                 folderview_select(mainwin->folderview, to_folder);
2209 }
2210
2211 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2212 {
2213         messageview_copy_clipboard(mainwin->messageview);
2214 }
2215
2216 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2217 {
2218         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2219                 summary_select_all(mainwin->summaryview);
2220         else if (mainwin->summaryview->msg_is_toggled_on &&
2221                  GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2222                 messageview_select_all(mainwin->messageview);
2223 }
2224
2225 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2226                                  GtkWidget *widget)
2227 {
2228         prefs_common_open();
2229 }
2230
2231 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2232                                  GtkWidget *widget)
2233 {
2234         prefs_filter_open();
2235 }
2236
2237 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2238                                   GtkWidget *widget)
2239 {
2240         prefs_scoring_open(NULL);
2241 }
2242
2243 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2244                                     GtkWidget *widget)
2245 {
2246         prefs_filtering_open();
2247 }
2248
2249 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2250                                   GtkWidget *widget)
2251 {
2252         if (!cur_account) {
2253                 new_account_cb(mainwin, 0, widget);
2254         } else {
2255                 gboolean prev_default = cur_account->is_default;
2256
2257                 prefs_account_open(cur_account);
2258                 if (!prev_default && cur_account->is_default)
2259                         account_set_as_default(cur_account);
2260                 account_save_config_all();
2261                 account_set_menu();
2262                 main_window_reflect_prefs_all();
2263         }
2264 }
2265
2266 static void new_account_cb(MainWindow *mainwin, guint action,
2267                            GtkWidget *widget)
2268 {
2269         account_edit_open();
2270         if (!compose_get_compose_list()) account_add();
2271 }
2272
2273 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2274 {
2275         cur_account = (PrefsAccount *)data;
2276         main_window_reflect_prefs_all();
2277 }
2278
2279 static void manual_open_cb(MainWindow *mainwin, guint action,
2280                            GtkWidget *widget)
2281 {
2282         manual_open((ManualLang)action);
2283 }
2284
2285 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2286 {
2287         MainWindow *mainwin = (MainWindow *)data;
2288         gchar *str;
2289
2290         if (item->path)
2291                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2292                                       LOCAL_FOLDER(folder)->rootpath,
2293                                       G_DIR_SEPARATOR,
2294                                       item->path);
2295         else
2296                 str = g_strdup_printf(_("Scanning folder %s ..."),
2297                                       LOCAL_FOLDER(folder)->rootpath);
2298
2299         STATUSBAR_PUSH(mainwin, str);
2300         STATUSBAR_POP(mainwin);
2301         g_free(str);
2302 }