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 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);
204 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
205 GTK_SIGNAL_FUNC(focus_in), msgview);
207 n_menu_entries = sizeof(messageview_entries) / sizeof(messageview_entries[0]);
208 menubar = menubar_create(window, messageview_entries,
209 n_menu_entries, "<MessageView>", msgview);
210 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
212 handlebox = gtk_handle_box_new();
213 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
214 messageview_toolbar_create(msgview,handlebox);
216 gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET_PTR(msgview));
217 gtk_widget_grab_focus(msgview->textview->text);
218 gtk_widget_show_all(window);
220 msgview->new_window = TRUE;
221 msgview->window = window;
222 msgview->visible = TRUE;
223 msgview->menubar = menubar;
224 msgview->handlebox = handlebox;
227 messageview_init(msgview);
228 common_toolbar_set_style(msgview, TOOLBAR_MSGVIEW);
233 void messageview_init(MessageView *messageview)
235 headerview_init(messageview->headerview);
236 textview_init(messageview->textview);
237 imageview_init(messageview->imageview);
238 mimeview_init(messageview->mimeview);
239 /*messageview_set_font(messageview);*/
241 noticeview_hide(messageview->noticeview);
244 static void notification_convert_header(gchar *dest, gint len,
250 g_return_if_fail(src_ != NULL);
251 g_return_if_fail(dest != NULL);
255 Xstrndup_a(src, src_, len, return);
259 if (is_ascii_str(src)) {
260 strncpy2(dest, src, len);
261 dest[len - 1] = '\0';
264 conv_encode_header(dest, len, src, header_len);
267 static gint disposition_notification_queue(PrefsAccount * account,
268 gchar * to, const gchar *file)
276 debug_print("queueing message...\n");
277 g_return_val_if_fail(account != NULL, -1);
279 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
280 G_DIR_SEPARATOR, (gint)file);
281 if ((fp = fopen(tmp, "wb")) == NULL) {
282 FILE_OP_ERROR(tmp, "fopen");
286 if ((src_fp = fopen(file, "rb")) == NULL) {
287 FILE_OP_ERROR(file, "fopen");
293 if (change_file_mode_rw(fp, tmp) < 0) {
294 FILE_OP_ERROR(tmp, "chmod");
295 g_warning(_("can't change file mode\n"));
298 /* queueing variables */
299 fprintf(fp, "AF:\n");
300 fprintf(fp, "NF:0\n");
301 fprintf(fp, "PS:10\n");
302 fprintf(fp, "SRH:1\n");
303 fprintf(fp, "SFN:\n");
304 fprintf(fp, "DSR:\n");
305 fprintf(fp, "MID:\n");
306 fprintf(fp, "CFG:\n");
307 fprintf(fp, "PT:0\n");
308 fprintf(fp, "S:%s\n", account->address);
309 fprintf(fp, "RQ:\n");
310 if (account->smtp_server)
311 fprintf(fp, "SSV:%s\n", account->smtp_server);
313 fprintf(fp, "SSV:\n");
314 if (account->nntp_server)
315 fprintf(fp, "NSV:%s\n", account->nntp_server);
317 fprintf(fp, "NSV:\n");
318 fprintf(fp, "SSH:\n");
319 fprintf(fp, "R:<%s>", to);
323 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
324 if (fputs(buf, fp) == EOF) {
325 FILE_OP_ERROR(tmp, "fputs");
335 if (fclose(fp) == EOF) {
336 FILE_OP_ERROR(tmp, "fclose");
342 queue = folder_get_default_queue();
343 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
344 g_warning(_("can't queue the message\n"));
351 folder_update_item(queue, TRUE);
356 static gint disposition_notification_send(MsgInfo *msginfo)
359 gchar tmp[MAXPATHLEN + 1];
363 PrefsAccount *account;
367 if ((!msginfo->returnreceiptto) &&
368 (!msginfo->dispositionnotificationto))
371 /* RFC2298: Test for Return-Path */
372 if (msginfo->dispositionnotificationto)
373 to = msginfo->dispositionnotificationto;
375 to = msginfo->returnreceiptto;
377 ok = get_header_from_msginfo(msginfo, buf, sizeof(buf),
380 gchar *to_addr = g_strdup(to);
381 extract_address(to_addr);
382 extract_address(buf);
383 ok = strcmp(to_addr, buf);
386 strncpy(buf, _("<No Return-Path found>"),
393 message = g_strdup_printf(
394 _("The notification address to which the "
395 "return receipt is to be sent\n"
396 "does not correspond to the return path:\n"
397 "Notification address: %s\n"
399 "It is advised to not to send the return "
400 "receipt."), to, buf);
401 val = alertpanel(_("Warning"), message, _("Send"),
402 _("+Don't Send"), NULL);
403 if (val != G_ALERTDEFAULT)
407 ac_list = account_find_all_from_address(NULL, msginfo->to);
408 ac_list = account_find_all_from_address(ac_list, msginfo->cc);
410 if (ac_list == NULL) {
411 alertpanel_error(_("This message is asking for a return "
412 "receipt notification\n"
413 "but according to its 'To:' and 'CC:' "
414 "headers it was not\nofficially addressed "
416 "Receipt notification cancelled."));
420 if (g_list_length(ac_list) > 1)
421 account = select_account_from_list(ac_list);
423 account = (PrefsAccount *) ac_list->data;
424 g_list_free(ac_list);
429 /* write to temporary file */
430 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
431 get_rc_dir(), G_DIR_SEPARATOR, (gint)msginfo);
433 if ((fp = fopen(tmp, "wb")) == NULL) {
434 FILE_OP_ERROR(tmp, "fopen");
438 /* chmod for security */
439 if (change_file_mode_rw(fp, tmp) < 0) {
440 FILE_OP_ERROR(tmp, "chmod");
441 g_warning(_("can't change file mode\n"));
445 get_rfc822_date(buf, sizeof(buf));
446 fprintf(fp, "Date: %s\n", buf);
449 if (account->name && *account->name) {
450 notification_convert_header
451 (buf, sizeof(buf), account->name,
453 fprintf(fp, "From: %s <%s>\n", buf, account->address);
455 fprintf(fp, "From: %s\n", account->address);
457 fprintf(fp, "To: %s\n", to);
460 notification_convert_header(buf, sizeof(buf), msginfo->subject,
461 strlen("Subject: "));
462 fprintf(fp, "Subject: Disposition notification: %s\n", buf);
464 if (fclose(fp) == EOF) {
465 FILE_OP_ERROR(tmp, "fclose");
470 to_list = address_list_append(NULL, to);
471 ok = send_message(tmp, account, to_list);
474 if (prefs_common.queue_msg) {
479 _("Error occurred while sending the notification.\n"
480 "Put this notification into queue folder?"),
481 _("OK"), _("Cancel"), NULL);
482 if (G_ALERTDEFAULT == val) {
483 ok = disposition_notification_queue(account, to, tmp);
485 alertpanel_error(_("Can't queue the notification."));
488 alertpanel_error(_("Error occurred while sending the notification."));
491 if (unlink(tmp) < 0) FILE_OP_ERROR(tmp, "unlink");
496 void messageview_show(MessageView *messageview, MsgInfo *msginfo,
497 gboolean all_headers)
504 g_return_if_fail(msginfo != NULL);
505 messageview->msginfo = msginfo;
508 if ((fp = procmsg_open_message_decrypted(msginfo, &mimeinfo)) == NULL)
510 #else /* !USE_GPGME */
511 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
512 mimeinfo = procmime_scan_mime_header(fp);
513 #endif /* USE_GPGME */
515 if (!mimeinfo) return;
517 file = procmsg_get_message_file_path(msginfo);
519 g_warning(_("can't get message file path.\n"));
520 procmime_mimeinfo_free_all(mimeinfo);
524 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
526 headerview_show(messageview->headerview, tmpmsginfo);
527 procmsg_msginfo_free(tmpmsginfo);
529 messageview->all_headers = all_headers;
530 textview_set_all_headers(messageview->textview, all_headers);
531 textview_set_all_headers(messageview->mimeview->textview, all_headers);
533 if (mimeinfo->mime_type != MIME_TEXT &&
534 mimeinfo->mime_type != MIME_TEXT_HTML) {
535 messageview_change_view_type(messageview, MVIEW_MIME);
536 mimeview_show_message(messageview->mimeview, mimeinfo, file);
538 messageview_change_view_type(messageview, MVIEW_TEXT);
539 textview_show_message(messageview->textview, mimeinfo, file);
540 procmime_mimeinfo_free_all(mimeinfo);
543 if (MSG_IS_RETRCPT_PENDING(msginfo->flags))
544 return_receipt_show(messageview->noticeview, msginfo);
546 noticeview_hide(messageview->noticeview);
551 static void messageview_change_view_type(MessageView *messageview,
554 TextView *textview = messageview->textview;
555 MimeView *mimeview = messageview->mimeview;
557 if (messageview->type == type) return;
559 if (type == MVIEW_MIME) {
560 gtkut_container_remove
561 (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
562 GTK_WIDGET_PTR(textview));
563 gtk_box_pack_start(GTK_BOX(messageview->vbox),
564 GTK_WIDGET_PTR(mimeview), TRUE, TRUE, 0);
565 gtk_container_add(GTK_CONTAINER(mimeview->vbox),
566 GTK_WIDGET_PTR(textview));
567 } else if (type == MVIEW_TEXT) {
568 gtkut_container_remove
569 (GTK_CONTAINER(GTK_WIDGET_PTR(messageview)),
570 GTK_WIDGET_PTR(mimeview));
572 if (mimeview->vbox == GTK_WIDGET_PTR(textview)->parent)
573 gtkut_container_remove(GTK_CONTAINER(mimeview->vbox),
574 GTK_WIDGET_PTR(textview));
576 gtk_box_pack_start(GTK_BOX(messageview->vbox),
577 GTK_WIDGET_PTR(textview), TRUE, TRUE, 0);
581 messageview->type = type;
584 void messageview_clear(MessageView *messageview)
586 messageview_change_view_type(messageview, MVIEW_TEXT);
587 headerview_clear(messageview->headerview);
588 textview_clear(messageview->textview);
589 imageview_clear(messageview->imageview);
590 noticeview_hide(messageview->noticeview);
593 void messageview_destroy(MessageView *messageview)
595 GtkWidget *textview = GTK_WIDGET_PTR(messageview->textview);
596 GtkWidget *imageview = GTK_WIDGET_PTR(messageview->imageview);
597 GtkWidget *mimeview = GTK_WIDGET_PTR(messageview->mimeview);
599 headerview_destroy(messageview->headerview);
600 textview_destroy(messageview->textview);
601 imageview_destroy(messageview->imageview);
602 mimeview_destroy(messageview->mimeview);
603 noticeview_destroy(messageview->noticeview);
605 toolbar_clear_list(TOOLBAR_MSGVIEW);
606 TOOLBAR_DESTROY_ITEMS(messageview->toolbar->item_list);
607 TOOLBAR_DESTROY_ACTIONS(messageview->toolbar->action_list);
611 gtk_widget_unref(textview);
612 gtk_widget_unref(imageview);
613 gtk_widget_unref(mimeview);
616 void messageview_quote_color_set(void)
620 void messageview_set_font(MessageView *messageview)
622 textview_set_font(messageview->textview, NULL);
625 TextView *messageview_get_current_textview(MessageView *messageview)
627 TextView *text = NULL;
629 if (messageview->type == MVIEW_TEXT)
630 text = messageview->textview;
631 else if (messageview->type == MVIEW_MIME) {
632 if (gtk_notebook_get_current_page
633 (GTK_NOTEBOOK(messageview->mimeview->notebook)) == 0)
634 text = messageview->textview;
635 else if (messageview->mimeview->type == MIMEVIEW_TEXT)
636 text = messageview->mimeview->textview;
642 void messageview_copy_clipboard(MessageView *messageview)
646 text = messageview_get_current_textview(messageview);
648 gtk_editable_copy_clipboard(GTK_EDITABLE(text->text));
651 void messageview_select_all(MessageView *messageview)
655 text = messageview_get_current_textview(messageview);
657 gtk_editable_select_region(GTK_EDITABLE(text->text), 0, -1);
660 void messageview_set_position(MessageView *messageview, gint pos)
662 textview_set_position(messageview->textview, pos);
665 gboolean messageview_search_string(MessageView *messageview, const gchar *str,
668 return textview_search_string(messageview->textview, str, case_sens);
672 gboolean messageview_search_string_backward(MessageView *messageview,
676 return textview_search_string_backward(messageview->textview,
681 gboolean messageview_is_visible(MessageView *messageview)
683 return messageview->visible;
686 static void messageview_destroy_cb(GtkWidget *widget, MessageView *messageview)
688 messageview_destroy(messageview);
691 static void messageview_size_allocate_cb(GtkWidget *widget,
692 GtkAllocation *allocation)
694 g_return_if_fail(allocation != NULL);
696 prefs_common.msgwin_width = allocation->width;
697 prefs_common.msgwin_height = allocation->height;
700 static void key_pressed(GtkWidget *widget, GdkEventKey *event,
701 MessageView *messageview)
703 if (event && event->keyval == GDK_Escape && messageview->window)
704 gtk_widget_destroy(messageview->window);
707 static void focus_in(GtkWidget *widget, GdkEventFocus *event,
710 MessageView *msgview = (MessageView*)data;
712 summary_select_by_msgnum(msgview->mainwin->summaryview,
713 msgview->msginfo->msgnum);
716 void messageview_toggle_view_real(MessageView *messageview)
718 MainWindow *mainwin = messageview->mainwin;
719 union CompositeWin *cwin = &mainwin->win;
720 GtkWidget *vpaned = NULL;
721 GtkWidget *container = NULL;
722 GtkItemFactory *ifactory = gtk_item_factory_from_widget(mainwin->menubar);
724 switch (mainwin->type) {
726 vpaned = cwin->sep_none.vpaned;
727 container = cwin->sep_none.hpaned;
729 case SEPARATE_FOLDER:
730 vpaned = cwin->sep_folder.vpaned;
731 container = mainwin->vbox_body;
733 case SEPARATE_MESSAGE:
738 if (vpaned->parent != NULL) {
739 gtk_widget_ref(vpaned);
740 gtkut_container_remove(GTK_CONTAINER(container), vpaned);
741 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), container);
742 menu_set_sensitive(ifactory, "/View/Expand Summary View", FALSE);
743 gtk_widget_grab_focus(GTK_WIDGET(messageview->textview->text));
745 gtk_widget_reparent(GTK_WIDGET_PTR(messageview), vpaned);
746 gtk_container_add(GTK_CONTAINER(container), vpaned);
747 gtk_widget_unref(vpaned);
748 menu_set_sensitive(ifactory, "/View/Expand Summary View", TRUE);
749 gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
753 static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
755 noticeview_set_text(noticeview, _("This messages asks for a return receipt."));
756 noticeview_set_button_text(noticeview, _("Send receipt"));
757 noticeview_set_button_press_callback(noticeview,
758 GTK_SIGNAL_FUNC(return_receipt_send_clicked),
760 noticeview_show(noticeview);
763 static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
768 file = procmsg_get_message_file_path(msginfo);
770 g_warning(_("can't get message file path.\n"));
774 tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
775 tmpmsginfo->folder = msginfo->folder;
776 tmpmsginfo->msgnum = msginfo->msgnum;
778 if (disposition_notification_send(tmpmsginfo) >= 0) {
779 procmsg_msginfo_unset_flags(msginfo, MSG_RETRCPT_PENDING, 0);
780 noticeview_hide(noticeview);
783 procmsg_msginfo_free(tmpmsginfo);
787 static void select_account_cb(GtkWidget *w, gpointer data)
789 *(gint*)data = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(w)));
792 static PrefsAccount *select_account_from_list(GList *ac_list)
798 g_return_val_if_fail(ac_list != NULL, NULL);
799 g_return_val_if_fail(ac_list->data != NULL, NULL);
801 optmenu = gtk_option_menu_new();
802 menu = gtkut_account_menu_new(ac_list, select_account_cb, &account_id);
805 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
806 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
807 account_id = ((PrefsAccount *) ac_list->data)->account_id;
808 if (alertpanel_with_widget(
809 _("Return Receipt Notification"),
810 _("The message was sent to several of your "
812 "Please choose which account do you want to "
813 "use for sending the receipt notification:"),
814 _("Send Notification"), _("+Cancel"), NULL,
815 optmenu) != G_ALERTDEFAULT)
817 return account_find_from_id(account_id);
820 static void messageview_toolbar_create(MessageView *messageview,
821 GtkWidget *container)
823 ToolbarItem *toolbar_item;
826 GtkWidget *icon_wid = NULL;
828 GtkTooltips *toolbar_tips;
829 ToolbarSylpheedActions *action_item;
831 GSList *toolbar_list;
832 toolbar_tips = gtk_tooltips_new();
834 toolbar_read_config_file(TOOLBAR_MSGVIEW);
835 toolbar_list = toolbar_get_list(TOOLBAR_MSGVIEW);
837 messageview->toolbar = g_new0(Toolbar, 1);
839 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
841 gtk_container_add(GTK_CONTAINER(container), toolbar);
842 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
843 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
844 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
845 GTK_TOOLBAR_SPACE_LINE);
847 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
849 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, SEPARATOR) == 0) {
850 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
854 toolbar_item = g_new0(ToolbarItem, 1);
855 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
856 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
857 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
859 toolbar_item->parent = g_new0(ToolbarParent, 1);
860 toolbar_item->parent->data = (gpointer)messageview;
861 toolbar_item->parent->type = TOOLBAR_MSGVIEW;
863 /* collect toolbar items in list to keep track */
864 messageview->toolbar->item_list =
865 g_slist_append(messageview->toolbar->item_list,
868 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
869 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
873 icon_wid, toolbar_messageview_buttons_cb,
876 switch (toolbar_item->index) {
877 case A_COMPOSE_EMAIL:
878 messageview->toolbar->compose_mail_btn = item;
879 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
880 messageview->toolbar->compose_mail_btn,
881 _("Compose Email"), NULL);
883 case A_REPLY_MESSAGE:
884 messageview->toolbar->reply_btn = item;
885 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
886 messageview->toolbar->reply_btn,
887 _("Reply to Message"), NULL);
890 messageview->toolbar->replysender_btn = item;
891 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
892 messageview->toolbar->replysender_btn,
893 _("Reply to Sender"), NULL);
896 messageview->toolbar->replyall_btn = item;
897 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
898 messageview->toolbar->replyall_btn,
899 _("Reply to All"), NULL);
902 messageview->toolbar->replylist_btn = item;
903 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
904 messageview->toolbar->replylist_btn,
905 _("Reply to Mailing-list"), NULL);
908 messageview->toolbar->fwd_btn = item;
909 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
910 messageview->toolbar->fwd_btn,
911 _("Forward Message"), NULL);
914 messageview->toolbar->delete_btn = item;
915 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
916 messageview->toolbar->delete_btn,
917 _("Delete Message"), NULL);
920 messageview->toolbar->next_btn = item;
921 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
922 messageview->toolbar->next_btn,
923 _("Goto Next Message"), NULL);
926 action_item = g_new0(ToolbarSylpheedActions, 1);
927 action_item->widget = item;
928 action_item->name = g_strdup(toolbar_item->text);
930 messageview->toolbar->action_list =
931 g_slist_append(messageview->toolbar->action_list,
934 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
936 action_item->name, NULL);
938 gtk_widget_show(item);
945 messageview->toolbar->toolbar = toolbar;
947 gtk_widget_show_all(toolbar);
950 static void toolbar_messageview_buttons_cb(GtkWidget *widget,
956 void (*func)(GtkWidget *widget, gpointer data);
957 } messageview_action[] = {
958 { A_COMPOSE_EMAIL, common_toolbar_compose_cb },
959 { A_REPLY_MESSAGE, common_toolbar_reply_cb },
960 { A_REPLY_SENDER, common_toolbar_reply_to_sender_cb },
961 { A_REPLY_ALL, common_toolbar_reply_to_all_cb },
962 { A_REPLY_ML, common_toolbar_reply_to_list_cb },
963 { A_FORWARD, common_toolbar_forward_cb },
964 { A_DELETE, common_toolbar_delete_cb },
965 { A_GOTO_NEXT, common_toolbar_next_unread_cb },
966 { A_SYL_ACTIONS, common_toolbar_actions_execute_cb },
970 gint num_items = sizeof(messageview_action)/sizeof(messageview_action[0]);
972 for (i = 0; i < num_items; i++) {
974 if (messageview_action[i].index == item->index) {
975 messageview_action[i].func(widget, (gpointer)item->parent);
981 void messageview_reply_cb(gpointer data, guint action, GtkWidget *widget)
983 MessageView *messageview = (MessageView *)data;
987 common_toolbar_reply_cb(NULL,messageview);
989 case COMPOSE_REPLY_TO_ALL:
990 common_toolbar_reply_to_all_cb(NULL,messageview);
992 case COMPOSE_REPLY_TO_SENDER:
993 common_toolbar_reply_to_sender_cb(NULL,messageview);
995 case COMPOSE_REPLY_TO_LIST:
996 common_toolbar_reply_to_list_cb(NULL,messageview);
1001 static void messageview_delete_cb(gpointer data, guint action, GtkWidget *widget)
1003 MessageView *messageview = (MessageView *)data;
1005 common_toolbar_delete_cb(NULL,messageview);
1008 static void messageview_close_cb(gpointer data, guint action, GtkWidget *widget)
1010 MessageView *messageview = (MessageView *)data;
1012 gtk_widget_destroy(messageview->window);