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