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