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