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