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