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