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