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