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