sync with sylpheed 0.5.1cvs1-3
[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
780         /* set account selection menu */
781         ac_menu = gtk_item_factory_get_widget
782                 (ifactory, "/Configuration/Change current account");
783         mainwin->ac_menu = ac_menu;
784
785         main_window_set_toolbar_sensitive(mainwin, FALSE);
786
787         /* show main window */
788         gtk_widget_set_uposition(mainwin->window,
789                                  prefs_common.mainwin_x,
790                                  prefs_common.mainwin_y);
791         gtk_widget_set_usize(window, prefs_common.mainwin_width,
792                              prefs_common.mainwin_height);
793         gtk_widget_show(mainwin->window);
794
795         /* initialize views */
796         folderview_init(folderview);
797         summary_init(summaryview);
798         messageview_init(messageview);
799         header_window_init(mainwin->headerwin);
800         log_window_init(mainwin->logwin);
801
802         mainwin->cursor_count = 0;
803
804         if (!watch_cursor)
805                 watch_cursor = gdk_cursor_new(GDK_WATCH);
806
807         mainwin_list = g_list_append(mainwin_list, mainwin);
808
809         return mainwin;
810 }
811
812 void main_window_cursor_wait(MainWindow *mainwin)
813 {
814         if (mainwin->cursor_count == 0)
815                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
816
817         mainwin->cursor_count++;
818
819         gdk_flush();
820 }
821
822 void main_window_cursor_normal(MainWindow *mainwin)
823 {
824         if (mainwin->cursor_count)
825                 mainwin->cursor_count--;
826
827         if (mainwin->cursor_count == 0)
828                 gdk_window_set_cursor(mainwin->window->window, NULL);
829
830         gdk_flush();
831 }
832
833 void main_window_reflect_prefs_all(void)
834 {
835         GList *cur;
836         MainWindow *mainwin;
837
838         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
839                 mainwin = (MainWindow *)cur->data;
840
841                 main_window_show_cur_account(mainwin);
842                 if (cur_account) {
843                         gtk_widget_set_sensitive(mainwin->get_btn,    TRUE);
844                         gtk_widget_set_sensitive(mainwin->getall_btn, TRUE);
845                 } else {
846                         gtk_widget_set_sensitive(mainwin->get_btn,    FALSE);
847                         gtk_widget_set_sensitive(mainwin->getall_btn, FALSE);
848                 }
849
850                 if (prefs_common.immediate_exec)
851                         gtk_widget_hide(mainwin->exec_btn);
852                 else
853                         gtk_widget_show(mainwin->exec_btn);
854
855                 summary_change_display_item(mainwin->summaryview);
856                 summary_redisplay_msg(mainwin->summaryview);
857                 headerview_set_visibility(mainwin->messageview->headerview,
858                                           prefs_common.display_header_pane);
859         }
860 }
861
862 void main_window_set_account_menu(GList *account_list)
863 {
864         GList *cur, *cur_ac, *cur_item;
865         GtkWidget *menuitem;
866         MainWindow *mainwin;
867         PrefsAccount *ac_prefs;
868
869         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
870                 mainwin = (MainWindow *)cur->data;
871
872                 /* destroy all previous menu item */
873                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
874                 while (cur_item != NULL) {
875                         GList *next = cur_item->next;
876                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
877                         cur_item = next;
878                 }
879
880                 for (cur_ac = account_list; cur_ac != NULL;
881                      cur_ac = cur_ac->next) {
882                         ac_prefs = (PrefsAccount *)cur_ac->data;
883
884                         menuitem = gtk_menu_item_new_with_label
885                                 (ac_prefs->account_name
886                                  ? ac_prefs->account_name : _("Untitled"));
887                         gtk_widget_show(menuitem);
888                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
889                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
890                                            GTK_SIGNAL_FUNC(account_menu_cb),
891                                            ac_prefs);
892                 }
893         }
894 }
895
896 static void main_window_show_cur_account(MainWindow *mainwin)
897 {
898         gchar *buf;
899         gchar *ac_name;
900
901         ac_name = g_strdup(cur_account
902                            ? (cur_account->account_name
903                               ? cur_account->account_name : _("Untitled"))
904                            : _("none"));
905
906         if (cur_account)
907                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
908         else
909                 buf = g_strdup(PROG_VERSION);
910         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
911         g_free(buf);
912
913         buf = g_strdup_printf(_("Current account: %s"), ac_name);
914         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), buf);
915         gtk_widget_queue_resize(mainwin->ac_button);
916         g_free(buf);
917
918         g_free(ac_name);
919 }
920
921 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
922 {
923         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
924         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
925         GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
926
927         if (mainwin->type == type) return;
928
929         /* remove widgets from those containers */
930         gtk_widget_ref(folder_wid);
931         gtk_widget_ref(summary_wid);
932         gtk_widget_ref(message_wid);
933         gtk_container_remove
934                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
935         gtk_container_remove
936                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
937         gtk_container_remove
938                 (GTK_CONTAINER(message_wid->parent), message_wid);
939
940         /* clean containers */
941         switch (mainwin->type) {
942         case SEPARATE_NONE:
943                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
944                 break;
945         case SEPARATE_FOLDER:
946                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
947                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
948                 break;
949         case SEPARATE_MESSAGE:
950                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
951                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
952                 break;
953         case SEPARATE_BOTH:
954                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
955                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
956                 break;
957         }
958
959         gtk_widget_hide(mainwin->window);
960         main_window_set_widgets(mainwin, type);
961         gtk_widget_show(mainwin->window);
962
963         gtk_widget_unref(folder_wid);
964         gtk_widget_unref(summary_wid);
965         gtk_widget_unref(message_wid);
966 }
967
968 void main_window_get_size(MainWindow *mainwin)
969 {
970         GtkAllocation *allocation;
971
972         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
973
974         prefs_common.summaryview_width  = allocation->width;
975
976         if (mainwin->summaryview->msg_is_toggled_on)
977                 prefs_common.summaryview_height = allocation->height;
978
979         prefs_common.mainview_width     = allocation->width;
980
981         allocation = &mainwin->window->allocation;
982
983         prefs_common.mainview_height = allocation->height;
984         prefs_common.mainwin_width   = allocation->width;
985         prefs_common.mainwin_height  = allocation->height;
986
987         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
988
989         prefs_common.folderview_width  = allocation->width;
990         prefs_common.folderview_height = allocation->height;
991 }
992
993 void main_window_get_position(MainWindow *mainwin)
994 {
995         gint x, y;
996
997         gtkut_widget_get_uposition(mainwin->window, &x, &y);
998
999         prefs_common.mainview_x = x;
1000         prefs_common.mainview_y = y;
1001         prefs_common.mainwin_x = x;
1002         prefs_common.mainwin_y = y;
1003
1004         debug_print(_("window position: x = %d, y = %d\n"), x, y);
1005 }
1006
1007 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1008 {
1009         GList *list;
1010
1011         if (confirm) {
1012                 if (alertpanel(_("Empty trash"),
1013                                _("Empty all messages in trash?"),
1014                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1015                         return;
1016                 manage_window_focus_in(mainwin->window, NULL, NULL);
1017         }
1018
1019         procmsg_empty_trash();
1020
1021         for (list = folder_get_list(); list != NULL; list = list->next) {
1022                 Folder *folder;
1023
1024                 folder = list->data;
1025                 if (folder->trash) {
1026                         folder_item_scan(folder->trash);
1027                         folderview_update_item(folder->trash, TRUE);
1028                 }
1029         }
1030
1031         if (mainwin->summaryview->folder_item &&
1032             mainwin->summaryview->folder_item->stype == F_TRASH)
1033                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1034 }
1035
1036 void main_window_add_mailbox(MainWindow *mainwin)
1037 {
1038         gchar *path;
1039         Folder *folder;
1040
1041         path = input_dialog(_("Add mailbox"),
1042                             _("Input the location of mailbox.\n"
1043                               "If the existing mailbox is specified, it will be\n"
1044                               "scanned automatically."),
1045                             "Mail");
1046         if (!path) return;
1047         if (folder_find_from_path(path)) {
1048                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1049                 g_free(path);
1050                 return;
1051         }
1052
1053         if (!strcmp(path, "Mail"))
1054                 folder = folder_new(F_MH, _("Mailbox"), path);
1055         else
1056                 folder = folder_new(F_MH, g_basename(path), path);
1057
1058         g_free(path);
1059
1060         if (folder->create_tree(folder) < 0) {
1061                 alertpanel_error(_("Creation of the mailbox failed.\n"
1062                                    "Maybe some files already exist, or you don't have the permission to write there."));
1063                 folder_destroy(folder);
1064                 return;
1065         }
1066
1067         folder_add(folder);
1068         folder_set_ui_func(folder, scan_tree_func, mainwin);
1069         folder->scan_tree(folder);
1070         folder_set_ui_func(folder, NULL, NULL);
1071
1072         folderview_set(mainwin->folderview);
1073 }
1074
1075 void main_window_add_mbox(MainWindow *mainwin)
1076 {
1077         gchar *path;
1078         Folder *folder;
1079         FolderItem * item;
1080
1081         path = input_dialog(_("Add mbox mailbox"),
1082                             _("Input the location of mailbox."),
1083                             "mail");
1084
1085         if (!path) return;
1086
1087         if (folder_find_from_path(path)) {
1088                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1089                 g_free(path);
1090                 return;
1091         }
1092
1093         /*
1094         if (!strcmp(path, "Mail"))
1095                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1096                 else
1097         */
1098
1099         folder = folder_new(F_MBOX, g_basename(path), path);
1100         g_free(path);
1101
1102         if (folder->create_tree(folder) < 0) {
1103                 alertpanel_error(_("Creation of the mailbox failed."));
1104                 folder_destroy(folder);
1105                 return;
1106         }
1107
1108         folder_add(folder);
1109
1110         item = folder_item_new(folder->name, NULL);
1111         item->folder = folder;
1112         folder->node = g_node_new(item);
1113
1114         folder->create_folder(folder, item, "inbox");
1115         folder->create_folder(folder, item, "outbox");
1116         folder->create_folder(folder, item, "queue");
1117         folder->create_folder(folder, item, "draft");
1118         folder->create_folder(folder, item, "trash");
1119
1120         folderview_set(mainwin->folderview);
1121 }
1122
1123 void main_window_set_toolbar_sensitive(MainWindow *mainwin, gboolean sensitive)
1124 {
1125         gtk_widget_set_sensitive(mainwin->reply_btn,       sensitive);
1126         gtk_widget_set_sensitive(mainwin->replyall_btn,    sensitive);
1127         gtk_widget_set_sensitive(mainwin->replysender_btn, sensitive);
1128         gtk_widget_set_sensitive(mainwin->fwd_btn,         sensitive);
1129         gtk_widget_set_sensitive(mainwin->exec_btn,        sensitive);
1130         gtk_widget_set_sensitive(mainwin->next_btn,        sensitive);
1131
1132         if (!mainwin->summaryview->folder_item ||
1133             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1134                 gtk_widget_set_sensitive(mainwin->delete_btn, FALSE);
1135         else
1136                 gtk_widget_set_sensitive(mainwin->delete_btn, sensitive);
1137 }
1138
1139 void main_window_set_menu_sensitive(MainWindow *mainwin, gint selection)
1140 {
1141         GtkItemFactory *ifactory;
1142         gboolean sens;
1143         gboolean exec;
1144
1145         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1146
1147         if (selection == SUMMARY_SELECTED_SINGLE)
1148                 sens = TRUE;
1149         else
1150                 sens = FALSE;
1151         if (!mainwin->summaryview->folder_item ||
1152             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1153                 exec = FALSE;
1154         else
1155                 exec = TRUE;
1156
1157         menu_set_sensitive(ifactory, "/File/Save as...", sens);
1158         menu_set_sensitive(ifactory, "/Message/Reply", sens);
1159         menu_set_sensitive(ifactory, "/Message/Reply to sender", sens);
1160         menu_set_sensitive(ifactory, "/Message/Reply to all", sens);
1161         menu_set_sensitive(ifactory, "/Message/Forward", TRUE);
1162         menu_set_sensitive(ifactory, "/Message/Forward as attachment", TRUE);
1163         menu_set_sensitive(ifactory, "/Message/Open in new window", sens);
1164         menu_set_sensitive(ifactory, "/Message/Show all header", sens);
1165         menu_set_sensitive(ifactory, "/Message/View source", sens);
1166         if (sens && (!mainwin->summaryview->folder_item ||
1167                      mainwin->summaryview->folder_item->stype != F_DRAFT))
1168                 sens = FALSE;
1169         menu_set_sensitive(ifactory, "/Message/Re-edit", sens);
1170
1171         if (selection == SUMMARY_SELECTED_SINGLE ||
1172             selection == SUMMARY_SELECTED_MULTIPLE)
1173                 sens = TRUE;
1174         else
1175                 sens = FALSE;
1176
1177         menu_set_sensitive(ifactory, "/File/Print..."  , sens);
1178         menu_set_sensitive(ifactory, "/Message/Move...", sens && exec);
1179         menu_set_sensitive(ifactory, "/Message/Copy...", sens && exec);
1180         menu_set_sensitive(ifactory, "/Message/Delete" , sens && exec);
1181         menu_set_sensitive(ifactory, "/Message/Mark"   , sens);
1182
1183         if (selection != SUMMARY_NONE)
1184                 sens = TRUE;
1185         else
1186                 sens = FALSE;
1187
1188         menu_set_sensitive(ifactory, "/Summary/Delete duplicated messages", sens && exec);
1189         menu_set_sensitive(ifactory, "/Summary/Filter messages", sens && exec);
1190         menu_set_sensitive(ifactory, "/Summary/Execute", sens);
1191         menu_set_sensitive(ifactory, "/Summary/Prev message", sens);
1192         menu_set_sensitive(ifactory, "/Summary/Next message", sens);
1193         menu_set_sensitive(ifactory, "/Summary/Next unread message", sens);
1194         menu_set_sensitive(ifactory, "/Summary/Sort", sens);
1195
1196         if (mainwin->summaryview->folder_item &&
1197             mainwin->summaryview->folder_item->folder->account)
1198                 sens = mainwin->summaryview->folder_item->folder->account->protocol == A_NNTP;
1199         else
1200                 sens = FALSE;
1201         menu_set_sensitive(ifactory, "/Message/Follow-up and reply to", sens);
1202 }
1203
1204 void main_window_popup(MainWindow *mainwin)
1205 {
1206         gint x, y;
1207         gint sx, sy;
1208         GtkWidget *widget;
1209
1210         gdk_window_get_origin(mainwin->window->window, &x, &y);
1211         sx = gdk_screen_width();
1212         sy = gdk_screen_height();
1213         x %= sx; if (x < 0) x += sx;
1214         y %= sy; if (y < 0) y += sy;
1215         gdk_window_move(mainwin->window->window, x, y);
1216         gdk_window_raise(mainwin->window->window);
1217
1218         debug_print("window position: x = %d, y = %d\n", x, y);
1219
1220         switch (mainwin->type) {
1221         case SEPARATE_FOLDER:
1222                 widget = mainwin->win.sep_folder.folderwin;
1223                 gdk_window_get_origin(widget->window, &x, &y);
1224                 x %= sx; if (x < 0) x += sx;
1225                 y %= sy; if (y < 0) y += sy;
1226                 gdk_window_move(widget->window, x, y);
1227                 gdk_window_raise(widget->window);
1228                 break;
1229         case SEPARATE_MESSAGE:
1230                 widget = mainwin->win.sep_message.messagewin;
1231                 gdk_window_get_origin(widget->window, &x, &y);
1232                 x %= sx; if (x < 0) x += sx;
1233                 y %= sy; if (y < 0) y += sy;
1234                 gdk_window_move(widget->window, x, y);
1235                 gdk_window_raise(widget->window);
1236                 break;
1237         case SEPARATE_BOTH:
1238                 widget = mainwin->win.sep_both.folderwin;
1239                 gdk_window_get_origin(widget->window, &x, &y);
1240                 x %= sx; if (x < 0) x += sx;
1241                 y %= sy; if (y < 0) y += sy;
1242                 gdk_window_move(widget->window, x, y);
1243                 gdk_window_raise(widget->window);
1244                 widget = mainwin->win.sep_both.messagewin;
1245                 gdk_window_get_origin(widget->window, &x, &y);
1246                 x %= sx; if (x < 0) x += sx;
1247                 y %= sy; if (y < 0) y += sy;
1248                 gdk_window_move(widget->window, x, y);
1249                 gdk_window_raise(widget->window);
1250                 break;
1251         default:
1252                 break;
1253         }
1254 }
1255
1256 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1257 {
1258         GtkWidget *folderwin = NULL;
1259         GtkWidget *messagewin = NULL;
1260         GtkWidget *hpaned;
1261         GtkWidget *vpaned;
1262         GtkWidget *vbox_body = mainwin->vbox_body;
1263
1264         debug_print(_("Setting widgets..."));
1265
1266         /* create separated window(s) if needed */
1267         if (type & SEPARATE_FOLDER) {
1268                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1269                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1270                                       TRUE, TRUE, FALSE);
1271                 gtk_widget_set_usize(folderwin, -1,
1272                                      prefs_common.mainview_height);
1273                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1274                                                BORDER_WIDTH);
1275                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1276                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1277                                    NULL);
1278         }
1279         if (type & SEPARATE_MESSAGE) {
1280                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1281                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1282                                       TRUE, TRUE, FALSE);
1283                 gtk_widget_set_usize
1284                         (messagewin, prefs_common.mainview_width,
1285                          prefs_common.mainview_height
1286                          - prefs_common.summaryview_height
1287                          + DEFAULT_HEADERVIEW_HEIGHT);
1288                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1289                                                BORDER_WIDTH);
1290                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1291                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1292                                    NULL);
1293         }
1294
1295         switch (type) {
1296         case SEPARATE_NONE:
1297                 hpaned = gtk_hpaned_new();
1298                 gtk_widget_show(hpaned);
1299                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1300                 gtk_paned_add1(GTK_PANED(hpaned),
1301                                GTK_WIDGET_PTR(mainwin->folderview));
1302
1303                 vpaned = gtk_vpaned_new();
1304                 if (mainwin->summaryview->msg_is_toggled_on) {
1305                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1306                         gtk_paned_add1(GTK_PANED(vpaned),
1307                                        GTK_WIDGET_PTR(mainwin->summaryview));
1308                 } else {
1309                         gtk_paned_add2(GTK_PANED(hpaned),
1310                                        GTK_WIDGET_PTR(mainwin->summaryview));
1311                         gtk_widget_ref(vpaned);
1312                 }
1313                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1314                                      prefs_common.summaryview_width,
1315                                      prefs_common.summaryview_height);
1316                 gtk_paned_add2(GTK_PANED(vpaned),
1317                                GTK_WIDGET_PTR(mainwin->messageview));
1318                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1319                                      prefs_common.mainview_width, -1);
1320                 gtk_widget_set_usize(mainwin->window,
1321                                      prefs_common.folderview_width +
1322                                      prefs_common.mainview_width,
1323                                      prefs_common.mainwin_height);
1324                 gtk_widget_show_all(vpaned);
1325
1326                 mainwin->win.sep_none.hpaned = hpaned;
1327                 mainwin->win.sep_none.vpaned = vpaned;
1328                 break;
1329         case SEPARATE_FOLDER:
1330                 vpaned = gtk_vpaned_new();
1331                 if (mainwin->summaryview->msg_is_toggled_on) {
1332                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1333                                            TRUE, TRUE, 0);
1334                         gtk_paned_add1(GTK_PANED(vpaned),
1335                                        GTK_WIDGET_PTR(mainwin->summaryview));
1336                 } else {
1337                         gtk_box_pack_start(GTK_BOX(vbox_body),
1338                                            GTK_WIDGET_PTR(mainwin->summaryview),
1339                                            TRUE, TRUE, 0);
1340                         gtk_widget_ref(vpaned);
1341                 }
1342                 gtk_paned_add2(GTK_PANED(vpaned),
1343                                GTK_WIDGET_PTR(mainwin->messageview));
1344                 gtk_widget_show_all(vpaned);
1345                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1346                                      prefs_common.summaryview_width,
1347                                      prefs_common.summaryview_height);
1348                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1349                                      prefs_common.mainview_width, -1);
1350                 gtk_widget_set_usize(mainwin->window,
1351                                      prefs_common.mainview_width,
1352                                      prefs_common.mainview_height);
1353
1354                 gtk_container_add(GTK_CONTAINER(folderwin),
1355                                   GTK_WIDGET_PTR(mainwin->folderview));
1356
1357                 mainwin->win.sep_folder.folderwin = folderwin;
1358                 mainwin->win.sep_folder.vpaned    = vpaned;
1359
1360                 gtk_widget_show_all(folderwin);
1361                 break;
1362         case SEPARATE_MESSAGE:
1363                 hpaned = gtk_hpaned_new();
1364                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1365
1366                 gtk_paned_add1(GTK_PANED(hpaned),
1367                                GTK_WIDGET_PTR(mainwin->folderview));
1368                 gtk_paned_add2(GTK_PANED(hpaned),
1369                                GTK_WIDGET_PTR(mainwin->summaryview));
1370                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1371                                      prefs_common.summaryview_width,
1372                                      prefs_common.summaryview_height);
1373                 gtk_widget_set_usize(mainwin->window,
1374                                      prefs_common.folderview_width +
1375                                      prefs_common.mainview_width,
1376                                      prefs_common.mainwin_height);
1377                 gtk_widget_show_all(hpaned);
1378                 gtk_container_add(GTK_CONTAINER(messagewin),
1379                                   GTK_WIDGET_PTR(mainwin->messageview));
1380
1381                 mainwin->win.sep_message.messagewin = messagewin;
1382                 mainwin->win.sep_message.hpaned     = hpaned;
1383
1384                 gtk_widget_show_all(messagewin);
1385                 break;
1386         case SEPARATE_BOTH:
1387                 gtk_box_pack_start(GTK_BOX(vbox_body),
1388                                    GTK_WIDGET_PTR(mainwin->summaryview),
1389                                    TRUE, TRUE, 0);
1390                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1391                                      prefs_common.summaryview_width,
1392                                      prefs_common.summaryview_height);
1393                 gtk_widget_set_usize(mainwin->window,
1394                                      prefs_common.mainview_width,
1395                                      prefs_common.mainwin_height);
1396                 gtk_container_add(GTK_CONTAINER(folderwin),
1397                                   GTK_WIDGET_PTR(mainwin->folderview));
1398                 gtk_container_add(GTK_CONTAINER(messagewin),
1399                                   GTK_WIDGET_PTR(mainwin->messageview));
1400
1401                 mainwin->win.sep_both.folderwin = folderwin;
1402                 mainwin->win.sep_both.messagewin = messagewin;
1403
1404                 gtk_widget_show_all(folderwin);
1405                 gtk_widget_show_all(messagewin);
1406                 break;
1407         }
1408
1409         mainwin->type = type;
1410
1411         debug_print(_("done.\n"));
1412 }
1413
1414 #include "pixmaps/stock_mail_receive.xpm"
1415 #include "pixmaps/stock_mail_receive_all.xpm"
1416 #include "pixmaps/stock_mail_compose.xpm"
1417 #include "pixmaps/stock_news_compose.xpm"
1418 #include "pixmaps/stock_mail_reply.xpm"
1419 #include "pixmaps/stock_mail_reply_to_all.xpm"
1420 #include "pixmaps/stock_mail_reply_to_author.xpm"
1421 #include "pixmaps/stock_mail_forward.xpm"
1422 #include "pixmaps/stock_mail_send.xpm"
1423 #include "pixmaps/stock_preferences.xpm"
1424 #include "pixmaps/stock_properties.xpm"
1425 #include "pixmaps/stock_down_arrow.xpm"
1426 #include "pixmaps/stock_close.xpm"
1427 #include "pixmaps/stock_exec.xpm"
1428
1429 #define CREATE_TOOLBAR_ICON(xpm_d) \
1430 { \
1431         icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1432                                             &container->style->white, \
1433                                             xpm_d); \
1434         icon_wid = gtk_pixmap_new(icon, mask); \
1435 }
1436
1437 static void main_window_toolbar_create(MainWindow *mainwin,
1438                                        GtkWidget *container)
1439 {
1440         GtkWidget *toolbar;
1441         GdkPixmap *icon;
1442         GdkBitmap *mask;
1443         GtkWidget *icon_wid;
1444         GtkWidget *get_btn;
1445         GtkWidget *getall_btn;
1446         GtkWidget *compose_mail_btn;
1447         GtkWidget *compose_news_btn;
1448         GtkWidget *compose_mail_btn_plain;
1449         GtkWidget *compose_news_btn_plain;
1450         GtkWidget *reply_btn;
1451         GtkWidget *replyall_btn;
1452         GtkWidget *replysender_btn;
1453         GtkWidget *fwd_btn;
1454         GtkWidget *send_btn;
1455         /*
1456         GtkWidget *prefs_btn;
1457         GtkWidget *account_btn;
1458         */
1459         GtkWidget *next_btn;
1460         GtkWidget *delete_btn;
1461         GtkWidget *exec_btn;
1462         GtkWidget *compose_type_btn;
1463         GtkWidget *compose_type_arrow;
1464         GtkWidget *compose_box;
1465         GtkWidget *compose_label;
1466         GtkTooltips *tooltips;
1467
1468         toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1469                                   GTK_TOOLBAR_BOTH);
1470         gtk_container_add(GTK_CONTAINER(container), toolbar);
1471         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1472         gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1473         gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1474                                     GTK_TOOLBAR_SPACE_LINE);
1475
1476         CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1477         get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1478                                           _("Get"),
1479                                           _("Get new mail from current account"),
1480                                           "Get",
1481                                           icon_wid, toolbar_inc_cb, mainwin);
1482         CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1483         getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1484                                              _("Get all"),
1485                                              _("Get new mail from all accounts"),
1486                                              "Get all",
1487                                              icon_wid,
1488                                              toolbar_inc_all_cb,
1489                                              mainwin);
1490
1491         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1492
1493         CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1494         send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1495                                            _("Send"),
1496                                            _("Send queued message(s)"),
1497                                            "Send",
1498                                            icon_wid,
1499                                            toolbar_send_cb,
1500                                            mainwin);
1501
1502         /* to implement Leandro's "combined" compose buttons, we create
1503          * two sets of compose buttons, one for normal (text + icon) 
1504          * toolbar, and one for both text-only and icon-only toolbar;
1505          * we switch between those sets. */
1506
1507         /* insert compose mail button widget */                                    
1508
1509         compose_mail_btn = gtk_button_new();
1510         gtk_widget_show(compose_mail_btn);
1511         tooltips = gtk_tooltips_new();
1512         gtk_tooltips_set_tip(tooltips, compose_mail_btn, 
1513                                                  _("Compose email message"),
1514                                                  _("email"));
1515         compose_box = gtk_vbox_new(0, 0);
1516         gtk_widget_show(compose_box);
1517         
1518         gtk_container_add(GTK_CONTAINER(compose_mail_btn), compose_box);
1519         CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1520         gtk_box_pack_start(GTK_BOX(compose_box), icon_wid, FALSE, FALSE, 0);
1521
1522         compose_label = gtk_label_new(_("Email"));
1523         gtk_widget_show(compose_label);
1524         gtk_box_pack_start(GTK_BOX(compose_box), compose_label, FALSE, FALSE, 0);
1525         
1526         GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(compose_mail_btn), GTK_CAN_FOCUS);
1527         gtk_button_set_relief(GTK_BUTTON(compose_mail_btn), GTK_RELIEF_NONE);
1528         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar), compose_mail_btn,
1529                 NULL, NULL);
1530
1531         /* insert compose news button widget */
1532
1533         compose_news_btn = gtk_button_new();
1534         gtk_widget_show(compose_news_btn);
1535         tooltips = gtk_tooltips_new();
1536         gtk_tooltips_set_tip(tooltips, compose_news_btn,
1537                                                  _("Compose news article"),
1538                                                  _("news"));
1539         compose_box = gtk_vbox_new(0, 0);
1540         gtk_widget_show(compose_box);
1541         
1542         gtk_container_add(GTK_CONTAINER(compose_news_btn), compose_box);
1543         CREATE_TOOLBAR_ICON(stock_news_compose_xpm);
1544         gtk_box_pack_start(GTK_BOX(compose_box), icon_wid, FALSE, FALSE, 0);
1545
1546         compose_label = gtk_label_new(_("News"));
1547         gtk_widget_show(compose_label);
1548         gtk_box_pack_start(GTK_BOX(compose_box), compose_label, FALSE, FALSE, 0);
1549         
1550         GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(compose_news_btn), GTK_CAN_FOCUS);
1551         gtk_button_set_relief(GTK_BUTTON(compose_news_btn), GTK_RELIEF_NONE);
1552         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar), compose_news_btn,
1553                 NULL, NULL);
1554         
1555         /* insert compose btn plain */
1556         
1557         CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1558         compose_mail_btn_plain = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1559                                               _("Email"),
1560                                               _("Compose an email message"),
1561                                               "New",
1562                                               icon_wid,
1563                                               toolbar_compose_mail_cb,
1564                                               mainwin);
1565
1566         /* insert compose btn plain */
1567
1568         CREATE_TOOLBAR_ICON(stock_news_compose_xpm);
1569         compose_news_btn_plain = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1570                                               _("News"),
1571                                               _("Compose a news message"),
1572                                               "New",
1573                                               icon_wid,
1574                                               toolbar_compose_news_cb,
1575                                               mainwin);
1576
1577         /* insert compose button type widget */
1578         
1579         compose_type_btn = gtk_button_new();
1580         gtk_widget_show(compose_type_btn);
1581         
1582         compose_type_arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1583         gtk_widget_show(compose_type_arrow);
1584         
1585         gtk_container_add(GTK_CONTAINER(compose_type_btn), compose_type_arrow);
1586
1587         GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(compose_type_btn), GTK_CAN_FOCUS);
1588         gtk_button_set_relief(GTK_BUTTON(compose_type_btn), GTK_RELIEF_NONE);
1589
1590         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar), compose_type_btn,
1591                 NULL, NULL);
1592
1593         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1594         
1595         CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1596         reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1597                                             _("Reply"),
1598                                             _("Reply to the message"),
1599                                             "Reply",
1600                                             icon_wid,
1601                                             toolbar_reply_cb,
1602                                             mainwin);
1603         CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1604         replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1605                                                _("All"),
1606                                                _("Reply to all"),
1607                                                "Reply to all",
1608                                                icon_wid,
1609                                                toolbar_reply_to_all_cb,
1610                                                mainwin);
1611         CREATE_TOOLBAR_ICON(stock_mail_reply_to_author_xpm);
1612         replysender_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1613                                                   _("Sender"),
1614                                                   _("Reply to sender"),
1615                                                   "Reply to sender",
1616                                                   icon_wid,
1617                                                   toolbar_reply_to_sender_cb,
1618                                                   mainwin);
1619         CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1620         fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1621                                           _("Forward"),
1622                                           _("Forward the message"),
1623                                           "Fwd",
1624                                           icon_wid,
1625                                           toolbar_forward_cb,
1626                                           mainwin);
1627
1628         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1629
1630         CREATE_TOOLBAR_ICON(stock_close_xpm);
1631         delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1632                                           _("Delete"),
1633                                           _("Delete the message"),
1634                                           "Delete",
1635                                           icon_wid,
1636                                           toolbar_delete_cb,
1637                                           mainwin);
1638
1639         CREATE_TOOLBAR_ICON(stock_exec_xpm);
1640         exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1641                                            _("Execute"),
1642                                            _("Execute marked process"),
1643                                            "Execute",
1644                                            icon_wid,
1645                                            toolbar_exec_cb,
1646                                            mainwin);
1647
1648         CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1649         next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1650                                            _("Next"),
1651                                            _("Next unread message"),
1652                                            "Next unread",
1653                                            icon_wid,
1654                                            toolbar_next_unread_cb,
1655                                            mainwin);
1656
1657         /*
1658         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1659
1660         CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1661         prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1662                                             _("Prefs"),
1663                                             _("Common preference"),
1664                                             "Prefs",
1665                                             icon_wid,
1666                                             toolbar_prefs_cb,
1667                                             mainwin);
1668         CREATE_TOOLBAR_ICON(stock_properties_xpm);
1669         account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1670                                               _("Account"),
1671                                               _("Account setting"),
1672                                               "Account",
1673                                               icon_wid,
1674                                               toolbar_account_cb,
1675                                               mainwin);
1676         gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1677                            GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1678                            mainwin);
1679         */
1680
1681         gtk_signal_connect(GTK_OBJECT(compose_type_btn), "clicked",
1682                 GTK_SIGNAL_FUNC(toolbar_popup_compose_type_cb),
1683                 mainwin);
1684
1685         gtk_signal_connect(GTK_OBJECT(compose_mail_btn), "clicked",
1686                 GTK_SIGNAL_FUNC(toolbar_compose_mail_cb),
1687                 mainwin);
1688
1689         gtk_signal_connect(GTK_OBJECT(compose_news_btn), "clicked",
1690                 GTK_SIGNAL_FUNC(toolbar_compose_news_cb),
1691                 mainwin);
1692
1693         mainwin->toolbar         = toolbar;
1694         mainwin->get_btn         = get_btn;
1695         mainwin->getall_btn      = getall_btn;
1696         mainwin->compose_mail_btn = compose_mail_btn;
1697         mainwin->compose_news_btn = compose_news_btn;
1698         mainwin->compose_mail_btn_plain = compose_mail_btn_plain;
1699         mainwin->compose_news_btn_plain = compose_news_btn_plain;
1700         mainwin->reply_btn       = reply_btn;
1701         mainwin->replyall_btn    = replyall_btn;
1702         mainwin->replysender_btn = replysender_btn;
1703         mainwin->fwd_btn         = fwd_btn;
1704         mainwin->send_btn        = send_btn;
1705         /*
1706         mainwin->prefs_btn       = prefs_btn;
1707         mainwin->account_btn     = account_btn;
1708         */
1709         mainwin->next_btn        = next_btn;
1710         mainwin->delete_btn      = delete_btn;
1711         mainwin->exec_btn        = exec_btn;
1712
1713         gtk_widget_show_all(toolbar);
1714
1715         /* activate Leandro menu system */
1716         activate_compose_button(mainwin, 
1717                                 prefs_common.toolbar_style,
1718                                 mainwin->compose_btn_type);
1719 }
1720
1721 /* callback functions */
1722
1723 static void toolbar_popup_compose_type_cb       (GtkWidget      *widget,
1724                                  gpointer data)
1725 {
1726         MainWindow *mainwindow = (MainWindow *) data;
1727         GtkWidget *compose_menu, *compose_item;
1728
1729         g_return_if_fail(mainwindow != NULL);
1730         
1731         compose_menu = gtk_menu_new();
1732         
1733         compose_item = gtk_menu_item_new_with_label(_("Email message"));
1734         gtk_widget_show(compose_item);
1735         gtk_menu_append(GTK_MENU(compose_menu), compose_item);
1736         gtk_signal_connect(GTK_OBJECT(compose_item), "activate",
1737                 GTK_SIGNAL_FUNC(toolbar_popup_compose_type_set),
1738                 mainwindow);
1739         gtk_object_set_data(GTK_OBJECT(compose_item), "entry", GINT_TO_POINTER(COMPOSEBUTTON_MAIL));            
1740         
1741         compose_item = gtk_menu_item_new_with_label(_("News article"));
1742         gtk_widget_show(compose_item);
1743         gtk_menu_append(GTK_MENU(compose_menu), compose_item);
1744         gtk_signal_connect(GTK_OBJECT(compose_item), "activate",
1745                 GTK_SIGNAL_FUNC(toolbar_popup_compose_type_set),
1746                 mainwindow);
1747         gtk_object_set_data(GTK_OBJECT(compose_item), "entry", GINT_TO_POINTER(COMPOSEBUTTON_NEWS));            
1748                 
1749         gtk_menu_popup(GTK_MENU(compose_menu), NULL, NULL, NULL,
1750                 NULL, 1, 0);
1751 }
1752
1753 static void toolbar_popup_compose_type_set(GtkWidget *widget, gpointer data)
1754 {
1755         ComposeButtonType compose_type = GPOINTER_TO_INT( gtk_object_get_data(GTK_OBJECT(widget), "entry") );
1756         MainWindow *mainwindow = (MainWindow *) data;
1757
1758         mainwindow->compose_btn_type = compose_type;
1759
1760         activate_compose_button(mainwindow, prefs_common.toolbar_style, mainwindow->compose_btn_type);
1761 }       
1762
1763 static void toolbar_inc_cb      (GtkWidget      *widget,
1764                                  gpointer        data)
1765 {
1766         MainWindow *mainwin = (MainWindow *)data;
1767
1768         inc_mail_cb(mainwin, 0, NULL);
1769 }
1770
1771 static void toolbar_inc_all_cb  (GtkWidget      *widget,
1772                                  gpointer        data)
1773 {
1774         MainWindow *mainwin = (MainWindow *)data;
1775
1776         inc_all_account_mail_cb(mainwin, 0, NULL);
1777 }
1778
1779 static void toolbar_send_cb     (GtkWidget      *widget,
1780                                  gpointer        data)
1781 {
1782         MainWindow *mainwin = (MainWindow *)data;
1783
1784         send_queue_cb(mainwin, 0, NULL);
1785 }
1786
1787 static void toolbar_compose_cb  (GtkWidget      *widget,
1788                                  gpointer        data)
1789 {
1790         MainWindow *mainwin = (MainWindow *)data;
1791
1792         if (mainwin->compose_btn_type == COMPOSEBUTTON_MAIL)
1793                 compose_cb(mainwin, 0, NULL);
1794         else
1795                 compose_news_cb(mainwin, 0, NULL);
1796 }
1797
1798 static void toolbar_compose_news_cb     (GtkWidget      *widget,
1799                                  gpointer        data)
1800 {
1801         MainWindow *mainwin = (MainWindow *)data;
1802
1803         compose_news_cb(mainwin, 0, NULL);
1804 }
1805
1806 static void toolbar_compose_mail_cb     (GtkWidget      *widget,
1807                                  gpointer        data)
1808 {
1809         MainWindow *mainwin = (MainWindow *)data;
1810
1811         compose_mail_cb(mainwin, 0, NULL);
1812 }
1813
1814 static void toolbar_reply_cb    (GtkWidget      *widget,
1815                                  gpointer        data)
1816 {
1817         MainWindow *mainwin = (MainWindow *)data;
1818
1819         reply_cb(mainwin, COMPOSE_REPLY, NULL);
1820 }
1821
1822 static void toolbar_reply_to_all_cb     (GtkWidget      *widget,
1823                                          gpointer        data)
1824 {
1825         MainWindow *mainwin = (MainWindow *)data;
1826
1827         reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
1828 }
1829
1830 static void toolbar_reply_to_sender_cb  (GtkWidget      *widget,
1831                                          gpointer        data)
1832 {
1833         MainWindow *mainwin = (MainWindow *)data;
1834
1835         reply_cb(mainwin, COMPOSE_REPLY_TO_SENDER, NULL);
1836 }
1837
1838 static void toolbar_forward_cb  (GtkWidget      *widget,
1839                                  gpointer        data)
1840 {
1841         MainWindow *mainwin = (MainWindow *)data;
1842
1843         if (prefs_common.forward_as_attachment)
1844                 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
1845         else
1846                 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1847 }
1848
1849 static void toolbar_delete_cb   (GtkWidget      *widget,
1850                                  gpointer        data)
1851 {
1852         MainWindow *mainwin = (MainWindow *)data;
1853
1854         summary_delete(mainwin->summaryview);
1855 }
1856
1857 static void toolbar_exec_cb     (GtkWidget      *widget,
1858                                  gpointer        data)
1859 {
1860         MainWindow *mainwin = (MainWindow *)data;
1861
1862         summary_execute(mainwin->summaryview);
1863 }
1864
1865 static void toolbar_next_unread_cb      (GtkWidget      *widget,
1866                                          gpointer        data)
1867 {
1868         MainWindow *mainwin = (MainWindow *)data;
1869
1870         next_unread_cb(mainwin, 0, NULL);
1871 }
1872
1873 static void toolbar_prefs_cb    (GtkWidget      *widget,
1874                                  gpointer        data)
1875 {
1876         prefs_common_open();
1877 }
1878
1879 static void toolbar_account_cb  (GtkWidget      *widget,
1880                                  gpointer        data)
1881 {
1882         MainWindow *mainwin = (MainWindow *)data;
1883
1884         prefs_account_open_cb(mainwin, 0, NULL);
1885 }
1886
1887 static void toolbar_account_button_pressed(GtkWidget *widget,
1888                                            GdkEventButton *event,
1889                                            gpointer data)
1890 {
1891         MainWindow *mainwin = (MainWindow *)data;
1892
1893         if (!event) return;
1894         if (event->button != 3) return;
1895
1896         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1897                        event->button, event->time);
1898 }
1899
1900 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1901                                     gpointer data)
1902 {
1903         MainWindow *mainwin = (MainWindow *)data;
1904
1905         if (!event) return;
1906
1907         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1908                        event->button, event->time);
1909 }
1910
1911 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1912                                  gpointer data)
1913 {
1914         app_exit_cb(data, 0, widget);
1915
1916         return TRUE;
1917 }
1918
1919 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1920                            GtkWidget *widget)
1921 {
1922         main_window_add_mailbox(mainwin);
1923 }
1924
1925 static void add_mbox_cb(MainWindow *mainwin, guint action,
1926                         GtkWidget *widget)
1927 {
1928         main_window_add_mbox(mainwin);
1929 }
1930
1931 static void update_folderview_cb(MainWindow *mainwin, guint action,
1932                                  GtkWidget *widget)
1933 {
1934         summary_show(mainwin->summaryview, NULL, FALSE);
1935         folderview_update_all();
1936 }
1937
1938 static void new_folder_cb(MainWindow *mainwin, guint action,
1939                           GtkWidget *widget)
1940 {
1941         folderview_new_folder(mainwin->folderview);
1942 }
1943
1944 static void rename_folder_cb(MainWindow *mainwin, guint action,
1945                              GtkWidget *widget)
1946 {
1947         folderview_rename_folder(mainwin->folderview);
1948 }
1949
1950 static void delete_folder_cb(MainWindow *mainwin, guint action,
1951                              GtkWidget *widget)
1952 {
1953         folderview_delete_folder(mainwin->folderview);
1954 }
1955
1956 static void import_mbox_cb(MainWindow *mainwin, guint action,
1957                            GtkWidget *widget)
1958 {
1959         import_mbox(mainwin->summaryview->folder_item);
1960 }
1961
1962 static void export_mbox_cb(MainWindow *mainwin, guint action,
1963                            GtkWidget *widget)
1964 {
1965         export_mbox(mainwin->summaryview->folder_item);
1966 }
1967
1968 static void empty_trash_cb(MainWindow *mainwin, guint action,
1969                            GtkWidget *widget)
1970 {
1971         main_window_empty_trash(mainwin, TRUE);
1972 }
1973
1974 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1975 {
1976         summary_save_as(mainwin->summaryview);
1977 }
1978
1979 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1980 {
1981         summary_print(mainwin->summaryview);
1982 }
1983
1984 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1985 {
1986         if (prefs_common.confirm_on_exit) {
1987                 if (alertpanel(_("Exit"), _("Exit this program?"),
1988                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
1989                         return;
1990                 manage_window_focus_in(mainwin->window, NULL, NULL);
1991         }
1992
1993         app_will_exit(widget, mainwin);
1994 }
1995
1996 static void toggle_folder_cb(MainWindow *mainwin, guint action,
1997                              GtkWidget *widget)
1998 {
1999         switch (mainwin->type) {
2000         case SEPARATE_NONE:
2001         case SEPARATE_MESSAGE:
2002                 break;
2003         case SEPARATE_FOLDER:
2004                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2005                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2006                 else
2007                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2008                 break;
2009         case SEPARATE_BOTH:
2010                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2011                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2012                 else
2013                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2014                 break;
2015         }
2016 }
2017
2018 static void toggle_message_cb(MainWindow *mainwin, guint action,
2019                               GtkWidget *widget)
2020 {
2021         switch (mainwin->type) {
2022         case SEPARATE_NONE:
2023         case SEPARATE_FOLDER:
2024                 break;
2025         case SEPARATE_MESSAGE:
2026                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2027                         gtk_widget_show(mainwin->win.sep_message.messagewin);
2028                 else
2029                         gtk_widget_hide(mainwin->win.sep_message.messagewin);
2030                 break;
2031         case SEPARATE_BOTH:
2032                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2033                         gtk_widget_show(mainwin->win.sep_both.messagewin);
2034                 else
2035                         gtk_widget_hide(mainwin->win.sep_both.messagewin);
2036                 break;
2037         }
2038 }
2039
2040 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2041                               GtkWidget *widget)
2042 {
2043         activate_compose_button(mainwin, (ToolbarStyle)action, 
2044                         mainwin->compose_btn_type);
2045         
2046         switch ((ToolbarStyle)action) {
2047         case TOOLBAR_NONE:
2048                 gtk_widget_hide(mainwin->handlebox);
2049         case TOOLBAR_ICON:
2050                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2051                                       GTK_TOOLBAR_ICONS);
2052                 break;
2053         case TOOLBAR_TEXT:
2054                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2055                                       GTK_TOOLBAR_TEXT);
2056                 break;
2057         case TOOLBAR_BOTH:
2058                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2059                                       GTK_TOOLBAR_BOTH);
2060                 break;
2061         }
2062
2063         if (action != TOOLBAR_NONE) {
2064                 gtk_widget_show(mainwin->handlebox);
2065                 gtk_widget_queue_resize(mainwin->handlebox);
2066         }
2067
2068         mainwin->toolbar_style = (ToolbarStyle)action;
2069         prefs_common.toolbar_style = (ToolbarStyle)action;
2070 }
2071
2072 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2073                                 GtkWidget *widget)
2074 {
2075         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2076                 gtk_widget_show(mainwin->hbox_stat);
2077                 prefs_common.show_statusbar = TRUE;
2078         } else {
2079                 gtk_widget_hide(mainwin->hbox_stat);
2080                 prefs_common.show_statusbar = FALSE;
2081         }
2082 }
2083
2084 static void separate_widget_cb(GtkCheckMenuItem *checkitem, guint action)
2085 {
2086         MainWindow *mainwin;
2087         SeparateType type;
2088
2089         mainwin = (MainWindow *) gtk_object_get_data(GTK_OBJECT(checkitem), "mainwindow");
2090         g_return_if_fail(mainwin != NULL);
2091
2092         type = mainwin->type ^ action;
2093         main_window_separation_change(mainwin, type);
2094
2095         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2096         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2097 }
2098
2099 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2100                                 GtkWidget *widget)
2101 {
2102         addressbook_open(NULL);
2103 }
2104
2105 static void log_window_show_cb(MainWindow *mainwin, guint action,
2106                                GtkWidget *widget)
2107 {
2108         log_window_show(mainwin->logwin);
2109 }
2110
2111 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2112 {
2113         inc_mail(mainwin);
2114 }
2115
2116 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
2117                                     GtkWidget *widget)
2118 {
2119         inc_all_account_mail(mainwin);
2120 }
2121
2122 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2123 {
2124         GList *list;
2125
2126         if (procmsg_send_queue() < 0)
2127                 alertpanel_error(_("Sending queued message failed."));
2128
2129         statusbar_pop_all();
2130
2131         for (list = folder_get_list(); list != NULL; list = list->next) {
2132                 Folder *folder;
2133
2134                 folder = list->data;
2135                 if (folder->queue) {
2136                         folder_item_scan(folder->queue);
2137                         folderview_update_item(folder->queue, TRUE);
2138                 }
2139         }
2140 }
2141
2142 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2143 {
2144         if (mainwin->summaryview->folder_item) {
2145                 if (mainwin->summaryview->folder_item->folder->account != NULL
2146                     && mainwin->summaryview->folder_item->folder->account->protocol == A_NNTP)
2147                         compose_new_with_recipient(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item->path);
2148                 else
2149                         compose_new_with_folderitem(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item);
2150         }
2151         else
2152                 compose_new(NULL);
2153 }
2154
2155 static void compose_mail_cb(MainWindow *mainwin, guint action,
2156                             GtkWidget *widget)
2157 {
2158         PrefsAccount * ac;
2159         GList * list;
2160         GList * cur;
2161
2162         if (mainwin->summaryview->folder_item) {
2163                 ac = mainwin->summaryview->folder_item->folder->account;
2164                 if (ac && ac->protocol != A_NNTP) {
2165                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2166                         return;
2167                 }
2168         }
2169
2170         if(cur_account && (cur_account->protocol != A_NNTP)) {
2171                 compose_new_with_folderitem(cur_account, mainwin->summaryview->folder_item);
2172                 return;
2173         }
2174
2175         list = account_get_list();
2176         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2177                 ac = (PrefsAccount *) cur->data;
2178                 if (ac->protocol != A_NNTP) {
2179                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2180                         return;
2181                 }
2182         }
2183 }
2184
2185 static void compose_news_cb(MainWindow *mainwin, guint action,
2186                             GtkWidget *widget)
2187 {
2188         PrefsAccount * ac = NULL;
2189         GList * list;
2190         GList * cur;
2191
2192         if (mainwin->summaryview->folder_item) {
2193                 ac = mainwin->summaryview->folder_item->folder->account;
2194                 if (ac && ac->protocol == A_NNTP) {
2195                         compose_new_with_recipient
2196                                 (ac, mainwin->summaryview->folder_item->path);
2197                         return;
2198                 }
2199         }
2200
2201         list = account_get_list();
2202         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2203                 ac = (PrefsAccount *) cur->data;
2204                 if (ac->protocol == A_NNTP) {
2205                         compose_new(ac);
2206                         return;
2207                 }
2208         }
2209 }
2210
2211 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2212 {
2213         GList  *sel = GTK_CLIST(mainwin->summaryview->ctree)->selection;
2214         MsgInfo *msginfo;
2215
2216         msginfo = gtk_ctree_node_get_row_data
2217                 (GTK_CTREE(mainwin->summaryview->ctree),
2218                  mainwin->summaryview->selected);
2219
2220         if (!msginfo) return;
2221
2222         switch (action) {
2223         case COMPOSE_REPLY:
2224                 compose_reply(msginfo, prefs_common.reply_with_quote,
2225                               FALSE, FALSE);
2226                 break;
2227         case COMPOSE_REPLY_TO_SENDER:
2228                 compose_reply(msginfo, prefs_common.reply_with_quote,
2229                               FALSE, TRUE);
2230                 break;
2231         case COMPOSE_FOLLOWUP_AND_REPLY_TO:
2232                 compose_followup_and_reply_to(msginfo,
2233                                               prefs_common.reply_with_quote,
2234                                               FALSE, TRUE);
2235                 break;
2236         case COMPOSE_REPLY_TO_ALL:
2237                 compose_reply(msginfo, prefs_common.reply_with_quote,
2238                               TRUE, FALSE);
2239                 break;
2240         case COMPOSE_FORWARD:
2241                 if (!sel->next) {
2242                         compose_forward(NULL, msginfo, FALSE);
2243                         break;
2244                 }
2245                 /* if (sel->next) FALL_THROUGH */
2246         case COMPOSE_FORWARD_AS_ATTACH:
2247                 {
2248                         GSList *msginfo_list = NULL;
2249                         for ( ; sel != NULL; sel = sel->next)
2250                                 msginfo_list = g_slist_append(msginfo_list, 
2251                                         gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->summaryview->ctree),
2252                                                 GTK_CTREE_NODE(sel->data)));
2253                         compose_forward_multiple(NULL, msginfo_list);
2254                         g_slist_free(msginfo_list);
2255                 }                       
2256                 break;
2257         default:
2258                 g_warning("reply_cb(): invalid action type: %d\n", action);
2259         }
2260
2261         summary_set_marks_selected(mainwin->summaryview);
2262 }
2263
2264 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2265 {
2266         summary_move_to(mainwin->summaryview);
2267 }
2268
2269 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2270 {
2271         summary_copy_to(mainwin->summaryview);
2272 }
2273
2274 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2275 {
2276         summary_delete(mainwin->summaryview);
2277 }
2278
2279 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2280 {
2281         summary_open_msg(mainwin->summaryview);
2282 }
2283
2284 static void view_source_cb(MainWindow *mainwin, guint action,
2285                            GtkWidget *widget)
2286 {
2287         summary_view_source(mainwin->summaryview);
2288 }
2289
2290 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2291 {
2292         summary_reedit(mainwin->summaryview);
2293 }
2294
2295 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2296 {
2297         summary_mark(mainwin->summaryview);
2298 }
2299
2300 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2301 {
2302         summary_unmark(mainwin->summaryview);
2303 }
2304
2305 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2306                               GtkWidget *widget)
2307 {
2308         summary_mark_as_unread(mainwin->summaryview);
2309 }
2310
2311 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2312                             GtkWidget *widget)
2313 {
2314         summary_mark_as_read(mainwin->summaryview);
2315 }
2316
2317 static void set_charset_cb(MainWindow *mainwin, guint action,
2318                            GtkWidget *widget)
2319 {
2320         const gchar *str;
2321
2322         str = conv_get_charset_str((CharSet)action);
2323         g_free(prefs_common.force_charset);
2324         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2325
2326         summary_redisplay_msg(mainwin->summaryview);
2327
2328         debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
2329 }
2330
2331 void main_window_set_thread_option(MainWindow *mainwin)
2332 {
2333         GtkItemFactory *ifactory;
2334         gboolean no_item = FALSE;
2335
2336         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2337
2338         if (mainwin->summaryview == NULL)
2339                 no_item = TRUE;
2340         else if (mainwin->summaryview->folder_item == NULL)
2341                 no_item = TRUE;
2342
2343         if (no_item) {
2344                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
2345                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
2346         }
2347         else {
2348                 if (mainwin->summaryview->folder_item->prefs->enable_thread) {
2349                         menu_set_sensitive(ifactory,
2350                                            "/Summary/Thread view",   FALSE);
2351                         menu_set_sensitive(ifactory,
2352                                            "/Summary/Unthread view", TRUE);
2353                         summary_thread_build(mainwin->summaryview);
2354                 }
2355                 else {
2356                         menu_set_sensitive(ifactory,
2357                                            "/Summary/Thread view",   TRUE);
2358                         menu_set_sensitive(ifactory,
2359                                            "/Summary/Unthread view", FALSE);
2360                         summary_unthread(mainwin->summaryview);
2361                 }
2362                 prefs_folder_item_save_config(mainwin->summaryview->folder_item);
2363         }
2364 }
2365
2366 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2367 {
2368         mainwin->summaryview->folder_item->prefs->enable_thread =
2369                 !mainwin->summaryview->folder_item->prefs->enable_thread;
2370         main_window_set_thread_option(mainwin);
2371
2372         /*
2373         if (0 == action) {
2374                 summary_thread_build(mainwin->summaryview);
2375                 mainwin->summaryview->folder_item->prefs->enable_thread =
2376                         TRUE;
2377                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
2378                 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
2379         } else {
2380                 summary_unthread(mainwin->summaryview);
2381                 mainwin->summaryview->folder_item->prefs->enable_thread =
2382                         FALSE;
2383                 menu_set_sensitive(ifactory, "/Summary/Thread view",   TRUE);
2384                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
2385         }
2386         */
2387 }
2388
2389 static void set_display_item_cb(MainWindow *mainwin, guint action,
2390                                 GtkWidget *widget)
2391 {
2392         prefs_summary_display_item_set();
2393 }
2394
2395 static void sort_summary_cb(MainWindow *mainwin, guint action,
2396                             GtkWidget *widget)
2397 {
2398         summary_sort(mainwin->summaryview, (SummarySortType)action);
2399 }
2400
2401 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2402                                   GtkWidget *widget)
2403 {
2404         summary_attract_by_subject(mainwin->summaryview);
2405 }
2406
2407 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2408                                  GtkWidget *widget)
2409 {
2410         summary_delete_duplicated(mainwin->summaryview);
2411 }
2412
2413 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2414 {
2415         summary_filter(mainwin->summaryview);
2416 }
2417
2418 static void execute_summary_cb(MainWindow *mainwin, guint action,
2419                                GtkWidget *widget)
2420 {
2421         summary_execute(mainwin->summaryview);
2422 }
2423
2424 static void update_summary_cb(MainWindow *mainwin, guint action,
2425                               GtkWidget *widget)
2426 {
2427         FolderItem *fitem;
2428         FolderView *folderview = mainwin->folderview;
2429
2430         if (!mainwin->summaryview->folder_item) return;
2431         if (!folderview->opened) return;
2432
2433         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2434                                             folderview->opened);
2435         if (!fitem) return;
2436
2437         summary_show(mainwin->summaryview, fitem, TRUE);
2438 }
2439
2440 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2441 {
2442         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2443 }
2444
2445 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2446 {
2447         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2448 }
2449
2450 static void next_unread_cb(MainWindow *mainwin, guint action,
2451                            GtkWidget *widget)
2452 {
2453         summary_select_next_unread(mainwin->summaryview);
2454 }
2455
2456 static void next_marked_cb(MainWindow *mainwin, guint action,
2457                            GtkWidget *widget)
2458 {
2459         summary_select_next_marked(mainwin->summaryview);
2460 }
2461
2462 static void prev_marked_cb(MainWindow *mainwin, guint action,
2463                            GtkWidget *widget)
2464 {
2465         summary_select_prev_marked(mainwin->summaryview);
2466 }
2467
2468 static void goto_folder_cb(MainWindow *mainwin, guint action,
2469                            GtkWidget *widget)
2470 {
2471         FolderItem *to_folder;
2472
2473         to_folder = foldersel_folder_sel(NULL, NULL);
2474
2475         if (to_folder)
2476                 folderview_select(mainwin->folderview, to_folder);
2477 }
2478
2479 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2480 {
2481         messageview_copy_clipboard(mainwin->messageview);
2482 }
2483
2484 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2485 {
2486         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2487                 summary_select_all(mainwin->summaryview);
2488         else if (mainwin->summaryview->msg_is_toggled_on &&
2489                  GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2490                 messageview_select_all(mainwin->messageview);
2491 }
2492
2493 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2494                                  GtkWidget *widget)
2495 {
2496         prefs_common_open();
2497 }
2498
2499 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2500                                  GtkWidget *widget)
2501 {
2502         prefs_filter_open();
2503 }
2504
2505 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2506                                   GtkWidget *widget)
2507 {
2508         prefs_scoring_open(NULL);
2509 }
2510
2511 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2512                                     GtkWidget *widget)
2513 {
2514         prefs_filtering_open();
2515 }
2516
2517 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2518                                   GtkWidget *widget)
2519 {
2520         if (!cur_account) {
2521                 new_account_cb(mainwin, 0, widget);
2522         } else {
2523                 gboolean prev_default = cur_account->is_default;
2524
2525                 prefs_account_open(cur_account);
2526                 if (!prev_default && cur_account->is_default)
2527                         account_set_as_default(cur_account);
2528                 account_save_config_all();
2529                 account_set_menu();
2530                 main_window_reflect_prefs_all();
2531         }
2532 }
2533
2534 static void new_account_cb(MainWindow *mainwin, guint action,
2535                            GtkWidget *widget)
2536 {
2537         account_edit_open();
2538         if (!compose_get_compose_list()) account_add();
2539 }
2540
2541 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2542 {
2543         cur_account = (PrefsAccount *)data;
2544         main_window_reflect_prefs_all();
2545 }
2546
2547 static void manual_open_cb(MainWindow *mainwin, guint action,
2548                            GtkWidget *widget)
2549 {
2550         manual_open((ManualLang)action);
2551 }
2552
2553 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2554 {
2555         MainWindow *mainwin = (MainWindow *)data;
2556         gchar *str;
2557
2558         if (item->path)
2559                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2560                                       LOCAL_FOLDER(folder)->rootpath,
2561                                       G_DIR_SEPARATOR,
2562                                       item->path);
2563         else
2564                 str = g_strdup_printf(_("Scanning folder %s ..."),
2565                                       LOCAL_FOLDER(folder)->rootpath);
2566
2567         STATUSBAR_PUSH(mainwin, str);
2568         STATUSBAR_POP(mainwin);
2569         g_free(str);
2570 }
2571
2572 static void activate_compose_button (MainWindow *mainwin,
2573                                 ToolbarStyle style,
2574                                 ComposeButtonType type)
2575 {
2576         if (style == TOOLBAR_NONE) 
2577                 return;
2578
2579         if (style == TOOLBAR_BOTH) {    
2580                 gtk_widget_hide(mainwin->compose_mail_btn_plain);
2581                 gtk_widget_hide(mainwin->compose_news_btn_plain);
2582                 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? mainwin->compose_mail_btn 
2583                         : mainwin->compose_news_btn);
2584                 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? mainwin->compose_news_btn
2585                         : mainwin->compose_mail_btn);
2586                 mainwin->compose_btn_type = type;       
2587         }
2588         else {
2589                 gtk_widget_hide(mainwin->compose_news_btn);
2590                 gtk_widget_hide(mainwin->compose_mail_btn);
2591                 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? mainwin->compose_mail_btn_plain 
2592                         : mainwin->compose_news_btn_plain);
2593                 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? mainwin->compose_news_btn_plain
2594                         : mainwin->compose_mail_btn_plain);
2595                 mainwin->compose_btn_type = type;               
2596         }
2597 }
2598