diff options
Diffstat (limited to 'mail/em-format-html-display.c')
-rw-r--r-- | mail/em-format-html-display.c | 1518 |
1 files changed, 342 insertions, 1176 deletions
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c index f20af59683..6faa6ae803 100644 --- a/mail/em-format-html-display.c +++ b/mail/em-format-html-display.c @@ -40,17 +40,11 @@ #include <gtkhtml/gtkhtml.h> #include <gtkhtml/gtkhtml-embedded.h> -#include <gtkhtml/gtkhtml-search.h> #include <glade/glade.h> #include <glib/gi18n.h> -#include <bonobo/bonobo-control-frame.h> -#include <bonobo/bonobo-stream-memory.h> -#include <bonobo/bonobo-widget.h> -#include <bonobo-activation/bonobo-activation-mime.h> - #include <camel/camel-stream.h> #include <camel/camel-stream-filter.h> #include <camel/camel-stream-mem.h> @@ -79,13 +73,12 @@ #include "mail-config.h" +#include "e-mail-display.h" #include "e-mail-attachment-bar.h" #include "em-format-html-display.h" -#include "e-searching-tokenizer.h" #include "em-icon-stream.h" #include "em-utils.h" #include "em-popup.h" -#include "e-icon-entry.h" #include "widgets/misc/e-attachment-button.h" #include "widgets/misc/e-attachment-view.h" @@ -101,28 +94,53 @@ #define d(x) -struct _EMFormatHTMLDisplayPrivate { - /* For the interactive search dialogue */ - /* TODO: Should this be more subtle, like the mozilla one? */ - GtkHBox *search_dialog; - GtkWidget *search_entry; - GtkWidget *search_entry_box; - GtkWidget *search_matches_label; - GtkWidget *search_case_check; - char *search_text; - int search_wrap; /* are we doing a wrap search */ - gboolean search_active; /* if the search is active */ +#define EM_FORMAT_HTML_DISPLAY_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), EM_TYPE_FORMAT_HTML_DISPLAY, EMFormatHTMLDisplayPrivate)) +struct _EMFormatHTMLDisplayPrivate { GtkWidget *attachment_view; /* weak reference */ }; -static int efhd_html_button_press_event (GtkWidget *widget, GdkEventButton *event, EMFormatHTMLDisplay *efh); -static void efhd_html_link_clicked (GtkHTML *html, const char *url, EMFormatHTMLDisplay *efhd); -static void efhd_html_on_url (GtkHTML *html, const char *url, EMFormatHTMLDisplay *efhd); +struct _smime_pobject { + EMFormatHTMLPObject object; + + int signature; + CamelCipherValidity *valid; + GtkWidget *widget; +}; + +/* TODO: move the dialogue elsehwere */ +/* FIXME: also in em-format-html.c */ +static const struct { + const char *icon, *shortdesc, *description; +} smime_sign_table[5] = { + { "stock_signature-bad", N_("Unsigned"), N_("This message is not signed. There is no guarantee that this message is authentic.") }, + { "stock_signature-ok", N_("Valid signature"), N_("This message is signed and is valid meaning that it is very likely that this message is authentic.") }, + { "stock_signature-bad", N_("Invalid signature"), N_("The signature of this message cannot be verified, it may have been altered in transit.") }, + { "stock_signature", N_("Valid signature, but cannot verify sender"), N_("This message is signed with a valid signature, but the sender of the message cannot be verified.") }, + { "stock_signature-bad", N_("Signature exists, but need public key"), N_("This message is signed with a signature, but there is no corresponding public key.") }, + +}; + +static const struct { + const char *icon, *shortdesc, *description; +} smime_encrypt_table[4] = { + { "stock_lock-broken", N_("Unencrypted"), N_("This message is not encrypted. Its content may be viewed in transit across the Internet.") }, + { "stock_lock-ok", N_("Encrypted, weak"), N_("This message is encrypted, but with a weak encryption algorithm. It would be difficult, but not impossible for an outsider to view the content of this message in a practical amount of time.") }, + { "stock_lock-ok", N_("Encrypted"), N_("This message is encrypted. It would be difficult for an outsider to view the content of this message.") }, + { "stock_lock-ok", N_("Encrypted, strong"), N_("This message is encrypted, with a strong encryption algorithm. It would be very difficult for an outsider to view the content of this message in a practical amount of time.") }, +}; + +static const char *smime_sign_colour[5] = { + "", " bgcolor=\"#88bb88\"", " bgcolor=\"#bb8888\"", " bgcolor=\"#e8d122\"","" +}; static void efhd_attachment_frame(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri); static gboolean efhd_attachment_image(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject); static void efhd_message_add_bar(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info); +static gboolean efhd_attachment_button (EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject); +static gboolean efhd_attachment_optional (EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *object); struct _attach_puri { EMFormatPURI puri; @@ -135,7 +153,6 @@ struct _attach_puri { GtkWidget *forward, *down; /* currently no way to correlate this data to the frame :( */ GtkHTML *frame; - CamelStream *output; unsigned int shown:1; /* Embedded Frame */ @@ -159,794 +176,14 @@ struct _attach_puri { }; -static void efhd_iframe_created(GtkHTML *html, GtkHTML *iframe, EMFormatHTMLDisplay *efh); -/*static void efhd_url_requested(GtkHTML *html, const char *url, GtkHTMLStream *handle, EMFormatHTMLDisplay *efh); - static gboolean efhd_object_requested(GtkHTML *html, GtkHTMLEmbedded *eb, EMFormatHTMLDisplay *efh);*/ - static void efhd_message_prefix(EMFormat *emf, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info); -static const EMFormatHandler *efhd_find_handler(EMFormat *emf, const char *mime_type); -static void efhd_format_clone(EMFormat *, CamelFolder *folder, const char *, CamelMimeMessage *msg, EMFormat *); -static void efhd_format_error(EMFormat *emf, CamelStream *stream, const char *txt); -static void efhd_format_source(EMFormat *, CamelStream *, CamelMimePart *); -static void efhd_format_attachment(EMFormat *, CamelStream *, CamelMimePart *, const char *, const EMFormatHandler *); -static void efhd_format_optional(EMFormat *, CamelStream *, CamelMimePart *, CamelStream *); -static void efhd_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid); -static void efhd_complete(EMFormat *); - -static gboolean efhd_bonobo_object(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject); -static gboolean efhd_use_component(const char *mime_type); static void efhd_builtin_init(EMFormatHTMLDisplayClass *efhc); -enum { - EFHD_LINK_CLICKED, - EFHD_POPUP_EVENT, - EFHD_ON_URL, - EFHD_LAST_SIGNAL, -}; - -static guint efhd_signals[EFHD_LAST_SIGNAL] = { 0 }; - -/* EMFormatHandler's for bonobo objects */ -static GHashTable *efhd_bonobo_handlers; -static EMFormatHTMLClass *efhd_parent; -static EMFormatClass *efhd_format_class; - -static void -efhd_gtkhtml_realise(GtkHTML *html, EMFormatHTMLDisplay *efhd) -{ - GtkStyle *style; - - /* FIXME: does this have to be re-done every time we draw? */ - - /* My favorite thing to do... muck around with colors so we respect people's stupid themes. - However, we only do this if we are rendering to the screen -- we ignore the theme - when we are printing. */ - style = gtk_widget_get_style((GtkWidget *)html); - if (style) { - int state = GTK_WIDGET_STATE(html); - gushort r, g, b; - - r = style->fg[state].red >> 8; - g = style->fg[state].green >> 8; - b = style->fg[state].blue >> 8; - - efhd->formathtml.header_colour = ((r<<16) | (g<< 8) | b) & 0xffffff; - - r = style->bg[state].red >> 8; - g = style->bg[state].green >> 8; - b = style->bg[state].blue >> 8; - - efhd->formathtml.body_colour = ((r<<16) | (g<< 8) | b) & 0xffffff; - - r = style->dark[state].red >> 8; - g = style->dark[state].green >> 8; - b = style->dark[state].blue >> 8; - - efhd->formathtml.frame_colour = ((r<<16) | (g<< 8) | b) & 0xffffff; - - r = style->base[GTK_STATE_NORMAL].red >> 8; - g = style->base[GTK_STATE_NORMAL].green >> 8; - b = style->base[GTK_STATE_NORMAL].blue >> 8; - - efhd->formathtml.content_colour = ((r<<16) | (g<< 8) | b) & 0xffffff; - - r = style->text[state].red >> 8; - g = style->text[state].green >> 8; - b = style->text[state].blue >> 8; - - efhd->formathtml.text_colour = ((r<<16) | (g<< 8) | b) & 0xffffff; -#undef DARKER - } -} - -static void -efhd_gtkhtml_style_set(GtkHTML *html, GtkStyle *old, EMFormatHTMLDisplay *efhd) -{ - efhd_gtkhtml_realise(html, efhd); - em_format_redraw((EMFormat *)efhd); -} - -static void -efhd_init(GObject *o) -{ - EMFormatHTMLDisplay *efhd = (EMFormatHTMLDisplay *)o; -#define efh ((EMFormatHTML *)efhd) - - efhd->priv = g_malloc0(sizeof(*efhd->priv)); - - efhd->search_tok = (ESearchingTokenizer *)e_searching_tokenizer_new(); - gtk_html_set_tokenizer (efh->html, (HTMLTokenizer *)efhd->search_tok); - - g_signal_connect(efh->html, "realize", G_CALLBACK(efhd_gtkhtml_realise), o); - g_signal_connect(efh->html, "style-set", G_CALLBACK(efhd_gtkhtml_style_set), o); - /* we want to convert url's etc */ - efh->text_html_flags |= CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS | CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES; -#undef efh - - efhd->nobar = getenv("EVOLUTION_NO_BAR") != NULL; -} - -static void -efhd_finalise(GObject *o) -{ - EMFormatHTMLDisplay *efhd = (EMFormatHTMLDisplay *)o; - - /* check pending stuff */ - - g_free(efhd->priv->search_text); - g_free(efhd->priv); - - ((GObjectClass *)efhd_parent)->finalize(o); -} - -static gboolean -efhd_bool_accumulator(GSignalInvocationHint *ihint, GValue *out, const GValue *in, void *data) -{ - gboolean val = g_value_get_boolean(in); - - g_value_set_boolean(out, val); - - return !val; -} - -static void -efhd_class_init(GObjectClass *klass) -{ - ((EMFormatClass *)klass)->find_handler = efhd_find_handler; - ((EMFormatClass *)klass)->format_clone = efhd_format_clone; - ((EMFormatClass *)klass)->format_error = efhd_format_error; - ((EMFormatClass *)klass)->format_source = efhd_format_source; - ((EMFormatClass *)klass)->format_attachment = efhd_format_attachment; - ((EMFormatClass *)klass)->format_optional = efhd_format_optional; - ((EMFormatClass *)klass)->format_secure = efhd_format_secure; - ((EMFormatClass *)klass)->complete = efhd_complete; - - klass->finalize = efhd_finalise; - - efhd_signals[EFHD_LINK_CLICKED] = - g_signal_new("link_clicked", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(EMFormatHTMLDisplayClass, link_clicked), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, G_TYPE_POINTER); - - efhd_signals[EFHD_POPUP_EVENT] = - g_signal_new("popup_event", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(EMFormatHTMLDisplayClass, popup_event), - efhd_bool_accumulator, NULL, - e_marshal_BOOLEAN__BOXED_POINTER_POINTER, - G_TYPE_BOOLEAN, 3, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE, - G_TYPE_POINTER, G_TYPE_POINTER); - - efhd_signals[EFHD_ON_URL] = - g_signal_new("on_url", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(EMFormatHTMLDisplayClass, on_url), - NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, - G_TYPE_STRING); - - efhd_builtin_init((EMFormatHTMLDisplayClass *)klass); -} - -GType -em_format_html_display_get_type(void) -{ - static GType type = 0; - - if (type == 0) { - static const GTypeInfo info = { - sizeof(EMFormatHTMLDisplayClass), - NULL, NULL, - (GClassInitFunc)efhd_class_init, - NULL, NULL, - sizeof(EMFormatHTMLDisplay), 0, - (GInstanceInitFunc)efhd_init - }; - efhd_parent = g_type_class_ref(em_format_html_get_type()); - efhd_format_class = g_type_class_ref(em_format_get_type()); - type = g_type_register_static(em_format_html_get_type(), "EMFormatHTMLDisplay", &info, 0); - - efhd_bonobo_handlers = g_hash_table_new(g_str_hash, g_str_equal); - } - - return type; -} - -static gboolean -efhd_scroll_event(GtkWidget *w, GdkEventScroll *event, EMFormatHTMLDisplay *efhd) -{ - if(event->state & GDK_CONTROL_MASK) - { - if(event->direction == GDK_SCROLL_UP) - { - gtk_html_zoom_in (efhd->formathtml.html); - } - else if(event->direction == GDK_SCROLL_DOWN) - { - gtk_html_zoom_out (efhd->formathtml.html); - } - return TRUE; - } - return FALSE; -} - -EMFormatHTMLDisplay *em_format_html_display_new(void) -{ - EMFormatHTMLDisplay *efhd; - - efhd = g_object_new(em_format_html_display_get_type(), 0); - - g_signal_connect(efhd->formathtml.html, "iframe_created", G_CALLBACK(efhd_iframe_created), efhd); - g_signal_connect(efhd->formathtml.html, "link_clicked", G_CALLBACK(efhd_html_link_clicked), efhd); - g_signal_connect(efhd->formathtml.html, "on_url", G_CALLBACK(efhd_html_on_url), efhd); - g_signal_connect(efhd->formathtml.html, "button_press_event", G_CALLBACK(efhd_html_button_press_event), efhd); - g_signal_connect(efhd->formathtml.html,"scroll_event", G_CALLBACK(efhd_scroll_event), efhd); - - return efhd; -} - -void em_format_html_display_goto_anchor(EMFormatHTMLDisplay *efhd, const char *name) -{ - printf("FIXME: go to anchor '%s'\n", name); -} - -void em_format_html_display_set_animate(EMFormatHTMLDisplay *efhd, gboolean state) -{ - efhd->animate = state; - gtk_html_set_animate(((EMFormatHTML *)efhd)->html, state); -} - -void em_format_html_display_set_caret_mode(EMFormatHTMLDisplay *efhd, gboolean state) -{ - efhd->caret_mode = state; - gtk_html_set_caret_mode(((EMFormatHTML *)efhd)->html, state); -} - -void -em_format_html_display_set_search(EMFormatHTMLDisplay *efhd, int type, GSList *strings) -{ - switch(type&3) { - case EM_FORMAT_HTML_DISPLAY_SEARCH_PRIMARY: - e_searching_tokenizer_set_primary_case_sensitivity(efhd->search_tok, (type&EM_FORMAT_HTML_DISPLAY_SEARCH_ICASE) == 0); - e_searching_tokenizer_set_primary_search_string(efhd->search_tok, NULL); - while (strings) { - e_searching_tokenizer_add_primary_search_string(efhd->search_tok, strings->data); - strings = strings->next; - } - break; - case EM_FORMAT_HTML_DISPLAY_SEARCH_SECONDARY: - default: - e_searching_tokenizer_set_secondary_case_sensitivity(efhd->search_tok, (type&EM_FORMAT_HTML_DISPLAY_SEARCH_ICASE) == 0); - e_searching_tokenizer_set_secondary_search_string(efhd->search_tok, NULL); - while (strings) { - e_searching_tokenizer_add_secondary_search_string(efhd->search_tok, strings->data); - strings = strings->next; - } - break; - } - - d(printf("redrawing with search\n")); - em_format_redraw((EMFormat *)efhd); -} - -static void -efhd_update_matches(EMFormatHTMLDisplay *efhd) -{ - struct _EMFormatHTMLDisplayPrivate *p = efhd->priv; - char *str; - /* message-search popup match count string */ - char *fmt = _("Matches: %d"); - - if (p->search_dialog) { - str = alloca(strlen(fmt)+32); - sprintf(str, fmt, e_searching_tokenizer_match_count(efhd->search_tok)); - gtk_label_set_text((GtkLabel *)p->search_matches_label, str); - } - gtk_widget_show((GtkWidget *)p->search_matches_label); - -} - -static void -efhd_update_search(EMFormatHTMLDisplay *efhd) -{ - struct _EMFormatHTMLDisplayPrivate *p = efhd->priv; - GSList *words = NULL; - int flags = 0; - - if (!gtk_toggle_button_get_active((GtkToggleButton *)p->search_case_check)) - flags = EM_FORMAT_HTML_DISPLAY_SEARCH_ICASE | EM_FORMAT_HTML_DISPLAY_SEARCH_PRIMARY; - else - flags = EM_FORMAT_HTML_DISPLAY_SEARCH_PRIMARY; - - if (p->search_text) - words = g_slist_append(words, p->search_text); - - em_format_html_display_set_search(efhd, flags, words); - g_slist_free(words); -} - -static void -efhd_search_response(GtkWidget *w, EMFormatHTMLDisplay *efhd) -{ - struct _EMFormatHTMLDisplayPrivate *p = efhd->priv; - - char *txt = g_strdup(gtk_entry_get_text((GtkEntry *)p->search_entry)); - - g_strstrip(txt); - if (p->search_text && strcmp(p->search_text, txt) == 0 && !p->search_wrap) { - gtk_html_engine_search_set_forward (((EMFormatHTML *)efhd)->html, TRUE); - if (!gtk_html_engine_search_next(((EMFormatHTML *)efhd)->html)) - p->search_wrap = TRUE; - g_free(txt); - } else { - g_free(p->search_text); - p->search_text = txt; - if (!p->search_wrap) - efhd_update_search(efhd); - p->search_wrap = FALSE; - gtk_html_engine_search(((EMFormatHTML *)efhd)->html, txt, - gtk_toggle_button_get_active((GtkToggleButton *)p->search_case_check), - TRUE, FALSE); - } -} - - -static void -efhd_search_response_back (GtkWidget *w, EMFormatHTMLDisplay *efhd) -{ - struct _EMFormatHTMLDisplayPrivate *p = efhd->priv; - - char *txt = g_strdup(gtk_entry_get_text((GtkEntry *)p->search_entry)); - - g_strstrip(txt); - if (p->search_text && strcmp(p->search_text, txt) == 0 && !p->search_wrap) { - gtk_html_engine_search_set_forward (((EMFormatHTML *)efhd)->html, FALSE); - if (!gtk_html_engine_search_next(((EMFormatHTML *)efhd)->html)) - p->search_wrap = TRUE; - g_free(txt); - } else { - g_free(p->search_text); - p->search_text = txt; - if (!p->search_wrap) - efhd_update_search(efhd); - p->search_wrap = FALSE; - gtk_html_engine_search(((EMFormatHTML *)efhd)->html, txt, - gtk_toggle_button_get_active((GtkToggleButton *)p->search_case_check), - FALSE, FALSE); - } -} - - -static void -efhd_search_destroy(GtkWidget *w, EMFormatHTMLDisplay *efhd) -{ - struct _EMFormatHTMLDisplayPrivate *p = efhd->priv; - g_free(p->search_text); - p->search_text = NULL; - gtk_widget_hide((GtkWidget *)p->search_dialog); - em_format_html_display_set_search(efhd, EM_FORMAT_HTML_DISPLAY_SEARCH_PRIMARY, NULL); - p->search_active = FALSE; -} - -static void -efhd_search_case_toggled(GtkWidget *w, EMFormatHTMLDisplay *efhd) -{ - struct _EMFormatHTMLDisplayPrivate *p = efhd->priv; - - g_free(p->search_text); - p->search_text = NULL; - efhd_search_response(w, efhd); -} - -static gboolean -efhd_key_pressed (GtkWidget *w, GdkEventKey *event, EMFormatHTMLDisplay *efhd) -{ - if (event->keyval == GDK_Escape){ - efhd_search_destroy (w, efhd); - return TRUE; - } - return FALSE; -} - -static void -clear_button_clicked_cb (GtkWidget *widget, gpointer dummy, EMFormatHTMLDisplay *efhd) -{ - struct _EMFormatHTMLDisplayPrivate *p = efhd->priv; - - gtk_entry_set_text (GTK_ENTRY (p->search_entry), ""); - - g_signal_emit_by_name (p->search_entry, "activate", efhd); -} - -/* Controlls the visibility of icon_entry's visibility */ -static void -icon_entry_changed_cb (GtkWidget *widget, GtkWidget *clear_button) -{ - const char *text = gtk_entry_get_text (GTK_ENTRY (widget)); - - if (text && *text) - gtk_widget_show (clear_button); - else - gtk_widget_hide (clear_button); -} - -GtkWidget * -em_format_html_get_search_dialog (EMFormatHTMLDisplay *efhd) -{ - struct _EMFormatHTMLDisplayPrivate *p = efhd->priv; - GtkWidget *hbox2, *button3, *button2, *label1; - GtkWidget *icon_entry, *clear_button; - - p->search_entry_box = gtk_hbox_new (FALSE, 0); - - label1 = gtk_label_new_with_mnemonic (_("Fin_d:")); - gtk_widget_show (label1); - gtk_box_pack_start ((GtkBox *)(p->search_entry_box), label1, FALSE, FALSE, 5); - - /* Icon entry */ - icon_entry = e_icon_entry_new (); - p->search_entry = e_icon_entry_get_entry (E_ICON_ENTRY (icon_entry)); - gtk_label_set_mnemonic_widget (GTK_LABEL (label1), p->search_entry); - gtk_widget_show (p->search_entry); - clear_button = e_icon_entry_create_button ("gtk-clear"); - e_icon_entry_pack_widget (E_ICON_ENTRY (icon_entry), clear_button, FALSE); - gtk_widget_show_all (icon_entry); - gtk_widget_hide (clear_button); - - g_signal_connect (G_OBJECT (clear_button), "button-press-event", (GCallback) clear_button_clicked_cb, efhd); - g_signal_connect (G_OBJECT (p->search_entry), "changed", (GCallback) icon_entry_changed_cb, clear_button); - - gtk_box_pack_start ((GtkBox *)(p->search_entry_box), icon_entry, FALSE, FALSE, 0); -// gtk_box_pack_start ((GtkBox *)(p->search_entry_box), icon_entry, TRUE, TRUE, 0); - - hbox2 = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start ((GtkBox *)(hbox2), p->search_entry_box, FALSE, FALSE, 5); -// gtk_box_pack_start ((GtkBox *)(hbox2), p->search_entry_box, TRUE, TRUE, 5); - - button3 = gtk_button_new_with_mnemonic (_("_Previous")); - gtk_button_set_image (GTK_BUTTON (button3), GTK_WIDGET(gtk_image_new_from_stock(GTK_STOCK_GO_BACK, GTK_ICON_SIZE_BUTTON))); - gtk_widget_show (button3); - gtk_box_pack_start (GTK_BOX (hbox2), button3, FALSE, FALSE, 5); - - button2 = gtk_button_new_with_mnemonic (_("_Next")); - gtk_button_set_image (GTK_BUTTON (button2), gtk_image_new_from_stock(GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON)); - gtk_widget_show (button2); - gtk_box_pack_start (GTK_BOX (hbox2), button2, FALSE, FALSE, 5); - - p->search_case_check = gtk_check_button_new_with_mnemonic (_("M_atch case")); - gtk_widget_show (p->search_case_check); - gtk_box_pack_start (GTK_BOX (hbox2), p->search_case_check, FALSE, FALSE, 0); - - p->search_matches_label = gtk_label_new (""); - gtk_widget_show (p->search_matches_label); - gtk_box_pack_start (GTK_BOX (hbox2), p->search_matches_label, TRUE, TRUE, 0); - p->search_dialog = GTK_HBOX (hbox2); - - p->search_wrap = FALSE; - - g_signal_connect (p->search_entry, "activate", G_CALLBACK(efhd_search_response), efhd); - g_signal_connect (p->search_entry, "key-press-event", G_CALLBACK(efhd_key_pressed), efhd); - g_signal_connect (p->search_case_check, "toggled", G_CALLBACK(efhd_search_case_toggled), efhd); - g_signal_connect (button2, "clicked", G_CALLBACK(efhd_search_response), efhd); - g_signal_connect (button3, "clicked", G_CALLBACK(efhd_search_response_back), efhd); - - p->search_active = FALSE; - - efhd_update_matches(efhd); - - return (GtkWidget *)p->search_dialog; - -} - -static void -set_focus_cb (GtkWidget *window, GtkWidget *widget, EMFormatHTMLDisplay *efhd) -{ - struct _EMFormatHTMLDisplayPrivate *p = efhd->priv; - GtkWidget *sbar = GTK_WIDGET (p->search_dialog); - - while (widget != NULL && widget != sbar) { - widget = widget->parent; - } - - if (widget != sbar) - efhd_search_destroy(widget, efhd); -} - -/** - * em_format_html_display_search: - * @efhd: - * - * Run an interactive search dialogue. - **/ -void -em_format_html_display_search(EMFormatHTMLDisplay *efhd) -{ - struct _EMFormatHTMLDisplayPrivate *p = efhd->priv; - - if (p->search_dialog){ - GtkWidget *toplevel; - - gtk_widget_show (GTK_WIDGET (p->search_dialog)); - gtk_widget_grab_focus (p->search_entry); - gtk_widget_show (p->search_entry_box); - - p->search_active = TRUE; - - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (p->search_dialog)); - - g_signal_connect (toplevel, "set-focus", - G_CALLBACK (set_focus_cb), efhd); - } - -} -/** - * em_format_html_display_search_with: - * @efhd: - * - * Run an interactive search dialogue. - **/ -void -em_format_html_display_search_with (EMFormatHTMLDisplay *efhd, char *word) -{ - struct _EMFormatHTMLDisplayPrivate *p = efhd->priv; - - if (p->search_dialog){ - gtk_widget_show (GTK_WIDGET (p->search_dialog)); - p->search_active = TRUE; - - /* Set the query */ - gtk_entry_set_text (GTK_ENTRY (p->search_entry), word); - gtk_widget_hide (p->search_entry_box); - - /* Trigger the search */ - g_signal_emit_by_name (p->search_entry, "activate", efhd); - } -} - -void -em_format_html_display_search_close (EMFormatHTMLDisplay *efhd) -{ - struct _EMFormatHTMLDisplayPrivate *p = efhd->priv; - - if (p->search_dialog && p->search_active) - efhd_search_destroy(GTK_WIDGET (p->search_dialog), efhd); -} - -void -em_format_html_display_cut (EMFormatHTMLDisplay *efhd) -{ - gtk_html_cut (((EMFormatHTML *) efhd)->html); -} - -void -em_format_html_display_copy (EMFormatHTMLDisplay *efhd) -{ - gtk_html_copy (((EMFormatHTML *) efhd)->html); -} - -void -em_format_html_display_paste (EMFormatHTMLDisplay *efhd) -{ - gtk_html_paste (((EMFormatHTML *) efhd)->html, FALSE); -} - -void -em_format_html_display_zoom_in (EMFormatHTMLDisplay *efhd) -{ - gtk_html_zoom_in (((EMFormatHTML *) efhd)->html); -} - -void -em_format_html_display_zoom_out (EMFormatHTMLDisplay *efhd) -{ - gtk_html_zoom_out (((EMFormatHTML *) efhd)->html); -} - -void -em_format_html_display_zoom_reset (EMFormatHTMLDisplay *efhd) -{ - gtk_html_zoom_reset (((EMFormatHTML *) efhd)->html); -} - -/* ********************************************************************** */ - -static void -efhd_iframe_created(GtkHTML *html, GtkHTML *iframe, EMFormatHTMLDisplay *efh) -{ - d(printf("Iframe created %p ... \n", iframe)); - - g_signal_connect(iframe, "button_press_event", G_CALLBACK (efhd_html_button_press_event), efh); - - return; -} - -static void -efhd_get_uri_puri (GtkWidget *html, GdkEventButton *event, EMFormatHTMLDisplay *efhd, char **uri, EMFormatPURI **puri) -{ - char *url, *img_url; - - g_return_if_fail (html != NULL); - g_return_if_fail (GTK_IS_HTML (html)); - g_return_if_fail (efhd != NULL); - - if (event) { - url = gtk_html_get_url_at (GTK_HTML (html), event->x, event->y); - img_url = gtk_html_get_image_src_at (GTK_HTML (html), event->x, event->y); - } else { - url = gtk_html_get_cursor_url (GTK_HTML (html)); - img_url = gtk_html_get_cursor_image_src (GTK_HTML (html)); - } - - if (img_url) { - if (!(strstr (img_url, "://") || g_ascii_strncasecmp (img_url, "cid:", 4) == 0)) { - char *u = g_filename_to_uri (img_url, NULL, NULL); - g_free (img_url); - img_url = u; - } - } - - if (puri) { - if (url) - *puri = em_format_find_puri ((EMFormat *)efhd, url); - - if (!*puri && img_url) - *puri = em_format_find_puri ((EMFormat *)efhd, img_url); - } - - if (uri) { - *uri = NULL; - if (img_url && g_ascii_strncasecmp (img_url, "cid:", 4) != 0) { - if (url) - *uri = g_strdup_printf ("%s\n%s", url, img_url); - else { - *uri = img_url; - img_url = NULL; - } - } else { - *uri = url; - url = NULL; - } - } - - g_free (url); - g_free (img_url); -} - -static int -efhd_html_button_press_event (GtkWidget *widget, GdkEventButton *event, EMFormatHTMLDisplay *efhd) -{ - char *uri = NULL; - EMFormatPURI *puri = NULL; - gboolean res = FALSE; - - if (event->button != 3) - return FALSE; - - d(printf("popup button pressed\n")); - - efhd_get_uri_puri (widget, event, efhd, &uri, &puri); - - if (uri && !strncmp (uri, "##", 2)) { - g_free (uri); - return TRUE; - } - - g_signal_emit((GtkObject *)efhd, efhd_signals[EFHD_POPUP_EVENT], 0, event, uri, puri?puri->part:NULL, &res); - - g_free (uri); - - return res; -} - -gboolean -em_format_html_display_popup_menu (EMFormatHTMLDisplay *efhd) -{ - GtkHTML *html; - char *uri = NULL; - EMFormatPURI *puri = NULL; - gboolean res = FALSE; - - html = efhd->formathtml.html; - - efhd_get_uri_puri (GTK_WIDGET (html), NULL, efhd, &uri, &puri); - - g_signal_emit ((GtkObject *)efhd, efhd_signals[EFHD_POPUP_EVENT], 0, NULL, uri, puri?puri->part:NULL, &res); - - g_free (uri); - - return res; -} - -static void -efhd_html_link_clicked (GtkHTML *html, const char *url, EMFormatHTMLDisplay *efhd) -{ - d(printf("link clicked event '%s'\n", url)); - if (url && !strncmp(url, "##", 2)) { - if (!strcmp (url, "##TO##")) - if (!(((EMFormatHTML *) efhd)->header_wrap_flags & EM_FORMAT_HTML_HEADER_TO)) - ((EMFormatHTML *) efhd)->header_wrap_flags |= EM_FORMAT_HTML_HEADER_TO; - else - ((EMFormatHTML *) efhd)->header_wrap_flags &= ~EM_FORMAT_HTML_HEADER_TO; - else if (!strcmp (url, "##CC##")) - if (!(((EMFormatHTML *) efhd)->header_wrap_flags & EM_FORMAT_HTML_HEADER_CC)) - ((EMFormatHTML *) efhd)->header_wrap_flags |= EM_FORMAT_HTML_HEADER_CC; - else - ((EMFormatHTML *) efhd)->header_wrap_flags &= ~EM_FORMAT_HTML_HEADER_CC; - else if (!strcmp (url, "##BCC##")) { - if (!(((EMFormatHTML *) efhd)->header_wrap_flags & EM_FORMAT_HTML_HEADER_BCC)) - ((EMFormatHTML *) efhd)->header_wrap_flags |= EM_FORMAT_HTML_HEADER_BCC; - else - ((EMFormatHTML *) efhd)->header_wrap_flags &= ~EM_FORMAT_HTML_HEADER_BCC; - } - em_format_redraw((EMFormat *)efhd); - } else - g_signal_emit((GObject *)efhd, efhd_signals[EFHD_LINK_CLICKED], 0, url); -} - -static void -efhd_html_on_url (GtkHTML *html, const char *url, EMFormatHTMLDisplay *efhd) -{ - d(printf("on_url event '%s'\n", url)); - - g_signal_emit((GObject *)efhd, efhd_signals[EFHD_ON_URL], 0, url); -} +static gpointer parent_class; static void -efhd_complete(EMFormat *emf) -{ - EMFormatHTMLDisplay *efhd = (EMFormatHTMLDisplay *)emf; - - if (efhd->priv->search_dialog && efhd->priv->search_active) - efhd_update_matches(efhd); -} - -/* ********************************************************************** */ - -/* TODO: move the dialogue elsehwere */ -/* FIXME: also in em-format-html.c */ -static const struct { - const char *icon, *shortdesc, *description; -} smime_sign_table[5] = { - { "stock_signature-bad", N_("Unsigned"), N_("This message is not signed. There is no guarantee that this message is authentic.") }, - { "stock_signature-ok", N_("Valid signature"), N_("This message is signed and is valid meaning that it is very likely that this message is authentic.") }, - { "stock_signature-bad", N_("Invalid signature"), N_("The signature of this message cannot be verified, it may have been altered in transit.") }, - { "stock_signature", N_("Valid signature, but cannot verify sender"), N_("This message is signed with a valid signature, but the sender of the message cannot be verified.") }, - { "stock_signature-bad", N_("Signature exists, but need public key"), N_("This message is signed with a signature, but there is no corresponding public key.") }, - -}; - -static const struct { - const char *icon, *shortdesc, *description; -} smime_encrypt_table[4] = { - { "stock_lock-broken", N_("Unencrypted"), N_("This message is not encrypted. Its content may be viewed in transit across the Internet.") }, - { "stock_lock-ok", N_("Encrypted, weak"), N_("This message is encrypted, but with a weak encryption algorithm. It would be difficult, but not impossible for an outsider to view the content of this message in a practical amount of time.") }, - { "stock_lock-ok", N_("Encrypted"), N_("This message is encrypted. It would be difficult for an outsider to view the content of this message.") }, - { "stock_lock-ok", N_("Encrypted, strong"), N_("This message is encrypted, with a strong encryption algorithm. It would be very difficult for an outsider to view the content of this message in a practical amount of time.") }, -}; - -static const char *smime_sign_colour[5] = { - "", " bgcolor=\"#88bb88\"", " bgcolor=\"#bb8888\"", " bgcolor=\"#e8d122\"","" -}; - -struct _smime_pobject { - EMFormatHTMLPObject object; - - int signature; - CamelCipherValidity *valid; - GtkWidget *widget; -}; - -static void -efhd_xpkcs7mime_free(EMFormatHTMLPObject *o) +efhd_xpkcs7mime_free (EMFormatHTMLPObject *o) { struct _smime_pobject *po = (struct _smime_pobject *)o; @@ -956,21 +193,18 @@ efhd_xpkcs7mime_free(EMFormatHTMLPObject *o) } static void -efhd_xpkcs7mime_info_response(GtkWidget *w, guint button, struct _smime_pobject *po) +efhd_xpkcs7mime_info_response (GtkWidget *widget, + guint button, + struct _smime_pobject *po) { - gtk_widget_destroy(w); + gtk_widget_destroy (widget); po->widget = NULL; } #ifdef HAVE_NSS static void -efhd_xpkcs7mime_viewcert_foad(GtkWidget *w, guint button, struct _smime_pobject *po) -{ - gtk_widget_destroy(w); -} - -static void -efhd_xpkcs7mime_viewcert_clicked(GtkWidget *button, struct _smime_pobject *po) +efhd_xpkcs7mime_viewcert_clicked (GtkWidget *button, + struct _smime_pobject *po) { CamelCipherCertInfo *info = g_object_get_data((GObject *)button, "e-cert-info"); ECertDB *db = e_cert_db_peek(); @@ -987,7 +221,7 @@ efhd_xpkcs7mime_viewcert_clicked(GtkWidget *button, struct _smime_pobject *po) /* oddly enough certificate_viewer_show doesn't ... */ gtk_widget_show(w); - g_signal_connect(w, "response", G_CALLBACK(efhd_xpkcs7mime_viewcert_foad), po); + g_signal_connect(w, "response", G_CALLBACK(gtk_widget_destroy), NULL); if (w && po->widget) gtk_window_set_transient_for((GtkWindow *)w, (GtkWindow *)po->widget); @@ -1000,7 +234,9 @@ efhd_xpkcs7mime_viewcert_clicked(GtkWidget *button, struct _smime_pobject *po) #endif static void -efhd_xpkcs7mime_add_cert_table(GtkWidget *vbox, CamelDList *certlist, struct _smime_pobject *po) +efhd_xpkcs7mime_add_cert_table (GtkWidget *vbox, + CamelDList *certlist, + struct _smime_pobject *po) { CamelCipherCertInfo *info = (CamelCipherCertInfo *)certlist->head; GtkTable *table = (GtkTable *)gtk_table_new(camel_dlist_length(certlist), 2, FALSE); @@ -1059,7 +295,8 @@ efhd_xpkcs7mime_add_cert_table(GtkWidget *vbox, CamelDList *certlist, struct _sm } static void -efhd_xpkcs7mime_validity_clicked(GtkWidget *button, EMFormatHTMLPObject *pobject) +efhd_xpkcs7mime_validity_clicked (GtkWidget *button, + EMFormatHTMLPObject *pobject) { struct _smime_pobject *po = (struct _smime_pobject *)pobject; GladeXML *xml; @@ -1070,10 +307,9 @@ efhd_xpkcs7mime_validity_clicked(GtkWidget *button, EMFormatHTMLPObject *pobject /* FIXME: window raise? */ return; - gladefile = g_build_filename (EVOLUTION_GLADEDIR, - "mail-dialogs.glade", - NULL); - xml = glade_xml_new(gladefile, "message_security_dialog", NULL); + gladefile = g_build_filename ( + EVOLUTION_GLADEDIR, "mail-dialogs.glade", NULL); + xml = glade_xml_new (gladefile, "message_security_dialog", NULL); g_free (gladefile); po->widget = glade_xml_get_widget(xml, "message_security_dialog"); @@ -1149,9 +385,12 @@ efhd_xpkcs7mime_validity_clicked(GtkWidget *button, EMFormatHTMLPObject *pobject } static gboolean -efhd_xpkcs7mime_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject) +efhd_xpkcs7mime_button (EMFormatHTML *efh, + GtkHTMLEmbedded *eb, + EMFormatHTMLPObject *pobject) { - GtkWidget *icon, *button; + GtkWidget *container; + GtkWidget *widget; struct _smime_pobject *po = (struct _smime_pobject *)pobject; const char *icon_name; @@ -1161,25 +400,171 @@ efhd_xpkcs7mime_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje else icon_name = smime_encrypt_table[po->valid->encrypt.status].icon; - icon = gtk_image_new_from_icon_name ( - icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR); - gtk_widget_show(icon); + container = GTK_WIDGET (eb); - button = gtk_button_new(); - g_signal_connect(button, "clicked", G_CALLBACK(efhd_xpkcs7mime_validity_clicked), pobject); + widget = gtk_button_new (); + g_signal_connect ( + widget, "clicked", + G_CALLBACK (efhd_xpkcs7mime_validity_clicked), pobject); + gtk_container_add (GTK_CONTAINER (container), widget); + gtk_widget_show (widget); - gtk_container_add((GtkContainer *)button, icon); - gtk_widget_show(button); - gtk_container_add((GtkContainer *)eb, button); + container = widget; + + widget = gtk_image_new_from_icon_name ( + icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR); + gtk_container_add (GTK_CONTAINER (container), widget); + gtk_widget_show (widget); return TRUE; } static void -efhd_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid) +efhd_format_clone (EMFormat *emf, + CamelFolder *folder, + const gchar *uid, + CamelMimeMessage *msg, + EMFormat *src) { - /* Note: We call EMFormatClass directly, not EMFormatHTML, our parent */ - efhd_format_class->format_secure(emf, stream, part, valid); + if (emf != src) + EM_FORMAT_HTML (emf)->header_wrap_flags = 0; + + /* Chain up to parent's format_clone() method. */ + EM_FORMAT_CLASS (parent_class)-> + format_clone (emf, folder, uid, msg, src); +} + +static void +efhd_format_attachment (EMFormat *emf, + CamelStream *stream, + CamelMimePart *part, + const gchar *mime_type, + const EMFormatHandler *handle) +{ + char *classid, *text, *html; + struct _attach_puri *info; + + classid = g_strdup_printf ("attachment%s", emf->part_id->str); + info = (struct _attach_puri *) em_format_add_puri ( + emf, sizeof (*info), classid, part, efhd_attachment_frame); + em_format_html_add_pobject ( + EM_FORMAT_HTML (emf), sizeof (EMFormatHTMLPObject), + classid, part, efhd_attachment_button); + info->handle = handle; + info->shown = em_format_is_inline ( + emf, info->puri.part_id, info->puri.part, handle); + info->snoop_mime_type = emf->snoop_mime_type; + info->attachment = e_attachment_new (); + e_attachment_set_mime_part (info->attachment, info->puri.part); + + if (emf->valid) { + info->sign = emf->valid->sign.status; + info->encrypt = emf->valid->encrypt.status; + } + + camel_stream_write_string ( + stream, EM_FORMAT_HTML_VPAD + "<table cellspacing=0 cellpadding=0><tr><td>" + "<table width=10 cellspacing=0 cellpadding=0>" + "<tr><td></td></tr></table></td>"); + + camel_stream_printf ( + stream, "<td><object classid=\"%s\"></object></td>", classid); + + camel_stream_write_string ( + stream, "<td><table width=3 cellspacing=0 cellpadding=0>" + "<tr><td></td></tr></table></td><td><font size=-1>"); + + /* output some info about it */ + /* FIXME: should we look up mime_type from object again? */ + text = em_format_describe_part (part, mime_type); + html = camel_text_to_html ( + text, EM_FORMAT_HTML (emf)->text_html_flags & + CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0); + camel_stream_write_string (stream, html); + g_free (html); + g_free (text); + + camel_stream_write_string ( + stream, "</font></td></tr><tr></table>\n" + EM_FORMAT_HTML_VPAD); + + if (handle && info->shown) + handle->handler (emf, stream, part, handle); + + g_free (classid); +} + +static void +efhd_format_optional (EMFormat *emf, + CamelStream *fstream, + CamelMimePart *part, + CamelStream *mstream) +{ + char *classid, *html; + struct _attach_puri *info; + CamelStream *stream; + + if (CAMEL_IS_STREAM_FILTER (fstream) && ((CamelStreamFilter *) fstream)->source) + stream = ((CamelStreamFilter *) fstream)->source; + else + stream = fstream; + + classid = g_strdup_printf ("optional%s", emf->part_id->str); + info = (struct _attach_puri *) em_format_add_puri ( + emf, sizeof (*info), classid, part, efhd_attachment_frame); + em_format_html_add_pobject ( + EM_FORMAT_HTML (emf), sizeof (EMFormatHTMLPObject), + classid, part, efhd_attachment_optional); + info->handle = em_format_find_handler (emf, "text/plain"); + info->shown = FALSE; + info->snoop_mime_type = "text/plain"; + info->attachment = e_attachment_new (); + e_attachment_set_mime_part (info->attachment, info->puri.part); + info->mstream = (CamelStreamMem *) mstream; + if (emf->valid) { + info->sign = emf->valid->sign.status; + info->encrypt = emf->valid->encrypt.status; + } + + camel_stream_write_string ( + stream, EM_FORMAT_HTML_VPAD + "<table cellspacing=0 cellpadding=0><tr><td>" + "<h3><font size=-1 color=red>"); + + html = camel_text_to_html ( + _("Evolution cannot render this email as it is too " + "large to process. You can view it unformatted or " + "with an external text editor."), + EM_FORMAT_HTML (emf)->text_html_flags & + CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0); + camel_stream_write_string (stream, html); + camel_stream_write_string ( + stream, "</font></h3></td></tr></table>\n"); + camel_stream_write_string ( + stream, "<table cellspacing=0 cellpadding=0><tr>"); + camel_stream_printf ( + stream, "<td><object classid=\"%s\"></object>" + "</td></tr></table>", classid); + + g_free(html); + + camel_stream_write_string ( + stream, EM_FORMAT_HTML_VPAD); + + g_free (classid); +} + +static void +efhd_format_secure (EMFormat *emf, + CamelStream *stream, + CamelMimePart *part, + CamelCipherValidity *valid) +{ + EMFormatClass *format_class; + + format_class = g_type_class_peek (EM_TYPE_FORMAT); + format_class->format_secure (emf, stream, part, valid); if (emf->valid == valid && (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE @@ -1187,24 +572,45 @@ efhd_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, Came char *classid; struct _smime_pobject *pobj; - camel_stream_printf (stream, "<table border=0 width=\"100%%\" cellpadding=3 cellspacing=0%s><tr>", - smime_sign_colour[valid->sign.status]); - - classid = g_strdup_printf("smime:///em-format-html/%s/icon/signed", emf->part_id->str); - pobj = (struct _smime_pobject *)em_format_html_add_pobject((EMFormatHTML *)emf, sizeof(*pobj), classid, part, efhd_xpkcs7mime_button); + camel_stream_printf ( + stream, "<table border=0 width=\"100%%\" " + "cellpadding=3 cellspacing=0%s><tr>", + smime_sign_colour[valid->sign.status]); + + classid = g_strdup_printf ( + "smime:///em-format-html/%s/icon/signed", + emf->part_id->str); + pobj = (struct _smime_pobject *) em_format_html_add_pobject ( + EM_FORMAT_HTML (emf), sizeof (*pobj), + classid, part, efhd_xpkcs7mime_button); pobj->valid = camel_cipher_validity_clone(valid); pobj->object.free = efhd_xpkcs7mime_free; - camel_stream_printf(stream, "<td valign=center><object classid=\"%s\"></object></td><td width=100%% valign=center>", classid); - g_free(classid); + camel_stream_printf ( + stream, "<td valign=center><object classid=\"%s\">" + "</object></td><td width=100%% valign=center>", + classid); + g_free (classid); + if (valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE) { - camel_stream_printf (stream, "%s", _(smime_sign_table[valid->sign.status].shortdesc)); + const gchar *desc; + gint status; + + status = valid->sign.status; + desc = smime_sign_table[status].shortdesc; + camel_stream_printf (stream, "%s", gettext (desc)); } if (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE) { + const gchar *desc; + gint status; + if (valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE) { camel_stream_printf (stream, "<br>"); } - camel_stream_printf (stream, "%s", _(smime_encrypt_table[valid->encrypt.status].shortdesc)); + + status = valid->encrypt.status; + desc = smime_encrypt_table[status].shortdesc; + camel_stream_printf (stream, "%s", gettext (desc)); } camel_stream_printf(stream, "</td></tr></table>"); @@ -1212,6 +618,80 @@ efhd_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, Came } static void +efhd_class_init (EMFormatHTMLDisplayClass *class) +{ + EMFormatClass *format_class; + EMFormatHTMLClass *format_html_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EMFormatHTMLDisplayPrivate)); + + format_class = EM_FORMAT_CLASS (class); + format_class->format_clone = efhd_format_clone; + format_class->format_attachment = efhd_format_attachment; + format_class->format_optional = efhd_format_optional; + format_class->format_secure = efhd_format_secure; + + format_html_class = EM_FORMAT_HTML_CLASS (class); + format_html_class->html_widget_type = E_TYPE_MAIL_DISPLAY; + + efhd_builtin_init (class); +} + +static void +efhd_init (EMFormatHTMLDisplay *efhd) +{ + GtkHTML *html; + + html = EM_FORMAT_HTML (efhd)->html; + + efhd->priv = EM_FORMAT_HTML_DISPLAY_GET_PRIVATE (efhd); + + e_mail_display_set_formatter ( + E_MAIL_DISPLAY (html), EM_FORMAT_HTML (efhd)); + + /* we want to convert url's etc */ + EM_FORMAT_HTML (efhd)->text_html_flags |= + CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS | + CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES; +} + +GType +em_format_html_display_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EMFormatHTMLDisplayClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) efhd_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EMFormatHTMLDisplay), + 0, /* n_preallocs */ + (GInstanceInitFunc) efhd_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + EM_TYPE_FORMAT_HTML, "EMFormatHTMLDisplay", + &type_info, 0); + } + + return type; +} + +EMFormatHTMLDisplay * +em_format_html_display_new (void) +{ + return g_object_new (EM_TYPE_FORMAT_HTML_DISPLAY, NULL); +} + +/* ********************************************************************** */ + +static void efhd_image(EMFormatHTML *efh, CamelStream *stream, CamelMimePart *part, EMFormatHandler *handle) { char *classid; @@ -1262,7 +742,7 @@ static EMFormatHandler type_builtin_table[] = { { "image/pjpeg", (EMFormatFunc)efhd_image }, { "x-evolution/message/prefix", (EMFormatFunc)efhd_message_prefix }, - { "x-evolution/message/post-header", (EMFormatFunc)efhd_message_add_bar } + { "x-evolution/message/post-header", (EMFormatFunc)efhd_message_add_bar }, }; static void @@ -1274,48 +754,6 @@ efhd_builtin_init(EMFormatHTMLDisplayClass *efhc) em_format_class_add_handler((EMFormatClass *)efhc, &type_builtin_table[i]); } -/* ********************************************************************** */ -static void -efhd_bonobo_unknown(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info) -{ - char *classid; - - classid = g_strdup_printf("bonobo-unknown:///em-format-html-display/%s", emf->part_id->str); - em_format_html_add_pobject((EMFormatHTML *)emf, sizeof(EMFormatHTMLPObject), classid, part, efhd_bonobo_object); - camel_stream_printf(stream, "<object classid=\"%s\" type=\"%s\"></object><br>\n", classid, info->mime_type); - g_free(classid); -} - - /* ********************************************************************** */ -static const EMFormatHandler *efhd_find_handler(EMFormat *emf, const char *mime_type) -{ - const EMFormatHandler *handle; - - if ( (handle = ((EMFormatClass *)efhd_parent)->find_handler(emf, mime_type)) == NULL - && efhd_use_component(mime_type) - && (handle = g_hash_table_lookup(efhd_bonobo_handlers, mime_type)) == NULL) { - - EMFormatHandler *h = g_malloc0(sizeof(*h)); - - h->mime_type = g_strdup(mime_type); - h->handler = efhd_bonobo_unknown; - h->flags = EM_FORMAT_HANDLER_INLINE_DISPOSITION; - g_hash_table_insert(efhd_bonobo_handlers, h->mime_type, h); - - handle = h; - } - - return handle; -} - -static void efhd_format_clone(EMFormat *emf, CamelFolder *folder, const char *uid, CamelMimeMessage *msg, EMFormat *src) -{ - if (emf != src) - ((EMFormatHTML *) emf)->header_wrap_flags = 0; - - ((EMFormatClass *)efhd_parent)->format_clone(emf, folder, uid, msg, src); -} - static void efhd_write_image(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri) { @@ -1327,7 +765,8 @@ efhd_write_image(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri) camel_stream_close(stream); } -static void efhd_message_prefix(EMFormat *emf, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info) +static void +efhd_message_prefix(EMFormat *emf, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info) { const char *flag, *comp, *due; time_t date; @@ -1386,17 +825,6 @@ static void efhd_message_prefix(EMFormat *emf, CamelStream *stream, CamelMimePar camel_stream_printf(stream, "</td></tr></table>"); } -/* TODO: if these aren't going to do anything should remove */ -static void efhd_format_error(EMFormat *emf, CamelStream *stream, const char *txt) -{ - ((EMFormatClass *)efhd_parent)->format_error(emf, stream, txt); -} - -static void efhd_format_source(EMFormat *emf, CamelStream *stream, CamelMimePart *part) -{ - ((EMFormatClass *)efhd_parent)->format_source(emf, stream, part); -} - /* ********************************************************************** */ /* Checks on the widget whether it can be processed, based on the state of EMFormatHTML. @@ -1824,187 +1252,35 @@ efhd_attachment_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje return TRUE; } -/* not used currently */ -/* frame source callback */ static void -efhd_attachment_frame(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri) +efhd_attachment_frame (EMFormat *emf, + CamelStream *stream, + EMFormatPURI *puri) { struct _attach_puri *info = (struct _attach_puri *)puri; - if (info->shown) { - d(printf("writing to frame content, handler is '%s'\n", info->handle->mime_type)); - info->handle->handler(emf, stream, info->puri.part, info->handle); - camel_stream_close(stream); - } else { - /* FIXME: this is leaked if the object is closed without showing it - NB: need a virtual puri_free method? */ - info->output = stream; - camel_object_ref(stream); - } -} + if (info->shown) + info->handle->handler ( + emf, stream, info->puri.part, info->handle); -static gboolean -efhd_bonobo_object(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject) -{ - CamelDataWrapper *wrapper; - Bonobo_ServerInfo *component; - GtkWidget *embedded; - Bonobo_PersistStream persist; - CORBA_Environment ev; - CamelStreamMem *cstream; - BonoboStream *bstream; - BonoboControlFrame *control_frame; - Bonobo_PropertyBag prop_bag; - - component = bonobo_activation_get_default_component_for_mime_type (eb->type); - if (component == NULL) - return FALSE; - - embedded = bonobo_widget_new_control(component->iid, NULL); - CORBA_free(component); - if (embedded == NULL) - return FALSE; - - CORBA_exception_init(&ev); - - control_frame = bonobo_widget_get_control_frame((BonoboWidget *)embedded); - prop_bag = bonobo_control_frame_get_control_property_bag(control_frame, NULL); - if (prop_bag != CORBA_OBJECT_NIL) { - /* - * Now we can take care of business. Currently, the only control - * that needs something passed to it through a property bag is - * the iTip control, and it needs only the From email address, - * but perhaps in the future we can generalize this section of code - * to pass a bunch of useful things to all embedded controls. - */ - const CamelInternetAddress *from; - char *from_address; - - from = camel_mime_message_get_from((CamelMimeMessage *)((EMFormat *)efh)->message); - from_address = camel_address_encode((CamelAddress *)from); - bonobo_property_bag_client_set_value_string(prop_bag, "from_address", from_address, &ev); - g_free(from_address); - - Bonobo_Unknown_unref(prop_bag, &ev); - } - - persist = (Bonobo_PersistStream)Bonobo_Unknown_queryInterface(bonobo_widget_get_objref((BonoboWidget *)embedded), - "IDL:Bonobo/PersistStream:1.0", &ev); - if (persist == CORBA_OBJECT_NIL) { - g_object_ref_sink(embedded); - CORBA_exception_free(&ev); - return FALSE; - } - - /* Write the data to a CamelStreamMem... */ - cstream = (CamelStreamMem *)camel_stream_mem_new(); - wrapper = camel_medium_get_content_object((CamelMedium *)pobject->part); - if (FALSE && !g_ascii_strncasecmp (eb->type, "text/", 5)) { - /* do charset conversion, etc */ - d(printf("performing charset conversion for %s component\n", eb->type)); - em_format_format_text((EMFormat *)efh, (CamelStream *)cstream, wrapper); - } else { - camel_data_wrapper_decode_to_stream (wrapper, (CamelStream *) cstream); - } - - /* ...convert the CamelStreamMem to a BonoboStreamMem... */ - bstream = bonobo_stream_mem_create((char *)cstream->buffer->data, cstream->buffer->len, TRUE, FALSE); - camel_object_unref(cstream); - - /* ...and hydrate the PersistStream from the BonoboStream. */ - Bonobo_PersistStream_load(persist, - bonobo_object_corba_objref(BONOBO_OBJECT (bstream)), - eb->type, &ev); - bonobo_object_unref(BONOBO_OBJECT (bstream)); - Bonobo_Unknown_unref(persist, &ev); - CORBA_Object_release(persist, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_object_ref_sink(embedded); - CORBA_exception_free(&ev); - return FALSE; - } - CORBA_exception_free(&ev); - - gtk_widget_show(embedded); - gtk_container_add(GTK_CONTAINER (eb), embedded); - - return TRUE; -} - -static gboolean -efhd_check_server_prop(Bonobo_ServerInfo *component, const char *propname, const char *value) -{ - CORBA_sequence_CORBA_string stringv; - Bonobo_ActivationProperty *prop; - int i; - - prop = bonobo_server_info_prop_find(component, propname); - if (!prop || prop->v._d != Bonobo_ACTIVATION_P_STRINGV) - return FALSE; - - stringv = prop->v._u.value_stringv; - for (i = 0; i < stringv._length; i++) { - if (!g_ascii_strcasecmp(value, stringv._buffer[i])) - return TRUE; - } - - return FALSE; -} - -static gboolean -efhd_use_component(const char *mime_type) -{ - GList *components, *iter; - Bonobo_ServerInfo *component = NULL; - - /* should this cache it? */ - - if (g_ascii_strcasecmp(mime_type, "text/x-vcard") != 0 - && g_ascii_strcasecmp(mime_type, "text/calendar") != 0) { - const char **mime_types; - int i; - - mime_types = mail_config_get_allowable_mime_types(); - for (i = 0; mime_types[i]; i++) { - if (!g_ascii_strcasecmp(mime_types[i], mime_type)) - goto type_ok; - } - return FALSE; - } -type_ok: - components = bonobo_activation_get_all_components_for_mime_type (mime_type); - for (iter = components; iter; iter = iter->next) { - Bonobo_ServerInfo *comp = iter->data; - - comp = iter->data; - if (efhd_check_server_prop(comp, "repo_ids", "IDL:Bonobo/PersistStream:1.0") - && efhd_check_server_prop(comp, "bonobo:supported_mime_types", mime_type)) { - component = comp; - break; - } - } - - /* FIXME: How should I free the Bonobo_ServerInfo's ? */ - g_list_foreach (components, (GFunc)CORBA_free, NULL); - g_list_free (components); - - return component != NULL; + camel_stream_close (stream); } static void efhd_bar_resize (EMFormatHTML *efh, GtkAllocation *event) { - EMFormatHTMLDisplay *efhd = (EMFormatHTMLDisplay *) efh; + EMFormatHTMLDisplayPrivate *priv; GtkWidget *widget; gint width; + priv = EM_FORMAT_HTML_DISPLAY_GET_PRIVATE (efh); + widget = GTK_WIDGET (efh->html); width = widget->allocation.width - 12; if (width > 0) { - widget = efhd->priv->attachment_view; + widget = priv->attachment_view; gtk_widget_set_size_request (widget, width, -1); } } @@ -2014,12 +1290,14 @@ efhd_add_bar (EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject) { - EMFormatHTMLDisplay *efhd = (EMFormatHTMLDisplay *) efh; + EMFormatHTMLDisplayPrivate *priv; GtkWidget *widget; + priv = EM_FORMAT_HTML_DISPLAY_GET_PRIVATE (efh); + widget = e_mail_attachment_bar_new (); gtk_container_add (GTK_CONTAINER (eb), widget); - efhd->priv->attachment_view = widget; + priv->attachment_view = widget; gtk_widget_hide (widget); g_signal_connect_swapped ( @@ -2038,7 +1316,7 @@ efhd_message_add_bar (EMFormat *emf, const char *classid = "attachment-bar"; em_format_html_add_pobject ( - (EMFormatHTML *) emf, + EM_FORMAT_HTML (emf), sizeof (EMFormatHTMLPObject), classid, part, efhd_add_bar); @@ -2047,71 +1325,6 @@ efhd_message_add_bar (EMFormat *emf, } static void -efhd_format_attachment(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const char *mime_type, const EMFormatHandler *handle) -{ - char *classid, *text, *html; - struct _attach_puri *info; - - classid = g_strdup_printf ("attachment%s", emf->part_id->str); - info = (struct _attach_puri *)em_format_add_puri ( - emf, sizeof (*info), classid, part, efhd_attachment_frame); - em_format_html_add_pobject ( - (EMFormatHTML *) emf, sizeof (EMFormatHTMLPObject), - classid, part, efhd_attachment_button); - info->handle = handle; - info->shown = em_format_is_inline ( - emf, info->puri.part_id, info->puri.part, handle); - info->snoop_mime_type = emf->snoop_mime_type; - info->attachment = e_attachment_new (); - e_attachment_set_mime_part (info->attachment, info->puri.part); - - if (emf->valid) { - info->sign = emf->valid->sign.status; - info->encrypt = emf->valid->encrypt.status; - } - - camel_stream_write_string ( - stream, EM_FORMAT_HTML_VPAD - "<table cellspacing=0 cellpadding=0><tr><td>" - "<table width=10 cellspacing=0 cellpadding=0>" - "<tr><td></td></tr></table></td>"); - - camel_stream_printf ( - stream, "<td><object classid=\"%s\"></object></td>", classid); - - camel_stream_write_string ( - stream, "<td><table width=3 cellspacing=0 cellpadding=0>" - "<tr><td></td></tr></table></td><td><font size=-1>"); - - /* output some info about it */ - /* FIXME: should we look up mime_type from object again? */ - text = em_format_describe_part (part, mime_type); - html = camel_text_to_html ( - text, ((EMFormatHTML *)emf)->text_html_flags & - CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0); - camel_stream_write_string (stream, html); - g_free (html); - g_free (text); - - camel_stream_write_string ( - stream, "</font></td></tr><tr></table>\n" - EM_FORMAT_HTML_VPAD); - - if (handle) { - if (info->shown) - handle->handler(emf, stream, part, handle); - } else if (efhd_use_component(mime_type)) { - g_free(classid); /* messy */ - - classid = g_strdup_printf("bonobo-unknown:///em-format-html-display/%s", emf->part_id->str); - em_format_html_add_pobject((EMFormatHTML *)emf, sizeof(EMFormatHTMLPObject), classid, part, efhd_bonobo_object); - camel_stream_printf(stream, "<object classid=\"%s\" type=\"%s\"></object><br>>\n", classid, mime_type); - } - - g_free(classid); -} - -static void efhd_optional_button_show (GtkWidget *widget, GtkWidget *w) { GtkWidget *label = g_object_get_data (G_OBJECT (widget), "text-label"); @@ -2224,50 +1437,3 @@ efhd_attachment_optional(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPOb return TRUE; } -static void -efhd_format_optional(EMFormat *emf, CamelStream *fstream, CamelMimePart *part, CamelStream *mstream) -{ - char *classid, *html; - struct _attach_puri *info; - CamelStream *stream; - - if (CAMEL_IS_STREAM_FILTER (fstream) && ((CamelStreamFilter *) fstream)->source) - stream = ((CamelStreamFilter *) fstream)->source; - else - stream = fstream; - - classid = g_strdup_printf("optional%s", emf->part_id->str); - info = (struct _attach_puri *)em_format_add_puri(emf, sizeof(*info), classid, part, efhd_attachment_frame); - em_format_html_add_pobject((EMFormatHTML *)emf, sizeof(EMFormatHTMLPObject), classid, part, efhd_attachment_optional); - info->handle = em_format_find_handler(emf, "text/plain"); - info->shown = FALSE; - info->snoop_mime_type = "text/plain"; - info->attachment = e_attachment_new (); - e_attachment_set_mime_part (info->attachment, info->puri.part); - info->mstream = (CamelStreamMem *)mstream; - if (emf->valid) { - info->sign = emf->valid->sign.status; - info->encrypt = emf->valid->encrypt.status; - } - - camel_stream_write_string(stream, - EM_FORMAT_HTML_VPAD - "<table cellspacing=0 cellpadding=0><tr><td><h3><font size=-1 color=red>"); - - html = camel_text_to_html(_("Evolution cannot render this email as it is too large to process. You can view it unformatted or with an external text editor."), ((EMFormatHTML *)emf)->text_html_flags & CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0); - camel_stream_write_string(stream, html); - camel_stream_write_string(stream, - "</font></h3></td></tr></table>\n"); - camel_stream_write_string(stream, - "<table cellspacing=0 cellpadding=0>" - "<tr>"); - camel_stream_printf(stream, "<td><object classid=\"%s\"></object></td></tr></table>", classid); - - g_free(html); - - camel_stream_write_string(stream, -/* "</font></h2></td></tr></table>\n" */ - EM_FORMAT_HTML_VPAD); - - g_free(classid); -} |