53fd490167e78e0e9fdeeb86bed8145a23d42982
[claws.git] / src / mainwindow.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2002 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include "defs.h"
21
22 #include <glib.h>
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtkmain.h>
25 #include <gtk/gtkwindow.h>
26 #include <gtk/gtkwidget.h>
27 #include <gtk/gtksignal.h>
28 #include <gtk/gtkvbox.h>
29 #include <gtk/gtkcontainer.h>
30 #include <gtk/gtkstatusbar.h>
31 #include <gtk/gtkprogressbar.h>
32 #include <gtk/gtkhpaned.h>
33 #include <gtk/gtkvpaned.h>
34 #include <gtk/gtkcheckmenuitem.h>
35 #include <gtk/gtkitemfactory.h>
36 #include <gtk/gtkeditable.h>
37 #include <gtk/gtkmenu.h>
38 #include <gtk/gtkmenuitem.h>
39 #include <gtk/gtkhandlebox.h>
40 #include <gtk/gtktoolbar.h>
41 #include <gtk/gtkbutton.h>
42 #include <string.h>
43
44 #include "intl.h"
45 #include "main.h"
46 #include "mainwindow.h"
47 #include "folderview.h"
48 #include "foldersel.h"
49 #include "summaryview.h"
50 #include "summary_search.h"
51 #include "messageview.h"
52 #include "message_search.h"
53 #include "headerview.h"
54 #include "menu.h"
55 #include "stock_pixmap.h"
56 #include "folder.h"
57 #include "inc.h"
58 #include "compose.h"
59 #include "procmsg.h"
60 #include "import.h"
61 #include "export.h"
62 #include "prefs_common.h"
63 #include "prefs_actions.h"
64 #include "prefs_filtering.h"
65 #include "prefs_scoring.h"
66 #include "prefs_account.h"
67 #include "prefs_folder_item.h"
68 #include "prefs_summary_column.h"
69 #include "prefs_template.h"
70 #include "prefs_toolbar.h"
71 #include "account.h"
72 #include "addressbook.h"
73 #include "logwindow.h"
74 #include "manage_window.h"
75 #include "alertpanel.h"
76 #include "statusbar.h"
77 #include "inputdialog.h"
78 #include "utils.h"
79 #include "gtkutils.h"
80 #include "codeconv.h"
81 #include "about.h"
82 #include "manual.h"
83 #include "version.h"
84 #include "selective_download.h"
85 #include "ssl_manager.h"
86 #include "sslcertwindow.h"
87
88 #define AC_LABEL_WIDTH  240
89
90 /* list of all instantiated MainWindow */
91 static GList *mainwin_list = NULL;
92
93 static GdkCursor *watch_cursor;
94
95 static void main_window_menu_callback_block     (MainWindow     *mainwin);
96 static void main_window_menu_callback_unblock   (MainWindow     *mainwin);
97
98 static void main_window_show_cur_account        (MainWindow     *mainwin);
99
100 static void main_window_set_widgets             (MainWindow     *mainwin,
101                                                  SeparateType    type);
102
103 #if 0
104 static void toolbar_account_button_pressed      (GtkWidget      *widget,
105                                                  GdkEventButton *event,
106                                                  gpointer        data);
107 #endif
108 static void ac_label_button_pressed             (GtkWidget      *widget,
109                                                  GdkEventButton *event,
110                                                  gpointer        data);
111 static void ac_menu_popup_closed                (GtkMenuShell   *menu_shell,
112                                                  gpointer        data);
113
114 static gint main_window_close_cb        (GtkWidget      *widget,
115                                          GdkEventAny    *event,
116                                          gpointer        data);
117 static gint folder_window_close_cb      (GtkWidget      *widget,
118                                          GdkEventAny    *event,
119                                          gpointer        data);
120 static gint message_window_close_cb     (GtkWidget      *widget,
121                                          GdkEventAny    *event,
122                                          gpointer        data);
123
124 static void add_mailbox_cb       (MainWindow    *mainwin,
125                                   guint          action,
126                                   GtkWidget     *widget);
127 static void add_mbox_cb          (MainWindow    *mainwin,
128                                   guint          action,
129                                   GtkWidget     *widget);
130 static void update_folderview_cb (MainWindow    *mainwin,
131                                   guint          action,
132                                   GtkWidget     *widget);
133 static void new_folder_cb        (MainWindow    *mainwin,
134                                   guint          action,
135                                   GtkWidget     *widget);
136 static void rename_folder_cb     (MainWindow    *mainwin,
137                                   guint          action,
138                                   GtkWidget     *widget);
139 static void delete_folder_cb     (MainWindow    *mainwin,
140                                   guint          action,
141                                   GtkWidget     *widget);
142 static void import_mbox_cb       (MainWindow    *mainwin,
143                                   guint          action,
144                                   GtkWidget     *widget);
145 static void export_mbox_cb       (MainWindow    *mainwin,
146                                   guint          action,
147                                   GtkWidget     *widget);
148 static void empty_trash_cb       (MainWindow    *mainwin,
149                                   guint          action,
150                                   GtkWidget     *widget);
151
152 static void save_as_cb           (MainWindow    *mainwin,
153                                   guint          action,
154                                   GtkWidget     *widget);
155 static void print_cb             (MainWindow    *mainwin,
156                                   guint          action,
157                                   GtkWidget     *widget);
158 static void app_exit_cb          (MainWindow    *mainwin,
159                                   guint          action,
160                                   GtkWidget     *widget);
161
162 static void search_cb            (MainWindow    *mainwin,
163                                   guint          action,
164                                   GtkWidget     *widget);
165
166 static void toggle_folder_cb     (MainWindow    *mainwin,
167                                   guint          action,
168                                   GtkWidget     *widget);
169 static void toggle_message_cb    (MainWindow    *mainwin,
170                                   guint          action,
171                                   GtkWidget     *widget);
172 static void toggle_toolbar_cb    (MainWindow    *mainwin,
173                                   guint          action,
174                                   GtkWidget     *widget);
175 static void toggle_statusbar_cb  (MainWindow    *mainwin,
176                                   guint          action,
177                                   GtkWidget     *widget);
178 static void separate_widget_cb   (MainWindow    *mainwin,
179                                   guint          action,
180                                   GtkWidget     *widget);
181
182 static void addressbook_open_cb (MainWindow     *mainwin,
183                                  guint           action,
184                                  GtkWidget      *widget);
185 static void log_window_show_cb  (MainWindow     *mainwin,
186                                  guint           action,
187                                  GtkWidget      *widget);
188 static void sel_download_cb          (MainWindow *mainwin, 
189                                  guint action,
190                                  GtkWidget *widget);
191 static void prefs_toolbar_cb        (MainWindow *mainwin, 
192                                  guint action,
193                                  GtkWidget *widget);
194
195 static void reply_cb                              (MainWindow   *mainwin,
196                                          guint           action,
197                                          GtkWidget      *widget);
198
199 static void inc_mail_cb                           (MainWindow   *mainwin,
200                                          guint           action,
201                                          GtkWidget      *widget);
202
203 static void inc_all_account_mail_cb               (MainWindow   *mainwin,
204                                          guint           action,
205                                          GtkWidget      *widget);
206
207 static void send_queue_cb                         (MainWindow   *mainwin,
208                                          guint           action,
209                                          GtkWidget      *widget);
210
211 static void compose_mail_cb                          (MainWindow       *mainwin, 
212                                          guint action,
213                                            GtkWidget         *widget);
214
215 static void compose_news_cb                          (MainWindow       *mainwin, 
216                                          guint action,
217                                            GtkWidget         *widget);
218
219 static void next_unread_cb                         (MainWindow  *mainwin,
220                                           guint          action,
221                                           GtkWidget     *widget);
222
223 static void toolbar_inc_cb              (GtkWidget      *widget,
224                                          gpointer        data);
225
226 static void toolbar_inc_all_cb          (GtkWidget      *widget,
227                                          gpointer        data);
228
229 static void toolbar_send_cb             (GtkWidget      *widget,
230                                          gpointer        data);
231
232 static void toolbar_compose_cb          (GtkWidget      *widget,
233                                          gpointer        data);
234
235 static void toolbar_reply_cb            (GtkWidget      *widget,
236                                          gpointer        data);
237
238 static void toolbar_reply_to_all_cb     (GtkWidget      *widget,
239                                          gpointer        data);
240
241 static void toolbar_reply_to_list_cb    (GtkWidget      *widget,
242                                          gpointer        data);
243
244 static void toolbar_reply_to_sender_cb  (GtkWidget      *widget,
245                                          gpointer        data);
246
247 static void toolbar_forward_cb          (GtkWidget      *widget,
248                                          gpointer        data);
249
250 static void toolbar_exec_cb             (GtkWidget      *widget,
251                                          gpointer        data);
252
253 static void toolbar_next_unread_cb      (GtkWidget      *widget,
254                                          gpointer        data);
255
256
257 static void toolbar_reply_popup_cb             (GtkWidget       *widget,
258                                                 GdkEventButton  *event,
259                                                 gpointer         data);
260 static void toolbar_reply_popup_closed_cb      (GtkMenuShell    *menu_shell,
261                                                 gpointer         data);
262
263 static void toolbar_reply_to_all_popup_cb      (GtkWidget       *widget,
264                                                 GdkEventButton  *event,
265                                                 gpointer         data);
266
267 static void toolbar_reply_to_all_popup_closed_cb
268                                         (GtkMenuShell   *menu_shell,
269                                          gpointer        data);
270
271 static void toolbar_reply_to_list_popup_cb       (GtkWidget     *widget,
272                                                 GdkEventButton  *event,
273                                                 gpointer         data);
274
275 static void toolbar_reply_to_list_popup_closed_cb
276                                         (GtkMenuShell   *menu_shell,
277                                          gpointer        data);
278
279 static void toolbar_reply_to_sender_popup_cb(GtkWidget  *widget,
280                                          GdkEventButton *event,
281                                          gpointer        data);
282 static void toolbar_reply_to_sender_popup_closed_cb
283                                         (GtkMenuShell   *menu_shell,
284                                          gpointer        data);
285
286 static void toolbar_forward_popup_cb     (GtkWidget      *widget,
287                                          GdkEventButton    *event,
288                                          gpointer        data);
289
290 static void toolbar_forward_popup_closed_cb             
291                                         (GtkMenuShell   *menu_shell,
292                                          gpointer        data);
293
294 static void activate_compose_button     (Toolbar       *toolbar,
295                                          ToolbarStyle      style,
296                                          ComposeButtonType type);
297 static void toolbar_buttons_cb          (GtkWidget         *widget, 
298                                          ToolbarItem       *item);
299 static void toolbar_create              (MainWindow        *mainwin,
300                                          GtkWidget         *container);
301
302 static void toolbar_update              (MainWindow        *mainwin);
303
304 static void inc_cancel_cb               (MainWindow     *mainwin,
305                                          guint           action,
306                                          GtkWidget      *widget);
307
308 static void open_msg_cb                 (MainWindow     *mainwin,
309                                          guint           action,
310                                          GtkWidget      *widget);
311
312 static void view_source_cb              (MainWindow     *mainwin,
313                                          guint           action,
314                                          GtkWidget      *widget);
315
316 static void show_all_header_cb          (MainWindow     *mainwin,
317                                          guint           action,
318                                          GtkWidget      *widget);
319
320 static void reedit_cb                   (MainWindow     *mainwin,
321                                          guint           action,
322                                          GtkWidget      *widget);
323
324 static void move_to_cb                  (MainWindow     *mainwin,
325                                          guint           action,
326                                          GtkWidget      *widget);
327 static void copy_to_cb                  (MainWindow     *mainwin,
328                                          guint           action,
329                                          GtkWidget      *widget);
330 static void delete_cb                   (MainWindow     *mainwin,
331                                          guint           action,
332                                          GtkWidget      *widget);
333
334 static void cancel_cb                   (MainWindow     *mainwin,
335                                          guint           action,
336                                          GtkWidget      *widget);
337
338 static void mark_cb                     (MainWindow     *mainwin,
339                                          guint           action,
340                                          GtkWidget      *widget);
341 static void unmark_cb                   (MainWindow     *mainwin,
342                                          guint           action,
343                                          GtkWidget      *widget);
344
345 static void mark_as_unread_cb           (MainWindow     *mainwin,
346                                          guint           action,
347                                          GtkWidget      *widget);
348 static void mark_as_read_cb             (MainWindow     *mainwin,
349                                          guint           action,
350                                          GtkWidget      *widget);
351 static void mark_all_read_cb            (MainWindow     *mainwin,
352                                          guint           action,
353                                          GtkWidget      *widget);
354 static void add_address_cb              (MainWindow     *mainwin,
355                                          guint           action,
356                                          GtkWidget      *widget);
357
358 static void set_charset_cb              (MainWindow     *mainwin,
359                                          guint           action,
360                                          GtkWidget      *widget);
361
362 static void hide_read_messages   (MainWindow    *mainwin,
363                                   guint          action,
364                                   GtkWidget     *widget);
365
366 static void thread_cb            (MainWindow    *mainwin,
367                                   guint          action,
368                                   GtkWidget     *widget);
369 static void expand_threads_cb    (MainWindow    *mainwin,
370                                   guint          action,
371                                   GtkWidget     *widget);
372 static void collapse_threads_cb  (MainWindow    *mainwin,
373                                   guint          action,
374                                   GtkWidget     *widget);
375
376 static void set_display_item_cb  (MainWindow    *mainwin,
377                                   guint          action,
378                                   GtkWidget     *widget);
379 static void sort_summary_cb      (MainWindow    *mainwin,
380                                   guint          action,
381                                   GtkWidget     *widget);
382 static void sort_summary_type_cb (MainWindow    *mainwin,
383                                   guint          action,
384                                   GtkWidget     *widget);
385 static void attract_by_subject_cb(MainWindow    *mainwin,
386                                   guint          action,
387                                   GtkWidget     *widget);
388
389 static void delete_duplicated_cb (MainWindow    *mainwin,
390                                   guint          action,
391                                   GtkWidget     *widget);
392 static void filter_cb            (MainWindow    *mainwin,
393                                   guint          action,
394                                   GtkWidget     *widget);
395 static void execute_summary_cb   (MainWindow    *mainwin,
396                                   guint          action,
397                                   GtkWidget     *widget);
398 static void update_summary_cb    (MainWindow    *mainwin,
399                                   guint          action,
400                                   GtkWidget     *widget);
401
402 static void prev_cb              (MainWindow    *mainwin,
403                                   guint          action,
404                                   GtkWidget     *widget);
405 static void next_cb              (MainWindow    *mainwin,
406                                   guint          action,
407                                   GtkWidget     *widget);
408
409 static void prev_unread_cb       (MainWindow    *mainwin,
410                                   guint          action,
411                                   GtkWidget     *widget);
412
413 static void prev_new_cb          (MainWindow    *mainwin,
414                                   guint          action,
415                                   GtkWidget     *widget);
416 static void next_new_cb          (MainWindow    *mainwin,
417                                   guint          action,
418                                   GtkWidget     *widget);
419 static void prev_marked_cb       (MainWindow    *mainwin,
420                                   guint          action,
421                                   GtkWidget     *widget);
422 static void next_marked_cb       (MainWindow    *mainwin,
423                                   guint          action,
424                                   GtkWidget     *widget);
425 static void prev_labeled_cb      (MainWindow    *mainwin,
426                                   guint          action,
427                                   GtkWidget     *widget);
428 static void next_labeled_cb      (MainWindow    *mainwin,
429                                   guint          action,
430                                   GtkWidget     *widget);
431
432 static void goto_folder_cb       (MainWindow    *mainwin,
433                                   guint          action,
434                                   GtkWidget     *widget);
435
436 static void copy_cb              (MainWindow    *mainwin,
437                                   guint          action,
438                                   GtkWidget     *widget);
439 static void allsel_cb            (MainWindow    *mainwin,
440                                   guint          action,
441                                   GtkWidget     *widget);
442 static void select_thread_cb     (MainWindow    *mainwin,
443                                   guint          action,
444                                   GtkWidget     *widget);
445
446 static void create_filter_cb     (MainWindow    *mainwin,
447                                   guint          action,
448                                   GtkWidget     *widget);
449
450 static void prefs_common_open_cb        (MainWindow     *mainwin,
451                                          guint           action,
452                                          GtkWidget      *widget);
453 static void prefs_template_open_cb      (MainWindow     *mainwin,
454                                          guint           action,
455                                          GtkWidget      *widget);
456 static void prefs_actions_open_cb       (MainWindow     *mainwin,
457                                          guint           action,
458                                          GtkWidget      *widget);
459 static void prefs_account_open_cb       (MainWindow     *mainwin,
460                                          guint           action,
461                                          GtkWidget      *widget);
462 static void prefs_scoring_open_cb       (MainWindow     *mainwin,
463                                          guint           action,
464                                          GtkWidget      *widget);
465 static void prefs_filtering_open_cb     (MainWindow     *mainwin,
466                                          guint           action,
467                                          GtkWidget      *widget);
468 #ifdef USE_OPENSSL
469 static void ssl_manager_open_cb         (MainWindow     *mainwin,
470                                          guint           action,
471                                          GtkWidget      *widget);
472 #endif
473 static void new_account_cb       (MainWindow    *mainwin,
474                                   guint          action,
475                                   GtkWidget     *widget);
476
477 static void account_menu_cb      (GtkMenuItem   *menuitem,
478                                   gpointer       data);
479
480 static void online_switch_clicked(GtkButton     *btn, 
481                                   gpointer data);
482
483 static void manual_open_cb       (MainWindow    *mainwin,
484                                   guint          action,
485                                   GtkWidget     *widget);
486
487 static void scan_tree_func       (Folder        *folder,
488                                   FolderItem    *item,
489                                   gpointer       data);
490                                   
491 static void key_pressed (GtkWidget *widget, 
492                                 GdkEventKey *event,
493                                 gpointer data);
494
495 static void toggle_work_offline_cb(MainWindow *mainwin, guint action, GtkWidget *widget);
496
497 static void addr_harvest_cb      ( MainWindow  *mainwin,
498                                    guint       action,
499                                    GtkWidget   *widget );
500
501 static void addr_harvest_msg_cb  ( MainWindow  *mainwin,
502                                    guint       action,
503                                    GtkWidget   *widget );
504
505 #define  SEPARATE_ACTION 500 
506
507 static GtkItemFactoryEntry mainwin_entries[] =
508 {
509         {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
510         {N_("/_File/_Add mailbox..."),          NULL, add_mailbox_cb, 0, NULL},
511         {N_("/_File/_Add mbox mailbox..."),     NULL, add_mbox_cb, 0, NULL},
512         {N_("/_File/_Check for new messages in all folders"),
513                                                 NULL, update_folderview_cb, 0, NULL},
514         {N_("/_File/_Folder"),                  NULL, NULL, 0, "<Branch>"},
515         {N_("/_File/_Folder/Create _new folder..."),
516                                                 NULL, new_folder_cb, 0, NULL},
517         {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
518         {N_("/_File/_Folder/_Delete folder"),   NULL, delete_folder_cb, 0, NULL},
519         {N_("/_File/_Import mbox file..."),     NULL, import_mbox_cb, 0, NULL},
520         {N_("/_File/_Export to mbox file..."),  NULL, export_mbox_cb, 0, NULL},
521         {N_("/_File/Empty _trash"),             "<shift>D", empty_trash_cb, 0, NULL},
522         {N_("/_File/_Work offline"),            "<control>W", toggle_work_offline_cb, 0, "<ToggleItem>"},                                               
523         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
524         {N_("/_File/_Save as..."),              "<control>S", save_as_cb, 0, NULL},
525         {N_("/_File/_Print..."),                NULL, print_cb, 0, NULL},
526         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
527         /* {N_("/_File/_Close"),                "<alt>W", app_exit_cb, 0, NULL}, */
528         {N_("/_File/E_xit"),                    "<control>Q", app_exit_cb, 0, NULL},
529
530         {N_("/_Edit"),                          NULL, NULL, 0, "<Branch>"},
531         {N_("/_Edit/_Copy"),                    "<control>C", copy_cb, 0, NULL},
532         {N_("/_Edit/Select _all"),              "<control>A", allsel_cb, 0, NULL},
533         {N_("/_Edit/Select _thread"),           NULL, select_thread_cb, 0, NULL},
534         {N_("/_Edit/---"),                      NULL, NULL, 0, "<Separator>"},
535         {N_("/_Edit/_Find in current message..."),
536                                                 "<control>F", search_cb, 0, NULL},
537         {N_("/_Edit/_Search folder..."),        "<shift><control>F", search_cb, 1, NULL},
538         {N_("/_View"),                          NULL, NULL, 0, "<Branch>"},
539         {N_("/_View/Show or hi_de"),            NULL, NULL, 0, "<Branch>"},
540         {N_("/_View/Show or hi_de/_Folder tree"),
541                                                 NULL, toggle_folder_cb, 0, "<ToggleItem>"},
542         {N_("/_View/Show or hi_de/_Message view"),
543                                                 "V", toggle_message_cb, 0, "<ToggleItem>"},
544         {N_("/_View/Show or hi_de/_Toolbar"),
545                                                 NULL, NULL, 0, "<Branch>"},
546         {N_("/_View/Show or hi_de/_Toolbar/Icon _and text"),
547                                                 NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
548         {N_("/_View/Show or hi_de/_Toolbar/_Icon"),
549                                                 NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Show or hide/Toolbar/Icon and text"},
550         {N_("/_View/Show or hi_de/_Toolbar/_Text"),
551                                                 NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Show or hide/Toolbar/Icon and text"},
552         {N_("/_View/Show or hi_de/_Toolbar/_None"),
553                                                 NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Show or hide/Toolbar/Icon and text"},
554         {N_("/_View/Show or hi_de/Status _bar"),
555                                                 NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
556         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
557         {N_("/_View/Separate f_older tree"),    NULL, separate_widget_cb, SEPARATE_FOLDER, "<ToggleItem>"},
558         {N_("/_View/Separate m_essage view"),   NULL, separate_widget_cb, SEPARATE_MESSAGE, "<ToggleItem>"},
559         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
560         {N_("/_View/_Sort"),                    NULL, NULL, 0, "<Branch>"},
561         {N_("/_View/_Sort/by _number"),         NULL, sort_summary_cb, SORT_BY_NUMBER, "<RadioItem>"},
562         {N_("/_View/_Sort/by s_ize"),           NULL, sort_summary_cb, SORT_BY_SIZE, "/View/Sort/by number"},
563         {N_("/_View/_Sort/by _date"),           NULL, sort_summary_cb, SORT_BY_DATE, "/View/Sort/by number"},
564         {N_("/_View/_Sort/by _from"),           NULL, sort_summary_cb, SORT_BY_FROM, "/View/Sort/by number"},
565         {N_("/_View/_Sort/by _subject"),        NULL, sort_summary_cb, SORT_BY_SUBJECT, "/View/Sort/by number"},
566         {N_("/_View/_Sort/by _color label"),
567                                                 NULL, sort_summary_cb, SORT_BY_LABEL, "/View/Sort/by number"},
568         {N_("/_View/_Sort/by _mark"),           NULL, sort_summary_cb, SORT_BY_MARK, "/View/Sort/by number"},
569         {N_("/_View/_Sort/by _unread"),         NULL, sort_summary_cb, SORT_BY_UNREAD, "/View/Sort/by number"},
570         {N_("/_View/_Sort/by a_ttachment"),
571                                                 NULL, sort_summary_cb, SORT_BY_MIME, "/View/Sort/by number"},
572         {N_("/_View/_Sort/by score"),           NULL, sort_summary_cb, SORT_BY_SCORE, "/View/Sort/by number"},
573         {N_("/_View/_Sort/by locked"),          NULL, sort_summary_cb, SORT_BY_LOCKED, "/View/Sort/by number"},
574         {N_("/_View/_Sort/D_on't sort"),        NULL, sort_summary_cb, SORT_BY_NONE, "/View/Sort/by number"},
575         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
576         {N_("/_View/_Sort/Ascending"),          NULL, sort_summary_type_cb, SORT_ASCENDING, "<RadioItem>"},
577         {N_("/_View/_Sort/Descending"),         NULL, sort_summary_type_cb, SORT_DESCENDING, "/View/Sort/Ascending"},
578         {N_("/_View/_Sort/---"),                NULL, NULL, 0, "<Separator>"},
579         {N_("/_View/_Sort/_Attract by subject"),
580                                                 NULL, attract_by_subject_cb, 0, NULL},
581         {N_("/_View/Th_read view"),             "<control>T", thread_cb, 0, "<ToggleItem>"},
582         {N_("/_View/E_xpand all threads"),      NULL, expand_threads_cb, 0, NULL},
583         {N_("/_View/Co_llapse all threads"),    NULL, collapse_threads_cb, 0, NULL},
584         {N_("/_View/_Hide read messages"),      NULL, hide_read_messages, 0, "<ToggleItem>"},
585         {N_("/_View/Set displayed _items..."),  NULL, set_display_item_cb, 0, NULL},
586
587         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
588         {N_("/_View/_Go to"),                   NULL, NULL, 0, "<Branch>"},
589         {N_("/_View/_Go to/_Prev message"),     "P", prev_cb, 0, NULL},
590         {N_("/_View/_Go to/_Next message"),     "N", next_cb, 0, NULL},
591         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
592         {N_("/_View/_Go to/P_rev unread message"),
593                                                 "<shift>P", prev_unread_cb, 0, NULL},
594         {N_("/_View/_Go to/N_ext unread message"),
595                                                 "<shift>N", next_unread_cb, 0, NULL},
596         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
597         {N_("/_View/_Go to/Prev ne_w message"), NULL, prev_new_cb, 0, NULL},
598         {N_("/_View/_Go to/Ne_xt new message"), NULL, next_new_cb, 0, NULL},
599         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
600         {N_("/_View/_Go to/Prev _marked message"),
601                                                 NULL, prev_marked_cb, 0, NULL},
602         {N_("/_View/_Go to/Next m_arked message"),
603                                                 NULL, next_marked_cb, 0, NULL},
604         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
605         {N_("/_View/_Go to/Prev _labeled message"),
606                                                 NULL, prev_labeled_cb, 0, NULL},
607         {N_("/_View/_Go to/Next la_beled message"),
608                                                 NULL, next_labeled_cb, 0, NULL},
609         {N_("/_View/_Go to/---"),               NULL, NULL, 0, "<Separator>"},
610         {N_("/_View/_Go to/Other _folder..."),  "G", goto_folder_cb, 0, NULL},
611         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
612
613 #define CODESET_SEPARATOR \
614         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"}
615 #define CODESET_ACTION(action) \
616          NULL, set_charset_cb, action, "/View/Code set/Auto detect"
617
618         {N_("/_View/_Code set"),                NULL, NULL, 0, "<Branch>"},
619         {N_("/_View/_Code set/_Auto detect"),
620          NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
621         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"},
622         {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
623          CODESET_ACTION(C_US_ASCII)},
624
625 #if HAVE_LIBJCONV
626         {N_("/_View/_Code set/Unicode (_UTF-8)"),
627          CODESET_ACTION(C_UTF_8)},
628         CODESET_SEPARATOR,
629 #endif
630         {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
631          CODESET_ACTION(C_ISO_8859_1)},
632         {N_("/_View/_Code set/Western European (ISO-8859-15)"),
633          CODESET_ACTION(C_ISO_8859_15)},
634         CODESET_SEPARATOR,
635 #if HAVE_LIBJCONV
636         {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
637          CODESET_ACTION(C_ISO_8859_2)},
638         CODESET_SEPARATOR,
639         {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
640          CODESET_ACTION(C_ISO_8859_13)},
641         {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
642          CODESET_ACTION(C_ISO_8859_4)},
643         CODESET_SEPARATOR,
644         {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
645          CODESET_ACTION(C_ISO_8859_7)},
646         CODESET_SEPARATOR,
647         {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
648          CODESET_ACTION(C_ISO_8859_9)},
649         CODESET_SEPARATOR,
650         {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
651          CODESET_ACTION(C_ISO_8859_5)},
652         {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
653          CODESET_ACTION(C_KOI8_R)},
654         {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
655          CODESET_ACTION(C_WINDOWS_1251)},
656         CODESET_SEPARATOR,
657 #endif
658         {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
659          CODESET_ACTION(C_ISO_2022_JP)},
660 #if HAVE_LIBJCONV
661         {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
662          CODESET_ACTION(C_ISO_2022_JP_2)},
663 #endif
664         {N_("/_View/_Code set/Japanese (_EUC-JP)"),
665          CODESET_ACTION(C_EUC_JP)},
666         {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
667          CODESET_ACTION(C_SHIFT_JIS)},
668 #if HAVE_LIBJCONV
669         CODESET_SEPARATOR,
670         {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
671          CODESET_ACTION(C_GB2312)},
672         {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
673          CODESET_ACTION(C_BIG5)},
674         {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
675          CODESET_ACTION(C_EUC_TW)},
676         {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
677          CODESET_ACTION(C_ISO_2022_CN)},
678         CODESET_SEPARATOR,
679         {N_("/_View/_Code set/Korean (EUC-_KR)"),
680          CODESET_ACTION(C_EUC_KR)},
681         {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
682          CODESET_ACTION(C_ISO_2022_KR)},
683         CODESET_SEPARATOR,
684         {N_("/_View/_Code set/Thai (TIS-620)"),
685          CODESET_ACTION(C_TIS_620)},
686         {N_("/_View/_Code set/Thai (Windows-874)"),
687          CODESET_ACTION(C_WINDOWS_874)},
688 #endif
689
690 #undef CODESET_SEPARATOR
691 #undef CODESET_ACTION
692
693         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
694         {N_("/_View/Open in new _window"),      "<control><alt>N", open_msg_cb, 0, NULL},
695         {N_("/_View/Mess_age source"),          "<control>U", view_source_cb, 0, NULL},
696         {N_("/_View/Show all _headers"),        "<control>H", show_all_header_cb, 0, "<ToggleItem>"},
697         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
698         {N_("/_View/_Update summary"),          "<control><alt>U", update_summary_cb,  0, NULL},
699
700         {N_("/_Message"),                       NULL, NULL, 0, "<Branch>"},
701         {N_("/_Message/Get new ma_il"),         "<control>I",   inc_mail_cb, 0, NULL},
702         {N_("/_Message/Get from _all accounts"),
703                                                 "<shift><control>I", inc_all_account_mail_cb, 0, NULL},
704         {N_("/_Message/Cancel receivin_g"),     NULL, inc_cancel_cb, 0, NULL},
705         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
706         {N_("/_Message/_Send queued messages"), NULL, send_queue_cb, 0, NULL},
707         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
708         {N_("/_Message/Compose a_n email message"),     "<control>M", compose_mail_cb, 0, NULL},
709         {N_("/_Message/Compose a news message"),        NULL,   compose_news_cb, 0, NULL},
710         {N_("/_Message/_Reply"),                "<control>R",   reply_cb, COMPOSE_REPLY, NULL},
711         {N_("/_Message/Repl_y to"),             NULL, NULL, 0, "<Branch>"},
712         {N_("/_Message/Repl_y to/_all"),        "<shift><control>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
713         {N_("/_Message/Repl_y to/_sender"),     NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
714         {N_("/_Message/Repl_y to/mailing _list"),
715                                                 "<control>L", reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
716         {N_("/_Message/Follow-up and reply to"),NULL, reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
717         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
718         {N_("/_Message/_Forward"),              "<control><alt>F", reply_cb, COMPOSE_FORWARD, NULL},
719         {N_("/_Message/Redirect"),              NULL, reply_cb, COMPOSE_REDIRECT, NULL},
720         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
721         {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
722         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
723         {N_("/_Message/M_ove..."),              "<control>O", move_to_cb, 0, NULL},
724         {N_("/_Message/_Copy..."),              "<shift><control>O", copy_to_cb, 0, NULL},
725         {N_("/_Message/_Delete"),               "<control>D", delete_cb,  0, NULL},
726         {N_("/_Message/Cancel a news message"), "", cancel_cb,  0, NULL},
727         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
728         {N_("/_Message/_Mark"),                 NULL, NULL, 0, "<Branch>"},
729         {N_("/_Message/_Mark/_Mark"),           "<shift>asterisk", mark_cb, 0, NULL},
730         {N_("/_Message/_Mark/_Unmark"),         "U", unmark_cb, 0, NULL},
731         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
732         {N_("/_Message/_Mark/Mark as unr_ead"), "<shift>exclam", mark_as_unread_cb, 0, NULL},
733         {N_("/_Message/_Mark/Mark as rea_d"),
734                                                 NULL, mark_as_read_cb, 0, NULL},
735         {N_("/_Message/_Mark/Mark all _read"),  NULL, mark_all_read_cb, 0, NULL},
736
737         {N_("/_Tools"),                         NULL, NULL, 0, "<Branch>"},
738         {N_("/_Tools/_Selective download..."),  "<alt>S", sel_download_cb, 0, NULL},
739         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
740         {N_("/_Tools/_Address book..."),        "<shift><control>A", addressbook_open_cb, 0, NULL},
741         {N_("/_Tools/Add sender to address boo_k"),
742                                                 NULL, add_address_cb, 0, NULL},
743         {N_("/_Tools/_Harvest addresses"),      NULL, NULL, 0, "<Branch>"},
744         {N_("/_Tools/_Harvest addresses/from _Folder..."),
745                                                 NULL, addr_harvest_cb, 0, NULL},
746         {N_("/_Tools/_Harvest addresses/from _Messages..."),
747                                                 NULL, addr_harvest_msg_cb, 0, NULL},
748         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
749         {N_("/_Tools/_Filter messages"),                NULL, filter_cb, 0, NULL},
750         {N_("/_Tools/_Create filter rule"),     NULL, NULL, 0, "<Branch>"},
751         {N_("/_Tools/_Create filter rule/_Automatically"),
752                                                 NULL, create_filter_cb, FILTER_BY_AUTO, NULL},
753         {N_("/_Tools/_Create filter rule/by _From"),
754                                                 NULL, create_filter_cb, FILTER_BY_FROM, NULL},
755         {N_("/_Tools/_Create filter rule/by _To"),
756                                                 NULL, create_filter_cb, FILTER_BY_TO, NULL},
757         {N_("/_Tools/_Create filter rule/by _Subject"),
758                                                 NULL, create_filter_cb, FILTER_BY_SUBJECT, NULL},
759         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
760         {N_("/_Tools/Actio_ns"),                NULL, NULL, 0, "<Branch>"},
761         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
762         {N_("/_Tools/Delete du_plicated messages"),
763                                                 NULL, delete_duplicated_cb,   0, NULL},
764         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
765         {N_("/_Tools/E_xecute"),                "X", execute_summary_cb, 0, NULL},
766 #ifdef USE_OPENSSL
767         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
768         {N_("/_Tools/SSL certi_ficates..."),    
769                                                 NULL, ssl_manager_open_cb, 0, NULL},
770 #endif
771         {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
772         {N_("/_Tools/_Log window"),             "<shift><control>L", log_window_show_cb, 0, NULL},
773
774         {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
775         {N_("/_Configuration/_Common preferences..."),
776                                                 NULL, prefs_common_open_cb, 0, NULL},
777         {N_("/_Configuration/C_ustomize toolbars"),
778                                                 NULL, NULL, 0, "<Branch>"},
779         {N_("/_Configuration/C_ustomize toolbars/_Main window..."),
780                                                 NULL, prefs_toolbar_cb, TOOLBAR_MAIN, NULL},
781         {N_("/_Configuration/C_ustomize toolbars/_Compose window..."),
782                                                 NULL, prefs_toolbar_cb, TOOLBAR_COMPOSE, NULL},
783         {N_("/_Configuration/C_ustomize toolbars/M_essage view..."),
784                                                 NULL, prefs_toolbar_cb, TOOLBAR_MSGVIEW, NULL},
785         {N_("/_Configuration/_Scoring..."),
786                                                 NULL, prefs_scoring_open_cb, 0, NULL},
787         {N_("/_Configuration/_Filtering..."),
788                                                 NULL, prefs_filtering_open_cb, 0, NULL},
789         {N_("/_Configuration/_Templates..."),   NULL, prefs_template_open_cb, 0, NULL},
790         {N_("/_Configuration/_Actions..."),     NULL, prefs_actions_open_cb, 0, NULL},
791         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
792         {N_("/_Configuration/_Preferences for current account..."),
793                                                 NULL, prefs_account_open_cb, 0, NULL},
794         {N_("/_Configuration/Create _new account..."),
795                                                 NULL, new_account_cb, 0, NULL},
796         {N_("/_Configuration/_Edit accounts..."),
797                                                 NULL, account_edit_open, 0, NULL},
798         {N_("/_Configuration/C_hange current account"),
799                                                 NULL, NULL, 0, "<Branch>"},
800
801         {N_("/_Help"),                          NULL, NULL, 0, "<Branch>"},
802         {N_("/_Help/_Manual (Local)"),          NULL, manual_open_cb, MANUAL_MANUAL_LOCAL, NULL},
803         {N_("/_Help/_Manual (Sylpheed Doc Homepage)"),
804                                                 NULL, manual_open_cb, MANUAL_MANUAL_SYLDOC, NULL},
805         {N_("/_Help/_FAQ (Local)"),             NULL, manual_open_cb, MANUAL_FAQ_LOCAL, NULL},
806         {N_("/_Help/_FAQ (Sylpheed Doc Homepage)"),
807                                                 NULL, manual_open_cb, MANUAL_FAQ_SYLDOC, NULL},
808         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
809         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
810 };
811
812
813
814 static GtkItemFactoryEntry reply_popup_entries[] =
815 {
816         {N_("/Reply with _quote"), NULL, reply_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
817         {N_("/_Reply without quote"), NULL, reply_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
818 };
819 static GtkItemFactoryEntry replyall_popup_entries[] =
820 {
821         {N_("/Reply to all with _quote"), "<shift>A", reply_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
822         {N_("/_Reply to all without quote"), "a", reply_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
823 };
824 static GtkItemFactoryEntry replylist_popup_entries[] =
825 {
826         {N_("/Reply to list with _quote"), NULL, reply_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
827         {N_("/_Reply to list without quote"), NULL, reply_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
828 };
829 static GtkItemFactoryEntry replysender_popup_entries[] =
830 {
831         {N_("/Reply to sender with _quote"), NULL, reply_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
832         {N_("/_Reply to sender without quote"), NULL, reply_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
833 };
834 static GtkItemFactoryEntry fwd_popup_entries[] =
835 {
836         {N_("/_Forward message (inline style)"), "f", reply_cb, COMPOSE_FORWARD_INLINE, NULL},
837         {N_("/Forward message as _attachment"), "<shift>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
838 };
839
840 MainWindow *main_window_create(SeparateType type)
841 {
842         MainWindow *mainwin;
843         GtkWidget *window;
844         GtkWidget *vbox;
845         GtkWidget *menubar;
846         GtkWidget *handlebox;
847         GtkWidget *vbox_body;
848         GtkWidget *hbox_stat;
849         GtkWidget *statusbar;
850         GtkWidget *progressbar;
851         GtkWidget *statuslabel;
852         GtkWidget *ac_button;
853         GtkWidget *ac_label;
854         GtkWidget *online_pixmap;
855         GtkWidget *offline_pixmap;
856         GtkWidget *online_switch;
857         GtkWidget *offline_switch;
858
859         FolderView *folderview;
860         SummaryView *summaryview;
861         MessageView *messageview;
862         GdkColormap *colormap;
863         GdkColor color[4];
864         gboolean success[4];
865         GtkItemFactory *ifactory;
866         GtkWidget *ac_menu;
867         GtkWidget *menuitem;
868         gint i;
869         guint n_menu_entries;
870
871         static GdkGeometry geometry;
872
873         debug_print("Creating main window...\n");
874         mainwin = g_new0(MainWindow, 1);
875
876         /* main window */
877         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
878         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
879         gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
880         gtk_window_set_wmclass(GTK_WINDOW(window), "main_window", "Sylpheed");
881
882         if (!geometry.min_height) {
883                 geometry.min_width = 320;
884                 geometry.min_height = 200;
885         }
886         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
887                                       GDK_HINT_MIN_SIZE);
888
889         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
890                            GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
891         MANAGE_WINDOW_SIGNALS_CONNECT(window);
892         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
893                                 GTK_SIGNAL_FUNC(key_pressed), mainwin);
894
895         gtk_widget_realize(window);
896         gtk_widget_add_events(window, GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK);
897         
898
899         gtkut_widget_set_app_icon(window);
900
901         vbox = gtk_vbox_new(FALSE, 0);
902         gtk_widget_show(vbox);
903         gtk_container_add(GTK_CONTAINER(window), vbox);
904
905         /* menu bar */
906         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
907         menubar = menubar_create(window, mainwin_entries, 
908                                  n_menu_entries, "<Main>", mainwin);
909         gtk_widget_show(menubar);
910         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
911         ifactory = gtk_item_factory_from_widget(menubar);
912
913         menu_set_sensitive(ifactory, "/Help/Manual (Local)", manual_available(MANUAL_MANUAL_LOCAL));
914         menu_set_sensitive(ifactory, "/Help/FAQ (Local)", manual_available(MANUAL_FAQ_LOCAL));
915
916         handlebox = gtk_handle_box_new();
917         gtk_widget_show(handlebox);
918         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
919
920         /* link window to mainwin->window to avoid gdk warnings */
921         mainwin->window       = window;
922         
923         /* create toolbar */
924         toolbar_create(mainwin, handlebox);
925
926         /* vbox that contains body */
927         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
928         gtk_widget_show(vbox_body);
929         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
930         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
931
932         hbox_stat = gtk_hbox_new(FALSE, 2);
933         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
934
935         statusbar = statusbar_create();
936         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
937
938         progressbar = gtk_progress_bar_new();
939         gtk_widget_set_usize(progressbar, 120, 1);
940         gtk_box_pack_start(GTK_BOX(hbox_stat), progressbar, FALSE, FALSE, 0);
941
942         online_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_WORK_ONLINE);
943         offline_pixmap = stock_pixmap_widget(hbox_stat, STOCK_PIXMAP_WORK_OFFLINE);
944         online_switch = gtk_button_new ();
945         offline_switch = gtk_button_new ();
946         gtk_container_add (GTK_CONTAINER(online_switch), online_pixmap);
947         gtk_button_set_relief (GTK_BUTTON(online_switch), GTK_RELIEF_NONE);
948         gtk_signal_connect (GTK_OBJECT(online_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
949         gtk_box_pack_start (GTK_BOX(hbox_stat), online_switch, FALSE, FALSE, 0);
950         gtk_container_add (GTK_CONTAINER(offline_switch), offline_pixmap);
951         gtk_button_set_relief (GTK_BUTTON(offline_switch), GTK_RELIEF_NONE);
952         gtk_signal_connect (GTK_OBJECT(offline_switch), "clicked", (GtkSignalFunc)online_switch_clicked, mainwin);
953         gtk_box_pack_start (GTK_BOX(hbox_stat), offline_switch, FALSE, FALSE, 0);
954         
955         statuslabel = gtk_label_new("");
956         gtk_box_pack_start(GTK_BOX(hbox_stat), statuslabel, FALSE, FALSE, 0);
957
958         ac_button = gtk_button_new();
959         gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
960         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
961         gtk_widget_set_usize(ac_button, -1, 1);
962         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
963         gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
964                            GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
965
966         ac_label = gtk_label_new("");
967         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
968
969         gtk_widget_show_all(hbox_stat);
970
971         gtk_widget_hide(offline_switch);
972         /* create views */
973         mainwin->folderview  = folderview  = folderview_create();
974         mainwin->summaryview = summaryview = summary_create();
975         mainwin->messageview = messageview = messageview_create(mainwin);
976         mainwin->logwin      = log_window_create();
977
978         folderview->mainwin      = mainwin;
979         folderview->summaryview  = summaryview;
980
981         summaryview->mainwin     = mainwin;
982         summaryview->folderview  = folderview;
983         summaryview->messageview = messageview;
984         summaryview->window      = window;
985
986         mainwin->vbox         = vbox;
987         mainwin->menubar      = menubar;
988         mainwin->menu_factory = ifactory;
989         mainwin->handlebox    = handlebox;
990         mainwin->vbox_body    = vbox_body;
991         mainwin->hbox_stat    = hbox_stat;
992         mainwin->statusbar    = statusbar;
993         mainwin->progressbar  = progressbar;
994         mainwin->statuslabel  = statuslabel;
995         mainwin->ac_button    = ac_button;
996         mainwin->ac_label     = ac_label;
997         
998         mainwin->online_switch     = online_switch;
999         mainwin->offline_switch    = offline_switch;
1000         mainwin->online_pixmap     = online_pixmap;
1001         mainwin->offline_pixmap    = offline_pixmap;
1002         
1003         /* set context IDs for status bar */
1004         mainwin->mainwin_cid = gtk_statusbar_get_context_id
1005                 (GTK_STATUSBAR(statusbar), "Main Window");
1006         mainwin->folderview_cid = gtk_statusbar_get_context_id
1007                 (GTK_STATUSBAR(statusbar), "Folder View");
1008         mainwin->summaryview_cid = gtk_statusbar_get_context_id
1009                 (GTK_STATUSBAR(statusbar), "Summary View");
1010
1011         /* allocate colors for summary view and folder view */
1012         summaryview->color_marked.red = summaryview->color_marked.green = 0;
1013         summaryview->color_marked.blue = (guint16)65535;
1014
1015         summaryview->color_dim.red = summaryview->color_dim.green =
1016                 summaryview->color_dim.blue = COLOR_DIM;
1017
1018         folderview->color_new.red = (guint16)55000;
1019         folderview->color_new.green = folderview->color_new.blue = 15000;
1020
1021         gtkut_convert_int_to_gdk_color(prefs_common.tgt_folder_col,
1022                                        &folderview->color_op);
1023
1024         summaryview->color_important.red = 0;
1025         summaryview->color_important.green = 0;
1026         summaryview->color_important.blue = (guint16)65535;
1027
1028         color[0] = summaryview->color_marked;
1029         color[1] = summaryview->color_dim;
1030         color[2] = folderview->color_new;
1031         color[3] = folderview->color_op;
1032
1033         colormap = gdk_window_get_colormap(window->window);
1034         gdk_colormap_alloc_colors(colormap, color, 4, FALSE, TRUE, success);
1035         for (i = 0; i < 4; i++) {
1036                 if (success[i] == FALSE)
1037                         g_warning("MainWindow: color allocation %d failed\n", i);
1038         }
1039
1040         debug_print("done.\n");
1041
1042         messageview->visible = TRUE;
1043
1044         main_window_set_widgets(mainwin, type);
1045
1046         /* set menu items */
1047         menuitem = gtk_item_factory_get_item
1048                 (ifactory, "/View/Code set/Auto detect");
1049         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1050
1051         switch (prefs_common.toolbar_style) {
1052         case TOOLBAR_NONE:
1053                 menuitem = gtk_item_factory_get_item
1054                         (ifactory, "/View/Show or hide/Toolbar/None");
1055                 break;
1056         case TOOLBAR_ICON:
1057                 menuitem = gtk_item_factory_get_item
1058                         (ifactory, "/View/Show or hide/Toolbar/Icon");
1059                 break;
1060         case TOOLBAR_TEXT:
1061                 menuitem = gtk_item_factory_get_item
1062                         (ifactory, "/View/Show or hide/Toolbar/Text");
1063                 break;
1064         case TOOLBAR_BOTH:
1065                 menuitem = gtk_item_factory_get_item
1066                         (ifactory, "/View/Show or hide/Toolbar/Icon and text");
1067         }
1068         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1069
1070         gtk_widget_hide(mainwin->hbox_stat);
1071         menuitem = gtk_item_factory_get_item
1072                 (ifactory, "/View/Show or hide/Status bar");
1073         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1074                                        prefs_common.show_statusbar);
1075         
1076         gtk_widget_hide(GTK_WIDGET(mainwin->summaryview->hbox_search));
1077         
1078         if (prefs_common.show_searchbar)
1079                 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mainwin->summaryview->toggle_search), TRUE);
1080
1081
1082         /* set account selection menu */
1083         ac_menu = gtk_item_factory_get_widget
1084                 (ifactory, "/Configuration/Change current account");
1085         gtk_signal_connect(GTK_OBJECT(ac_menu), "selection_done",
1086                            GTK_SIGNAL_FUNC(ac_menu_popup_closed), mainwin);
1087         mainwin->ac_menu = ac_menu;
1088
1089         toolbar_set_sensitive(mainwin);
1090
1091         /* create actions menu */
1092         update_mainwin_actions_menu(ifactory, mainwin);
1093
1094         /* show main window */
1095         gtk_widget_set_uposition(mainwin->window,
1096                                  prefs_common.mainwin_x,
1097                                  prefs_common.mainwin_y);
1098         gtk_widget_set_usize(window, prefs_common.mainwin_width,
1099                              prefs_common.mainwin_height);
1100         gtk_widget_show(mainwin->window);
1101
1102         /* initialize views */
1103         folderview_init(folderview);
1104         summary_init(summaryview);
1105         messageview_init(messageview);
1106         log_window_init(mainwin->logwin);
1107 #ifdef USE_OPENSSL
1108         sslcertwindow_register_hook();
1109 #endif
1110         mainwin->lock_count = 0;
1111         mainwin->menu_lock_count = 0;
1112         mainwin->cursor_count = 0;
1113
1114         if (!watch_cursor)
1115                 watch_cursor = gdk_cursor_new(GDK_WATCH);
1116
1117         mainwin_list = g_list_append(mainwin_list, mainwin);
1118
1119         /* init work_offline */
1120         if (prefs_common.work_offline)
1121                 online_switch_clicked (GTK_BUTTON(online_switch), mainwin);
1122
1123         return mainwin;
1124 }
1125
1126 void main_window_cursor_wait(MainWindow *mainwin)
1127 {
1128
1129         if (mainwin->cursor_count == 0)
1130                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
1131
1132         mainwin->cursor_count++;
1133
1134         gdk_flush();
1135 }
1136
1137 void main_window_cursor_normal(MainWindow *mainwin)
1138 {
1139         if (mainwin->cursor_count)
1140                 mainwin->cursor_count--;
1141
1142         if (mainwin->cursor_count == 0)
1143                 gdk_window_set_cursor(mainwin->window->window, NULL);
1144
1145         gdk_flush();
1146 }
1147
1148 /* lock / unlock the user-interface */
1149 void main_window_lock(MainWindow *mainwin)
1150 {
1151         if (mainwin->lock_count == 0)
1152                 gtk_widget_set_sensitive(mainwin->ac_button, FALSE);
1153
1154         mainwin->lock_count++;
1155
1156         main_window_set_menu_sensitive(mainwin);
1157         toolbar_set_sensitive(mainwin);
1158 }
1159
1160 void main_window_unlock(MainWindow *mainwin)
1161 {
1162         if (mainwin->lock_count)
1163                 mainwin->lock_count--;
1164
1165         main_window_set_menu_sensitive(mainwin);
1166         toolbar_set_sensitive(mainwin);
1167
1168         if (mainwin->lock_count == 0)
1169                 gtk_widget_set_sensitive(mainwin->ac_button, TRUE);
1170 }
1171
1172 static void main_window_menu_callback_block(MainWindow *mainwin)
1173 {
1174         mainwin->menu_lock_count++;
1175 }
1176
1177 static void main_window_menu_callback_unblock(MainWindow *mainwin)
1178 {
1179         if (mainwin->menu_lock_count)
1180                 mainwin->menu_lock_count--;
1181 }
1182
1183 void main_window_reflect_prefs_all(void)
1184 {
1185         main_window_reflect_prefs_all_real(FALSE);
1186 }
1187
1188 void main_window_reflect_prefs_all_real(gboolean pixmap_theme_changed)
1189 {
1190         GList *cur;
1191         MainWindow *mainwin;
1192         GtkWidget *pixmap;
1193
1194         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1195                 mainwin = (MainWindow *)cur->data;
1196
1197                 main_window_show_cur_account(mainwin);
1198                 main_window_set_menu_sensitive(mainwin);
1199                 toolbar_set_sensitive(mainwin);
1200
1201                 /* pixmap themes */
1202                 if (pixmap_theme_changed) {
1203                         toolbar_update(mainwin);
1204                         common_toolbar_set_style(mainwin, TOOLBAR_MAIN);
1205                         folderview_reflect_prefs_pixmap_theme(mainwin->folderview);
1206                         summary_reflect_prefs_pixmap_theme(mainwin->summaryview);
1207
1208                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_WORK_ONLINE);
1209                         gtk_container_remove(GTK_CONTAINER(mainwin->online_switch), 
1210                                              mainwin->online_pixmap);
1211                         gtk_container_add (GTK_CONTAINER(mainwin->online_switch), pixmap);
1212                         gtk_widget_show(pixmap);
1213                         mainwin->online_pixmap = pixmap;
1214                         pixmap = stock_pixmap_widget(mainwin->hbox_stat, STOCK_PIXMAP_WORK_OFFLINE);
1215                         gtk_container_remove(GTK_CONTAINER(mainwin->offline_switch), 
1216                                              mainwin->offline_pixmap);
1217                         gtk_container_add (GTK_CONTAINER(mainwin->offline_switch), pixmap);
1218                         gtk_widget_show(pixmap);
1219                         mainwin->offline_pixmap = pixmap;
1220                 }
1221                 
1222                 summary_redisplay_msg(mainwin->summaryview);
1223                 headerview_set_visibility(mainwin->messageview->headerview,
1224                                           prefs_common.display_header_pane);
1225         }
1226 }
1227
1228 void main_window_set_summary_column(void)
1229 {
1230         GList *cur;
1231         MainWindow *mainwin;
1232
1233         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1234                 mainwin = (MainWindow *)cur->data;
1235                 summary_set_column_order(mainwin->summaryview);
1236         }
1237 }
1238
1239 void main_window_set_account_menu(GList *account_list)
1240 {
1241         GList *cur, *cur_ac, *cur_item;
1242         GtkWidget *menuitem;
1243         MainWindow *mainwin;
1244         PrefsAccount *ac_prefs;
1245
1246         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
1247                 mainwin = (MainWindow *)cur->data;
1248
1249                 /* destroy all previous menu item */
1250                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
1251                 while (cur_item != NULL) {
1252                         GList *next = cur_item->next;
1253                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
1254                         cur_item = next;
1255                 }
1256
1257                 for (cur_ac = account_list; cur_ac != NULL;
1258                      cur_ac = cur_ac->next) {
1259                         ac_prefs = (PrefsAccount *)cur_ac->data;
1260
1261                         menuitem = gtk_menu_item_new_with_label
1262                                 (ac_prefs->account_name
1263                                  ? ac_prefs->account_name : _("Untitled"));
1264                         gtk_widget_show(menuitem);
1265                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
1266                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
1267                                            GTK_SIGNAL_FUNC(account_menu_cb),
1268                                            ac_prefs);
1269                 }
1270         }
1271 }
1272
1273 static void main_window_show_cur_account(MainWindow *mainwin)
1274 {
1275         gchar *buf;
1276         gchar *ac_name;
1277
1278         ac_name = g_strdup(cur_account
1279                            ? (cur_account->account_name
1280                               ? cur_account->account_name : _("Untitled"))
1281                            : _("none"));
1282
1283         if (cur_account)
1284                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
1285         else
1286                 buf = g_strdup(PROG_VERSION);
1287         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
1288         g_free(buf);
1289
1290         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), ac_name);
1291         gtk_widget_queue_resize(mainwin->ac_button);
1292
1293         g_free(ac_name);
1294 }
1295
1296 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
1297 {
1298         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
1299         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
1300         //GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
1301         GtkWidget *message_wid = mainwin->messageview->vbox;
1302
1303         debug_print("Changing window separation type from %d to %d\n",
1304                     mainwin->type, type);
1305
1306         if (mainwin->type == type) return;
1307
1308         /* remove widgets from those containers */
1309         gtk_widget_ref(folder_wid);
1310         gtk_widget_ref(summary_wid);
1311         gtk_widget_ref(message_wid);
1312         gtkut_container_remove
1313                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
1314         gtkut_container_remove
1315                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
1316         gtkut_container_remove
1317                 (GTK_CONTAINER(message_wid->parent), message_wid);
1318
1319         /* clean containers */
1320         switch (mainwin->type) {
1321         case SEPARATE_NONE:
1322                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
1323                 break;
1324         case SEPARATE_FOLDER:
1325                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
1326                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
1327                 break;
1328         case SEPARATE_MESSAGE:
1329                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
1330                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
1331                 break;
1332         case SEPARATE_BOTH:
1333                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
1334                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
1335                 break;
1336         }
1337
1338         gtk_widget_hide(mainwin->window);
1339         main_window_set_widgets(mainwin, type);
1340         gtk_widget_show(mainwin->window);
1341
1342         gtk_widget_unref(folder_wid);
1343         gtk_widget_unref(summary_wid);
1344         gtk_widget_unref(message_wid);
1345 }
1346
1347 void main_window_toggle_message_view(MainWindow *mainwin)
1348 {
1349         SummaryView *summaryview = mainwin->summaryview;
1350         union CompositeWin *cwin = &mainwin->win;
1351         GtkWidget *vpaned = NULL;
1352         GtkWidget *container = NULL;
1353         GtkWidget *msgwin = NULL;
1354
1355         switch (mainwin->type) {
1356         case SEPARATE_NONE:
1357                 vpaned = cwin->sep_none.vpaned;
1358                 container = cwin->sep_none.hpaned;
1359                 break;
1360         case SEPARATE_FOLDER:
1361                 vpaned = cwin->sep_folder.vpaned;
1362                 container = mainwin->vbox_body;
1363                 break;
1364         case SEPARATE_MESSAGE:
1365                 msgwin = mainwin->win.sep_message.messagewin;
1366                 break;
1367         case SEPARATE_BOTH:
1368                 msgwin = mainwin->win.sep_both.messagewin;
1369                 break;
1370         }
1371
1372         if (msgwin) {
1373                 if (GTK_WIDGET_VISIBLE(msgwin)) {
1374                         gtk_widget_hide(msgwin);
1375                         mainwin->messageview->visible = FALSE;
1376                         summaryview->displayed = NULL;
1377                 } else {
1378                         gtk_widget_show(msgwin);
1379                         mainwin->messageview->visible = TRUE;
1380                 }
1381         } else if (vpaned->parent != NULL) {
1382                 mainwin->messageview->visible = FALSE;
1383                 summaryview->displayed = NULL;
1384                 gtk_widget_ref(vpaned);
1385                 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
1386                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), container);
1387                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1388                               GTK_ARROW_UP, GTK_SHADOW_OUT);
1389         } else {
1390                 mainwin->messageview->visible = TRUE;
1391                 gtk_widget_reparent(GTK_WIDGET_PTR(summaryview), vpaned);
1392                 gtk_container_add(GTK_CONTAINER(container), vpaned);
1393                 gtk_widget_unref(vpaned);
1394                 gtk_arrow_set(GTK_ARROW(summaryview->toggle_arrow),
1395                               GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1396         }
1397
1398         main_window_set_menu_sensitive(mainwin);
1399
1400         gtk_widget_grab_focus(summaryview->ctree);
1401 }
1402
1403 void main_window_get_size(MainWindow *mainwin)
1404 {
1405         GtkAllocation *allocation;
1406
1407         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
1408
1409         prefs_common.summaryview_width  = allocation->width;
1410
1411         if ((mainwin->type == SEPARATE_NONE ||
1412              mainwin->type == SEPARATE_FOLDER) &&
1413             messageview_is_visible(mainwin->messageview))
1414                 prefs_common.summaryview_height = allocation->height;
1415
1416         prefs_common.mainview_width     = allocation->width;
1417
1418         allocation = &mainwin->window->allocation;
1419
1420         prefs_common.mainview_height = allocation->height;
1421         prefs_common.mainwin_width   = allocation->width;
1422         prefs_common.mainwin_height  = allocation->height;
1423
1424         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1425
1426         prefs_common.folderview_width  = allocation->width;
1427         prefs_common.folderview_height = allocation->height;
1428 }
1429
1430 void main_window_get_position(MainWindow *mainwin)
1431 {
1432         gint x, y;
1433
1434         gtkut_widget_get_uposition(mainwin->window, &x, &y);
1435
1436         prefs_common.mainview_x = x;
1437         prefs_common.mainview_y = y;
1438         prefs_common.mainwin_x = x;
1439         prefs_common.mainwin_y = y;
1440
1441         debug_print("window position: x = %d, y = %d\n", x, y);
1442 }
1443
1444 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1445 {
1446         GList *list;
1447         guint has_trash;
1448         Folder *folder;
1449
1450         for (has_trash = 0, list = folder_get_list(); list != NULL; list = list->next) {
1451                 folder = FOLDER(list->data);
1452                 if (folder && folder->trash && folder->trash->total > 0)
1453                         has_trash++;
1454         }
1455
1456         if (!has_trash) return;
1457         
1458         if (confirm) {
1459                 if (alertpanel(_("Empty trash"),
1460                                _("Empty all messages in trash?"),
1461                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1462                         return;
1463                 manage_window_focus_in(mainwin->window, NULL, NULL);
1464         }
1465
1466         procmsg_empty_trash();
1467
1468         for (list = folder_get_list(); list != NULL; list = list->next) {
1469                 folder = list->data;
1470                 if (folder && folder->trash) {
1471                         folder_update_item(folder->trash, TRUE);
1472                 }
1473         }
1474
1475         if (mainwin->summaryview->folder_item &&
1476             mainwin->summaryview->folder_item->stype == F_TRASH)
1477                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1478 }
1479
1480 void main_window_add_mailbox(MainWindow *mainwin)
1481 {
1482         gchar *path;
1483         Folder *folder;
1484
1485         path = input_dialog(_("Add mailbox"),
1486                             _("Input the location of mailbox.\n"
1487                               "If the existing mailbox is specified, it will be\n"
1488                               "scanned automatically."),
1489                             "Mail");
1490         if (!path) return;
1491         if (folder_find_from_path(path)) {
1492                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1493                 g_free(path);
1494                 return;
1495         }
1496         if (!strcmp(path, "Mail"))
1497                 folder = folder_new(F_MH, _("Mailbox"), path);
1498         else
1499                 folder = folder_new(F_MH, g_basename(path), path);
1500         g_free(path);
1501
1502         if (folder->create_tree(folder) < 0) {
1503                 alertpanel_error(_("Creation of the mailbox failed.\n"
1504                                    "Maybe some files already exist, or you don't have the permission to write there."));
1505                 folder_destroy(folder);
1506                 return;
1507         }
1508
1509         folder_add(folder);
1510         folder_set_ui_func(folder, scan_tree_func, mainwin);
1511         folder_scan_tree(folder);
1512         folder_set_ui_func(folder, NULL, NULL);
1513
1514         folderview_set(mainwin->folderview);
1515 }
1516
1517 void main_window_add_mbox(MainWindow *mainwin)
1518 {
1519         gchar *path;
1520         Folder *folder;
1521         FolderItem * item;
1522
1523         path = input_dialog(_("Add mbox mailbox"),
1524                             _("Input the location of mailbox."),
1525                             "mail");
1526
1527         if (!path) return;
1528
1529         if (folder_find_from_path(path)) {
1530                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1531                 g_free(path);
1532                 return;
1533         }
1534
1535         /*
1536         if (!strcmp(path, "Mail"))
1537                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1538                 else
1539         */
1540
1541         folder = folder_new(F_MBOX, g_basename(path), path);
1542         g_free(path);
1543
1544         if (folder->create_tree(folder) < 0) {
1545                 alertpanel_error(_("Creation of the mailbox failed."));
1546                 folder_destroy(folder);
1547                 return;
1548         }
1549
1550         folder_add(folder);
1551
1552         item = folder_item_new(folder, folder->name, NULL);
1553         item->folder = folder;
1554         folder->node = g_node_new(item);
1555
1556         folder_create_folder(item, "inbox");
1557         folder_create_folder(item, "outbox");
1558         folder_create_folder(item, "queue");
1559         folder_create_folder(item, "draft");
1560         folder_create_folder(item, "trash");
1561
1562         folderview_set(mainwin->folderview);
1563 }
1564
1565 SensitiveCond main_window_get_current_state(MainWindow *mainwin)
1566 {
1567         SensitiveCond state = 0;
1568         SummarySelection selection;
1569         FolderItem *item = mainwin->summaryview->folder_item;
1570         GList *account_list = account_get_list();
1571         
1572         selection = summary_get_selection_type(mainwin->summaryview);
1573
1574         if (mainwin->lock_count == 0)
1575                 state |= M_UNLOCKED;
1576         if (selection != SUMMARY_NONE)
1577                 state |= M_MSG_EXIST;
1578         if (item && item->path && item->parent && !item->no_select) {
1579                 state |= M_EXEC;
1580                 /*              if (item->folder->type != F_NEWS) */
1581                 state |= M_ALLOW_DELETE;
1582
1583                 if (prefs_common.immediate_exec == 0
1584                     && mainwin->lock_count == 0)
1585                         state |= M_DELAY_EXEC;
1586
1587                 if ((selection == SUMMARY_NONE && item->hide_read_msgs)
1588                     || selection != SUMMARY_NONE)
1589                         state |= M_HIDE_READ_MSG;       
1590         }               
1591         if (mainwin->summaryview->threaded)
1592                 state |= M_THREADED;
1593         else
1594                 state |= M_UNTHREADED;  
1595         if (selection == SUMMARY_SELECTED_SINGLE ||
1596             selection == SUMMARY_SELECTED_MULTIPLE)
1597                 state |= M_TARGET_EXIST;
1598         if (selection == SUMMARY_SELECTED_SINGLE)
1599                 state |= M_SINGLE_TARGET_EXIST;
1600         if (mainwin->summaryview->folder_item &&
1601             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1602                 state |= M_NEWS;
1603         else
1604                 state |= M_NOT_NEWS;
1605         if (selection == SUMMARY_SELECTED_SINGLE &&
1606             (item &&
1607              (item->stype == F_OUTBOX || item->stype == F_DRAFT ||
1608               item->stype == F_QUEUE)))
1609                 state |= M_ALLOW_REEDIT;
1610         if (cur_account)
1611                 state |= M_HAVE_ACCOUNT;
1612         
1613         for ( ; account_list != NULL; account_list = account_list->next) {
1614                 if (((PrefsAccount*)account_list->data)->protocol == A_NNTP) {
1615                         state |= M_HAVE_NEWS_ACCOUNT;
1616                         break;
1617                 }
1618         }
1619
1620         if (inc_is_active())
1621                 state |= M_INC_ACTIVE;
1622
1623         return state;
1624 }
1625
1626
1627
1628 void main_window_set_menu_sensitive(MainWindow *mainwin)
1629 {
1630         GtkItemFactory *ifactory = mainwin->menu_factory;
1631         SensitiveCond state;
1632         gboolean sensitive;
1633         GtkWidget *menuitem;
1634         SummaryView *summaryview;
1635         gchar *menu_path;
1636         gint i;
1637
1638         static const struct {
1639                 gchar *const entry;
1640                 SensitiveCond cond;
1641         } entry[] = {
1642                 {"/File/Add mailbox..."                       , M_UNLOCKED},
1643                 {"/File/Add mbox mailbox..."                  , M_UNLOCKED},
1644                 {"/File/Check for new messages in all folders", M_UNLOCKED},
1645                 {"/File/Folder"                               , M_UNLOCKED},
1646                 {"/File/Import mbox file..."                  , M_UNLOCKED},
1647                 {"/File/Export to mbox file..."               , M_UNLOCKED},
1648                 {"/File/Empty trash"                          , M_UNLOCKED},
1649                 {"/File/Work offline"                         , M_UNLOCKED},
1650
1651                 {"/File/Save as...", M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1652                 {"/File/Print..."  , M_TARGET_EXIST|M_UNLOCKED},
1653                 /* {"/File/Close"  , M_UNLOCKED}, */
1654                 {"/File/Exit"      , M_UNLOCKED},
1655
1656                 {"/Edit/Select thread"             , M_SINGLE_TARGET_EXIST},
1657
1658                 {"/View/Sort"                      , M_EXEC},
1659                 {"/View/Thread view"               , M_EXEC},
1660                 {"/View/Expand all threads"        , M_MSG_EXIST},
1661                 {"/View/Collapse all threads"      , M_MSG_EXIST},
1662                 {"/View/Hide read messages"        , M_HIDE_READ_MSG},
1663                 {"/View/Go to/Prev message"        , M_MSG_EXIST},
1664                 {"/View/Go to/Next message"        , M_MSG_EXIST},
1665                 {"/View/Go to/Prev unread message" , M_MSG_EXIST},
1666                 {"/View/Go to/Next unread message" , M_MSG_EXIST},
1667                 {"/View/Go to/Prev new message"    , M_MSG_EXIST},
1668                 {"/View/Go to/Next new message"    , M_MSG_EXIST},
1669                 {"/View/Go to/Prev marked message" , M_MSG_EXIST},
1670                 {"/View/Go to/Next marked message" , M_MSG_EXIST},
1671                 {"/View/Go to/Prev labeled message", M_MSG_EXIST},
1672                 {"/View/Go to/Next labeled message", M_MSG_EXIST},
1673                 {"/View/Open in new window"        , M_SINGLE_TARGET_EXIST},
1674                 {"/View/Show all headers"          , M_SINGLE_TARGET_EXIST},
1675                 {"/View/Message source"            , M_SINGLE_TARGET_EXIST},
1676
1677                 {"/Message/Get new mail"          , M_HAVE_ACCOUNT|M_UNLOCKED},
1678                 {"/Message/Get from all accounts" , M_HAVE_ACCOUNT|M_UNLOCKED},
1679                 {"/Message/Cancel receiving"      , M_INC_ACTIVE},
1680                 {"/Message/Compose a news message", M_HAVE_NEWS_ACCOUNT},
1681                 {"/Message/Reply"                 , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1682                 {"/Message/Reply to"             , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1683                 {"/Message/Follow-up and reply to", M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST|M_NEWS},
1684                 {"/Message/Forward"               , M_HAVE_ACCOUNT|M_TARGET_EXIST},
1685                 {"/Message/Redirect"              , M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST},
1686                 {"/Message/Re-edit"               , M_HAVE_ACCOUNT|M_ALLOW_REEDIT},
1687                 {"/Message/Move..."               , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1688                 {"/Message/Copy..."               , M_TARGET_EXIST|M_EXEC|M_UNLOCKED},
1689                 {"/Message/Delete"                , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NOT_NEWS},
1690                 {"/Message/Cancel a news message" , M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED|M_NEWS},
1691                 {"/Message/Mark"                  , M_TARGET_EXIST},
1692
1693                 {"/Tools/Selective download..."     , M_HAVE_ACCOUNT|M_UNLOCKED},
1694                 {"/Tools/Add sender to address book", M_SINGLE_TARGET_EXIST},
1695                 {"/Tools/Harvest addresses"         , M_UNLOCKED},
1696                 {"/Tools/Filter messages"           , M_MSG_EXIST|M_EXEC|M_UNLOCKED},
1697                 {"/Tools/Create filter rule"        , M_SINGLE_TARGET_EXIST|M_UNLOCKED},
1698                 {"/Tools/Actions"                   , M_TARGET_EXIST|M_UNLOCKED},
1699                 {"/Tools/Execute"                   , M_DELAY_EXEC},
1700                 {"/Tools/Delete duplicated messages", M_MSG_EXIST|M_ALLOW_DELETE|M_UNLOCKED},
1701
1702                 {"/Configuration", M_UNLOCKED},
1703
1704                 {NULL, 0}
1705         };
1706
1707         state = main_window_get_current_state(mainwin);
1708
1709         for (i = 0; entry[i].entry != NULL; i++) {
1710                 sensitive = ((entry[i].cond & state) == entry[i].cond);
1711                 menu_set_sensitive(ifactory, entry[i].entry, sensitive);
1712         }
1713
1714         main_window_menu_callback_block(mainwin);
1715
1716 #define SET_CHECK_MENU_ACTIVE(path, active) \
1717 { \
1718         menuitem = gtk_item_factory_get_widget(ifactory, path); \
1719         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), active); \
1720 }
1721
1722         SET_CHECK_MENU_ACTIVE("/View/Show or hide/Message view",
1723                               messageview_is_visible(mainwin->messageview));
1724
1725         summaryview = mainwin->summaryview;
1726         menu_path = "/View/Sort/Don't sort";
1727
1728         switch (summaryview->sort_key) {
1729         case SORT_BY_NUMBER:
1730                 menu_path = "/View/Sort/by number"; break;
1731         case SORT_BY_SIZE:
1732                 menu_path = "/View/Sort/by size"; break;
1733         case SORT_BY_DATE:
1734                 menu_path = "/View/Sort/by date"; break;
1735         case SORT_BY_FROM:
1736                 menu_path = "/View/Sort/by from"; break;
1737         case SORT_BY_SUBJECT:
1738                 menu_path = "/View/Sort/by subject"; break;
1739         case SORT_BY_LABEL:
1740                 menu_path = "/View/Sort/by color label"; break;
1741         case SORT_BY_MARK:
1742                 menu_path = "/View/Sort/by mark"; break;
1743         case SORT_BY_UNREAD:
1744                 menu_path = "/View/Sort/by unread"; break;
1745         case SORT_BY_MIME:
1746                 menu_path = "/View/Sort/by attachment"; break;
1747         case SORT_BY_SCORE:
1748                 menu_path = "/View/Sort/by score"; break;
1749         case SORT_BY_LOCKED:
1750                 menu_path = "/View/Sort/by locked"; break;
1751         case SORT_BY_NONE:
1752         default:
1753                 menu_path = "/View/Sort/Don't sort"; break;
1754         }
1755         SET_CHECK_MENU_ACTIVE(menu_path, TRUE);
1756
1757         if (summaryview->sort_type == SORT_ASCENDING) {
1758                 SET_CHECK_MENU_ACTIVE("/View/Sort/Ascending", TRUE);
1759         } else {
1760                 SET_CHECK_MENU_ACTIVE("/View/Sort/Descending", TRUE);
1761         }
1762
1763         if (summaryview->sort_key != SORT_BY_NONE) {
1764                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", TRUE);
1765                 menu_set_sensitive(ifactory, "/View/Sort/Descending", TRUE);
1766         } else {
1767                 menu_set_sensitive(ifactory, "/View/Sort/Ascending", FALSE);
1768                 menu_set_sensitive(ifactory, "/View/Sort/Descending", FALSE);
1769         }
1770
1771         SET_CHECK_MENU_ACTIVE("/View/Show all headers",
1772                               mainwin->messageview->textview->show_all_headers);
1773         SET_CHECK_MENU_ACTIVE("/View/Thread view", (state & M_THREADED) != 0);
1774
1775 #undef SET_CHECK_MENU_ACTIVE
1776
1777         main_window_menu_callback_unblock(mainwin);
1778 }
1779
1780 void main_window_popup(MainWindow *mainwin)
1781 {
1782         gtkut_window_popup(mainwin->window);
1783
1784         switch (mainwin->type) {
1785         case SEPARATE_FOLDER:
1786                 gtkut_window_popup(mainwin->win.sep_folder.folderwin);
1787                 break;
1788         case SEPARATE_MESSAGE:
1789                 gtkut_window_popup(mainwin->win.sep_message.messagewin);
1790                 break;
1791         case SEPARATE_BOTH:
1792                 gtkut_window_popup(mainwin->win.sep_both.folderwin);
1793                 gtkut_window_popup(mainwin->win.sep_both.messagewin);
1794                 break;
1795         default:
1796                 break;
1797         }
1798 }
1799
1800 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1801 {
1802         GtkWidget *folderwin = NULL;
1803         GtkWidget *messagewin = NULL;
1804         GtkWidget *hpaned;
1805         GtkWidget *vpaned;
1806         GtkWidget *vbox_body = mainwin->vbox_body;
1807         GtkItemFactory *ifactory = mainwin->menu_factory;
1808         GtkWidget *menuitem;
1809
1810         debug_print("Setting widgets...");
1811
1812         /* create separated window(s) if needed */
1813         if (type & SEPARATE_FOLDER) {
1814                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1815                 gtk_window_set_title(GTK_WINDOW(folderwin),
1816                                      _("Sylpheed - Folder View"));
1817                 gtk_window_set_wmclass(GTK_WINDOW(folderwin),
1818                                        "folder_view", "Sylpheed");
1819                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1820                                       TRUE, TRUE, FALSE);
1821                 gtk_widget_set_usize(folderwin, -1,
1822                                      prefs_common.mainview_height);
1823                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1824                                                BORDER_WIDTH);
1825                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1826                                    GTK_SIGNAL_FUNC(folder_window_close_cb),
1827                                    mainwin);
1828         }
1829         if (type & SEPARATE_MESSAGE) {
1830                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1831                 gtk_window_set_title(GTK_WINDOW(messagewin),
1832                                      _("Sylpheed - Message View"));
1833                 gtk_window_set_wmclass(GTK_WINDOW(messagewin),
1834                                        "message_view", "Sylpheed");
1835                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1836                                       TRUE, TRUE, FALSE);
1837                 gtk_widget_set_usize
1838                         (messagewin, prefs_common.mainview_width,
1839                          prefs_common.mainview_height
1840                          - prefs_common.summaryview_height
1841                          + DEFAULT_HEADERVIEW_HEIGHT);
1842                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1843                                                BORDER_WIDTH);
1844                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1845                                    GTK_SIGNAL_FUNC(message_window_close_cb),
1846                                    mainwin);
1847         }
1848
1849         switch (type) {
1850         case SEPARATE_NONE:
1851                 hpaned = gtk_hpaned_new();
1852                 gtk_widget_show(hpaned);
1853                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1854                 gtk_paned_add1(GTK_PANED(hpaned),
1855                                GTK_WIDGET_PTR(mainwin->folderview));
1856
1857                 vpaned = gtk_vpaned_new();
1858                 if (messageview_is_visible(mainwin->messageview)) {
1859                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1860                         gtk_paned_add1(GTK_PANED(vpaned),
1861                                        GTK_WIDGET_PTR(mainwin->summaryview));
1862                 } else {
1863                         gtk_paned_add2(GTK_PANED(hpaned),
1864                                        GTK_WIDGET_PTR(mainwin->summaryview));
1865                         gtk_widget_ref(vpaned);
1866                 }
1867                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1868                                      prefs_common.summaryview_width,
1869                                      prefs_common.summaryview_height);
1870                 gtk_paned_add2(GTK_PANED(vpaned),
1871                                GTK_WIDGET_PTR(mainwin->messageview));
1872                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1873                                      prefs_common.mainview_width, -1);
1874                 gtk_widget_set_usize(mainwin->window,
1875                                      prefs_common.folderview_width +
1876                                      prefs_common.mainview_width,
1877                                      prefs_common.mainwin_height);
1878                 gtk_widget_show_all(vpaned);
1879
1880                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1881                  * lose track of its visibility state */
1882                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1883                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1884
1885                 mainwin->win.sep_none.hpaned = hpaned;
1886                 mainwin->win.sep_none.vpaned = vpaned;
1887                 
1888                 /* remove headerview if not in prefs */
1889                 headerview_set_visibility(mainwin->messageview->headerview,
1890                                           prefs_common.display_header_pane);
1891                 break;
1892         case SEPARATE_FOLDER:
1893                 vpaned = gtk_vpaned_new();
1894                 if (messageview_is_visible(mainwin->messageview)) {
1895                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1896                                            TRUE, TRUE, 0);
1897                         gtk_paned_add1(GTK_PANED(vpaned),
1898                                        GTK_WIDGET_PTR(mainwin->summaryview));
1899                 } else {
1900                         gtk_box_pack_start(GTK_BOX(vbox_body),
1901                                            GTK_WIDGET_PTR(mainwin->summaryview),
1902                                            TRUE, TRUE, 0);
1903                         gtk_widget_ref(vpaned);
1904                 }
1905                 gtk_paned_add2(GTK_PANED(vpaned),
1906                                GTK_WIDGET_PTR(mainwin->messageview));
1907                 gtk_widget_show_all(vpaned);
1908                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1909                                      prefs_common.summaryview_width,
1910                                      prefs_common.summaryview_height);
1911                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1912                                      prefs_common.mainview_width, -1);
1913                 gtk_widget_set_usize(mainwin->window,
1914                                      prefs_common.mainview_width,
1915                                      prefs_common.mainview_height);
1916
1917                 gtk_container_add(GTK_CONTAINER(folderwin),
1918                                   GTK_WIDGET_PTR(mainwin->folderview));
1919
1920                 mainwin->win.sep_folder.folderwin = folderwin;
1921                 mainwin->win.sep_folder.vpaned    = vpaned;
1922
1923                 gtk_widget_show_all(folderwin);
1924                 
1925                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1926                  * lose track of its visibility state */
1927                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1928                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1929                 
1930                 /* remove headerview if not in prefs */
1931                 headerview_set_visibility(mainwin->messageview->headerview,
1932                                           prefs_common.display_header_pane);
1933                 
1934                 break;
1935         case SEPARATE_MESSAGE:
1936                 hpaned = gtk_hpaned_new();
1937                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1938
1939                 gtk_paned_add1(GTK_PANED(hpaned),
1940                                GTK_WIDGET_PTR(mainwin->folderview));
1941                 gtk_paned_add2(GTK_PANED(hpaned),
1942                                GTK_WIDGET_PTR(mainwin->summaryview));
1943                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1944                                      prefs_common.summaryview_width,
1945                                      prefs_common.summaryview_height);
1946                 gtk_widget_set_usize(mainwin->window,
1947                                      prefs_common.folderview_width +
1948                                      prefs_common.mainview_width,
1949                                      prefs_common.mainwin_height);
1950                 gtk_widget_show_all(hpaned);
1951                 gtk_container_add(GTK_CONTAINER(messagewin),
1952                                   GTK_WIDGET_PTR(mainwin->messageview));
1953
1954                 mainwin->win.sep_message.messagewin = messagewin;
1955                 mainwin->win.sep_message.hpaned     = hpaned;
1956
1957                 gtk_widget_show_all(messagewin);
1958                 
1959                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1960                  * lose track of its visibility state */
1961                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1962                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1963                 break;
1964         case SEPARATE_BOTH:
1965                 gtk_box_pack_start(GTK_BOX(vbox_body),
1966                                    GTK_WIDGET_PTR(mainwin->summaryview),
1967                                    TRUE, TRUE, 0);
1968                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1969                                      prefs_common.summaryview_width,
1970                                      prefs_common.summaryview_height);
1971                 gtk_widget_set_usize(mainwin->window,
1972                                      prefs_common.mainview_width,
1973                                      prefs_common.mainwin_height);
1974                 gtk_container_add(GTK_CONTAINER(folderwin),
1975                                   GTK_WIDGET_PTR(mainwin->folderview));
1976                 gtk_container_add(GTK_CONTAINER(messagewin),
1977                                   GTK_WIDGET_PTR(mainwin->messageview));
1978
1979                 mainwin->win.sep_both.folderwin = folderwin;
1980                 mainwin->win.sep_both.messagewin = messagewin;
1981
1982                 gtk_widget_show_all(folderwin);
1983                 gtk_widget_show_all(messagewin);
1984
1985                 /* CLAWS: previous "gtk_widget_show_all" makes noticeview
1986                  * lose track of its visibility state */
1987                 if (!noticeview_is_visible(mainwin->messageview->noticeview)) 
1988                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->messageview->noticeview));
1989                 break;
1990         }
1991
1992         /* rehide quick search if necessary */
1993         if (!prefs_common.show_searchbar)
1994                 gtk_widget_hide(mainwin->summaryview->hbox_search);
1995         
1996         mainwin->type = type;
1997
1998         mainwin->messageview->visible = TRUE;
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), TRUE);
2004         menuitem = gtk_item_factory_get_item
2005                 (ifactory, "/View/Show or hide/Message view");
2006         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2007
2008         menuitem = gtk_item_factory_get_item
2009                 (ifactory, "/View/Separate folder tree");
2010         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2011                                        ((type & SEPARATE_FOLDER) != 0));
2012         menuitem = gtk_item_factory_get_item
2013                 (ifactory, "/View/Separate message view");
2014         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2015                                        ((type & SEPARATE_MESSAGE) != 0));
2016
2017         debug_print("done.\n");
2018 }
2019
2020 void main_window_destroy_all(void)
2021 {
2022         while (mainwin_list != NULL) {
2023                 MainWindow *mainwin = (MainWindow*)mainwin_list->data;
2024                 
2025                 /* free toolbar stuff */
2026                 toolbar_clear_list(TOOLBAR_MAIN);
2027                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2028                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
2029
2030                 g_free(mainwin->toolbar);
2031                 g_free(mainwin);
2032                 
2033                 mainwin_list = g_list_remove(mainwin_list, mainwin);
2034         }
2035         g_list_free(mainwin_list);
2036 }
2037
2038 #if 0
2039 static void toolbar_account_button_pressed(GtkWidget *widget,
2040                                            GdkEventButton *event,
2041                                            gpointer data)
2042 {
2043         MainWindow *mainwin = (MainWindow *)data;
2044
2045         if (!event) return;
2046         if (event->button != 3) return;
2047
2048         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2049         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2050                             widget);
2051
2052         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2053                        menu_button_position, widget,
2054                        event->button, event->time);
2055 }
2056 #endif
2057
2058 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
2059                                     gpointer data)
2060 {
2061         MainWindow *mainwin = (MainWindow *)data;
2062
2063         if (!event) return;
2064
2065         gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2066         gtk_object_set_data(GTK_OBJECT(mainwin->ac_menu), "menu_button",
2067                             widget);
2068
2069         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL,
2070                        menu_button_position, widget,
2071                        event->button, event->time);
2072 }
2073
2074 static void ac_menu_popup_closed(GtkMenuShell *menu_shell, gpointer data)
2075 {
2076         MainWindow *mainwin = (MainWindow *)data;
2077         GtkWidget *button;
2078
2079         button = gtk_object_get_data(GTK_OBJECT(menu_shell), "menu_button");
2080         if (!button) return;
2081         gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
2082         gtk_object_remove_data(GTK_OBJECT(mainwin->ac_menu), "menu_button");
2083         manage_window_focus_in(mainwin->window, NULL, NULL);
2084 }
2085
2086 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2087                                  gpointer data)
2088 {
2089         MainWindow *mainwin = (MainWindow *)data;
2090
2091         if (mainwin->lock_count == 0)
2092                 app_exit_cb(data, 0, widget);
2093
2094         return TRUE;
2095 }
2096
2097 static gint folder_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2098                                    gpointer data)
2099 {
2100         MainWindow *mainwin = (MainWindow *)data;
2101         GtkWidget *menuitem;
2102
2103         menuitem = gtk_item_factory_get_item
2104                 (mainwin->menu_factory, "/View/Show or hide/Folder tree");
2105         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2106
2107         return TRUE;
2108 }
2109
2110 static gint message_window_close_cb(GtkWidget *widget, GdkEventAny *event,
2111                                     gpointer data)
2112 {
2113         MainWindow *mainwin = (MainWindow *)data;
2114         GtkWidget *menuitem;
2115
2116         menuitem = gtk_item_factory_get_item
2117                 (mainwin->menu_factory, "/View/Show or hide/Message view");
2118         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2119
2120         return TRUE;
2121 }
2122
2123 static void add_mailbox_cb(MainWindow *mainwin, guint action,
2124                            GtkWidget *widget)
2125 {
2126         main_window_add_mailbox(mainwin);
2127 }
2128
2129 static void add_mbox_cb(MainWindow *mainwin, guint action,
2130                         GtkWidget *widget)
2131 {
2132         main_window_add_mbox(mainwin);
2133 }
2134
2135 static void update_folderview_cb(MainWindow *mainwin, guint action,
2136                                  GtkWidget *widget)
2137 {
2138         summary_show(mainwin->summaryview, NULL);
2139         folderview_check_new_all();
2140 }
2141
2142 static void new_folder_cb(MainWindow *mainwin, guint action,
2143                           GtkWidget *widget)
2144 {
2145         folderview_new_folder(mainwin->folderview);
2146 }
2147
2148 static void rename_folder_cb(MainWindow *mainwin, guint action,
2149                              GtkWidget *widget)
2150 {
2151         folderview_rename_folder(mainwin->folderview);
2152 }
2153
2154 static void delete_folder_cb(MainWindow *mainwin, guint action,
2155                              GtkWidget *widget)
2156 {
2157         folderview_delete_folder(mainwin->folderview);
2158 }
2159
2160 static void import_mbox_cb(MainWindow *mainwin, guint action,
2161                            GtkWidget *widget)
2162 {
2163         import_mbox(mainwin->summaryview->folder_item);
2164 }
2165
2166 static void export_mbox_cb(MainWindow *mainwin, guint action,
2167                            GtkWidget *widget)
2168 {
2169         export_mbox(mainwin->summaryview->folder_item);
2170 }
2171
2172 static void empty_trash_cb(MainWindow *mainwin, guint action,
2173                            GtkWidget *widget)
2174 {
2175         main_window_empty_trash(mainwin, TRUE);
2176 }
2177
2178 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2179 {
2180         summary_save_as(mainwin->summaryview);
2181 }
2182
2183 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2184 {
2185         summary_print(mainwin->summaryview);
2186 }
2187
2188 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2189 {
2190         if (prefs_common.confirm_on_exit) {
2191                 if (alertpanel(_("Exit"), _("Exit this program?"),
2192                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2193                         return;
2194                 manage_window_focus_in(mainwin->window, NULL, NULL);
2195         }
2196
2197         app_will_exit(widget, mainwin);
2198 }
2199
2200 static void search_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2201 {
2202         if (action == 1)
2203                 summary_search(mainwin->summaryview);
2204         else
2205                 message_search(mainwin->messageview);
2206 }
2207
2208 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2209                              GtkWidget *widget)
2210 {
2211         gboolean active;
2212
2213         active = GTK_CHECK_MENU_ITEM(widget)->active;
2214
2215         switch (mainwin->type) {
2216         case SEPARATE_NONE:
2217         case SEPARATE_MESSAGE:
2218 #if 0
2219                 if (active)
2220                         gtk_widget_show(GTK_WIDGET_PTR(mainwin->folderview));
2221                 else
2222                         gtk_widget_hide(GTK_WIDGET_PTR(mainwin->folderview));
2223 #endif
2224                 break;
2225         case SEPARATE_FOLDER:
2226                 debug_print("separate folder\n");
2227                 if (active)
2228                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2229                 else
2230                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2231                 break;
2232         case SEPARATE_BOTH:
2233                 if (active)
2234                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2235                 else
2236                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2237                 break;
2238         }
2239 }
2240
2241 static void toggle_message_cb(MainWindow *mainwin, guint action,
2242                               GtkWidget *widget)
2243 {
2244         gboolean active;
2245
2246         active = GTK_CHECK_MENU_ITEM(widget)->active;
2247
2248         if (active != messageview_is_visible(mainwin->messageview))
2249                 summary_toggle_view(mainwin->summaryview);
2250 }
2251
2252 /* Toolbar handling */
2253 static void toolbar_inc_cb(GtkWidget    *widget,
2254                            gpointer      data)
2255 {
2256         MainWindow *mainwin = (MainWindow *)data;
2257
2258         inc_mail_cb(mainwin, 0, NULL);
2259 }
2260
2261 static void toolbar_inc_all_cb(GtkWidget        *widget,
2262                                gpointer  data)
2263 {
2264         MainWindow *mainwin = (MainWindow *)data;
2265
2266         inc_all_account_mail_cb(mainwin, 0, NULL);
2267 }
2268
2269 static void toolbar_send_cb(GtkWidget   *widget,
2270                             gpointer     data)
2271 {
2272         MainWindow *mainwin = (MainWindow *)data;
2273
2274         send_queue_cb(mainwin, 0, NULL);
2275 }
2276
2277 static void toolbar_compose_cb(GtkWidget  *widget,
2278                                gpointer    data)
2279 {
2280         MainWindow *mainwin = (MainWindow *)data;
2281
2282         if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS) 
2283                 compose_news_cb(mainwin, 0, NULL);
2284         else
2285                 compose_mail_cb(mainwin, 0, NULL);
2286 }
2287
2288 static void toolbar_reply_cb(GtkWidget   *widget, 
2289                              gpointer     data)
2290 {
2291         MainWindow *mainwin = (MainWindow *)data;
2292
2293         if (prefs_common.default_reply_list)
2294                 reply_cb(mainwin, 
2295                          prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE 
2296                          : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, 
2297                          NULL);
2298         else
2299                 reply_cb(mainwin, 
2300                          prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE 
2301                          : COMPOSE_REPLY_WITHOUT_QUOTE,
2302                          NULL);
2303 }
2304
2305 static void toolbar_reply_to_all_cb(GtkWidget   *widget, 
2306                                     gpointer     data)
2307 {
2308         MainWindow *mainwin = (MainWindow *)data;
2309
2310         reply_cb(mainwin, 
2311                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
2312                  : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, 
2313                  NULL);
2314 }
2315
2316 static void toolbar_reply_to_list_cb(GtkWidget   *widget, 
2317                                     gpointer     data)
2318 {
2319         MainWindow *mainwin = (MainWindow *)data;
2320
2321         reply_cb(mainwin, 
2322                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE 
2323                  : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, 
2324                  NULL);
2325 }
2326
2327 static void toolbar_reply_to_sender_cb(GtkWidget   *widget, 
2328                                        gpointer     data)
2329 {
2330         MainWindow *mainwin = (MainWindow *)data;
2331
2332         reply_cb(mainwin, 
2333                  prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
2334                  : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, 
2335                  NULL);
2336 }
2337
2338 static void toolbar_forward_cb(GtkWidget        *widget,
2339                                gpointer          data)
2340 {
2341         MainWindow *mainwin = (MainWindow *)data;
2342
2343         if (prefs_common.forward_as_attachment)
2344                 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
2345         else
2346                 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
2347 }
2348
2349 static void toolbar_exec_cb(GtkWidget   *widget,
2350                             gpointer     data)
2351 {
2352         MainWindow *mainwin = (MainWindow *)data;
2353
2354         summary_execute(mainwin->summaryview);
2355 }
2356
2357 static void toolbar_next_unread_cb(GtkWidget    *widget,
2358                                    gpointer      data)
2359 {
2360         MainWindow *mainwin = (MainWindow *)data;
2361
2362         next_unread_cb(mainwin, 0, NULL);
2363 }
2364
2365 /* popup callback functions */
2366 static void toolbar_reply_popup_cb(GtkWidget       *widget, 
2367                                    GdkEventButton  *event, 
2368                                    gpointer         data)
2369 {
2370         MainWindow *mainwindow = (MainWindow *) data;
2371         
2372         if (!event) return;
2373
2374         if (event->button == 3) {
2375                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2376                 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->reply_popup), NULL, NULL,
2377                        menu_button_position, widget,
2378                        event->button, event->time);
2379         }
2380 }
2381
2382 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2383 {
2384         MainWindow *mainwin = (MainWindow *)data;
2385
2386         gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->reply_btn), GTK_RELIEF_NONE);
2387         manage_window_focus_in(mainwin->window, NULL, NULL);
2388 }
2389
2390 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2391 {
2392         MainWindow *mainwindow = (MainWindow *) data;
2393         
2394         if (!event) return;
2395
2396         if (event->button == 3) {
2397                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2398                 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->replyall_popup), NULL, NULL,
2399                        menu_button_position, widget,
2400                        event->button, event->time);
2401         }
2402 }
2403
2404 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2405 {
2406         MainWindow *mainwin = (MainWindow *)data;
2407
2408         gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->replyall_btn), GTK_RELIEF_NONE);
2409         manage_window_focus_in(mainwin->window, NULL, NULL);
2410 }
2411
2412 static void toolbar_reply_to_list_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2413 {
2414         MainWindow *mainwindow = (MainWindow *) data;
2415         
2416         if (!event) return;
2417
2418         if (event->button == 3) {
2419                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2420                 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->replylist_popup), NULL, NULL,
2421                        menu_button_position, widget,
2422                        event->button, event->time);
2423         }
2424 }
2425
2426 static void toolbar_reply_to_list_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2427 {
2428         MainWindow *mainwin = (MainWindow *)data;
2429
2430         gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->replylist_btn), GTK_RELIEF_NONE);
2431         manage_window_focus_in(mainwin->window, NULL, NULL);
2432 }
2433
2434 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2435 {
2436         MainWindow *mainwindow = (MainWindow *) data;
2437
2438         if (!event) return;
2439
2440         if (event->button == 3) {
2441                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2442                 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->replysender_popup), NULL, NULL,
2443                        menu_button_position, widget,
2444                        event->button, event->time);
2445         }
2446 }
2447
2448 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
2449 {
2450         MainWindow *mainwin = (MainWindow *)data;
2451
2452         gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->replysender_btn), GTK_RELIEF_NONE);
2453         manage_window_focus_in(mainwin->window, NULL, NULL);
2454 }
2455
2456 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
2457 {
2458         MainWindow *mainwindow = (MainWindow *) data;
2459         
2460         if (!event) return;
2461
2462         if (event->button == 3) {
2463                 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
2464                 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->fwd_popup), NULL, NULL,
2465                        menu_button_position, widget,
2466                        event->button, event->time);
2467         }
2468 }
2469
2470 static void toolbar_forward_popup_closed_cb (GtkMenuShell *menu_shell, 
2471                                              gpointer     data)
2472 {
2473         MainWindow *mainwin = (MainWindow *)data;
2474
2475         gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->fwd_btn), GTK_RELIEF_NONE);
2476         manage_window_focus_in(mainwin->window, NULL, NULL);
2477 }
2478
2479 static void activate_compose_button (Toolbar           *toolbar,
2480                                      ToolbarStyle      style,
2481                                      ComposeButtonType type)
2482 {
2483         if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
2484                 return;
2485
2486         gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn 
2487                         : toolbar->compose_news_btn);
2488         gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
2489                         : toolbar->compose_mail_btn);
2490         toolbar->compose_btn_type = type;       
2491 }
2492
2493 void toolbar_set_compose_button(Toolbar            *toolbar, 
2494                                 ComposeButtonType  compose_btn_type)
2495 {
2496         if (toolbar->compose_btn_type != compose_btn_type)
2497                 activate_compose_button(toolbar, 
2498                                         prefs_common.toolbar_style,
2499                                         compose_btn_type);
2500 }
2501
2502 static void toolbar_buttons_cb(GtkWidget         *widget, 
2503                                ToolbarItem       *item)
2504 {
2505         struct {
2506                 gint   index;
2507                 void (*func)(GtkWidget *widget, gpointer data);
2508         } toolbar_action[] = {
2509                 { A_RECEIVE_ALL,    toolbar_inc_all_cb                  },
2510                 { A_RECEIVE_CUR,    toolbar_inc_cb                      },
2511                 { A_SEND_QUEUED,    toolbar_send_cb                     },
2512                 { A_COMPOSE_EMAIL,  toolbar_compose_cb                  },
2513                 { A_REPLY_MESSAGE,  toolbar_reply_cb                    },
2514                 { A_REPLY_SENDER,   toolbar_reply_to_sender_cb          },
2515                 { A_REPLY_ALL,      toolbar_reply_to_all_cb             },
2516                 { A_REPLY_ML,       toolbar_reply_to_list_cb            },
2517                 { A_FORWARD,        toolbar_forward_cb                  },
2518                 { A_DELETE,         common_toolbar_delete_cb            },
2519                 { A_EXECUTE,        toolbar_exec_cb                     },
2520                 { A_GOTO_NEXT,      toolbar_next_unread_cb              },
2521                 { A_SYL_ACTIONS,    common_toolbar_actions_execute_cb   },
2522                 
2523                 { A_COMPOSE_NEWS,   toolbar_compose_cb                  },    
2524                 { A_SEPARATOR,      NULL                                }};
2525
2526         gint num_items = sizeof(toolbar_action)/sizeof(toolbar_action[0]);
2527         gint i;
2528
2529         for (i = A_RECEIVE_ALL; i < num_items; i++) {
2530
2531                 if (toolbar_action[i].index == item->index) {
2532                         if ((item->index == A_SYL_ACTIONS) || (item->index == A_DELETE))
2533                                 /* the common_toolbar_* stuff takes item->parent as data
2534                                    pointer */                              
2535                                 toolbar_action[i].func(widget, (gpointer)item->parent);
2536                         else /* to be removed */
2537                                 toolbar_action[i].func(widget, (gpointer)item->parent->data);
2538                         break;
2539                 }
2540         }
2541 }
2542
2543 void toolbar_set_sensitive(MainWindow *mainwin)
2544 {
2545         SensitiveCond state;
2546         gboolean sensitive;
2547         Toolbar *toolbar = mainwin->toolbar;
2548         GSList *cur;
2549         GSList *entry_list = NULL;
2550         
2551         typedef struct _Entry Entry;
2552         struct _Entry {
2553                 GtkWidget *widget;
2554                 SensitiveCond cond;
2555                 gboolean empty;
2556         };
2557
2558 #define SET_WIDGET_COND(w, c)     \
2559 { \
2560         Entry *e = g_new0(Entry, 1); \
2561         e->widget = w; \
2562         e->cond   = c; \
2563         entry_list = g_slist_append(entry_list, e); \
2564 }
2565
2566         SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
2567         SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
2568         SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
2569         SET_WIDGET_COND(toolbar->reply_btn,
2570                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
2571         SET_WIDGET_COND(toolbar->replyall_btn,
2572                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
2573         SET_WIDGET_COND(toolbar->replylist_btn,
2574                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
2575         SET_WIDGET_COND(toolbar->replysender_btn,
2576                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
2577         SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
2578
2579         SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
2580         SET_WIDGET_COND(toolbar->delete_btn,
2581                         M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
2582         SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
2583
2584         for (cur = toolbar->action_list; cur != NULL;  cur = cur->next) {
2585                 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
2586                 
2587                 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2588         }
2589
2590 #undef SET_WIDGET_COND
2591
2592         state = main_window_get_current_state(mainwin);
2593
2594         for (cur = entry_list; cur != NULL; cur = cur->next) {
2595                 Entry *e = (Entry*) cur->data;
2596
2597                 if (e->widget != NULL) {
2598                         sensitive = ((e->cond & state) == e->cond);
2599                         gtk_widget_set_sensitive(e->widget, sensitive); 
2600                 }
2601         }
2602         
2603         while (entry_list != NULL) {
2604                 Entry *e = (Entry*) entry_list->data;
2605
2606                 if (e)
2607                         g_free(e);
2608                 entry_list = g_slist_remove(entry_list, e);
2609         }
2610
2611         g_slist_free(entry_list);
2612
2613         activate_compose_button(toolbar, 
2614                                 prefs_common.toolbar_style,
2615                                 toolbar->compose_btn_type);
2616 }
2617
2618 static void toolbar_update(MainWindow *mainwin)
2619 {
2620         gtk_container_remove(GTK_CONTAINER(mainwin->handlebox), 
2621                              GTK_WIDGET(mainwin->toolbar->toolbar));
2622         
2623         mainwin->toolbar->toolbar    = NULL;
2624         mainwin->toolbar->get_btn    = NULL;
2625         mainwin->toolbar->getall_btn = NULL;
2626         mainwin->toolbar->send_btn   = NULL;
2627         mainwin->toolbar->compose_mail_btn = NULL;
2628         mainwin->toolbar->compose_news_btn = NULL;
2629         mainwin->toolbar->reply_btn        = NULL;      
2630         mainwin->toolbar->replyall_btn     = NULL;      
2631         mainwin->toolbar->replylist_btn     = NULL;     
2632         mainwin->toolbar->replysender_btn  = NULL;      
2633         mainwin->toolbar->fwd_btn    = NULL;    
2634         mainwin->toolbar->delete_btn = NULL;    
2635         mainwin->toolbar->next_btn   = NULL;    
2636         mainwin->toolbar->exec_btn   = NULL;
2637
2638         toolbar_clear_list(TOOLBAR_MAIN);
2639         TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2640         toolbar_create(mainwin, mainwin->handlebox);    
2641         toolbar_set_sensitive(mainwin);
2642
2643 }
2644
2645 static void toolbar_create(MainWindow *mainwin,
2646                            GtkWidget  *container)
2647 {
2648         ToolbarItem *toolbar_item;
2649
2650         GtkWidget *toolbar;
2651         GtkWidget *icon_wid  = NULL;
2652         GtkWidget *icon_news = NULL;
2653         GtkWidget *item_news = NULL;
2654         GtkWidget *item;
2655         GtkTooltips *toolbar_tips;
2656         ToolbarSylpheedActions *action_item;
2657         GSList *cur;
2658         GSList *toolbar_list;
2659
2660         guint n_menu_entries;
2661         GtkWidget *reply_popup;
2662         GtkWidget *replyall_popup;
2663         GtkWidget *replylist_popup;
2664         GtkWidget *replysender_popup;
2665         GtkWidget *fwd_popup;
2666
2667         toolbar_tips = gtk_tooltips_new();
2668
2669         if (mainwin->toolbar != NULL) {
2670                 toolbar_clear_list(TOOLBAR_MAIN);
2671                 TOOLBAR_DESTROY_ACTIONS(mainwin->toolbar->action_list);
2672                 TOOLBAR_DESTROY_ITEMS(mainwin->toolbar->item_list);
2673                 g_free(mainwin->toolbar);
2674         }
2675
2676         toolbar_read_config_file(TOOLBAR_MAIN);
2677         toolbar_list = toolbar_get_list(TOOLBAR_MAIN);
2678
2679         mainwin->toolbar = g_new0(Toolbar, 1); 
2680
2681         toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
2682                                   GTK_TOOLBAR_BOTH);
2683         gtk_container_add(GTK_CONTAINER(container), toolbar);
2684         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2685         gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
2686         gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
2687                                     GTK_TOOLBAR_SPACE_LINE);
2688         
2689         for (cur = toolbar_list; cur != NULL; cur = cur->next) {
2690         
2691                 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, SEPARATOR) == 0) {
2692                         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
2693                         continue;
2694                 }
2695                 
2696                 toolbar_item = g_new0(ToolbarItem, 1); 
2697                 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
2698                 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
2699                 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
2700                 
2701                 toolbar_item->parent = g_new0(ToolbarParent, 1);
2702                 toolbar_item->parent->data = (gpointer)mainwin;
2703                 toolbar_item->parent->type = TOOLBAR_MAIN;
2704
2705                 /* collect toolbar items in list to keep track */
2706                 mainwin->toolbar->item_list = g_slist_append(mainwin->toolbar->item_list, 
2707                                                              toolbar_item);
2708                 
2709                 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
2710                 item  = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2711                                                 toolbar_item->text,
2712                                                 (""),
2713                                                 (""),
2714                                                 icon_wid, toolbar_buttons_cb, 
2715                                                 toolbar_item);
2716                 
2717                 switch (toolbar_item->index) {
2718                 case A_RECEIVE_ALL:
2719                         mainwin->toolbar->getall_btn = item;
2720                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2721                                              mainwin->toolbar->getall_btn, 
2722                                            _("Receive Mail on all Accounts"), NULL);
2723                         break;
2724                 case A_RECEIVE_CUR:
2725                         mainwin->toolbar->get_btn = item;
2726                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2727                                              mainwin->toolbar->get_btn,
2728                                            _("Receive Mail on current Account"), NULL);
2729                         break;
2730                 case A_SEND_QUEUED:
2731                         mainwin->toolbar->send_btn = item; 
2732                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2733                                              mainwin->toolbar->send_btn,
2734                                            _("Send Queued Message(s)"), NULL);
2735                         break;
2736                 case A_COMPOSE_EMAIL:
2737                         icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
2738                         item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
2739                                                             _("News"),
2740                                                             (""),
2741                                                             (""),
2742                                                             icon_news, toolbar_buttons_cb, 
2743                                                             toolbar_item);
2744                         mainwin->toolbar->compose_mail_btn = item; 
2745                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2746                                              mainwin->toolbar->compose_mail_btn,
2747                                            _("Compose Email"), NULL);
2748                         mainwin->toolbar->compose_news_btn = item_news;
2749                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2750                                              mainwin->toolbar->compose_news_btn,
2751                                            _("Compose News"), NULL);
2752                         break;
2753                 case A_REPLY_MESSAGE:
2754                         mainwin->toolbar->reply_btn = item;
2755                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2756                                              mainwin->toolbar->reply_btn,
2757                                            _("Reply to Message"), NULL);
2758                         gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->reply_btn), 
2759                                            "button_press_event",
2760                                            GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
2761                                            mainwin);
2762                         n_menu_entries = sizeof(reply_popup_entries) /
2763                                 sizeof(reply_popup_entries[0]);
2764                         reply_popup = popupmenu_create(mainwin->window, reply_popup_entries, n_menu_entries,
2765                                                        "<ReplyPopup>", mainwin);
2766                         gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
2767                                            GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), mainwin);
2768                         mainwin->toolbar->reply_popup       = reply_popup;
2769                         break;
2770                 case A_REPLY_SENDER:
2771                         mainwin->toolbar->replysender_btn = item;
2772                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2773                                              mainwin->toolbar->replysender_btn,
2774                                            _("Reply to Sender"), NULL);
2775                         gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->replysender_btn), 
2776                                            "button_press_event",
2777                                            GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
2778                                            mainwin);
2779                         n_menu_entries = sizeof(replysender_popup_entries) /
2780                                 sizeof(replysender_popup_entries[0]);
2781                         replysender_popup = popupmenu_create(mainwin->window, 
2782                                                              replysender_popup_entries, n_menu_entries,
2783                                                              "<ReplySenderPopup>", mainwin);
2784                         gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
2785                                            GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), mainwin);
2786                         mainwin->toolbar->replysender_popup = replysender_popup;
2787                         break;
2788                 case A_REPLY_ALL:
2789                         mainwin->toolbar->replyall_btn = item;
2790                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2791                                              mainwin->toolbar->replyall_btn,
2792                                            _("Reply to All"), NULL);
2793                         gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->replyall_btn), 
2794                                            "button_press_event",
2795                                            GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
2796                                            mainwin);
2797                         n_menu_entries = sizeof(replyall_popup_entries) /
2798                                 sizeof(replyall_popup_entries[0]);
2799                         replyall_popup = popupmenu_create(mainwin->window, 
2800                                                           replyall_popup_entries, n_menu_entries,
2801                                                           "<ReplyAllPopup>", mainwin);
2802                         gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
2803                                            GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), mainwin);
2804                         mainwin->toolbar->replyall_popup    = replyall_popup;
2805                         break;
2806                 case A_REPLY_ML:
2807                         mainwin->toolbar->replylist_btn = item;
2808                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2809                                              mainwin->toolbar->replylist_btn,
2810                                            _("Reply to Mailing-list"), NULL);
2811                         gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->replylist_btn), 
2812                                            "button_press_event",
2813                                            GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_cb),
2814                                            mainwin);
2815                         n_menu_entries = sizeof(replylist_popup_entries) /
2816                                 sizeof(replylist_popup_entries[0]);
2817                         replylist_popup = popupmenu_create(mainwin->window, 
2818                                                           replylist_popup_entries, n_menu_entries,
2819                                                           "<ReplyMlPopup>", mainwin);
2820                         gtk_signal_connect(GTK_OBJECT(replylist_popup), "selection_done",
2821                                            GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_closed_cb), mainwin);
2822                         mainwin->toolbar->replylist_popup    = replylist_popup;
2823                         break;
2824                 case A_FORWARD:
2825                         mainwin->toolbar->fwd_btn = item;
2826                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2827                                              mainwin->toolbar->fwd_btn,
2828                                            _("Forward Message"), NULL);
2829                         gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->fwd_btn), 
2830                                            "button_press_event",
2831                                            GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
2832                                            mainwin);
2833                         n_menu_entries = sizeof(fwd_popup_entries) /
2834                                 sizeof(fwd_popup_entries[0]);
2835                         fwd_popup = popupmenu_create(mainwin->window, 
2836                                                      fwd_popup_entries, n_menu_entries,
2837                                                      "<ForwardPopup>", mainwin);
2838                         gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
2839                                            GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), mainwin);
2840                         mainwin->toolbar->fwd_popup         = fwd_popup;
2841                         break;
2842                 case A_DELETE:
2843                         mainwin->toolbar->delete_btn = item;
2844                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2845                                              mainwin->toolbar->delete_btn,
2846                                            _("Delete Message"), NULL);
2847                         break;
2848                 case A_EXECUTE:
2849                         mainwin->toolbar->exec_btn = item;
2850                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2851                                              mainwin->toolbar->exec_btn,
2852                                            _("Execute"), NULL);
2853                         break;
2854                 case A_GOTO_NEXT:
2855                         mainwin->toolbar->next_btn = item;
2856                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2857                                              mainwin->toolbar->next_btn,
2858                                            _("Goto Next Message"), NULL);
2859                         break;
2860                 case A_SYL_ACTIONS:
2861                         action_item = g_new0(ToolbarSylpheedActions, 1);
2862                         action_item->widget = item;
2863                         action_item->name   = g_strdup(toolbar_item->text);
2864
2865                         mainwin->toolbar->action_list = 
2866                                 g_slist_append(mainwin->toolbar->action_list,
2867                                                action_item);
2868
2869                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
2870                                              item,
2871                                              action_item->name, NULL);
2872
2873                         gtk_widget_show(item);
2874                         break;
2875                 default:
2876                         break;
2877                 }
2878         }
2879
2880         mainwin->toolbar->toolbar = toolbar;
2881
2882         activate_compose_button(mainwin->toolbar, 
2883                                 prefs_common.toolbar_style, 
2884                                 mainwin->toolbar->compose_btn_type);
2885
2886         gtk_widget_show_all(toolbar);
2887 }
2888
2889 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2890                               GtkWidget *widget)
2891 {
2892         switch ((ToolbarStyle)action) {
2893         case TOOLBAR_NONE:
2894                 gtk_widget_hide(mainwin->handlebox);
2895         case TOOLBAR_ICON:
2896                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2897                                       GTK_TOOLBAR_ICONS);
2898                 break;
2899         case TOOLBAR_TEXT:
2900                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2901                                       GTK_TOOLBAR_TEXT);
2902                 break;
2903         case TOOLBAR_BOTH:
2904                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar->toolbar),
2905                                       GTK_TOOLBAR_BOTH);
2906                 break;
2907         }
2908
2909         if (action != TOOLBAR_NONE) {
2910                 gtk_widget_show(mainwin->handlebox);
2911                 gtk_widget_queue_resize(mainwin->handlebox);
2912         }
2913
2914         mainwin->toolbar_style = (ToolbarStyle)action;
2915         prefs_common.toolbar_style = (ToolbarStyle)action;
2916 }
2917
2918 /* END Toolbar Stuff */
2919
2920 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2921                                 GtkWidget *widget)
2922 {
2923         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2924                 gtk_widget_show(mainwin->hbox_stat);
2925                 prefs_common.show_statusbar = TRUE;
2926         } else {
2927                 gtk_widget_hide(mainwin->hbox_stat);
2928                 prefs_common.show_statusbar = FALSE;
2929         }
2930 }
2931
2932 static void separate_widget_cb(MainWindow *mainwin, guint action,
2933                                GtkWidget *widget)
2934 {
2935         SeparateType type;
2936
2937         if (GTK_CHECK_MENU_ITEM(widget)->active)
2938                 type = mainwin->type | action;
2939         else
2940                 type = mainwin->type & ~action;
2941
2942         main_window_separation_change(mainwin, type);
2943
2944         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2945         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2946 }
2947
2948 void main_window_toggle_work_offline (MainWindow *mainwin, gboolean offline)
2949 {
2950         if (offline)
2951                 online_switch_clicked (GTK_BUTTON(mainwin->online_switch), mainwin);
2952         else
2953                 online_switch_clicked (GTK_BUTTON(mainwin->offline_switch), mainwin);
2954 }
2955
2956 static void toggle_work_offline_cb (MainWindow *mainwin, guint action, GtkWidget *widget)
2957 {
2958         main_window_toggle_work_offline(mainwin, GTK_CHECK_MENU_ITEM(widget)->active);
2959 }
2960
2961 static void online_switch_clicked (GtkButton *btn, gpointer data) 
2962 {
2963         MainWindow *mainwin;
2964         GtkItemFactory *ifactory;
2965         GtkCheckMenuItem *menuitem;
2966
2967         mainwin = (MainWindow *) data;
2968         
2969         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2970         menuitem = GTK_CHECK_MENU_ITEM (gtk_item_factory_get_widget(ifactory, "/File/Work offline"));
2971         
2972         g_return_if_fail(mainwin != NULL);
2973         g_return_if_fail(menuitem != NULL);
2974         
2975         if (btn == GTK_BUTTON(mainwin->online_switch)) {
2976                 /* go offline */
2977                 gtk_widget_hide (mainwin->online_switch);
2978                 gtk_widget_show (mainwin->offline_switch);
2979                 menuitem->active = TRUE;
2980                 prefs_common.work_offline = TRUE;
2981                 inc_autocheck_timer_remove();           
2982         } else {
2983                 /*go online */
2984                 gtk_widget_hide (mainwin->offline_switch);
2985                 gtk_widget_show (mainwin->online_switch);
2986                 menuitem->active = FALSE;
2987                 prefs_common.work_offline = FALSE;
2988                 inc_autocheck_timer_set();
2989         }
2990 }
2991
2992 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2993                                 GtkWidget *widget)
2994 {
2995         addressbook_open(NULL);
2996 }
2997
2998 static void log_window_show_cb(MainWindow *mainwin, guint action,
2999                                GtkWidget *widget)
3000 {
3001         log_window_show(mainwin->logwin);
3002 }
3003
3004 static void sel_download_cb(MainWindow *mainwin, guint action,
3005                                GtkWidget *widget)
3006 {
3007         selective_download(mainwin);
3008 }
3009
3010 static void prefs_toolbar_cb(MainWindow *mainwin, guint action,
3011                              GtkWidget *widget)
3012 {
3013         prefs_toolbar_open((ToolbarType)action);
3014 }
3015
3016
3017 void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3018 {
3019         inc_mail(mainwin, prefs_common.newmail_notify_manu);
3020 }
3021
3022 void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
3023                                     GtkWidget *widget)
3024 {
3025         inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
3026 }
3027
3028 static void inc_cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3029 {
3030         inc_cancel_all();
3031 }
3032
3033 void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3034 {
3035         GList *list;
3036
3037         if (prefs_common.work_offline)
3038                 if (alertpanel(_("Offline warning"), 
3039                                _("You're working offline. Override?"),
3040                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
3041                 return;
3042
3043         for (list = folder_get_list(); list != NULL; list = list->next) {
3044                 Folder *folder = list->data;
3045
3046                 if (folder->queue) {
3047                         if (procmsg_send_queue
3048                                 (folder->queue, prefs_common.savemsg) < 0)
3049                                 alertpanel_error(_("Some errors occurred while sending queued messages."));
3050                         folder_item_scan(folder->queue);
3051                         folder_update_item(folder->queue, TRUE);
3052                 }
3053         }
3054 }
3055
3056 void compose_mail_cb(MainWindow *mainwin, guint action,
3057                             GtkWidget *widget)
3058 {
3059         PrefsAccount *ac = NULL;
3060         FolderItem *item = mainwin->summaryview->folder_item;   
3061         GList * list;
3062         GList * cur;
3063
3064         if (item) {
3065                 ac = account_find_from_item(item);
3066                 if (ac && ac->protocol != A_NNTP) {
3067                         compose_new_with_folderitem(ac, item);          /* CLAWS */
3068                         return;
3069                 }
3070         }
3071
3072         /*
3073          * CLAWS - use current account
3074          */
3075         if (cur_account && (cur_account->protocol != A_NNTP)) {
3076                 compose_new_with_folderitem(cur_account, item);
3077                 return;
3078         }
3079
3080         /*
3081          * CLAWS - just get the first one
3082          */
3083         list = account_get_list();
3084         for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
3085                 ac = (PrefsAccount *) cur->data;
3086                 if (ac->protocol != A_NNTP) {
3087                         compose_new_with_folderitem(ac, item);
3088                         return;
3089                 }
3090         }
3091 }
3092
3093 void compose_news_cb(MainWindow *mainwin, guint action,
3094                             GtkWidget *widget)
3095 {
3096         PrefsAccount * ac = NULL;
3097         GList * list;
3098         GList * cur;
3099
3100         if (mainwin->summaryview->folder_item) {
3101                 ac = mainwin->summaryview->folder_item->folder->account;
3102                 if (ac && ac->protocol == A_NNTP) {
3103                         compose_new(ac,
3104                                     mainwin->summaryview->folder_item->path,
3105                                     NULL);
3106                         return;
3107                 }
3108         }
3109
3110         list = account_get_list();
3111         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
3112                 ac = (PrefsAccount *) cur->data;
3113                 if (ac->protocol == A_NNTP) {
3114                         compose_new(ac, NULL, NULL);
3115                         return;
3116                 }
3117         }
3118 }
3119
3120 void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3121 {
3122         summary_reply(mainwin->summaryview, (ComposeMode)action);
3123 }
3124
3125 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3126 {
3127         summary_move_to(mainwin->summaryview);
3128 }
3129
3130 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3131 {
3132         summary_copy_to(mainwin->summaryview);
3133 }
3134
3135 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3136 {
3137         summary_delete(mainwin->summaryview);
3138 }
3139
3140 static void cancel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3141 {
3142         summary_cancel(mainwin->summaryview);
3143 }
3144
3145 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3146 {
3147         summary_open_msg(mainwin->summaryview);
3148 }
3149
3150 static void view_source_cb(MainWindow *mainwin, guint action,
3151                            GtkWidget *widget)
3152 {
3153         summary_view_source(mainwin->summaryview);
3154 }
3155
3156 static void show_all_header_cb(MainWindow *mainwin, guint action,
3157                                GtkWidget *widget)
3158 {
3159         if (mainwin->menu_lock_count) return;
3160         summary_display_msg_selected(mainwin->summaryview,
3161                                      GTK_CHECK_MENU_ITEM(widget)->active);
3162 }
3163
3164 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3165 {
3166         summary_reedit(mainwin->summaryview);
3167 }
3168
3169 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3170 {
3171         summary_mark(mainwin->summaryview);
3172 }
3173
3174 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3175 {
3176         summary_unmark(mainwin->summaryview);
3177 }
3178
3179 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
3180                               GtkWidget *widget)
3181 {
3182         summary_mark_as_unread(mainwin->summaryview);
3183 }
3184
3185 static void mark_as_read_cb(MainWindow *mainwin, guint action,
3186                             GtkWidget *widget)
3187 {
3188         summary_mark_as_read(mainwin->summaryview);
3189 }
3190
3191 static void mark_all_read_cb(MainWindow *mainwin, guint action,
3192                              GtkWidget *widget)
3193 {
3194         summary_mark_all_read(mainwin->summaryview);
3195 }
3196
3197 static void add_address_cb(MainWindow *mainwin, guint action,
3198                            GtkWidget *widget)
3199 {
3200         summary_add_address(mainwin->summaryview);
3201 }
3202
3203 static void set_charset_cb(MainWindow *mainwin, guint action,
3204                            GtkWidget *widget)
3205 {
3206         const gchar *str;
3207
3208         str = conv_get_charset_str((CharSet)action);
3209         g_free(prefs_common.force_charset);
3210         prefs_common.force_charset = str ? g_strdup(str) : NULL;
3211
3212         summary_redisplay_msg(mainwin->summaryview);
3213
3214         debug_print("forced charset: %s\n", str ? str : "Auto-Detect");
3215 }
3216
3217 static void hide_read_messages (MainWindow *mainwin, guint action,
3218                                 GtkWidget *widget)
3219 {
3220         if (!mainwin->summaryview->folder_item
3221             || gtk_object_get_data(GTK_OBJECT(widget), "dont_toggle"))
3222                 return;
3223         summary_toggle_show_read_messages(mainwin->summaryview);
3224 }
3225
3226 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3227 {
3228         if (mainwin->menu_lock_count) return;
3229         if (!mainwin->summaryview->folder_item) return;
3230
3231         if (GTK_CHECK_MENU_ITEM(widget)->active) {
3232                 summary_thread_build(mainwin->summaryview);
3233 /*              mainwin->summaryview->folder_item->threaded = TRUE; */
3234         } else {
3235                 summary_unthread(mainwin->summaryview);
3236 /*              mainwin->summaryview->folder_item->threaded = FALSE; */
3237         }
3238 }
3239
3240 static void expand_threads_cb(MainWindow *mainwin, guint action,
3241                               GtkWidget *widget)
3242 {
3243         summary_expand_threads(mainwin->summaryview);
3244 }
3245
3246 static void collapse_threads_cb(MainWindow *mainwin, guint action,
3247                                 GtkWidget *widget)
3248 {
3249         summary_collapse_threads(mainwin->summaryview);
3250 }
3251
3252 static void set_display_item_cb(MainWindow *mainwin, guint action,
3253                                 GtkWidget *widget)
3254 {
3255         prefs_summary_column_open();
3256 }
3257
3258 static void sort_summary_cb(MainWindow *mainwin, guint action,
3259                             GtkWidget *widget)
3260 {
3261         FolderItem *item = mainwin->summaryview->folder_item;
3262         GtkWidget *menuitem;
3263
3264         if (mainwin->menu_lock_count) return;
3265         if (item) {
3266                 menuitem = gtk_item_factory_get_item
3267                         (mainwin->menu_factory, "/View/Sort/Ascending");
3268                 summary_sort(mainwin->summaryview, (FolderSortKey)action,
3269                              GTK_CHECK_MENU_ITEM(menuitem)->active
3270                              ? SORT_ASCENDING : SORT_DESCENDING);
3271         }
3272 }
3273
3274 static void sort_summary_type_cb(MainWindow *mainwin, guint action,
3275                                  GtkWidget *widget)
3276 {
3277         FolderItem *item = mainwin->summaryview->folder_item;
3278
3279         if (mainwin->menu_lock_count) return;
3280         if (item)
3281                 summary_sort(mainwin->summaryview,
3282                              item->sort_key, (FolderSortType)action);
3283 }
3284
3285 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
3286                                   GtkWidget *widget)
3287 {
3288         summary_attract_by_subject(mainwin->summaryview);
3289 }
3290
3291 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
3292                                  GtkWidget *widget)
3293 {
3294         summary_delete_duplicated(mainwin->summaryview);
3295 }
3296
3297 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3298 {
3299         summary_filter(mainwin->summaryview);
3300 }
3301
3302 static void execute_summary_cb(MainWindow *mainwin, guint action,
3303                                GtkWidget *widget)
3304 {
3305         summary_execute(mainwin->summaryview);
3306 }
3307
3308 static void update_summary_cb(MainWindow *mainwin, guint action,
3309                               GtkWidget *widget)
3310 {
3311         FolderItem *fitem;
3312         FolderView *folderview = mainwin->folderview;
3313
3314         if (!mainwin->summaryview->folder_item) return;
3315         if (!folderview->opened) return;
3316
3317         folder_update_op_count();
3318
3319         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
3320                                             folderview->opened);
3321         if (!fitem) return;
3322
3323         folder_item_scan(fitem);
3324         summary_show(mainwin->summaryview, fitem);
3325 }
3326
3327 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3328 {
3329         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
3330 }
3331
3332 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3333 {
3334         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
3335 }
3336
3337 static void prev_unread_cb(MainWindow *mainwin, guint action,
3338                            GtkWidget *widget)
3339 {
3340         summary_select_prev_unread(mainwin->summaryview);
3341 }
3342
3343 void next_unread_cb(MainWindow *mainwin, guint action,
3344                            GtkWidget *widget)
3345 {
3346         summary_select_next_unread(mainwin->summaryview);
3347 }
3348
3349 static void prev_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3350 {
3351         summary_select_prev_new(mainwin->summaryview);
3352 }
3353
3354 static void next_new_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3355 {
3356         summary_select_next_new(mainwin->summaryview);
3357 }
3358
3359 static void prev_marked_cb(MainWindow *mainwin, guint action,
3360                            GtkWidget *widget)
3361 {
3362         summary_select_prev_marked(mainwin->summaryview);
3363 }
3364
3365 static void next_marked_cb(MainWindow *mainwin, guint action,
3366                            GtkWidget *widget)
3367 {
3368         summary_select_next_marked(mainwin->summaryview);
3369 }
3370
3371 static void prev_labeled_cb(MainWindow *mainwin, guint action,
3372                             GtkWidget *widget)
3373 {
3374         summary_select_prev_labeled(mainwin->summaryview);
3375 }
3376
3377 static void next_labeled_cb(MainWindow *mainwin, guint action,
3378                             GtkWidget *widget)
3379 {
3380         summary_select_next_labeled(mainwin->summaryview);
3381 }
3382
3383 static void goto_folder_cb(MainWindow *mainwin, guint action,
3384                            GtkWidget *widget)
3385 {
3386         FolderItem *to_folder;
3387
3388         to_folder = foldersel_folder_sel(NULL, FOLDER_SEL_ALL, NULL);
3389
3390         if (to_folder)
3391                 folderview_select(mainwin->folderview, to_folder);
3392 }
3393
3394 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3395 {
3396         messageview_copy_clipboard(mainwin->messageview);
3397 }
3398
3399 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
3400 {
3401         MessageView *msgview = mainwin->messageview;
3402
3403         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
3404                 summary_select_all(mainwin->summaryview);
3405         else if (messageview_is_visible(msgview) &&
3406                  (GTK_WIDGET_HAS_FOCUS(msgview->textview->text) ||
3407                   GTK_WIDGET_HAS_FOCUS(msgview->mimeview->textview->text)))
3408                 messageview_select_all(mainwin->messageview);
3409 }
3410
3411 static void select_thread_cb(MainWindow *mainwin, guint action,
3412                              GtkWidget *widget)
3413 {
3414         summary_select_thread(mainwin->summaryview);
3415 }
3416
3417 static void create_filter_cb(MainWindow *mainwin, guint action,
3418                              GtkWidget *widget)
3419 {
3420         summary_filter_open(mainwin->summaryview, (PrefsFilterType)action);
3421 }
3422
3423 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
3424                                  GtkWidget *widget)
3425 {
3426         prefs_common_open();
3427 }
3428
3429 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
3430                                   GtkWidget *widget)
3431 {
3432         prefs_scoring_open(NULL);
3433 }
3434
3435 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
3436                                     GtkWidget *widget)
3437 {
3438         prefs_filtering_open(NULL, NULL, NULL);
3439 }
3440
3441 static void prefs_template_open_cb(MainWindow *mainwin, guint action,
3442                                    GtkWidget *widget)
3443 {
3444         prefs_template_open();
3445 }
3446
3447 static void prefs_actions_open_cb(MainWindow *mainwin, guint action,
3448                                   GtkWidget *widget)
3449 {
3450         prefs_actions_open(mainwin);
3451 }
3452 #ifdef USE_OPENSSL
3453 static void ssl_manager_open_cb(MainWindow *mainwin, guint action,
3454                                   GtkWidget *widget)
3455 {
3456         ssl_manager_open(mainwin);
3457 }
3458 #endif
3459 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
3460                                   GtkWidget *widget)
3461 {
3462         if (!cur_account) {
3463                 new_account_cb(mainwin, 0, widget);
3464         } else {
3465                 account_open(cur_account);
3466         }
3467 }
3468
3469 static void new_account_cb(MainWindow *mainwin, guint action,
3470                            GtkWidget *widget)
3471 {
3472         account_edit_open();
3473         if (!compose_get_compose_list()) account_add();
3474 }
3475
3476 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
3477 {
3478         cur_account = (PrefsAccount *)data;
3479         main_window_reflect_prefs_all();
3480 }
3481
3482 static void manual_open_cb(MainWindow *mainwin, guint action,
3483                            GtkWidget *widget)
3484 {
3485         manual_open((ManualType)action);
3486 }
3487
3488 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
3489 {
3490         MainWindow *mainwin = (MainWindow *)data;
3491         gchar *str;
3492
3493         if (item->path)
3494                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
3495                                       LOCAL_FOLDER(folder)->rootpath,
3496                                       G_DIR_SEPARATOR,
3497                                       item->path);
3498         else
3499                 str = g_strdup_printf(_("Scanning folder %s ..."),
3500                                       LOCAL_FOLDER(folder)->rootpath);
3501
3502         STATUSBAR_PUSH(mainwin, str);
3503         STATUSBAR_POP(mainwin);
3504         g_free(str);
3505 }
3506
3507 #define BREAK_ON_MODIFIER_KEY() \
3508         if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) != 0) break
3509
3510 static void key_pressed (GtkWidget *widget, GdkEventKey *event, gpointer data)
3511 {
3512         MainWindow *mainwin = (MainWindow*) data;
3513         
3514         if (!mainwin || !event) return;
3515                 
3516         switch (event->keyval) {
3517         case GDK_Q:             /* Quit */
3518                 BREAK_ON_MODIFIER_KEY();
3519
3520                 app_exit_cb(mainwin, 0, NULL);
3521                 return;
3522         case GDK_space:
3523                 if (mainwin->folderview && mainwin->summaryview
3524                     && !mainwin->summaryview->displayed) {
3525                         summary_lock(mainwin->summaryview);
3526                         folderview_select_next_unread(mainwin->folderview);
3527                         summary_unlock(mainwin->summaryview);
3528                 }
3529                 break;
3530         default:
3531                 break;
3532         }
3533 }
3534
3535 #undef BREAK_ON_MODIFIER_KEY
3536
3537 /*
3538  * Harvest addresses for selected folder.
3539  */
3540 static void addr_harvest_cb( MainWindow *mainwin,
3541                             guint action,
3542                             GtkWidget *widget )
3543 {
3544         addressbook_harvest( mainwin->summaryview->folder_item, FALSE, NULL );
3545 }
3546
3547 /*
3548  * Harvest addresses for selected messages in summary view.
3549  */
3550 static void addr_harvest_msg_cb( MainWindow *mainwin,
3551                             guint action,
3552                             GtkWidget *widget )
3553 {
3554         summary_harvest_address( mainwin->summaryview );
3555 }
3556
3557 /*
3558 * End of Source.
3559 */
3560