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