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