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 focus_in (GtkWidget *widget,
68 static void messageview_toolbar_create (MessageView *messageview,
69 GtkWidget *container);
70 static void toolbar_messageview_buttons_cb (GtkWidget *widget,
73 static void return_receipt_show (NoticeView *noticeview,
75 static void return_receipt_send_clicked (NoticeView *noticeview,
78 static PrefsAccount *select_account_from_list
81 static void messageview_reply_cb (gpointer data,
85 static void messageview_delete_cb (gpointer data,
89 static void messageview_close_cb (gpointer data,
93 static void set_toolbar_style(MessageView *messageview);
96 MessageView *messageview_create(MainWindow *mainwin)
98 MessageView *messageview;
100 HeaderView *headerview;
102 ImageView *imageview;
104 NoticeView *noticeview;
106 debug_print("Creating message view...\n");
107 messageview = g_new0(MessageView, 1);
109 messageview->type = MVIEW_TEXT;
111 headerview = headerview_create();
113 noticeview = noticeview_create(mainwin);
115 textview = textview_create();
116 textview->messageview = messageview;
118 imageview = imageview_create();
119 imageview->messageview = messageview;
121 mimeview = mimeview_create();
122 mimeview->textview = textview_create();
123 mimeview->textview->messageview = messageview;
124 mimeview->imageview = imageview;
125 mimeview->messageview = messageview;
127 vbox = gtk_vbox_new(FALSE, 0);
128 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
130 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
132 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(textview),
135 /* to remove without destroyed */
136 gtk_widget_ref(GTK_WIDGET_PTR(textview));
137 gtk_widget_ref(GTK_WIDGET_PTR(imageview));
138 gtk_widget_ref(GTK_WIDGET_PTR(mimeview));
139 gtk_widget_ref(GTK_WIDGET_PTR(mimeview->textview));
141 messageview->vbox = vbox;
142 messageview->new_window = FALSE;
143 messageview->window = NULL;
144 messageview->headerview = headerview;
145 messageview->textview = textview;
146 messageview->imageview = imageview;
147 messageview->mimeview = mimeview;
148 messageview->noticeview = noticeview;
149 messageview->mainwin = mainwin;
154 static GtkItemFactoryEntry messageview_entries[] =
156 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
157 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
158 {N_("/_File/_Close"), "<control>W", messageview_close_cb, 0, NULL},
160 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
161 {N_("/_Message/_Reply"), "<control>R", messageview_reply_cb, COMPOSE_REPLY, NULL},
162 {N_("/_Message/Repl_y to"), NULL, NULL, 0, "<Branch>"},
163 {N_("/_Message/Repl_y to/_all"), "<shift><control>R", messageview_reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
164 {N_("/_Message/Repl_y to/_sender"), NULL, messageview_reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
165 {N_("/_Message/Repl_y to/mailing _list"),
166 "<control>L", messageview_reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
167 {N_("/_Message/Follow-up and reply to"),NULL, messageview_reply_cb, COMPOSE_FOLLOWUP_AND_REPLY_TO, NULL},
168 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
169 {N_("/_Message/_Delete"), "<control>D", messageview_delete_cb, 0, NULL},
171 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
172 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
177 MessageView *messageview_create_with_new_window(MainWindow *mainwin)
180 MessageView *msgview;
183 GtkWidget *handlebox;
185 guint n_menu_entries;
187 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
188 gtk_window_set_title(GTK_WINDOW(window), _("Sylpheed - Message View"));
189 gtk_window_set_wmclass(GTK_WINDOW(window), "message_view", "Sylpheed");
190 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
191 gtk_widget_set_usize(window, prefs_common.msgwin_width,
192 prefs_common.msgwin_height);
194 vbox = gtk_vbox_new(FALSE, 0);
195 gtk_widget_show(vbox);
196 gtk_container_add(GTK_CONTAINER(window), vbox);
198 msgview = messageview_create(mainwin);
200 gtk_signal_connect(GTK_OBJECT(window), "size_allocate",
201 GTK_SIGNAL_FUNC(messageview_size_allocate_cb),
203 gtk_signal_connect(GTK_OBJECT(window), "destroy",
204 GTK_SIGNAL_FUNC(messageview_destroy_cb), msgview);
205 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
206 GTK_SIGNAL_FUNC(key_pressed), msgview);
207 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
208 GTK_SIGNAL_FUNC(focus_in), msgview);
210 n_menu_entries = sizeof(messageview_entries) / sizeof(messageview_entries[0]);
211 menubar = menubar_create(window, messageview_entries,
212 n_menu_entries, "<MessageView>", msgview);
213 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
215 handlebox = gtk_handle_box_new();
216 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
217 messageview_toolbar_create(msgview,handlebox);
219 gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET_PTR(msgview));
220 gtk_widget_grab_focus(msgview->textview->text);
221 gtk_widget_show_all(window);
223 msgview->new_window = TRUE;
224 msgview->window = window;
225 msgview->visible = TRUE;
226 msgview->menubar = menubar;
227 msgview->handlebox = handlebox;
230 messageview_init(msgview);
231 common_toolbar_set_style(msgview, TOOLBAR_MSGVIEW);
236 void messageview_init(MessageView *messageview)
238 headerview_init(messageview->headerview);
239 textview_init(messageview->textview);
240 imageview_init(messageview->imageview);
241 mimeview_init(messageview->mimeview);
242 /*messageview_set_font(messageview);*/
244 noticeview_hide(messageview->noticeview);
247 static void notification_convert_header(gchar *dest, gint len,
253 g_return_if_fail(src_ != NULL);
254 g_return_if_fail(dest != NULL);
258 Xstrndup_a(src, src_, len, return);
262 if (is_ascii_str(src)) {
263 strncpy2(dest, src, len);
264 dest[len - 1] = '\0';
267 conv_encode_header(dest, len, src, header_len);
270 static gint disposition_notification_queue(PrefsAccount * account,
271 gchar * to, const gchar *file)
279 debug_print("queueing message...\n");
280 g_return_val_if_fail(account != NULL, -1);
282 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
283 G_DIR_SEPARATOR, (gint)file);
284 if ((fp = fopen(tmp, "wb")) == NULL) {
285 FILE_OP_ERROR(tmp, "fopen");
289 if ((src_fp = fopen(file, "rb")) == NULL) {
290 FILE_OP_ERROR(file, "fopen");
296 if (change_file_mode_rw(fp, tmp) < 0) {
297 FILE_OP_ERROR(tmp, "chmod");
298 g_warning(_("can't change file mode\n"));
301 /* queueing variables */
302 fprintf(fp, "AF:\n");
303 fprintf(fp, "NF:0\n");
304 fprintf(fp, "PS:10\n");
305 fprintf(fp, "SRH:1\n");
306 fprintf(fp, "SFN:\n");
307 fprintf(fp, "DSR:\n");
308 fprintf(fp, "MID:\n");
309 fprintf(fp, "CFG:\n");
310 fprintf(fp, "PT:0\n");
311 fprintf(fp, "S:%s\n", account->address);
312 fprintf(fp, "RQ:\n");
313 if (account->smtp_server)
314 fprintf(fp, "SSV:%s\n", account->smtp_server);
316 fprintf(fp, "SSV:\n");
317 if (account->nntp_server)
318 fprintf(fp, "NSV:%s\n", account->nntp_server);
320 fprintf(fp, "NSV:\n");
321 fprintf(fp, "SSH:\n");
322 fprintf(fp, "R:<%s>", to);
326 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
327 if (fputs(buf, fp) == EOF) {
328 FILE_OP_ERROR(tmp, "fputs");
338 if (fclose(fp) == EOF) {
339 FILE_OP_ERROR(tmp, "fclose");
345 queue = folder_get_default_queue();
346 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
347 g_warning(_("can't queue the message\n"));
354 folder_update_item(queue, TRUE);
359 static gint disposition_notification_send(MsgInfo *msginfo)
362 gchar tmp[MAXPATHLEN + 1];
366 PrefsAccount *account;
370 if ((!msginfo->returnreceiptto) &&
371 (!msginfo->dispositionnotificationto))
374 /* RFC2298: Test for Return-Path */
375 if (msginfo->dispositionnotificationto)
376 to = msginfo->dispositionnotificationto;
378 to = msginfo->returnreceiptto;
380 ok = get_header_from_msginfo(msginfo, buf, sizeof(buf),
383 gchar *to_addr = g_strdup(to);
384 extract_address(to_addr);
385 extract_address(buf);
386 ok = strcmp(to_addr, buf);
389 strncpy(buf, _("<No Return-Path found>"),
396 message = g_strdup_printf(
397 _("The notification address to which the "
398 "return receipt is to be sent\n"
399 "does not correspond to the return path:\n"
400 "Notification address: %s\n"
402 "It is advised to not to send the return "
403 "receipt."), to, buf);
404 val = alertpanel(_("Warning"), message, _("Send"),
405 _("+Don't Send"), NULL);
406 if (val != G_ALERTDEFAULT)
410 ac_list = account_find_all_from_address(NULL, msginfo->to);
411 ac_list = account_find_all_from_address(ac_list, msginfo->cc);
413 if (ac_list == NULL) {
414 alertpanel_error(_("This message is asking for a return "
415 "receipt notification\n"
416 "but according to its 'To:' and 'CC:' "
417 "headers it was not\nofficially addressed "
419 "Receipt notification cancelled."));
423 if (g_list_length(ac_list) > 1)
424 account = select_account_from_list(ac_list);
426 account = (PrefsAccount *) ac_list->data;
427 g_list_free(ac_list);
432 /* write to temporary file */
433 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
434 get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
436 if ((fp = fopen(tmp, "wb")) == NULL) {
437 FILE_OP_ERROR(tmp, "fopen");
441 /* chmod for security */
442 if (change_file_mode_rw(fp, tmp) < 0) {
443 FILE_OP_ERROR(tmp, "chmod");
444 g_warning(_("can't change file mode\n"));
448 get_rfc822_date(buf, sizeof(buf));
449 fprintf(fp, "Date: %s\n", buf);
452 if (account->name && *account->name) {
453 notification_convert_header
454 (buf, sizeof(buf), account->name,
456 fprintf(fp, "From: %s <%s>\n", buf, account->address);
458 fprintf(fp, "From: %s\n", account->address);
460 fprintf(fp, "To: %s\n", to);
463 notification_convert_header(buf, sizeof(buf), msginfo->subject,
464 strlen("Subject: "));
465 fprintf(fp, "Subject: Disposition notification: %s\n", buf);
467 if (fclose(fp) == EOF) {
468 FILE_OP_ERROR(tmp, "fclose");
473 to_list = address_list_append(NULL, to);
474 ok = send_message(tmp, account, to_list);
477 if (prefs_common.queue_msg) {
482 _("Error occurred while sending the notification.\n"
483 "Put this notification into queue folder?"),
484 _("OK"), _("Cancel"), NULL);
485 if (G_ALERTDEFAULT == val) {
486 ok = disposition_notification_queue(account, to, tmp);
488 alertpanel_error(_("Can't queue the notification."));
491 alertpanel_error(_("Error occurred while sending the notification."));
494 if (unlink(tmp) < 0) FILE_OP_ERROR(tmp, "unlink");
499 void messageview_show(MessageView *messageview, MsgInfo *msginfo,
500 gboolean all_headers)
507 g_return_if_fail(msginfo != NULL);
508 messageview->msginfo = msginfo;
511 if ((fp = procmsg_open_message_decrypted(msginfo, &mimeinfo)) == NULL)
513 #else /* !USE_GPGME */
514 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
515 mimeinfo = procmime_scan_mime_header(fp);
516 #endif /* USE_GPGME */
518 if (!mimeinfo) return;
520 file = procmsg_get_message_file_path(msginfo);
522 g_warning(_("can't get message file path.\n"));
523 procmime_mimeinfo_free_all(mimeinfo);
527 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
529 headerview_show(messageview->headerview, tmpmsginfo);
530 procmsg_msginfo_free(tmpmsginfo);
532 messageview->all_headers = all_headers;
533 textview_set_all_headers(messageview->textview, all_headers);
534 textview_set_all_headers(messageview->mimeview->textview, all_headers);
536 if (mimeinfo->mime_type != MIME_TEXT &&
537 mimeinfo->mime_type != MIME_TEXT_HTML) {
538 messageview_change_view_type(messageview, MVIEW_MIME);
539 mimeview_show_message(messageview->mimeview, mimeinfo, file);
541 messageview_change_view_type(messageview, MVIEW_TEXT);
542 textview_show_message(messageview->textview, mimeinfo, file);
543 procmime_mimeinfo_free_all(mimeinfo);
546 if (MSG_IS_RETRCPT_PENDING(msginfo->flags))
547 return_receipt_show(messageview->noticeview, msginfo);
549 noticeview_hide(messageview->noticeview);
554 static void messageview_change_view_type(MessageView *messageview,
557 TextView *textview = messageview->textview;
558 MimeView *mimeview = messageview->mimeview;
560 if (messageview->type == type) return;
562 if (type == MVIEW_MIME) {
563 gtkut_container_remove
564 (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
565 GTK_WIDGET_PTR(textview));
566 gtk_box_pack_start(GTK_BOX(messageview->vbox),
567 GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
568 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
569 GTK_WIDGET_PTR(textview));
570 } else if (type == MVIEW_TEXT) {
571 gtkut_container_remove
572 (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
573 GTK_WIDGET_PTR(mimeview));
575 if (mimeview->vbox == GTK_WIDGET_PTR(textview)->parent)
576 gtkut_container_remove(GTK_CONTAINER(mimeview->vbox),
577 GTK_WIDGET_PTR(textview));
579 gtk_box_pack_start(GTK_BOX(messageview->vbox),
580 GTK_WIDGET_PTR(textview), TRUE, TRUE, 0);
584 messageview->type = type;
587 void messageview_clear(MessageView *messageview)
589 messageview_change_view_type(messageview, MVIEW_TEXT);
590 headerview_clear(messageview->headerview);
591 textview_clear(messageview->textview);
592 imageview_clear(messageview->imageview);
593 noticeview_hide(messageview->noticeview);
596 void messageview_destroy(MessageView *messageview)
598 GtkWidget *textview = GTK_WIDGET_PTR(messageview->textview);
599 GtkWidget *imageview = GTK_WIDGET_PTR(messageview->imageview);
600 GtkWidget *mimeview = GTK_WIDGET_PTR(messageview->mimeview);
602 headerview_destroy(messageview->headerview);
603 textview_destroy(messageview->textview);
604 imageview_destroy(messageview->imageview);
605 mimeview_destroy(messageview->mimeview);
606 noticeview_destroy(messageview->noticeview);
608 toolbar_clear_list(TOOLBAR_MSGVIEW);
609 TOOLBAR_DESTROY_ITEMS(messageview->toolbar->item_list);
610 TOOLBAR_DESTROY_ACTIONS(messageview->toolbar->action_list);
614 gtk_widget_unref(textview);
615 gtk_widget_unref(imageview);
616 gtk_widget_unref(mimeview);
619 void messageview_quote_color_set(void)
623 void messageview_set_font(MessageView *messageview)
625 textview_set_font(messageview->textview, NULL);
628 TextView *messageview_get_current_textview(MessageView *messageview)
630 TextView *text = NULL;
632 if (messageview->type == MVIEW_TEXT)
633 text = messageview->textview;
634 else if (messageview->type == MVIEW_MIME) {
635 if (gtk_notebook_get_current_page
636 (GTK_NOTEBOOK(messageview->mimeview->notebook)) == 0)
637 text = messageview->textview;
638 else if (messageview->mimeview->type == MIMEVIEW_TEXT)
639 text = messageview->mimeview->textview;
645 void messageview_copy_clipboard(MessageView *messageview)
649 text = messageview_get_current_textview(messageview);
651 gtk_editable_copy_clipboard(GTK_EDITABLE(text->text));
654 void messageview_select_all(MessageView *messageview)
658 text = messageview_get_current_textview(messageview);
660 gtk_editable_select_region(GTK_EDITABLE(text->text), 0, -1);
663 void messageview_set_position(MessageView *messageview, gint pos)
665 textview_set_position(messageview->textview, pos);
668 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
671 return textview_search_string(messageview->textview, str, case_sens);
675 gboolean messageview_search_string_backward(MessageView *messageview,
679 return textview_search_string_backward(messageview->textview,
684 gboolean messageview_is_visible(MessageView *messageview)
686 return messageview->visible;
689 static void messageview_destroy_cb(GtkWidget *widget, MessageView *messageview)
691 messageview_destroy(messageview);
694 static void messageview_size_allocate_cb(GtkWidget *widget,
695 GtkAllocation *allocation)
697 g_return_if_fail(allocation != NULL);
699 prefs_common.msgwin_width = allocation->width;
700 prefs_common.msgwin_height = allocation->height;
703 static void key_pressed(GtkWidget *widget, GdkEventKey *event,
704 MessageView *messageview)
706 if (event && event->keyval == GDK_Escape && messageview->window)
707 gtk_widget_destroy(messageview->window);
710 static void focus_in(GtkWidget *widget, GdkEventFocus *event,
713 MessageView *msgview = (MessageView*)data;
715 summary_select_by_msgnum(msgview->mainwin->summaryview,
716 msgview->msginfo->msgnum);
719 void messageview_toggle_view_real(MessageView *messageview)
721 MainWindow *mainwin = messageview->mainwin;
722 union CompositeWin *cwin = &mainwin->win;
723 GtkWidget *vpaned = NULL;
724 GtkWidget *container = NULL;
725 GtkItemFactory *ifactory = gtk_item_factory_from_widget(mainwin->menubar);
727 switch (mainwin->type) {
729 vpaned = cwin->sep_none.vpaned;
730 container = cwin->sep_none.hpaned;
732 case SEPARATE_FOLDER:
733 vpaned = cwin->sep_folder.vpaned;
734 container = mainwin->vbox_body;
736 case SEPARATE_MESSAGE:
741 if (vpaned->parent != NULL) {
742 gtk_widget_ref(vpaned);
743 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
744 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), container);
745 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
746 gtk_widget_grab_focus(GTK_WIDGET(messageview->textview->text));
748 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), vpaned);
749 gtk_container_add(GTK_CONTAINER(container), vpaned);
750 gtk_widget_unref(vpaned);
751 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
752 gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
756 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
758 noticeview_set_text(noticeview, _("This messages asks for a return receipt."));
759 noticeview_set_button_text(noticeview, _("Send receipt"));
760 noticeview_set_button_press_callback(noticeview,
761 GTK_SIGNAL_FUNC(return_receipt_send_clicked),
763 noticeview_show(noticeview);
766 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
771 file = procmsg_get_message_file_path(msginfo);
773 g_warning(_("can't get message file path.\n"));
777 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
778 tmpmsginfo->folder = msginfo->folder;
779 tmpmsginfo->msgnum = msginfo->msgnum;
781 if (disposition_notification_send(tmpmsginfo) >= 0) {
782 procmsg_msginfo_unset_flags(msginfo, MSG_RETRCPT_PENDING, 0);
783 noticeview_hide(noticeview);
786 procmsg_msginfo_free(tmpmsginfo);
790 static void select_account_cb(GtkWidget *w, gpointer data)
792 *(gint*)data = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(w)));
795 static PrefsAccount *select_account_from_list(GList *ac_list)
801 g_return_val_if_fail(ac_list != NULL, NULL);
802 g_return_val_if_fail(ac_list->data != NULL, NULL);
804 optmenu = gtk_option_menu_new();
805 menu = gtkut_account_menu_new(ac_list, select_account_cb, &account_id);
808 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
809 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
810 account_id = ((PrefsAccount *) ac_list->data)->account_id;
811 if (alertpanel_with_widget(
812 _("Return Receipt Notification"),
813 _("The message was sent to several of your "
815 "Please choose which account do you want to "
816 "use for sending the receipt notification:"),
817 _("Send Notification"), _("+Cancel"), NULL,
818 optmenu) != G_ALERTDEFAULT)
820 return account_find_from_id(account_id);
823 static void messageview_toolbar_create(MessageView *messageview,
824 GtkWidget *container)
826 ToolbarItem *toolbar_item;
829 GtkWidget *icon_wid = NULL;
831 GtkTooltips *toolbar_tips;
832 ToolbarSylpheedActions *action_item;
834 GSList *toolbar_list;
836 toolbar_tips = gtk_tooltips_new();
838 toolbar_read_config_file(TOOLBAR_MSGVIEW);
839 toolbar_list = toolbar_get_list(TOOLBAR_MSGVIEW);
841 messageview->toolbar = g_new0(Toolbar, 1);
843 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
845 gtk_container_add(GTK_CONTAINER(container), toolbar);
846 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
847 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
848 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
849 GTK_TOOLBAR_SPACE_LINE);
851 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
853 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, SEPARATOR) == 0) {
854 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
858 toolbar_item = g_new0(ToolbarItem, 1);
859 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
860 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
861 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
863 toolbar_item->parent = g_new0(ToolbarParent, 1);
864 toolbar_item->parent->data = (gpointer)messageview;
865 toolbar_item->parent->type = TOOLBAR_MSGVIEW;
867 /* collect toolbar items in list to keep track */
868 messageview->toolbar->item_list =
869 g_slist_append(messageview->toolbar->item_list,
872 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
873 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
877 icon_wid, toolbar_messageview_buttons_cb,
880 switch (toolbar_item->index) {
881 case A_COMPOSE_EMAIL:
882 messageview->toolbar->compose_mail_btn = item;
883 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
884 messageview->toolbar->compose_mail_btn,
885 _("Compose Email"), NULL);
887 case A_REPLY_MESSAGE:
888 messageview->toolbar->reply_btn = item;
889 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
890 messageview->toolbar->reply_btn,
891 _("Reply to Message"), NULL);
894 messageview->toolbar->replysender_btn = item;
895 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
896 messageview->toolbar->replysender_btn,
897 _("Reply to Sender"), NULL);
900 messageview->toolbar->replyall_btn = item;
901 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
902 messageview->toolbar->replyall_btn,
903 _("Reply to All"), NULL);
906 messageview->toolbar->replylist_btn = item;
907 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
908 messageview->toolbar->replylist_btn,
909 _("Reply to Mailing-list"), NULL);
912 messageview->toolbar->fwd_btn = item;
913 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
914 messageview->toolbar->fwd_btn,
915 _("Forward Message"), NULL);
918 messageview->toolbar->delete_btn = item;
919 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
920 messageview->toolbar->delete_btn,
921 _("Delete Message"), NULL);
924 messageview->toolbar->next_btn = item;
925 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
926 messageview->toolbar->next_btn,
927 _("Goto Next Message"), NULL);
930 action_item = g_new0(ToolbarSylpheedActions, 1);
931 action_item->widget = item;
932 action_item->name = g_strdup(toolbar_item->text);
934 messageview->toolbar->action_list =
935 g_slist_append(messageview->toolbar->action_list,
938 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
940 action_item->name, NULL);
942 gtk_widget_show(item);
949 messageview->toolbar->toolbar = toolbar;
951 gtk_widget_show_all(toolbar);
954 static void toolbar_messageview_buttons_cb(GtkWidget *widget,
960 void (*func)(GtkWidget *widget, gpointer data);
961 } messageview_action[] = {
962 { A_COMPOSE_EMAIL, common_toolbar_compose_cb },
963 { A_REPLY_MESSAGE, common_toolbar_reply_cb },
964 { A_REPLY_SENDER, common_toolbar_reply_to_sender_cb },
965 { A_REPLY_ALL, common_toolbar_reply_to_all_cb },
966 { A_REPLY_ML, common_toolbar_reply_to_list_cb },
967 { A_FORWARD, common_toolbar_forward_cb },
968 { A_DELETE, common_toolbar_delete_cb },
969 { A_GOTO_NEXT, common_toolbar_next_unread_cb },
970 { A_SYL_ACTIONS, common_toolbar_actions_execute_cb },
974 gint num_items = sizeof(messageview_action)/sizeof(messageview_action[0]);
976 for (i = 0; i < num_items; i++) {
978 if (messageview_action[i].index == item->index) {
979 messageview_action[i].func(widget, (gpointer)item->parent);
985 void messageview_reply_cb(gpointer data, guint action, GtkWidget *widget)
987 MessageView *messageview = (MessageView *)data;
991 common_toolbar_reply_cb(NULL,messageview);
993 case COMPOSE_REPLY_TO_ALL:
994 common_toolbar_reply_to_all_cb(NULL,messageview);
996 case COMPOSE_REPLY_TO_SENDER:
997 common_toolbar_reply_to_sender_cb(NULL,messageview);
999 case COMPOSE_REPLY_TO_LIST:
1000 common_toolbar_reply_to_list_cb(NULL,messageview);
1005 static void messageview_delete_cb(gpointer data, guint action, GtkWidget *widget)
1007 MessageView *messageview = (MessageView *)data;
1009 common_toolbar_delete_cb(NULL,messageview);
1012 static void messageview_close_cb(gpointer data, guint action, GtkWidget *widget)
1014 MessageView *messageview = (MessageView *)data;
1016 gtk_widget_destroy(messageview->window);