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