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