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