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