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