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