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