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