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