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