f8e3f34e253ec636bfe6750b062b8eb8283f1043
[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         gboolean hasTrash = 0;
1205
1206         for (list = folder_get_list(); list != NULL; list = list->next) {
1207                 Folder *folder;
1208
1209                 folder = list->data;
1210                 if (folder->trash) {
1211                         hasTrash = (folder->trash->total > 0);
1212                 }
1213         }
1214
1215         if (!hasTrash) {
1216           return;
1217         }
1218  
1219         if (confirm) {
1220                 if (alertpanel(_("Empty trash"),
1221                                _("Empty all messages in trash?"),
1222                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1223                         return;
1224                 manage_window_focus_in(mainwin->window, NULL, NULL);
1225         }
1226
1227         procmsg_empty_trash();
1228
1229         for (list = folder_get_list(); list != NULL; list = list->next) {
1230                 Folder *folder;
1231
1232                 folder = list->data;
1233                 if (folder->trash && folder->trash->total != 0) {
1234                         folder_item_scan(folder->trash);
1235                         folderview_update_item(folder->trash, TRUE);
1236                 }
1237         }
1238
1239         if (mainwin->summaryview->folder_item &&
1240             mainwin->summaryview->folder_item->stype == F_TRASH)
1241                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1242 }
1243
1244 void main_window_add_mailbox(MainWindow *mainwin)
1245 {
1246         gchar *path;
1247         Folder *folder;
1248
1249         path = input_dialog(_("Add mailbox"),
1250                             _("Input the location of mailbox.\n"
1251                               "If the existing mailbox is specified, it will be\n"
1252                               "scanned automatically."),
1253                             "Mail");
1254         if (!path) return;
1255         if (folder_find_from_path(path)) {
1256                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1257                 g_free(path);
1258                 return;
1259         }
1260         if (!strcmp(path, "Mail"))
1261                 folder = folder_new(F_MH, _("Mailbox"), path);
1262         else
1263                 folder = folder_new(F_MH, g_basename(path), path);
1264         g_free(path);
1265
1266         if (folder->create_tree(folder) < 0) {
1267                 alertpanel_error(_("Creation of the mailbox failed.\n"
1268                                    "Maybe some files already exist, or you don't have the permission to write there."));
1269                 folder_destroy(folder);
1270                 return;
1271         }
1272
1273         folder_add(folder);
1274         folder_set_ui_func(folder, scan_tree_func, mainwin);
1275         folder->scan_tree(folder);
1276         folder_set_ui_func(folder, NULL, NULL);
1277
1278         folderview_set(mainwin->folderview);
1279 }
1280
1281 void main_window_add_mbox(MainWindow *mainwin)
1282 {
1283         gchar *path;
1284         Folder *folder;
1285         FolderItem * item;
1286
1287         path = input_dialog(_("Add mbox mailbox"),
1288                             _("Input the location of mailbox."),
1289                             "mail");
1290
1291         if (!path) return;
1292
1293         if (folder_find_from_path(path)) {
1294                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1295                 g_free(path);
1296                 return;
1297         }
1298
1299         /*
1300         if (!strcmp(path, "Mail"))
1301                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1302                 else
1303         */
1304
1305         folder = folder_new(F_MBOX, g_basename(path), path);
1306         g_free(path);
1307
1308         if (folder->create_tree(folder) < 0) {
1309                 alertpanel_error(_("Creation of the mailbox failed."));
1310                 folder_destroy(folder);
1311                 return;
1312         }
1313
1314         folder_add(folder);
1315
1316         item = folder_item_new(folder->name, NULL);
1317         item->folder = folder;
1318         folder->node = g_node_new(item);
1319
1320         folder->create_folder(folder, item, "inbox");
1321         folder->create_folder(folder, item, "outbox");
1322         folder->create_folder(folder, item, "queue");
1323         folder->create_folder(folder, item, "draft");
1324         folder->create_folder(folder, item, "trash");
1325
1326         folderview_set(mainwin->folderview);
1327 }
1328
1329 typedef enum
1330 {
1331         M_UNLOCKED            = 1 << 0,
1332         M_MSG_EXIST           = 1 << 1,
1333         M_TARGET_EXIST        = 1 << 2,
1334         M_SINGLE_TARGET_EXIST = 1 << 3,
1335         M_EXEC                = 1 << 4,
1336         M_ALLOW_REEDIT        = 1 << 5,
1337         M_HAVE_ACCOUNT        = 1 << 6,
1338         M_THREADED            = 1 << 7,
1339         M_UNTHREADED          = 1 << 8,
1340         M_NEWS                = 1 << 9,
1341         M_HAVE_NEWS_ACCOUNT   = 1 << 10
1342 } SensitiveCond;
1343
1344 static SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1345 {
1346         SensitiveCond state = 0;
1347         SummarySelection selection;
1348         FolderItem *item = mainwin->summaryview->folder_item;
1349         GList *account_list = account_get_list();
1350         
1351         selection = summary_get_selection_type(mainwin->summaryview);
1352
1353         if (mainwin->lock_count == 0)
1354                 state |= M_UNLOCKED;
1355         if (selection != SUMMARY_NONE)
1356                 state |= M_MSG_EXIST;
1357         if (item) {
1358                 if (item->threaded)
1359                         state |= M_THREADED;
1360                 else
1361                         state |= M_UNTHREADED;  
1362         }               
1363         if (selection == SUMMARY_SELECTED_SINGLE ||
1364             selection == SUMMARY_SELECTED_MULTIPLE)
1365                 state |= M_TARGET_EXIST;
1366         if (selection == SUMMARY_SELECTED_SINGLE)
1367                 state |= M_SINGLE_TARGET_EXIST;
1368         if (item && item->folder->type != F_NEWS)
1369                 state |= M_EXEC;
1370         if (mainwin->summaryview->folder_item &&
1371             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1372                 state |= M_NEWS;
1373         if (selection == SUMMARY_SELECTED_SINGLE &&
1374             (item &&
1375              (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1376               item->stype == F_QUEUE)))
1377                 state |= M_ALLOW_REEDIT;
1378         if (cur_account)
1379                 state |= M_HAVE_ACCOUNT;
1380         
1381         for ( ; account_list != NULL; account_list = account_list->next) {
1382                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
1383                         state |= M_HAVE_NEWS_ACCOUNT;
1384                         break;
1385                 }
1386         }
1387
1388         return state;
1389 }
1390
1391 void main_window_set_toolbar_sensitive(MainWindow *mainwin)
1392 {
1393         SensitiveCond state;
1394     gboolean sensitive;
1395         gint i;
1396
1397         const struct {
1398                 GtkWidget *widget;
1399                 SensitiveCond cond;
1400         } entry[] = {
1401                 {mainwin->get_btn         , M_HAVE_ACCOUNT|M_UNLOCKED},
1402                 {mainwin->getall_btn      , M_HAVE_ACCOUNT|M_UNLOCKED},
1403                 {mainwin->compose_mail_btn, M_HAVE_ACCOUNT},
1404                 {mainwin->compose_news_btn, M_HAVE_NEWS_ACCOUNT},
1405                 {mainwin->reply_btn       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1406                 {mainwin->replyall_btn    , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1407                 {mainwin->replysender_btn , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1408                 {mainwin->fwd_btn         , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1409                 /* {mainwin->prefs_btn      , M_UNLOCKED},
1410                 {mainwin->account_btn    , M_UNLOCKED}, */
1411                 {mainwin->next_btn        , M_MSG_EXIST},
1412                 {mainwin->delete_btn      , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1413                 {mainwin->exec_btn        , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1414                 {NULL, 0}
1415         };
1416
1417         state = main_window_get_current_state(mainwin);
1418
1419         for (i = 0; entry[i].widget != NULL; i++) {
1420                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1421                 gtk_widget_set_sensitive(entry[i].widget, sensitive);
1422         }
1423
1424         activate_compose_button(mainwin, 
1425                         prefs_common.toolbar_style,
1426                         mainwin->compose_btn_type);
1427 }
1428
1429 void main_window_set_menu_sensitive(MainWindow *mainwin)
1430 {
1431         GtkItemFactory *ifactory;
1432         SensitiveCond state;
1433         gboolean sensitive;
1434         gint i;
1435
1436         static const struct {
1437                 gchar *const entry;
1438                 SensitiveCond cond;
1439         } entry[] = {
1440                 {"/File/Add mailbox..."        , M_UNLOCKED},
1441                 {"/File/Add mbox mailbox..."   , M_UNLOCKED},
1442                 {"/File/Rescan folder tree"    , M_UNLOCKED},
1443                 {"/File/Folder"                , M_UNLOCKED},
1444                 {"/File/Import mbox file..."   , M_UNLOCKED},
1445                 {"/File/Export to mbox file...", M_UNLOCKED},
1446                 {"/File/Empty trash"           , M_UNLOCKED},
1447                 {"/File/Save as...", M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1448                 {"/File/Print..."  , M_TARGET_EXIST|M_UNLOCKED},
1449 /*              {"/File/Close", M_UNLOCKED},*/
1450                 {"/File/Exit" , M_UNLOCKED},
1451
1452                 {"/View/Show all header"      , M_SINGLE_TARGET_EXIST},
1453                 {"/View/View source"          , M_SINGLE_TARGET_EXIST},
1454
1455                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1456                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1457 /*              {"/Message/Compose new message"   , M_HAVE_ACCOUNT}, */
1458                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
1459                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1460                 {"/Message/Reply to sender"       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1461                 {"/Message/Reply to all"          , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1462                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1463                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1464                 {"/Message/Bounce"                , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1465                 {"/Message/Open in new window"    , M_SINGLE_TARGET_EXIST},
1466                 {"/Message/Re-edit", M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1467                 {"/Message/Move...", M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1468                 {"/Message/Copy...", M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1469                 {"/Message/Delete" , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1470                 {"/Message/Mark"   , M_TARGET_EXIST},
1471
1472                 {"/Summary/Delete duplicated messages", M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1473                 {"/Summary/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1474                 {"/Summary/Execute"                   , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1475                 {"/Summary/Go to"                     , M_MSG_EXIST},
1476                 {"/Summary/Go to/Prev message"        , M_MSG_EXIST},
1477                 {"/Summary/Go to/Next message"        , M_MSG_EXIST},
1478                 {"/Summary/Go to/Next unread message" , M_MSG_EXIST},
1479                 {"/Summary/Go to/Prev marked message" , M_MSG_EXIST},
1480                 {"/Summary/Go to/Next marked message" , M_MSG_EXIST},
1481                 {"/Summary/Go to/Prev labeled message", M_MSG_EXIST},
1482                 {"/Summary/Go to/Next labeled message", M_MSG_EXIST},
1483                 {"/Summary/Sort"                      , M_MSG_EXIST},
1484                 {"/Summary/Thread view"               , M_UNTHREADED},
1485                 {"/Summary/Unthread view"             , M_THREADED},
1486
1487                 {"/Configuration", M_UNLOCKED},
1488
1489                 {NULL, 0}
1490         };
1491         
1492         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1493         state = main_window_get_current_state(mainwin);
1494
1495         for (i = 0; entry[i].entry != NULL; i++) {
1496                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1497                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
1498         }
1499 }
1500
1501 void main_window_popup(MainWindow *mainwin)
1502 {
1503         gint x, y;
1504         gint sx, sy;
1505         GtkWidget *widget;
1506
1507         gdk_window_get_origin(mainwin->window->window, &x, &y);
1508         sx = gdk_screen_width();
1509         sy = gdk_screen_height();
1510         x %= sx; if (x < 0) x = 0;
1511         y %= sy; if (y < 0) y = 0;
1512         gdk_window_move(mainwin->window->window, x, y);
1513         gdk_window_raise(mainwin->window->window);
1514         gdk_window_show(mainwin->window->window);
1515
1516         debug_print("window position: x = %d, y = %d\n", x, y);
1517
1518         switch (mainwin->type) {
1519         case SEPARATE_FOLDER:
1520                 widget = mainwin->win.sep_folder.folderwin;
1521                 gdk_window_get_origin(widget->window, &x, &y);
1522                 x %= sx; if (x < 0) x = 0;
1523                 y %= sy; if (y < 0) y = 0;
1524                 gdk_window_move(widget->window, x, y);
1525                 gdk_window_raise(widget->window);
1526                 break;
1527         case SEPARATE_MESSAGE:
1528                 widget = mainwin->win.sep_message.messagewin;
1529                 gdk_window_get_origin(widget->window, &x, &y);
1530                 x %= sx; if (x < 0) x = 0;
1531                 y %= sy; if (y < 0) y = 0;
1532                 gdk_window_move(widget->window, x, y);
1533                 gdk_window_raise(widget->window);
1534                 break;
1535         case SEPARATE_BOTH:
1536                 widget = mainwin->win.sep_both.folderwin;
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                 widget = mainwin->win.sep_both.messagewin;
1543                 gdk_window_get_origin(widget->window, &x, &y);
1544                 x %= sx; if (x < 0) x = 0;
1545                 y %= sy; if (y < 0) y = 0;
1546                 gdk_window_move(widget->window, x, y);
1547                 gdk_window_raise(widget->window);
1548                 break;
1549         default:
1550                 break;
1551         }
1552 }
1553
1554 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1555 {
1556         GtkWidget *folderwin = NULL;
1557         GtkWidget *messagewin = NULL;
1558         GtkWidget *hpaned;
1559         GtkWidget *vpaned;
1560         GtkWidget *vbox_body = mainwin->vbox_body;
1561         GtkItemFactory *ifactory=gtk_item_factory_from_widget(mainwin->menubar);
1562
1563         debug_print(_("Setting widgets..."));
1564
1565         /* create separated window(s) if needed */
1566         if (type & SEPARATE_FOLDER) {
1567                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1568                 gtk_window_set_title(GTK_WINDOW(folderwin), _("Sylpheed - folder view"));
1569                 gtk_window_set_wmclass(GTK_WINDOW(folderwin), "separate folderview", "Sylpheed");
1570                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1571                                       TRUE, TRUE, FALSE);
1572                 gtk_widget_set_usize(folderwin, -1,
1573                                      prefs_common.mainview_height);
1574                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1575                                                BORDER_WIDTH);
1576                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1577                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1578                                    NULL);
1579         }
1580         if (type & SEPARATE_MESSAGE) {
1581                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1582                 gtk_window_set_title(GTK_WINDOW(messagewin), _("Sylpheed - message view"));
1583                 gtk_window_set_wmclass(GTK_WINDOW(messagewin), "separate messageview", "Sylpheed");
1584                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1585                                       TRUE, TRUE, FALSE);
1586                 gtk_widget_set_usize
1587                         (messagewin, prefs_common.mainview_width,
1588                          prefs_common.mainview_height
1589                          - prefs_common.summaryview_height
1590                          + DEFAULT_HEADERVIEW_HEIGHT);
1591                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1592                                                BORDER_WIDTH);
1593                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1594                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1595                                    NULL);
1596         }
1597
1598         switch (type) {
1599         case SEPARATE_NONE:
1600                 hpaned = gtk_hpaned_new();
1601                 gtk_widget_show(hpaned);
1602                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1603                 gtk_paned_add1(GTK_PANED(hpaned),
1604                                GTK_WIDGET_PTR(mainwin->folderview));
1605
1606                 vpaned = gtk_vpaned_new();
1607                 if (mainwin->summaryview->msg_is_toggled_on) {
1608                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1609                         gtk_paned_add1(GTK_PANED(vpaned),
1610                                        GTK_WIDGET_PTR(mainwin->summaryview));
1611                 } else {
1612                         gtk_paned_add2(GTK_PANED(hpaned),
1613                                        GTK_WIDGET_PTR(mainwin->summaryview));
1614                         gtk_widget_ref(vpaned);
1615                 }
1616                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1617                                      prefs_common.summaryview_width,
1618                                      prefs_common.summaryview_height);
1619                 gtk_paned_add2(GTK_PANED(vpaned),
1620                                GTK_WIDGET_PTR(mainwin->messageview));
1621                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1622                                      prefs_common.mainview_width, -1);
1623                 gtk_widget_set_usize(mainwin->window,
1624                                      prefs_common.folderview_width +
1625                                      prefs_common.mainview_width,
1626                                      prefs_common.mainwin_height);
1627                 gtk_widget_show_all(vpaned);
1628
1629                 menu_set_sensitive(ifactory, "/View/Message view", FALSE);
1630                 menu_set_sensitive(ifactory, "/View/Folder tree", FALSE);
1631                 
1632                 mainwin->win.sep_none.hpaned = hpaned;
1633                 mainwin->win.sep_none.vpaned = vpaned;
1634                 break;
1635         case SEPARATE_FOLDER:
1636                 vpaned = gtk_vpaned_new();
1637                 if (mainwin->summaryview->msg_is_toggled_on) {
1638                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1639                                            TRUE, TRUE, 0);
1640                         gtk_paned_add1(GTK_PANED(vpaned),
1641                                        GTK_WIDGET_PTR(mainwin->summaryview));
1642                 } else {
1643                         gtk_box_pack_start(GTK_BOX(vbox_body),
1644                                            GTK_WIDGET_PTR(mainwin->summaryview),
1645                                            TRUE, TRUE, 0);
1646                         gtk_widget_ref(vpaned);
1647                 }
1648                 gtk_paned_add2(GTK_PANED(vpaned),
1649                                GTK_WIDGET_PTR(mainwin->messageview));
1650                 gtk_widget_show_all(vpaned);
1651                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1652                                      prefs_common.summaryview_width,
1653                                      prefs_common.summaryview_height);
1654                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1655                                      prefs_common.mainview_width, -1);
1656                 gtk_widget_set_usize(mainwin->window,
1657                                      prefs_common.mainview_width,
1658                                      prefs_common.mainview_height);
1659
1660                 gtk_container_add(GTK_CONTAINER(folderwin),
1661                                   GTK_WIDGET_PTR(mainwin->folderview));
1662
1663                 menu_set_sensitive(ifactory, "/View/Message view", FALSE);
1664                 menu_set_sensitive(ifactory, "/View/Folder tree", TRUE);
1665                 
1666                 mainwin->win.sep_folder.folderwin = folderwin;
1667                 mainwin->win.sep_folder.vpaned    = vpaned;
1668
1669                 gtk_widget_show_all(folderwin);
1670                 break;
1671         case SEPARATE_MESSAGE:
1672                 hpaned = gtk_hpaned_new();
1673                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1674
1675                 gtk_paned_add1(GTK_PANED(hpaned),
1676                                GTK_WIDGET_PTR(mainwin->folderview));
1677                 gtk_paned_add2(GTK_PANED(hpaned),
1678                                GTK_WIDGET_PTR(mainwin->summaryview));
1679                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1680                                      prefs_common.summaryview_width,
1681                                      prefs_common.summaryview_height);
1682                 gtk_widget_set_usize(mainwin->window,
1683                                      prefs_common.folderview_width +
1684                                      prefs_common.mainview_width,
1685                                      prefs_common.mainwin_height);
1686                 gtk_widget_show_all(hpaned);
1687                 gtk_container_add(GTK_CONTAINER(messagewin),
1688                                   GTK_WIDGET_PTR(mainwin->messageview));
1689         
1690                 menu_set_sensitive(ifactory, "/View/Message view", TRUE);
1691                 menu_set_sensitive(ifactory, "/View/Folder tree", FALSE);
1692
1693                 mainwin->win.sep_message.messagewin = messagewin;
1694                 mainwin->win.sep_message.hpaned     = hpaned;
1695
1696                 gtk_widget_show_all(messagewin);
1697                 break;
1698         case SEPARATE_BOTH:
1699                 gtk_box_pack_start(GTK_BOX(vbox_body),
1700                                    GTK_WIDGET_PTR(mainwin->summaryview),
1701                                    TRUE, TRUE, 0);
1702                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1703                                      prefs_common.summaryview_width,
1704                                      prefs_common.summaryview_height);
1705                 gtk_widget_set_usize(mainwin->window,
1706                                      prefs_common.mainview_width,
1707                                      prefs_common.mainwin_height);
1708                 gtk_container_add(GTK_CONTAINER(folderwin),
1709                                   GTK_WIDGET_PTR(mainwin->folderview));
1710                 gtk_container_add(GTK_CONTAINER(messagewin),
1711                                   GTK_WIDGET_PTR(mainwin->messageview));
1712
1713                 menu_set_sensitive(ifactory, "/View/Message view", TRUE);
1714                 menu_set_sensitive(ifactory, "/View/Folder tree", TRUE);
1715         
1716                 mainwin->win.sep_both.folderwin = folderwin;
1717                 mainwin->win.sep_both.messagewin = messagewin;
1718
1719                 gtk_widget_show_all(folderwin);
1720                 gtk_widget_show_all(messagewin);
1721                 break;
1722         }
1723
1724         mainwin->type = type;
1725
1726         debug_print(_("done.\n"));
1727 }
1728
1729 static void main_window_toolbar_create(MainWindow *mainwin,
1730                                        GtkWidget *container)
1731 {
1732         GtkWidget *toolbar;
1733         GtkWidget *icon_wid;
1734         GtkWidget *get_btn;
1735         GtkWidget *getall_btn;
1736         GtkWidget *compose_mail_btn;
1737         GtkWidget *compose_news_btn;
1738         GtkWidget *reply_btn;
1739         GtkWidget *replyall_btn;
1740         GtkWidget *replysender_btn;
1741         GtkWidget *fwd_btn;
1742         GtkWidget *send_btn;
1743         /*
1744         GtkWidget *prefs_btn;
1745         GtkWidget *account_btn;
1746         */
1747         GtkWidget *next_btn;
1748         GtkWidget *delete_btn;
1749         GtkWidget *exec_btn;
1750         
1751         GtkTooltips *tooltips;
1752
1753         toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1754                                   GTK_TOOLBAR_BOTH);
1755         gtk_container_add(GTK_CONTAINER(container), toolbar);
1756         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1757         gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1758         gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1759                                     GTK_TOOLBAR_SPACE_LINE);
1760
1761         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_RECEIVE);
1762         get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1763                                           _("Get"),
1764                                           _("Get new mail from current account"),
1765                                           "Get",
1766                                           icon_wid, toolbar_inc_cb, mainwin);
1767         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_RECEIVE_ALL);
1768         getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1769                                              _("Get all"),
1770                                              _("Get new mail from all accounts"),
1771                                              "Get all",
1772                                              icon_wid,
1773                                              toolbar_inc_all_cb,
1774                                              mainwin);
1775
1776         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1777
1778         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_SEND);
1779         send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1780                                            _("Send"),
1781                                            _("Send queued message(s)"),
1782                                            "Send",
1783                                            icon_wid,
1784                                            toolbar_send_cb,
1785                                            mainwin);
1786
1787         /* insert compose mail button widget */                                    
1788         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_COMPOSE);
1789         compose_mail_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1790                                               _("Email"),
1791                                               _("Compose an email message"),
1792                                               "New",
1793                                               icon_wid,
1794                                               toolbar_compose_mail_cb,
1795                                               mainwin);
1796
1797         /* insert compose news button widget */
1798         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1799         compose_news_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1800                                               _("News"),
1801                                               _("Compose a news message"),
1802                                               "New",
1803                                               icon_wid,
1804                                               toolbar_compose_news_cb,
1805                                               mainwin);
1806
1807         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1808         
1809         /* reply button */
1810         
1811         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_REPLY);
1812         reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1813                                             _("Reply"),
1814                                             _("Reply to the message - Right button: more options"),
1815                                             "Reply",
1816                                             icon_wid,
1817                                             toolbar_reply_cb,
1818                                             mainwin);
1819
1820         /* replyall button */
1821
1822         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_REPLY_TO_ALL);
1823         replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1824                                                _("All"),
1825                                                _("Reply to all - Right button: more options"),
1826                                                "Reply to all",
1827                                                icon_wid,
1828                                                toolbar_reply_to_all_cb,
1829                                                mainwin);
1830
1831         /* reply to sender button */
1832         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR);
1833         replysender_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1834                                                   _("Sender"),
1835                                                   _("Reply to sender - Right button: more options"),
1836                                                   "Reply to sender",
1837                                                   icon_wid,
1838                                                   toolbar_reply_to_sender_cb,
1839                                                   mainwin);
1840
1841         /* forward button */
1842         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_MAIL_FORWARD);
1843         fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1844                                           _("Forward"),
1845                                           _("Forward the message - Right button: more options"),
1846                                           "Fwd",
1847                                           icon_wid,
1848                                           toolbar_forward_cb,
1849                                           mainwin);
1850
1851         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1852
1853         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_CLOSE);
1854         delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1855                                           _("Delete"),
1856                                           _("Delete the message"),
1857                                           "Delete",
1858                                           icon_wid,
1859                                           toolbar_delete_cb,
1860                                           mainwin);
1861
1862         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EXEC);
1863         exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1864                                            _("Execute"),
1865                                            _("Execute marked process"),
1866                                            "Execute",
1867                                            icon_wid,
1868                                            toolbar_exec_cb,
1869                                            mainwin);
1870
1871         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_DOWN_ARROW);
1872         next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1873                                            _("Next"),
1874                                            _("Next unread message"),
1875                                            "Next unread",
1876                                            icon_wid,
1877                                            toolbar_next_unread_cb,
1878                                            mainwin);
1879
1880         /*
1881         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1882
1883         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_PREFERENCES);
1884         prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1885                                             _("Prefs"),
1886                                             _("Common preference"),
1887                                             "Prefs",
1888                                             icon_wid,
1889                                             toolbar_prefs_cb,
1890                                             mainwin);
1891         icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_PROPERTIES);
1892         account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1893                                               _("Account"),
1894                                               _("Account setting"),
1895                                               "Account",
1896                                               icon_wid,
1897                                               toolbar_account_cb,
1898                                               mainwin);
1899         gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1900                            GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1901                            mainwin);
1902         */
1903
1904         gtk_signal_connect(GTK_OBJECT(reply_btn), "button_press_event",
1905                 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
1906                 mainwin);
1907         
1908         gtk_signal_connect(GTK_OBJECT(replyall_btn), "button_press_event",
1909                 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
1910                 mainwin);
1911         
1912         gtk_signal_connect(GTK_OBJECT(replysender_btn), "button_press_event",
1913                 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
1914                 mainwin);
1915         
1916         gtk_signal_connect(GTK_OBJECT(fwd_btn), "button_press_event",
1917                 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
1918                 mainwin);
1919         
1920
1921         mainwin->toolbar                         = toolbar;
1922         mainwin->get_btn                         = get_btn;
1923         mainwin->getall_btn                      = getall_btn;
1924         mainwin->compose_mail_btn                = compose_mail_btn;
1925         mainwin->compose_news_btn                = compose_news_btn;
1926         mainwin->reply_btn                       = reply_btn;
1927         mainwin->replyall_btn                    = replyall_btn;
1928         mainwin->replysender_btn                 = replysender_btn;
1929         mainwin->fwd_btn         = fwd_btn;
1930         mainwin->send_btn        = send_btn;
1931         /*
1932         mainwin->prefs_btn       = prefs_btn;
1933         mainwin->account_btn     = account_btn;
1934         */
1935         mainwin->next_btn        = next_btn;
1936         mainwin->delete_btn      = delete_btn;
1937         mainwin->exec_btn        = exec_btn;
1938
1939         gtk_widget_show_all(toolbar);
1940 }
1941
1942 /* callback functions */
1943 static void toolbar_reply_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1944 {
1945         MainWindow *mainwindow = (MainWindow *) data;
1946         
1947         if (!event) return;
1948
1949         if (event->button == 3) {
1950                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1951                 gtk_menu_popup(GTK_MENU(mainwindow->reply_popup), NULL, NULL,
1952                        menu_button_position, widget,
1953                        event->button, event->time);
1954         }
1955 }
1956
1957 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
1958 {
1959         MainWindow *mainwin = (MainWindow *)data;
1960
1961         gtk_button_set_relief(GTK_BUTTON(mainwin->reply_btn), GTK_RELIEF_NONE);
1962         manage_window_focus_in(mainwin->window, NULL, NULL);
1963 }
1964
1965 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1966 {
1967         MainWindow *mainwindow = (MainWindow *) data;
1968         
1969         if (!event) return;
1970
1971         if (event->button == 3) {
1972                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1973                 gtk_menu_popup(GTK_MENU(mainwindow->replyall_popup), NULL, NULL,
1974                        menu_button_position, widget,
1975                        event->button, event->time);
1976         }
1977 }
1978
1979 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
1980 {
1981         MainWindow *mainwin = (MainWindow *)data;
1982
1983         gtk_button_set_relief(GTK_BUTTON(mainwin->replyall_btn), GTK_RELIEF_NONE);
1984         manage_window_focus_in(mainwin->window, NULL, NULL);
1985 }
1986
1987 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1988 {
1989         MainWindow *mainwindow = (MainWindow *) data;
1990         GtkWidget *replysender_menu, *replysender_item;
1991
1992         if (!event) return;
1993
1994         if (event->button == 3) {
1995                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1996                 gtk_menu_popup(GTK_MENU(mainwindow->replysender_popup), NULL, NULL,
1997                        menu_button_position, widget,
1998                        event->button, event->time);
1999         }
2000 }
2001
2002 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2003 {
2004         MainWindow *mainwin = (MainWindow *)data;
2005
2006         gtk_button_set_relief(GTK_BUTTON(mainwin->replysender_btn), GTK_RELIEF_NONE);
2007         manage_window_focus_in(mainwin->window, NULL, NULL);
2008 }
2009
2010 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2011 {
2012         MainWindow *mainwindow = (MainWindow *) data;
2013         
2014         if (!event) return;
2015
2016         if (event->button == 3) {
2017                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2018                 gtk_menu_popup(GTK_MENU(mainwindow->fwd_popup), NULL, NULL,
2019                        menu_button_position, widget,
2020                        event->button, event->time);
2021         }
2022 }
2023
2024 static void toolbar_forward_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2025 {
2026         MainWindow *mainwin = (MainWindow *)data;
2027
2028         gtk_button_set_relief(GTK_BUTTON(mainwin->fwd_btn), GTK_RELIEF_NONE);
2029         manage_window_focus_in(mainwin->window, NULL, NULL);
2030 }
2031
2032 static void toolbar_inc_cb      (GtkWidget      *widget,
2033                                  gpointer        data)
2034 {
2035         MainWindow *mainwin = (MainWindow *)data;
2036
2037         inc_mail_cb(mainwin, 0, NULL);
2038 }
2039
2040 static void toolbar_inc_all_cb  (GtkWidget      *widget,
2041                                  gpointer        data)
2042 {
2043         MainWindow *mainwin = (MainWindow *)data;
2044
2045         inc_all_account_mail_cb(mainwin, 0, NULL);
2046 }
2047
2048 static void toolbar_send_cb     (GtkWidget      *widget,
2049                                  gpointer        data)
2050 {
2051         MainWindow *mainwin = (MainWindow *)data;
2052
2053         send_queue_cb(mainwin, 0, NULL);
2054 }
2055
2056 static void toolbar_compose_cb  (GtkWidget      *widget,
2057                                  gpointer        data)
2058 {
2059         MainWindow *mainwin = (MainWindow *)data;
2060
2061         if (mainwin->compose_btn_type == COMPOSEBUTTON_MAIL)
2062                 compose_cb(mainwin, 0, NULL);
2063         else
2064                 compose_news_cb(mainwin, 0, NULL);
2065 }
2066
2067 static void toolbar_compose_news_cb     (GtkWidget      *widget,
2068                                  gpointer        data)
2069 {
2070         MainWindow *mainwin = (MainWindow *)data;
2071
2072         compose_news_cb(mainwin, 0, NULL);
2073 }
2074
2075 static void toolbar_compose_mail_cb     (GtkWidget      *widget,
2076                                  gpointer        data)
2077 {
2078         MainWindow *mainwin = (MainWindow *)data;
2079
2080         compose_mail_cb(mainwin, 0, NULL);
2081 }
2082
2083 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
2084 {
2085         MainWindow *mainwin = (MainWindow *)data;
2086
2087         reply_cb(mainwin, 
2088                  prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE 
2089                  : COMPOSE_REPLY_WITHOUT_QUOTE,
2090                  NULL);
2091 }
2092
2093 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
2094 {
2095         MainWindow *mainwin = (MainWindow *)data;
2096
2097         reply_cb(mainwin, 
2098                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
2099                  : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, 
2100                  NULL);
2101 }
2102
2103
2104 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
2105 {
2106         MainWindow *mainwin = (MainWindow *)data;
2107
2108         reply_cb(mainwin, 
2109                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
2110                  : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, 
2111                  NULL);
2112 }
2113
2114 static void toolbar_forward_cb  (GtkWidget      *widget,
2115                                  gpointer        data)
2116 {
2117         MainWindow *mainwin = (MainWindow *)data;
2118
2119         if (prefs_common.forward_as_attachment)
2120                 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
2121         else
2122                 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
2123 }
2124
2125 static void toolbar_delete_cb   (GtkWidget      *widget,
2126                                  gpointer        data)
2127 {
2128         MainWindow *mainwin = (MainWindow *)data;
2129
2130         summary_delete(mainwin->summaryview);
2131 }
2132
2133 static void toolbar_exec_cb     (GtkWidget      *widget,
2134                                  gpointer        data)
2135 {
2136         MainWindow *mainwin = (MainWindow *)data;
2137
2138         summary_execute(mainwin->summaryview);
2139 }
2140
2141 static void toolbar_next_unread_cb      (GtkWidget      *widget,
2142                                          gpointer        data)
2143 {
2144         MainWindow *mainwin = (MainWindow *)data;
2145
2146         next_unread_cb(mainwin, 0, NULL);
2147 }
2148
2149 static void toolbar_prefs_cb    (GtkWidget      *widget,
2150                                  gpointer        data)
2151 {
2152         prefs_common_open();
2153 }
2154
2155 static void toolbar_account_cb  (GtkWidget      *widget,
2156                                  gpointer        data)
2157 {
2158         MainWindow *mainwin = (MainWindow *)data;
2159
2160         prefs_account_open_cb(mainwin, 0, NULL);
2161 }
2162
2163 static void toolbar_account_button_pressed(GtkWidget *widget,
2164                                            GdkEventButton *event,
2165                                            gpointer data)
2166 {
2167         MainWindow *mainwin = (MainWindow *)data;
2168
2169         if (!event) return;
2170         if (event->button != 3) return;
2171
2172         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2173         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2174                             widget);
2175
2176         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2177                        menu_button_position, widget,
2178                        event->button, event->time);
2179 }
2180
2181 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2182                                     gpointer data)
2183 {
2184         MainWindow *mainwin = (MainWindow *)data;
2185
2186         if (!event) return;
2187
2188         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2189         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2190                             widget);
2191
2192         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2193                        menu_button_position, widget,
2194                        event->button, event->time);
2195 }
2196
2197 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
2198 {
2199         MainWindow *mainwin = (MainWindow *)data;
2200         GtkWidget *button;
2201
2202         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
2203         if (!button) return;
2204         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
2205         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
2206         manage_window_focus_in(mainwin->window, NULL, NULL);
2207 }
2208
2209 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2210                                  gpointer data)
2211 {
2212         MainWindow *mainwin = (MainWindow *)data;
2213
2214         if (mainwin->lock_count == 0)
2215                 app_exit_cb(data, 0, widget);
2216
2217         return TRUE;
2218 }
2219
2220 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2221                            GtkWidget *widget)
2222 {
2223         main_window_add_mailbox(mainwin);
2224 }
2225
2226 static void add_mbox_cb(MainWindow *mainwin, guint action,
2227                         GtkWidget *widget)
2228 {
2229         main_window_add_mbox(mainwin);
2230 }
2231
2232 static void update_folderview_cb(MainWindow *mainwin, guint action,
2233                                  GtkWidget *widget)
2234 {
2235         summary_show(mainwin->summaryview, NULL, FALSE);
2236         folderview_update_all();
2237 }
2238
2239 static void new_folder_cb(MainWindow *mainwin, guint action,
2240                           GtkWidget *widget)
2241 {
2242         folderview_new_folder(mainwin->folderview);
2243 }
2244
2245 static void rename_folder_cb(MainWindow *mainwin, guint action,
2246                              GtkWidget *widget)
2247 {
2248         folderview_rename_folder(mainwin->folderview);
2249 }
2250
2251 static void delete_folder_cb(MainWindow *mainwin, guint action,
2252                              GtkWidget *widget)
2253 {
2254         folderview_delete_folder(mainwin->folderview);
2255 }
2256
2257 static void import_mbox_cb(MainWindow *mainwin, guint action,
2258                            GtkWidget *widget)
2259 {
2260         import_mbox(mainwin->summaryview->folder_item);
2261 }
2262
2263 static void export_mbox_cb(MainWindow *mainwin, guint action,
2264                            GtkWidget *widget)
2265 {
2266         export_mbox(mainwin->summaryview->folder_item);
2267 }
2268
2269 static void empty_trash_cb(MainWindow *mainwin, guint action,
2270                            GtkWidget *widget)
2271 {
2272         main_window_empty_trash(mainwin, TRUE);
2273 }
2274
2275 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2276 {
2277         summary_save_as(mainwin->summaryview);
2278 }
2279
2280 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2281 {
2282         summary_print(mainwin->summaryview);
2283 }
2284
2285 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2286 {
2287         if (prefs_common.confirm_on_exit) {
2288                 if (alertpanel(_("Exit"), _("Exit this program?"),
2289                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2290                         return;
2291                 manage_window_focus_in(mainwin->window, NULL, NULL);
2292         }
2293
2294         app_will_exit(widget, mainwin);
2295 }
2296
2297 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2298 {
2299         if (action == 1)
2300                 summary_search(mainwin->summaryview);
2301         else
2302                 message_search(mainwin->messageview);
2303 }
2304
2305 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2306                              GtkWidget *widget)
2307 {
2308         switch (mainwin->type) {
2309         case SEPARATE_NONE:
2310         case SEPARATE_MESSAGE:
2311                 break;
2312         case SEPARATE_FOLDER:
2313                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2314                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2315                 else
2316                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2317                 break;
2318         case SEPARATE_BOTH:
2319                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2320                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2321                 else
2322                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2323                 break;
2324         }
2325 }
2326
2327 static void toggle_message_cb(MainWindow *mainwin, guint action,
2328                               GtkWidget *widget)
2329 {
2330         switch (mainwin->type) {
2331         case SEPARATE_NONE:
2332         case SEPARATE_FOLDER:
2333                 break;
2334         case SEPARATE_MESSAGE:
2335                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2336                         gtk_widget_show(mainwin->win.sep_message.messagewin);
2337                 else
2338                         gtk_widget_hide(mainwin->win.sep_message.messagewin);
2339                 break;
2340         case SEPARATE_BOTH:
2341                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2342                         gtk_widget_show(mainwin->win.sep_both.messagewin);
2343                 else
2344                         gtk_widget_hide(mainwin->win.sep_both.messagewin);
2345                 break;
2346         }
2347 }
2348
2349 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2350                               GtkWidget *widget)
2351 {
2352 /*      activate_compose_button(mainwin, (ToolbarStyle)action, 
2353                         mainwin->compose_btn_type);
2354         set_toolbar_reply_button(mainwin, (ToolbarStyle)action);
2355         set_toolbar_replyall_button(mainwin, (ToolbarStyle)action);
2356         set_toolbar_replysender_button(mainwin, (ToolbarStyle)action);
2357         set_toolbar_forward_button(mainwin, (ToolbarStyle)action);*/
2358         
2359         switch ((ToolbarStyle)action) {
2360         case TOOLBAR_NONE:
2361                 gtk_widget_hide(mainwin->handlebox);
2362         case TOOLBAR_ICON:
2363                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2364                                       GTK_TOOLBAR_ICONS);
2365                 break;
2366         case TOOLBAR_TEXT:
2367                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2368                                       GTK_TOOLBAR_TEXT);
2369                 break;
2370         case TOOLBAR_BOTH:
2371                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2372                                       GTK_TOOLBAR_BOTH);
2373                 break;
2374         }
2375
2376         if (action != TOOLBAR_NONE) {
2377                 gtk_widget_show(mainwin->handlebox);
2378                 gtk_widget_queue_resize(mainwin->handlebox);
2379         }
2380
2381         mainwin->toolbar_style = (ToolbarStyle)action;
2382         prefs_common.toolbar_style = (ToolbarStyle)action;
2383 }
2384
2385 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2386                                 GtkWidget *widget)
2387 {
2388         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2389                 gtk_widget_show(mainwin->hbox_stat);
2390                 prefs_common.show_statusbar = TRUE;
2391         } else {
2392                 gtk_widget_hide(mainwin->hbox_stat);
2393                 prefs_common.show_statusbar = FALSE;
2394         }
2395 }
2396
2397 static void separate_widget_cb(GtkCheckMenuItem *checkitem, guint action, GtkWidget *widget)
2398
2399 {
2400         MainWindow *mainwin;
2401         SeparateType type;
2402
2403         mainwin = (MainWindow *) gtk_object_get_data(GTK_OBJECT(checkitem), "mainwindow");
2404         g_return_if_fail(mainwin != NULL);
2405
2406         type = mainwin->type ^ action;
2407         main_window_separation_change(mainwin, type);
2408
2409         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2410         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2411 }
2412
2413 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2414                                 GtkWidget *widget)
2415 {
2416         addressbook_open(NULL);
2417 }
2418
2419 static void log_window_show_cb(MainWindow *mainwin, guint action,
2420                                GtkWidget *widget)
2421 {
2422         log_window_show(mainwin->logwin);
2423 }
2424
2425 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2426 {
2427         inc_mail(mainwin);
2428 }
2429
2430 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
2431                                     GtkWidget *widget)
2432 {
2433         inc_all_account_mail(mainwin);
2434 }
2435
2436 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2437 {
2438         GList *list;
2439
2440         if (procmsg_send_queue() < 0)
2441                 alertpanel_error(_("Some errors occurred while sending queued messages."));
2442
2443         statusbar_pop_all();
2444
2445         for (list = folder_get_list(); list != NULL; list = list->next) {
2446                 Folder *folder;
2447
2448                 folder = list->data;
2449                 if (folder->queue) {
2450                         folder_item_scan(folder->queue);
2451                         folderview_update_item(folder->queue, TRUE);
2452                 }
2453         }
2454 }
2455
2456 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2457 {
2458         if (mainwin->summaryview->folder_item) {
2459                 if (mainwin->summaryview->folder_item->folder->account != NULL
2460                     && mainwin->summaryview->folder_item->folder->account->protocol == A_NNTP)
2461                         compose_new_with_recipient(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item->path);
2462                 else
2463                         compose_new_with_folderitem(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item);
2464         }
2465         else
2466                 compose_new(NULL);
2467 }
2468
2469 static void compose_mail_cb(MainWindow *mainwin, guint action,
2470                             GtkWidget *widget)
2471 {
2472         PrefsAccount * ac;
2473         GList * list;
2474         GList * cur;
2475
2476         if (mainwin->summaryview->folder_item) {
2477                 ac = mainwin->summaryview->folder_item->folder->account;
2478                 if (ac && ac->protocol != A_NNTP) {
2479                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2480                         return;
2481                 }
2482         }
2483
2484         if(cur_account && (cur_account->protocol != A_NNTP)) {
2485                 compose_new_with_folderitem(cur_account, mainwin->summaryview->folder_item);
2486                 return;
2487         }
2488
2489         list = account_get_list();
2490         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2491                 ac = (PrefsAccount *) cur->data;
2492                 if (ac->protocol != A_NNTP) {
2493                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2494                         return;
2495                 }
2496         }
2497 }
2498
2499 static void compose_news_cb(MainWindow *mainwin, guint action,
2500                             GtkWidget *widget)
2501 {
2502         PrefsAccount * ac = NULL;
2503         GList * list;
2504         GList * cur;
2505
2506         if (mainwin->summaryview->folder_item) {
2507                 ac = mainwin->summaryview->folder_item->folder->account;
2508                 if (ac && ac->protocol == A_NNTP) {
2509                         compose_new_with_recipient
2510                                 (ac, mainwin->summaryview->folder_item->path);
2511                         return;
2512                 }
2513         }
2514
2515         list = account_get_list();
2516         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2517                 ac = (PrefsAccount *) cur->data;
2518                 if (ac->protocol == A_NNTP) {
2519                         compose_new(ac);
2520                         return;
2521                 }
2522         }
2523 }
2524
2525 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2526 {
2527         GList  *sel = GTK_CLIST(mainwin->summaryview->ctree)->selection;
2528         MsgInfo *msginfo;
2529
2530         msginfo = gtk_ctree_node_get_row_data
2531                 (GTK_CTREE(mainwin->summaryview->ctree),
2532                  mainwin->summaryview->selected);
2533
2534         if (!msginfo) return;
2535
2536         switch (action) {
2537         case COMPOSE_REPLY:
2538                 compose_reply(msginfo, prefs_common.reply_with_quote,
2539                               FALSE, FALSE);
2540                 break;
2541         case COMPOSE_REPLY_WITH_QUOTE:
2542                 compose_reply(msginfo, TRUE, FALSE, FALSE);
2543                 break;
2544         case COMPOSE_REPLY_WITHOUT_QUOTE:
2545                 compose_reply(msginfo, FALSE, FALSE, FALSE);
2546                 break;
2547         case COMPOSE_REPLY_TO_SENDER:
2548                 compose_reply(msginfo, prefs_common.reply_with_quote,
2549                               FALSE, TRUE);
2550                 break;
2551         case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
2552                 compose_reply(msginfo, TRUE, FALSE, TRUE);
2553                 break;
2554         case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
2555                 compose_reply(msginfo, FALSE, FALSE, TRUE);
2556                 break;
2557         case COMPOSE_FOLLOWUP_AND_REPLY_TO:
2558                 compose_followup_and_reply_to(msginfo,
2559                                               prefs_common.reply_with_quote,
2560                                               FALSE, TRUE);
2561                 break;
2562         case COMPOSE_REPLY_TO_ALL:
2563                 compose_reply(msginfo, prefs_common.reply_with_quote,
2564                               TRUE, TRUE);
2565                 break;
2566         case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
2567                 compose_reply(msginfo, TRUE, TRUE, TRUE);
2568                 break;
2569         case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
2570                 compose_reply(msginfo, FALSE, TRUE, TRUE);
2571                 break;
2572         case COMPOSE_FORWARD:
2573                 if (prefs_common.forward_as_attachment) {
2574                         reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, widget);
2575                         return;
2576                 } else {
2577                         reply_cb(mainwin, COMPOSE_FORWARD_INLINE, widget);
2578                         return;
2579                 }
2580                 break;
2581         case COMPOSE_FORWARD_INLINE:
2582                 if (!sel->next) {
2583                         compose_forward(NULL, msginfo, FALSE);
2584                         break;
2585                 }
2586                 /* if (sel->next) FALL_THROUGH */
2587         case COMPOSE_FORWARD_AS_ATTACH:
2588                 {
2589                         GSList *msginfo_list = NULL;
2590                         for ( ; sel != NULL; sel = sel->next)
2591                                 msginfo_list = g_slist_append(msginfo_list, 
2592                                         gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->summaryview->ctree),
2593                                                 GTK_CTREE_NODE(sel->data)));
2594                         compose_forward_multiple(NULL, msginfo_list);
2595                         g_slist_free(msginfo_list);
2596                 }                       
2597                 break;
2598         case COMPOSE_BOUNCE:
2599                         compose_bounce(NULL, msginfo);
2600                         break;
2601         default:
2602                 g_warning("reply_cb(): invalid action type: %d\n", action);
2603         }
2604
2605         summary_set_marks_selected(mainwin->summaryview);
2606 }
2607
2608 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2609 {
2610         summary_move_to(mainwin->summaryview);
2611 }
2612
2613 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2614 {
2615         summary_copy_to(mainwin->summaryview);
2616 }
2617
2618 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2619 {
2620         summary_delete(mainwin->summaryview);
2621 }
2622
2623 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2624 {
2625         summary_open_msg(mainwin->summaryview);
2626 }
2627
2628 static void view_source_cb(MainWindow *mainwin, guint action,
2629                            GtkWidget *widget)
2630 {
2631         summary_view_source(mainwin->summaryview);
2632 }
2633
2634 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2635 {
2636         summary_reedit(mainwin->summaryview);
2637 }
2638
2639 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2640 {
2641         summary_mark(mainwin->summaryview);
2642 }
2643
2644 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2645 {
2646         summary_unmark(mainwin->summaryview);
2647 }
2648
2649 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2650                               GtkWidget *widget)
2651 {
2652         summary_mark_as_unread(mainwin->summaryview);
2653 }
2654
2655 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2656                             GtkWidget *widget)
2657 {
2658         summary_mark_as_read(mainwin->summaryview);
2659 }
2660
2661 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2662                              GtkWidget *widget)
2663 {
2664         summary_mark_all_read(mainwin->summaryview);
2665 }
2666
2667 static void add_address_cb(MainWindow *mainwin, guint action,
2668                            GtkWidget *widget)
2669 {
2670         summary_add_address(mainwin->summaryview);
2671 }
2672
2673 static void set_charset_cb(MainWindow *mainwin, guint action,
2674                            GtkWidget *widget)
2675 {
2676         const gchar *str;
2677
2678         str = conv_get_charset_str((CharSet)action);
2679         g_free(prefs_common.force_charset);
2680         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2681
2682         summary_redisplay_msg(mainwin->summaryview);
2683
2684         debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
2685 }
2686
2687 static void hide_read_messages (MainWindow *mainwin, guint action,
2688                                 GtkWidget *widget)
2689 {
2690         if (!mainwin->summaryview->folder_item
2691             || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
2692                 return;
2693         summary_toggle_show_read_messages(mainwin->summaryview);
2694 }
2695
2696 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2697 {
2698         GtkItemFactory *ifactory;
2699
2700         if (!mainwin->summaryview->folder_item) return;
2701
2702         ifactory = gtk_item_factory_from_widget(widget);
2703
2704         if (0 == action) {
2705                 summary_thread_build(mainwin->summaryview);
2706                 mainwin->summaryview->folder_item->threaded = TRUE;
2707                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
2708                 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
2709         } else {
2710                 summary_unthread(mainwin->summaryview);
2711                 mainwin->summaryview->folder_item->threaded = FALSE;
2712                 menu_set_sensitive(ifactory, "/Summary/Thread view",   TRUE);
2713                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
2714         }
2715 }
2716
2717 static void set_display_item_cb(MainWindow *mainwin, guint action,
2718                                 GtkWidget *widget)
2719 {
2720         prefs_summary_column_open();
2721 }
2722
2723 static void sort_summary_cb(MainWindow *mainwin, guint action,
2724                             GtkWidget *widget)
2725 {
2726         summary_sort(mainwin->summaryview, (SummarySortType)action);
2727 }
2728
2729 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2730                                   GtkWidget *widget)
2731 {
2732         summary_attract_by_subject(mainwin->summaryview);
2733 }
2734
2735 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2736                                  GtkWidget *widget)
2737 {
2738         summary_delete_duplicated(mainwin->summaryview);
2739 }
2740
2741 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2742 {
2743         summary_filter(mainwin->summaryview);
2744 }
2745
2746 static void execute_summary_cb(MainWindow *mainwin, guint action,
2747                                GtkWidget *widget)
2748 {
2749         summary_execute(mainwin->summaryview);
2750 }
2751
2752 static void update_summary_cb(MainWindow *mainwin, guint action,
2753                               GtkWidget *widget)
2754 {
2755         FolderItem *fitem;
2756         FolderView *folderview = mainwin->folderview;
2757
2758         if (!mainwin->summaryview->folder_item) return;
2759         if (!folderview->opened) return;
2760
2761         folder_update_op_count();
2762
2763         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2764                                             folderview->opened);
2765         if (!fitem) return;
2766
2767         summary_show(mainwin->summaryview, fitem, TRUE);
2768 }
2769
2770 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2771 {
2772         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2773 }
2774
2775 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2776 {
2777         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2778 }
2779
2780 static void prev_unread_cb(MainWindow *mainwin, guint action,
2781                            GtkWidget *widget)
2782 {
2783         summary_select_prev_unread(mainwin->summaryview);
2784 }
2785
2786 static void next_unread_cb(MainWindow *mainwin, guint action,
2787                            GtkWidget *widget)
2788 {
2789         summary_select_next_unread(mainwin->summaryview);
2790 }
2791
2792 static void prev_marked_cb(MainWindow *mainwin, guint action,
2793                            GtkWidget *widget)
2794 {
2795         summary_select_prev_marked(mainwin->summaryview);
2796 }
2797
2798 static void next_marked_cb(MainWindow *mainwin, guint action,
2799                            GtkWidget *widget)
2800 {
2801         summary_select_next_marked(mainwin->summaryview);
2802 }
2803
2804 static void prev_labeled_cb(MainWindow *mainwin, guint action,
2805                             GtkWidget *widget)
2806 {
2807         summary_select_prev_labeled(mainwin->summaryview);
2808 }
2809
2810 static void next_labeled_cb(MainWindow *mainwin, guint action,
2811                             GtkWidget *widget)
2812 {
2813         summary_select_next_labeled(mainwin->summaryview);
2814 }
2815
2816 static void goto_folder_cb(MainWindow *mainwin, guint action,
2817                            GtkWidget *widget)
2818 {
2819         FolderItem *to_folder;
2820
2821         to_folder = foldersel_folder_sel(NULL, NULL);
2822
2823         if (to_folder)
2824                 folderview_select(mainwin->folderview, to_folder);
2825 }
2826
2827 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2828 {
2829         messageview_copy_clipboard(mainwin->messageview);
2830 }
2831
2832 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2833 {
2834         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2835                 summary_select_all(mainwin->summaryview);
2836         else if (mainwin->summaryview->msg_is_toggled_on &&
2837                  GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2838                 messageview_select_all(mainwin->messageview);
2839 }
2840
2841 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2842                                  GtkWidget *widget)
2843 {
2844         prefs_common_open();
2845 }
2846
2847 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2848                                  GtkWidget *widget)
2849 {
2850         prefs_filter_open();
2851 }
2852
2853 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2854                                   GtkWidget *widget)
2855 {
2856         prefs_scoring_open(NULL);
2857 }
2858
2859 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2860                                     GtkWidget *widget)
2861 {
2862         prefs_filtering_open(NULL);
2863 }
2864
2865 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
2866                                    GtkWidget *widget)
2867 {
2868         prefs_template_open();
2869 }
2870
2871 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2872                                   GtkWidget *widget)
2873 {
2874         if (!cur_account) {
2875                 new_account_cb(mainwin, 0, widget);
2876         } else {
2877                 gboolean prev_default = cur_account->is_default;
2878
2879                 prefs_account_open(cur_account);
2880                 if (!prev_default && cur_account->is_default)
2881                         account_set_as_default(cur_account);
2882                 account_save_config_all();
2883                 account_set_menu();
2884                 main_window_reflect_prefs_all();
2885         }
2886 }
2887
2888 static void new_account_cb(MainWindow *mainwin, guint action,
2889                            GtkWidget *widget)
2890 {
2891         account_edit_open();
2892         if (!compose_get_compose_list()) account_add();
2893 }
2894
2895 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2896 {
2897         cur_account = (PrefsAccount *)data;
2898         main_window_reflect_prefs_all();
2899 }
2900
2901 static void manual_open_cb(MainWindow *mainwin, guint action,
2902                            GtkWidget *widget)
2903 {
2904         manual_open((ManualLang)action);
2905 }
2906
2907 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2908 {
2909         MainWindow *mainwin = (MainWindow *)data;
2910         gchar *str;
2911
2912         if (item->path)
2913                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2914                                       LOCAL_FOLDER(folder)->rootpath,
2915                                       G_DIR_SEPARATOR,
2916                                       item->path);
2917         else
2918                 str = g_strdup_printf(_("Scanning folder %s ..."),
2919                                       LOCAL_FOLDER(folder)->rootpath);
2920
2921         STATUSBAR_PUSH(mainwin, str);
2922         STATUSBAR_POP(mainwin);
2923         g_free(str);
2924 }
2925
2926 static void activate_compose_button (MainWindow *mainwin,
2927                                 ToolbarStyle style,
2928                                 ComposeButtonType type)
2929 {
2930         SensitiveCond state = main_window_get_current_state(mainwin);
2931
2932         if (style == TOOLBAR_NONE) 
2933                 return;
2934
2935         gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? mainwin->compose_mail_btn 
2936                 : mainwin->compose_news_btn);
2937         gtk_widget_show(type == COMPOSEBUTTON_NEWS ? mainwin->compose_news_btn
2938                 : mainwin->compose_mail_btn);
2939         mainwin->compose_btn_type = type;       
2940 }
2941
2942 void main_window_toolbar_set_compose_button(MainWindow *mainwin, ComposeButtonType compose_btn_type)
2943 {
2944         if (mainwin->compose_btn_type != compose_btn_type)
2945                 activate_compose_button(mainwin, 
2946                                         prefs_common.toolbar_style,
2947                                         compose_btn_type);
2948 }