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