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