From 2e55f851fb04637dac674bd0d9deb2a071026ba5 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Wed, 3 Apr 2002 22:55:34 +0000 Subject: Set the window title/icon here instead. 2002-04-03 Jeffrey Stedfast * message-tag-followup.c (construct): Set the window title/icon here instead. * message-tag-editor.c (message_tag_editor_init): Don't set the title or window icon here, this is a generic class. * mail-format.c (handle_multipart_signed): Replace get_url_for_icon with the new mail_display_get_url_for_icon function. (handle_multipart_digest): Here too. (get_cid): Use mail_display_add_url instead. (get_location): Same. (handle_text_enriched): Here too. (handle_multipart_signed): And here. * message-tag-followup.c (message_tag_followup_i18n_name): Use the U_() macro, not the _() macro as it is what we really want. * mail-ops.c (mail_send_message): Don't cast the message into a CamelMedium before sending anymore. * mail-callbacks.c (expunge_folder): Set the followup argument to NULL here. (done_message_selected): Get the followup value here and pass it to the mail-display here. (do_mail_fetch_and_print): Again with the NULL followup here. * folder-browser.c (folder_browser_set_message_preview): Update to pass in NULL as the followup since we are setting the message to NULL here. (done_message_selected): Get and set the appropriate followup value here. (do_message_selected): Update to pass in NULL as the followup since we are setting the message to NULL here. * mail-display.c (mail_display_set_message): Now takes a followup tag value. (mail_display_init): Set md->followup to NULL. (mail_display_destroy): Free md->followup. (mail_display_add_url): New: replaces the static add_url function originally in mail-format.c (mail_display_get_url_for_icon): New: replaces get_url_for_icon which was originally in mail-format.c svn path=/trunk/; revision=16334 --- mail/mail-display.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 122 insertions(+), 8 deletions(-) (limited to 'mail/mail-display.c') diff --git a/mail/mail-display.c b/mail/mail-display.c index a98f5418ba..e3dbcfc67d 100644 --- a/mail/mail-display.c +++ b/mail/mail-display.c @@ -46,6 +46,7 @@ #include "e-searching-tokenizer.h" #include "folder-browser-factory.h" #include "mail-stream-gtkhtml.h" +#include "message-tag-followup.h" #include "folder-browser-window.h" #include "folder-browser.h" #include "mail-display.h" @@ -1483,26 +1484,77 @@ clear_data (CamelObject *object, gpointer event_data, gpointer user_data) g_datalist_clear (&data); } + +#define COLOR_IS_LIGHT(r, g, b) ((r + g + b) > (128 * 3)) + void mail_display_render (MailDisplay *md, GtkHTML *html, gboolean reset_scroll) { GtkHTMLStream *stream; - + char bgcolor[7], fontcolor[7]; + GtkStyle *style = NULL; + g_return_if_fail (IS_MAIL_DISPLAY (md)); g_return_if_fail (GTK_IS_HTML (html)); - + stream = gtk_html_begin (html); if (!reset_scroll) { /* This is a hack until there's a clean way to do this. */ GTK_HTML (md->html)->engine->newPage = FALSE; } - + mail_html_write (html, stream, "\n" "\n" "\n\n\n"); mail_html_write (html, stream, "\n"); + if (md->followup) { + /* my favorite thing to do... muck around with colors so we respect people's stupid themes. */ + style = gtk_widget_get_style (GTK_WIDGET (html)); + if (style && !md->printing) { + int state = GTK_WIDGET_STATE (GTK_WIDGET (html)); + gushort r, g, b; + + r = style->base[state].red / 256; + g = style->base[state].green / 256; + b = style->base[state].blue / 256; + + if (COLOR_IS_LIGHT (r, g, b)) { + r *= 0.92; + g *= 0.92; + b *= 0.92; + } else { + r = 255 - (0.92 * (255 - r)); + g = 255 - (0.92 * (255 - g)); + b = 255 - (0.92 * (255 - b)); + } + + sprintf (bgcolor, "%.2X%.2X%.2X", r, g, b); + + r = style->text[state].red / 256; + g = style->text[state].green / 256; + b = style->text[state].blue / 256; + + sprintf (fontcolor, "%.2X%.2X%.2X", r, g, b); + } else { + strcpy (bgcolor, "EEEEEE"); + strcpy (fontcolor, "000000"); + } + + gtk_html_stream_printf (stream, "" + "
" + "" + "
" + "\n", fontcolor, bgcolor); + + gtk_html_stream_printf (stream, "\n", + mail_display_get_url_for_icon (md, EVOLUTION_IMAGES "/flag-for-followup-16.png"), + message_tag_followup_i18n_name (md->followup->type)); + + mail_html_write (html, stream, "
%s
"); + } + if (md->current_message) { if (md->display_style == MAIL_CONFIG_DISPLAY_SOURCE) mail_format_raw_message (md->current_message, md, html, stream); @@ -1539,25 +1591,30 @@ mail_display_redisplay (MailDisplay *md, gboolean reset_scroll) * mail_display_set_message: * @mail_display: the mail display object * @medium: the input camel medium, or %NULL + * @followup: followup value * * Makes the mail_display object show the contents of the medium * param. **/ void -mail_display_set_message (MailDisplay *md, CamelMedium *medium) +mail_display_set_message (MailDisplay *md, CamelMedium *medium, const char *followup) { /* For the moment, we deal only with CamelMimeMessage, but in * the future, we should be able to deal with any medium. */ if (medium && !CAMEL_IS_MIME_MESSAGE (medium)) return; - + /* Clean up from previous message. */ if (md->current_message) camel_object_unref (CAMEL_OBJECT (md->current_message)); - - md->current_message = (CamelMimeMessage*)medium; - + + g_free (md->followup); + + md->current_message = (CamelMimeMessage *) medium; + + md->followup = followup ? message_tag_followup_decode (followup) : NULL; + g_datalist_init (md->data); mail_display_redisplay (md, TRUE); if (medium) { @@ -1613,6 +1670,7 @@ mail_display_init (GtkObject *object) mail_display->idle_id = 0; mail_display->selection = NULL; mail_display->charset = NULL; + mail_display->followup = NULL; mail_display->current_message = NULL; mail_display->data = NULL; @@ -1630,6 +1688,7 @@ mail_display_destroy (GtkObject *object) g_free (mail_display->charset); g_free (mail_display->selection); + g_free (mail_display->followup); g_datalist_clear (mail_display->data); g_free (mail_display->data); @@ -2274,4 +2333,59 @@ mail_display_initialize_gtkhtml (MailDisplay *mail_display, GtkHTML *html) } +char * +mail_display_add_url (MailDisplay *md, const char *kind, char *url, gpointer data) +{ + GHashTable *urls; + gpointer old_key, old_value; + + urls = g_datalist_get_data (md->data, kind); + g_return_val_if_fail (urls != NULL, NULL); + if (g_hash_table_lookup_extended (urls, url, &old_key, &old_value)) { + g_free (url); + url = old_key; + } + + g_hash_table_insert (urls, url, data); + + return url; +} + +const char * +mail_display_get_url_for_icon (MailDisplay *md, const char *icon_name) +{ + char *icon_path, buf[1024], *url; + int fd, nread; + GByteArray *ba; + + /* FIXME: cache */ + + if (*icon_name == '/') + icon_path = g_strdup (icon_name); + else { + icon_path = gnome_pixmap_file (icon_name); + if (!icon_path) + return "file:///dev/null"; + } + + fd = open (icon_path, O_RDONLY); + g_free (icon_path); + if (fd == -1) + return "file:///dev/null"; + + ba = g_byte_array_new (); + while (1) { + nread = read (fd, buf, sizeof (buf)); + if (nread < 1) + break; + g_byte_array_append (ba, buf, nread); + } + close (fd); + + url = g_strdup_printf ("x-evolution-data:%p", ba); + + return mail_display_add_url (md, "data_urls", url, ba); +} + + E_MAKE_TYPE (mail_display, "MailDisplay", MailDisplay, mail_display_class_init, mail_display_init, PARENT_TYPE); -- cgit v1.2.3