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