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