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