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