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