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