sync with 0.8.1cvs24
[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 messages 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..."),
659                                                 NULL, prefs_toolbar_cb, 0, NULL},
660         {N_("/_Configuration/_Filter setting..."),
661                                                 NULL, prefs_filter_open_cb, 0, NULL},
662         {N_("/_Configuration/_Scoring..."),
663                                                 NULL, prefs_scoring_open_cb, 0, NULL},
664         {N_("/_Configuration/_Filtering..."),
665                                                 NULL, prefs_filtering_open_cb, 0, NULL},
666         {N_("/_Configuration/_Template..."),    NULL, prefs_template_open_cb, 0, NULL},
667         {N_("/_Configuration/_Actions..."),     NULL, prefs_actions_open_cb, 0, NULL},
668         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
669         {N_("/_Configuration/_Preferences for current account..."),
670                                                 NULL, prefs_account_open_cb, 0, NULL},
671         {N_("/_Configuration/Create _new account..."),
672                                                 NULL, new_account_cb, 0, NULL},
673         {N_("/_Configuration/_Edit accounts..."),
674                                                 NULL, account_edit_open, 0, NULL},
675         {N_("/_Configuration/C_hange current account"),
676                                                 NULL, NULL, 0, "<Branch>"},
677
678         {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
679         {N_("/_Help/_Manual"),                  NULL, NULL, 0, "<Branch>"},
680         {N_("/_Help/_Manual/_English"),         NULL, manual_open_cb, MANUAL_LANG_EN, NULL},
681         {N_("/_Help/_Manual/_German"),          NULL, manual_open_cb, MANUAL_LANG_DE, NULL},
682         {N_("/_Help/_Manual/_Spanish"),         NULL, manual_open_cb, MANUAL_LANG_ES, NULL},
683         {N_("/_Help/_Manual/_French"),          NULL, manual_open_cb, MANUAL_LANG_FR, NULL},
684         {N_("/_Help/_Manual/_Japanese"),        NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
685         {N_("/_Help/_FAQ"),                     NULL, NULL, 0, "<Branch>"},
686         {N_("/_Help/_FAQ/_English"),            NULL, faq_open_cb, MANUAL_LANG_EN, NULL},
687         {N_("/_Help/_FAQ/_German"),             NULL, faq_open_cb, MANUAL_LANG_DE, NULL},
688         {N_("/_Help/_FAQ/_Spanish"),            NULL, faq_open_cb, MANUAL_LANG_ES, NULL},
689         {N_("/_Help/_FAQ/_French"),             NULL, faq_open_cb, MANUAL_LANG_FR, NULL},
690         {N_("/_Help/_FAQ/_Italian"),            NULL, faq_open_cb, MANUAL_LANG_IT, NULL},
691         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
692         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
693 };
694
695 MainWindow *main_window_create(SeparateType type)
696 {
697         MainWindow *mainwin;
698         GtkWidget *window;
699         GtkWidget *vbox;
700         GtkWidget *menubar;
701         GtkWidget *handlebox;
702         GtkWidget *vbox_body;
703         GtkWidget *hbox_stat;
704         GtkWidget *statusbar;
705         GtkWidget *progressbar;
706         GtkWidget *statuslabel;
707         GtkWidget *ac_button;
708         GtkWidget *ac_label;
709         GtkWidget *online_status;
710         GtkWidget *offline_status;
711         GtkWidget *online_switch;
712         GtkWidget *offline_switch;
713
714         FolderView *folderview;
715         SummaryView *summaryview;
716         MessageView *messageview;
717         GdkColormap *colormap;
718         GdkColor color[4];
719         gboolean success[4];
720         GtkItemFactory *ifactory;
721         GtkWidget *ac_menu;
722         GtkWidget *menuitem;
723         gint i;
724         guint n_menu_entries;
725
726         static GdkGeometry geometry;
727
728         debug_print("Creating main window...\n");
729         mainwin = g_new0(MainWindow, 1);
730
731         /* main window */
732         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
733         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
734         gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
735         gtk_window_set_wmclass(GTK_WINDOW(window), "main_window", "Sylpheed");
736
737         if (!geometry.min_height) {
738                 geometry.min_width = 320;
739                 geometry.min_height = 200;
740         }
741         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
742                                       GDK_HINT_MIN_SIZE);
743
744         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
745                            GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
746         MANAGE_WINDOW_SIGNALS_CONNECT(window);
747         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
748                                 GTK_SIGNAL_FUNC(key_pressed), mainwin);
749
750         gtk_widget_realize(window);
751         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
752         
753
754         gtkut_widget_set_app_icon(window);
755
756         vbox = gtk_vbox_new(FALSE, 0);
757         gtk_widget_show(vbox);
758         gtk_container_add(GTK_CONTAINER(window), vbox);
759
760         /* menu bar */
761         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
762         menubar = menubar_create(window, mainwin_entries, 
763                                  n_menu_entries, "<Main>", mainwin);
764         gtk_widget_show(menubar);
765         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
766         ifactory = gtk_item_factory_from_widget(menubar);
767
768         handlebox = gtk_handle_box_new();
769         gtk_widget_show(handlebox);
770         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
771
772         /* create the popup menus for the reply buttons specials */
773         toolbar_popups_create(mainwin, window);
774         toolbar_create(mainwin, handlebox);
775
776         /* vbox that contains body */
777         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
778         gtk_widget_show(vbox_body);
779         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
780         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
781
782         hbox_stat = gtk_hbox_new(FALSE, 2);
783         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
784
785         statusbar = statusbar_create();
786         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
787
788         progressbar = gtk_progress_bar_new();
789         gtk_widget_set_usize(progressbar, 120, 1);
790         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
791
792         online_status = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_WORK_ONLINE);
793         offline_status = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_WORK_OFFLINE);
794         online_switch = gtk_button_new ();
795         offline_switch = gtk_button_new ();
796         gtk_container_add (GTK_CONTAINER(online_switch), online_status);
797         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
798         gtk_signal_connect (GTK_OBJECT(online_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
799         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
800         gtk_container_add (GTK_CONTAINER(offline_switch), offline_status);
801         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
802         gtk_signal_connect (GTK_OBJECT(offline_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
803         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
804         
805         statuslabel = gtk_label_new("");
806         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
807
808         ac_button = gtk_button_new();
809         gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
810         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
811         gtk_widget_set_usize(ac_button, -1, 1);
812         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
813         gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
814                            GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
815
816         ac_label = gtk_label_new("");
817         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
818
819         gtk_widget_show_all(hbox_stat);
820
821         gtk_widget_hide(offline_switch);
822         /* create views */
823         mainwin->folderview  = folderview  = folderview_create();
824         mainwin->summaryview = summaryview = summary_create();
825         mainwin->messageview = messageview = messageview_create();
826         mainwin->logwin      = log_window_create();
827
828         folderview->mainwin      = mainwin;
829         folderview->summaryview  = summaryview;
830
831         summaryview->mainwin     = mainwin;
832         summaryview->folderview  = folderview;
833         summaryview->messageview = messageview;
834         summaryview->window      = window;
835
836         messageview->mainwin     = mainwin;
837
838         mainwin->window       = window;
839         mainwin->vbox         = vbox;
840         mainwin->menubar      = menubar;
841         mainwin->menu_factory = ifactory;
842         mainwin->handlebox    = handlebox;
843         mainwin->vbox_body    = vbox_body;
844         mainwin->hbox_stat    = hbox_stat;
845         mainwin->statusbar    = statusbar;
846         mainwin->progressbar  = progressbar;
847         mainwin->statuslabel  = statuslabel;
848         mainwin->ac_button    = ac_button;
849         mainwin->ac_label     = ac_label;
850         
851         mainwin->online_switch     = online_switch;
852         mainwin->offline_switch    = offline_switch;
853         
854         /* set context IDs for status bar */
855         mainwin->mainwin_cid = gtk_statusbar_get_context_id
856                 (GTK_STATUSBAR(statusbar), "Main Window");
857         mainwin->folderview_cid = gtk_statusbar_get_context_id
858                 (GTK_STATUSBAR(statusbar), "Folder View");
859         mainwin->summaryview_cid = gtk_statusbar_get_context_id
860                 (GTK_STATUSBAR(statusbar), "Summary View");
861
862         /* allocate colors for summary view and folder view */
863         summaryview->color_marked.red = summaryview->color_marked.green = 0;
864         summaryview->color_marked.blue = (guint16)65535;
865
866         summaryview->color_dim.red = summaryview->color_dim.green =
867                 summaryview->color_dim.blue = COLOR_DIM;
868
869         folderview->color_new.red = (guint16)55000;
870         folderview->color_new.green = folderview->color_new.blue = 15000;
871
872         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
873                                        &folderview->color_op);
874
875         summaryview->color_important.red = 0;
876         summaryview->color_important.green = 0;
877         summaryview->color_important.blue = (guint16)65535;
878
879         color[0] = summaryview->color_marked;
880         color[1] = summaryview->color_dim;
881         color[2] = folderview->color_new;
882         color[3] = folderview->color_op;
883
884         colormap = gdk_window_get_colormap(window->window);
885         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
886         for (i = 0; i < 4; i++) {
887                 if (success[i] == FALSE)
888                         g_warning(_("MainWindow: color allocation %d failed\n"), i);
889         }
890
891         debug_print("done.\n");
892
893         messageview->visible = TRUE;
894
895         main_window_set_widgets(mainwin, type);
896
897         /* set menu items */
898         menuitem = gtk_item_factory_get_item
899                 (ifactory, "/View/Code set/Auto detect");
900         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
901
902         switch (prefs_common.toolbar_style) {
903         case TOOLBAR_NONE:
904                 menuitem = gtk_item_factory_get_item
905                         (ifactory, "/View/Show or hide/Toolbar/None");
906                 break;
907         case TOOLBAR_ICON:
908                 menuitem = gtk_item_factory_get_item
909                         (ifactory, "/View/Show or hide/Toolbar/Icon");
910                 break;
911         case TOOLBAR_TEXT:
912                 menuitem = gtk_item_factory_get_item
913                         (ifactory, "/View/Show or hide/Toolbar/Text");
914                 break;
915         case TOOLBAR_BOTH:
916                 menuitem = gtk_item_factory_get_item
917                         (ifactory, "/View/Show or hide/Toolbar/Icon and text");
918         }
919         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
920
921         gtk_widget_hide(mainwin->hbox_stat);
922         menuitem = gtk_item_factory_get_item
923                 (ifactory, "/View/Show or hide/Status bar");
924         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
925                                        prefs_common.show_statusbar);
926
927         /* set account selection menu */
928         ac_menu = gtk_item_factory_get_widget
929                 (ifactory, "/Configuration/Change current account");
930         gtk_signal_connect(GTK_OBJECT(ac_menu), "selection_done",
931                            GTK_SIGNAL_FUNC(ac_menu_popup_closed), mainwin);
932         mainwin->ac_menu = ac_menu;
933
934         toolbar_set_sensitive(mainwin);
935
936         /* create actions menu */
937         update_mainwin_actions_menu(ifactory, mainwin);
938
939         /* show main window */
940         gtk_widget_set_uposition(mainwin->window,
941                                  prefs_common.mainwin_x,
942                                  prefs_common.mainwin_y);
943         gtk_widget_set_usize(window, prefs_common.mainwin_width,
944                              prefs_common.mainwin_height);
945         gtk_widget_show(mainwin->window);
946
947         /* initialize views */
948         folderview_init(folderview);
949         summary_init(summaryview);
950         messageview_init(messageview);
951         log_window_init(mainwin->logwin);
952
953         mainwin->lock_count = 0;
954         mainwin->menu_lock_count = 0;
955         mainwin->cursor_count = 0;
956
957         if (!watch_cursor)
958                 watch_cursor = gdk_cursor_new(GDK_WATCH);
959
960         mainwin_list = g_list_append(mainwin_list, mainwin);
961
962         /* init work_offline */
963         if (prefs_common.work_offline)
964                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
965
966         return mainwin;
967 }
968
969 void main_window_cursor_wait(MainWindow *mainwin)
970 {
971
972         if (mainwin->cursor_count == 0)
973                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
974
975         mainwin->cursor_count++;
976
977         gdk_flush();
978 }
979
980 void main_window_cursor_normal(MainWindow *mainwin)
981 {
982         if (mainwin->cursor_count)
983                 mainwin->cursor_count--;
984
985         if (mainwin->cursor_count == 0)
986                 gdk_window_set_cursor(mainwin->window->window, NULL);
987
988         gdk_flush();
989 }
990
991 /* lock / unlock the user-interface */
992 void main_window_lock(MainWindow *mainwin)
993 {
994         if (mainwin->lock_count == 0)
995                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
996
997         mainwin->lock_count++;
998
999         main_window_set_menu_sensitive(mainwin);
1000         toolbar_set_sensitive(mainwin);
1001 }
1002
1003 void main_window_unlock(MainWindow *mainwin)
1004 {
1005         if (mainwin->lock_count)
1006                 mainwin->lock_count--;
1007
1008         main_window_set_menu_sensitive(mainwin);
1009         toolbar_set_sensitive(mainwin);
1010
1011         if (mainwin->lock_count == 0)
1012                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1013 }
1014
1015 static void main_window_menu_callback_block(MainWindow *mainwin)
1016 {
1017         mainwin->menu_lock_count++;
1018 }
1019
1020 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1021 {
1022         if (mainwin->menu_lock_count)
1023                 mainwin->menu_lock_count--;
1024 }
1025
1026 void main_window_reflect_prefs_all(void)
1027 {
1028         main_window_reflect_prefs_all_real(FALSE);
1029 }
1030
1031 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1032 {
1033         GList *cur;
1034         MainWindow *mainwin;
1035
1036         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1037                 mainwin = (MainWindow *)cur->data;
1038
1039                 main_window_show_cur_account(mainwin);
1040                 main_window_set_menu_sensitive(mainwin);
1041                 toolbar_set_sensitive(mainwin);
1042
1043                 /* pixmap themes */
1044                 if (pixmap_theme_changed) {
1045                         toolbar_update();
1046                         set_toolbar_style(mainwin);
1047                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1048                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1049                 }
1050                 
1051                 if (prefs_common.immediate_exec)
1052                         gtk_widget_hide(mainwin->toolbar->exec_btn);
1053                 else
1054                         gtk_widget_show(mainwin->toolbar->exec_btn);
1055
1056                 summary_redisplay_msg(mainwin->summaryview);
1057                 headerview_set_visibility(mainwin->messageview->headerview,
1058                                           prefs_common.display_header_pane);
1059         }
1060 }
1061
1062 void main_window_set_summary_column(void)
1063 {
1064         GList *cur;
1065         MainWindow *mainwin;
1066
1067         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1068                 mainwin = (MainWindow *)cur->data;
1069                 summary_set_column_order(mainwin->summaryview);
1070         }
1071 }
1072
1073 void main_window_set_account_menu(GList *account_list)
1074 {
1075         GList *cur, *cur_ac, *cur_item;
1076         GtkWidget *menuitem;
1077         MainWindow *mainwin;
1078         PrefsAccount *ac_prefs;
1079
1080         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1081                 mainwin = (MainWindow *)cur->data;
1082
1083                 /* destroy all previous menu item */
1084                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1085                 while (cur_item != NULL) {
1086                         GList *next = cur_item->next;
1087                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1088                         cur_item = next;
1089                 }
1090
1091                 for (cur_ac = account_list; cur_ac != NULL;
1092                      cur_ac = cur_ac->next) {
1093                         ac_prefs = (PrefsAccount *)cur_ac->data;
1094
1095                         menuitem = gtk_menu_item_new_with_label
1096                                 (ac_prefs->account_name
1097                                  ? ac_prefs->account_name : _("Untitled"));
1098                         gtk_widget_show(menuitem);
1099                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1100                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
1101                                            GTK_SIGNAL_FUNC(account_menu_cb),
1102                                            ac_prefs);
1103                 }
1104         }
1105 }
1106
1107 static void main_window_show_cur_account(MainWindow *mainwin)
1108 {
1109         gchar *buf;
1110         gchar *ac_name;
1111
1112         ac_name = g_strdup(cur_account
1113                            ? (cur_account->account_name
1114                               ? cur_account->account_name : _("Untitled"))
1115                            : _("none"));
1116
1117         if (cur_account)
1118                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1119         else
1120                 buf = g_strdup(PROG_VERSION);
1121         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1122         g_free(buf);
1123
1124         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1125         gtk_widget_queue_resize(mainwin->ac_button);
1126
1127         g_free(ac_name);
1128 }
1129
1130 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1131 {
1132         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1133         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1134         GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
1135
1136         debug_print("Changing window separation type from %d to %d\n",
1137                     mainwin->type, type);
1138
1139         if (mainwin->type == type) return;
1140
1141         /* remove widgets from those containers */
1142         gtk_widget_ref(folder_wid);
1143         gtk_widget_ref(summary_wid);
1144         gtk_widget_ref(message_wid);
1145         gtkut_container_remove
1146                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1147         gtkut_container_remove
1148                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1149         gtkut_container_remove
1150                 (GTK_CONTAINER(message_wid->parent), message_wid);
1151
1152         /* clean containers */
1153         switch (mainwin->type) {
1154         case SEPARATE_NONE:
1155                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1156                 break;
1157         case SEPARATE_FOLDER:
1158                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1159                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1160                 break;
1161         case SEPARATE_MESSAGE:
1162                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1163                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1164                 break;
1165         case SEPARATE_BOTH:
1166                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1167                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1168                 break;
1169         }
1170
1171         gtk_widget_hide(mainwin->window);
1172         main_window_set_widgets(mainwin, type);
1173         gtk_widget_show(mainwin->window);
1174
1175         gtk_widget_unref(folder_wid);
1176         gtk_widget_unref(summary_wid);
1177         gtk_widget_unref(message_wid);
1178 }
1179
1180 void main_window_toggle_message_view(MainWindow *mainwin)
1181 {
1182         SummaryView *summaryview = mainwin->summaryview;
1183         union CompositeWin *cwin = &mainwin->win;
1184         GtkWidget *vpaned = NULL;
1185         GtkWidget *container = NULL;
1186         GtkWidget *msgwin = NULL;
1187
1188         switch (mainwin->type) {
1189         case SEPARATE_NONE:
1190                 vpaned = cwin->sep_none.vpaned;
1191                 container = cwin->sep_none.hpaned;
1192                 break;
1193         case SEPARATE_FOLDER:
1194                 vpaned = cwin->sep_folder.vpaned;
1195                 container = mainwin->vbox_body;
1196                 break;
1197         case SEPARATE_MESSAGE:
1198                 msgwin = mainwin->win.sep_message.messagewin;
1199                 break;
1200         case SEPARATE_BOTH:
1201                 msgwin = mainwin->win.sep_both.messagewin;
1202                 break;
1203         }
1204
1205         if (msgwin) {
1206                 if (GTK_WIDGET_VISIBLE(msgwin)) {
1207                         gtk_widget_hide(msgwin);
1208                         mainwin->messageview->visible = FALSE;
1209                         summaryview->displayed = NULL;
1210                 } else {
1211                         gtk_widget_show(msgwin);
1212                         mainwin->messageview->visible = TRUE;
1213                 }
1214         } else if (vpaned->parent != NULL) {
1215                 mainwin->messageview->visible = FALSE;
1216                 summaryview->displayed = NULL;
1217                 gtk_widget_ref(vpaned);
1218                 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1219                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1220                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1221                               GTK_ARROW_UP, GTK_SHADOW_OUT);
1222         } else {
1223                 mainwin->messageview->visible = TRUE;
1224                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
1225                 gtk_container_add(GTK_CONTAINER(container), vpaned);
1226                 gtk_widget_unref(vpaned);
1227                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1228                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1229         }
1230
1231         main_window_set_menu_sensitive(mainwin);
1232
1233         gtk_widget_grab_focus(summaryview->ctree);
1234 }
1235
1236 void main_window_get_size(MainWindow *mainwin)
1237 {
1238         GtkAllocation *allocation;
1239
1240         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1241
1242         prefs_common.summaryview_width  = allocation->width;
1243
1244         if ((mainwin->type == SEPARATE_NONE ||
1245              mainwin->type == SEPARATE_FOLDER) &&
1246             messageview_is_visible(mainwin->messageview))
1247                 prefs_common.summaryview_height = allocation->height;
1248
1249         prefs_common.mainview_width     = allocation->width;
1250
1251         allocation = &mainwin->window->allocation;
1252
1253         prefs_common.mainview_height = allocation->height;
1254         prefs_common.mainwin_width   = allocation->width;
1255         prefs_common.mainwin_height  = allocation->height;
1256
1257         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1258
1259         prefs_common.folderview_width  = allocation->width;
1260         prefs_common.folderview_height = allocation->height;
1261 }
1262
1263 void main_window_get_position(MainWindow *mainwin)
1264 {
1265         gint x, y;
1266
1267         gtkut_widget_get_uposition(mainwin->window, &x, &y);
1268
1269         prefs_common.mainview_x = x;
1270         prefs_common.mainview_y = y;
1271         prefs_common.mainwin_x = x;
1272         prefs_common.mainwin_y = y;
1273
1274         debug_print("window position: x = %d, y = %d\n", x, y);
1275 }
1276
1277 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1278 {
1279         GList *list;
1280         guint has_trash;
1281         Folder *folder;
1282
1283         for (has_trash = 0, list = folder_get_list(); list != NULL; list = list->next) {
1284                 folder = FOLDER(list->data);
1285                 if (folder && folder->trash && folder->trash->total > 0)
1286                         has_trash++;
1287         }
1288
1289         if (!has_trash) return;
1290         
1291         if (confirm) {
1292                 if (alertpanel(_("Empty trash"),
1293                                _("Empty all messages in trash?"),
1294                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1295                         return;
1296                 manage_window_focus_in(mainwin->window, NULL, NULL);
1297         }
1298
1299         procmsg_empty_trash();
1300
1301         for (list = folder_get_list(); list != NULL; list = list->next) {
1302                 folder = list->data;
1303                 if (folder && folder->trash) {
1304                         folderview_update_item(folder->trash, TRUE);
1305                 }
1306         }
1307
1308         if (mainwin->summaryview->folder_item &&
1309             mainwin->summaryview->folder_item->stype == F_TRASH)
1310                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1311 }
1312
1313 void main_window_add_mailbox(MainWindow *mainwin)
1314 {
1315         gchar *path;
1316         Folder *folder;
1317
1318         path = input_dialog(_("Add mailbox"),
1319                             _("Input the location of mailbox.\n"
1320                               "If the existing mailbox is specified, it will be\n"
1321                               "scanned automatically."),
1322                             "Mail");
1323         if (!path) return;
1324         if (folder_find_from_path(path)) {
1325                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1326                 g_free(path);
1327                 return;
1328         }
1329         if (!strcmp(path, "Mail"))
1330                 folder = folder_new(F_MH, _("Mailbox"), path);
1331         else
1332                 folder = folder_new(F_MH, g_basename(path), path);
1333         g_free(path);
1334
1335         if (folder->create_tree(folder) < 0) {
1336                 alertpanel_error(_("Creation of the mailbox failed.\n"
1337                                    "Maybe some files already exist, or you don't have the permission to write there."));
1338                 folder_destroy(folder);
1339                 return;
1340         }
1341
1342         folder_add(folder);
1343         folder_set_ui_func(folder, scan_tree_func, mainwin);
1344         folder_scan_tree(folder);
1345         folder_set_ui_func(folder, NULL, NULL);
1346
1347         folderview_set(mainwin->folderview);
1348 }
1349
1350 void main_window_add_mbox(MainWindow *mainwin)
1351 {
1352         gchar *path;
1353         Folder *folder;
1354         FolderItem * item;
1355
1356         path = input_dialog(_("Add mbox mailbox"),
1357                             _("Input the location of mailbox."),
1358                             "mail");
1359
1360         if (!path) return;
1361
1362         if (folder_find_from_path(path)) {
1363                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1364                 g_free(path);
1365                 return;
1366         }
1367
1368         /*
1369         if (!strcmp(path, "Mail"))
1370                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1371                 else
1372         */
1373
1374         folder = folder_new(F_MBOX, g_basename(path), path);
1375         g_free(path);
1376
1377         if (folder->create_tree(folder) < 0) {
1378                 alertpanel_error(_("Creation of the mailbox failed."));
1379                 folder_destroy(folder);
1380                 return;
1381         }
1382
1383         folder_add(folder);
1384
1385         item = folder_item_new(folder, folder->name, NULL);
1386         item->folder = folder;
1387         folder->node = g_node_new(item);
1388
1389         folder->create_folder(folder, item, "inbox");
1390         folder->create_folder(folder, item, "outbox");
1391         folder->create_folder(folder, item, "queue");
1392         folder->create_folder(folder, item, "draft");
1393         folder->create_folder(folder, item, "trash");
1394
1395         folderview_set(mainwin->folderview);
1396 }
1397
1398 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1399 {
1400         SensitiveCond state = 0;
1401         SummarySelection selection;
1402         FolderItem *item = mainwin->summaryview->folder_item;
1403         GList *account_list = account_get_list();
1404         
1405         selection = summary_get_selection_type(mainwin->summaryview);
1406
1407         if (mainwin->lock_count == 0)
1408                 state |= M_UNLOCKED;
1409         if (selection != SUMMARY_NONE)
1410                 state |= M_MSG_EXIST;
1411         if (item && item->path && item->parent && !item->no_select) {
1412                 state |= M_EXEC;
1413                 if (item->threaded)
1414                         state |= M_THREADED;
1415                 else
1416                         state |= M_UNTHREADED;  
1417                 /*              if (item->folder->type != F_NEWS) */
1418                 state |= M_ALLOW_DELETE;
1419
1420                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
1421                     || selection != SUMMARY_NONE)
1422                         state |= M_HIDE_READ_MSG;       
1423         }               
1424         if (selection == SUMMARY_SELECTED_SINGLE ||
1425             selection == SUMMARY_SELECTED_MULTIPLE)
1426                 state |= M_TARGET_EXIST;
1427         if (selection == SUMMARY_SELECTED_SINGLE)
1428                 state |= M_SINGLE_TARGET_EXIST;
1429         if (mainwin->summaryview->folder_item &&
1430             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1431                 state |= M_NEWS;
1432         if (selection == SUMMARY_SELECTED_SINGLE &&
1433             (item &&
1434              (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1435               item->stype == F_QUEUE)))
1436                 state |= M_ALLOW_REEDIT;
1437         if (cur_account)
1438                 state |= M_HAVE_ACCOUNT;
1439         
1440         for ( ; account_list != NULL; account_list = account_list->next) {
1441                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
1442                         state |= M_HAVE_NEWS_ACCOUNT;
1443                         break;
1444                 }
1445         }
1446
1447         if (inc_is_active())
1448                 state |= M_INC_ACTIVE;
1449
1450         return state;
1451 }
1452
1453
1454
1455 void main_window_set_menu_sensitive(MainWindow *mainwin)
1456 {
1457         GtkItemFactory *ifactory = mainwin->menu_factory;
1458         SensitiveCond state;
1459         gboolean sensitive;
1460         GtkWidget *menuitem;
1461         FolderItem *item;
1462         gchar *menu_path;
1463         gint i;
1464
1465         static const struct {
1466                 gchar *const entry;
1467                 SensitiveCond cond;
1468         } entry[] = {
1469                 {"/File/Add mailbox..."                       , M_UNLOCKED},
1470                 {"/File/Add mbox mailbox..."                  , M_UNLOCKED},
1471                 {"/File/Check for new messages in all folders", M_UNLOCKED},
1472                 {"/File/Folder"                               , M_UNLOCKED},
1473                 {"/File/Import mbox file..."                  , M_UNLOCKED},
1474                 {"/File/Export to mbox file..."               , M_UNLOCKED},
1475                 {"/File/Empty trash"                          , M_UNLOCKED},
1476                 {"/File/Work offline"                         , M_UNLOCKED},
1477
1478                 {"/File/Save as...", M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1479                 {"/File/Print..."  , M_TARGET_EXIST|M_UNLOCKED},
1480                 /* {"/File/Close"  , M_UNLOCKED}, */
1481                 {"/File/Exit"      , M_UNLOCKED},
1482
1483                 {"/Edit/Select thread"             , M_SINGLE_TARGET_EXIST},
1484                 {"/View/Sort"                      , M_EXEC},
1485                 {"/View/Thread view"               , M_EXEC},
1486                 {"/View/Expand all threads"        , M_MSG_EXIST},
1487                 {"/View/Collapse all threads"      , M_MSG_EXIST},
1488                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
1489                 {"/View/Go to/Prev message"        , M_MSG_EXIST},
1490                 {"/View/Go to/Next message"        , M_MSG_EXIST},
1491                 {"/View/Go to/Prev unread message" , M_MSG_EXIST},
1492                 {"/View/Go to/Next unread message" , M_MSG_EXIST},
1493                 {"/View/Go to/Prev new message"    , M_MSG_EXIST},
1494                 {"/View/Go to/Next new message"    , M_MSG_EXIST},
1495                 {"/View/Go to/Prev marked message" , M_MSG_EXIST},
1496                 {"/View/Go to/Next marked message" , M_MSG_EXIST},
1497                 {"/View/Go to/Prev labeled message", M_MSG_EXIST},
1498                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
1499                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
1500                 {"/View/Show all header"           , M_SINGLE_TARGET_EXIST},
1501                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
1502
1503                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1504                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1505                 {"/Message/Cancel receiving"      , M_INC_ACTIVE},
1506                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
1507                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1508                 {"/Message/Reply to sender"       , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1509                 {"/Message/Reply to all"          , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1510                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1511                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1512                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1513                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1514                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1515                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1516                 {"/Message/Delete"                , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1517                 {"/Message/Mark"                  , M_TARGET_EXIST},
1518
1519                 {"/Tools/Selective download..."     , M_HAVE_ACCOUNT|M_UNLOCKED},
1520                 {"/Tools/Add sender to address book", M_SINGLE_TARGET_EXIST},
1521                 {"/Tools/Harvest addresses"         , M_UNLOCKED},
1522                 {"/Tools/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1523                 {"/Tools/Create filter rule"        , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1524                 {"/Tools/Actions"                   , M_TARGET_EXIST|M_UNLOCKED},
1525                 {"/Tools/Execute"                   , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1526                 {"/Tools/Delete duplicated messages", M_MSG_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1527
1528                 {"/Configuration", M_UNLOCKED},
1529
1530                 {NULL, 0}
1531         };
1532
1533         state = main_window_get_current_state(mainwin);
1534
1535         for (i = 0; entry[i].entry != NULL; i++) {
1536                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1537                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
1538         }
1539
1540         main_window_menu_callback_block(mainwin);
1541
1542 #define SET_CHECK_MENU_ACTIVE(path, active) \
1543 { \
1544         menuitem = gtk_item_factory_get_widget(ifactory, path); \
1545         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
1546 }
1547
1548         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
1549                               messageview_is_visible(mainwin->messageview));
1550
1551         item = mainwin->summaryview->folder_item;
1552         menu_path = "/View/Sort/Don't sort";
1553         if (item) {
1554                 switch (item->sort_key) {
1555                 case SORT_BY_NUMBER:
1556                         menu_path = "/View/Sort/by number"; break;
1557                 case SORT_BY_SIZE:
1558                         menu_path = "/View/Sort/by size"; break;
1559                 case SORT_BY_DATE:
1560                         menu_path = "/View/Sort/by date"; break;
1561                 case SORT_BY_FROM:
1562                         menu_path = "/View/Sort/by from"; break;
1563                 case SORT_BY_SUBJECT:
1564                         menu_path = "/View/Sort/by subject"; break;
1565                 case SORT_BY_LABEL:
1566                         menu_path = "/View/Sort/by color label"; break;
1567                 case SORT_BY_MARK:
1568                         menu_path = "/View/Sort/by mark"; break;
1569                 case SORT_BY_UNREAD:
1570                         menu_path = "/View/Sort/by unread"; break;
1571                 case SORT_BY_MIME:
1572                         menu_path = "/View/Sort/by attachment"; break;
1573                 case SORT_BY_SCORE:
1574                         menu_path = "/View/Sort/by score"; break;
1575                 case SORT_BY_LOCKED:
1576                         menu_path = "/View/Sort/by locked"; break;
1577                 case SORT_BY_NONE:
1578                 default:
1579                         menu_path = "/View/Sort/Don't sort"; break;
1580                 }
1581         }
1582         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
1583
1584         if (!item || item->sort_type == SORT_ASCENDING) {
1585                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
1586         } else {
1587                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
1588         }
1589
1590         if (item && item->sort_key != SORT_BY_NONE) {
1591                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
1592                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
1593         } else {
1594                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
1595                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
1596         }
1597
1598         SET_CHECK_MENU_ACTIVE("/View/Show all header",
1599                               mainwin->messageview->textview->show_all_headers);
1600         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
1601
1602 #undef SET_CHECK_MENU_ACTIVE
1603
1604         main_window_menu_callback_unblock(mainwin);
1605 }
1606
1607 void main_window_popup(MainWindow *mainwin)
1608 {
1609         gint x, y;
1610         gint sx, sy;
1611         GtkWidget *widget;
1612
1613         gdk_window_get_origin(mainwin->window->window, &x, &y);
1614         sx = gdk_screen_width();
1615         sy = gdk_screen_height();
1616         x %= sx; if (x < 0) x = 0;
1617         y %= sy; if (y < 0) y = 0;
1618         gdk_window_move(mainwin->window->window, x, y);
1619         gdk_window_raise(mainwin->window->window);
1620         gdk_window_show(mainwin->window->window);
1621
1622         debug_print("window position: x = %d, y = %d\n", x, y);
1623
1624         switch (mainwin->type) {
1625         case SEPARATE_FOLDER:
1626                 widget = mainwin->win.sep_folder.folderwin;
1627                 gdk_window_get_origin(widget->window, &x, &y);
1628                 x %= sx; if (x < 0) x = 0;
1629                 y %= sy; if (y < 0) y = 0;
1630                 gdk_window_move(widget->window, x, y);
1631                 gdk_window_raise(widget->window);
1632                 break;
1633         case SEPARATE_MESSAGE:
1634                 widget = mainwin->win.sep_message.messagewin;
1635                 gdk_window_get_origin(widget->window, &x, &y);
1636                 x %= sx; if (x < 0) x = 0;
1637                 y %= sy; if (y < 0) y = 0;
1638                 gdk_window_move(widget->window, x, y);
1639                 gdk_window_raise(widget->window);
1640                 break;
1641         case SEPARATE_BOTH:
1642                 widget = mainwin->win.sep_both.folderwin;
1643                 gdk_window_get_origin(widget->window, &x, &y);
1644                 x %= sx; if (x < 0) x = 0;
1645                 y %= sy; if (y < 0) y = 0;
1646                 gdk_window_move(widget->window, x, y);
1647                 gdk_window_raise(widget->window);
1648                 widget = mainwin->win.sep_both.messagewin;
1649                 gdk_window_get_origin(widget->window, &x, &y);
1650                 x %= sx; if (x < 0) x = 0;
1651                 y %= sy; if (y < 0) y = 0;
1652                 gdk_window_move(widget->window, x, y);
1653                 gdk_window_raise(widget->window);
1654                 break;
1655         default:
1656                 break;
1657         }
1658 }
1659
1660 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1661 {
1662         GtkWidget *folderwin = NULL;
1663         GtkWidget *messagewin = NULL;
1664         GtkWidget *hpaned;
1665         GtkWidget *vpaned;
1666         GtkWidget *vbox_body = mainwin->vbox_body;
1667         GtkItemFactory *ifactory = mainwin->menu_factory;
1668         GtkWidget *menuitem;
1669
1670         debug_print("Setting widgets...");
1671
1672         /* create separated window(s) if needed */
1673         if (type & SEPARATE_FOLDER) {
1674                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1675                 gtk_window_set_title(GTK_WINDOW(folderwin),
1676                                      _("Sylpheed - Folder View"));
1677                 gtk_window_set_wmclass(GTK_WINDOW(folderwin),
1678                                        "folder_view", "Sylpheed");
1679                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1680                                       TRUE, TRUE, FALSE);
1681                 gtk_widget_set_usize(folderwin, -1,
1682                                      prefs_common.mainview_height);
1683                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1684                                                BORDER_WIDTH);
1685                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1686                                    GTK_SIGNAL_FUNC(folder_window_close_cb),
1687                                    mainwin);
1688         }
1689         if (type & SEPARATE_MESSAGE) {
1690                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1691                 gtk_window_set_title(GTK_WINDOW(messagewin),
1692                                      _("Sylpheed - Message View"));
1693                 gtk_window_set_wmclass(GTK_WINDOW(messagewin),
1694                                        "message_view", "Sylpheed");
1695                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1696                                       TRUE, TRUE, FALSE);
1697                 gtk_widget_set_usize
1698                         (messagewin, prefs_common.mainview_width,
1699                          prefs_common.mainview_height
1700                          - prefs_common.summaryview_height
1701                          + DEFAULT_HEADERVIEW_HEIGHT);
1702                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1703                                                BORDER_WIDTH);
1704                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1705                                    GTK_SIGNAL_FUNC(message_window_close_cb),
1706                                    mainwin);
1707         }
1708
1709         switch (type) {
1710         case SEPARATE_NONE:
1711                 hpaned = gtk_hpaned_new();
1712                 gtk_widget_show(hpaned);
1713                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1714                 gtk_paned_add1(GTK_PANED(hpaned),
1715                                GTK_WIDGET_PTR(mainwin->folderview));
1716
1717                 vpaned = gtk_vpaned_new();
1718                 if (messageview_is_visible(mainwin->messageview)) {
1719                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1720                         gtk_paned_add1(GTK_PANED(vpaned),
1721                                        GTK_WIDGET_PTR(mainwin->summaryview));
1722                 } else {
1723                         gtk_paned_add2(GTK_PANED(hpaned),
1724                                        GTK_WIDGET_PTR(mainwin->summaryview));
1725                         gtk_widget_ref(vpaned);
1726                 }
1727                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1728                                      prefs_common.summaryview_width,
1729                                      prefs_common.summaryview_height);
1730                 gtk_paned_add2(GTK_PANED(vpaned),
1731                                GTK_WIDGET_PTR(mainwin->messageview));
1732                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1733                                      prefs_common.mainview_width, -1);
1734                 gtk_widget_set_usize(mainwin->window,
1735                                      prefs_common.folderview_width +
1736                                      prefs_common.mainview_width,
1737                                      prefs_common.mainwin_height);
1738                 gtk_widget_show_all(vpaned);
1739
1740                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1741                  * lose track of its visibility state */
1742                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1743                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1744
1745                 mainwin->win.sep_none.hpaned = hpaned;
1746                 mainwin->win.sep_none.vpaned = vpaned;
1747                 break;
1748         case SEPARATE_FOLDER:
1749                 vpaned = gtk_vpaned_new();
1750                 if (messageview_is_visible(mainwin->messageview)) {
1751                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1752                                            TRUE, TRUE, 0);
1753                         gtk_paned_add1(GTK_PANED(vpaned),
1754                                        GTK_WIDGET_PTR(mainwin->summaryview));
1755                 } else {
1756                         gtk_box_pack_start(GTK_BOX(vbox_body),
1757                                            GTK_WIDGET_PTR(mainwin->summaryview),
1758                                            TRUE, TRUE, 0);
1759                         gtk_widget_ref(vpaned);
1760                 }
1761                 gtk_paned_add2(GTK_PANED(vpaned),
1762                                GTK_WIDGET_PTR(mainwin->messageview));
1763                 gtk_widget_show_all(vpaned);
1764                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1765                                      prefs_common.summaryview_width,
1766                                      prefs_common.summaryview_height);
1767                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1768                                      prefs_common.mainview_width, -1);
1769                 gtk_widget_set_usize(mainwin->window,
1770                                      prefs_common.mainview_width,
1771                                      prefs_common.mainview_height);
1772
1773                 gtk_container_add(GTK_CONTAINER(folderwin),
1774                                   GTK_WIDGET_PTR(mainwin->folderview));
1775
1776                 mainwin->win.sep_folder.folderwin = folderwin;
1777                 mainwin->win.sep_folder.vpaned    = vpaned;
1778
1779                 gtk_widget_show_all(folderwin);
1780                 break;
1781         case SEPARATE_MESSAGE:
1782                 hpaned = gtk_hpaned_new();
1783                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1784
1785                 gtk_paned_add1(GTK_PANED(hpaned),
1786                                GTK_WIDGET_PTR(mainwin->folderview));
1787                 gtk_paned_add2(GTK_PANED(hpaned),
1788                                GTK_WIDGET_PTR(mainwin->summaryview));
1789                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1790                                      prefs_common.summaryview_width,
1791                                      prefs_common.summaryview_height);
1792                 gtk_widget_set_usize(mainwin->window,
1793                                      prefs_common.folderview_width +
1794                                      prefs_common.mainview_width,
1795                                      prefs_common.mainwin_height);
1796                 gtk_widget_show_all(hpaned);
1797                 gtk_container_add(GTK_CONTAINER(messagewin),
1798                                   GTK_WIDGET_PTR(mainwin->messageview));
1799
1800                 mainwin->win.sep_message.messagewin = messagewin;
1801                 mainwin->win.sep_message.hpaned     = hpaned;
1802
1803                 gtk_widget_show_all(messagewin);
1804                 
1805                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1806                  * lose track of its visibility state */
1807                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1808                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1809                 break;
1810         case SEPARATE_BOTH:
1811                 gtk_box_pack_start(GTK_BOX(vbox_body),
1812                                    GTK_WIDGET_PTR(mainwin->summaryview),
1813                                    TRUE, TRUE, 0);
1814                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1815                                      prefs_common.summaryview_width,
1816                                      prefs_common.summaryview_height);
1817                 gtk_widget_set_usize(mainwin->window,
1818                                      prefs_common.mainview_width,
1819                                      prefs_common.mainwin_height);
1820                 gtk_container_add(GTK_CONTAINER(folderwin),
1821                                   GTK_WIDGET_PTR(mainwin->folderview));
1822                 gtk_container_add(GTK_CONTAINER(messagewin),
1823                                   GTK_WIDGET_PTR(mainwin->messageview));
1824
1825                 mainwin->win.sep_both.folderwin = folderwin;
1826                 mainwin->win.sep_both.messagewin = messagewin;
1827
1828                 gtk_widget_show_all(folderwin);
1829                 gtk_widget_show_all(messagewin);
1830
1831                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1832                  * lose track of its visibility state */
1833                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1834                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1835                 break;
1836         }
1837
1838         mainwin->type = type;
1839
1840         mainwin->messageview->visible = TRUE;
1841
1842         /* toggle menu state */
1843         menuitem = gtk_item_factory_get_item
1844                 (ifactory, "/View/Show or hide/Folder tree");
1845         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1846         menuitem = gtk_item_factory_get_item
1847                 (ifactory, "/View/Show or hide/Message view");
1848         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1849
1850         menuitem = gtk_item_factory_get_item
1851                 (ifactory, "/View/Separate folder tree");
1852         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1853                                        ((type & SEPARATE_FOLDER) != 0));
1854         menuitem = gtk_item_factory_get_item
1855                 (ifactory, "/View/Separate message view");
1856         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1857                                        ((type & SEPARATE_MESSAGE) != 0));
1858
1859         debug_print("done.\n");
1860 }
1861
1862 #if 0
1863 static void toolbar_account_button_pressed(GtkWidget *widget,
1864                                            GdkEventButton *event,
1865                                            gpointer data)
1866 {
1867         MainWindow *mainwin = (MainWindow *)data;
1868
1869         if (!event) return;
1870         if (event->button != 3) return;
1871
1872         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1873         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
1874                             widget);
1875
1876         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
1877                        menu_button_position, widget,
1878                        event->button, event->time);
1879 }
1880 #endif
1881
1882 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1883                                     gpointer data)
1884 {
1885         MainWindow *mainwin = (MainWindow *)data;
1886
1887         if (!event) return;
1888
1889         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1890         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
1891                             widget);
1892
1893         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
1894                        menu_button_position, widget,
1895                        event->button, event->time);
1896 }
1897
1898 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
1899 {
1900         MainWindow *mainwin = (MainWindow *)data;
1901         GtkWidget *button;
1902
1903         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
1904         if (!button) return;
1905         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
1906         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
1907         manage_window_focus_in(mainwin->window, NULL, NULL);
1908 }
1909
1910 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1911                                  gpointer data)
1912 {
1913         MainWindow *mainwin = (MainWindow *)data;
1914
1915         if (mainwin->lock_count == 0)
1916                 app_exit_cb(data, 0, widget);
1917
1918         return TRUE;
1919 }
1920
1921 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1922                                    gpointer data)
1923 {
1924         MainWindow *mainwin = (MainWindow *)data;
1925         GtkWidget *menuitem;
1926
1927         menuitem = gtk_item_factory_get_item
1928                 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
1929         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
1930
1931         return TRUE;
1932 }
1933
1934 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1935                                     gpointer data)
1936 {
1937         MainWindow *mainwin = (MainWindow *)data;
1938         GtkWidget *menuitem;
1939
1940         menuitem = gtk_item_factory_get_item
1941                 (mainwin->menu_factory, "/View/Show or hide/Message view");
1942         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
1943
1944         return TRUE;
1945 }
1946
1947 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1948                            GtkWidget *widget)
1949 {
1950         main_window_add_mailbox(mainwin);
1951 }
1952
1953 static void add_mbox_cb(MainWindow *mainwin, guint action,
1954                         GtkWidget *widget)
1955 {
1956         main_window_add_mbox(mainwin);
1957 }
1958
1959 static void update_folderview_cb(MainWindow *mainwin, guint action,
1960                                  GtkWidget *widget)
1961 {
1962         summary_show(mainwin->summaryview, NULL);
1963         folderview_check_new_all();
1964 }
1965
1966 static void new_folder_cb(MainWindow *mainwin, guint action,
1967                           GtkWidget *widget)
1968 {
1969         folderview_new_folder(mainwin->folderview);
1970 }
1971
1972 static void rename_folder_cb(MainWindow *mainwin, guint action,
1973                              GtkWidget *widget)
1974 {
1975         folderview_rename_folder(mainwin->folderview);
1976 }
1977
1978 static void delete_folder_cb(MainWindow *mainwin, guint action,
1979                              GtkWidget *widget)
1980 {
1981         folderview_delete_folder(mainwin->folderview);
1982 }
1983
1984 static void import_mbox_cb(MainWindow *mainwin, guint action,
1985                            GtkWidget *widget)
1986 {
1987         import_mbox(mainwin->summaryview->folder_item);
1988 }
1989
1990 static void export_mbox_cb(MainWindow *mainwin, guint action,
1991                            GtkWidget *widget)
1992 {
1993         export_mbox(mainwin->summaryview->folder_item);
1994 }
1995
1996 static void empty_trash_cb(MainWindow *mainwin, guint action,
1997                            GtkWidget *widget)
1998 {
1999         main_window_empty_trash(mainwin, TRUE);
2000 }
2001
2002 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2003 {
2004         summary_save_as(mainwin->summaryview);
2005 }
2006
2007 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2008 {
2009         summary_print(mainwin->summaryview);
2010 }
2011
2012 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2013 {
2014         if (prefs_common.confirm_on_exit) {
2015                 if (alertpanel(_("Exit"), _("Exit this program?"),
2016                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2017                         return;
2018                 manage_window_focus_in(mainwin->window, NULL, NULL);
2019         }
2020
2021         app_will_exit(widget, mainwin);
2022 }
2023
2024 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2025 {
2026         if (action == 1)
2027                 summary_search(mainwin->summaryview);
2028         else
2029                 message_search(mainwin->messageview);
2030 }
2031
2032 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2033                              GtkWidget *widget)
2034 {
2035         gboolean active;
2036
2037         active = GTK_CHECK_MENU_ITEM(widget)->active;
2038
2039         switch (mainwin->type) {
2040         case SEPARATE_NONE:
2041         case SEPARATE_MESSAGE:
2042 #if 0
2043                 if (active)
2044                         gtk_widget_show(GTK_WIDGET_PTR(mainwin->folderview));
2045                 else
2046                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->folderview));
2047 #endif
2048                 break;
2049         case SEPARATE_FOLDER:
2050                 debug_print("separate folder\n");
2051                 if (active)
2052                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2053                 else
2054                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2055                 break;
2056         case SEPARATE_BOTH:
2057                 if (active)
2058                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2059                 else
2060                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2061                 break;
2062         }
2063 }
2064
2065 static void toggle_message_cb(MainWindow *mainwin, guint action,
2066                               GtkWidget *widget)
2067 {
2068         gboolean active;
2069
2070         active = GTK_CHECK_MENU_ITEM(widget)->active;
2071
2072         if (active != messageview_is_visible(mainwin->messageview))
2073                 summary_toggle_view(mainwin->summaryview);
2074 }
2075
2076 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2077                               GtkWidget *widget)
2078 {
2079         switch ((ToolbarStyle)action) {
2080         case TOOLBAR_NONE:
2081                 gtk_widget_hide(mainwin->handlebox);
2082         case TOOLBAR_ICON:
2083                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2084                                       GTK_TOOLBAR_ICONS);
2085                 break;
2086         case TOOLBAR_TEXT:
2087                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2088                                       GTK_TOOLBAR_TEXT);
2089                 break;
2090         case TOOLBAR_BOTH:
2091                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2092                                       GTK_TOOLBAR_BOTH);
2093                 break;
2094         }
2095
2096         if (action != TOOLBAR_NONE) {
2097                 gtk_widget_show(mainwin->handlebox);
2098                 gtk_widget_queue_resize(mainwin->handlebox);
2099         }
2100
2101         mainwin->toolbar_style = (ToolbarStyle)action;
2102         prefs_common.toolbar_style = (ToolbarStyle)action;
2103 }
2104
2105 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2106                                 GtkWidget *widget)
2107 {
2108         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2109                 gtk_widget_show(mainwin->hbox_stat);
2110                 prefs_common.show_statusbar = TRUE;
2111         } else {
2112                 gtk_widget_hide(mainwin->hbox_stat);
2113                 prefs_common.show_statusbar = FALSE;
2114         }
2115 }
2116
2117 static void separate_widget_cb(MainWindow *mainwin, guint action,
2118                                GtkWidget *widget)
2119 {
2120         SeparateType type;
2121
2122         if (GTK_CHECK_MENU_ITEM(widget)->active)
2123                 type = mainwin->type | action;
2124         else
2125                 type = mainwin->type & ~action;
2126
2127         main_window_separation_change(mainwin, type);
2128
2129         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2130         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2131 }
2132
2133 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2134 {
2135         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2136                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
2137         } else {
2138                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);           
2139         }
2140 }
2141
2142 static void online_switch_clicked (GtkButton *btn, gpointer data) 
2143 {
2144         MainWindow *mainwin;
2145         GtkItemFactory *ifactory;
2146         GtkCheckMenuItem *menuitem;
2147
2148         mainwin = (MainWindow *) data;
2149         
2150         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2151         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
2152         
2153         g_return_if_fail(mainwin != NULL);
2154         g_return_if_fail(menuitem != NULL);
2155         
2156         if (btn == GTK_BUTTON(mainwin->online_switch)) {
2157                 /* go offline */
2158                 gtk_widget_hide (mainwin->online_switch);
2159                 gtk_widget_show (mainwin->offline_switch);
2160                 menuitem->active = TRUE;
2161                 prefs_common.work_offline = TRUE;
2162                 inc_autocheck_timer_remove();           
2163         } else {
2164                 /*go online */
2165                 gtk_widget_hide (mainwin->offline_switch);
2166                 gtk_widget_show (mainwin->online_switch);
2167                 menuitem->active = FALSE;
2168                 prefs_common.work_offline = FALSE;
2169                 inc_autocheck_timer_set();
2170         }
2171 }
2172
2173 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2174                                 GtkWidget *widget)
2175 {
2176         addressbook_open(NULL);
2177 }
2178
2179 static void log_window_show_cb(MainWindow *mainwin, guint action,
2180                                GtkWidget *widget)
2181 {
2182         log_window_show(mainwin->logwin);
2183 }
2184
2185 static void sel_download_cb(MainWindow *mainwin, guint action,
2186                                GtkWidget *widget)
2187 {
2188         selective_download(mainwin);
2189 }
2190
2191 static void prefs_toolbar_cb(MainWindow *mainwin, guint action,
2192                                GtkWidget *widget)
2193 {
2194         prefs_toolbar();
2195 }
2196
2197
2198 void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2199 {
2200         inc_mail(mainwin, prefs_common.newmail_notify_manu);
2201 }
2202
2203 void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
2204                                     GtkWidget *widget)
2205 {
2206         inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
2207 }
2208
2209 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2210 {
2211         inc_cancel_all();
2212 }
2213
2214 void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2215 {
2216         GList *list;
2217
2218         if (prefs_common.work_offline)
2219                 if (alertpanel(_("Offline warning"), 
2220                                _("You're working offline. Override?"),
2221                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
2222                 return;
2223
2224         for (list = folder_get_list(); list != NULL; list = list->next) {
2225                 Folder *folder = list->data;
2226
2227                 if (folder->queue) {
2228                         if (procmsg_send_queue
2229                                 (folder->queue, prefs_common.savemsg) < 0)
2230                                 alertpanel_error(_("Some errors occurred while sending queued messages."));
2231                         statusbar_pop_all();
2232                         folder_item_scan(folder->queue);
2233                         folderview_update_item(folder->queue, TRUE);
2234                 }
2235         }
2236 }
2237
2238 void compose_mail_cb(MainWindow *mainwin, guint action,
2239                             GtkWidget *widget)
2240 {
2241         PrefsAccount * ac;
2242         GList * list;
2243         GList * cur;
2244
2245         if (mainwin->summaryview->folder_item) {
2246                 ac = mainwin->summaryview->folder_item->folder->account;
2247                 if (ac && ac->protocol != A_NNTP) {
2248                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2249                         return;
2250                 }
2251         }
2252
2253         if(cur_account && (cur_account->protocol != A_NNTP)) {
2254                 compose_new_with_folderitem(cur_account, mainwin->summaryview->folder_item);
2255                 return;
2256         }
2257
2258         list = account_get_list();
2259         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2260                 ac = (PrefsAccount *) cur->data;
2261                 if (ac->protocol != A_NNTP) {
2262                         compose_new_with_folderitem(ac, mainwin->summaryview->folder_item);
2263                         return;
2264                 }
2265         }
2266 }
2267
2268 void compose_news_cb(MainWindow *mainwin, guint action,
2269                             GtkWidget *widget)
2270 {
2271         PrefsAccount * ac = NULL;
2272         GList * list;
2273         GList * cur;
2274
2275         if (mainwin->summaryview->folder_item) {
2276                 ac = mainwin->summaryview->folder_item->folder->account;
2277                 if (ac && ac->protocol == A_NNTP) {
2278                         compose_new(ac,
2279                                     mainwin->summaryview->folder_item->path,
2280                                     NULL);
2281                         return;
2282                 }
2283         }
2284
2285         list = account_get_list();
2286         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2287                 ac = (PrefsAccount *) cur->data;
2288                 if (ac->protocol == A_NNTP) {
2289                         compose_new(ac, NULL, NULL);
2290                         return;
2291                 }
2292         }
2293 }
2294
2295 void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2296 {
2297         summary_reply(mainwin->summaryview, (ComposeMode)action);
2298 }
2299
2300 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2301 {
2302         summary_move_to(mainwin->summaryview);
2303 }
2304
2305 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2306 {
2307         summary_copy_to(mainwin->summaryview);
2308 }
2309
2310 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2311 {
2312         summary_delete(mainwin->summaryview);
2313 }
2314
2315 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2316 {
2317         summary_open_msg(mainwin->summaryview);
2318 }
2319
2320 static void view_source_cb(MainWindow *mainwin, guint action,
2321                            GtkWidget *widget)
2322 {
2323         summary_view_source(mainwin->summaryview);
2324 }
2325
2326 static void show_all_header_cb(MainWindow *mainwin, guint action,
2327                                GtkWidget *widget)
2328 {
2329         if (mainwin->menu_lock_count) return;
2330         summary_display_msg_selected(mainwin->summaryview,
2331                                      GTK_CHECK_MENU_ITEM(widget)->active);
2332 }
2333
2334 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2335 {
2336         summary_reedit(mainwin->summaryview);
2337 }
2338
2339 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2340 {
2341         summary_mark(mainwin->summaryview);
2342 }
2343
2344 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2345 {
2346         summary_unmark(mainwin->summaryview);
2347 }
2348
2349 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2350                               GtkWidget *widget)
2351 {
2352         summary_mark_as_unread(mainwin->summaryview);
2353 }
2354
2355 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2356                             GtkWidget *widget)
2357 {
2358         summary_mark_as_read(mainwin->summaryview);
2359 }
2360
2361 static void mark_all_read_cb(MainWindow *mainwin, guint action,
2362                              GtkWidget *widget)
2363 {
2364         summary_mark_all_read(mainwin->summaryview);
2365 }
2366
2367 static void add_address_cb(MainWindow *mainwin, guint action,
2368                            GtkWidget *widget)
2369 {
2370         summary_add_address(mainwin->summaryview);
2371 }
2372
2373 static void set_charset_cb(MainWindow *mainwin, guint action,
2374                            GtkWidget *widget)
2375 {
2376         const gchar *str;
2377
2378         str = conv_get_charset_str((CharSet)action);
2379         g_free(prefs_common.force_charset);
2380         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2381
2382         summary_redisplay_msg(mainwin->summaryview);
2383
2384         debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
2385 }
2386
2387 static void hide_read_messages (MainWindow *mainwin, guint action,
2388                                 GtkWidget *widget)
2389 {
2390         if (!mainwin->summaryview->folder_item
2391             || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
2392                 return;
2393         summary_toggle_show_read_messages(mainwin->summaryview);
2394 }
2395
2396 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2397 {
2398         if (mainwin->menu_lock_count) return;
2399         if (!mainwin->summaryview->folder_item) return;
2400
2401         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2402                 summary_thread_build(mainwin->summaryview);
2403                 mainwin->summaryview->folder_item->threaded = TRUE;
2404         } else {
2405                 summary_unthread(mainwin->summaryview);
2406                 mainwin->summaryview->folder_item->threaded = FALSE;
2407         }
2408 }
2409
2410 static void expand_threads_cb(MainWindow *mainwin, guint action,
2411                               GtkWidget *widget)
2412 {
2413         summary_expand_threads(mainwin->summaryview);
2414 }
2415
2416 static void collapse_threads_cb(MainWindow *mainwin, guint action,
2417                                 GtkWidget *widget)
2418 {
2419         summary_collapse_threads(mainwin->summaryview);
2420 }
2421
2422 static void set_display_item_cb(MainWindow *mainwin, guint action,
2423                                 GtkWidget *widget)
2424 {
2425         prefs_summary_column_open();
2426 }
2427
2428 static void sort_summary_cb(MainWindow *mainwin, guint action,
2429                             GtkWidget *widget)
2430 {
2431         FolderItem *item = mainwin->summaryview->folder_item;
2432         GtkWidget *menuitem;
2433
2434         if (mainwin->menu_lock_count) return;
2435         if (item) {
2436                 menuitem = gtk_item_factory_get_item
2437                         (mainwin->menu_factory, "/View/Sort/Ascending");
2438                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
2439                              GTK_CHECK_MENU_ITEM(menuitem)->active
2440                              ? SORT_ASCENDING : SORT_DESCENDING);
2441         }
2442 }
2443
2444 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
2445                                  GtkWidget *widget)
2446 {
2447         FolderItem *item = mainwin->summaryview->folder_item;
2448
2449         if (mainwin->menu_lock_count) return;
2450         if (item)
2451                 summary_sort(mainwin->summaryview,
2452                              item->sort_key, (FolderSortType)action);
2453 }
2454
2455 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2456                                   GtkWidget *widget)
2457 {
2458         summary_attract_by_subject(mainwin->summaryview);
2459 }
2460
2461 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2462                                  GtkWidget *widget)
2463 {
2464         summary_delete_duplicated(mainwin->summaryview);
2465 }
2466
2467 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2468 {
2469         summary_filter(mainwin->summaryview);
2470 }
2471
2472 static void execute_summary_cb(MainWindow *mainwin, guint action,
2473                                GtkWidget *widget)
2474 {
2475         summary_execute(mainwin->summaryview);
2476 }
2477
2478 static void update_summary_cb(MainWindow *mainwin, guint action,
2479                               GtkWidget *widget)
2480 {
2481         FolderItem *fitem;
2482         FolderView *folderview = mainwin->folderview;
2483
2484         if (!mainwin->summaryview->folder_item) return;
2485         if (!folderview->opened) return;
2486
2487         folder_update_op_count();
2488
2489         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2490                                             folderview->opened);
2491         if (!fitem) return;
2492
2493         folder_item_scan(fitem);
2494         summary_show(mainwin->summaryview, fitem);
2495 }
2496
2497 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2498 {
2499         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2500 }
2501
2502 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2503 {
2504         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2505 }
2506
2507 static void prev_unread_cb(MainWindow *mainwin, guint action,
2508                            GtkWidget *widget)
2509 {
2510         summary_select_prev_unread(mainwin->summaryview);
2511 }
2512
2513 void next_unread_cb(MainWindow *mainwin, guint action,
2514                            GtkWidget *widget)
2515 {
2516         summary_select_next_unread(mainwin->summaryview);
2517 }
2518
2519 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2520 {
2521         summary_select_prev_new(mainwin->summaryview);
2522 }
2523
2524 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2525 {
2526         summary_select_next_new(mainwin->summaryview);
2527 }
2528
2529 static void prev_marked_cb(MainWindow *mainwin, guint action,
2530                            GtkWidget *widget)
2531 {
2532         summary_select_prev_marked(mainwin->summaryview);
2533 }
2534
2535 static void next_marked_cb(MainWindow *mainwin, guint action,
2536                            GtkWidget *widget)
2537 {
2538         summary_select_next_marked(mainwin->summaryview);
2539 }
2540
2541 static void prev_labeled_cb(MainWindow *mainwin, guint action,
2542                             GtkWidget *widget)
2543 {
2544         summary_select_prev_labeled(mainwin->summaryview);
2545 }
2546
2547 static void next_labeled_cb(MainWindow *mainwin, guint action,
2548                             GtkWidget *widget)
2549 {
2550         summary_select_next_labeled(mainwin->summaryview);
2551 }
2552
2553 static void goto_folder_cb(MainWindow *mainwin, guint action,
2554                            GtkWidget *widget)
2555 {
2556         FolderItem *to_folder;
2557
2558         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
2559
2560         if (to_folder)
2561                 folderview_select(mainwin->folderview, to_folder);
2562 }
2563
2564 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2565 {
2566         messageview_copy_clipboard(mainwin->messageview);
2567 }
2568
2569 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2570 {
2571         MessageView *msgview = mainwin->messageview;
2572
2573         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2574                 summary_select_all(mainwin->summaryview);
2575         else if (messageview_is_visible(msgview) &&
2576                  (GTK_WIDGET_HAS_FOCUS(msgview->textview->text) ||
2577                   GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
2578                 messageview_select_all(mainwin->messageview);
2579 }
2580
2581 static void selthread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2582 {
2583         if (messageview_is_visible(mainwin->summaryview->messageview))
2584                 summary_select_thread(mainwin->summaryview);
2585 }
2586
2587 static void create_filter_cb(MainWindow *mainwin, guint action,
2588                              GtkWidget *widget)
2589 {
2590         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action);
2591 }
2592
2593 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2594                                  GtkWidget *widget)
2595 {
2596         prefs_common_open();
2597 }
2598
2599 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2600                                  GtkWidget *widget)
2601 {
2602         prefs_filter_open(NULL, NULL);
2603 }
2604
2605 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2606                                   GtkWidget *widget)
2607 {
2608         prefs_scoring_open(NULL);
2609 }
2610
2611 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2612                                     GtkWidget *widget)
2613 {
2614         prefs_filtering_open(NULL, NULL, NULL);
2615 }
2616
2617 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
2618                                    GtkWidget *widget)
2619 {
2620         prefs_template_open();
2621 }
2622
2623 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
2624                                   GtkWidget *widget)
2625 {
2626         prefs_actions_open(mainwin);
2627 }
2628
2629 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2630                                   GtkWidget *widget)
2631 {
2632         if (!cur_account) {
2633                 new_account_cb(mainwin, 0, widget);
2634         } else {
2635                 gboolean prev_default = cur_account->is_default;
2636
2637                 prefs_account_open(cur_account);
2638                 if (!prev_default && cur_account->is_default)
2639                         account_set_as_default(cur_account);
2640                 account_save_config_all();
2641                 account_set_menu();
2642                 main_window_reflect_prefs_all();
2643         }
2644 }
2645
2646 static void new_account_cb(MainWindow *mainwin, guint action,
2647                            GtkWidget *widget)
2648 {
2649         account_edit_open();
2650         if (!compose_get_compose_list()) account_add();
2651 }
2652
2653 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2654 {
2655         cur_account = (PrefsAccount *)data;
2656         main_window_reflect_prefs_all();
2657 }
2658
2659 static void manual_open_cb(MainWindow *mainwin, guint action,
2660                            GtkWidget *widget)
2661 {
2662         manual_open((ManualLang)action);
2663 }
2664
2665 static void faq_open_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2666 {
2667         faq_open((ManualLang)action);
2668 }
2669
2670 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2671 {
2672         MainWindow *mainwin = (MainWindow *)data;
2673         gchar *str;
2674
2675         if (item->path)
2676                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2677                                       LOCAL_FOLDER(folder)->rootpath,
2678                                       G_DIR_SEPARATOR,
2679                                       item->path);
2680         else
2681                 str = g_strdup_printf(_("Scanning folder %s ..."),
2682                                       LOCAL_FOLDER(folder)->rootpath);
2683
2684         STATUSBAR_PUSH(mainwin, str);
2685         STATUSBAR_POP(mainwin);
2686         g_free(str);
2687 }
2688
2689 #define BREAK_ON_MODIFIER_KEY() \
2690         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
2691
2692 static void key_pressed (GtkWidget *widget, GdkEventKey *event, gpointer data)
2693 {
2694         MainWindow *mainwin = (MainWindow*) data;
2695         
2696         if (!mainwin || !event) return;
2697                 
2698         switch (event->keyval) {
2699         case GDK_Q:             /* Quit */
2700                 BREAK_ON_MODIFIER_KEY();
2701
2702                 app_exit_cb(mainwin, 0, NULL);
2703                 return;
2704         default:
2705                 break;
2706         }
2707 }
2708
2709 #undef BREAK_ON_MODIFIER_KEY
2710
2711 static void set_toolbar_style(MainWindow *mainwin)
2712 {
2713         switch (prefs_common.toolbar_style) {
2714         case TOOLBAR_NONE:
2715                 gtk_widget_hide(mainwin->handlebox);
2716                 break;
2717         case TOOLBAR_ICON:
2718                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2719                                       GTK_TOOLBAR_ICONS);
2720                 break;
2721         case TOOLBAR_TEXT:
2722                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2723                                       GTK_TOOLBAR_TEXT);
2724                 break;
2725         case TOOLBAR_BOTH:
2726                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2727                                       GTK_TOOLBAR_BOTH);
2728                 break;
2729         }
2730         
2731         if (prefs_common.toolbar_style != TOOLBAR_NONE) {
2732                 gtk_widget_show(mainwin->handlebox);
2733                 gtk_widget_queue_resize(mainwin->handlebox);
2734         }
2735 }
2736
2737 /*
2738  * Harvest addresses for selected folder.
2739  */
2740 static void addr_harvest_cb( MainWindow *mainwin,
2741                             guint action,
2742                             GtkWidget *widget )
2743 {
2744         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
2745 }
2746
2747 /*
2748  * Harvest addresses for selected messages in summary view.
2749  */
2750 static void addr_harvest_msg_cb( MainWindow *mainwin,
2751                             guint action,
2752                             GtkWidget *widget )
2753 {
2754         summary_harvest_address( mainwin->summaryview );
2755 }
2756
2757 /*
2758 * End of Source.
2759 */
2760