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