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