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