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