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