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