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