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