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