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