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