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