tags file added
[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                 headerview_set_visibility(mainwin->messageview->headerview,
787                                           prefs_common.display_header_pane);
788         }
789 }
790
791 void main_window_set_account_menu(GList *account_list)
792 {
793         GList *cur, *cur_ac, *cur_item;
794         GtkWidget *menuitem;
795         MainWindow *mainwin;
796         PrefsAccount *ac_prefs;
797
798         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
799                 mainwin = (MainWindow *)cur->data;
800
801                 /* destroy all previous menu item */
802                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
803                 while (cur_item != NULL) {
804                         GList *next = cur_item->next;
805                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
806                         cur_item = next;
807                 }
808
809                 for (cur_ac = account_list; cur_ac != NULL;
810                      cur_ac = cur_ac->next) {
811                         ac_prefs = (PrefsAccount *)cur_ac->data;
812
813                         menuitem = gtk_menu_item_new_with_label
814                                 (ac_prefs->account_name
815                                  ? ac_prefs->account_name : _("Untitled"));
816                         gtk_widget_show(menuitem);
817                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
818                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
819                                            GTK_SIGNAL_FUNC(account_menu_cb),
820                                            ac_prefs);
821                 }
822         }
823 }
824
825 static void main_window_show_cur_account(MainWindow *mainwin)
826 {
827         gchar *buf;
828         gchar *ac_name;
829
830         ac_name = g_strdup(cur_account
831                            ? (cur_account->account_name
832                               ? cur_account->account_name : _("Untitled"))
833                            : _("none"));
834
835         if (cur_account)
836                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
837         else
838                 buf = g_strdup(PROG_VERSION);
839         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
840         g_free(buf);
841
842         buf = g_strdup_printf(_("Current account: %s"), ac_name);
843         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), buf);
844         gtk_widget_queue_resize(mainwin->ac_button);
845         g_free(buf);
846
847         g_free(ac_name);
848 }
849
850 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
851 {
852         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
853         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
854         GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
855
856         if (mainwin->type == type) return;
857
858         /* remove widgets from those containers */
859         gtk_widget_ref(folder_wid);
860         gtk_widget_ref(summary_wid);
861         gtk_widget_ref(message_wid);
862         gtk_container_remove
863                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
864         gtk_container_remove
865                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
866         gtk_container_remove
867                 (GTK_CONTAINER(message_wid->parent), message_wid);
868
869         /* clean containers */
870         switch (mainwin->type) {
871         case SEPARATE_NONE:
872                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
873                 break;
874         case SEPARATE_FOLDER:
875                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
876                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
877                 break;
878         case SEPARATE_MESSAGE:
879                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
880                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
881                 break;
882         case SEPARATE_BOTH:
883                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
884                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
885                 break;
886         }
887
888         gtk_widget_hide(mainwin->window);
889         main_window_set_widgets(mainwin, type);
890         gtk_widget_show(mainwin->window);
891
892         gtk_widget_unref(folder_wid);
893         gtk_widget_unref(summary_wid);
894         gtk_widget_unref(message_wid);
895 }
896
897 void main_window_get_size(MainWindow *mainwin)
898 {
899         GtkAllocation *allocation;
900
901         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
902
903         prefs_common.summaryview_width  = allocation->width;
904
905         if (mainwin->summaryview->msg_is_toggled_on)
906                 prefs_common.summaryview_height = allocation->height;
907
908         prefs_common.mainview_width     = allocation->width;
909
910         allocation = &mainwin->window->allocation;
911
912         prefs_common.mainview_height = allocation->height;
913         prefs_common.mainwin_width   = allocation->width;
914         prefs_common.mainwin_height  = allocation->height;
915
916         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
917
918         prefs_common.folderview_width  = allocation->width;
919         prefs_common.folderview_height = allocation->height;
920 }
921
922 void main_window_get_position(MainWindow *mainwin)
923 {
924         gint x, y;
925
926         gtkut_widget_get_uposition(mainwin->window, &x, &y);
927
928         prefs_common.mainview_x = x;
929         prefs_common.mainview_y = y;
930         prefs_common.mainwin_x = x;
931         prefs_common.mainwin_y = y;
932
933         debug_print(_("window position: x = %d, y = %d\n"), x, y);
934 }
935
936 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
937 {
938         GList *list;
939
940         if (confirm) {
941                 if (alertpanel(_("Empty trash"),
942                                _("Empty all messages in trash?"),
943                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
944                         return;
945         }
946
947         procmsg_empty_trash();
948
949         for (list = folder_get_list(); list != NULL; list = list->next) {
950                 Folder *folder;
951
952                 folder = list->data;
953                 if (folder->trash) {
954                         folder_item_scan(folder->trash);
955                         folderview_update_item(folder->trash, TRUE);
956                 }
957         }
958
959         if (mainwin->summaryview->folder_item &&
960             mainwin->summaryview->folder_item->stype == F_TRASH)
961                 gtk_widget_grab_focus(mainwin->folderview->ctree);
962 }
963
964 void main_window_add_mailbox(MainWindow *mainwin)
965 {
966         gchar *path;
967         Folder *folder;
968
969         path = input_dialog(_("Add mailbox"),
970                             _("Input the location of mailbox.\n"
971                               "If the existing mailbox is specified, it will be\n"
972                               "scanned automatically."),
973                             "Mail");
974         if (!path) return;
975         if (folder_find_from_path(path)) {
976                 alertpanel_error(_("The mailbox `%s' already exists."), path);
977                 g_free(path);
978                 return;
979         }
980         if (!strcmp(path, "Mail"))
981                 folder = folder_new(F_MH, _("Mailbox"), path);
982         else
983                 folder = folder_new(F_MH, g_basename(path), path);
984         g_free(path);
985
986         if (folder->create_tree(folder) < 0) {
987                 alertpanel_error(_("Creation of the mailbox failed.\n"
988                                    "Maybe some files already exist, or you don't have the permission to write there."));
989                 folder_destroy(folder);
990                 return;
991         }
992
993         folder_add(folder);
994         folder_set_ui_func(folder, scan_tree_func, mainwin);
995         folder->scan_tree(folder);
996         folder_set_ui_func(folder, NULL, NULL);
997
998         folderview_set(mainwin->folderview);
999 }
1000
1001 void main_window_set_toolbar_sensitive(MainWindow *mainwin, gboolean sensitive)
1002 {
1003         gtk_widget_set_sensitive(mainwin->reply_btn,    sensitive);
1004         gtk_widget_set_sensitive(mainwin->replyall_btn, sensitive);
1005         gtk_widget_set_sensitive(mainwin->fwd_btn,      sensitive);
1006         gtk_widget_set_sensitive(mainwin->exec_btn,     sensitive);
1007         gtk_widget_set_sensitive(mainwin->next_btn,     sensitive);
1008
1009         if (!mainwin->summaryview->folder_item ||
1010             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1011                 gtk_widget_set_sensitive(mainwin->delete_btn, FALSE);
1012         else
1013                 gtk_widget_set_sensitive(mainwin->delete_btn, sensitive);
1014 }
1015
1016 void main_window_set_menu_sensitive(MainWindow *mainwin, gint selection)
1017 {
1018         GtkItemFactory *ifactory;
1019         gboolean sens;
1020         gboolean exec;
1021
1022         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1023
1024         if (selection == SUMMARY_SELECTED_SINGLE)
1025                 sens = TRUE;
1026         else
1027                 sens = FALSE;
1028         if (!mainwin->summaryview->folder_item ||
1029             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1030                 exec = FALSE;
1031         else
1032                 exec = TRUE;
1033
1034         menu_set_sensitive(ifactory, "/File/Save as...", sens);
1035         menu_set_sensitive(ifactory, "/Message/Reply", sens);
1036         menu_set_sensitive(ifactory, "/Message/Reply to all", sens);
1037         menu_set_sensitive(ifactory, "/Message/Forward", sens);
1038         menu_set_sensitive(ifactory, "/Message/Forward as an attachment", sens);
1039         menu_set_sensitive(ifactory, "/Message/Open in new window", sens);
1040         menu_set_sensitive(ifactory, "/Message/Show all header", sens);
1041         menu_set_sensitive(ifactory, "/Message/View source", sens);
1042         if (sens && (!mainwin->summaryview->folder_item ||
1043                      mainwin->summaryview->folder_item->stype != F_DRAFT))
1044                 sens = FALSE;
1045         menu_set_sensitive(ifactory, "/Message/Reedit", sens);
1046
1047         if (selection == SUMMARY_SELECTED_SINGLE ||
1048             selection == SUMMARY_SELECTED_MULTIPLE)
1049                 sens = TRUE;
1050         else
1051                 sens = FALSE;
1052
1053         menu_set_sensitive(ifactory, "/File/Print..."  , sens);
1054         menu_set_sensitive(ifactory, "/Message/Move...", sens && exec);
1055         menu_set_sensitive(ifactory, "/Message/Copy...", sens && exec);
1056         menu_set_sensitive(ifactory, "/Message/Delete" , sens && exec);
1057         menu_set_sensitive(ifactory, "/Message/Mark"   , sens);
1058
1059         if (selection != SUMMARY_NONE)
1060                 sens = TRUE;
1061         else
1062                 sens = FALSE;
1063
1064         menu_set_sensitive(ifactory, "/Summary/Delete duplicated messages", sens && exec);
1065         menu_set_sensitive(ifactory, "/Summary/Filter messages", sens && exec);
1066         menu_set_sensitive(ifactory, "/Summary/Execute", sens);
1067         menu_set_sensitive(ifactory, "/Summary/Prev message", sens);
1068         menu_set_sensitive(ifactory, "/Summary/Next message", sens);
1069         menu_set_sensitive(ifactory, "/Summary/Next unread message", sens);
1070         menu_set_sensitive(ifactory, "/Summary/Sort", sens);
1071 }
1072
1073 void main_window_popup(MainWindow *mainwin)
1074 {
1075         gint x, y;
1076         gint sx, sy;
1077         GtkWidget *widget;
1078
1079         gdk_window_get_origin(mainwin->window->window, &x, &y);
1080         sx = gdk_screen_width();
1081         sy = gdk_screen_height();
1082         x %= sx; if (x < 0) x += sx;
1083         y %= sy; if (y < 0) y += sy;
1084         gdk_window_move(mainwin->window->window, x, y);
1085         gdk_window_raise(mainwin->window->window);
1086
1087         debug_print("window position: x = %d, y = %d\n", x, y);
1088
1089         switch (mainwin->type) {
1090         case SEPARATE_FOLDER:
1091                 widget = mainwin->win.sep_folder.folderwin;
1092                 gdk_window_get_origin(widget->window, &x, &y);
1093                 x %= sx; if (x < 0) x += sx;
1094                 y %= sy; if (y < 0) y += sy;
1095                 gdk_window_move(widget->window, x, y);
1096                 gdk_window_raise(widget->window);
1097                 break;
1098         case SEPARATE_MESSAGE:
1099                 widget = mainwin->win.sep_message.messagewin;
1100                 gdk_window_get_origin(widget->window, &x, &y);
1101                 x %= sx; if (x < 0) x += sx;
1102                 y %= sy; if (y < 0) y += sy;
1103                 gdk_window_move(widget->window, x, y);
1104                 gdk_window_raise(widget->window);
1105                 break;
1106         case SEPARATE_BOTH:
1107                 widget = mainwin->win.sep_both.folderwin;
1108                 gdk_window_get_origin(widget->window, &x, &y);
1109                 x %= sx; if (x < 0) x += sx;
1110                 y %= sy; if (y < 0) y += sy;
1111                 gdk_window_move(widget->window, x, y);
1112                 gdk_window_raise(widget->window);
1113                 widget = mainwin->win.sep_both.messagewin;
1114                 gdk_window_get_origin(widget->window, &x, &y);
1115                 x %= sx; if (x < 0) x += sx;
1116                 y %= sy; if (y < 0) y += sy;
1117                 gdk_window_move(widget->window, x, y);
1118                 gdk_window_raise(widget->window);
1119                 break;
1120         default:
1121         }
1122 }
1123
1124 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1125 {
1126         GtkWidget *folderwin = NULL;
1127         GtkWidget *messagewin = NULL;
1128         GtkWidget *hpaned;
1129         GtkWidget *vpaned;
1130         GtkWidget *vbox_body = mainwin->vbox_body;
1131
1132         debug_print(_("Setting widgets..."));
1133
1134         /* create separated window(s) if needed */
1135         if (type & SEPARATE_FOLDER) {
1136                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1137                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1138                                       TRUE, TRUE, FALSE);
1139                 gtk_widget_set_usize(folderwin, -1,
1140                                      prefs_common.mainview_height);
1141                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1142                                                BORDER_WIDTH);
1143                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1144                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1145                                    NULL);
1146         }
1147         if (type & SEPARATE_MESSAGE) {
1148                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1149                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1150                                       TRUE, TRUE, FALSE);
1151                 gtk_widget_set_usize
1152                         (messagewin, prefs_common.mainview_width,
1153                          prefs_common.mainview_height
1154                          - prefs_common.summaryview_height
1155                          + DEFAULT_HEADERVIEW_HEIGHT);
1156                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1157                                                BORDER_WIDTH);
1158                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1159                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1160                                    NULL);
1161         }
1162
1163         switch (type) {
1164         case SEPARATE_NONE:
1165                 hpaned = gtk_hpaned_new();
1166                 gtk_widget_show(hpaned);
1167                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1168                 gtk_paned_add1(GTK_PANED(hpaned),
1169                                GTK_WIDGET_PTR(mainwin->folderview));
1170
1171                 vpaned = gtk_vpaned_new();
1172                 if (mainwin->summaryview->msg_is_toggled_on) {
1173                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1174                         gtk_paned_add1(GTK_PANED(vpaned),
1175                                        GTK_WIDGET_PTR(mainwin->summaryview));
1176                 } else {
1177                         gtk_paned_add2(GTK_PANED(hpaned),
1178                                        GTK_WIDGET_PTR(mainwin->summaryview));
1179                         gtk_widget_ref(vpaned);
1180                 }
1181                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1182                                      prefs_common.summaryview_width,
1183                                      prefs_common.summaryview_height);
1184                 gtk_paned_add2(GTK_PANED(vpaned),
1185                                GTK_WIDGET_PTR(mainwin->messageview));
1186                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1187                                      prefs_common.mainview_width, -1);
1188                 gtk_widget_set_usize(mainwin->window,
1189                                      prefs_common.folderview_width +
1190                                      prefs_common.mainview_width,
1191                                      prefs_common.mainwin_height);
1192                 gtk_widget_show_all(vpaned);
1193
1194                 mainwin->win.sep_none.hpaned = hpaned;
1195                 mainwin->win.sep_none.vpaned = vpaned;
1196                 break;
1197         case SEPARATE_FOLDER:
1198                 vpaned = gtk_vpaned_new();
1199                 if (mainwin->summaryview->msg_is_toggled_on) {
1200                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1201                                            TRUE, TRUE, 0);
1202                         gtk_paned_add1(GTK_PANED(vpaned),
1203                                        GTK_WIDGET_PTR(mainwin->summaryview));
1204                 } else {
1205                         gtk_box_pack_start(GTK_BOX(vbox_body),
1206                                            GTK_WIDGET_PTR(mainwin->summaryview),
1207                                            TRUE, TRUE, 0);
1208                         gtk_widget_ref(vpaned);
1209                 }
1210                 gtk_paned_add2(GTK_PANED(vpaned),
1211                                GTK_WIDGET_PTR(mainwin->messageview));
1212                 gtk_widget_show_all(vpaned);
1213                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1214                                      prefs_common.summaryview_width,
1215                                      prefs_common.summaryview_height);
1216                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1217                                      prefs_common.mainview_width, -1);
1218                 gtk_widget_set_usize(mainwin->window,
1219                                      prefs_common.mainview_width,
1220                                      prefs_common.mainview_height);
1221
1222                 gtk_container_add(GTK_CONTAINER(folderwin),
1223                                   GTK_WIDGET_PTR(mainwin->folderview));
1224
1225                 mainwin->win.sep_folder.folderwin = folderwin;
1226                 mainwin->win.sep_folder.vpaned    = vpaned;
1227
1228                 gtk_widget_show_all(folderwin);
1229                 break;
1230         case SEPARATE_MESSAGE:
1231                 hpaned = gtk_hpaned_new();
1232                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1233
1234                 gtk_paned_add1(GTK_PANED(hpaned),
1235                                GTK_WIDGET_PTR(mainwin->folderview));
1236                 gtk_paned_add2(GTK_PANED(hpaned),
1237                                GTK_WIDGET_PTR(mainwin->summaryview));
1238                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1239                                      prefs_common.summaryview_width,
1240                                      prefs_common.summaryview_height);
1241                 gtk_widget_set_usize(mainwin->window,
1242                                      prefs_common.folderview_width +
1243                                      prefs_common.mainview_width,
1244                                      prefs_common.mainwin_height);
1245                 gtk_widget_show_all(hpaned);
1246                 gtk_container_add(GTK_CONTAINER(messagewin),
1247                                   GTK_WIDGET_PTR(mainwin->messageview));
1248
1249                 mainwin->win.sep_message.messagewin = messagewin;
1250                 mainwin->win.sep_message.hpaned     = hpaned;
1251
1252                 gtk_widget_show_all(messagewin);
1253                 break;
1254         case SEPARATE_BOTH:
1255                 gtk_box_pack_start(GTK_BOX(vbox_body),
1256                                    GTK_WIDGET_PTR(mainwin->summaryview),
1257                                    TRUE, TRUE, 0);
1258                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1259                                      prefs_common.summaryview_width,
1260                                      prefs_common.summaryview_height);
1261                 gtk_widget_set_usize(mainwin->window,
1262                                      prefs_common.mainview_width,
1263                                      prefs_common.mainwin_height);
1264                 gtk_container_add(GTK_CONTAINER(folderwin),
1265                                   GTK_WIDGET_PTR(mainwin->folderview));
1266                 gtk_container_add(GTK_CONTAINER(messagewin),
1267                                   GTK_WIDGET_PTR(mainwin->messageview));
1268
1269                 mainwin->win.sep_both.folderwin = folderwin;
1270                 mainwin->win.sep_both.messagewin = messagewin;
1271
1272                 gtk_widget_show_all(folderwin);
1273                 gtk_widget_show_all(messagewin);
1274                 break;
1275         }
1276
1277         mainwin->type = type;
1278
1279         debug_print(_("done.\n"));
1280 }
1281
1282 #include "pixmaps/stock_mail_receive.xpm"
1283 #include "pixmaps/stock_mail_receive_all.xpm"
1284 #include "pixmaps/stock_mail_compose.xpm"
1285 #include "pixmaps/stock_mail_reply.xpm"
1286 #include "pixmaps/stock_mail_reply_to_all.xpm"
1287 #include "pixmaps/stock_mail_forward.xpm"
1288 #include "pixmaps/stock_mail_send.xpm"
1289 #include "pixmaps/stock_preferences.xpm"
1290 #include "pixmaps/stock_properties.xpm"
1291 #include "pixmaps/stock_down_arrow.xpm"
1292 #include "pixmaps/stock_close.xpm"
1293 #include "pixmaps/stock_exec.xpm"
1294
1295 #define CREATE_TOOLBAR_ICON(xpm_d) \
1296 { \
1297         icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1298                                             &container->style->white, \
1299                                             xpm_d); \
1300         icon_wid = gtk_pixmap_new(icon, mask); \
1301 }
1302
1303 static void main_window_toolbar_create(MainWindow *mainwin,
1304                                        GtkWidget *container)
1305 {
1306         GtkWidget *toolbar;
1307         GdkPixmap *icon;
1308         GdkBitmap *mask;
1309         GtkWidget *icon_wid;
1310         GtkWidget *get_btn;
1311         GtkWidget *getall_btn;
1312         GtkWidget *compose_btn;
1313         GtkWidget *reply_btn;
1314         GtkWidget *replyall_btn;
1315         GtkWidget *fwd_btn;
1316         GtkWidget *send_btn;
1317         GtkWidget *prefs_btn;
1318         GtkWidget *account_btn;
1319         GtkWidget *next_btn;
1320         GtkWidget *delete_btn;
1321         GtkWidget *exec_btn;
1322
1323         toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1324                                   GTK_TOOLBAR_BOTH);
1325         gtk_container_add(GTK_CONTAINER(container), toolbar);
1326         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1327         gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1328         gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1329                                     GTK_TOOLBAR_SPACE_LINE);
1330
1331         CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1332         get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1333                                           _("Get"),
1334                                           _("Incorporate new mail"),
1335                                           "Get",
1336                                           icon_wid, toolbar_inc_cb, mainwin);
1337         CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1338         getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1339                                              _("Get all"),
1340                                              _("Incorporate new mail of all accounts"),
1341                                              "Get all",
1342                                              icon_wid,
1343                                              toolbar_inc_all_cb,
1344                                              mainwin);
1345
1346         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1347
1348         CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1349         send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1350                                            _("Send"),
1351                                            _("Send queued message(s)"),
1352                                            "Send",
1353                                            icon_wid,
1354                                            toolbar_send_cb,
1355                                            mainwin);
1356
1357         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1358
1359         CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1360         compose_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1361                                               _("Compose"),
1362                                               _("Compose new message"),
1363                                               "New",
1364                                               icon_wid,
1365                                               toolbar_compose_cb,
1366                                               mainwin);
1367         CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1368         reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1369                                             _("Reply"),
1370                                             _("Reply to the message"),
1371                                             "Reply",
1372                                             icon_wid,
1373                                             toolbar_reply_cb,
1374                                             mainwin);
1375         CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1376         replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1377                                                _("Reply all"),
1378                                                _("Reply to all"),
1379                                                "Reply to all",
1380                                                icon_wid,
1381                                                toolbar_reply_to_all_cb,
1382                                                mainwin);
1383         CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1384         fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1385                                           _("Forward"),
1386                                           _("Forward the message"),
1387                                           "Fwd",
1388                                           icon_wid,
1389                                           toolbar_forward_cb,
1390                                           mainwin);
1391
1392         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1393
1394         CREATE_TOOLBAR_ICON(stock_close_xpm);
1395         delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1396                                           _("Delete"),
1397                                           _("Delete the message"),
1398                                           "Delete",
1399                                           icon_wid,
1400                                           toolbar_delete_cb,
1401                                           mainwin);
1402
1403         CREATE_TOOLBAR_ICON(stock_exec_xpm);
1404         exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1405                                            _("Execute"),
1406                                            _("Execute marked process"),
1407                                            "Execute",
1408                                            icon_wid,
1409                                            toolbar_exec_cb,
1410                                            mainwin);
1411
1412         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1413
1414         CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1415         next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1416                                            _("Next"),
1417                                            _("Next unread message"),
1418                                            "Next unread",
1419                                            icon_wid,
1420                                            toolbar_next_unread_cb,
1421                                            mainwin);
1422
1423         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1424
1425         CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1426         prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1427                                             _("Prefs"),
1428                                             _("Common preference"),
1429                                             "Prefs",
1430                                             icon_wid,
1431                                             toolbar_prefs_cb,
1432                                             mainwin);
1433         CREATE_TOOLBAR_ICON(stock_properties_xpm);
1434         account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1435                                               _("Account"),
1436                                               _("Account setting"),
1437                                               "Account",
1438                                               icon_wid,
1439                                               toolbar_account_cb,
1440                                               mainwin);
1441         gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1442                            GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1443                            mainwin);
1444
1445         mainwin->toolbar      = toolbar;
1446         mainwin->get_btn      = get_btn;
1447         mainwin->getall_btn   = getall_btn;
1448         mainwin->compose_btn  = compose_btn;
1449         mainwin->reply_btn    = reply_btn;
1450         mainwin->replyall_btn = replyall_btn;
1451         mainwin->fwd_btn      = fwd_btn;
1452         mainwin->send_btn     = send_btn;
1453         mainwin->prefs_btn    = prefs_btn;
1454         mainwin->account_btn  = account_btn;
1455         mainwin->next_btn     = next_btn;
1456         mainwin->delete_btn   = delete_btn;
1457         mainwin->exec_btn     = exec_btn;
1458
1459         gtk_widget_show_all(toolbar);
1460 }
1461
1462 /* callback functions */
1463
1464 static void toolbar_inc_cb      (GtkWidget      *widget,
1465                                  gpointer        data)
1466 {
1467         MainWindow *mainwin = (MainWindow *)data;
1468
1469         inc_mail_cb(mainwin, 0, NULL);
1470 }
1471
1472 static void toolbar_inc_all_cb  (GtkWidget      *widget,
1473                                  gpointer        data)
1474 {
1475         MainWindow *mainwin = (MainWindow *)data;
1476
1477         inc_all_account_mail_cb(mainwin, 0, NULL);
1478 }
1479
1480 static void toolbar_send_cb     (GtkWidget      *widget,
1481                                  gpointer        data)
1482 {
1483         MainWindow *mainwin = (MainWindow *)data;
1484
1485         send_queue_cb(mainwin, 0, NULL);
1486 }
1487
1488 static void toolbar_compose_cb  (GtkWidget      *widget,
1489                                  gpointer        data)
1490 {
1491         MainWindow *mainwin = (MainWindow *)data;
1492
1493         compose_cb(mainwin, 0, NULL);
1494 }
1495
1496 static void toolbar_reply_cb    (GtkWidget      *widget,
1497                                  gpointer        data)
1498 {
1499         MainWindow *mainwin = (MainWindow *)data;
1500
1501         reply_cb(mainwin, COMPOSE_REPLY, NULL);
1502 }
1503
1504 static void toolbar_reply_to_all_cb     (GtkWidget      *widget,
1505                                          gpointer        data)
1506 {
1507         MainWindow *mainwin = (MainWindow *)data;
1508
1509         reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
1510 }
1511
1512 static void toolbar_forward_cb  (GtkWidget      *widget,
1513                                  gpointer        data)
1514 {
1515         MainWindow *mainwin = (MainWindow *)data;
1516
1517         reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1518 }
1519
1520 static void toolbar_delete_cb   (GtkWidget      *widget,
1521                                  gpointer        data)
1522 {
1523         MainWindow *mainwin = (MainWindow *)data;
1524
1525         summary_delete(mainwin->summaryview);
1526 }
1527
1528 static void toolbar_exec_cb     (GtkWidget      *widget,
1529                                  gpointer        data)
1530 {
1531         MainWindow *mainwin = (MainWindow *)data;
1532
1533         summary_execute(mainwin->summaryview);
1534 }
1535
1536 static void toolbar_next_unread_cb      (GtkWidget      *widget,
1537                                          gpointer        data)
1538 {
1539         MainWindow *mainwin = (MainWindow *)data;
1540
1541         next_unread_cb(mainwin, 0, NULL);
1542 }
1543
1544 static void toolbar_prefs_cb    (GtkWidget      *widget,
1545                                  gpointer        data)
1546 {
1547         prefs_common_open();
1548 }
1549
1550 static void toolbar_account_cb  (GtkWidget      *widget,
1551                                  gpointer        data)
1552 {
1553         MainWindow *mainwin = (MainWindow *)data;
1554
1555         prefs_account_open_cb(mainwin, 0, NULL);
1556 }
1557
1558 static void toolbar_account_button_pressed(GtkWidget *widget,
1559                                            GdkEventButton *event,
1560                                            gpointer data)
1561 {
1562         MainWindow *mainwin = (MainWindow *)data;
1563
1564         if (!event) return;
1565         if (event->button != 3) return;
1566
1567         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1568                        event->button, event->time);
1569 }
1570
1571 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1572                                     gpointer data)
1573 {
1574         MainWindow *mainwin = (MainWindow *)data;
1575
1576         if (!event) return;
1577
1578         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1579                        event->button, event->time);
1580 }
1581
1582 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1583                                  gpointer data)
1584 {
1585         app_exit_cb(data, 0, widget);
1586
1587         return TRUE;
1588 }
1589
1590 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1591                            GtkWidget *widget)
1592 {
1593         main_window_add_mailbox(mainwin);
1594 }
1595
1596 static void update_folderview_cb(MainWindow *mainwin, guint action,
1597                                  GtkWidget *widget)
1598 {
1599         summary_show(mainwin->summaryview, NULL, FALSE);
1600         folderview_update_all();
1601 }
1602
1603 static void new_folder_cb(MainWindow *mainwin, guint action,
1604                           GtkWidget *widget)
1605 {
1606         folderview_new_folder(mainwin->folderview);
1607 }
1608
1609 static void rename_folder_cb(MainWindow *mainwin, guint action,
1610                              GtkWidget *widget)
1611 {
1612         folderview_rename_folder(mainwin->folderview);
1613 }
1614
1615 static void delete_folder_cb(MainWindow *mainwin, guint action,
1616                              GtkWidget *widget)
1617 {
1618         folderview_delete_folder(mainwin->folderview);
1619 }
1620
1621 static void import_mbox_cb(MainWindow *mainwin, guint action,
1622                            GtkWidget *widget)
1623 {
1624         import_mbox(mainwin->summaryview->folder_item);
1625 }
1626
1627 static void export_mbox_cb(MainWindow *mainwin, guint action,
1628                            GtkWidget *widget)
1629 {
1630         export_mbox(mainwin->summaryview->folder_item);
1631 }
1632
1633 static void empty_trash_cb(MainWindow *mainwin, guint action,
1634                            GtkWidget *widget)
1635 {
1636         main_window_empty_trash(mainwin, TRUE);
1637 }
1638
1639 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1640 {
1641         summary_save_as(mainwin->summaryview);
1642 }
1643
1644 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1645 {
1646         summary_print(mainwin->summaryview);
1647 }
1648
1649 static gint queued_messages(void)
1650 {
1651         FolderItem *queue = folder_get_default_queue();
1652         folder_item_scan(queue);
1653         return queue->total;
1654 }
1655
1656 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1657 {
1658         if (prefs_common.confirm_on_exit) {
1659                 if (alertpanel(_("Exit"), _("Exit this program?"),
1660                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
1661                         return;
1662         }
1663
1664         if (prefs_common.warn_queued_on_exit && queued_messages() > 0) {
1665                 if (alertpanel(_("Queued messages"), 
1666                                _("Some unsent messages are queued. Exit now?"),
1667                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
1668                         return;
1669         }
1670
1671         manage_window_focus_in(mainwin->window, NULL, NULL);
1672         app_will_exit(widget, mainwin);
1673 }
1674
1675 static void toggle_folder_cb(MainWindow *mainwin, guint action,
1676                              GtkWidget *widget)
1677 {
1678         switch (mainwin->type) {
1679         case SEPARATE_NONE:
1680         case SEPARATE_MESSAGE:
1681                 break;
1682         case SEPARATE_FOLDER:
1683                 if (GTK_CHECK_MENU_ITEM(widget)->active)
1684                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
1685                 else
1686                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
1687                 break;
1688         case SEPARATE_BOTH:
1689                 if (GTK_CHECK_MENU_ITEM(widget)->active)
1690                         gtk_widget_show(mainwin->win.sep_both.folderwin);
1691                 else
1692                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
1693                 break;
1694         }
1695 }
1696
1697 static void toggle_message_cb(MainWindow *mainwin, guint action,
1698                               GtkWidget *widget)
1699 {
1700         switch (mainwin->type) {
1701         case SEPARATE_NONE:
1702         case SEPARATE_FOLDER:
1703                 break;
1704         case SEPARATE_MESSAGE:
1705                 if (GTK_CHECK_MENU_ITEM(widget)->active)
1706                         gtk_widget_show(mainwin->win.sep_message.messagewin);
1707                 else
1708                         gtk_widget_hide(mainwin->win.sep_message.messagewin);
1709                 break;
1710         case SEPARATE_BOTH:
1711                 if (GTK_CHECK_MENU_ITEM(widget)->active)
1712                         gtk_widget_show(mainwin->win.sep_both.messagewin);
1713                 else
1714                         gtk_widget_hide(mainwin->win.sep_both.messagewin);
1715                 break;
1716         }
1717 }
1718
1719 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
1720                               GtkWidget *widget)
1721 {
1722         switch ((ToolbarStyle)action) {
1723         case TOOLBAR_NONE:
1724                 gtk_widget_hide(mainwin->handlebox);
1725         case TOOLBAR_ICON:
1726                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1727                                       GTK_TOOLBAR_ICONS);
1728                 break;
1729         case TOOLBAR_TEXT:
1730                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1731                                       GTK_TOOLBAR_TEXT);
1732                 break;
1733         case TOOLBAR_BOTH:
1734                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
1735                                       GTK_TOOLBAR_BOTH);
1736                 break;
1737         }
1738
1739         if (action != TOOLBAR_NONE) {
1740                 gtk_widget_show(mainwin->handlebox);
1741                 gtk_widget_queue_resize(mainwin->handlebox);
1742         }
1743
1744         mainwin->toolbar_style = (ToolbarStyle)action;
1745         prefs_common.toolbar_style = (ToolbarStyle)action;
1746 }
1747
1748 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
1749                                 GtkWidget *widget)
1750 {
1751         if (GTK_CHECK_MENU_ITEM(widget)->active) {
1752                 gtk_widget_show(mainwin->hbox_stat);
1753                 prefs_common.show_statusbar = TRUE;
1754         } else {
1755                 gtk_widget_hide(mainwin->hbox_stat);
1756                 prefs_common.show_statusbar = FALSE;
1757         }
1758 }
1759
1760 static void separate_widget_cb(MainWindow *mainwin, guint action,
1761                                GtkWidget *widget)
1762 {
1763         SeparateType type;
1764
1765         type = mainwin->type ^ action;
1766         main_window_separation_change(mainwin, type);
1767
1768         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
1769         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
1770 }
1771
1772 static void addressbook_open_cb(MainWindow *mainwin, guint action,
1773                                 GtkWidget *widget)
1774 {
1775         addressbook_open(NULL);
1776 }
1777
1778 static void log_window_show_cb(MainWindow *mainwin, guint action,
1779                                GtkWidget *widget)
1780 {
1781         log_window_show(mainwin->logwin);
1782 }
1783
1784 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1785 {
1786         inc_mail(mainwin);
1787 }
1788
1789 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
1790                                     GtkWidget *widget)
1791 {
1792         inc_all_account_mail(mainwin);
1793 }
1794
1795 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1796 {
1797         GList *list;
1798
1799         if (procmsg_send_queue() < 0)
1800                 alertpanel_error(_("Sending queued message failed."));
1801
1802         statusbar_pop_all();
1803
1804         for (list = folder_get_list(); list != NULL; list = list->next) {
1805                 Folder *folder;
1806
1807                 folder = list->data;
1808                 if (folder->queue) {
1809                         folder_item_scan(folder->queue);
1810                         folderview_update_item(folder->queue, TRUE);
1811                 }
1812         }
1813 }
1814
1815 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1816 {
1817         if (mainwin->summaryview->folder_item)
1818                 compose_new(mainwin->summaryview->folder_item->folder->account);
1819         else
1820                 compose_new(NULL);
1821 }
1822
1823 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1824 {
1825         MsgInfo *msginfo;
1826
1827         msginfo = gtk_ctree_node_get_row_data
1828                 (GTK_CTREE(mainwin->summaryview->ctree),
1829                  mainwin->summaryview->selected);
1830
1831         if (!msginfo) return;
1832
1833         switch (action) {
1834         case COMPOSE_REPLY:
1835                 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1836                 break;
1837         case COMPOSE_REPLY_TO_ALL:
1838                 compose_reply(msginfo, prefs_common.reply_with_quote, TRUE);
1839                 break;
1840         case COMPOSE_FORWARD:
1841                 compose_forward(msginfo, FALSE);
1842                 break;
1843         case COMPOSE_FORWARD_AS_ATTACH:
1844                 compose_forward(msginfo, TRUE);
1845                 break;
1846         default:
1847                 compose_reply(msginfo, prefs_common.reply_with_quote, FALSE);
1848         }
1849
1850         summary_set_marks_selected(mainwin->summaryview);
1851 }
1852
1853 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1854 {
1855         summary_move_to(mainwin->summaryview);
1856 }
1857
1858 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1859 {
1860         summary_copy_to(mainwin->summaryview);
1861 }
1862
1863 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1864 {
1865         summary_delete(mainwin->summaryview);
1866 }
1867
1868 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1869 {
1870         summary_open_msg(mainwin->summaryview);
1871 }
1872
1873 static void view_source_cb(MainWindow *mainwin, guint action,
1874                            GtkWidget *widget)
1875 {
1876         summary_view_source(mainwin->summaryview);
1877 }
1878
1879 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1880 {
1881         summary_reedit(mainwin->summaryview);
1882 }
1883
1884 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1885 {
1886         summary_mark(mainwin->summaryview);
1887 }
1888
1889 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1890 {
1891         summary_unmark(mainwin->summaryview);
1892 }
1893
1894 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
1895                               GtkWidget *widget)
1896 {
1897         summary_mark_as_unread(mainwin->summaryview);
1898 }
1899
1900 static void mark_as_read_cb(MainWindow *mainwin, guint action,
1901                             GtkWidget *widget)
1902 {
1903         summary_mark_as_read(mainwin->summaryview);
1904 }
1905
1906 static void set_charset_cb(MainWindow *mainwin, guint action,
1907                            GtkWidget *widget)
1908 {
1909         const gchar *str;
1910
1911         str = conv_get_charset_str((CharSet)action);
1912         g_free(prefs_common.force_charset);
1913         prefs_common.force_charset = str ? g_strdup(str) : NULL;
1914
1915         summary_redisplay_msg(mainwin->summaryview);
1916
1917         debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
1918 }
1919
1920 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1921 {
1922         GtkItemFactory *ifactory;
1923
1924         ifactory = gtk_item_factory_from_widget(widget);
1925
1926         if (0 == action) {
1927                 summary_thread_build(mainwin->summaryview);
1928                 prefs_common.enable_thread = TRUE;
1929                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
1930                 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
1931         } else {
1932                 summary_unthread(mainwin->summaryview);
1933                 prefs_common.enable_thread = FALSE;
1934                 menu_set_sensitive(ifactory, "/Summary/Thread view",   TRUE);
1935                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
1936         }
1937 }
1938
1939 static void set_display_item_cb(MainWindow *mainwin, guint action,
1940                                 GtkWidget *widget)
1941 {
1942         prefs_summary_display_item_set();
1943 }
1944
1945 static void sort_summary_cb(MainWindow *mainwin, guint action,
1946                             GtkWidget *widget)
1947 {
1948         summary_sort(mainwin->summaryview, (SummarySortType)action);
1949 }
1950
1951 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
1952                                   GtkWidget *widget)
1953 {
1954         summary_attract_by_subject(mainwin->summaryview);
1955 }
1956
1957 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
1958                                  GtkWidget *widget)
1959 {
1960         summary_delete_duplicated(mainwin->summaryview);
1961 }
1962
1963 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1964 {
1965         summary_filter(mainwin->summaryview);
1966 }
1967
1968 static void execute_summary_cb(MainWindow *mainwin, guint action,
1969                                GtkWidget *widget)
1970 {
1971         summary_execute(mainwin->summaryview);
1972 }
1973
1974 static void update_summary_cb(MainWindow *mainwin, guint action,
1975                               GtkWidget *widget)
1976 {
1977         FolderItem *fitem;
1978         FolderView *folderview = mainwin->folderview;
1979
1980         if (!mainwin->summaryview->folder_item) return;
1981         if (!folderview->opened) return;
1982
1983         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
1984                                             folderview->opened);
1985         if (!fitem) return;
1986
1987         summary_show(mainwin->summaryview, fitem, TRUE);
1988 }
1989
1990 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1991 {
1992         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
1993 }
1994
1995 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1996 {
1997         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
1998 }
1999
2000 static void next_unread_cb(MainWindow *mainwin, guint action,
2001                            GtkWidget *widget)
2002 {
2003         summary_select_next_unread(mainwin->summaryview);
2004 }
2005
2006 static void goto_folder_cb(MainWindow *mainwin, guint action,
2007                            GtkWidget *widget)
2008 {
2009         FolderItem *to_folder;
2010
2011         to_folder = foldersel_folder_sel(NULL);
2012
2013         if (to_folder)
2014                 folderview_select(mainwin->folderview, to_folder);
2015 }
2016
2017 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2018 {
2019         messageview_copy_clipboard(mainwin->messageview);
2020 }
2021
2022 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2023 {
2024         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2025                 summary_select_all(mainwin->summaryview);
2026         else if (mainwin->summaryview->msg_is_toggled_on &&
2027                  GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2028                 messageview_select_all(mainwin->messageview);
2029 }
2030
2031 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2032                                  GtkWidget *widget)
2033 {
2034         prefs_common_open();
2035 }
2036
2037 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2038                                  GtkWidget *widget)
2039 {
2040         prefs_filter_open();
2041 }
2042
2043 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2044                                   GtkWidget *widget)
2045 {
2046         if (!cur_account) {
2047                 new_account_cb(mainwin, 0, widget);
2048         } else {
2049                 gboolean prev_default = cur_account->is_default;
2050
2051                 prefs_account_open(cur_account);
2052                 if (!prev_default && cur_account->is_default)
2053                         account_set_as_default(cur_account);
2054                 account_save_config_all();
2055                 account_set_menu();
2056                 main_window_reflect_prefs_all();
2057         }
2058 }
2059
2060 static void new_account_cb(MainWindow *mainwin, guint action,
2061                            GtkWidget *widget)
2062 {
2063         account_edit_open();
2064         if (!compose_get_compose_list()) account_add();
2065 }
2066
2067 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2068 {
2069         cur_account = (PrefsAccount *)data;
2070         main_window_reflect_prefs_all();
2071 }
2072
2073 static void manual_open_cb(MainWindow *mainwin, guint action,
2074                            GtkWidget *widget)
2075 {
2076         manual_open((ManualLang)action);
2077 }
2078
2079 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2080 {
2081         MainWindow *mainwin = (MainWindow *)data;
2082         gchar *str;
2083
2084         if (item->path)
2085                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2086                                       LOCAL_FOLDER(folder)->rootpath,
2087                                       G_DIR_SEPARATOR,
2088                                       item->path);
2089         else
2090                 str = g_strdup_printf(_("Scanning folder %s ..."),
2091                                       LOCAL_FOLDER(folder)->rootpath);
2092
2093         STATUSBAR_PUSH(mainwin, str);
2094         STATUSBAR_POP(mainwin);
2095         g_free(str);
2096 }