b5a19fbee157e5ca655ed46504730de647f0c7b4
[claws.git] / src / mainwindow.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 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 <gtk/gtkmain.h>
24 #include <gtk/gtkwindow.h>
25 #include <gtk/gtkwidget.h>
26 #include <gtk/gtksignal.h>
27 #include <gtk/gtkvbox.h>
28 #include <gtk/gtkcontainer.h>
29 #include <gtk/gtkstatusbar.h>
30 #include <gtk/gtkhpaned.h>
31 #include <gtk/gtkvpaned.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkitemfactory.h>
34 #include <gtk/gtkeditable.h>
35 #include <gtk/gtkmenu.h>
36 #include <gtk/gtkmenuitem.h>
37 #include <gtk/gtkhandlebox.h>
38 #include <gtk/gtktoolbar.h>
39 #include <gtk/gtkbutton.h>
40 #include <string.h>
41
42 #include "intl.h"
43 #include "main.h"
44 #include "mainwindow.h"
45 #include "folderview.h"
46 #include "foldersel.h"
47 #include "summaryview.h"
48 #include "summary_search.h"
49 #include "messageview.h"
50 #include "headerview.h"
51 #include "menu.h"
52 #include "folder.h"
53 #include "inc.h"
54 #include "compose.h"
55 #include "procmsg.h"
56 #include "import.h"
57 #include "export.h"
58 #include "prefs_common.h"
59 #include "prefs_filter.h"
60 #include "prefs_filtering.h"
61 #include "prefs_scoring.h"
62 #include "prefs_account.h"
63 #include "prefs_folder_item.h"
64 #include "account.h"
65 #include "addressbook.h"
66 #include "headerwindow.h"
67 #include "logwindow.h"
68 #include "manage_window.h"
69 #include "alertpanel.h"
70 #include "statusbar.h"
71 #include "inputdialog.h"
72 #include "utils.h"
73 #include "gtkutils.h"
74 #include "codeconv.h"
75 #include "about.h"
76 #include "manual.h"
77
78 #define AC_LABEL_WIDTH  240
79
80 #define STATUSBAR_PUSH(mainwin, str) \
81 { \
82         gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar), \
83                            mainwin->mainwin_cid, str); \
84         gtkut_widget_wait_for_draw(mainwin->hbox_stat); \
85 }
86
87 #define STATUSBAR_POP(mainwin) \
88 { \
89         gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar), \
90                           mainwin->mainwin_cid); \
91 }
92
93 /* list of all instantiated MainWindow */
94 static GList *mainwin_list = NULL;
95
96 static GdkCursor *watch_cursor;
97
98 static void main_window_show_cur_account        (MainWindow     *mainwin);
99
100 static void main_window_set_widgets             (MainWindow     *mainwin,
101                                                  SeparateType    type);
102 static void main_window_toolbar_create          (MainWindow     *mainwin,
103                                                  GtkWidget      *container);
104
105 /* callback functions */
106 static void toolbar_inc_cb              (GtkWidget      *widget,
107                                          gpointer        data);
108 static void toolbar_inc_all_cb          (GtkWidget      *widget,
109                                          gpointer        data);
110 static void toolbar_send_cb             (GtkWidget      *widget,
111                                          gpointer        data);
112
113 static void toolbar_compose_cb          (GtkWidget      *widget,
114                                          gpointer        data);
115 static void toolbar_popup_compose_type_cb(GtkWidget     *widget,
116                                          gpointer        data);
117 static void toolbar_popup_compose_type_set(GtkWidget    *widget,
118                                          gpointer        data);
119 static void toolbar_compose_news_cb             (GtkWidget      *widget,
120                                          gpointer        data);
121 static void toolbar_compose_mail_cb             (GtkWidget      *widget,
122                                          gpointer        data);
123 static void toolbar_reply_cb            (GtkWidget      *widget,
124                                          gpointer        data);
125 static void toolbar_reply_to_all_cb     (GtkWidget      *widget,
126                                          gpointer        data);
127 static void toolbar_reply_to_sender_cb  (GtkWidget      *widget,
128                                          gpointer        data);
129 static void toolbar_forward_cb          (GtkWidget      *widget,
130                                          gpointer        data);
131
132 static void toolbar_delete_cb           (GtkWidget      *widget,
133                                          gpointer        data);
134 static void toolbar_exec_cb             (GtkWidget      *widget,
135                                          gpointer        data);
136
137 static void toolbar_next_unread_cb      (GtkWidget      *widget,
138                                          gpointer        data);
139
140 static void toolbar_prefs_cb            (GtkWidget      *widget,
141                                          gpointer        data);
142 static void toolbar_account_cb          (GtkWidget      *widget,
143                                          gpointer        data);
144
145 static void toolbar_account_button_pressed      (GtkWidget      *widget,
146                                                  GdkEventButton *event,
147                                                  gpointer        data);
148 static void ac_label_button_pressed             (GtkWidget      *widget,
149                                                  GdkEventButton *event,
150                                                  gpointer        data);
151
152 static gint main_window_close_cb (GtkWidget     *widget,
153                                   GdkEventAny   *event,
154                                   gpointer       data);
155
156 static void add_mailbox_cb       (MainWindow    *mainwin,
157                                   guint          action,
158                                   GtkWidget     *widget);
159 static void add_mbox_cb          (MainWindow    *mainwin,
160                                   guint          action,
161                                   GtkWidget     *widget);
162 static void update_folderview_cb (MainWindow    *mainwin,
163                                   guint          action,
164                                   GtkWidget     *widget);
165 static void new_folder_cb        (MainWindow    *mainwin,
166                                   guint          action,
167                                   GtkWidget     *widget);
168 static void rename_folder_cb     (MainWindow    *mainwin,
169                                   guint          action,
170                                   GtkWidget     *widget);
171 static void delete_folder_cb     (MainWindow    *mainwin,
172                                   guint          action,
173                                   GtkWidget     *widget);
174 static void import_mbox_cb       (MainWindow    *mainwin,
175                                   guint          action,
176                                   GtkWidget     *widget);
177 static void export_mbox_cb       (MainWindow    *mainwin,
178                                   guint          action,
179                                   GtkWidget     *widget);
180 static void empty_trash_cb       (MainWindow    *mainwin,
181                                   guint          action,
182                                   GtkWidget     *widget);
183
184 static void save_as_cb           (MainWindow    *mainwin,
185                                   guint          action,
186                                   GtkWidget     *widget);
187 static void print_cb             (MainWindow    *mainwin,
188                                   guint          action,
189                                   GtkWidget     *widget);
190 static void app_exit_cb          (MainWindow    *mainwin,
191                                   guint          action,
192                                   GtkWidget     *widget);
193
194 static void toggle_folder_cb     (MainWindow    *mainwin,
195                                   guint          action,
196                                   GtkWidget     *widget);
197 static void toggle_message_cb    (MainWindow    *mainwin,
198                                   guint          action,
199                                   GtkWidget     *widget);
200 static void toggle_toolbar_cb    (MainWindow    *mainwin,
201                                   guint          action,
202                                   GtkWidget     *widget);
203 static void toggle_statusbar_cb  (MainWindow    *mainwin,
204                                   guint          action,
205                                   GtkWidget     *widget);
206 static void separate_widget_cb(GtkCheckMenuItem *checkitem, guint action);
207
208 static void addressbook_open_cb (MainWindow     *mainwin,
209                                  guint           action,
210                                  GtkWidget      *widget);
211 static void log_window_show_cb  (MainWindow     *mainwin,
212                                  guint           action,
213                                  GtkWidget      *widget);
214
215 static void inc_mail_cb                 (MainWindow     *mainwin,
216                                          guint           action,
217                                          GtkWidget      *widget);
218 static void inc_all_account_mail_cb     (MainWindow     *mainwin,
219                                          guint           action,
220                                          GtkWidget      *widget);
221
222 static void send_queue_cb               (MainWindow     *mainwin,
223                                          guint           action,
224                                          GtkWidget      *widget);
225
226 static void compose_cb                  (MainWindow     *mainwin,
227                                          guint           action,
228                                          GtkWidget      *widget);
229 static void compose_mail_cb(MainWindow *mainwin, guint action,
230                             GtkWidget *widget);
231 static void compose_news_cb(MainWindow *mainwin, guint action,
232                             GtkWidget *widget);
233 static void reply_cb                    (MainWindow     *mainwin,
234                                          guint           action,
235                                          GtkWidget      *widget);
236
237 static void open_msg_cb                 (MainWindow     *mainwin,
238                                          guint           action,
239                                          GtkWidget      *widget);
240
241 static void view_source_cb              (MainWindow     *mainwin,
242                                          guint           action,
243                                          GtkWidget      *widget);
244
245 static void reedit_cb                   (MainWindow     *mainwin,
246                                          guint           action,
247                                          GtkWidget      *widget);
248
249 static void move_to_cb                  (MainWindow     *mainwin,
250                                          guint           action,
251                                          GtkWidget      *widget);
252 static void copy_to_cb                  (MainWindow     *mainwin,
253                                          guint           action,
254                                          GtkWidget      *widget);
255 static void delete_cb                   (MainWindow     *mainwin,
256                                          guint           action,
257                                          GtkWidget      *widget);
258
259 static void mark_cb                     (MainWindow     *mainwin,
260                                          guint           action,
261                                          GtkWidget      *widget);
262 static void unmark_cb                   (MainWindow     *mainwin,
263                                          guint           action,
264                                          GtkWidget      *widget);
265
266 static void mark_as_unread_cb           (MainWindow     *mainwin,
267                                          guint           action,
268                                          GtkWidget      *widget);
269 static void mark_as_read_cb             (MainWindow     *mainwin,
270                                          guint           action,
271                                          GtkWidget      *widget);
272
273 static void set_charset_cb              (MainWindow     *mainwin,
274                                          guint           action,
275                                          GtkWidget      *widget);
276
277 static void thread_cb            (MainWindow    *mainwin,
278                                   guint          action,
279                                   GtkWidget     *widget);
280 static void set_display_item_cb  (MainWindow    *mainwin,
281                                   guint          action,
282                                   GtkWidget     *widget);
283 static void sort_summary_cb      (MainWindow    *mainwin,
284                                   guint          action,
285                                   GtkWidget     *widget);
286 static void attract_by_subject_cb(MainWindow    *mainwin,
287                                   guint          action,
288                                   GtkWidget     *widget);
289
290 static void delete_duplicated_cb (MainWindow    *mainwin,
291                                   guint          action,
292                                   GtkWidget     *widget);
293 static void filter_cb            (MainWindow    *mainwin,
294                                   guint          action,
295                                   GtkWidget     *widget);
296 static void execute_summary_cb   (MainWindow    *mainwin,
297                                   guint          action,
298                                   GtkWidget     *widget);
299 static void update_summary_cb    (MainWindow    *mainwin,
300                                   guint          action,
301                                   GtkWidget     *widget);
302
303 static void prev_cb              (MainWindow    *mainwin,
304                                   guint          action,
305                                   GtkWidget     *widget);
306 static void next_cb              (MainWindow    *mainwin,
307                                   guint          action,
308                                   GtkWidget     *widget);
309
310 static void next_unread_cb       (MainWindow    *mainwin,
311                                   guint          action,
312                                   GtkWidget     *widget);
313
314 static void next_marked_cb       (MainWindow    *mainwin,
315                                   guint          action,
316                                   GtkWidget     *widget);
317
318 static void prev_marked_cb       (MainWindow    *mainwin,
319                                   guint          action,
320                                   GtkWidget     *widget);
321
322 static void goto_folder_cb       (MainWindow    *mainwin,
323                                   guint          action,
324                                   GtkWidget     *widget);
325
326 static void copy_cb              (MainWindow    *mainwin,
327                                   guint          action,
328                                   GtkWidget     *widget);
329 static void allsel_cb            (MainWindow    *mainwin,
330                                   guint          action,
331                                   GtkWidget     *widget);
332
333 static void prefs_common_open_cb (MainWindow    *mainwin,
334                                   guint          action,
335                                   GtkWidget     *widget);
336 static void prefs_filter_open_cb (MainWindow    *mainwin,
337                                   guint          action,
338                                   GtkWidget     *widget);
339 static void prefs_scoring_open_cb (MainWindow   *mainwin,
340                                   guint          action,
341                                   GtkWidget     *widget);
342 static void prefs_filtering_open_cb (MainWindow *mainwin,
343                                   guint          action,
344                                   GtkWidget     *widget);
345 static void prefs_account_open_cb(MainWindow    *mainwin,
346                                   guint          action,
347                                   GtkWidget     *widget);
348 static void new_account_cb       (MainWindow    *mainwin,
349                                   guint          action,
350                                   GtkWidget     *widget);
351
352 static void account_menu_cb      (GtkMenuItem   *menuitem,
353                                   gpointer       data);
354
355 static void manual_open_cb       (MainWindow    *mainwin,
356                                   guint          action,
357                                   GtkWidget     *widget);
358
359 static void scan_tree_func       (Folder        *folder,
360                                   FolderItem    *item,
361                                   gpointer       data);
362                                   
363 static void activate_compose_button (MainWindow *mainwin,
364                                 ToolbarStyle      style,
365                                 ComposeButtonType type);
366
367 #define  SEPARATE_ACTION  667
368
369 static GtkItemFactoryEntry mainwin_entries[] =
370 {
371         {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
372         {N_("/_File/_Add mailbox..."),          NULL, add_mailbox_cb, 0, NULL},
373         {N_("/_File/_Add mbox mailbox..."),     NULL, add_mbox_cb, 0, NULL},
374         {N_("/_File/_Update folder tree"),      NULL, update_folderview_cb, 0, NULL},
375         {N_("/_File/_Folder"),                  NULL, NULL, 0, "<Branch>"},
376         {N_("/_File/_Folder/Create _new folder..."),
377                                                 NULL, new_folder_cb, 0, NULL},
378         {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
379         {N_("/_File/_Folder/_Delete folder"),   NULL, delete_folder_cb, 0, NULL},
380         {N_("/_File/_Import mbox file..."),     NULL, import_mbox_cb, 0, NULL},
381         {N_("/_File/_Export to mbox file..."),  NULL, export_mbox_cb, 0, NULL},
382         {N_("/_File/Empty _trash"),             NULL, empty_trash_cb, 0, NULL},
383         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
384         {N_("/_File/_Save as..."),              NULL, save_as_cb, 0, NULL},
385         {N_("/_File/_Print..."),                "<alt>P", print_cb, 0, NULL},
386         {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
387         {N_("/_File/_Close"),                   "<alt>W", app_exit_cb, 0, NULL},
388         {N_("/_File/E_xit"),                    "<alt>Q", app_exit_cb, 0, NULL},
389
390         {N_("/_Edit"),                          NULL, NULL, 0, "<Branch>"},
391         {N_("/_Edit/_Copy"),                    "<control>C", copy_cb, 0, NULL},
392         {N_("/_Edit/Select _all"),              "<control>A", allsel_cb, 0, NULL},
393         {N_("/_Edit/---"),                      NULL, NULL, 0, "<Separator>"},
394         {N_("/_Edit/_Search"),                  "<control>S", summary_search_cb, 0, NULL},
395
396         {N_("/_View"),                          NULL, NULL, 0, "<Branch>"},
397         {N_("/_View/_Folder tree"),             NULL, toggle_folder_cb, 0, "<ToggleItem>"},
398         {N_("/_View/_Message view"),            NULL, toggle_message_cb, 0, "<ToggleItem>"},
399         {N_("/_View/_Toolbar"),                 NULL, NULL, 0, "<Branch>"},
400         {N_("/_View/_Toolbar/Icon _and text"),  NULL, toggle_toolbar_cb, TOOLBAR_BOTH, "<RadioItem>"},
401         {N_("/_View/_Toolbar/_Icon"),           NULL, toggle_toolbar_cb, TOOLBAR_ICON, "/View/Toolbar/Icon and text"},
402         {N_("/_View/_Toolbar/_Text"),           NULL, toggle_toolbar_cb, TOOLBAR_TEXT, "/View/Toolbar/Icon and text"},
403         {N_("/_View/_Toolbar/_None"),           NULL, toggle_toolbar_cb, TOOLBAR_NONE, "/View/Toolbar/Icon and text"},
404         {N_("/_View/_Status bar"),              NULL, toggle_statusbar_cb, 0, "<ToggleItem>"},
405         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
406         {N_("/_View/Separate f_older tree"),    NULL, NULL, SEPARATE_ACTION + SEPARATE_FOLDER, "<ToggleItem>"},
407         {N_("/_View/Separate m_essage view"),   NULL, NULL, SEPARATE_ACTION + SEPARATE_MESSAGE, "<ToggleItem>"},
408         {N_("/_View/---"),                      NULL, NULL, 0, "<Separator>"},
409         {N_("/_View/_Code set"),                NULL, NULL, 0, "<Branch>"},
410         {N_("/_View/_Code set/_Auto detect"),
411          NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
412
413 #define CODESET_SEPARATOR \
414         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"}
415 #define CODESET_ACTION(action) \
416          NULL, set_charset_cb, action, "/View/Code set/Auto detect"
417
418         {N_("/_View/_Code set/---"),            NULL, NULL, 0, "<Separator>"},
419         {N_("/_View/_Code set/7bit ascii (US-ASC_II)"),
420          CODESET_ACTION(C_US_ASCII)},
421
422 #if HAVE_LIBJCONV
423         {N_("/_View/_Code set/Unicode (_UTF-8)"),
424          CODESET_ACTION(C_UTF_8)},
425         CODESET_SEPARATOR,
426 #endif
427         {N_("/_View/_Code set/Western European (ISO-8859-_1)"),
428          CODESET_ACTION(C_ISO_8859_1)},
429         CODESET_SEPARATOR,
430 #if HAVE_LIBJCONV
431         {N_("/_View/_Code set/Central European (ISO-8859-_2)"),
432          CODESET_ACTION(C_ISO_8859_2)},
433         CODESET_SEPARATOR,
434         {N_("/_View/_Code set/_Baltic (ISO-8859-13)"),
435          CODESET_ACTION(C_ISO_8859_13)},
436         {N_("/_View/_Code set/Baltic (ISO-8859-_4)"),
437          CODESET_ACTION(C_ISO_8859_4)},
438         CODESET_SEPARATOR,
439         {N_("/_View/_Code set/Greek (ISO-8859-_7)"),
440          CODESET_ACTION(C_ISO_8859_7)},
441         CODESET_SEPARATOR,
442         {N_("/_View/_Code set/Turkish (ISO-8859-_9)"),
443          CODESET_ACTION(C_ISO_8859_9)},
444         CODESET_SEPARATOR,
445         {N_("/_View/_Code set/Cyrillic (ISO-8859-_5)"),
446          CODESET_ACTION(C_ISO_8859_5)},
447         {N_("/_View/_Code set/Cyrillic (KOI8-_R)"),
448          CODESET_ACTION(C_KOI8_R)},
449         {N_("/_View/_Code set/Cyrillic (Windows-1251)"),
450          CODESET_ACTION(C_CP1251)},
451         CODESET_SEPARATOR,
452 #endif
453         {N_("/_View/_Code set/Japanese (ISO-2022-_JP)"),
454          CODESET_ACTION(C_ISO_2022_JP)},
455 #if HAVE_LIBJCONV
456         {N_("/_View/_Code set/Japanese (ISO-2022-JP-2)"),
457          CODESET_ACTION(C_ISO_2022_JP_2)},
458 #endif
459         {N_("/_View/_Code set/Japanese (_EUC-JP)"),
460          CODESET_ACTION(C_EUC_JP)},
461         {N_("/_View/_Code set/Japanese (_Shift__JIS)"),
462          CODESET_ACTION(C_SHIFT_JIS)},
463 #if HAVE_LIBJCONV
464         CODESET_SEPARATOR,
465         {N_("/_View/_Code set/Simplified Chinese (_GB2312)"),
466          CODESET_ACTION(C_GB2312)},
467         {N_("/_View/_Code set/Traditional Chinese (_Big5)"),
468          CODESET_ACTION(C_BIG5)},
469         {N_("/_View/_Code set/Traditional Chinese (EUC-_TW)"),
470          CODESET_ACTION(C_EUC_TW)},
471         {N_("/_View/_Code set/Chinese (ISO-2022-_CN)"),
472          CODESET_ACTION(C_ISO_2022_CN)},
473         CODESET_SEPARATOR,
474         {N_("/_View/_Code set/Korean (EUC-_KR)"),
475          CODESET_ACTION(C_EUC_KR)},
476         {N_("/_View/_Code set/Korean (ISO-2022-KR)"),
477          CODESET_ACTION(C_ISO_2022_KR)},
478 #endif
479
480 #undef CODESET_SEPARATOR
481 #undef CODESET_ACTION
482
483         {N_("/_Message"),                       NULL, NULL, 0, "<Branch>"},
484         {N_("/_Message/Get new ma_il"),         "<alt>I",       inc_mail_cb, 0, NULL},
485         {N_("/_Message/Get from _all accounts"),
486                                                 "<shift><alt>I", inc_all_account_mail_cb, 0, NULL},
487         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
488         {N_("/_Message/Send queued messa_ges"),
489                                                 NULL, send_queue_cb, 0, NULL},
490         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
491         {N_("/_Message/Compose a_n email message"),     "<alt>N", compose_mail_cb, 0, NULL},
492         {N_("/_Message/Compose a news message"),        NULL,   compose_news_cb, 0, NULL},
493         {N_("/_Message/_Reply"),                "<alt>R",       reply_cb, COMPOSE_REPLY, NULL},
494         {N_("/_Message/Repl_y to sender"),      "<control><alt>R", reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
495         {N_("/_Message/Follow-up and reply to"), NULL, reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
496         {N_("/_Message/Reply to a_ll"),         "<shift><alt>R", reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
497         {N_("/_Message/_Forward"),              "<control>F", reply_cb, COMPOSE_FORWARD, NULL},
498         {N_("/_Message/Forward as a_ttachment"),
499                                                 "<shift><control>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
500         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
501         {N_("/_Message/M_ove..."),              "<alt>O", move_to_cb, 0, NULL},
502         {N_("/_Message/_Copy..."),              NULL, copy_to_cb, 0, NULL},
503         {N_("/_Message/_Delete"),               "<alt>D", delete_cb,  0, NULL},
504         {N_("/_Message/_Mark"),                 NULL, NULL, 0, "<Branch>"},
505         {N_("/_Message/_Mark/_Mark"),           NULL, mark_cb,   0, NULL},
506         {N_("/_Message/_Mark/_Unmark"),         NULL, unmark_cb, 0, NULL},
507         {N_("/_Message/_Mark/---"),             NULL, NULL, 0, "<Separator>"},
508         {N_("/_Message/_Mark/Mark as unr_ead"), NULL, mark_as_unread_cb, 0, NULL},
509         {N_("/_Message/_Mark/Mark as rea_d"),
510                                                 NULL, mark_as_read_cb, 0, NULL},
511         {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
512         {N_("/_Message/Open in new _window"),   "<shift><control>N", open_msg_cb, 0, NULL},
513         {N_("/_Message/View _source"),          "<control>U", view_source_cb, 0, NULL},
514         {N_("/_Message/Show all _header"),      "<control>H", header_window_show_cb, 0, NULL},
515         {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
516
517         {N_("/_Summary"),                       NULL, NULL, 0, "<Branch>"},
518         {N_("/_Summary/_Delete duplicated messages"),
519                                                 NULL, delete_duplicated_cb,   0, NULL},
520         {N_("/_Summary/_Filter messages"),      NULL, filter_cb, 0, NULL},
521         {N_("/_Summary/E_xecute"),              "<alt>X", execute_summary_cb, 0, NULL},
522         {N_("/_Summary/_Update"),               "<alt>U", update_summary_cb,  0, NULL},
523         {N_("/_Summary/---"),                   NULL, NULL, 0, "<Separator>"},
524         {N_("/_Summary/_Prev message"),         NULL, prev_cb, 0, NULL},
525         {N_("/_Summary/_Next message"),         NULL, next_cb, 0, NULL},
526         {N_("/_Summary/N_ext unread message"),  NULL, next_unread_cb, 0, NULL},
527         {N_("/_Summary/Prev marked message"),   NULL, prev_marked_cb, 0, NULL},
528         {N_("/_Summary/Next marked message"),   NULL, next_marked_cb, 0, NULL},
529         {N_("/_Summary/---"),                   NULL, NULL, 0, "<Separator>"},
530         {N_("/_Summary/_Go to other folder"),   "<alt>G", goto_folder_cb, 0, NULL},
531         {N_("/_Summary/---"),                   NULL, NULL, 0, "<Separator>"},
532         {N_("/_Summary/_Sort"),                 NULL, NULL, 0, "<Branch>"},
533         {N_("/_Summary/_Sort/Sort by _number"), NULL, sort_summary_cb, SORT_BY_NUMBER, NULL},
534         {N_("/_Summary/_Sort/Sort by s_ize"),   NULL, sort_summary_cb, SORT_BY_SIZE, NULL},
535         {N_("/_Summary/_Sort/Sort by _date"),   NULL, sort_summary_cb, SORT_BY_DATE, NULL},
536         {N_("/_Summary/_Sort/Sort by _from"),   NULL, sort_summary_cb, SORT_BY_FROM, NULL},
537         {N_("/_Summary/_Sort/Sort by _subject"),NULL, sort_summary_cb, SORT_BY_SUBJECT, NULL},
538         {N_("/_Summary/_Sort/Sort by sco_re"),  NULL, sort_summary_cb, SORT_BY_SCORE, NULL},
539         {N_("/_Summary/_Sort/Sort by _label"),  NULL, sort_summary_cb, SORT_BY_LABEL, NULL},
540         {N_("/_Summary/_Sort/---"),             NULL, NULL, 0, "<Separator>"},
541         {N_("/_Summary/_Sort/_Attract by subject"),
542                                                 NULL, attract_by_subject_cb, 0, NULL},
543         {N_("/_Summary/_Thread view"),          "<control>T",        thread_cb, 0, NULL},
544         {N_("/_Summary/Unt_hread view"),        "<shift><control>T", thread_cb, 1, NULL},
545         {N_("/_Summary/Set display _item..."),  NULL, set_display_item_cb, 0, NULL},
546
547         {N_("/_Tool"),                          NULL, NULL, 0, "<Branch>"},
548         {N_("/_Tool/_Address book"),            "<alt>A", addressbook_open_cb, 0, NULL},
549         {N_("/_Tool/_Log window"),              "<alt>L", log_window_show_cb, 0, NULL},
550
551         {N_("/_Configuration"),                 NULL, NULL, 0, "<Branch>"},
552         {N_("/_Configuration/_Common preferences..."),
553                                                 NULL, prefs_common_open_cb, 0, NULL},
554         {N_("/_Configuration/_Filter setting..."),
555                                                 NULL, prefs_filter_open_cb, 0, NULL},
556         {N_("/_Configuration/_Scoring ..."),
557                                                 NULL, prefs_scoring_open_cb, 0, NULL},
558         {N_("/_Configuration/_Filtering ..."),
559                                                 NULL, prefs_filtering_open_cb, 0, NULL},
560         {N_("/_Configuration/_Preferences per account..."),
561                                                 NULL, prefs_account_open_cb, 0, NULL},
562         {N_("/_Configuration/---"),             NULL, NULL, 0, "<Separator>"},
563         {N_("/_Configuration/Create _new account..."),
564                                                 NULL, new_account_cb, 0, NULL},
565         {N_("/_Configuration/_Edit accounts..."),
566                                                 NULL, account_edit_open, 0, NULL},
567         {N_("/_Configuration/C_hange current account"),
568                                                 NULL, NULL, 0, "<Branch>"},
569
570         {N_("/_Help"),                          NULL, NULL, 0, "<LastBranch>"},
571         {N_("/_Help/_Manual"),                  NULL, NULL, 0, "<Branch>"},
572         {N_("/_Help/_Manual/_English"),         NULL, NULL, MANUAL_LANG_EN, NULL},
573         {N_("/_Help/_Manual/_Japanese"),        NULL, manual_open_cb, MANUAL_LANG_JA, NULL},
574         {N_("/_Help/---"),                      NULL, NULL, 0, "<Separator>"},
575         {N_("/_Help/_About"),                   NULL, about_show, 0, NULL}
576 };
577
578 MainWindow *main_window_create(SeparateType type)
579 {
580         MainWindow *mainwin;
581         GtkWidget *window;
582         GtkWidget *vbox;
583         GtkWidget *menubar;
584         GtkWidget *handlebox;
585         GtkWidget *vbox_body;
586         GtkWidget *hbox_stat;
587         GtkWidget *statusbar;
588         GtkWidget *ac_button;
589         GtkWidget *ac_label;
590
591         FolderView *folderview;
592         SummaryView *summaryview;
593         MessageView *messageview;
594         GdkColormap *colormap;
595         GdkColor color[5];
596         gboolean success[5];
597         guint n_menu_entries;
598         GtkItemFactory *ifactory;
599         GtkWidget *ac_menu;
600         GtkWidget *menuitem;
601         gint i;
602
603         debug_print(_("Creating main window...\n"));
604         mainwin = g_new0(MainWindow, 1);
605
606         /* main window */
607         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
608         gtk_window_set_title(GTK_WINDOW(window), PROG_VERSION);
609         gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
610         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
611                            GTK_SIGNAL_FUNC(main_window_close_cb), mainwin);
612         gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
613                            GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
614         gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
615                            GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
616         gtk_widget_realize(window);
617
618         vbox = gtk_vbox_new(FALSE, 0);
619         gtk_widget_show(vbox);
620         gtk_container_add(GTK_CONTAINER(window), vbox);
621
622         /* menu bar */
623         n_menu_entries = sizeof(mainwin_entries) / sizeof(mainwin_entries[0]);
624         menubar = menubar_create(window, mainwin_entries, 
625                                  n_menu_entries, "<Main>", mainwin);
626         gtk_widget_show(menubar);
627         gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
628
629         handlebox = gtk_handle_box_new();
630         gtk_widget_show(handlebox);
631         gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
632
633         main_window_toolbar_create(mainwin, handlebox);
634
635         /* vbox that contains body */
636         vbox_body = gtk_vbox_new(FALSE, BORDER_WIDTH);
637         gtk_widget_show(vbox_body);
638         gtk_container_set_border_width(GTK_CONTAINER(vbox_body), BORDER_WIDTH);
639         gtk_box_pack_start(GTK_BOX(vbox), vbox_body, TRUE, TRUE, 0);
640
641         hbox_stat = gtk_hbox_new(FALSE, 2);
642         gtk_box_pack_end(GTK_BOX(vbox_body), hbox_stat, FALSE, FALSE, 0);
643
644         statusbar = statusbar_create();
645         gtk_box_pack_start(GTK_BOX(hbox_stat), statusbar, TRUE, TRUE, 0);
646
647         ac_button = gtk_button_new();
648         gtk_button_set_relief(GTK_BUTTON(ac_button), GTK_RELIEF_NONE);
649         GTK_WIDGET_UNSET_FLAGS(ac_button, GTK_CAN_FOCUS);
650         gtk_widget_set_usize(ac_button, -1, 1);
651         gtk_box_pack_end(GTK_BOX(hbox_stat), ac_button, FALSE, FALSE, 0);
652         gtk_signal_connect(GTK_OBJECT(ac_button), "button_press_event",
653                            GTK_SIGNAL_FUNC(ac_label_button_pressed), mainwin);
654
655         ac_label = gtk_label_new("");
656         gtk_container_add(GTK_CONTAINER(ac_button), ac_label);
657
658         gtk_widget_show_all(hbox_stat);
659
660         /* create views */
661         mainwin->folderview  = folderview  = folderview_create();
662         mainwin->summaryview = summaryview = summary_create();
663         mainwin->messageview = messageview = messageview_create();
664         mainwin->headerwin   = header_window_create();
665         mainwin->logwin      = log_window_create();
666
667         folderview->mainwin      = mainwin;
668         folderview->summaryview  = summaryview;
669
670         summaryview->mainwin     = mainwin;
671         summaryview->folderview  = folderview;
672         summaryview->messageview = messageview;
673         summaryview->headerwin   = mainwin->headerwin;
674         summaryview->window      = window;
675
676         messageview->mainwin     = mainwin;
677
678         mainwin->window    = window;
679         mainwin->vbox      = vbox;
680         mainwin->menubar   = menubar;
681         mainwin->handlebox = handlebox;
682         mainwin->vbox_body = vbox_body;
683         mainwin->hbox_stat = hbox_stat;
684         mainwin->statusbar = statusbar;
685         mainwin->ac_button = ac_button;
686         mainwin->ac_label  = ac_label;
687
688         /* set context IDs for status bar */
689         mainwin->mainwin_cid = gtk_statusbar_get_context_id
690                 (GTK_STATUSBAR(statusbar), "Main Window");
691         mainwin->folderview_cid = gtk_statusbar_get_context_id
692                 (GTK_STATUSBAR(statusbar), "Folder View");
693         mainwin->summaryview_cid = gtk_statusbar_get_context_id
694                 (GTK_STATUSBAR(statusbar), "Summary View");
695
696         /* allocate colors for summary view and folder view */
697         summaryview->color_marked.red = summaryview->color_marked.green = 0;
698         summaryview->color_marked.blue = (guint16)65535;
699
700         summaryview->color_dim.red = summaryview->color_dim.green =
701                 summaryview->color_dim.blue = COLOR_DIM;
702
703         summaryview->color_normal.red = summaryview->color_normal.green =
704                 summaryview->color_normal.blue = 0;
705
706         folderview->color_new.red = (guint16)55000;
707         folderview->color_new.green = folderview->color_new.blue = 15000;
708
709         folderview->color_normal.red = folderview->color_normal.green =
710                 folderview->color_normal.blue = 0;
711
712         summaryview->color_important.red = 0;
713         summaryview->color_marked.green = 0;
714         summaryview->color_important.blue = (guint16)65535;
715
716         color[0] = summaryview->color_marked;
717         color[1] = summaryview->color_dim;
718         color[2] = summaryview->color_normal;
719         color[3] = folderview->color_new;
720         color[4] = folderview->color_normal;
721
722         colormap = gdk_window_get_colormap(window->window);
723         gdk_colormap_alloc_colors(colormap, color, 5, FALSE, TRUE, success);
724         for (i = 0; i < 5; i++) {
725                 if (success[i] == FALSE)
726                         g_warning(_("MainWindow: color allocation %d failed\n"), i);
727         }
728
729         debug_print(_("done.\n"));
730
731         main_window_set_widgets(mainwin, type);
732
733         /* set menu items */
734         ifactory = gtk_item_factory_from_widget(menubar);
735         menuitem = gtk_item_factory_get_item
736                 (ifactory, "/View/Code set/Auto detect");
737         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
738
739         switch (prefs_common.toolbar_style) {
740         case TOOLBAR_NONE:
741                 menuitem = gtk_item_factory_get_item
742                         (ifactory, "/View/Toolbar/None");
743                 break;
744         case TOOLBAR_ICON:
745                 menuitem = gtk_item_factory_get_item
746                         (ifactory, "/View/Toolbar/Icon");
747                 break;
748         case TOOLBAR_TEXT:
749                 menuitem = gtk_item_factory_get_item
750                         (ifactory, "/View/Toolbar/Text");
751                 break;
752         case TOOLBAR_BOTH:
753                 menuitem = gtk_item_factory_get_item
754                         (ifactory, "/View/Toolbar/Icon and text");
755         }
756         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
757
758         gtk_widget_hide(mainwin->hbox_stat);
759         menuitem = gtk_item_factory_get_item(ifactory, "/View/Status bar");
760         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
761                                        prefs_common.show_statusbar);
762
763         /* set the check of the SEPARATE_xxx menu items. we also need the main window
764          * as a property and pass the action type to the callback */
765         menuitem = gtk_item_factory_get_widget_by_action(ifactory, SEPARATE_ACTION + SEPARATE_FOLDER);
766         g_assert(menuitem);
767         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), type & SEPARATE_FOLDER);
768         gtk_object_set_data(GTK_OBJECT(menuitem), "mainwindow", mainwin);
769         gtk_signal_connect(GTK_OBJECT(menuitem), "toggled", GTK_SIGNAL_FUNC(separate_widget_cb), 
770                                            GUINT_TO_POINTER(SEPARATE_FOLDER));
771
772         menuitem = gtk_item_factory_get_widget_by_action(ifactory, SEPARATE_ACTION + SEPARATE_MESSAGE);
773         g_assert(menuitem);
774         gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), type & SEPARATE_MESSAGE);
775         gtk_object_set_data(GTK_OBJECT(menuitem), "mainwindow", mainwin);
776         gtk_signal_connect(GTK_OBJECT(menuitem), "toggled", GTK_SIGNAL_FUNC(separate_widget_cb), 
777                                            GUINT_TO_POINTER(SEPARATE_MESSAGE));
778
779         /*
780         menu_set_sensitive(ifactory, "/Summary/Thread view",
781                            prefs_common.enable_thread ? FALSE : TRUE);
782         menu_set_sensitive(ifactory, "/Summary/Unthread view",
783                            prefs_common.enable_thread ? TRUE : FALSE);
784         */
785         main_window_set_thread_option(mainwin);
786
787         menu_set_sensitive(ifactory, "/Help/Manual/English", FALSE);
788
789         /* set account selection menu */
790         ac_menu = gtk_item_factory_get_widget
791                 (ifactory, "/Configuration/Change current account");
792         mainwin->ac_menu = ac_menu;
793
794         main_window_set_toolbar_sensitive(mainwin, FALSE);
795
796         /* show main window */
797         gtk_widget_set_uposition(mainwin->window,
798                                  prefs_common.mainwin_x,
799                                  prefs_common.mainwin_y);
800         gtk_widget_set_usize(window, prefs_common.mainwin_width,
801                              prefs_common.mainwin_height);
802         gtk_widget_show(mainwin->window);
803
804         /* initialize views */
805         folderview_init(folderview);
806         summary_init(summaryview);
807         messageview_init(messageview);
808         header_window_init(mainwin->headerwin);
809         log_window_init(mainwin->logwin);
810
811         {
812                 GtkStyle *newstyle;
813
814                 gtk_widget_ensure_style(folderview->ctree);
815                 newstyle = gtk_widget_get_style(folderview->ctree);
816                 newstyle = gtk_style_copy(newstyle);
817                 gtk_widget_set_style(summaryview->ctree, newstyle);
818                 gtk_widget_ensure_style(summaryview->ctree);
819                 gtk_widget_realize(summaryview->ctree);
820         }
821
822         mainwin->cursor_count = 0;
823
824         if (!watch_cursor)
825                 watch_cursor = gdk_cursor_new(GDK_WATCH);
826
827         mainwin_list = g_list_append(mainwin_list, mainwin);
828
829         return mainwin;
830 }
831
832 void main_window_cursor_wait(MainWindow *mainwin)
833 {
834         if (mainwin->cursor_count == 0)
835                 gdk_window_set_cursor(mainwin->window->window, watch_cursor);
836
837         mainwin->cursor_count++;
838
839         gdk_flush();
840 }
841
842 void main_window_cursor_normal(MainWindow *mainwin)
843 {
844         if (mainwin->cursor_count)
845                 mainwin->cursor_count--;
846
847         if (mainwin->cursor_count == 0)
848                 gdk_window_set_cursor(mainwin->window->window, NULL);
849
850         gdk_flush();
851 }
852
853 void main_window_reflect_prefs_all(void)
854 {
855         GList *cur;
856         MainWindow *mainwin;
857
858         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
859                 mainwin = (MainWindow *)cur->data;
860
861                 main_window_show_cur_account(mainwin);
862                 if (cur_account) {
863                         gtk_widget_set_sensitive(mainwin->get_btn,    TRUE);
864                         gtk_widget_set_sensitive(mainwin->getall_btn, TRUE);
865                 } else {
866                         gtk_widget_set_sensitive(mainwin->get_btn,    FALSE);
867                         gtk_widget_set_sensitive(mainwin->getall_btn, FALSE);
868                 }
869
870                 if (prefs_common.immediate_exec)
871                         gtk_widget_hide(mainwin->exec_btn);
872                 else
873                         gtk_widget_show(mainwin->exec_btn);
874
875                 summary_change_display_item(mainwin->summaryview);
876                 summary_redisplay_msg(mainwin->summaryview);
877                 headerview_set_visibility(mainwin->messageview->headerview,
878                                           prefs_common.display_header_pane);
879         }
880 }
881
882 void main_window_set_account_menu(GList *account_list)
883 {
884         GList *cur, *cur_ac, *cur_item;
885         GtkWidget *menuitem;
886         MainWindow *mainwin;
887         PrefsAccount *ac_prefs;
888
889         for (cur = mainwin_list; cur != NULL; cur = cur->next) {
890                 mainwin = (MainWindow *)cur->data;
891
892                 /* destroy all previous menu item */
893                 cur_item = GTK_MENU_SHELL(mainwin->ac_menu)->children;
894                 while (cur_item != NULL) {
895                         GList *next = cur_item->next;
896                         gtk_widget_destroy(GTK_WIDGET(cur_item->data));
897                         cur_item = next;
898                 }
899
900                 for (cur_ac = account_list; cur_ac != NULL;
901                      cur_ac = cur_ac->next) {
902                         ac_prefs = (PrefsAccount *)cur_ac->data;
903
904                         menuitem = gtk_menu_item_new_with_label
905                                 (ac_prefs->account_name
906                                  ? ac_prefs->account_name : _("Untitled"));
907                         gtk_widget_show(menuitem);
908                         gtk_menu_append(GTK_MENU(mainwin->ac_menu), menuitem);
909                         gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
910                                            GTK_SIGNAL_FUNC(account_menu_cb),
911                                            ac_prefs);
912                 }
913         }
914 }
915
916 static void main_window_show_cur_account(MainWindow *mainwin)
917 {
918         gchar *buf;
919         gchar *ac_name;
920
921         ac_name = g_strdup(cur_account
922                            ? (cur_account->account_name
923                               ? cur_account->account_name : _("Untitled"))
924                            : _("none"));
925
926         if (cur_account)
927                 buf = g_strdup_printf("%s - %s", ac_name, PROG_VERSION);
928         else
929                 buf = g_strdup(PROG_VERSION);
930         gtk_window_set_title(GTK_WINDOW(mainwin->window), buf);
931         g_free(buf);
932
933         buf = g_strdup_printf(_("Current account: %s"), ac_name);
934         gtk_label_set_text(GTK_LABEL(mainwin->ac_label), buf);
935         gtk_widget_queue_resize(mainwin->ac_button);
936         g_free(buf);
937
938         g_free(ac_name);
939 }
940
941 void main_window_separation_change(MainWindow *mainwin, SeparateType type)
942 {
943         GtkWidget *folder_wid  = GTK_WIDGET_PTR(mainwin->folderview);
944         GtkWidget *summary_wid = GTK_WIDGET_PTR(mainwin->summaryview);
945         GtkWidget *message_wid = GTK_WIDGET_PTR(mainwin->messageview);
946
947         if (mainwin->type == type) return;
948
949         /* remove widgets from those containers */
950         gtk_widget_ref(folder_wid);
951         gtk_widget_ref(summary_wid);
952         gtk_widget_ref(message_wid);
953         gtk_container_remove
954                 (GTK_CONTAINER(folder_wid->parent), folder_wid);
955         gtk_container_remove
956                 (GTK_CONTAINER(summary_wid->parent), summary_wid);
957         gtk_container_remove
958                 (GTK_CONTAINER(message_wid->parent), message_wid);
959
960         /* clean containers */
961         switch (mainwin->type) {
962         case SEPARATE_NONE:
963                 gtk_widget_destroy(mainwin->win.sep_none.hpaned);
964                 break;
965         case SEPARATE_FOLDER:
966                 gtk_widget_destroy(mainwin->win.sep_folder.vpaned);
967                 gtk_widget_destroy(mainwin->win.sep_folder.folderwin);
968                 break;
969         case SEPARATE_MESSAGE:
970                 gtk_widget_destroy(mainwin->win.sep_message.hpaned);
971                 gtk_widget_destroy(mainwin->win.sep_message.messagewin);
972                 break;
973         case SEPARATE_BOTH:
974                 gtk_widget_destroy(mainwin->win.sep_both.messagewin);
975                 gtk_widget_destroy(mainwin->win.sep_both.folderwin);
976                 break;
977         }
978
979         gtk_widget_hide(mainwin->window);
980         main_window_set_widgets(mainwin, type);
981         gtk_widget_show(mainwin->window);
982
983         gtk_widget_unref(folder_wid);
984         gtk_widget_unref(summary_wid);
985         gtk_widget_unref(message_wid);
986 }
987
988 void main_window_get_size(MainWindow *mainwin)
989 {
990         GtkAllocation *allocation;
991
992         allocation = &(GTK_WIDGET_PTR(mainwin->summaryview)->allocation);
993
994         prefs_common.summaryview_width  = allocation->width;
995
996         if (mainwin->summaryview->msg_is_toggled_on)
997                 prefs_common.summaryview_height = allocation->height;
998
999         prefs_common.mainview_width     = allocation->width;
1000
1001         allocation = &mainwin->window->allocation;
1002
1003         prefs_common.mainview_height = allocation->height;
1004         prefs_common.mainwin_width   = allocation->width;
1005         prefs_common.mainwin_height  = allocation->height;
1006
1007         allocation = &(GTK_WIDGET_PTR(mainwin->folderview)->allocation);
1008
1009         prefs_common.folderview_width  = allocation->width;
1010         prefs_common.folderview_height = allocation->height;
1011 }
1012
1013 void main_window_get_position(MainWindow *mainwin)
1014 {
1015         gint x, y;
1016
1017         gtkut_widget_get_uposition(mainwin->window, &x, &y);
1018
1019         prefs_common.mainview_x = x;
1020         prefs_common.mainview_y = y;
1021         prefs_common.mainwin_x = x;
1022         prefs_common.mainwin_y = y;
1023
1024         debug_print(_("window position: x = %d, y = %d\n"), x, y);
1025 }
1026
1027 void main_window_empty_trash(MainWindow *mainwin, gboolean confirm)
1028 {
1029         GList *list;
1030
1031         if (confirm) {
1032                 if (alertpanel(_("Empty trash"),
1033                                _("Empty all messages in trash?"),
1034                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1035                         return;
1036                 manage_window_focus_in(mainwin->window, NULL, NULL);
1037         }
1038
1039         procmsg_empty_trash();
1040
1041         for (list = folder_get_list(); list != NULL; list = list->next) {
1042                 Folder *folder;
1043
1044                 folder = list->data;
1045                 if (folder->trash) {
1046                         folder_item_scan(folder->trash);
1047                         folderview_update_item(folder->trash, TRUE);
1048                 }
1049         }
1050
1051         if (mainwin->summaryview->folder_item &&
1052             mainwin->summaryview->folder_item->stype == F_TRASH)
1053                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1054 }
1055
1056 void main_window_add_mailbox(MainWindow *mainwin)
1057 {
1058         gchar *path;
1059         Folder *folder;
1060
1061         path = input_dialog(_("Add mailbox"),
1062                             _("Input the location of mailbox.\n"
1063                               "If the existing mailbox is specified, it will be\n"
1064                               "scanned automatically."),
1065                             "Mail");
1066         if (!path) return;
1067         if (folder_find_from_path(path)) {
1068                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1069                 g_free(path);
1070                 return;
1071         }
1072
1073         if (!strcmp(path, "Mail"))
1074                 folder = folder_new(F_MH, _("Mailbox"), path);
1075         else
1076                 folder = folder_new(F_MH, g_basename(path), path);
1077
1078         g_free(path);
1079
1080         if (folder->create_tree(folder) < 0) {
1081                 alertpanel_error(_("Creation of the mailbox failed.\n"
1082                                    "Maybe some files already exist, or you don't have the permission to write there."));
1083                 folder_destroy(folder);
1084                 return;
1085         }
1086
1087         folder_add(folder);
1088         folder_set_ui_func(folder, scan_tree_func, mainwin);
1089         folder->scan_tree(folder);
1090         folder_set_ui_func(folder, NULL, NULL);
1091
1092         folderview_set(mainwin->folderview);
1093 }
1094
1095 void main_window_add_mbox(MainWindow *mainwin)
1096 {
1097         gchar *path;
1098         Folder *folder;
1099         FolderItem * item;
1100
1101         path = input_dialog(_("Add mbox mailbox"),
1102                             _("Input the location of mailbox."),
1103                             "mail");
1104
1105         if (!path) return;
1106
1107         if (folder_find_from_path(path)) {
1108                 alertpanel_error(_("The mailbox `%s' already exists."), path);
1109                 g_free(path);
1110                 return;
1111         }
1112
1113         /*
1114         if (!strcmp(path, "Mail"))
1115                 folder = folder_new(F_MBOX, _("Mailbox"), path);
1116                 else
1117         */
1118
1119         folder = folder_new(F_MBOX, g_basename(path), path);
1120         g_free(path);
1121
1122         if (folder->create_tree(folder) < 0) {
1123                 alertpanel_error(_("Creation of the mailbox failed."));
1124                 folder_destroy(folder);
1125                 return;
1126         }
1127
1128         folder_add(folder);
1129
1130         item = folder_item_new(folder->name, NULL);
1131         item->folder = folder;
1132         folder->node = g_node_new(item);
1133
1134         folder->create_folder(folder, item, "inbox");
1135         folder->create_folder(folder, item, "outbox");
1136         folder->create_folder(folder, item, "queue");
1137         folder->create_folder(folder, item, "draft");
1138         folder->create_folder(folder, item, "trash");
1139
1140         folderview_set(mainwin->folderview);
1141 }
1142
1143 void main_window_set_toolbar_sensitive(MainWindow *mainwin, gboolean sensitive)
1144 {
1145         gtk_widget_set_sensitive(mainwin->reply_btn,       sensitive);
1146         gtk_widget_set_sensitive(mainwin->replyall_btn,    sensitive);
1147         gtk_widget_set_sensitive(mainwin->replysender_btn, sensitive);
1148         gtk_widget_set_sensitive(mainwin->fwd_btn,         sensitive);
1149         gtk_widget_set_sensitive(mainwin->exec_btn,        sensitive);
1150         gtk_widget_set_sensitive(mainwin->next_btn,        sensitive);
1151
1152         if (!mainwin->summaryview->folder_item ||
1153             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1154                 gtk_widget_set_sensitive(mainwin->delete_btn, FALSE);
1155         else
1156                 gtk_widget_set_sensitive(mainwin->delete_btn, sensitive);
1157 }
1158
1159 void main_window_set_menu_sensitive(MainWindow *mainwin, gint selection)
1160 {
1161         GtkItemFactory *ifactory;
1162         gboolean sens;
1163         gboolean exec;
1164
1165         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
1166
1167         if (selection == SUMMARY_SELECTED_SINGLE)
1168                 sens = TRUE;
1169         else
1170                 sens = FALSE;
1171         if (!mainwin->summaryview->folder_item ||
1172             mainwin->summaryview->folder_item->folder->type == F_NEWS)
1173                 exec = FALSE;
1174         else
1175                 exec = TRUE;
1176
1177         menu_set_sensitive(ifactory, "/File/Save as...", sens);
1178         menu_set_sensitive(ifactory, "/Message/Reply", sens);
1179         menu_set_sensitive(ifactory, "/Message/Reply to sender", sens);
1180         menu_set_sensitive(ifactory, "/Message/Reply to all", sens);
1181         menu_set_sensitive(ifactory, "/Message/Forward", TRUE);
1182         menu_set_sensitive(ifactory, "/Message/Forward as attachment", TRUE);
1183         menu_set_sensitive(ifactory, "/Message/Open in new window", sens);
1184         menu_set_sensitive(ifactory, "/Message/Show all header", sens);
1185         menu_set_sensitive(ifactory, "/Message/View source", sens);
1186         if (sens && (!mainwin->summaryview->folder_item ||
1187                      mainwin->summaryview->folder_item->stype != F_DRAFT))
1188                 sens = FALSE;
1189         menu_set_sensitive(ifactory, "/Message/Re-edit", sens);
1190
1191         if (selection == SUMMARY_SELECTED_SINGLE ||
1192             selection == SUMMARY_SELECTED_MULTIPLE)
1193                 sens = TRUE;
1194         else
1195                 sens = FALSE;
1196
1197         menu_set_sensitive(ifactory, "/File/Print..."  , sens);
1198         menu_set_sensitive(ifactory, "/Message/Move...", sens && exec);
1199         menu_set_sensitive(ifactory, "/Message/Copy...", sens && exec);
1200         menu_set_sensitive(ifactory, "/Message/Delete" , sens && exec);
1201         menu_set_sensitive(ifactory, "/Message/Mark"   , sens);
1202
1203         if (selection != SUMMARY_NONE)
1204                 sens = TRUE;
1205         else
1206                 sens = FALSE;
1207
1208         menu_set_sensitive(ifactory, "/Summary/Delete duplicated messages", sens && exec);
1209         menu_set_sensitive(ifactory, "/Summary/Filter messages", sens && exec);
1210         menu_set_sensitive(ifactory, "/Summary/Execute", sens);
1211         menu_set_sensitive(ifactory, "/Summary/Prev message", sens);
1212         menu_set_sensitive(ifactory, "/Summary/Next message", sens);
1213         menu_set_sensitive(ifactory, "/Summary/Next unread message", sens);
1214         menu_set_sensitive(ifactory, "/Summary/Sort", sens);
1215
1216         if (mainwin->summaryview->folder_item &&
1217             mainwin->summaryview->folder_item->folder->account)
1218                 sens = mainwin->summaryview->folder_item->folder->account->protocol == A_NNTP;
1219         else
1220                 sens = FALSE;
1221         menu_set_sensitive(ifactory, "/Message/Follow-up and reply to", sens);
1222 }
1223
1224 void main_window_popup(MainWindow *mainwin)
1225 {
1226         gint x, y;
1227         gint sx, sy;
1228         GtkWidget *widget;
1229
1230         gdk_window_get_origin(mainwin->window->window, &x, &y);
1231         sx = gdk_screen_width();
1232         sy = gdk_screen_height();
1233         x %= sx; if (x < 0) x += sx;
1234         y %= sy; if (y < 0) y += sy;
1235         gdk_window_move(mainwin->window->window, x, y);
1236         gdk_window_raise(mainwin->window->window);
1237
1238         debug_print("window position: x = %d, y = %d\n", x, y);
1239
1240         switch (mainwin->type) {
1241         case SEPARATE_FOLDER:
1242                 widget = mainwin->win.sep_folder.folderwin;
1243                 gdk_window_get_origin(widget->window, &x, &y);
1244                 x %= sx; if (x < 0) x += sx;
1245                 y %= sy; if (y < 0) y += sy;
1246                 gdk_window_move(widget->window, x, y);
1247                 gdk_window_raise(widget->window);
1248                 break;
1249         case SEPARATE_MESSAGE:
1250                 widget = mainwin->win.sep_message.messagewin;
1251                 gdk_window_get_origin(widget->window, &x, &y);
1252                 x %= sx; if (x < 0) x += sx;
1253                 y %= sy; if (y < 0) y += sy;
1254                 gdk_window_move(widget->window, x, y);
1255                 gdk_window_raise(widget->window);
1256                 break;
1257         case SEPARATE_BOTH:
1258                 widget = mainwin->win.sep_both.folderwin;
1259                 gdk_window_get_origin(widget->window, &x, &y);
1260                 x %= sx; if (x < 0) x += sx;
1261                 y %= sy; if (y < 0) y += sy;
1262                 gdk_window_move(widget->window, x, y);
1263                 gdk_window_raise(widget->window);
1264                 widget = mainwin->win.sep_both.messagewin;
1265                 gdk_window_get_origin(widget->window, &x, &y);
1266                 x %= sx; if (x < 0) x += sx;
1267                 y %= sy; if (y < 0) y += sy;
1268                 gdk_window_move(widget->window, x, y);
1269                 gdk_window_raise(widget->window);
1270                 break;
1271         default:
1272                 break;
1273         }
1274 }
1275
1276 static void main_window_set_widgets(MainWindow *mainwin, SeparateType type)
1277 {
1278         GtkWidget *folderwin = NULL;
1279         GtkWidget *messagewin = NULL;
1280         GtkWidget *hpaned;
1281         GtkWidget *vpaned;
1282         GtkWidget *vbox_body = mainwin->vbox_body;
1283
1284         debug_print(_("Setting widgets..."));
1285
1286         /* create separated window(s) if needed */
1287         if (type & SEPARATE_FOLDER) {
1288                 folderwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1289                 gtk_window_set_policy(GTK_WINDOW(folderwin),
1290                                       TRUE, TRUE, FALSE);
1291                 gtk_widget_set_usize(folderwin, -1,
1292                                      prefs_common.mainview_height);
1293                 gtk_container_set_border_width(GTK_CONTAINER(folderwin),
1294                                                BORDER_WIDTH);
1295                 gtk_signal_connect(GTK_OBJECT(folderwin), "delete_event",
1296                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1297                                    NULL);
1298         }
1299         if (type & SEPARATE_MESSAGE) {
1300                 messagewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1301                 gtk_window_set_policy(GTK_WINDOW(messagewin),
1302                                       TRUE, TRUE, FALSE);
1303                 gtk_widget_set_usize
1304                         (messagewin, prefs_common.mainview_width,
1305                          prefs_common.mainview_height
1306                          - prefs_common.summaryview_height
1307                          + DEFAULT_HEADERVIEW_HEIGHT);
1308                 gtk_container_set_border_width(GTK_CONTAINER(messagewin),
1309                                                BORDER_WIDTH);
1310                 gtk_signal_connect(GTK_OBJECT(messagewin), "delete_event",
1311                                    GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete),
1312                                    NULL);
1313         }
1314
1315         switch (type) {
1316         case SEPARATE_NONE:
1317                 hpaned = gtk_hpaned_new();
1318                 gtk_widget_show(hpaned);
1319                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1320                 gtk_paned_add1(GTK_PANED(hpaned),
1321                                GTK_WIDGET_PTR(mainwin->folderview));
1322
1323                 vpaned = gtk_vpaned_new();
1324                 if (mainwin->summaryview->msg_is_toggled_on) {
1325                         gtk_paned_add2(GTK_PANED(hpaned), vpaned);
1326                         gtk_paned_add1(GTK_PANED(vpaned),
1327                                        GTK_WIDGET_PTR(mainwin->summaryview));
1328                 } else {
1329                         gtk_paned_add2(GTK_PANED(hpaned),
1330                                        GTK_WIDGET_PTR(mainwin->summaryview));
1331                         gtk_widget_ref(vpaned);
1332                 }
1333                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1334                                      prefs_common.summaryview_width,
1335                                      prefs_common.summaryview_height);
1336                 gtk_paned_add2(GTK_PANED(vpaned),
1337                                GTK_WIDGET_PTR(mainwin->messageview));
1338                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1339                                      prefs_common.mainview_width, -1);
1340                 gtk_widget_set_usize(mainwin->window,
1341                                      prefs_common.folderview_width +
1342                                      prefs_common.mainview_width,
1343                                      prefs_common.mainwin_height);
1344                 gtk_widget_show_all(vpaned);
1345
1346                 mainwin->win.sep_none.hpaned = hpaned;
1347                 mainwin->win.sep_none.vpaned = vpaned;
1348                 break;
1349         case SEPARATE_FOLDER:
1350                 vpaned = gtk_vpaned_new();
1351                 if (mainwin->summaryview->msg_is_toggled_on) {
1352                         gtk_box_pack_start(GTK_BOX(vbox_body), vpaned,
1353                                            TRUE, TRUE, 0);
1354                         gtk_paned_add1(GTK_PANED(vpaned),
1355                                        GTK_WIDGET_PTR(mainwin->summaryview));
1356                 } else {
1357                         gtk_box_pack_start(GTK_BOX(vbox_body),
1358                                            GTK_WIDGET_PTR(mainwin->summaryview),
1359                                            TRUE, TRUE, 0);
1360                         gtk_widget_ref(vpaned);
1361                 }
1362                 gtk_paned_add2(GTK_PANED(vpaned),
1363                                GTK_WIDGET_PTR(mainwin->messageview));
1364                 gtk_widget_show_all(vpaned);
1365                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1366                                      prefs_common.summaryview_width,
1367                                      prefs_common.summaryview_height);
1368                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->messageview),
1369                                      prefs_common.mainview_width, -1);
1370                 gtk_widget_set_usize(mainwin->window,
1371                                      prefs_common.mainview_width,
1372                                      prefs_common.mainview_height);
1373
1374                 gtk_container_add(GTK_CONTAINER(folderwin),
1375                                   GTK_WIDGET_PTR(mainwin->folderview));
1376
1377                 mainwin->win.sep_folder.folderwin = folderwin;
1378                 mainwin->win.sep_folder.vpaned    = vpaned;
1379
1380                 gtk_widget_show_all(folderwin);
1381                 break;
1382         case SEPARATE_MESSAGE:
1383                 hpaned = gtk_hpaned_new();
1384                 gtk_box_pack_start(GTK_BOX(vbox_body), hpaned, TRUE, TRUE, 0);
1385
1386                 gtk_paned_add1(GTK_PANED(hpaned),
1387                                GTK_WIDGET_PTR(mainwin->folderview));
1388                 gtk_paned_add2(GTK_PANED(hpaned),
1389                                GTK_WIDGET_PTR(mainwin->summaryview));
1390                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1391                                      prefs_common.summaryview_width,
1392                                      prefs_common.summaryview_height);
1393                 gtk_widget_set_usize(mainwin->window,
1394                                      prefs_common.folderview_width +
1395                                      prefs_common.mainview_width,
1396                                      prefs_common.mainwin_height);
1397                 gtk_widget_show_all(hpaned);
1398                 gtk_container_add(GTK_CONTAINER(messagewin),
1399                                   GTK_WIDGET_PTR(mainwin->messageview));
1400
1401                 mainwin->win.sep_message.messagewin = messagewin;
1402                 mainwin->win.sep_message.hpaned     = hpaned;
1403
1404                 gtk_widget_show_all(messagewin);
1405                 break;
1406         case SEPARATE_BOTH:
1407                 gtk_box_pack_start(GTK_BOX(vbox_body),
1408                                    GTK_WIDGET_PTR(mainwin->summaryview),
1409                                    TRUE, TRUE, 0);
1410                 gtk_widget_set_usize(GTK_WIDGET_PTR(mainwin->summaryview),
1411                                      prefs_common.summaryview_width,
1412                                      prefs_common.summaryview_height);
1413                 gtk_widget_set_usize(mainwin->window,
1414                                      prefs_common.mainview_width,
1415                                      prefs_common.mainwin_height);
1416                 gtk_container_add(GTK_CONTAINER(folderwin),
1417                                   GTK_WIDGET_PTR(mainwin->folderview));
1418                 gtk_container_add(GTK_CONTAINER(messagewin),
1419                                   GTK_WIDGET_PTR(mainwin->messageview));
1420
1421                 mainwin->win.sep_both.folderwin = folderwin;
1422                 mainwin->win.sep_both.messagewin = messagewin;
1423
1424                 gtk_widget_show_all(folderwin);
1425                 gtk_widget_show_all(messagewin);
1426                 break;
1427         }
1428
1429         mainwin->type = type;
1430
1431         debug_print(_("done.\n"));
1432 }
1433
1434 #include "pixmaps/stock_mail_receive.xpm"
1435 #include "pixmaps/stock_mail_receive_all.xpm"
1436 #include "pixmaps/stock_mail_compose.xpm"
1437 #include "pixmaps/stock_news_compose.xpm"
1438 #include "pixmaps/stock_mail_reply.xpm"
1439 #include "pixmaps/stock_mail_reply_to_all.xpm"
1440 #include "pixmaps/stock_mail_reply_to_author.xpm"
1441 #include "pixmaps/stock_mail_forward.xpm"
1442 #include "pixmaps/stock_mail_send.xpm"
1443 #include "pixmaps/stock_preferences.xpm"
1444 #include "pixmaps/stock_properties.xpm"
1445 #include "pixmaps/stock_down_arrow.xpm"
1446 #include "pixmaps/stock_close.xpm"
1447 #include "pixmaps/stock_exec.xpm"
1448
1449 #define CREATE_TOOLBAR_ICON(xpm_d) \
1450 { \
1451         icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
1452                                             &container->style->white, \
1453                                             xpm_d); \
1454         icon_wid = gtk_pixmap_new(icon, mask); \
1455 }
1456
1457 static void main_window_toolbar_create(MainWindow *mainwin,
1458                                        GtkWidget *container)
1459 {
1460         GtkWidget *toolbar;
1461         GdkPixmap *icon;
1462         GdkBitmap *mask;
1463         GtkWidget *icon_wid;
1464         GtkWidget *get_btn;
1465         GtkWidget *getall_btn;
1466         GtkWidget *compose_mail_btn;
1467         GtkWidget *compose_news_btn;
1468         GtkWidget *compose_mail_btn_plain;
1469         GtkWidget *compose_news_btn_plain;
1470         GtkWidget *reply_btn;
1471         GtkWidget *replyall_btn;
1472         GtkWidget *replysender_btn;
1473         GtkWidget *fwd_btn;
1474         GtkWidget *send_btn;
1475         /*
1476         GtkWidget *prefs_btn;
1477         GtkWidget *account_btn;
1478         */
1479         GtkWidget *next_btn;
1480         GtkWidget *delete_btn;
1481         GtkWidget *exec_btn;
1482         GtkWidget *compose_type_btn;
1483         GtkWidget *compose_type_arrow;
1484         GtkWidget *compose_box;
1485         GtkWidget *compose_label;
1486         GtkTooltips *tooltips;
1487
1488         toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1489                                   GTK_TOOLBAR_BOTH);
1490         gtk_container_add(GTK_CONTAINER(container), toolbar);
1491         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1492         gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1493         gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1494                                     GTK_TOOLBAR_SPACE_LINE);
1495
1496         CREATE_TOOLBAR_ICON(stock_mail_receive_xpm);
1497         get_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1498                                           _("Get"),
1499                                           _("Get new mail from current account"),
1500                                           "Get",
1501                                           icon_wid, toolbar_inc_cb, mainwin);
1502         CREATE_TOOLBAR_ICON(stock_mail_receive_all_xpm);
1503         getall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1504                                              _("Get all"),
1505                                              _("Get new mail from all accounts"),
1506                                              "Get all",
1507                                              icon_wid,
1508                                              toolbar_inc_all_cb,
1509                                              mainwin);
1510
1511         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1512
1513         CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
1514         send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1515                                            _("Send"),
1516                                            _("Send queued message(s)"),
1517                                            "Send",
1518                                            icon_wid,
1519                                            toolbar_send_cb,
1520                                            mainwin);
1521
1522         /* to implement Leandro's "combined" compose buttons, we create
1523          * two sets of compose buttons, one for normal (text + icon) 
1524          * toolbar, and one for both text-only and icon-only toolbar;
1525          * we switch between those sets. */
1526
1527         /* insert compose mail button widget */                                    
1528
1529         compose_mail_btn = gtk_button_new();
1530         gtk_widget_show(compose_mail_btn);
1531         tooltips = gtk_tooltips_new();
1532         gtk_tooltips_set_tip(tooltips, compose_mail_btn, 
1533                                                  _("Compose email message"),
1534                                                  _("email"));
1535         compose_box = gtk_vbox_new(0, 0);
1536         gtk_widget_show(compose_box);
1537         
1538         gtk_container_add(GTK_CONTAINER(compose_mail_btn), compose_box);
1539         CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1540         gtk_box_pack_start(GTK_BOX(compose_box), icon_wid, FALSE, FALSE, 0);
1541
1542         compose_label = gtk_label_new(_("Email"));
1543         gtk_widget_show(compose_label);
1544         gtk_box_pack_start(GTK_BOX(compose_box), compose_label, FALSE, FALSE, 0);
1545         
1546         GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(compose_mail_btn), GTK_CAN_FOCUS);
1547         gtk_button_set_relief(GTK_BUTTON(compose_mail_btn), GTK_RELIEF_NONE);
1548         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar), compose_mail_btn,
1549                 NULL, NULL);
1550
1551         /* insert compose news button widget */
1552
1553         compose_news_btn = gtk_button_new();
1554         gtk_widget_show(compose_news_btn);
1555         tooltips = gtk_tooltips_new();
1556         gtk_tooltips_set_tip(tooltips, compose_news_btn,
1557                                                  _("Compose news article"),
1558                                                  _("news"));
1559         compose_box = gtk_vbox_new(0, 0);
1560         gtk_widget_show(compose_box);
1561         
1562         gtk_container_add(GTK_CONTAINER(compose_news_btn), compose_box);
1563         CREATE_TOOLBAR_ICON(stock_news_compose_xpm);
1564         gtk_box_pack_start(GTK_BOX(compose_box), icon_wid, FALSE, FALSE, 0);
1565
1566         compose_label = gtk_label_new(_("News"));
1567         gtk_widget_show(compose_label);
1568         gtk_box_pack_start(GTK_BOX(compose_box), compose_label, FALSE, FALSE, 0);
1569         
1570         GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(compose_news_btn), GTK_CAN_FOCUS);
1571         gtk_button_set_relief(GTK_BUTTON(compose_news_btn), GTK_RELIEF_NONE);
1572         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar), compose_news_btn,
1573                 NULL, NULL);
1574         
1575         /* insert compose btn plain */
1576         
1577         CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
1578         compose_mail_btn_plain = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1579                                               _("Compose email"),
1580                                               _("Compose an email message"),
1581                                               "New",
1582                                               icon_wid,
1583                                               toolbar_compose_mail_cb,
1584                                               mainwin);
1585
1586         /* insert compose btn plain */
1587
1588         CREATE_TOOLBAR_ICON(stock_news_compose_xpm);
1589         compose_news_btn_plain = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1590                                               _("Compose news"),
1591                                               _("Compose a news message"),
1592                                               "New",
1593                                               icon_wid,
1594                                               toolbar_compose_news_cb,
1595                                               mainwin);
1596
1597         /* insert compose button type widget */
1598         
1599         compose_type_btn = gtk_button_new();
1600         gtk_widget_show(compose_type_btn);
1601         
1602         compose_type_arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
1603         gtk_widget_show(compose_type_arrow);
1604         
1605         gtk_container_add(GTK_CONTAINER(compose_type_btn), compose_type_arrow);
1606
1607         GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(compose_type_btn), GTK_CAN_FOCUS);
1608         gtk_button_set_relief(GTK_BUTTON(compose_type_btn), GTK_RELIEF_NONE);
1609
1610         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar), compose_type_btn,
1611                 NULL, NULL);
1612
1613         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1614         
1615         CREATE_TOOLBAR_ICON(stock_mail_reply_xpm);
1616         reply_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1617                                             _("Reply"),
1618                                             _("Reply to the message"),
1619                                             "Reply",
1620                                             icon_wid,
1621                                             toolbar_reply_cb,
1622                                             mainwin);
1623         CREATE_TOOLBAR_ICON(stock_mail_reply_to_all_xpm);
1624         replyall_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1625                                                _("All"),
1626                                                _("Reply to all"),
1627                                                "Reply to all",
1628                                                icon_wid,
1629                                                toolbar_reply_to_all_cb,
1630                                                mainwin);
1631         CREATE_TOOLBAR_ICON(stock_mail_reply_to_author_xpm);
1632         replysender_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1633                                                   _("Sender"),
1634                                                   _("Reply to sender"),
1635                                                   "Reply to sender",
1636                                                   icon_wid,
1637                                                   toolbar_reply_to_sender_cb,
1638                                                   mainwin);
1639         CREATE_TOOLBAR_ICON(stock_mail_forward_xpm);
1640         fwd_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1641                                           _("Forward"),
1642                                           _("Forward the message"),
1643                                           "Fwd",
1644                                           icon_wid,
1645                                           toolbar_forward_cb,
1646                                           mainwin);
1647
1648         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1649
1650         CREATE_TOOLBAR_ICON(stock_close_xpm);
1651         delete_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1652                                           _("Delete"),
1653                                           _("Delete the message"),
1654                                           "Delete",
1655                                           icon_wid,
1656                                           toolbar_delete_cb,
1657                                           mainwin);
1658
1659         CREATE_TOOLBAR_ICON(stock_exec_xpm);
1660         exec_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1661                                            _("Execute"),
1662                                            _("Execute marked process"),
1663                                            "Execute",
1664                                            icon_wid,
1665                                            toolbar_exec_cb,
1666                                            mainwin);
1667
1668         CREATE_TOOLBAR_ICON(stock_down_arrow_xpm);
1669         next_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1670                                            _("Next"),
1671                                            _("Next unread message"),
1672                                            "Next unread",
1673                                            icon_wid,
1674                                            toolbar_next_unread_cb,
1675                                            mainwin);
1676
1677         /*
1678         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1679
1680         CREATE_TOOLBAR_ICON(stock_preferences_xpm);
1681         prefs_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1682                                             _("Prefs"),
1683                                             _("Common preference"),
1684                                             "Prefs",
1685                                             icon_wid,
1686                                             toolbar_prefs_cb,
1687                                             mainwin);
1688         CREATE_TOOLBAR_ICON(stock_properties_xpm);
1689         account_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1690                                               _("Account"),
1691                                               _("Account setting"),
1692                                               "Account",
1693                                               icon_wid,
1694                                               toolbar_account_cb,
1695                                               mainwin);
1696         gtk_signal_connect(GTK_OBJECT(account_btn), "button_press_event",
1697                            GTK_SIGNAL_FUNC(toolbar_account_button_pressed),
1698                            mainwin);
1699         */
1700
1701         gtk_signal_connect(GTK_OBJECT(compose_type_btn), "clicked",
1702                 GTK_SIGNAL_FUNC(toolbar_popup_compose_type_cb),
1703                 mainwin);
1704
1705         gtk_signal_connect(GTK_OBJECT(compose_mail_btn), "clicked",
1706                 GTK_SIGNAL_FUNC(toolbar_compose_cb),
1707                 mainwin);
1708
1709         gtk_signal_connect(GTK_OBJECT(compose_news_btn), "clicked",
1710                 GTK_SIGNAL_FUNC(toolbar_compose_cb),
1711                 mainwin);
1712
1713         mainwin->toolbar         = toolbar;
1714         mainwin->get_btn         = get_btn;
1715         mainwin->getall_btn      = getall_btn;
1716         mainwin->compose_mail_btn = compose_mail_btn;
1717         mainwin->compose_news_btn = compose_news_btn;
1718         mainwin->compose_mail_btn_plain = compose_mail_btn_plain;
1719         mainwin->compose_news_btn_plain = compose_news_btn_plain;
1720         mainwin->reply_btn       = reply_btn;
1721         mainwin->replyall_btn    = replyall_btn;
1722         mainwin->replysender_btn = replysender_btn;
1723         mainwin->fwd_btn         = fwd_btn;
1724         mainwin->send_btn        = send_btn;
1725         /*
1726         mainwin->prefs_btn       = prefs_btn;
1727         mainwin->account_btn     = account_btn;
1728         */
1729         mainwin->next_btn        = next_btn;
1730         mainwin->delete_btn      = delete_btn;
1731         mainwin->exec_btn        = exec_btn;
1732
1733         gtk_widget_show_all(toolbar);
1734
1735         /* activate Leandro menu system */
1736         activate_compose_button(mainwin, 
1737                                 prefs_common.toolbar_style,
1738                                 mainwin->compose_btn_type);
1739 }
1740
1741 /* callback functions */
1742
1743 static void toolbar_popup_compose_type_cb       (GtkWidget      *widget,
1744                                  gpointer data)
1745 {
1746         MainWindow *mainwindow = (MainWindow *) data;
1747         GtkWidget *compose_menu, *compose_item;
1748
1749         g_return_if_fail(mainwindow != NULL);
1750         
1751         compose_menu = gtk_menu_new();
1752         
1753         compose_item = gtk_menu_item_new_with_label(_("Email message"));
1754         gtk_widget_show(compose_item);
1755         gtk_menu_append(GTK_MENU(compose_menu), compose_item);
1756         gtk_signal_connect(GTK_OBJECT(compose_item), "activate",
1757                 GTK_SIGNAL_FUNC(toolbar_popup_compose_type_set),
1758                 mainwindow);
1759         gtk_object_set_data(GTK_OBJECT(compose_item), "entry", GINT_TO_POINTER(COMPOSEBUTTON_MAIL));            
1760         
1761         compose_item = gtk_menu_item_new_with_label(_("News article"));
1762         gtk_widget_show(compose_item);
1763         gtk_menu_append(GTK_MENU(compose_menu), compose_item);
1764         gtk_signal_connect(GTK_OBJECT(compose_item), "activate",
1765                 GTK_SIGNAL_FUNC(toolbar_popup_compose_type_set),
1766                 mainwindow);
1767         gtk_object_set_data(GTK_OBJECT(compose_item), "entry", GINT_TO_POINTER(COMPOSEBUTTON_NEWS));            
1768                 
1769         gtk_menu_popup(GTK_MENU(compose_menu), NULL, NULL, NULL,
1770                 NULL, 1, 0);
1771 }
1772
1773 static void toolbar_popup_compose_type_set(GtkWidget *widget, gpointer data)
1774 {
1775         ComposeButtonType compose_type = GPOINTER_TO_INT( gtk_object_get_data(GTK_OBJECT(widget), "entry") );
1776         MainWindow *mainwindow = (MainWindow *) data;
1777
1778         mainwindow->compose_btn_type = compose_type;
1779
1780         activate_compose_button(mainwindow, prefs_common.toolbar_style, mainwindow->compose_btn_type);
1781 }       
1782
1783 static void toolbar_inc_cb      (GtkWidget      *widget,
1784                                  gpointer        data)
1785 {
1786         MainWindow *mainwin = (MainWindow *)data;
1787
1788         inc_mail_cb(mainwin, 0, NULL);
1789 }
1790
1791 static void toolbar_inc_all_cb  (GtkWidget      *widget,
1792                                  gpointer        data)
1793 {
1794         MainWindow *mainwin = (MainWindow *)data;
1795
1796         inc_all_account_mail_cb(mainwin, 0, NULL);
1797 }
1798
1799 static void toolbar_send_cb     (GtkWidget      *widget,
1800                                  gpointer        data)
1801 {
1802         MainWindow *mainwin = (MainWindow *)data;
1803
1804         send_queue_cb(mainwin, 0, NULL);
1805 }
1806
1807 static void toolbar_compose_cb  (GtkWidget      *widget,
1808                                  gpointer        data)
1809 {
1810         MainWindow *mainwin = (MainWindow *)data;
1811
1812         if (mainwin->compose_btn_type == COMPOSEBUTTON_MAIL)
1813                 compose_cb(mainwin, 0, NULL);
1814         else
1815                 compose_news_cb(mainwin, 0, NULL);
1816 }
1817
1818 static void toolbar_compose_news_cb     (GtkWidget      *widget,
1819                                  gpointer        data)
1820 {
1821         MainWindow *mainwin = (MainWindow *)data;
1822
1823         compose_news_cb(mainwin, 0, NULL);
1824 }
1825
1826 static void toolbar_compose_mail_cb     (GtkWidget      *widget,
1827                                  gpointer        data)
1828 {
1829         MainWindow *mainwin = (MainWindow *)data;
1830
1831         compose_mail_cb(mainwin, 0, NULL);
1832 }
1833
1834 static void toolbar_reply_cb    (GtkWidget      *widget,
1835                                  gpointer        data)
1836 {
1837         MainWindow *mainwin = (MainWindow *)data;
1838
1839         reply_cb(mainwin, COMPOSE_REPLY, NULL);
1840 }
1841
1842 static void toolbar_reply_to_all_cb     (GtkWidget      *widget,
1843                                          gpointer        data)
1844 {
1845         MainWindow *mainwin = (MainWindow *)data;
1846
1847         reply_cb(mainwin, COMPOSE_REPLY_TO_ALL, NULL);
1848 }
1849
1850 static void toolbar_reply_to_sender_cb  (GtkWidget      *widget,
1851                                          gpointer        data)
1852 {
1853         MainWindow *mainwin = (MainWindow *)data;
1854
1855         reply_cb(mainwin, COMPOSE_REPLY_TO_SENDER, NULL);
1856 }
1857
1858 static void toolbar_forward_cb  (GtkWidget      *widget,
1859                                  gpointer        data)
1860 {
1861         MainWindow *mainwin = (MainWindow *)data;
1862
1863         if (prefs_common.forward_as_attachment)
1864                 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
1865         else
1866                 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1867 }
1868
1869 static void toolbar_delete_cb   (GtkWidget      *widget,
1870                                  gpointer        data)
1871 {
1872         MainWindow *mainwin = (MainWindow *)data;
1873
1874         summary_delete(mainwin->summaryview);
1875 }
1876
1877 static void toolbar_exec_cb     (GtkWidget      *widget,
1878                                  gpointer        data)
1879 {
1880         MainWindow *mainwin = (MainWindow *)data;
1881
1882         summary_execute(mainwin->summaryview);
1883 }
1884
1885 static void toolbar_next_unread_cb      (GtkWidget      *widget,
1886                                          gpointer        data)
1887 {
1888         MainWindow *mainwin = (MainWindow *)data;
1889
1890         next_unread_cb(mainwin, 0, NULL);
1891 }
1892
1893 static void toolbar_prefs_cb    (GtkWidget      *widget,
1894                                  gpointer        data)
1895 {
1896         prefs_common_open();
1897 }
1898
1899 static void toolbar_account_cb  (GtkWidget      *widget,
1900                                  gpointer        data)
1901 {
1902         MainWindow *mainwin = (MainWindow *)data;
1903
1904         prefs_account_open_cb(mainwin, 0, NULL);
1905 }
1906
1907 static void toolbar_account_button_pressed(GtkWidget *widget,
1908                                            GdkEventButton *event,
1909                                            gpointer data)
1910 {
1911         MainWindow *mainwin = (MainWindow *)data;
1912
1913         if (!event) return;
1914         if (event->button != 3) return;
1915
1916         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1917                        event->button, event->time);
1918 }
1919
1920 static void ac_label_button_pressed(GtkWidget *widget, GdkEventButton *event,
1921                                     gpointer data)
1922 {
1923         MainWindow *mainwin = (MainWindow *)data;
1924
1925         if (!event) return;
1926
1927         gtk_menu_popup(GTK_MENU(mainwin->ac_menu), NULL, NULL, NULL, NULL,
1928                        event->button, event->time);
1929 }
1930
1931 static gint main_window_close_cb(GtkWidget *widget, GdkEventAny *event,
1932                                  gpointer data)
1933 {
1934         app_exit_cb(data, 0, widget);
1935
1936         return TRUE;
1937 }
1938
1939 static void add_mailbox_cb(MainWindow *mainwin, guint action,
1940                            GtkWidget *widget)
1941 {
1942         main_window_add_mailbox(mainwin);
1943 }
1944
1945 static void add_mbox_cb(MainWindow *mainwin, guint action,
1946                         GtkWidget *widget)
1947 {
1948         main_window_add_mbox(mainwin);
1949 }
1950
1951 static void update_folderview_cb(MainWindow *mainwin, guint action,
1952                                  GtkWidget *widget)
1953 {
1954         summary_show(mainwin->summaryview, NULL, FALSE);
1955         folderview_update_all();
1956 }
1957
1958 static void new_folder_cb(MainWindow *mainwin, guint action,
1959                           GtkWidget *widget)
1960 {
1961         folderview_new_folder(mainwin->folderview);
1962 }
1963
1964 static void rename_folder_cb(MainWindow *mainwin, guint action,
1965                              GtkWidget *widget)
1966 {
1967         folderview_rename_folder(mainwin->folderview);
1968 }
1969
1970 static void delete_folder_cb(MainWindow *mainwin, guint action,
1971                              GtkWidget *widget)
1972 {
1973         folderview_delete_folder(mainwin->folderview);
1974 }
1975
1976 static void import_mbox_cb(MainWindow *mainwin, guint action,
1977                            GtkWidget *widget)
1978 {
1979         import_mbox(mainwin->summaryview->folder_item);
1980 }
1981
1982 static void export_mbox_cb(MainWindow *mainwin, guint action,
1983                            GtkWidget *widget)
1984 {
1985         export_mbox(mainwin->summaryview->folder_item);
1986 }
1987
1988 static void empty_trash_cb(MainWindow *mainwin, guint action,
1989                            GtkWidget *widget)
1990 {
1991         main_window_empty_trash(mainwin, TRUE);
1992 }
1993
1994 static void save_as_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
1995 {
1996         summary_save_as(mainwin->summaryview);
1997 }
1998
1999 static void print_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2000 {
2001         summary_print(mainwin->summaryview);
2002 }
2003
2004 static void app_exit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2005 {
2006         if (prefs_common.confirm_on_exit) {
2007                 if (alertpanel(_("Exit"), _("Exit this program?"),
2008                                _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
2009                         return;
2010                 manage_window_focus_in(mainwin->window, NULL, NULL);
2011         }
2012
2013         app_will_exit(widget, mainwin);
2014 }
2015
2016 static void toggle_folder_cb(MainWindow *mainwin, guint action,
2017                              GtkWidget *widget)
2018 {
2019         switch (mainwin->type) {
2020         case SEPARATE_NONE:
2021         case SEPARATE_MESSAGE:
2022                 break;
2023         case SEPARATE_FOLDER:
2024                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2025                         gtk_widget_show(mainwin->win.sep_folder.folderwin);
2026                 else
2027                         gtk_widget_hide(mainwin->win.sep_folder.folderwin);
2028                 break;
2029         case SEPARATE_BOTH:
2030                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2031                         gtk_widget_show(mainwin->win.sep_both.folderwin);
2032                 else
2033                         gtk_widget_hide(mainwin->win.sep_both.folderwin);
2034                 break;
2035         }
2036 }
2037
2038 static void toggle_message_cb(MainWindow *mainwin, guint action,
2039                               GtkWidget *widget)
2040 {
2041         switch (mainwin->type) {
2042         case SEPARATE_NONE:
2043         case SEPARATE_FOLDER:
2044                 break;
2045         case SEPARATE_MESSAGE:
2046                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2047                         gtk_widget_show(mainwin->win.sep_message.messagewin);
2048                 else
2049                         gtk_widget_hide(mainwin->win.sep_message.messagewin);
2050                 break;
2051         case SEPARATE_BOTH:
2052                 if (GTK_CHECK_MENU_ITEM(widget)->active)
2053                         gtk_widget_show(mainwin->win.sep_both.messagewin);
2054                 else
2055                         gtk_widget_hide(mainwin->win.sep_both.messagewin);
2056                 break;
2057         }
2058 }
2059
2060 static void toggle_toolbar_cb(MainWindow *mainwin, guint action,
2061                               GtkWidget *widget)
2062 {
2063         activate_compose_button(mainwin, (ToolbarStyle)action, 
2064                         mainwin->compose_btn_type);
2065         
2066         switch ((ToolbarStyle)action) {
2067         case TOOLBAR_NONE:
2068                 gtk_widget_hide(mainwin->handlebox);
2069         case TOOLBAR_ICON:
2070                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2071                                       GTK_TOOLBAR_ICONS);
2072                 break;
2073         case TOOLBAR_TEXT:
2074                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2075                                       GTK_TOOLBAR_TEXT);
2076                 break;
2077         case TOOLBAR_BOTH:
2078                 gtk_toolbar_set_style(GTK_TOOLBAR(mainwin->toolbar),
2079                                       GTK_TOOLBAR_BOTH);
2080                 break;
2081         }
2082
2083         if (action != TOOLBAR_NONE) {
2084                 gtk_widget_show(mainwin->handlebox);
2085                 gtk_widget_queue_resize(mainwin->handlebox);
2086         }
2087
2088         mainwin->toolbar_style = (ToolbarStyle)action;
2089         prefs_common.toolbar_style = (ToolbarStyle)action;
2090 }
2091
2092 static void toggle_statusbar_cb(MainWindow *mainwin, guint action,
2093                                 GtkWidget *widget)
2094 {
2095         if (GTK_CHECK_MENU_ITEM(widget)->active) {
2096                 gtk_widget_show(mainwin->hbox_stat);
2097                 prefs_common.show_statusbar = TRUE;
2098         } else {
2099                 gtk_widget_hide(mainwin->hbox_stat);
2100                 prefs_common.show_statusbar = FALSE;
2101         }
2102 }
2103
2104 static void separate_widget_cb(GtkCheckMenuItem *checkitem, guint action)
2105 {
2106         MainWindow *mainwin;
2107         SeparateType type;
2108
2109         mainwin = (MainWindow *) gtk_object_get_data(GTK_OBJECT(checkitem), "mainwindow");
2110         g_return_if_fail(mainwin != NULL);
2111
2112         type = mainwin->type ^ action;
2113         main_window_separation_change(mainwin, type);
2114
2115         prefs_common.sep_folder = (type & SEPARATE_FOLDER)  != 0;
2116         prefs_common.sep_msg    = (type & SEPARATE_MESSAGE) != 0;
2117 }
2118
2119 static void addressbook_open_cb(MainWindow *mainwin, guint action,
2120                                 GtkWidget *widget)
2121 {
2122         addressbook_open(NULL);
2123 }
2124
2125 static void log_window_show_cb(MainWindow *mainwin, guint action,
2126                                GtkWidget *widget)
2127 {
2128         log_window_show(mainwin->logwin);
2129 }
2130
2131 static void inc_mail_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2132 {
2133         inc_mail(mainwin);
2134 }
2135
2136 static void inc_all_account_mail_cb(MainWindow *mainwin, guint action,
2137                                     GtkWidget *widget)
2138 {
2139         inc_all_account_mail(mainwin);
2140 }
2141
2142 static void send_queue_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2143 {
2144         GList *list;
2145
2146         if (procmsg_send_queue() < 0)
2147                 alertpanel_error(_("Sending queued message failed."));
2148
2149         statusbar_pop_all();
2150
2151         for (list = folder_get_list(); list != NULL; list = list->next) {
2152                 Folder *folder;
2153
2154                 folder = list->data;
2155                 if (folder->queue) {
2156                         folder_item_scan(folder->queue);
2157                         folderview_update_item(folder->queue, TRUE);
2158                 }
2159         }
2160 }
2161
2162 static void compose_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2163 {
2164         if (mainwin->summaryview->folder_item) {
2165                 if (mainwin->summaryview->folder_item->folder->account != NULL
2166                     && mainwin->summaryview->folder_item->folder->account->protocol == A_NNTP)
2167                         compose_new_with_recipient(mainwin->summaryview->folder_item->folder->account, mainwin->summaryview->folder_item->path);
2168                 else
2169                         compose_new(mainwin->summaryview->folder_item->folder->account);
2170         }
2171         else
2172                 compose_new(NULL);
2173 }
2174
2175 static void compose_mail_cb(MainWindow *mainwin, guint action,
2176                             GtkWidget *widget)
2177 {
2178         PrefsAccount * ac;
2179         GList * list;
2180         GList * cur;
2181
2182         if (mainwin->summaryview->folder_item) {
2183                 ac = mainwin->summaryview->folder_item->folder->account;
2184                 if (ac && ac->protocol != A_NNTP) {
2185                         compose_new(ac);
2186                         return;
2187                 }
2188         }
2189
2190         list = account_get_list();
2191         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2192                 ac = (PrefsAccount *) cur->data;
2193                 if (ac->protocol != A_NNTP) {
2194                         compose_new(ac);
2195                         return;
2196                 }
2197         }
2198 }
2199
2200 static void compose_news_cb(MainWindow *mainwin, guint action,
2201                             GtkWidget *widget)
2202 {
2203         PrefsAccount * ac = NULL;
2204         GList * list;
2205         GList * cur;
2206
2207         if (mainwin->summaryview->folder_item) {
2208                 ac = mainwin->summaryview->folder_item->folder->account;
2209                 if (ac && ac->protocol == A_NNTP) {
2210                         compose_new_with_recipient
2211                                 (ac, mainwin->summaryview->folder_item->path);
2212                         return;
2213                 }
2214         }
2215
2216         list = account_get_list();
2217         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2218                 ac = (PrefsAccount *) cur->data;
2219                 if (ac->protocol == A_NNTP) {
2220                         compose_new(ac);
2221                         return;
2222                 }
2223         }
2224 }
2225
2226 static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2227 {
2228         GList  *sel = GTK_CLIST(mainwin->summaryview->ctree)->selection;
2229         MsgInfo *msginfo;
2230
2231         msginfo = gtk_ctree_node_get_row_data
2232                 (GTK_CTREE(mainwin->summaryview->ctree),
2233                  mainwin->summaryview->selected);
2234
2235         if (!msginfo) return;
2236
2237         switch (action) {
2238         case COMPOSE_REPLY:
2239                 compose_reply(msginfo, prefs_common.reply_with_quote,
2240                               FALSE, FALSE);
2241                 break;
2242         case COMPOSE_REPLY_TO_SENDER:
2243                 compose_reply(msginfo, prefs_common.reply_with_quote,
2244                               FALSE, TRUE);
2245                 break;
2246         case COMPOSE_FOLLOWUP_AND_REPLY_TO:
2247                 compose_followup_and_reply_to(msginfo,
2248                                               prefs_common.reply_with_quote,
2249                                               FALSE, TRUE);
2250                 break;
2251         case COMPOSE_REPLY_TO_ALL:
2252                 compose_reply(msginfo, prefs_common.reply_with_quote,
2253                               TRUE, FALSE);
2254                 break;
2255         case COMPOSE_FORWARD:
2256                 if (!sel->next) {
2257                         compose_forward(NULL, msginfo, FALSE);
2258                         break;
2259                 }
2260                 /* if (sel->next) FALL_THROUGH */
2261         case COMPOSE_FORWARD_AS_ATTACH:
2262                 {
2263                         GSList *msginfo_list = NULL;
2264                         for ( ; sel != NULL; sel = sel->next)
2265                                 msginfo_list = g_slist_append(msginfo_list, 
2266                                         gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->summaryview->ctree),
2267                                                 GTK_CTREE_NODE(sel->data)));
2268                         compose_forward_multiple(NULL, msginfo_list);
2269                         g_slist_free(msginfo_list);
2270                 }                       
2271                 break;
2272         default:
2273                 g_warning("reply_cb(): invalid action type: %d\n", action);
2274         }
2275
2276         summary_set_marks_selected(mainwin->summaryview);
2277 }
2278
2279 static void move_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2280 {
2281         summary_move_to(mainwin->summaryview);
2282 }
2283
2284 static void copy_to_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2285 {
2286         summary_copy_to(mainwin->summaryview);
2287 }
2288
2289 static void delete_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2290 {
2291         summary_delete(mainwin->summaryview);
2292 }
2293
2294 static void open_msg_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2295 {
2296         summary_open_msg(mainwin->summaryview);
2297 }
2298
2299 static void view_source_cb(MainWindow *mainwin, guint action,
2300                            GtkWidget *widget)
2301 {
2302         summary_view_source(mainwin->summaryview);
2303 }
2304
2305 static void reedit_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2306 {
2307         summary_reedit(mainwin->summaryview);
2308 }
2309
2310 static void mark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2311 {
2312         summary_mark(mainwin->summaryview);
2313 }
2314
2315 static void unmark_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2316 {
2317         summary_unmark(mainwin->summaryview);
2318 }
2319
2320 static void mark_as_unread_cb(MainWindow *mainwin, guint action,
2321                               GtkWidget *widget)
2322 {
2323         summary_mark_as_unread(mainwin->summaryview);
2324 }
2325
2326 static void mark_as_read_cb(MainWindow *mainwin, guint action,
2327                             GtkWidget *widget)
2328 {
2329         summary_mark_as_read(mainwin->summaryview);
2330 }
2331
2332 static void set_charset_cb(MainWindow *mainwin, guint action,
2333                            GtkWidget *widget)
2334 {
2335         const gchar *str;
2336
2337         str = conv_get_charset_str((CharSet)action);
2338         g_free(prefs_common.force_charset);
2339         prefs_common.force_charset = str ? g_strdup(str) : NULL;
2340
2341         summary_redisplay_msg(mainwin->summaryview);
2342
2343         debug_print(_("forced charset: %s\n"), str ? str : "Auto-Detect");
2344 }
2345
2346 void main_window_set_thread_option(MainWindow *mainwin)
2347 {
2348         GtkItemFactory *ifactory;
2349         gboolean no_item = FALSE;
2350
2351         ifactory = gtk_item_factory_from_widget(mainwin->menubar);
2352
2353         if (mainwin->summaryview == NULL)
2354                 no_item = TRUE;
2355         else if (mainwin->summaryview->folder_item == NULL)
2356                 no_item = TRUE;
2357
2358         if (no_item) {
2359                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
2360                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
2361         }
2362         else {
2363                 if (mainwin->summaryview->folder_item->prefs->enable_thread) {
2364                         menu_set_sensitive(ifactory,
2365                                            "/Summary/Thread view",   FALSE);
2366                         menu_set_sensitive(ifactory,
2367                                            "/Summary/Unthread view", TRUE);
2368                         summary_thread_build(mainwin->summaryview);
2369                 }
2370                 else {
2371                         menu_set_sensitive(ifactory,
2372                                            "/Summary/Thread view",   TRUE);
2373                         menu_set_sensitive(ifactory,
2374                                            "/Summary/Unthread view", FALSE);
2375                         summary_unthread(mainwin->summaryview);
2376                 }
2377                 prefs_folder_item_save_config(mainwin->summaryview->folder_item);
2378         }
2379 }
2380
2381 static void thread_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2382 {
2383         mainwin->summaryview->folder_item->prefs->enable_thread =
2384                 !mainwin->summaryview->folder_item->prefs->enable_thread;
2385         main_window_set_thread_option(mainwin);
2386
2387         /*
2388         if (0 == action) {
2389                 summary_thread_build(mainwin->summaryview);
2390                 mainwin->summaryview->folder_item->prefs->enable_thread =
2391                         TRUE;
2392                 menu_set_sensitive(ifactory, "/Summary/Thread view",   FALSE);
2393                 menu_set_sensitive(ifactory, "/Summary/Unthread view", TRUE);
2394         } else {
2395                 summary_unthread(mainwin->summaryview);
2396                 mainwin->summaryview->folder_item->prefs->enable_thread =
2397                         FALSE;
2398                 menu_set_sensitive(ifactory, "/Summary/Thread view",   TRUE);
2399                 menu_set_sensitive(ifactory, "/Summary/Unthread view", FALSE);
2400         }
2401         */
2402 }
2403
2404 static void set_display_item_cb(MainWindow *mainwin, guint action,
2405                                 GtkWidget *widget)
2406 {
2407         prefs_summary_display_item_set();
2408 }
2409
2410 static void sort_summary_cb(MainWindow *mainwin, guint action,
2411                             GtkWidget *widget)
2412 {
2413         summary_sort(mainwin->summaryview, (SummarySortType)action);
2414 }
2415
2416 static void attract_by_subject_cb(MainWindow *mainwin, guint action,
2417                                   GtkWidget *widget)
2418 {
2419         summary_attract_by_subject(mainwin->summaryview);
2420 }
2421
2422 static void delete_duplicated_cb(MainWindow *mainwin, guint action,
2423                                  GtkWidget *widget)
2424 {
2425         summary_delete_duplicated(mainwin->summaryview);
2426 }
2427
2428 static void filter_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2429 {
2430         summary_filter(mainwin->summaryview);
2431 }
2432
2433 static void execute_summary_cb(MainWindow *mainwin, guint action,
2434                                GtkWidget *widget)
2435 {
2436         summary_execute(mainwin->summaryview);
2437 }
2438
2439 static void update_summary_cb(MainWindow *mainwin, guint action,
2440                               GtkWidget *widget)
2441 {
2442         FolderItem *fitem;
2443         FolderView *folderview = mainwin->folderview;
2444
2445         if (!mainwin->summaryview->folder_item) return;
2446         if (!folderview->opened) return;
2447
2448         fitem = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree),
2449                                             folderview->opened);
2450         if (!fitem) return;
2451
2452         summary_show(mainwin->summaryview, fitem, TRUE);
2453 }
2454
2455 static void prev_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2456 {
2457         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_BACKWARD);
2458 }
2459
2460 static void next_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2461 {
2462         summary_step(mainwin->summaryview, GTK_SCROLL_STEP_FORWARD);
2463 }
2464
2465 static void next_unread_cb(MainWindow *mainwin, guint action,
2466                            GtkWidget *widget)
2467 {
2468         summary_select_next_unread(mainwin->summaryview);
2469 }
2470
2471 static void next_marked_cb(MainWindow *mainwin, guint action,
2472                            GtkWidget *widget)
2473 {
2474         summary_select_next_marked(mainwin->summaryview);
2475 }
2476
2477 static void prev_marked_cb(MainWindow *mainwin, guint action,
2478                            GtkWidget *widget)
2479 {
2480         summary_select_prev_marked(mainwin->summaryview);
2481 }
2482
2483 static void goto_folder_cb(MainWindow *mainwin, guint action,
2484                            GtkWidget *widget)
2485 {
2486         FolderItem *to_folder;
2487
2488         to_folder = foldersel_folder_sel(NULL, NULL);
2489
2490         if (to_folder)
2491                 folderview_select(mainwin->folderview, to_folder);
2492 }
2493
2494 static void copy_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2495 {
2496         messageview_copy_clipboard(mainwin->messageview);
2497 }
2498
2499 static void allsel_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
2500 {
2501         if (GTK_WIDGET_HAS_FOCUS(mainwin->summaryview->ctree))
2502                 summary_select_all(mainwin->summaryview);
2503         else if (mainwin->summaryview->msg_is_toggled_on &&
2504                  GTK_WIDGET_HAS_FOCUS(mainwin->messageview->textview->text))
2505                 messageview_select_all(mainwin->messageview);
2506 }
2507
2508 static void prefs_common_open_cb(MainWindow *mainwin, guint action,
2509                                  GtkWidget *widget)
2510 {
2511         prefs_common_open();
2512 }
2513
2514 static void prefs_filter_open_cb(MainWindow *mainwin, guint action,
2515                                  GtkWidget *widget)
2516 {
2517         prefs_filter_open();
2518 }
2519
2520 static void prefs_scoring_open_cb(MainWindow *mainwin, guint action,
2521                                   GtkWidget *widget)
2522 {
2523         prefs_scoring_open(NULL);
2524 }
2525
2526 static void prefs_filtering_open_cb(MainWindow *mainwin, guint action,
2527                                     GtkWidget *widget)
2528 {
2529         prefs_filtering_open();
2530 }
2531
2532 static void prefs_account_open_cb(MainWindow *mainwin, guint action,
2533                                   GtkWidget *widget)
2534 {
2535         if (!cur_account) {
2536                 new_account_cb(mainwin, 0, widget);
2537         } else {
2538                 gboolean prev_default = cur_account->is_default;
2539
2540                 prefs_account_open(cur_account);
2541                 if (!prev_default && cur_account->is_default)
2542                         account_set_as_default(cur_account);
2543                 account_save_config_all();
2544                 account_set_menu();
2545                 main_window_reflect_prefs_all();
2546         }
2547 }
2548
2549 static void new_account_cb(MainWindow *mainwin, guint action,
2550                            GtkWidget *widget)
2551 {
2552         account_edit_open();
2553         if (!compose_get_compose_list()) account_add();
2554 }
2555
2556 static void account_menu_cb(GtkMenuItem *menuitem, gpointer data)
2557 {
2558         cur_account = (PrefsAccount *)data;
2559         main_window_reflect_prefs_all();
2560 }
2561
2562 static void manual_open_cb(MainWindow *mainwin, guint action,
2563                            GtkWidget *widget)
2564 {
2565         manual_open((ManualLang)action);
2566 }
2567
2568 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
2569 {
2570         MainWindow *mainwin = (MainWindow *)data;
2571         gchar *str;
2572
2573         if (item->path)
2574                 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
2575                                       LOCAL_FOLDER(folder)->rootpath,
2576                                       G_DIR_SEPARATOR,
2577                                       item->path);
2578         else
2579                 str = g_strdup_printf(_("Scanning folder %s ..."),
2580                                       LOCAL_FOLDER(folder)->rootpath);
2581
2582         STATUSBAR_PUSH(mainwin, str);
2583         STATUSBAR_POP(mainwin);
2584         g_free(str);
2585 }
2586
2587 static void activate_compose_button (MainWindow *mainwin,
2588                                 ToolbarStyle style,
2589                                 ComposeButtonType type)
2590 {
2591         if (style == TOOLBAR_NONE) 
2592                 return;
2593
2594         if (style == TOOLBAR_BOTH) {    
2595                 gtk_widget_hide(mainwin->compose_mail_btn_plain);
2596                 gtk_widget_hide(mainwin->compose_news_btn_plain);
2597                 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? mainwin->compose_mail_btn 
2598                         : mainwin->compose_news_btn);
2599                 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? mainwin->compose_news_btn
2600                         : mainwin->compose_mail_btn);
2601                 mainwin->compose_btn_type = type;       
2602         }
2603         else {
2604                 gtk_widget_hide(mainwin->compose_news_btn);
2605                 gtk_widget_hide(mainwin->compose_mail_btn);
2606                 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? mainwin->compose_mail_btn_plain 
2607                         : mainwin->compose_news_btn_plain);
2608                 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? mainwin->compose_news_btn_plain
2609                         : mainwin->compose_mail_btn_plain);
2610                 mainwin->compose_btn_type = type;               
2611         }
2612 }
2613