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