Show key icon for encrypted mails in summary view.
[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"), "<control>F", search_cb, 0, NULL},
446         {N_("/_Edit/_Search folder..."),        "<control>S", search_cb, 1, NULL},
447
448         {N_("/_View"),                          NULL, NULL, 0, "<Branch>"},
449         {N_("/_View/_Folder tree"),             NULL, toggle_folder_cb, 0, "<ToggleItem>"},
450         {N_("/_View/_Message view"),            NULL, toggle_message_cb, 0, "<ToggleItem>"},
451         {N_("/_View/_Toolbar"),                 NULL, NULL, 0, "<Branch>"},
452         {N_("/_View/_Toolbar/Icon _and text"),  NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
453         {N_("/_View/_Toolbar/_Icon"),           NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Toolbar/Icon and text"},
454         {N_("/_View/_Toolbar/_Text"),           NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Toolbar/Icon and text"},
455         {N_("/_View/_Toolbar/_None"),           NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Toolbar/Icon and text"},
456         {N_("/_View/_Status bar"),              NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
457         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
458         {N_("/_View/Separate f_older tree"),    NULL, NULL, SEPARATE_ACTION + SEPARATE_FOLDER, "<ToggleItem>"},
459         {N_("/_View/Separate m_essage view"),   NULL, NULL, SEPARATE_ACTION + SEPARATE_MESSAGE, "<ToggleItem>"},
460         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
461         {N_("/_View/View _source"),             "<control>U", view_source_cb, 0, NULL},
462         {N_("/_View/Show all _header"),         "<control>H", header_window_show_cb, 0, NULL},
463         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
464         {N_("/_View/_Code set"),                NULL, NULL, 0, "<Branch>"},
465         {N_("/_View/_Code set/_Auto detect"),
466          NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
467
468 #define CODESET_SEPARATOR \
469         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"}
470 #define CODESET_ACTION(action) \
471          NULL, set_charset_cb, action, "/View/Code set/Auto detect"
472
473         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"},
474         {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
475          CODESET_ACTION(C_US_ASCII)},
476
477 #if HAVE_LIBJCONV
478         {N_("/_View/_Code set/Unicode (_UTF-8)"),
479          CODESET_ACTION(C_UTF_8)},
480         CODESET_SEPARATOR,
481 #endif
482         {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
483          CODESET_ACTION(C_ISO_8859_1)},
484         CODESET_SEPARATOR,
485 #if HAVE_LIBJCONV
486         {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
487          CODESET_ACTION(C_ISO_8859_2)},
488         CODESET_SEPARATOR,
489         {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
490          CODESET_ACTION(C_ISO_8859_13)},
491         {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
492          CODESET_ACTION(C_ISO_8859_4)},
493         CODESET_SEPARATOR,
494         {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
495          CODESET_ACTION(C_ISO_8859_7)},
496         CODESET_SEPARATOR,
497         {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
498          CODESET_ACTION(C_ISO_8859_9)},
499         CODESET_SEPARATOR,
500         {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
501          CODESET_ACTION(C_ISO_8859_5)},
502         {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
503          CODESET_ACTION(C_KOI8_R)},
504         {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
505          CODESET_ACTION(C_CP1251)},
506         CODESET_SEPARATOR,
507 #endif
508         {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
509          CODESET_ACTION(C_ISO_2022_JP)},
510 #if HAVE_LIBJCONV
511         {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
512          CODESET_ACTION(C_ISO_2022_JP_2)},
513 #endif
514         {N_("/_View/_Code set/Japanese (_EUC-JP)"),
515          CODESET_ACTION(C_EUC_JP)},
516         {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
517          CODESET_ACTION(C_SHIFT_JIS)},
518 #if HAVE_LIBJCONV
519         CODESET_SEPARATOR,
520         {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
521          CODESET_ACTION(C_GB2312)},
522         {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
523          CODESET_ACTION(C_BIG5)},
524         {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
525          CODESET_ACTION(C_EUC_TW)},
526         {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
527          CODESET_ACTION(C_ISO_2022_CN)},
528         CODESET_SEPARATOR,
529         {N_("/_View/_Code set/Korean (EUC-_KR)"),
530          CODESET_ACTION(C_EUC_KR)},
531         {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
532          CODESET_ACTION(C_ISO_2022_KR)},
533         CODESET_SEPARATOR,
534         {N_("/_View/_Code set/Thai (TIS-620)"),
535          CODESET_ACTION(C_TIS_620)},
536         {N_("/_View/_Code set/Thai (Windows-874)"),
537          CODESET_ACTION(C_WINDOWS_874)},
538 #endif
539
540 #undef CODESET_SEPARATOR
541 #undef CODESET_ACTION
542
543         {N_("/_Message"),                       NULL, NULL, 0, "<Branch>"},
544         {N_("/_Message/Get new ma_il"),         "<alt>I",       inc_mail_cb, 0, NULL},
545         {N_("/_Message/Get from _all accounts"),
546                                                 "<shift><alt>I", inc_all_account_mail_cb, 0, NULL},
547         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
548         {N_("/_Message/Send queued messa_ges"),
549                                                 NULL, send_queue_cb, 0, NULL},
550         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
551         {N_("/_Message/Compose a_n email message"),     "<alt>N", compose_mail_cb, 0, NULL},
552         {N_("/_Message/Compose a news message"),        NULL,   compose_news_cb, 0, NULL},
553         {N_("/_Message/_Reply"),                "<alt>R",       reply_cb, COMPOSE_REPLY, NULL},
554         {N_("/_Message/Repl_y to sender"),      "<control><alt>R", reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
555         {N_("/_Message/Follow-up and reply to"), NULL, reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
556         {N_("/_Message/Reply to a_ll"),         "<shift><alt>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
557         {N_("/_Message/_Forward"),              "<shift><alt>F", reply_cb, COMPOSE_FORWARD, NULL},
558         {N_("/_Message/Bounce"),                NULL, reply_cb, COMPOSE_BOUNCE, NULL},
559         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
560         {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
561         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
562         {N_("/_Message/M_ove..."),              "<alt>O", move_to_cb, 0, NULL},
563         {N_("/_Message/_Copy..."),              NULL, copy_to_cb, 0, NULL},
564         {N_("/_Message/_Delete"),               "<alt>D", delete_cb,  0, NULL},
565         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
566         {N_("/_Message/_Mark"),                 NULL, NULL, 0, "<Branch>"},
567         {N_("/_Message/_Mark/_Mark"),           NULL, mark_cb,   0, NULL},
568         {N_("/_Message/_Mark/_Unmark"),         NULL, unmark_cb, 0, NULL},
569         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
570         {N_("/_Message/_Mark/Mark as unr_ead"), NULL, mark_as_unread_cb, 0, NULL},
571         {N_("/_Message/_Mark/Mark as rea_d"),
572                                                 NULL, mark_as_read_cb, 0, NULL},
573         {N_("/_Message/_Mark/Mark all read"),   NULL, mark_all_read_cb, 0, NULL},                                                
574         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
575         {N_("/_Message/Open in new _window"),   "<shift><control>N", open_msg_cb, 0, NULL},
576
577         {N_("/_Summary"),                       NULL, NULL, 0, "<Branch>"},
578         {N_("/_Summary/_Hide read messages"),   NULL, hide_read_messages, 0, "<ToggleItem>"},
579         {N_("/_Summary/_Delete duplicated messages"),
580                                                 NULL, delete_duplicated_cb,   0, NULL},
581         {N_("/_Summary/_Filter messages"),      NULL, filter_cb, 0, NULL},
582         {N_("/_Summary/E_xecute"),              "<alt>X", execute_summary_cb, 0, NULL},
583         {N_("/_Summary/_Update"),               "<alt>U", update_summary_cb,  0, NULL},
584         {N_("/_Summary/---"),                   NULL, NULL, 0, "<Separator>"},
585         {N_("/_Summary/Go _to"),                NULL, NULL, 0, "<Branch>"},
586         {N_("/_Summary/Go _to/_Prev message"),  NULL, prev_cb, 0, NULL},
587         {N_("/_Summary/Go _to/_Next message"),  NULL, next_cb, 0, NULL},
588         {N_("/_Summary/Go _to/---"),            NULL, NULL, 0, "<Separator>"},
589         {N_("/_Summary/Go _to/P_rev unread message"),
590                                                 NULL, prev_unread_cb, 0, NULL},
591         {N_("/_Summary/Go _to/N_ext unread message"),
592                                                 NULL, next_unread_cb, 0, NULL},
593         {N_("/_Summary/Go _to/---"),            NULL, NULL, 0, "<Separator>"},
594         {N_("/_Summary/Go _to/Prev _marked message"),
595                                                 NULL, prev_marked_cb, 0, NULL},
596         {N_("/_Summary/Go _to/Next m_arked message"),
597                                                 NULL, next_marked_cb, 0, NULL},
598         {N_("/_Summary/Go _to/---"),            NULL, NULL, 0, "<Separator>"},
599         {N_("/_Summary/Go _to/Prev _labeled message"),
600                                                 NULL, prev_labeled_cb, 0, NULL},
601         {N_("/_Summary/Go _to/Next la_beled message"),
602                                                 NULL, next_labeled_cb, 0, NULL},
603         {N_("/_Summary/_Go to other folder..."),"<alt>G", goto_folder_cb, 0, NULL},
604         {N_("/_Summary/---"),                   NULL, NULL, 0, "<Separator>"},
605         {N_("/_Summary/_Sort"),                 NULL, NULL, 0, "<Branch>"},
606         {N_("/_Summary/_Sort/Sort by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, NULL},
607         {N_("/_Summary/_Sort/Sort by s_ize"),   NULL, sort_summary_cb, SORT_BY_SIZE, NULL},
608         {N_("/_Summary/_Sort/Sort by _date"),   NULL, sort_summary_cb, SORT_BY_DATE, NULL},
609         {N_("/_Summary/_Sort/Sort by _from"),   NULL, sort_summary_cb, SORT_BY_FROM, NULL},
610         {N_("/_Summary/_Sort/Sort by _subject"),NULL, sort_summary_cb, SORT_BY_SUBJECT, NULL},
611         {N_("/_Summary/_Sort/Sort by _color label"),
612                                                 NULL, sort_summary_cb, SORT_BY_LABEL, NULL},
613         {N_("/_Summary/_Sort/Sort by _mark"),   NULL, sort_summary_cb, SORT_BY_MARK, NULL},
614         {N_("/_Summary/_Sort/Sort by _unread"), NULL, sort_summary_cb, SORT_BY_UNREAD, NULL},
615         {N_("/_Summary/_Sort/Sort by a_ttachment"),
616                                                 NULL, sort_summary_cb, SORT_BY_MIME, NULL},
617         {N_("/_Summary/_Sort/---"),             NULL, NULL, 0, "<Separator>"},
618         {N_("/_Summary/_Sort/_Attract by subject"),
619                                                 NULL, attract_by_subject_cb, 0, NULL},
620         {N_("/_Summary/_Thread view"),          "<control>T",        thread_cb, 0, NULL},
621         {N_("/_Summary/Unt_hread view"),        "<shift><control>T", thread_cb, 1, NULL},
622         {N_("/_Summary/Set display _item..."),  NULL, set_display_item_cb, 0, NULL},
623
624         {N_("/_Tool"),                          NULL, NULL, 0, "<Branch>"},
625         {N_("/_Tool/_Address book"),            "<alt>A", addressbook_open_cb, 0, NULL},
626         {N_("/_Tool/_Log window"),              "<alt>L", log_window_show_cb, 0, NULL},
627
628         {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
629         {N_("/_Configuration/_Common preferences..."),
630                                                 NULL, prefs_common_open_cb, 0, NULL},
631         {N_("/_Configuration/_Filter setting..."),
632                                                 NULL, prefs_filter_open_cb, 0, NULL},
633         {N_("/_Configuration/_Scoring ..."),
634                                                 NULL, prefs_scoring_open_cb, 0, NULL},
635         {N_("/_Configuration/_Filtering ..."),
636                                                 NULL, prefs_filtering_open_cb, 0, NULL},
637         {N_("/_Configuration/_Template..."),    NULL, prefs_template_open_cb, 0, NULL},
638         {N_("/_Configuration/_Preferences for current account..."),
639                                                 NULL, prefs_account_open_cb, 0, NULL},
640         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
641         {N_("/_Configuration/Create _new account..."),
642                                                 NULL, new_account_cb, 0, NULL},
643         {N_("/_Configuration/_Edit accounts..."),
644                                                 NULL, account_edit_open, 0, NULL},
645         {N_("/_Configuration/C_hange current account"),
646                                                 NULL, NULL, 0, "<Branch>"},
647
648         {N_("/_Help"),                          NULL, NULL, 0, "<LastBranch>"},
649         {N_("/_Help/_Manual"),                  NULL, NULL, 0, "<Branch>"},
650         {N_("/_Help/_Manual/_English"),         NULL, manual_open_cb, MANUAL_LANG_EN, NULL},
651         {N_("/_Help/_Manual/_Japanese"),        NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
652         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
653         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
654 };
655 static GtkItemFactoryEntry reply_popup_entries[] =
656 {
657         {N_("/Reply with _quote"), NULL, reply_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
658         {N_("/_Reply without quote"), NULL, reply_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
659 };
660 static GtkItemFactoryEntry replyall_popup_entries[] =
661 {
662         {N_("/Reply to all with _quote"), NULL, reply_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
663         {N_("/_Reply to all without quote"), NULL, reply_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
664 };
665 static GtkItemFactoryEntry replysender_popup_entries[] =
666 {
667         {N_("/Reply to sender with _quote"), NULL, reply_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
668         {N_("/_Reply to sender without quote"), NULL, reply_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
669 };
670 static GtkItemFactoryEntry fwd_popup_entries[] =
671 {
672         {N_("/_Forward message (inline style)"), NULL, reply_cb, COMPOSE_FORWARD_INLINE, NULL},
673         {N_("/Forward message as _attachment"), NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
674 };
675
676
677 MainWindow *main_window_create(SeparateType type)
678 {
679         MainWindow *mainwin;
680         GtkWidget *window;
681         GtkWidget *vbox;
682         GtkWidget *menubar;
683         GtkWidget *handlebox;
684         GtkWidget *vbox_body;
685         GtkWidget *hbox_stat;
686         GtkWidget *statusbar;
687         GtkWidget *progressbar;
688         GtkWidget *statuslabel;
689         GtkWidget *ac_button;
690         GtkWidget *ac_label;
691
692         FolderView *folderview;
693         SummaryView *summaryview;
694         MessageView *messageview;
695         GdkColormap *colormap;
696         GdkColor color[4];
697         gboolean success[4];
698         guint n_menu_entries;
699         GtkItemFactory *ifactory;
700         GtkWidget *ac_menu;
701         GtkWidget *menuitem;
702         GtkWidget *compose_popup;
703         GtkWidget *reply_popup;
704         GtkWidget *replyall_popup;
705         GtkWidget *replysender_popup;
706         GtkWidget *fwd_popup;
707         gint i;
708
709         debug_print(_("Creating main window...\n"));
710         mainwin = g_new0(MainWindow, 1);
711
712         /* main window */
713         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
714         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
715         gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
716         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
717                            GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
718         gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
719                            GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
720         gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
721                            GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
722
723         gtk_widget_realize(window);
724         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
725
726         gtkut_widget_set_app_icon(window);
727
728         vbox = gtk_vbox_new(FALSE, 0);
729         gtk_widget_show(vbox);
730         gtk_container_add(GTK_CONTAINER(window), vbox);
731
732         /* menu bar */
733         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
734         menubar = menubar_create(window, mainwin_entries, 
735                                  n_menu_entries, "<Main>", mainwin);
736         gtk_widget_show(menubar);
737         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
738
739         handlebox = gtk_handle_box_new();
740         gtk_widget_show(handlebox);
741         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
742
743         /* create the popup menus for the reply buttons specials */
744         n_menu_entries = sizeof(reply_popup_entries) /
745                         sizeof(reply_popup_entries[0]);
746         reply_popup = popupmenu_create(window, reply_popup_entries, n_menu_entries,
747                                       "<ReplyPopup>", mainwin);
748         gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
749                            GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), mainwin);
750         n_menu_entries = sizeof(replyall_popup_entries) /
751                         sizeof(replyall_popup_entries[0]);
752         replyall_popup = popupmenu_create(window, replyall_popup_entries, n_menu_entries,
753                                       "<ReplyAllPopup>", mainwin);
754         gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
755                            GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), mainwin);
756         n_menu_entries = sizeof(replysender_popup_entries) /
757                         sizeof(replysender_popup_entries[0]);
758         replysender_popup = popupmenu_create(window, replysender_popup_entries, n_menu_entries,
759                                       "<ReplySenderPopup>", mainwin);
760         gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
761                            GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), mainwin);
762         /* create the popup menu for the forward button */
763         n_menu_entries = sizeof(fwd_popup_entries) /
764                         sizeof(fwd_popup_entries[0]);
765         fwd_popup = popupmenu_create(window, fwd_popup_entries, n_menu_entries,
766                                       "<ForwardPopup>", mainwin);
767         gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
768                            GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), mainwin);
769                            
770         main_window_toolbar_create(mainwin, handlebox);
771
772         /* vbox that contains body */
773         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
774         gtk_widget_show(vbox_body);
775         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
776         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
777
778         hbox_stat = gtk_hbox_new(FALSE, 2);
779         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
780
781         statusbar = statusbar_create();
782         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
783
784         progressbar = gtk_progress_bar_new();
785         gtk_widget_set_usize(progressbar, 120, 1);
786         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
787
788         statuslabel = gtk_label_new("");
789         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
790
791         ac_button = gtk_button_new();
792         gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
793         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
794         gtk_widget_set_usize(ac_button, -1, 1);
795         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
796         gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
797                            GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
798
799         ac_label = gtk_label_new("");
800         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
801
802         gtk_widget_show_all(hbox_stat);
803
804         /* create views */
805         mainwin->folderview  = folderview  = folderview_create();
806         mainwin->summaryview = summaryview = summary_create();
807         mainwin->messageview = messageview = messageview_create();
808         mainwin->headerwin   = header_window_create();
809         mainwin->logwin      = log_window_create();
810
811         folderview->mainwin      = mainwin;
812         folderview->summaryview  = summaryview;
813
814         summaryview->mainwin     = mainwin;
815         summaryview->folderview  = folderview;
816         summaryview->messageview = messageview;
817         summaryview->headerwin   = mainwin->headerwin;
818         summaryview->window      = window;
819
820         messageview->mainwin     = mainwin;
821
822         mainwin->window      = window;
823         mainwin->vbox        = vbox;
824         mainwin->menubar     = menubar;
825         mainwin->handlebox   = handlebox;
826         mainwin->vbox_body   = vbox_body;
827         mainwin->hbox_stat   = hbox_stat;
828         mainwin->statusbar   = statusbar;
829         mainwin->progressbar = progressbar;
830         mainwin->statuslabel = statuslabel;
831         mainwin->ac_button   = ac_button;
832         mainwin->ac_label    = ac_label;
833         mainwin->reply_popup = reply_popup;
834         mainwin->replyall_popup = replyall_popup;
835         mainwin->replysender_popup = replysender_popup;
836         mainwin->fwd_popup = fwd_popup;
837         
838         /* set context IDs for status bar */
839         mainwin->mainwin_cid = gtk_statusbar_get_context_id
840                 (GTK_STATUSBAR(statusbar), "Main Window");
841         mainwin->folderview_cid = gtk_statusbar_get_context_id
842                 (GTK_STATUSBAR(statusbar), "Folder View");
843         mainwin->summaryview_cid = gtk_statusbar_get_context_id
844                 (GTK_STATUSBAR(statusbar), "Summary View");
845
846         /* allocate colors for summary view and folder view */
847         summaryview->color_marked.red = summaryview->color_marked.green = 0;
848         summaryview->color_marked.blue = (guint16)65535;
849
850         summaryview->color_dim.red = summaryview->color_dim.green =
851                 summaryview->color_dim.blue = COLOR_DIM;
852
853         folderview->color_new.red = (guint16)55000;
854         folderview->color_new.green = folderview->color_new.blue = 15000;
855
856         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
857                                        &folderview->color_op);
858
859         summaryview->color_important.red = 0;
860         summaryview->color_marked.green = 0;
861         summaryview->color_important.blue = (guint16)65535;
862
863         color[0] = summaryview->color_marked;
864         color[1] = summaryview->color_dim;
865         color[2] = folderview->color_new;
866         color[3] = folderview->color_op;
867
868         colormap = gdk_window_get_colormap(window->window);
869         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
870         for (i = 0; i < 4; i++) {
871                 if (success[i] == FALSE)
872                         g_warning(_("MainWindow: color allocation %d failed\n"), i);
873         }
874
875         debug_print(_("done.\n"));
876
877         main_window_set_widgets(mainwin, type);
878
879         /* set menu items */
880         ifactory = gtk_item_factory_from_widget(menubar);
881         menuitem = gtk_item_factory_get_item
882                 (ifactory, "/View/Code set/Auto detect");
883         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
884
885         switch (prefs_common.toolbar_style) {
886         case TOOLBAR_NONE:
887                 menuitem = gtk_item_factory_get_item
888                         (ifactory, "/View/Toolbar/None");
889                 break;
890         case TOOLBAR_ICON:
891                 menuitem = gtk_item_factory_get_item
892                         (ifactory, "/View/Toolbar/Icon");
893                 break;
894         case TOOLBAR_TEXT:
895                 menuitem = gtk_item_factory_get_item
896                         (ifactory, "/View/Toolbar/Text");
897                 break;
898         case TOOLBAR_BOTH:
899                 menuitem = gtk_item_factory_get_item
900                         (ifactory, "/View/Toolbar/Icon and text");
901         }
902         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
903
904         gtk_widget_hide(mainwin->hbox_stat);
905         menuitem = gtk_item_factory_get_item(ifactory, "/View/Status bar");
906         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
907                                        prefs_common.show_statusbar);
908
909         /* Message view and Folder tree are always shown at startup
910          * make that in the menu visible */
911         menuitem = gtk_item_factory_get_item(ifactory, "/View/Message view");
912         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
913         menuitem = gtk_item_factory_get_item(ifactory, "/View/Folder tree");
914         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
915         
916         /* set the check of the SEPARATE_xxx menu items. we also need the main window
917          * as a property and pass the action type to the callback */
918         menuitem = gtk_item_factory_get_widget_by_action(ifactory, SEPARATE_ACTION + SEPARATE_FOLDER);
919         g_assert(menuitem);
920         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), type & SEPARATE_FOLDER);
921         gtk_object_set_data(GTK_OBJECT(menuitem), "mainwindow", mainwin);
922         gtk_signal_connect(GTK_OBJECT(menuitem), "toggled", GTK_SIGNAL_FUNC(separate_widget_cb), 
923                                            GUINT_TO_POINTER(SEPARATE_FOLDER));
924
925         menuitem = gtk_item_factory_get_widget_by_action(ifactory, SEPARATE_ACTION + SEPARATE_MESSAGE);
926         g_assert(menuitem);
927         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), type & SEPARATE_MESSAGE);
928         gtk_object_set_data(GTK_OBJECT(menuitem), "mainwindow", mainwin);
929         gtk_signal_connect(GTK_OBJECT(menuitem), "toggled", GTK_SIGNAL_FUNC(separate_widget_cb), 
930                                            GUINT_TO_POINTER(SEPARATE_MESSAGE));
931
932
933         menu_set_sensitive(ifactory, "/Summary/Thread view",
934                            prefs_common.enable_thread ? FALSE : TRUE);
935         menu_set_sensitive(ifactory, "/Summary/Unthread view",
936                            prefs_common.enable_thread ? TRUE : FALSE);
937         
938         /*main_window_set_thread_option(mainwin);*/
939
940
941         /* set account selection menu */
942         ac_menu = gtk_item_factory_get_widget
943                 (ifactory, "/Configuration/Change current account");
944         gtk_signal_connect(GTK_OBJECT(ac_menu), "selection_done",
945                            GTK_SIGNAL_FUNC(ac_menu_popup_closed), mainwin);
946         mainwin->ac_menu = ac_menu;
947
948         main_window_set_toolbar_sensitive(mainwin);
949
950         /* show main window */
951         gtk_widget_set_uposition(mainwin->window,
952                                  prefs_common.mainwin_x,
953                                  prefs_common.mainwin_y);
954         gtk_widget_set_usize(window, prefs_common.mainwin_width,
955                              prefs_common.mainwin_height);
956                              
957         gtk_widget_show(mainwin->window);
958
959         /* initialize views */
960         folderview_init(folderview);
961         summary_init(summaryview);
962         messageview_init(messageview);
963         header_window_init(mainwin->headerwin);
964         log_window_init(mainwin->logwin);
965
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/Show all header"      , M_SINGLE_TARGET_EXIST},
1447                 {"/View/View source"          , M_SINGLE_TARGET_EXIST},
1448
1449                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1450                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1451 /*              {"/Message/Compose new message"   , M_HAVE_ACCOUNT}, */
1452                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
1453                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1454                 {"/Message/Reply to sender"       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1455                 {"/Message/Reply to all"          , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1456                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1457                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1458                 {"/Message/Bounce"                , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1459                 {"/Message/Open in new window"    , M_SINGLE_TARGET_EXIST},
1460                 {"/Message/Re-edit", M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1461                 {"/Message/Move...", M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1462                 {"/Message/Copy...", M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1463                 {"/Message/Delete" , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1464                 {"/Message/Mark"   , M_TARGET_EXIST},
1465
1466                 {"/Summary/Delete duplicated messages", M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1467                 {"/Summary/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1468                 {"/Summary/Execute"                   , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1469                 {"/Summary/Go to"                     , M_MSG_EXIST},
1470                 {"/Summary/Go to/Prev message"        , M_MSG_EXIST},
1471                 {"/Summary/Go to/Next message"        , M_MSG_EXIST},
1472                 {"/Summary/Go to/Next unread message" , M_MSG_EXIST},
1473                 {"/Summary/Go to/Prev marked message" , M_MSG_EXIST},
1474                 {"/Summary/Go to/Next marked message" , M_MSG_EXIST},
1475                 {"/Summary/Go to/Prev labeled message", M_MSG_EXIST},
1476                 {"/Summary/Go to/Next labeled message", M_MSG_EXIST},
1477                 {"/Summary/Sort"                      , M_MSG_EXIST},
1478                 {"/Summary/Thread view"               , M_UNTHREADED},
1479                 {"/Summary/Unthread view"             , M_THREADED},
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), _("Sylpheed - folder view"));
1563                 gtk_window_set_wmclass(GTK_WINDOW(folderwin), "separate folderview", "Sylpheed");
1564                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1565                                       TRUE, TRUE, FALSE);
1566                 gtk_widget_set_usize(folderwin, -1,
1567                                      prefs_common.mainview_height);
1568                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1569                                                BORDER_WIDTH);
1570                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1571                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1572                                    NULL);
1573         }
1574         if (type & SEPARATE_MESSAGE) {
1575                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1576                 gtk_window_set_title(GTK_WINDOW(messagewin), _("Sylpheed - message view"));
1577                 gtk_window_set_wmclass(GTK_WINDOW(messagewin), "separate messageview", "Sylpheed");
1578                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1579                                       TRUE, TRUE, FALSE);
1580                 gtk_widget_set_usize
1581                         (messagewin, prefs_common.mainview_width,
1582                          prefs_common.mainview_height
1583                          - prefs_common.summaryview_height
1584                          + DEFAULT_HEADERVIEW_HEIGHT);
1585                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1586                                                BORDER_WIDTH);
1587                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1588                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1589                                    NULL);
1590         }
1591
1592         switch (type) {
1593         case SEPARATE_NONE:
1594                 hpaned = gtk_hpaned_new();
1595                 gtk_widget_show(hpaned);
1596                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1597                 gtk_paned_add1(GTK_PANED(hpaned),
1598                                GTK_WIDGET_PTR(mainwin->folderview));
1599
1600                 vpaned = gtk_vpaned_new();
1601                 if (mainwin->summaryview->msg_is_toggled_on) {
1602                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1603                         gtk_paned_add1(GTK_PANED(vpaned),
1604                                        GTK_WIDGET_PTR(mainwin->summaryview));
1605                 } else {
1606                         gtk_paned_add2(GTK_PANED(hpaned),
1607                                        GTK_WIDGET_PTR(mainwin->summaryview));
1608                         gtk_widget_ref(vpaned);
1609                 }
1610                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1611                                      prefs_common.summaryview_width,
1612                                      prefs_common.summaryview_height);
1613                 gtk_paned_add2(GTK_PANED(vpaned),
1614                                GTK_WIDGET_PTR(mainwin->messageview));
1615                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1616                                      prefs_common.mainview_width, -1);
1617                 gtk_widget_set_usize(mainwin->window,
1618                                      prefs_common.folderview_width +
1619                                      prefs_common.mainview_width,
1620                                      prefs_common.mainwin_height);
1621                 gtk_widget_show_all(vpaned);
1622
1623                 menu_set_sensitive(ifactory, "/View/Message view", FALSE);
1624                 menu_set_sensitive(ifactory, "/View/Folder tree", FALSE);
1625                 
1626                 mainwin->win.sep_none.hpaned = hpaned;
1627                 mainwin->win.sep_none.vpaned = vpaned;
1628                 break;
1629         case SEPARATE_FOLDER:
1630                 vpaned = gtk_vpaned_new();
1631                 if (mainwin->summaryview->msg_is_toggled_on) {
1632                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1633                                            TRUE, TRUE, 0);
1634                         gtk_paned_add1(GTK_PANED(vpaned),
1635                                        GTK_WIDGET_PTR(mainwin->summaryview));
1636                 } else {
1637                         gtk_box_pack_start(GTK_BOX(vbox_body),
1638                                            GTK_WIDGET_PTR(mainwin->summaryview),
1639                                            TRUE, TRUE, 0);
1640                         gtk_widget_ref(vpaned);
1641                 }
1642                 gtk_paned_add2(GTK_PANED(vpaned),
1643                                GTK_WIDGET_PTR(mainwin->messageview));
1644                 gtk_widget_show_all(vpaned);
1645                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1646                                      prefs_common.summaryview_width,
1647                                      prefs_common.summaryview_height);
1648                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1649                                      prefs_common.mainview_width, -1);
1650                 gtk_widget_set_usize(mainwin->window,
1651                                      prefs_common.mainview_width,
1652                                      prefs_common.mainview_height);
1653
1654                 gtk_container_add(GTK_CONTAINER(folderwin),
1655                                   GTK_WIDGET_PTR(mainwin->folderview));
1656
1657                 menu_set_sensitive(ifactory, "/View/Message view", FALSE);
1658                 menu_set_sensitive(ifactory, "/View/Folder tree", TRUE);
1659                 
1660                 mainwin->win.sep_folder.folderwin = folderwin;
1661                 mainwin->win.sep_folder.vpaned    = vpaned;
1662
1663                 gtk_widget_show_all(folderwin);
1664                 break;
1665         case SEPARATE_MESSAGE:
1666                 hpaned = gtk_hpaned_new();
1667                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1668
1669                 gtk_paned_add1(GTK_PANED(hpaned),
1670                                GTK_WIDGET_PTR(mainwin->folderview));
1671                 gtk_paned_add2(GTK_PANED(hpaned),
1672                                GTK_WIDGET_PTR(mainwin->summaryview));
1673                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1674                                      prefs_common.summaryview_width,
1675                                      prefs_common.summaryview_height);
1676                 gtk_widget_set_usize(mainwin->window,
1677                                      prefs_common.folderview_width +
1678                                      prefs_common.mainview_width,
1679                                      prefs_common.mainwin_height);
1680                 gtk_widget_show_all(hpaned);
1681                 gtk_container_add(GTK_CONTAINER(messagewin),
1682                                   GTK_WIDGET_PTR(mainwin->messageview));
1683         
1684                 menu_set_sensitive(ifactory, "/View/Message view", TRUE);
1685                 menu_set_sensitive(ifactory, "/View/Folder tree", FALSE);
1686
1687                 mainwin->win.sep_message.messagewin = messagewin;
1688                 mainwin->win.sep_message.hpaned     = hpaned;
1689
1690                 gtk_widget_show_all(messagewin);
1691                 break;
1692         case SEPARATE_BOTH:
1693                 gtk_box_pack_start(GTK_BOX(vbox_body),
1694                                    GTK_WIDGET_PTR(mainwin->summaryview),
1695                                    TRUE, TRUE, 0);
1696                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1697                                      prefs_common.summaryview_width,
1698                                      prefs_common.summaryview_height);
1699                 gtk_widget_set_usize(mainwin->window,
1700                                      prefs_common.mainview_width,
1701                                      prefs_common.mainwin_height);
1702                 gtk_container_add(GTK_CONTAINER(folderwin),
1703                                   GTK_WIDGET_PTR(mainwin->folderview));
1704                 gtk_container_add(GTK_CONTAINER(messagewin),
1705                                   GTK_WIDGET_PTR(mainwin->messageview));
1706
1707                 menu_set_sensitive(ifactory, "/View/Message view", TRUE);
1708                 menu_set_sensitive(ifactory, "/View/Folder tree", TRUE);
1709         
1710                 mainwin->win.sep_both.folderwin = folderwin;
1711                 mainwin->win.sep_both.messagewin = messagewin;
1712
1713                 gtk_widget_show_all(folderwin);
1714                 gtk_widget_show_all(messagewin);
1715                 break;
1716         }
1717
1718         mainwin->type = type;
1719
1720         debug_print(_("done.\n"));
1721 }
1722
1723 static void main_window_toolbar_create(MainWindow *mainwin,
1724                                        GtkWidget *container)
1725 {
1726         GtkWidget *toolbar;
1727         GtkWidget *icon_wid;
1728         GtkWidget *get_btn;
1729         GtkWidget *getall_btn;
1730         GtkWidget *compose_mail_btn;
1731         GtkWidget *compose_news_btn;
1732         GtkWidget *reply_btn;
1733         GtkWidget *replyall_btn;
1734         GtkWidget *replysender_btn;
1735         GtkWidget *fwd_btn;
1736         GtkWidget *send_btn;
1737         /*
1738         GtkWidget *prefs_btn;
1739         GtkWidget *account_btn;
1740         */
1741         GtkWidget *next_btn;
1742         GtkWidget *delete_btn;
1743         GtkWidget *exec_btn;
1744         
1745         GtkTooltips *tooltips;
1746
1747         toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1748                                   GTK_TOOLBAR_BOTH);
1749         gtk_container_add(GTK_CONTAINER(container), toolbar);
1750         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1751         gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1752         gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1753                                     GTK_TOOLBAR_SPACE_LINE);
1754
1755         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_RECEIVE);
1756         get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1757                                           _("Get"),
1758                                           _("Get new mail from current account"),
1759                                           "Get",
1760                                           icon_wid, toolbar_inc_cb, mainwin);
1761         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_RECEIVE_ALL);
1762         getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1763                                              _("Get all"),
1764                                              _("Get new mail from all accounts"),
1765                                              "Get all",
1766                                              icon_wid,
1767                                              toolbar_inc_all_cb,
1768                                              mainwin);
1769
1770         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1771
1772         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
1773         send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1774                                            _("Send"),
1775                                            _("Send queued message(s)"),
1776                                            "Send",
1777                                            icon_wid,
1778                                            toolbar_send_cb,
1779                                            mainwin);
1780
1781         /* insert compose mail button widget */                                    
1782         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_COMPOSE);
1783         compose_mail_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1784                                               _("Email"),
1785                                               _("Compose an email message"),
1786                                               "New",
1787                                               icon_wid,
1788                                               toolbar_compose_mail_cb,
1789                                               mainwin);
1790
1791         /* insert compose news button widget */
1792         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1793         compose_news_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1794                                               _("News"),
1795                                               _("Compose a news message"),
1796                                               "New",
1797                                               icon_wid,
1798                                               toolbar_compose_news_cb,
1799                                               mainwin);
1800
1801         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1802         
1803         /* reply button */
1804         
1805         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_REPLY);
1806         reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1807                                             _("Reply"),
1808                                             _("Reply to the message - Right button: more options"),
1809                                             "Reply",
1810                                             icon_wid,
1811                                             toolbar_reply_cb,
1812                                             mainwin);
1813
1814         /* replyall button */
1815
1816         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_REPLY_TO_ALL);
1817         replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1818                                                _("All"),
1819                                                _("Reply to all - Right button: more options"),
1820                                                "Reply to all",
1821                                                icon_wid,
1822                                                toolbar_reply_to_all_cb,
1823                                                mainwin);
1824
1825         /* reply to sender button */
1826         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR);
1827         replysender_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1828                                                   _("Sender"),
1829                                                   _("Reply to sender - Right button: more options"),
1830                                                   "Reply to sender",
1831                                                   icon_wid,
1832                                                   toolbar_reply_to_sender_cb,
1833                                                   mainwin);
1834
1835         /* forward button */
1836         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_FORWARD);
1837         fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1838                                           _("Forward"),
1839                                           _("Forward the message - Right button: more options"),
1840                                           "Fwd",
1841                                           icon_wid,
1842                                           toolbar_forward_cb,
1843                                           mainwin);
1844
1845         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1846
1847         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_CLOSE);
1848         delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1849                                           _("Delete"),
1850                                           _("Delete the message"),
1851                                           "Delete",
1852                                           icon_wid,
1853                                           toolbar_delete_cb,
1854                                           mainwin);
1855
1856         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EXEC);
1857         exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1858                                            _("Execute"),
1859                                            _("Execute marked process"),
1860                                            "Execute",
1861                                            icon_wid,
1862                                            toolbar_exec_cb,
1863                                            mainwin);
1864
1865         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_DOWN_ARROW);
1866         next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1867                                            _("Next"),
1868                                            _("Next unread message"),
1869                                            "Next unread",
1870                                            icon_wid,
1871                                            toolbar_next_unread_cb,
1872                                            mainwin);
1873
1874         /*
1875         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1876
1877         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_PREFERENCES);
1878         prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1879                                             _("Prefs"),
1880                                             _("Common preference"),
1881                                             "Prefs",
1882                                             icon_wid,
1883                                             toolbar_prefs_cb,
1884                                             mainwin);
1885         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_PROPERTIES);
1886         account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1887                                               _("Account"),
1888                                               _("Account setting"),
1889                                               "Account",
1890                                               icon_wid,
1891                                               toolbar_account_cb,
1892                                               mainwin);
1893         gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1894                            GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1895                            mainwin);
1896         */
1897
1898         gtk_signal_connect(GTK_OBJECT(reply_btn), "button_press_event",
1899                 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
1900                 mainwin);
1901         
1902         gtk_signal_connect(GTK_OBJECT(replyall_btn), "button_press_event",
1903                 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
1904                 mainwin);
1905         
1906         gtk_signal_connect(GTK_OBJECT(replysender_btn), "button_press_event",
1907                 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
1908                 mainwin);
1909         
1910         gtk_signal_connect(GTK_OBJECT(fwd_btn), "button_press_event",
1911                 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
1912                 mainwin);
1913         
1914
1915         mainwin->toolbar                         = toolbar;
1916         mainwin->get_btn                         = get_btn;
1917         mainwin->getall_btn                      = getall_btn;
1918         mainwin->compose_mail_btn                = compose_mail_btn;
1919         mainwin->compose_news_btn                = compose_news_btn;
1920         mainwin->reply_btn                       = reply_btn;
1921         mainwin->replyall_btn                    = replyall_btn;
1922         mainwin->replysender_btn                 = replysender_btn;
1923         mainwin->fwd_btn         = fwd_btn;
1924         mainwin->send_btn        = send_btn;
1925         /*
1926         mainwin->prefs_btn       = prefs_btn;
1927         mainwin->account_btn     = account_btn;
1928         */
1929         mainwin->next_btn        = next_btn;
1930         mainwin->delete_btn      = delete_btn;
1931         mainwin->exec_btn        = exec_btn;
1932
1933         gtk_widget_show_all(toolbar);
1934 }
1935
1936 /* callback functions */
1937 static void toolbar_reply_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1938 {
1939         MainWindow *mainwindow = (MainWindow *) data;
1940         
1941         if (!event) return;
1942
1943         if (event->button == 3) {
1944                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1945                 gtk_menu_popup(GTK_MENU(mainwindow->reply_popup), NULL, NULL,
1946                        menu_button_position, widget,
1947                        event->button, event->time);
1948         }
1949 }
1950
1951 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
1952 {
1953         MainWindow *mainwin = (MainWindow *)data;
1954
1955         gtk_button_set_relief(GTK_BUTTON(mainwin->reply_btn), GTK_RELIEF_NONE);
1956         manage_window_focus_in(mainwin->window, NULL, NULL);
1957 }
1958
1959 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1960 {
1961         MainWindow *mainwindow = (MainWindow *) data;
1962         
1963         if (!event) return;
1964
1965         if (event->button == 3) {
1966                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1967                 gtk_menu_popup(GTK_MENU(mainwindow->replyall_popup), NULL, NULL,
1968                        menu_button_position, widget,
1969                        event->button, event->time);
1970         }
1971 }
1972
1973 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
1974 {
1975         MainWindow *mainwin = (MainWindow *)data;
1976
1977         gtk_button_set_relief(GTK_BUTTON(mainwin->replyall_btn), GTK_RELIEF_NONE);
1978         manage_window_focus_in(mainwin->window, NULL, NULL);
1979 }
1980
1981 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1982 {
1983         MainWindow *mainwindow = (MainWindow *) data;
1984         GtkWidget *replysender_menu, *replysender_item;
1985
1986         if (!event) return;
1987
1988         if (event->button == 3) {
1989                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1990                 gtk_menu_popup(GTK_MENU(mainwindow->replysender_popup), NULL, NULL,
1991                        menu_button_position, widget,
1992                        event->button, event->time);
1993         }
1994 }
1995
1996 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
1997 {
1998         MainWindow *mainwin = (MainWindow *)data;
1999
2000         gtk_button_set_relief(GTK_BUTTON(mainwin->replysender_btn), GTK_RELIEF_NONE);
2001         manage_window_focus_in(mainwin->window, NULL, NULL);
2002 }
2003
2004 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2005 {
2006         MainWindow *mainwindow = (MainWindow *) data;
2007         
2008         if (!event) return;
2009
2010         if (event->button == 3) {
2011                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2012                 gtk_menu_popup(GTK_MENU(mainwindow->fwd_popup), NULL, NULL,
2013                        menu_button_position, widget,
2014                        event->button, event->time);
2015         }
2016 }
2017
2018 static void toolbar_forward_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2019 {
2020         MainWindow *mainwin = (MainWindow *)data;
2021
2022         gtk_button_set_relief(GTK_BUTTON(mainwin->fwd_btn), GTK_RELIEF_NONE);
2023         manage_window_focus_in(mainwin->window, NULL, NULL);
2024 }
2025
2026 static void toolbar_inc_cb      (GtkWidget      *widget,
2027                                  gpointer        data)
2028 {
2029         MainWindow *mainwin = (MainWindow *)data;
2030
2031         inc_mail_cb(mainwin, 0, NULL);
2032 }
2033
2034 static void toolbar_inc_all_cb  (GtkWidget      *widget,
2035                                  gpointer        data)
2036 {
2037         MainWindow *mainwin = (MainWindow *)data;
2038
2039         inc_all_account_mail_cb(mainwin, 0, NULL);
2040 }
2041
2042 static void toolbar_send_cb     (GtkWidget      *widget,
2043                                  gpointer        data)
2044 {
2045         MainWindow *mainwin = (MainWindow *)data;
2046
2047         send_queue_cb(mainwin, 0, NULL);
2048 }
2049
2050 static void toolbar_compose_cb  (GtkWidget      *widget,
2051                                  gpointer        data)
2052 {
2053         MainWindow *mainwin = (MainWindow *)data;
2054
2055         if (mainwin->compose_btn_type == COMPOSEBUTTON_MAIL)
2056                 compose_cb(mainwin, 0, NULL);
2057         else
2058                 compose_news_cb(mainwin, 0, NULL);
2059 }
2060
2061 static void toolbar_compose_news_cb     (GtkWidget      *widget,
2062                                  gpointer        data)
2063 {
2064         MainWindow *mainwin = (MainWindow *)data;
2065
2066         compose_news_cb(mainwin, 0, NULL);
2067 }
2068
2069 static void toolbar_compose_mail_cb     (GtkWidget      *widget,
2070                                  gpointer        data)
2071 {
2072         MainWindow *mainwin = (MainWindow *)data;
2073
2074         compose_mail_cb(mainwin, 0, NULL);
2075 }
2076
2077 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
2078 {
2079         MainWindow *mainwin = (MainWindow *)data;
2080
2081         reply_cb(mainwin, 
2082                  prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE 
2083                  : COMPOSE_REPLY_WITHOUT_QUOTE,
2084                  NULL);
2085 }
2086
2087 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
2088 {
2089         MainWindow *mainwin = (MainWindow *)data;
2090
2091         reply_cb(mainwin, 
2092                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
2093                  : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, 
2094                  NULL);
2095 }
2096
2097
2098 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
2099 {
2100         MainWindow *mainwin = (MainWindow *)data;
2101
2102         reply_cb(mainwin, 
2103                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
2104                  : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, 
2105                  NULL);
2106 }
2107
2108 static void toolbar_forward_cb  (GtkWidget      *widget,
2109                                  gpointer        data)
2110 {
2111         MainWindow *mainwin = (MainWindow *)data;
2112
2113         if (prefs_common.forward_as_attachment)
2114                 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
2115         else
2116                 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
2117 }
2118
2119 static void toolbar_delete_cb   (GtkWidget      *widget,
2120                                  gpointer        data)
2121 {
2122         MainWindow *mainwin = (MainWindow *)data;
2123
2124         summary_delete(mainwin->summaryview);
2125 }
2126
2127 static void toolbar_exec_cb     (GtkWidget      *widget,
2128                                  gpointer        data)
2129 {
2130         MainWindow *mainwin = (MainWindow *)data;
2131
2132         summary_execute(mainwin->summaryview);
2133 }
2134
2135 static void toolbar_next_unread_cb      (GtkWidget      *widget,
2136                                          gpointer        data)
2137 {
2138         MainWindow *mainwin = (MainWindow *)data;
2139
2140         next_unread_cb(mainwin, 0, NULL);
2141 }
2142
2143 static void toolbar_prefs_cb    (GtkWidget      *widget,
2144                                  gpointer        data)
2145 {
2146         prefs_common_open();
2147 }
2148
2149 static void toolbar_account_cb  (GtkWidget      *widget,
2150                                  gpointer        data)
2151 {
2152         MainWindow *mainwin = (MainWindow *)data;
2153
2154         prefs_account_open_cb(mainwin, 0, NULL);
2155 }
2156
2157 static void toolbar_account_button_pressed(GtkWidget *widget,
2158                                            GdkEventButton *event,
2159                                            gpointer data)
2160 {
2161         MainWindow *mainwin = (MainWindow *)data;
2162
2163         if (!event) return;
2164         if (event->button != 3) return;
2165
2166         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2167         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2168                             widget);
2169
2170         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2171                        menu_button_position, widget,
2172                        event->button, event->time);
2173 }
2174
2175 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2176                                     gpointer data)
2177 {
2178         MainWindow *mainwin = (MainWindow *)data;
2179
2180         if (!event) return;
2181
2182         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2183         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2184                             widget);
2185
2186         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2187                        menu_button_position, widget,
2188                        event->button, event->time);
2189 }
2190
2191 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
2192 {
2193         MainWindow *mainwin = (MainWindow *)data;
2194         GtkWidget *button;
2195
2196         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
2197         if (!button) return;
2198         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
2199         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
2200         manage_window_focus_in(mainwin->window, NULL, NULL);
2201 }
2202
2203 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2204                                  gpointer data)
2205 {
2206         MainWindow *mainwin = (MainWindow *)data;
2207
2208         if (mainwin->lock_count == 0)
2209                 app_exit_cb(data, 0, widget);
2210
2211         return TRUE;
2212 }
2213
2214 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2215                            GtkWidget *widget)
2216 {
2217         main_window_add_mailbox(mainwin);
2218 }
2219
2220 static void add_mbox_cb(MainWindow *mainwin, guint action,
2221                         GtkWidget *widget)
2222 {
2223         main_window_add_mbox(mainwin);
2224 }
2225
2226 static void update_folderview_cb(MainWindow *mainwin, guint action,
2227                                  GtkWidget *widget)
2228 {
2229         summary_show(mainwin->summaryview, NULL, FALSE);
2230         folderview_update_all();
2231 }
2232
2233 static void new_folder_cb(MainWindow *mainwin, guint action,
2234                           GtkWidget *widget)
2235 {
2236         folderview_new_folder(mainwin->folderview);
2237 }
2238
2239 static void rename_folder_cb(MainWindow *mainwin, guint action,
2240                              GtkWidget *widget)
2241 {
2242         folderview_rename_folder(mainwin->folderview);
2243 }
2244
2245 static void delete_folder_cb(MainWindow *mainwin, guint action,
2246                              GtkWidget *widget)
2247 {
2248         folderview_delete_folder(mainwin->folderview);
2249 }
2250
2251 static void import_mbox_cb(MainWindow *mainwin, guint action,
2252                            GtkWidget *widget)
2253 {
2254         import_mbox(mainwin->summaryview->folder_item);
2255 }
2256
2257 static void export_mbox_cb(MainWindow *mainwin, guint action,
2258                            GtkWidget *widget)
2259 {
2260         export_mbox(mainwin->summaryview->folder_item);
2261 }
2262
2263 static void empty_trash_cb(MainWindow *mainwin, guint action,
2264                            GtkWidget *widget)
2265 {
2266         main_window_empty_trash(mainwin, TRUE);
2267 }
2268
2269 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2270 {
2271         summary_save_as(mainwin->summaryview);
2272 }
2273
2274 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2275 {
2276         summary_print(mainwin->summaryview);
2277 }
2278
2279 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2280 {
2281         if (prefs_common.confirm_on_exit) {
2282                 if (alertpanel(_("Exit"), _("Exit this program?"),
2283                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2284                         return;
2285                 manage_window_focus_in(mainwin->window, NULL, NULL);
2286         }
2287
2288         app_will_exit(widget, mainwin);
2289 }
2290
2291 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2292 {
2293         if (action == 1)
2294                 summary_search(mainwin->summaryview);
2295         else
2296                 message_search(mainwin->messageview);
2297 }
2298
2299 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2300                              GtkWidget *widget)
2301 {
2302         switch (mainwin->type) {
2303         case SEPARATE_NONE:
2304         case SEPARATE_MESSAGE:
2305                 break;
2306         case SEPARATE_FOLDER:
2307                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2308                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2309                 else
2310                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2311                 break;
2312         case SEPARATE_BOTH:
2313                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2314                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2315                 else
2316                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2317                 break;
2318         }
2319 }
2320
2321 static void toggle_message_cb(MainWindow *mainwin, guint action,
2322                               GtkWidget *widget)
2323 {
2324         switch (mainwin->type) {
2325         case SEPARATE_NONE:
2326         case SEPARATE_FOLDER:
2327                 break;
2328         case SEPARATE_MESSAGE:
2329                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2330                         gtk_widget_show(mainwin->win.sep_message.messagewin);
2331                 else
2332                         gtk_widget_hide(mainwin->win.sep_message.messagewin);
2333                 break;
2334         case SEPARATE_BOTH:
2335                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2336                         gtk_widget_show(mainwin->win.sep_both.messagewin);
2337                 else
2338                         gtk_widget_hide(mainwin->win.sep_both.messagewin);
2339                 break;
2340         }
2341 }
2342
2343 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2344                               GtkWidget *widget)
2345 {
2346 /*      activate_compose_button(mainwin, (ToolbarStyle)action, 
2347                         mainwin->compose_btn_type);
2348         set_toolbar_reply_button(mainwin, (ToolbarStyle)action);
2349         set_toolbar_replyall_button(mainwin, (ToolbarStyle)action);
2350         set_toolbar_replysender_button(mainwin, (ToolbarStyle)action);
2351         set_toolbar_forward_button(mainwin, (ToolbarStyle)action);*/
2352         
2353         switch ((ToolbarStyle)action) {
2354         case TOOLBAR_NONE:
2355                 gtk_widget_hide(mainwin->handlebox);
2356         case TOOLBAR_ICON:
2357                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2358                                       GTK_TOOLBAR_ICONS);
2359                 break;
2360         case TOOLBAR_TEXT:
2361                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2362                                       GTK_TOOLBAR_TEXT);
2363                 break;
2364         case TOOLBAR_BOTH:
2365                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2366                                       GTK_TOOLBAR_BOTH);
2367                 break;
2368         }
2369
2370         if (action != TOOLBAR_NONE) {
2371                 gtk_widget_show(mainwin->handlebox);
2372                 gtk_widget_queue_resize(mainwin->handlebox);
2373         }
2374
2375         mainwin->toolbar_style = (ToolbarStyle)action;
2376         prefs_common.toolbar_style = (ToolbarStyle)action;
2377 }
2378
2379 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2380                                 GtkWidget *widget)
2381 {
2382         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2383                 gtk_widget_show(mainwin->hbox_stat);
2384                 prefs_common.show_statusbar = TRUE;
2385         } else {
2386                 gtk_widget_hide(mainwin->hbox_stat);
2387                 prefs_common.show_statusbar = FALSE;
2388         }
2389 }
2390
2391 static void separate_widget_cb(GtkCheckMenuItem *checkitem, guint action, GtkWidget *widget)
2392
2393 {
2394         MainWindow *mainwin;
2395         SeparateType type;
2396
2397         mainwin = (MainWindow *) gtk_object_get_data(GTK_OBJECT(checkitem), "mainwindow");
2398         g_return_if_fail(mainwin != NULL);
2399
2400         type = mainwin->type ^ action;
2401         main_window_separation_change(mainwin, type);
2402
2403         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2404         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2405 }
2406
2407 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2408                                 GtkWidget *widget)
2409 {
2410         addressbook_open(NULL);
2411 }
2412
2413 static void log_window_show_cb(MainWindow *mainwin, guint action,
2414                                GtkWidget *widget)
2415 {
2416         log_window_show(mainwin->logwin);
2417 }
2418
2419 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2420 {
2421         inc_mail(mainwin);
2422 }
2423
2424 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
2425                                     GtkWidget *widget)
2426 {
2427         inc_all_account_mail(mainwin);
2428 }
2429
2430 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2431 {
2432         GList *list;
2433
2434         if (procmsg_send_queue() < 0)
2435                 alertpanel_error(_("Some errors occurred while sending queued messages."));
2436
2437         statusbar_pop_all();
2438
2439         for (list = folder_get_list(); list != NULL; list = list->next) {
2440                 Folder *folder;
2441
2442                 folder = list->data;
2443                 if (folder->queue) {
2444                         folder_item_scan(folder->queue);
2445                         folderview_update_item(folder->queue, TRUE);
2446                 }
2447         }
2448 }
2449
2450 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2451 {
2452         if (mainwin->summaryview->folder_item) {
2453                 if (mainwin->summaryview->folder_item->folder->account != NULL
2454                     && mainwin->summaryview->folder_item->folder->account->protocol == A_NNTP)
2455                         compose_new_with_recipient(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item->path);
2456                 else
2457                         compose_new_with_folderitem(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item);
2458         }
2459         else
2460                 compose_new(NULL);
2461 }
2462
2463 static void compose_mail_cb(MainWindow *mainwin, guint action,
2464                             GtkWidget *widget)
2465 {
2466         PrefsAccount * ac;
2467         GList * list;
2468         GList * cur;
2469
2470         if (mainwin->summaryview->folder_item) {
2471                 ac = mainwin->summaryview->folder_item->folder->account;
2472                 if (ac && ac->protocol != A_NNTP) {
2473                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2474                         return;
2475                 }
2476         }
2477
2478         if(cur_account && (cur_account->protocol != A_NNTP)) {
2479                 compose_new_with_folderitem(cur_account, mainwin->summaryview->folder_item);
2480                 return;
2481         }
2482
2483         list = account_get_list();
2484         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2485                 ac = (PrefsAccount *) cur->data;
2486                 if (ac->protocol != A_NNTP) {
2487                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2488                         return;
2489                 }
2490         }
2491 }
2492
2493 static void compose_news_cb(MainWindow *mainwin, guint action,
2494                             GtkWidget *widget)
2495 {
2496         PrefsAccount * ac = NULL;
2497         GList * list;
2498         GList * cur;
2499
2500         if (mainwin->summaryview->folder_item) {
2501                 ac = mainwin->summaryview->folder_item->folder->account;
2502                 if (ac && ac->protocol == A_NNTP) {
2503                         compose_new_with_recipient
2504                                 (ac, mainwin->summaryview->folder_item->path);
2505                         return;
2506                 }
2507         }
2508
2509         list = account_get_list();
2510         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2511                 ac = (PrefsAccount *) cur->data;
2512                 if (ac->protocol == A_NNTP) {
2513                         compose_new(ac);
2514                         return;
2515                 }
2516         }
2517 }
2518
2519 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2520 {
2521         GList  *sel = GTK_CLIST(mainwin->summaryview->ctree)->selection;
2522         MsgInfo *msginfo;
2523
2524         msginfo = gtk_ctree_node_get_row_data
2525                 (GTK_CTREE(mainwin->summaryview->ctree),
2526                  mainwin->summaryview->selected);
2527
2528         if (!msginfo) return;
2529
2530         switch (action) {
2531         case COMPOSE_REPLY:
2532                 compose_reply(msginfo, prefs_common.reply_with_quote,
2533                               FALSE, FALSE);
2534                 break;
2535         case COMPOSE_REPLY_WITH_QUOTE:
2536                 compose_reply(msginfo, TRUE, FALSE, FALSE);
2537                 break;
2538         case COMPOSE_REPLY_WITHOUT_QUOTE:
2539                 compose_reply(msginfo, FALSE, FALSE, FALSE);
2540                 break;
2541         case COMPOSE_REPLY_TO_SENDER:
2542                 compose_reply(msginfo, prefs_common.reply_with_quote,
2543                               FALSE, TRUE);
2544                 break;
2545         case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
2546                 compose_reply(msginfo, TRUE, FALSE, TRUE);
2547                 break;
2548         case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
2549                 compose_reply(msginfo, FALSE, FALSE, TRUE);
2550                 break;
2551         case COMPOSE_FOLLOWUP_AND_REPLY_TO:
2552                 compose_followup_and_reply_to(msginfo,
2553                                               prefs_common.reply_with_quote,
2554                                               FALSE, TRUE);
2555                 break;
2556         case COMPOSE_REPLY_TO_ALL:
2557                 compose_reply(msginfo, prefs_common.reply_with_quote,
2558                               TRUE, TRUE);
2559                 break;
2560         case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
2561                 compose_reply(msginfo, TRUE, TRUE, TRUE);
2562                 break;
2563         case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
2564                 compose_reply(msginfo, FALSE, TRUE, TRUE);
2565                 break;
2566         case COMPOSE_FORWARD:
2567                 if (prefs_common.forward_as_attachment) {
2568                         reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, widget);
2569                         return;
2570                 } else {
2571                         reply_cb(mainwin, COMPOSE_FORWARD_INLINE, widget);
2572                         return;
2573                 }
2574                 break;
2575         case COMPOSE_FORWARD_INLINE:
2576                 if (!sel->next) {
2577                         compose_forward(NULL, msginfo, FALSE);
2578                         break;
2579                 }
2580                 /* if (sel->next) FALL_THROUGH */
2581         case COMPOSE_FORWARD_AS_ATTACH:
2582                 {
2583                         GSList *msginfo_list = NULL;
2584                         for ( ; sel != NULL; sel = sel->next)
2585                                 msginfo_list = g_slist_append(msginfo_list, 
2586                                         gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->summaryview->ctree),
2587                                                 GTK_CTREE_NODE(sel->data)));
2588                         compose_forward_multiple(NULL, msginfo_list);
2589                         g_slist_free(msginfo_list);
2590                 }                       
2591                 break;
2592         case COMPOSE_BOUNCE:
2593                         compose_bounce(NULL, msginfo);
2594                         break;
2595         default:
2596                 g_warning("reply_cb(): invalid action type: %d\n", action);
2597         }
2598
2599         summary_set_marks_selected(mainwin->summaryview);
2600 }
2601
2602 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2603 {
2604         summary_move_to(mainwin->summaryview);
2605 }
2606
2607 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2608 {
2609         summary_copy_to(mainwin->summaryview);
2610 }
2611
2612 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2613 {
2614         summary_delete(mainwin->summaryview);
2615 }
2616
2617 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2618 {
2619         summary_open_msg(mainwin->summaryview);
2620 }
2621
2622 static void view_source_cb(MainWindow *mainwin, guint action,
2623                            GtkWidget *widget)
2624 {
2625         summary_view_source(mainwin->summaryview);
2626 }
2627
2628 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2629 {
2630         summary_reedit(mainwin->summaryview);
2631 }
2632
2633 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2634 {
2635         summary_mark(mainwin->summaryview);
2636 }
2637
2638 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2639 {
2640         summary_unmark(mainwin->summaryview);
2641 }
2642
2643 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2644                               GtkWidget *widget)
2645 {
2646         summary_mark_as_unread(mainwin->summaryview);
2647 }
2648
2649 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2650                             GtkWidget *widget)
2651 {
2652         summary_mark_as_read(mainwin->summaryview);
2653 }
2654
2655 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2656                              GtkWidget *widget)
2657 {
2658         summary_mark_all_read(mainwin->summaryview);
2659 }
2660
2661 static void add_address_cb(MainWindow *mainwin, guint action,
2662                            GtkWidget *widget)
2663 {
2664         summary_add_address(mainwin->summaryview);
2665 }
2666
2667 static void set_charset_cb(MainWindow *mainwin, guint action,
2668                            GtkWidget *widget)
2669 {
2670         const gchar *str;
2671
2672         str = conv_get_charset_str((CharSet)action);
2673         g_free(prefs_common.force_charset);
2674         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2675
2676         summary_redisplay_msg(mainwin->summaryview);
2677
2678         debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
2679 }
2680
2681 static void hide_read_messages (MainWindow *mainwin, guint action,
2682                                 GtkWidget *widget)
2683 {
2684         if (!mainwin->summaryview->folder_item
2685             || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
2686                 return;
2687         summary_toggle_show_read_messages(mainwin->summaryview);
2688 }
2689
2690 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2691 {
2692         GtkItemFactory *ifactory;
2693
2694         if (!mainwin->summaryview->folder_item) return;
2695
2696         ifactory = gtk_item_factory_from_widget(widget);
2697
2698         if (0 == action) {
2699                 summary_thread_build(mainwin->summaryview);
2700                 mainwin->summaryview->folder_item->threaded = TRUE;
2701                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
2702                 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
2703         } else {
2704                 summary_unthread(mainwin->summaryview);
2705                 mainwin->summaryview->folder_item->threaded = FALSE;
2706                 menu_set_sensitive(ifactory, "/Summary/Thread view",   TRUE);
2707                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
2708         }
2709 }
2710
2711 static void set_display_item_cb(MainWindow *mainwin, guint action,
2712                                 GtkWidget *widget)
2713 {
2714         prefs_summary_column_open();
2715 }
2716
2717 static void sort_summary_cb(MainWindow *mainwin, guint action,
2718                             GtkWidget *widget)
2719 {
2720         summary_sort(mainwin->summaryview, (SummarySortType)action);
2721 }
2722
2723 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2724                                   GtkWidget *widget)
2725 {
2726         summary_attract_by_subject(mainwin->summaryview);
2727 }
2728
2729 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2730                                  GtkWidget *widget)
2731 {
2732         summary_delete_duplicated(mainwin->summaryview);
2733 }
2734
2735 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2736 {
2737         summary_filter(mainwin->summaryview);
2738 }
2739
2740 static void execute_summary_cb(MainWindow *mainwin, guint action,
2741                                GtkWidget *widget)
2742 {
2743         summary_execute(mainwin->summaryview);
2744 }
2745
2746 static void update_summary_cb(MainWindow *mainwin, guint action,
2747                               GtkWidget *widget)
2748 {
2749         FolderItem *fitem;
2750         FolderView *folderview = mainwin->folderview;
2751
2752         if (!mainwin->summaryview->folder_item) return;
2753         if (!folderview->opened) return;
2754
2755         folder_update_op_count();
2756
2757         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2758                                             folderview->opened);
2759         if (!fitem) return;
2760
2761         summary_show(mainwin->summaryview, fitem, TRUE);
2762 }
2763
2764 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2765 {
2766         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2767 }
2768
2769 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2770 {
2771         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2772 }
2773
2774 static void prev_unread_cb(MainWindow *mainwin, guint action,
2775                            GtkWidget *widget)
2776 {
2777         summary_select_prev_unread(mainwin->summaryview);
2778 }
2779
2780 static void next_unread_cb(MainWindow *mainwin, guint action,
2781                            GtkWidget *widget)
2782 {
2783         summary_select_next_unread(mainwin->summaryview);
2784 }
2785
2786 static void prev_marked_cb(MainWindow *mainwin, guint action,
2787                            GtkWidget *widget)
2788 {
2789         summary_select_prev_marked(mainwin->summaryview);
2790 }
2791
2792 static void next_marked_cb(MainWindow *mainwin, guint action,
2793                            GtkWidget *widget)
2794 {
2795         summary_select_next_marked(mainwin->summaryview);
2796 }
2797
2798 static void prev_labeled_cb(MainWindow *mainwin, guint action,
2799                             GtkWidget *widget)
2800 {
2801         summary_select_prev_labeled(mainwin->summaryview);
2802 }
2803
2804 static void next_labeled_cb(MainWindow *mainwin, guint action,
2805                             GtkWidget *widget)
2806 {
2807         summary_select_next_labeled(mainwin->summaryview);
2808 }
2809
2810 static void goto_folder_cb(MainWindow *mainwin, guint action,
2811                            GtkWidget *widget)
2812 {
2813         FolderItem *to_folder;
2814
2815         to_folder = foldersel_folder_sel(NULL, NULL);
2816
2817         if (to_folder)
2818                 folderview_select(mainwin->folderview, to_folder);
2819 }
2820
2821 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2822 {
2823         messageview_copy_clipboard(mainwin->messageview);
2824 }
2825
2826 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2827 {
2828         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2829                 summary_select_all(mainwin->summaryview);
2830         else if (mainwin->summaryview->msg_is_toggled_on &&
2831                  GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2832                 messageview_select_all(mainwin->messageview);
2833 }
2834
2835 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2836                                  GtkWidget *widget)
2837 {
2838         prefs_common_open();
2839 }
2840
2841 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2842                                  GtkWidget *widget)
2843 {
2844         prefs_filter_open();
2845 }
2846
2847 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2848                                   GtkWidget *widget)
2849 {
2850         prefs_scoring_open(NULL);
2851 }
2852
2853 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2854                                     GtkWidget *widget)
2855 {
2856         prefs_filtering_open(NULL);
2857 }
2858
2859 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
2860                                    GtkWidget *widget)
2861 {
2862         prefs_template_open();
2863 }
2864
2865 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2866                                   GtkWidget *widget)
2867 {
2868         if (!cur_account) {
2869                 new_account_cb(mainwin, 0, widget);
2870         } else {
2871                 gboolean prev_default = cur_account->is_default;
2872
2873                 prefs_account_open(cur_account);
2874                 if (!prev_default && cur_account->is_default)
2875                         account_set_as_default(cur_account);
2876                 account_save_config_all();
2877                 account_set_menu();
2878                 main_window_reflect_prefs_all();
2879         }
2880 }
2881
2882 static void new_account_cb(MainWindow *mainwin, guint action,
2883                            GtkWidget *widget)
2884 {
2885         account_edit_open();
2886         if (!compose_get_compose_list()) account_add();
2887 }
2888
2889 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2890 {
2891         cur_account = (PrefsAccount *)data;
2892         main_window_reflect_prefs_all();
2893 }
2894
2895 static void manual_open_cb(MainWindow *mainwin, guint action,
2896                            GtkWidget *widget)
2897 {
2898         manual_open((ManualLang)action);
2899 }
2900
2901 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2902 {
2903         MainWindow *mainwin = (MainWindow *)data;
2904         gchar *str;
2905
2906         if (item->path)
2907                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2908                                       LOCAL_FOLDER(folder)->rootpath,
2909                                       G_DIR_SEPARATOR,
2910                                       item->path);
2911         else
2912                 str = g_strdup_printf(_("Scanning folder %s ..."),
2913                                       LOCAL_FOLDER(folder)->rootpath);
2914
2915         STATUSBAR_PUSH(mainwin, str);
2916         STATUSBAR_POP(mainwin);
2917         g_free(str);
2918 }
2919
2920 static void activate_compose_button (MainWindow *mainwin,
2921                                 ToolbarStyle style,
2922                                 ComposeButtonType type)
2923 {
2924         SensitiveCond state = main_window_get_current_state(mainwin);
2925
2926         if (style == TOOLBAR_NONE) 
2927                 return;
2928
2929         gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? mainwin->compose_mail_btn 
2930                 : mainwin->compose_news_btn);
2931         gtk_widget_show(type == COMPOSEBUTTON_NEWS ? mainwin->compose_news_btn
2932                 : mainwin->compose_mail_btn);
2933         mainwin->compose_btn_type = type;       
2934 }
2935
2936 void main_window_toolbar_set_compose_button(MainWindow *mainwin, ComposeButtonType compose_btn_type)
2937 {
2938         if (mainwin->compose_btn_type != compose_btn_type)
2939                 activate_compose_button(mainwin, 
2940                                         prefs_common.toolbar_style,
2941                                         compose_btn_type);
2942 }