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