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