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