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