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