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