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