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