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