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