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