a87ded6508afb74ec70f09635eb0167d53e7792f
[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         gdk_window_show(mainwin->window->window);
1218
1219         debug_print("window position: x = %d, y = %d\n", x, y);
1220
1221         switch (mainwin->type) {
1222         case SEPARATE_FOLDER:
1223                 widget = mainwin->win.sep_folder.folderwin;
1224                 gdk_window_get_origin(widget->window, &x, &y);
1225                 x %= sx; if (x < 0) x += sx;
1226                 y %= sy; if (y < 0) y += sy;
1227                 gdk_window_move(widget->window, x, y);
1228                 gdk_window_raise(widget->window);
1229                 break;
1230         case SEPARATE_MESSAGE:
1231                 widget = mainwin->win.sep_message.messagewin;
1232                 gdk_window_get_origin(widget->window, &x, &y);
1233                 x %= sx; if (x < 0) x += sx;
1234                 y %= sy; if (y < 0) y += sy;
1235                 gdk_window_move(widget->window, x, y);
1236                 gdk_window_raise(widget->window);
1237                 break;
1238         case SEPARATE_BOTH:
1239                 widget = mainwin->win.sep_both.folderwin;
1240                 gdk_window_get_origin(widget->window, &x, &y);
1241                 x %= sx; if (x < 0) x += sx;
1242                 y %= sy; if (y < 0) y += sy;
1243                 gdk_window_move(widget->window, x, y);
1244                 gdk_window_raise(widget->window);
1245                 widget = mainwin->win.sep_both.messagewin;
1246                 gdk_window_get_origin(widget->window, &x, &y);
1247                 x %= sx; if (x < 0) x += sx;
1248                 y %= sy; if (y < 0) y += sy;
1249                 gdk_window_move(widget->window, x, y);
1250                 gdk_window_raise(widget->window);
1251                 break;
1252         default:
1253                 break;
1254         }
1255 }
1256
1257 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1258 {
1259         GtkWidget *folderwin = NULL;
1260         GtkWidget *messagewin = NULL;
1261         GtkWidget *hpaned;
1262         GtkWidget *vpaned;
1263         GtkWidget *vbox_body = mainwin->vbox_body;
1264
1265         debug_print(_("Setting widgets..."));
1266
1267         /* create separated window(s) if needed */
1268         if (type & SEPARATE_FOLDER) {
1269                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1270                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1271                                       TRUE, TRUE, FALSE);
1272                 gtk_widget_set_usize(folderwin, -1,
1273                                      prefs_common.mainview_height);
1274                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1275                                                BORDER_WIDTH);
1276                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1277                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1278                                    NULL);
1279         }
1280         if (type & SEPARATE_MESSAGE) {
1281                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1282                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1283                                       TRUE, TRUE, FALSE);
1284                 gtk_widget_set_usize
1285                         (messagewin, prefs_common.mainview_width,
1286                          prefs_common.mainview_height
1287                          - prefs_common.summaryview_height
1288                          + DEFAULT_HEADERVIEW_HEIGHT);
1289                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1290                                                BORDER_WIDTH);
1291                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1292                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1293                                    NULL);
1294         }
1295
1296         switch (type) {
1297         case SEPARATE_NONE:
1298                 hpaned = gtk_hpaned_new();
1299                 gtk_widget_show(hpaned);
1300                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1301                 gtk_paned_add1(GTK_PANED(hpaned),
1302                                GTK_WIDGET_PTR(mainwin->folderview));
1303
1304                 vpaned = gtk_vpaned_new();
1305                 if (mainwin->summaryview->msg_is_toggled_on) {
1306                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1307                         gtk_paned_add1(GTK_PANED(vpaned),
1308                                        GTK_WIDGET_PTR(mainwin->summaryview));
1309                 } else {
1310                         gtk_paned_add2(GTK_PANED(hpaned),
1311                                        GTK_WIDGET_PTR(mainwin->summaryview));
1312                         gtk_widget_ref(vpaned);
1313                 }
1314                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1315                                      prefs_common.summaryview_width,
1316                                      prefs_common.summaryview_height);
1317                 gtk_paned_add2(GTK_PANED(vpaned),
1318                                GTK_WIDGET_PTR(mainwin->messageview));
1319                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1320                                      prefs_common.mainview_width, -1);
1321                 gtk_widget_set_usize(mainwin->window,
1322                                      prefs_common.folderview_width +
1323                                      prefs_common.mainview_width,
1324                                      prefs_common.mainwin_height);
1325                 gtk_widget_show_all(vpaned);
1326
1327                 mainwin->win.sep_none.hpaned = hpaned;
1328                 mainwin->win.sep_none.vpaned = vpaned;
1329                 break;
1330         case SEPARATE_FOLDER:
1331                 vpaned = gtk_vpaned_new();
1332                 if (mainwin->summaryview->msg_is_toggled_on) {
1333                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1334                                            TRUE, TRUE, 0);
1335                         gtk_paned_add1(GTK_PANED(vpaned),
1336                                        GTK_WIDGET_PTR(mainwin->summaryview));
1337                 } else {
1338                         gtk_box_pack_start(GTK_BOX(vbox_body),
1339                                            GTK_WIDGET_PTR(mainwin->summaryview),
1340                                            TRUE, TRUE, 0);
1341                         gtk_widget_ref(vpaned);
1342                 }
1343                 gtk_paned_add2(GTK_PANED(vpaned),
1344                                GTK_WIDGET_PTR(mainwin->messageview));
1345                 gtk_widget_show_all(vpaned);
1346                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1347                                      prefs_common.summaryview_width,
1348                                      prefs_common.summaryview_height);
1349                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1350                                      prefs_common.mainview_width, -1);
1351                 gtk_widget_set_usize(mainwin->window,
1352                                      prefs_common.mainview_width,
1353                                      prefs_common.mainview_height);
1354
1355                 gtk_container_add(GTK_CONTAINER(folderwin),
1356                                   GTK_WIDGET_PTR(mainwin->folderview));
1357
1358                 mainwin->win.sep_folder.folderwin = folderwin;
1359                 mainwin->win.sep_folder.vpaned    = vpaned;
1360
1361                 gtk_widget_show_all(folderwin);
1362                 break;
1363         case SEPARATE_MESSAGE:
1364                 hpaned = gtk_hpaned_new();
1365                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1366
1367                 gtk_paned_add1(GTK_PANED(hpaned),
1368                                GTK_WIDGET_PTR(mainwin->folderview));
1369                 gtk_paned_add2(GTK_PANED(hpaned),
1370                                GTK_WIDGET_PTR(mainwin->summaryview));
1371                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1372                                      prefs_common.summaryview_width,
1373                                      prefs_common.summaryview_height);
1374                 gtk_widget_set_usize(mainwin->window,
1375                                      prefs_common.folderview_width +
1376                                      prefs_common.mainview_width,
1377                                      prefs_common.mainwin_height);
1378                 gtk_widget_show_all(hpaned);
1379                 gtk_container_add(GTK_CONTAINER(messagewin),
1380                                   GTK_WIDGET_PTR(mainwin->messageview));
1381
1382                 mainwin->win.sep_message.messagewin = messagewin;
1383                 mainwin->win.sep_message.hpaned     = hpaned;
1384
1385                 gtk_widget_show_all(messagewin);
1386                 break;
1387         case SEPARATE_BOTH:
1388                 gtk_box_pack_start(GTK_BOX(vbox_body),
1389                                    GTK_WIDGET_PTR(mainwin->summaryview),
1390                                    TRUE, TRUE, 0);
1391                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1392                                      prefs_common.summaryview_width,
1393                                      prefs_common.summaryview_height);
1394                 gtk_widget_set_usize(mainwin->window,
1395                                      prefs_common.mainview_width,
1396                                      prefs_common.mainwin_height);
1397                 gtk_container_add(GTK_CONTAINER(folderwin),
1398                                   GTK_WIDGET_PTR(mainwin->folderview));
1399                 gtk_container_add(GTK_CONTAINER(messagewin),
1400                                   GTK_WIDGET_PTR(mainwin->messageview));
1401
1402                 mainwin->win.sep_both.folderwin = folderwin;
1403                 mainwin->win.sep_both.messagewin = messagewin;
1404
1405                 gtk_widget_show_all(folderwin);
1406                 gtk_widget_show_all(messagewin);
1407                 break;
1408         }
1409
1410         mainwin->type = type;
1411
1412         debug_print(_("done.\n"));
1413 }
1414
1415 #include "pixmaps/stock_mail_receive.xpm"
1416 #include "pixmaps/stock_mail_receive_all.xpm"
1417 #include "pixmaps/stock_mail_compose.xpm"
1418 #include "pixmaps/stock_news_compose.xpm"
1419 #include "pixmaps/stock_mail_reply.xpm"
1420 #include "pixmaps/stock_mail_reply_to_all.xpm"
1421 #include "pixmaps/stock_mail_reply_to_author.xpm"
1422 #include "pixmaps/stock_mail_forward.xpm"
1423 #include "pixmaps/stock_mail_send.xpm"
1424 #include "pixmaps/stock_preferences.xpm"
1425 #include "pixmaps/stock_properties.xpm"
1426 #include "pixmaps/stock_down_arrow.xpm"
1427 #include "pixmaps/stock_close.xpm"
1428 #include "pixmaps/stock_exec.xpm"
1429
1430 #define CREATE_TOOLBAR_ICON(xpm_d) \
1431 { \
1432         icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1433                                             &container->style->white, \
1434                                             xpm_d); \
1435         icon_wid = gtk_pixmap_new(icon, mask); \
1436 }
1437
1438 static void main_window_toolbar_create(MainWindow *mainwin,
1439                                        GtkWidget *container)
1440 {
1441         GtkWidget *toolbar;
1442         GdkPixmap *icon;
1443         GdkBitmap *mask;
1444         GtkWidget *icon_wid;
1445         GtkWidget *get_btn;
1446         GtkWidget *getall_btn;
1447         GtkWidget *compose_mail_btn;
1448         GtkWidget *compose_news_btn;
1449         GtkWidget *compose_mail_btn_plain;
1450         GtkWidget *compose_news_btn_plain;
1451         GtkWidget *reply_btn;
1452         GtkWidget *replyall_btn;
1453         GtkWidget *replysender_btn;
1454         GtkWidget *fwd_btn;
1455         GtkWidget *send_btn;
1456         /*
1457         GtkWidget *prefs_btn;
1458         GtkWidget *account_btn;
1459         */
1460         GtkWidget *next_btn;
1461         GtkWidget *delete_btn;
1462         GtkWidget *exec_btn;
1463         GtkWidget *compose_type_btn;
1464         GtkWidget *compose_type_arrow;
1465         GtkWidget *compose_box;
1466         GtkWidget *compose_label;
1467         GtkTooltips *tooltips;
1468
1469         toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1470                                   GTK_TOOLBAR_BOTH);
1471         gtk_container_add(GTK_CONTAINER(container), toolbar);
1472         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1473         gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1474         gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1475                                     GTK_TOOLBAR_SPACE_LINE);
1476
1477         CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1478         get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1479                                           _("Get"),
1480                                           _("Get new mail from current account"),
1481                                           "Get",
1482                                           icon_wid, toolbar_inc_cb, mainwin);
1483         CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1484         getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1485                                              _("Get all"),
1486                                              _("Get new mail from all accounts"),
1487                                              "Get all",
1488                                              icon_wid,
1489                                              toolbar_inc_all_cb,
1490                                              mainwin);
1491
1492         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1493
1494         CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1495         send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1496                                            _("Send"),
1497                                            _("Send queued message(s)"),
1498                                            "Send",
1499                                            icon_wid,
1500                                            toolbar_send_cb,
1501                                            mainwin);
1502
1503         /* to implement Leandro's "combined" compose buttons, we create
1504          * two sets of compose buttons, one for normal (text + icon) 
1505          * toolbar, and one for both text-only and icon-only toolbar;
1506          * we switch between those sets. */
1507
1508         /* insert compose mail button widget */                                    
1509
1510         compose_mail_btn = gtk_button_new();
1511         gtk_widget_show(compose_mail_btn);
1512         tooltips = gtk_tooltips_new();
1513         gtk_tooltips_set_tip(tooltips, compose_mail_btn, 
1514                                                  _("Compose email message"),
1515                                                  _("email"));
1516         compose_box = gtk_vbox_new(0, 0);
1517         gtk_widget_show(compose_box);
1518         
1519         gtk_container_add(GTK_CONTAINER(compose_mail_btn), compose_box);
1520         CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1521         gtk_box_pack_start(GTK_BOX(compose_box), icon_wid, FALSE, FALSE, 0);
1522
1523         compose_label = gtk_label_new(_("Email"));
1524         gtk_widget_show(compose_label);
1525         gtk_box_pack_start(GTK_BOX(compose_box), compose_label, FALSE, FALSE, 0);
1526         
1527         GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(compose_mail_btn), GTK_CAN_FOCUS);
1528         gtk_button_set_relief(GTK_BUTTON(compose_mail_btn), GTK_RELIEF_NONE);
1529         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar), compose_mail_btn,
1530                 NULL, NULL);
1531
1532         /* insert compose news button widget */
1533
1534         compose_news_btn = gtk_button_new();
1535         gtk_widget_show(compose_news_btn);
1536         tooltips = gtk_tooltips_new();
1537         gtk_tooltips_set_tip(tooltips, compose_news_btn,
1538                                                  _("Compose news article"),
1539                                                  _("news"));
1540         compose_box = gtk_vbox_new(0, 0);
1541         gtk_widget_show(compose_box);
1542         
1543         gtk_container_add(GTK_CONTAINER(compose_news_btn), compose_box);
1544         CREATE_TOOLBAR_ICON(stock_news_compose_xpm);
1545         gtk_box_pack_start(GTK_BOX(compose_box), icon_wid, FALSE, FALSE, 0);
1546
1547         compose_label = gtk_label_new(_("News"));
1548         gtk_widget_show(compose_label);
1549         gtk_box_pack_start(GTK_BOX(compose_box), compose_label, FALSE, FALSE, 0);
1550         
1551         GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(compose_news_btn), GTK_CAN_FOCUS);
1552         gtk_button_set_relief(GTK_BUTTON(compose_news_btn), GTK_RELIEF_NONE);
1553         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar), compose_news_btn,
1554                 NULL, NULL);
1555         
1556         /* insert compose btn plain */
1557         
1558         CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1559         compose_mail_btn_plain = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1560                                               _("Email"),
1561                                               _("Compose an email message"),
1562                                               "New",
1563                                               icon_wid,
1564                                               toolbar_compose_mail_cb,
1565                                               mainwin);
1566
1567         /* insert compose btn plain */
1568
1569         CREATE_TOOLBAR_ICON(stock_news_compose_xpm);
1570         compose_news_btn_plain = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1571                                               _("News"),
1572                                               _("Compose a news message"),
1573                                               "New",
1574                                               icon_wid,
1575                                               toolbar_compose_news_cb,
1576                                               mainwin);
1577
1578         /* insert compose button type widget */
1579         
1580         compose_type_btn = gtk_button_new();
1581         gtk_widget_show(compose_type_btn);
1582         
1583         compose_type_arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1584         gtk_widget_show(compose_type_arrow);
1585         
1586         gtk_container_add(GTK_CONTAINER(compose_type_btn), compose_type_arrow);
1587
1588         GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(compose_type_btn), GTK_CAN_FOCUS);
1589         gtk_button_set_relief(GTK_BUTTON(compose_type_btn), GTK_RELIEF_NONE);
1590
1591         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar), compose_type_btn,
1592                 NULL, NULL);
1593
1594         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1595         
1596         CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1597         reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1598                                             _("Reply"),
1599                                             _("Reply to the message"),
1600                                             "Reply",
1601                                             icon_wid,
1602                                             toolbar_reply_cb,
1603                                             mainwin);
1604         CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1605         replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1606                                                _("All"),
1607                                                _("Reply to all"),
1608                                                "Reply to all",
1609                                                icon_wid,
1610                                                toolbar_reply_to_all_cb,
1611                                                mainwin);
1612         CREATE_TOOLBAR_ICON(stock_mail_reply_to_author_xpm);
1613         replysender_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1614                                                   _("Sender"),
1615                                                   _("Reply to sender"),
1616                                                   "Reply to sender",
1617                                                   icon_wid,
1618                                                   toolbar_reply_to_sender_cb,
1619                                                   mainwin);
1620         CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1621         fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1622                                           _("Forward"),
1623                                           _("Forward the message"),
1624                                           "Fwd",
1625                                           icon_wid,
1626                                           toolbar_forward_cb,
1627                                           mainwin);
1628
1629         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1630
1631         CREATE_TOOLBAR_ICON(stock_close_xpm);
1632         delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1633                                           _("Delete"),
1634                                           _("Delete the message"),
1635                                           "Delete",
1636                                           icon_wid,
1637                                           toolbar_delete_cb,
1638                                           mainwin);
1639
1640         CREATE_TOOLBAR_ICON(stock_exec_xpm);
1641         exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1642                                            _("Execute"),
1643                                            _("Execute marked process"),
1644                                            "Execute",
1645                                            icon_wid,
1646                                            toolbar_exec_cb,
1647                                            mainwin);
1648
1649         CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1650         next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1651                                            _("Next"),
1652                                            _("Next unread message"),
1653                                            "Next unread",
1654                                            icon_wid,
1655                                            toolbar_next_unread_cb,
1656                                            mainwin);
1657
1658         /*
1659         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1660
1661         CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1662         prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1663                                             _("Prefs"),
1664                                             _("Common preference"),
1665                                             "Prefs",
1666                                             icon_wid,
1667                                             toolbar_prefs_cb,
1668                                             mainwin);
1669         CREATE_TOOLBAR_ICON(stock_properties_xpm);
1670         account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1671                                               _("Account"),
1672                                               _("Account setting"),
1673                                               "Account",
1674                                               icon_wid,
1675                                               toolbar_account_cb,
1676                                               mainwin);
1677         gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1678                            GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1679                            mainwin);
1680         */
1681
1682         gtk_signal_connect(GTK_OBJECT(compose_type_btn), "clicked",
1683                 GTK_SIGNAL_FUNC(toolbar_popup_compose_type_cb),
1684                 mainwin);
1685
1686         gtk_signal_connect(GTK_OBJECT(compose_mail_btn), "clicked",
1687                 GTK_SIGNAL_FUNC(toolbar_compose_mail_cb),
1688                 mainwin);
1689
1690         gtk_signal_connect(GTK_OBJECT(compose_news_btn), "clicked",
1691                 GTK_SIGNAL_FUNC(toolbar_compose_news_cb),
1692                 mainwin);
1693
1694         mainwin->toolbar         = toolbar;
1695         mainwin->get_btn         = get_btn;
1696         mainwin->getall_btn      = getall_btn;
1697         mainwin->compose_mail_btn = compose_mail_btn;
1698         mainwin->compose_news_btn = compose_news_btn;
1699         mainwin->compose_mail_btn_plain = compose_mail_btn_plain;
1700         mainwin->compose_news_btn_plain = compose_news_btn_plain;
1701         mainwin->reply_btn       = reply_btn;
1702         mainwin->replyall_btn    = replyall_btn;
1703         mainwin->replysender_btn = replysender_btn;
1704         mainwin->fwd_btn         = fwd_btn;
1705         mainwin->send_btn        = send_btn;
1706         /*
1707         mainwin->prefs_btn       = prefs_btn;
1708         mainwin->account_btn     = account_btn;
1709         */
1710         mainwin->next_btn        = next_btn;
1711         mainwin->delete_btn      = delete_btn;
1712         mainwin->exec_btn        = exec_btn;
1713
1714         gtk_widget_show_all(toolbar);
1715
1716         /* activate Leandro menu system */
1717         activate_compose_button(mainwin, 
1718                                 prefs_common.toolbar_style,
1719                                 mainwin->compose_btn_type);
1720 }
1721
1722 /* callback functions */
1723
1724 static void toolbar_popup_compose_type_cb       (GtkWidget      *widget,
1725                                  gpointer data)
1726 {
1727         MainWindow *mainwindow = (MainWindow *) data;
1728         GtkWidget *compose_menu, *compose_item;
1729
1730         g_return_if_fail(mainwindow != NULL);
1731         
1732         compose_menu = gtk_menu_new();
1733         
1734         compose_item = gtk_menu_item_new_with_label(_("Email message"));
1735         gtk_widget_show(compose_item);
1736         gtk_menu_append(GTK_MENU(compose_menu), compose_item);
1737         gtk_signal_connect(GTK_OBJECT(compose_item), "activate",
1738                 GTK_SIGNAL_FUNC(toolbar_popup_compose_type_set),
1739                 mainwindow);
1740         gtk_object_set_data(GTK_OBJECT(compose_item), "entry", GINT_TO_POINTER(COMPOSEBUTTON_MAIL));            
1741         
1742         compose_item = gtk_menu_item_new_with_label(_("News article"));
1743         gtk_widget_show(compose_item);
1744         gtk_menu_append(GTK_MENU(compose_menu), compose_item);
1745         gtk_signal_connect(GTK_OBJECT(compose_item), "activate",
1746                 GTK_SIGNAL_FUNC(toolbar_popup_compose_type_set),
1747                 mainwindow);
1748         gtk_object_set_data(GTK_OBJECT(compose_item), "entry", GINT_TO_POINTER(COMPOSEBUTTON_NEWS));            
1749                 
1750         gtk_menu_popup(GTK_MENU(compose_menu), NULL, NULL, NULL,
1751                 NULL, 1, 0);
1752 }
1753
1754 static void toolbar_popup_compose_type_set(GtkWidget *widget, gpointer data)
1755 {
1756         ComposeButtonType compose_type = GPOINTER_TO_INT( gtk_object_get_data(GTK_OBJECT(widget), "entry") );
1757         MainWindow *mainwindow = (MainWindow *) data;
1758
1759         mainwindow->compose_btn_type = compose_type;
1760
1761         activate_compose_button(mainwindow, prefs_common.toolbar_style, mainwindow->compose_btn_type);
1762 }       
1763
1764 static void toolbar_inc_cb      (GtkWidget      *widget,
1765                                  gpointer        data)
1766 {
1767         MainWindow *mainwin = (MainWindow *)data;
1768
1769         inc_mail_cb(mainwin, 0, NULL);
1770 }
1771
1772 static void toolbar_inc_all_cb  (GtkWidget      *widget,
1773                                  gpointer        data)
1774 {
1775         MainWindow *mainwin = (MainWindow *)data;
1776
1777         inc_all_account_mail_cb(mainwin, 0, NULL);
1778 }
1779
1780 static void toolbar_send_cb     (GtkWidget      *widget,
1781                                  gpointer        data)
1782 {
1783         MainWindow *mainwin = (MainWindow *)data;
1784
1785         send_queue_cb(mainwin, 0, NULL);
1786 }
1787
1788 static void toolbar_compose_cb  (GtkWidget      *widget,
1789                                  gpointer        data)
1790 {
1791         MainWindow *mainwin = (MainWindow *)data;
1792
1793         if (mainwin->compose_btn_type == COMPOSEBUTTON_MAIL)
1794                 compose_cb(mainwin, 0, NULL);
1795         else
1796                 compose_news_cb(mainwin, 0, NULL);
1797 }
1798
1799 static void toolbar_compose_news_cb     (GtkWidget      *widget,
1800                                  gpointer        data)
1801 {
1802         MainWindow *mainwin = (MainWindow *)data;
1803
1804         compose_news_cb(mainwin, 0, NULL);
1805 }
1806
1807 static void toolbar_compose_mail_cb     (GtkWidget      *widget,
1808                                  gpointer        data)
1809 {
1810         MainWindow *mainwin = (MainWindow *)data;
1811
1812         compose_mail_cb(mainwin, 0, NULL);
1813 }
1814
1815 static void toolbar_reply_cb    (GtkWidget      *widget,
1816                                  gpointer        data)
1817 {
1818         MainWindow *mainwin = (MainWindow *)data;
1819
1820         reply_cb(mainwin, COMPOSE_REPLY, NULL);
1821 }
1822
1823 static void toolbar_reply_to_all_cb     (GtkWidget      *widget,
1824                                          gpointer        data)
1825 {
1826         MainWindow *mainwin = (MainWindow *)data;
1827
1828         reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
1829 }
1830
1831 static void toolbar_reply_to_sender_cb  (GtkWidget      *widget,
1832                                          gpointer        data)
1833 {
1834         MainWindow *mainwin = (MainWindow *)data;
1835
1836         reply_cb(mainwin, COMPOSE_REPLY_TO_SENDER, NULL);
1837 }
1838
1839 static void toolbar_forward_cb  (GtkWidget      *widget,
1840                                  gpointer        data)
1841 {
1842         MainWindow *mainwin = (MainWindow *)data;
1843
1844         if (prefs_common.forward_as_attachment)
1845                 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
1846         else
1847                 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1848 }
1849
1850 static void toolbar_delete_cb   (GtkWidget      *widget,
1851                                  gpointer        data)
1852 {
1853         MainWindow *mainwin = (MainWindow *)data;
1854
1855         summary_delete(mainwin->summaryview);
1856 }
1857
1858 static void toolbar_exec_cb     (GtkWidget      *widget,
1859                                  gpointer        data)
1860 {
1861         MainWindow *mainwin = (MainWindow *)data;
1862
1863         summary_execute(mainwin->summaryview);
1864 }
1865
1866 static void toolbar_next_unread_cb      (GtkWidget      *widget,
1867                                          gpointer        data)
1868 {
1869         MainWindow *mainwin = (MainWindow *)data;
1870
1871         next_unread_cb(mainwin, 0, NULL);
1872 }
1873
1874 static void toolbar_prefs_cb    (GtkWidget      *widget,
1875                                  gpointer        data)
1876 {
1877         prefs_common_open();
1878 }
1879
1880 static void toolbar_account_cb  (GtkWidget      *widget,
1881                                  gpointer        data)
1882 {
1883         MainWindow *mainwin = (MainWindow *)data;
1884
1885         prefs_account_open_cb(mainwin, 0, NULL);
1886 }
1887
1888 static void toolbar_account_button_pressed(GtkWidget *widget,
1889                                            GdkEventButton *event,
1890                                            gpointer data)
1891 {
1892         MainWindow *mainwin = (MainWindow *)data;
1893
1894         if (!event) return;
1895         if (event->button != 3) return;
1896
1897         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1898                        event->button, event->time);
1899 }
1900
1901 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1902                                     gpointer data)
1903 {
1904         MainWindow *mainwin = (MainWindow *)data;
1905
1906         if (!event) return;
1907
1908         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1909                        event->button, event->time);
1910 }
1911
1912 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1913                                  gpointer data)
1914 {
1915         app_exit_cb(data, 0, widget);
1916
1917         return TRUE;
1918 }
1919
1920 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1921                            GtkWidget *widget)
1922 {
1923         main_window_add_mailbox(mainwin);
1924 }
1925
1926 static void add_mbox_cb(MainWindow *mainwin, guint action,
1927                         GtkWidget *widget)
1928 {
1929         main_window_add_mbox(mainwin);
1930 }
1931
1932 static void update_folderview_cb(MainWindow *mainwin, guint action,
1933                                  GtkWidget *widget)
1934 {
1935         summary_show(mainwin->summaryview, NULL, FALSE);
1936         folderview_update_all();
1937 }
1938
1939 static void new_folder_cb(MainWindow *mainwin, guint action,
1940                           GtkWidget *widget)
1941 {
1942         folderview_new_folder(mainwin->folderview);
1943 }
1944
1945 static void rename_folder_cb(MainWindow *mainwin, guint action,
1946                              GtkWidget *widget)
1947 {
1948         folderview_rename_folder(mainwin->folderview);
1949 }
1950
1951 static void delete_folder_cb(MainWindow *mainwin, guint action,
1952                              GtkWidget *widget)
1953 {
1954         folderview_delete_folder(mainwin->folderview);
1955 }
1956
1957 static void import_mbox_cb(MainWindow *mainwin, guint action,
1958                            GtkWidget *widget)
1959 {
1960         import_mbox(mainwin->summaryview->folder_item);
1961 }
1962
1963 static void export_mbox_cb(MainWindow *mainwin, guint action,
1964                            GtkWidget *widget)
1965 {
1966         export_mbox(mainwin->summaryview->folder_item);
1967 }
1968
1969 static void empty_trash_cb(MainWindow *mainwin, guint action,
1970                            GtkWidget *widget)
1971 {
1972         main_window_empty_trash(mainwin, TRUE);
1973 }
1974
1975 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1976 {
1977         summary_save_as(mainwin->summaryview);
1978 }
1979
1980 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1981 {
1982         summary_print(mainwin->summaryview);
1983 }
1984
1985 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1986 {
1987         if (prefs_common.confirm_on_exit) {
1988                 if (alertpanel(_("Exit"), _("Exit this program?"),
1989                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
1990                         return;
1991                 manage_window_focus_in(mainwin->window, NULL, NULL);
1992         }
1993
1994         app_will_exit(widget, mainwin);
1995 }
1996
1997 static void toggle_folder_cb(MainWindow *mainwin, guint action,
1998                              GtkWidget *widget)
1999 {
2000         switch (mainwin->type) {
2001         case SEPARATE_NONE:
2002         case SEPARATE_MESSAGE:
2003                 break;
2004         case SEPARATE_FOLDER:
2005                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2006                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2007                 else
2008                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2009                 break;
2010         case SEPARATE_BOTH:
2011                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2012                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2013                 else
2014                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2015                 break;
2016         }
2017 }
2018
2019 static void toggle_message_cb(MainWindow *mainwin, guint action,
2020                               GtkWidget *widget)
2021 {
2022         switch (mainwin->type) {
2023         case SEPARATE_NONE:
2024         case SEPARATE_FOLDER:
2025                 break;
2026         case SEPARATE_MESSAGE:
2027                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2028                         gtk_widget_show(mainwin->win.sep_message.messagewin);
2029                 else
2030                         gtk_widget_hide(mainwin->win.sep_message.messagewin);
2031                 break;
2032         case SEPARATE_BOTH:
2033                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2034                         gtk_widget_show(mainwin->win.sep_both.messagewin);
2035                 else
2036                         gtk_widget_hide(mainwin->win.sep_both.messagewin);
2037                 break;
2038         }
2039 }
2040
2041 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2042                               GtkWidget *widget)
2043 {
2044         activate_compose_button(mainwin, (ToolbarStyle)action, 
2045                         mainwin->compose_btn_type);
2046         
2047         switch ((ToolbarStyle)action) {
2048         case TOOLBAR_NONE:
2049                 gtk_widget_hide(mainwin->handlebox);
2050         case TOOLBAR_ICON:
2051                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2052                                       GTK_TOOLBAR_ICONS);
2053                 break;
2054         case TOOLBAR_TEXT:
2055                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2056                                       GTK_TOOLBAR_TEXT);
2057                 break;
2058         case TOOLBAR_BOTH:
2059                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2060                                       GTK_TOOLBAR_BOTH);
2061                 break;
2062         }
2063
2064         if (action != TOOLBAR_NONE) {
2065                 gtk_widget_show(mainwin->handlebox);
2066                 gtk_widget_queue_resize(mainwin->handlebox);
2067         }
2068
2069         mainwin->toolbar_style = (ToolbarStyle)action;
2070         prefs_common.toolbar_style = (ToolbarStyle)action;
2071 }
2072
2073 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2074                                 GtkWidget *widget)
2075 {
2076         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2077                 gtk_widget_show(mainwin->hbox_stat);
2078                 prefs_common.show_statusbar = TRUE;
2079         } else {
2080                 gtk_widget_hide(mainwin->hbox_stat);
2081                 prefs_common.show_statusbar = FALSE;
2082         }
2083 }
2084
2085 static void separate_widget_cb(GtkCheckMenuItem *checkitem, guint action)
2086 {
2087         MainWindow *mainwin;
2088         SeparateType type;
2089
2090         mainwin = (MainWindow *) gtk_object_get_data(GTK_OBJECT(checkitem), "mainwindow");
2091         g_return_if_fail(mainwin != NULL);
2092
2093         type = mainwin->type ^ action;
2094         main_window_separation_change(mainwin, type);
2095
2096         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2097         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2098 }
2099
2100 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2101                                 GtkWidget *widget)
2102 {
2103         addressbook_open(NULL);
2104 }
2105
2106 static void log_window_show_cb(MainWindow *mainwin, guint action,
2107                                GtkWidget *widget)
2108 {
2109         log_window_show(mainwin->logwin);
2110 }
2111
2112 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2113 {
2114         inc_mail(mainwin);
2115 }
2116
2117 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
2118                                     GtkWidget *widget)
2119 {
2120         inc_all_account_mail(mainwin);
2121 }
2122
2123 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2124 {
2125         GList *list;
2126
2127         if (procmsg_send_queue() < 0)
2128                 alertpanel_error(_("Sending queued message failed."));
2129
2130         statusbar_pop_all();
2131
2132         for (list = folder_get_list(); list != NULL; list = list->next) {
2133                 Folder *folder;
2134
2135                 folder = list->data;
2136                 if (folder->queue) {
2137                         folder_item_scan(folder->queue);
2138                         folderview_update_item(folder->queue, TRUE);
2139                 }
2140         }
2141 }
2142
2143 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2144 {
2145         if (mainwin->summaryview->folder_item) {
2146                 if (mainwin->summaryview->folder_item->folder->account != NULL
2147                     && mainwin->summaryview->folder_item->folder->account->protocol == A_NNTP)
2148                         compose_new_with_recipient(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item->path);
2149                 else
2150                         compose_new_with_folderitem(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item);
2151         }
2152         else
2153                 compose_new(NULL);
2154 }
2155
2156 static void compose_mail_cb(MainWindow *mainwin, guint action,
2157                             GtkWidget *widget)
2158 {
2159         PrefsAccount * ac;
2160         GList * list;
2161         GList * cur;
2162
2163         if (mainwin->summaryview->folder_item) {
2164                 ac = mainwin->summaryview->folder_item->folder->account;
2165                 if (ac && ac->protocol != A_NNTP) {
2166                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2167                         return;
2168                 }
2169         }
2170
2171         if(cur_account && (cur_account->protocol != A_NNTP)) {
2172                 compose_new_with_folderitem(cur_account, mainwin->summaryview->folder_item);
2173                 return;
2174         }
2175
2176         list = account_get_list();
2177         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2178                 ac = (PrefsAccount *) cur->data;
2179                 if (ac->protocol != A_NNTP) {
2180                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2181                         return;
2182                 }
2183         }
2184 }
2185
2186 static void compose_news_cb(MainWindow *mainwin, guint action,
2187                             GtkWidget *widget)
2188 {
2189         PrefsAccount * ac = NULL;
2190         GList * list;
2191         GList * cur;
2192
2193         if (mainwin->summaryview->folder_item) {
2194                 ac = mainwin->summaryview->folder_item->folder->account;
2195                 if (ac && ac->protocol == A_NNTP) {
2196                         compose_new_with_recipient
2197                                 (ac, mainwin->summaryview->folder_item->path);
2198                         return;
2199                 }
2200         }
2201
2202         list = account_get_list();
2203         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2204                 ac = (PrefsAccount *) cur->data;
2205                 if (ac->protocol == A_NNTP) {
2206                         compose_new(ac);
2207                         return;
2208                 }
2209         }
2210 }
2211
2212 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2213 {
2214         GList  *sel = GTK_CLIST(mainwin->summaryview->ctree)->selection;
2215         MsgInfo *msginfo;
2216
2217         msginfo = gtk_ctree_node_get_row_data
2218                 (GTK_CTREE(mainwin->summaryview->ctree),
2219                  mainwin->summaryview->selected);
2220
2221         if (!msginfo) return;
2222
2223         switch (action) {
2224         case COMPOSE_REPLY:
2225                 compose_reply(msginfo, prefs_common.reply_with_quote,
2226                               FALSE, FALSE);
2227                 break;
2228         case COMPOSE_REPLY_TO_SENDER:
2229                 compose_reply(msginfo, prefs_common.reply_with_quote,
2230                               FALSE, TRUE);
2231                 break;
2232         case COMPOSE_FOLLOWUP_AND_REPLY_TO:
2233                 compose_followup_and_reply_to(msginfo,
2234                                               prefs_common.reply_with_quote,
2235                                               FALSE, TRUE);
2236                 break;
2237         case COMPOSE_REPLY_TO_ALL:
2238                 compose_reply(msginfo, prefs_common.reply_with_quote,
2239                               TRUE, FALSE);
2240                 break;
2241         case COMPOSE_FORWARD:
2242                 if (!sel->next) {
2243                         compose_forward(NULL, msginfo, FALSE);
2244                         break;
2245                 }
2246                 /* if (sel->next) FALL_THROUGH */
2247         case COMPOSE_FORWARD_AS_ATTACH:
2248                 {
2249                         GSList *msginfo_list = NULL;
2250                         for ( ; sel != NULL; sel = sel->next)
2251                                 msginfo_list = g_slist_append(msginfo_list, 
2252                                         gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->summaryview->ctree),
2253                                                 GTK_CTREE_NODE(sel->data)));
2254                         compose_forward_multiple(NULL, msginfo_list);
2255                         g_slist_free(msginfo_list);
2256                 }                       
2257                 break;
2258         default:
2259                 g_warning("reply_cb(): invalid action type: %d\n", action);
2260         }
2261
2262         summary_set_marks_selected(mainwin->summaryview);
2263 }
2264
2265 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2266 {
2267         summary_move_to(mainwin->summaryview);
2268 }
2269
2270 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2271 {
2272         summary_copy_to(mainwin->summaryview);
2273 }
2274
2275 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2276 {
2277         summary_delete(mainwin->summaryview);
2278 }
2279
2280 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2281 {
2282         summary_open_msg(mainwin->summaryview);
2283 }
2284
2285 static void view_source_cb(MainWindow *mainwin, guint action,
2286                            GtkWidget *widget)
2287 {
2288         summary_view_source(mainwin->summaryview);
2289 }
2290
2291 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2292 {
2293         summary_reedit(mainwin->summaryview);
2294 }
2295
2296 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2297 {
2298         summary_mark(mainwin->summaryview);
2299 }
2300
2301 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2302 {
2303         summary_unmark(mainwin->summaryview);
2304 }
2305
2306 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2307                               GtkWidget *widget)
2308 {
2309         summary_mark_as_unread(mainwin->summaryview);
2310 }
2311
2312 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2313                             GtkWidget *widget)
2314 {
2315         summary_mark_as_read(mainwin->summaryview);
2316 }
2317
2318 static void set_charset_cb(MainWindow *mainwin, guint action,
2319                            GtkWidget *widget)
2320 {
2321         const gchar *str;
2322
2323         str = conv_get_charset_str((CharSet)action);
2324         g_free(prefs_common.force_charset);
2325         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2326
2327         summary_redisplay_msg(mainwin->summaryview);
2328
2329         debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
2330 }
2331
2332 void main_window_set_thread_option(MainWindow *mainwin)
2333 {
2334         GtkItemFactory *ifactory;
2335         gboolean no_item = FALSE;
2336
2337         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2338
2339         if (mainwin->summaryview == NULL)
2340                 no_item = TRUE;
2341         else if (mainwin->summaryview->folder_item == NULL)
2342                 no_item = TRUE;
2343
2344         if (no_item) {
2345                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
2346                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
2347         }
2348         else {
2349                 if (mainwin->summaryview->folder_item->prefs->enable_thread) {
2350                         menu_set_sensitive(ifactory,
2351                                            "/Summary/Thread view",   FALSE);
2352                         menu_set_sensitive(ifactory,
2353                                            "/Summary/Unthread view", TRUE);
2354                         summary_thread_build(mainwin->summaryview);
2355                 }
2356                 else {
2357                         menu_set_sensitive(ifactory,
2358                                            "/Summary/Thread view",   TRUE);
2359                         menu_set_sensitive(ifactory,
2360                                            "/Summary/Unthread view", FALSE);
2361                         summary_unthread(mainwin->summaryview);
2362                 }
2363                 prefs_folder_item_save_config(mainwin->summaryview->folder_item);
2364         }
2365 }
2366
2367 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2368 {
2369         mainwin->summaryview->folder_item->prefs->enable_thread =
2370                 !mainwin->summaryview->folder_item->prefs->enable_thread;
2371         main_window_set_thread_option(mainwin);
2372
2373         /*
2374         if (0 == action) {
2375                 summary_thread_build(mainwin->summaryview);
2376                 mainwin->summaryview->folder_item->prefs->enable_thread =
2377                         TRUE;
2378                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
2379                 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
2380         } else {
2381                 summary_unthread(mainwin->summaryview);
2382                 mainwin->summaryview->folder_item->prefs->enable_thread =
2383                         FALSE;
2384                 menu_set_sensitive(ifactory, "/Summary/Thread view",   TRUE);
2385                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
2386         }
2387         */
2388 }
2389
2390 static void set_display_item_cb(MainWindow *mainwin, guint action,
2391                                 GtkWidget *widget)
2392 {
2393         prefs_summary_display_item_set();
2394 }
2395
2396 static void sort_summary_cb(MainWindow *mainwin, guint action,
2397                             GtkWidget *widget)
2398 {
2399         summary_sort(mainwin->summaryview, (SummarySortType)action);
2400 }
2401
2402 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2403                                   GtkWidget *widget)
2404 {
2405         summary_attract_by_subject(mainwin->summaryview);
2406 }
2407
2408 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2409                                  GtkWidget *widget)
2410 {
2411         summary_delete_duplicated(mainwin->summaryview);
2412 }
2413
2414 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2415 {
2416         summary_filter(mainwin->summaryview);
2417 }
2418
2419 static void execute_summary_cb(MainWindow *mainwin, guint action,
2420                                GtkWidget *widget)
2421 {
2422         summary_execute(mainwin->summaryview);
2423 }
2424
2425 static void update_summary_cb(MainWindow *mainwin, guint action,
2426                               GtkWidget *widget)
2427 {
2428         FolderItem *fitem;
2429         FolderView *folderview = mainwin->folderview;
2430
2431         if (!mainwin->summaryview->folder_item) return;
2432         if (!folderview->opened) return;
2433
2434         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2435                                             folderview->opened);
2436         if (!fitem) return;
2437
2438         summary_show(mainwin->summaryview, fitem, TRUE);
2439 }
2440
2441 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2442 {
2443         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2444 }
2445
2446 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2447 {
2448         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2449 }
2450
2451 static void next_unread_cb(MainWindow *mainwin, guint action,
2452                            GtkWidget *widget)
2453 {
2454         summary_select_next_unread(mainwin->summaryview);
2455 }
2456
2457 static void next_marked_cb(MainWindow *mainwin, guint action,
2458                            GtkWidget *widget)
2459 {
2460         summary_select_next_marked(mainwin->summaryview);
2461 }
2462
2463 static void prev_marked_cb(MainWindow *mainwin, guint action,
2464                            GtkWidget *widget)
2465 {
2466         summary_select_prev_marked(mainwin->summaryview);
2467 }
2468
2469 static void goto_folder_cb(MainWindow *mainwin, guint action,
2470                            GtkWidget *widget)
2471 {
2472         FolderItem *to_folder;
2473
2474         to_folder = foldersel_folder_sel(NULL, NULL);
2475
2476         if (to_folder)
2477                 folderview_select(mainwin->folderview, to_folder);
2478 }
2479
2480 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2481 {
2482         messageview_copy_clipboard(mainwin->messageview);
2483 }
2484
2485 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2486 {
2487         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2488                 summary_select_all(mainwin->summaryview);
2489         else if (mainwin->summaryview->msg_is_toggled_on &&
2490                  GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2491                 messageview_select_all(mainwin->messageview);
2492 }
2493
2494 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2495                                  GtkWidget *widget)
2496 {
2497         prefs_common_open();
2498 }
2499
2500 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2501                                  GtkWidget *widget)
2502 {
2503         prefs_filter_open();
2504 }
2505
2506 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2507                                   GtkWidget *widget)
2508 {
2509         prefs_scoring_open(NULL);
2510 }
2511
2512 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2513                                     GtkWidget *widget)
2514 {
2515         prefs_filtering_open();
2516 }
2517
2518 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2519                                   GtkWidget *widget)
2520 {
2521         if (!cur_account) {
2522                 new_account_cb(mainwin, 0, widget);
2523         } else {
2524                 gboolean prev_default = cur_account->is_default;
2525
2526                 prefs_account_open(cur_account);
2527                 if (!prev_default && cur_account->is_default)
2528                         account_set_as_default(cur_account);
2529                 account_save_config_all();
2530                 account_set_menu();
2531                 main_window_reflect_prefs_all();
2532         }
2533 }
2534
2535 static void new_account_cb(MainWindow *mainwin, guint action,
2536                            GtkWidget *widget)
2537 {
2538         account_edit_open();
2539         if (!compose_get_compose_list()) account_add();
2540 }
2541
2542 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2543 {
2544         cur_account = (PrefsAccount *)data;
2545         main_window_reflect_prefs_all();
2546 }
2547
2548 static void manual_open_cb(MainWindow *mainwin, guint action,
2549                            GtkWidget *widget)
2550 {
2551         manual_open((ManualLang)action);
2552 }
2553
2554 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2555 {
2556         MainWindow *mainwin = (MainWindow *)data;
2557         gchar *str;
2558
2559         if (item->path)
2560                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2561                                       LOCAL_FOLDER(folder)->rootpath,
2562                                       G_DIR_SEPARATOR,
2563                                       item->path);
2564         else
2565                 str = g_strdup_printf(_("Scanning folder %s ..."),
2566                                       LOCAL_FOLDER(folder)->rootpath);
2567
2568         STATUSBAR_PUSH(mainwin, str);
2569         STATUSBAR_POP(mainwin);
2570         g_free(str);
2571 }
2572
2573 static void activate_compose_button (MainWindow *mainwin,
2574                                 ToolbarStyle style,
2575                                 ComposeButtonType type)
2576 {
2577         if (style == TOOLBAR_NONE) 
2578                 return;
2579
2580         if (style == TOOLBAR_BOTH) {    
2581                 gtk_widget_hide(mainwin->compose_mail_btn_plain);
2582                 gtk_widget_hide(mainwin->compose_news_btn_plain);
2583                 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? mainwin->compose_mail_btn 
2584                         : mainwin->compose_news_btn);
2585                 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? mainwin->compose_news_btn
2586                         : mainwin->compose_mail_btn);
2587                 mainwin->compose_btn_type = type;       
2588         }
2589         else {
2590                 gtk_widget_hide(mainwin->compose_news_btn);
2591                 gtk_widget_hide(mainwin->compose_mail_btn);
2592                 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? mainwin->compose_mail_btn_plain 
2593                         : mainwin->compose_news_btn_plain);
2594                 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? mainwin->compose_news_btn_plain
2595                         : mainwin->compose_mail_btn_plain);
2596                 mainwin->compose_btn_type = type;               
2597         }
2598 }
2599