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