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