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