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