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