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