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