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