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