2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 Hiroyuki Yamamoto
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.
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.
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.
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtkvbox.h>
25 #include <gtk/gtkcontainer.h>
26 #include <gtk/gtkeditable.h>
27 #include <gtk/gtkwindow.h>
28 #include <gtk/gtktext.h>
35 #include "messageview.h"
36 #include "headerview.h"
37 #include "summaryview.h"
39 #include "imageview.h"
42 #include "procheader.h"
44 #include "prefs_common.h"
50 #include "alertpanel.h"
54 #include "stock_pixmap.h"
56 static void messageview_change_view_type(MessageView *messageview,
58 static void messageview_destroy_cb (GtkWidget *widget,
59 MessageView *messageview);
60 static void messageview_size_allocate_cb(GtkWidget *widget,
61 GtkAllocation *allocation);
62 static void key_pressed (GtkWidget *widget,
64 MessageView *messageview);
65 static void messageview_toolbar_create (MessageView *messageview,
66 GtkWidget *container);
67 static void toolbar_messageview_buttons_cb (GtkWidget *widget,
70 static void return_receipt_show (NoticeView *noticeview,
72 static void return_receipt_send_clicked (NoticeView *noticeview,
75 static PrefsAccount *select_account_from_list
78 static void messageview_reply_cb (gpointer data,
82 static void messageview_delete_cb (gpointer data,
86 static void messageview_close_cb (gpointer data,
90 static void set_toolbar_style(MessageView *messageview);
93 MessageView *messageview_create(MainWindow *mainwin)
95 MessageView *messageview;
97 HeaderView *headerview;
101 NoticeView *noticeview;
103 debug_print("Creating message view...\n");
104 messageview = g_new0(MessageView, 1);
106 messageview->type = MVIEW_TEXT;
108 headerview = headerview_create();
110 noticeview = noticeview_create(mainwin);
112 textview = textview_create();
113 textview->messageview = messageview;
115 imageview = imageview_create();
116 imageview->messageview = messageview;
118 mimeview = mimeview_create();
119 mimeview->textview = textview_create();
120 mimeview->textview->messageview = messageview;
121 mimeview->imageview = imageview;
122 mimeview->messageview = messageview;
124 vbox = gtk_vbox_new(FALSE, 0);
125 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
127 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
129 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(textview),
132 /* to remove without destroyed */
133 gtk_widget_ref(GTK_WIDGET_PTR(textview));
134 gtk_widget_ref(GTK_WIDGET_PTR(imageview));
135 gtk_widget_ref(GTK_WIDGET_PTR(mimeview));
136 gtk_widget_ref(GTK_WIDGET_PTR(mimeview->textview));
138 messageview->vbox = vbox;
139 messageview->new_window = FALSE;
140 messageview->window = NULL;
141 messageview->headerview = headerview;
142 messageview->textview = textview;
143 messageview->imageview = imageview;
144 messageview->mimeview = mimeview;
145 messageview->noticeview = noticeview;
146 messageview->mainwin = mainwin;
151 static GtkItemFactoryEntry messageview_entries[] =
153 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
154 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
155 {N_("/_File/_Close"), "<control>W", messageview_close_cb, 0, NULL},
157 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
158 {N_("/_Message/_Reply"), "<control>R", messageview_reply_cb, COMPOSE_REPLY, NULL},
159 {N_("/_Message/Repl_y to"), NULL, NULL, 0, "<Branch>"},
160 {N_("/_Message/Repl_y to/_all"), "<shift><control>R", messageview_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
161 {N_("/_Message/Repl_y to/_sender"), NULL, messageview_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
162 {N_("/_Message/Repl_y to/mailing _list"),
163 "<control>L", messageview_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
164 {N_("/_Message/Follow-up and reply to"),NULL, messageview_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
165 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
166 {N_("/_Message/_Delete"), "<control>D", messageview_delete_cb, 0, NULL},
168 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
169 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
174 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
177 MessageView *msgview;
180 GtkWidget *handlebox;
182 guint n_menu_entries;
184 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
185 gtk_window_set_title(GTK_WINDOW(window), _("Sylpheed - Message View"));
186 gtk_window_set_wmclass(GTK_WINDOW(window), "message_view", "Sylpheed");
187 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
188 gtk_widget_set_usize(window, prefs_common.msgwin_width,
189 prefs_common.msgwin_height);
191 vbox = gtk_vbox_new(FALSE, 0);
192 gtk_widget_show(vbox);
193 gtk_container_add(GTK_CONTAINER(window), vbox);
195 msgview = messageview_create(mainwin);
197 gtk_signal_connect(GTK_OBJECT(window), "size_allocate",
198 GTK_SIGNAL_FUNC(messageview_size_allocate_cb),
200 gtk_signal_connect(GTK_OBJECT(window), "destroy",
201 GTK_SIGNAL_FUNC(messageview_destroy_cb), msgview);
202 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
203 GTK_SIGNAL_FUNC(key_pressed), msgview);
205 n_menu_entries = sizeof(messageview_entries) / sizeof(messageview_entries[0]);
206 menubar = menubar_create(window, messageview_entries,
207 n_menu_entries, "<MessageView>", msgview);
208 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
210 handlebox = gtk_handle_box_new();
211 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
212 messageview_toolbar_create(msgview,handlebox);
214 gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET_PTR(msgview));
215 gtk_widget_grab_focus(msgview->textview->text);
216 gtk_widget_show_all(window);
218 msgview->new_window = TRUE;
219 msgview->window = window;
220 msgview->visible = TRUE;
221 msgview->menubar = menubar;
222 msgview->handlebox = handlebox;
225 messageview_init(msgview);
226 common_toolbar_set_style(msgview, TOOLBAR_MSGVIEW);
231 void messageview_init(MessageView *messageview)
233 headerview_init(messageview->headerview);
234 textview_init(messageview->textview);
235 imageview_init(messageview->imageview);
236 mimeview_init(messageview->mimeview);
237 /*messageview_set_font(messageview);*/
239 noticeview_hide(messageview->noticeview);
242 static void notification_convert_header(gchar *dest, gint len,
248 g_return_if_fail(src_ != NULL);
249 g_return_if_fail(dest != NULL);
253 Xstrndup_a(src, src_, len, return);
257 if (is_ascii_str(src)) {
258 strncpy2(dest, src, len);
259 dest[len - 1] = '\0';
262 conv_encode_header(dest, len, src, header_len);
265 static gint disposition_notification_queue(PrefsAccount * account,
266 gchar * to, const gchar *file)
274 debug_print("queueing message...\n");
275 g_return_val_if_fail(account != NULL, -1);
277 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
278 G_DIR_SEPARATOR, (gint)file);
279 if ((fp = fopen(tmp, "wb")) == NULL) {
280 FILE_OP_ERROR(tmp, "fopen");
284 if ((src_fp = fopen(file, "rb")) == NULL) {
285 FILE_OP_ERROR(file, "fopen");
291 if (change_file_mode_rw(fp, tmp) < 0) {
292 FILE_OP_ERROR(tmp, "chmod");
293 g_warning(_("can't change file mode\n"));
296 /* queueing variables */
297 fprintf(fp, "AF:\n");
298 fprintf(fp, "NF:0\n");
299 fprintf(fp, "PS:10\n");
300 fprintf(fp, "SRH:1\n");
301 fprintf(fp, "SFN:\n");
302 fprintf(fp, "DSR:\n");
303 fprintf(fp, "MID:\n");
304 fprintf(fp, "CFG:\n");
305 fprintf(fp, "PT:0\n");
306 fprintf(fp, "S:%s\n", account->address);
307 fprintf(fp, "RQ:\n");
308 if (account->smtp_server)
309 fprintf(fp, "SSV:%s\n", account->smtp_server);
311 fprintf(fp, "SSV:\n");
312 if (account->nntp_server)
313 fprintf(fp, "NSV:%s\n", account->nntp_server);
315 fprintf(fp, "NSV:\n");
316 fprintf(fp, "SSH:\n");
317 fprintf(fp, "R:<%s>", to);
321 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
322 if (fputs(buf, fp) == EOF) {
323 FILE_OP_ERROR(tmp, "fputs");
333 if (fclose(fp) == EOF) {
334 FILE_OP_ERROR(tmp, "fclose");
340 queue = folder_get_default_queue();
341 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
342 g_warning(_("can't queue the message\n"));
349 folder_update_item(queue, TRUE);
354 static gint disposition_notification_send(MsgInfo *msginfo)
357 gchar tmp[MAXPATHLEN + 1];
361 PrefsAccount *account;
365 if ((!msginfo->returnreceiptto) &&
366 (!msginfo->dispositionnotificationto))
369 /* RFC2298: Test for Return-Path */
370 if (msginfo->dispositionnotificationto)
371 to = msginfo->dispositionnotificationto;
373 to = msginfo->returnreceiptto;
375 ok = get_header_from_msginfo(msginfo, buf, sizeof(buf),
378 gchar *to_addr = g_strdup(to);
379 extract_address(to_addr);
380 extract_address(buf);
381 ok = strcmp(to_addr, buf);
384 strncpy(buf, _("<No Return-Path found>"),
391 message = g_strdup_printf(
392 _("The notification address to which the "
393 "return receipt is to be sent\n"
394 "does not correspond to the return path:\n"
395 "Notification address: %s\n"
397 "It is advised to not to send the return "
398 "receipt."), to, buf);
399 val = alertpanel(_("Warning"), message, _("Send"),
400 _("+Don't Send"), NULL);
401 if (val != G_ALERTDEFAULT)
405 ac_list = account_find_all_from_address(NULL, msginfo->to);
406 ac_list = account_find_all_from_address(ac_list, msginfo->cc);
408 if (ac_list == NULL) {
409 alertpanel_error(_("This message is asking for a return "
410 "receipt notification\n"
411 "but according to its 'To:' and 'CC:' "
412 "headers it was not\nofficially addressed "
414 "Receipt notification cancelled."));
418 if (g_list_length(ac_list) > 1)
419 account = select_account_from_list(ac_list);
421 account = (PrefsAccount *) ac_list->data;
422 g_list_free(ac_list);
427 /* write to temporary file */
428 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
429 get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
431 if ((fp = fopen(tmp, "wb")) == NULL) {
432 FILE_OP_ERROR(tmp, "fopen");
436 /* chmod for security */
437 if (change_file_mode_rw(fp, tmp) < 0) {
438 FILE_OP_ERROR(tmp, "chmod");
439 g_warning(_("can't change file mode\n"));
443 get_rfc822_date(buf, sizeof(buf));
444 fprintf(fp, "Date: %s\n", buf);
447 if (account->name && *account->name) {
448 notification_convert_header
449 (buf, sizeof(buf), account->name,
451 fprintf(fp, "From: %s <%s>\n", buf, account->address);
453 fprintf(fp, "From: %s\n", account->address);
455 fprintf(fp, "To: %s\n", to);
458 notification_convert_header(buf, sizeof(buf), msginfo->subject,
459 strlen("Subject: "));
460 fprintf(fp, "Subject: Disposition notification: %s\n", buf);
462 if (fclose(fp) == EOF) {
463 FILE_OP_ERROR(tmp, "fclose");
468 to_list = address_list_append(NULL, to);
469 ok = send_message(tmp, account, to_list);
472 if (prefs_common.queue_msg) {
477 _("Error occurred while sending the notification.\n"
478 "Put this notification into queue folder?"),
479 _("OK"), _("Cancel"), NULL);
480 if (G_ALERTDEFAULT == val) {
481 ok = disposition_notification_queue(account, to, tmp);
483 alertpanel_error(_("Can't queue the notification."));
486 alertpanel_error(_("Error occurred while sending the notification."));
489 if (unlink(tmp) < 0) FILE_OP_ERROR(tmp, "unlink");
494 void messageview_show(MessageView *messageview, MsgInfo *msginfo,
495 gboolean all_headers)
502 g_return_if_fail(msginfo != NULL);
503 messageview->msginfo = msginfo;
506 if ((fp = procmsg_open_message_decrypted(msginfo, &mimeinfo)) == NULL)
508 #else /* !USE_GPGME */
509 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
510 mimeinfo = procmime_scan_mime_header(fp);
511 #endif /* USE_GPGME */
513 if (!mimeinfo) return;
515 file = procmsg_get_message_file_path(msginfo);
517 g_warning(_("can't get message file path.\n"));
518 procmime_mimeinfo_free_all(mimeinfo);
522 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
524 headerview_show(messageview->headerview, tmpmsginfo);
525 procmsg_msginfo_free(tmpmsginfo);
527 messageview->all_headers = all_headers;
528 textview_set_all_headers(messageview->textview, all_headers);
529 textview_set_all_headers(messageview->mimeview->textview, all_headers);
531 if (mimeinfo->mime_type != MIME_TEXT &&
532 mimeinfo->mime_type != MIME_TEXT_HTML) {
533 messageview_change_view_type(messageview, MVIEW_MIME);
534 mimeview_show_message(messageview->mimeview, mimeinfo, file);
536 messageview_change_view_type(messageview, MVIEW_TEXT);
537 textview_show_message(messageview->textview, mimeinfo, file);
538 procmime_mimeinfo_free_all(mimeinfo);
541 if (MSG_IS_RETRCPT_PENDING(msginfo->flags))
542 return_receipt_show(messageview->noticeview, msginfo);
544 noticeview_hide(messageview->noticeview);
549 static void messageview_change_view_type(MessageView *messageview,
552 TextView *textview = messageview->textview;
553 MimeView *mimeview = messageview->mimeview;
555 if (messageview->type == type) return;
557 if (type == MVIEW_MIME) {
558 gtkut_container_remove
559 (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
560 GTK_WIDGET_PTR(textview));
561 gtk_box_pack_start(GTK_BOX(messageview->vbox),
562 GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
563 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
564 GTK_WIDGET_PTR(textview));
565 } else if (type == MVIEW_TEXT) {
566 gtkut_container_remove
567 (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
568 GTK_WIDGET_PTR(mimeview));
570 if (mimeview->vbox == GTK_WIDGET_PTR(textview)->parent)
571 gtkut_container_remove(GTK_CONTAINER(mimeview->vbox),
572 GTK_WIDGET_PTR(textview));
574 gtk_box_pack_start(GTK_BOX(messageview->vbox),
575 GTK_WIDGET_PTR(textview), TRUE, TRUE, 0);
579 messageview->type = type;
582 void messageview_clear(MessageView *messageview)
584 messageview_change_view_type(messageview, MVIEW_TEXT);
585 headerview_clear(messageview->headerview);
586 textview_clear(messageview->textview);
587 imageview_clear(messageview->imageview);
588 noticeview_hide(messageview->noticeview);
591 void messageview_destroy(MessageView *messageview)
593 GtkWidget *textview = GTK_WIDGET_PTR(messageview->textview);
594 GtkWidget *imageview = GTK_WIDGET_PTR(messageview->imageview);
595 GtkWidget *mimeview = GTK_WIDGET_PTR(messageview->mimeview);
597 headerview_destroy(messageview->headerview);
598 textview_destroy(messageview->textview);
599 imageview_destroy(messageview->imageview);
600 mimeview_destroy(messageview->mimeview);
601 noticeview_destroy(messageview->noticeview);
603 toolbar_clear_list(TOOLBAR_MSGVIEW);
604 TOOLBAR_DESTROY_ITEMS(messageview->toolbar->item_list);
605 TOOLBAR_DESTROY_ACTIONS(messageview->toolbar->action_list);
609 gtk_widget_unref(textview);
610 gtk_widget_unref(imageview);
611 gtk_widget_unref(mimeview);
614 void messageview_quote_color_set(void)
618 void messageview_set_font(MessageView *messageview)
620 textview_set_font(messageview->textview, NULL);
623 TextView *messageview_get_current_textview(MessageView *messageview)
625 TextView *text = NULL;
627 if (messageview->type == MVIEW_TEXT)
628 text = messageview->textview;
629 else if (messageview->type == MVIEW_MIME) {
630 if (gtk_notebook_get_current_page
631 (GTK_NOTEBOOK(messageview->mimeview->notebook)) == 0)
632 text = messageview->textview;
633 else if (messageview->mimeview->type == MIMEVIEW_TEXT)
634 text = messageview->mimeview->textview;
640 void messageview_copy_clipboard(MessageView *messageview)
644 text = messageview_get_current_textview(messageview);
646 gtk_editable_copy_clipboard(GTK_EDITABLE(text->text));
649 void messageview_select_all(MessageView *messageview)
653 text = messageview_get_current_textview(messageview);
655 gtk_editable_select_region(GTK_EDITABLE(text->text), 0, -1);
658 void messageview_set_position(MessageView *messageview, gint pos)
660 textview_set_position(messageview->textview, pos);
663 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
666 return textview_search_string(messageview->textview, str, case_sens);
670 gboolean messageview_search_string_backward(MessageView *messageview,
674 return textview_search_string_backward(messageview->textview,
679 gboolean messageview_is_visible(MessageView *messageview)
681 return messageview->visible;
684 static void messageview_destroy_cb(GtkWidget *widget, MessageView *messageview)
686 messageview_destroy(messageview);
689 static void messageview_size_allocate_cb(GtkWidget *widget,
690 GtkAllocation *allocation)
692 g_return_if_fail(allocation != NULL);
694 prefs_common.msgwin_width = allocation->width;
695 prefs_common.msgwin_height = allocation->height;
698 static void key_pressed(GtkWidget *widget, GdkEventKey *event,
699 MessageView *messageview)
701 if (event && event->keyval == GDK_Escape && messageview->window)
702 gtk_widget_destroy(messageview->window);
705 void messageview_toggle_view_real(MessageView *messageview)
707 MainWindow *mainwin = messageview->mainwin;
708 union CompositeWin *cwin = &mainwin->win;
709 GtkWidget *vpaned = NULL;
710 GtkWidget *container = NULL;
711 GtkItemFactory *ifactory = gtk_item_factory_from_widget(mainwin->menubar);
713 switch (mainwin->type) {
715 vpaned = cwin->sep_none.vpaned;
716 container = cwin->sep_none.hpaned;
718 case SEPARATE_FOLDER:
719 vpaned = cwin->sep_folder.vpaned;
720 container = mainwin->vbox_body;
722 case SEPARATE_MESSAGE:
727 if (vpaned->parent != NULL) {
728 gtk_widget_ref(vpaned);
729 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
730 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), container);
731 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
732 gtk_widget_grab_focus(GTK_WIDGET(messageview->textview->text));
734 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), vpaned);
735 gtk_container_add(GTK_CONTAINER(container), vpaned);
736 gtk_widget_unref(vpaned);
737 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
738 gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
742 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
744 noticeview_set_text(noticeview, _("This messages asks for a return receipt."));
745 noticeview_set_button_text(noticeview, _("Send receipt"));
746 noticeview_set_button_press_callback(noticeview,
747 GTK_SIGNAL_FUNC(return_receipt_send_clicked),
749 noticeview_show(noticeview);
752 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
757 file = procmsg_get_message_file_path(msginfo);
759 g_warning(_("can't get message file path.\n"));
763 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
764 tmpmsginfo->folder = msginfo->folder;
765 tmpmsginfo->msgnum = msginfo->msgnum;
767 if (disposition_notification_send(tmpmsginfo) >= 0) {
768 procmsg_msginfo_unset_flags(msginfo, MSG_RETRCPT_PENDING, 0);
769 noticeview_hide(noticeview);
772 procmsg_msginfo_free(tmpmsginfo);
776 static void select_account_cb(GtkWidget *w, gpointer data)
778 *(gint*)data = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(w)));
781 static PrefsAccount *select_account_from_list(GList *ac_list)
787 g_return_val_if_fail(ac_list != NULL, NULL);
788 g_return_val_if_fail(ac_list->data != NULL, NULL);
790 optmenu = gtk_option_menu_new();
791 menu = gtkut_account_menu_new(ac_list, select_account_cb, &account_id);
794 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
795 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
796 account_id = ((PrefsAccount *) ac_list->data)->account_id;
797 if (alertpanel_with_widget(
798 _("Return Receipt Notification"),
799 _("The message was sent to several of your "
801 "Please choose which account do you want to "
802 "use for sending the receipt notification:"),
803 _("Send Notification"), _("+Cancel"), NULL,
804 optmenu) != G_ALERTDEFAULT)
806 return account_find_from_id(account_id);
809 static void messageview_toolbar_create(MessageView *messageview,
810 GtkWidget *container)
812 ToolbarItem *toolbar_item;
815 GtkWidget *icon_wid = NULL;
817 GtkTooltips *toolbar_tips;
818 ToolbarSylpheedActions *action_item;
820 GSList *toolbar_list;
822 toolbar_tips = gtk_tooltips_new();
824 toolbar_read_config_file(TOOLBAR_MSGVIEW);
825 toolbar_list = toolbar_get_list(TOOLBAR_MSGVIEW);
827 messageview->toolbar = g_new0(Toolbar, 1);
829 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
831 gtk_container_add(GTK_CONTAINER(container), toolbar);
832 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
833 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
834 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
835 GTK_TOOLBAR_SPACE_LINE);
837 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
839 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, SEPARATOR) == 0) {
840 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
844 toolbar_item = g_new0(ToolbarItem, 1);
845 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
846 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
847 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
849 toolbar_item->parent = g_new0(ToolbarParent, 1);
850 toolbar_item->parent->data = (gpointer)messageview;
851 toolbar_item->parent->type = TOOLBAR_MSGVIEW;
853 /* collect toolbar items in list to keep track */
854 messageview->toolbar->item_list =
855 g_slist_append(messageview->toolbar->item_list,
858 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
859 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
863 icon_wid, toolbar_messageview_buttons_cb,
866 switch (toolbar_item->index) {
867 case A_COMPOSE_EMAIL:
868 messageview->toolbar->compose_mail_btn = item;
869 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
870 messageview->toolbar->compose_mail_btn,
871 _("Compose Email"), NULL);
873 case A_REPLY_MESSAGE:
874 messageview->toolbar->reply_btn = item;
875 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
876 messageview->toolbar->reply_btn,
877 _("Reply to Message"), NULL);
880 messageview->toolbar->replysender_btn = item;
881 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
882 messageview->toolbar->replysender_btn,
883 _("Reply to Sender"), NULL);
886 messageview->toolbar->replyall_btn = item;
887 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
888 messageview->toolbar->replyall_btn,
889 _("Reply to All"), NULL);
892 messageview->toolbar->replylist_btn = item;
893 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
894 messageview->toolbar->replylist_btn,
895 _("Reply to Mailing-list"), NULL);
898 messageview->toolbar->fwd_btn = item;
899 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
900 messageview->toolbar->fwd_btn,
901 _("Forward Message"), NULL);
904 messageview->toolbar->delete_btn = item;
905 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
906 messageview->toolbar->delete_btn,
907 _("Delete Message"), NULL);
910 messageview->toolbar->next_btn = item;
911 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
912 messageview->toolbar->next_btn,
913 _("Goto Next Message"), NULL);
916 action_item = g_new0(ToolbarSylpheedActions, 1);
917 action_item->widget = item;
918 action_item->name = g_strdup(toolbar_item->text);
920 messageview->toolbar->action_list =
921 g_slist_append(messageview->toolbar->action_list,
924 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
926 action_item->name, NULL);
928 gtk_widget_show(item);
935 messageview->toolbar->toolbar = toolbar;
937 gtk_widget_show_all(toolbar);
940 static void toolbar_messageview_buttons_cb(GtkWidget *widget,
946 void (*func)(GtkWidget *widget, gpointer data);
947 } messageview_action[] = {
948 { A_COMPOSE_EMAIL, common_toolbar_compose_cb },
949 { A_REPLY_MESSAGE, common_toolbar_reply_cb },
950 { A_REPLY_SENDER, common_toolbar_reply_to_sender_cb },
951 { A_REPLY_ALL, common_toolbar_reply_to_all_cb },
952 { A_REPLY_ML, common_toolbar_reply_to_list_cb },
953 { A_FORWARD, common_toolbar_forward_cb },
954 { A_DELETE, common_toolbar_delete_cb },
955 { A_GOTO_NEXT, common_toolbar_next_unread_cb },
956 { A_SYL_ACTIONS, common_toolbar_actions_execute_cb },
960 gint num_items = sizeof(messageview_action)/sizeof(messageview_action[0]);
962 for (i = 0; i < num_items; i++) {
964 if (messageview_action[i].index == item->index) {
965 messageview_action[i].func(widget, (gpointer)item->parent);
971 void messageview_reply_cb(gpointer data, guint action, GtkWidget *widget)
973 MessageView *messageview = (MessageView *)data;
977 common_toolbar_reply_cb(NULL,messageview);
979 case COMPOSE_REPLY_TO_ALL:
980 common_toolbar_reply_to_all_cb(NULL,messageview);
982 case COMPOSE_REPLY_TO_SENDER:
983 common_toolbar_reply_to_sender_cb(NULL,messageview);
985 case COMPOSE_REPLY_TO_LIST:
986 common_toolbar_reply_to_list_cb(NULL,messageview);
991 static void messageview_delete_cb(gpointer data, guint action, GtkWidget *widget)
993 MessageView *messageview = (MessageView *)data;
995 common_toolbar_delete_cb(NULL,messageview);
998 static void messageview_close_cb(gpointer data, guint action, GtkWidget *widget)
1000 MessageView *messageview = (MessageView *)data;
1002 gtk_widget_destroy(messageview->window);