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