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