diff options
author | nobody <nobody@localhost> | 2002-01-25 03:01:46 +0800 |
---|---|---|
committer | nobody <nobody@localhost> | 2002-01-25 03:01:46 +0800 |
commit | 76bbd700763e4b45614df6ad6174fe831ddb932e (patch) | |
tree | 46b61771dcad0f9692e7f34c7627f05edb733c6b /my-evolution/e-summary.c | |
parent | 7c9e80dd308222afbdec1068a925e4800f13dfb5 (diff) | |
download | gsoc2013-evolution-EVOLUTION_1_0_2.tar gsoc2013-evolution-EVOLUTION_1_0_2.tar.gz gsoc2013-evolution-EVOLUTION_1_0_2.tar.bz2 gsoc2013-evolution-EVOLUTION_1_0_2.tar.lz gsoc2013-evolution-EVOLUTION_1_0_2.tar.xz gsoc2013-evolution-EVOLUTION_1_0_2.tar.zst gsoc2013-evolution-EVOLUTION_1_0_2.zip |
This commit was manufactured by cvs2svn to create tagEVOLUTION_1_0_2
'EVOLUTION_1_0_2'.
svn path=/tags/EVOLUTION_1_0_2/; revision=15455
Diffstat (limited to 'my-evolution/e-summary.c')
-rw-r--r-- | my-evolution/e-summary.c | 156 |
1 files changed, 87 insertions, 69 deletions
diff --git a/my-evolution/e-summary.c b/my-evolution/e-summary.c index 2e70e74821..f03caa338d 100644 --- a/my-evolution/e-summary.c +++ b/my-evolution/e-summary.c @@ -24,12 +24,6 @@ #include <config.h> #endif -#include <stdio.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - #include <glib.h> #include <libgnome/gnome-defs.h> #include <libgnome/gnome-i18n.h> @@ -40,6 +34,8 @@ #include <gtkhtml/htmlengine.h> #include <gtkhtml/htmlselection.h> +#include <libgnomevfs/gnome-vfs.h> + #include <gal/util/e-util.h> #include <gal/widgets/e-gui-utils.h> #include <gal/widgets/e-unicode.h> @@ -81,6 +77,13 @@ struct _ESummaryMailFolderInfo { int unread; }; +typedef struct _DownloadInfo { + GtkHTMLStream *stream; + char *uri; + char *buffer, *ptr; + guint32 bufsize; +} DownloadInfo; + struct _ESummaryPrivate { GNOME_Evolution_Shell shell; GNOME_Evolution_ShellView shell_view_interface; @@ -287,6 +290,74 @@ struct _imgcache { }; static void +close_callback (GnomeVFSAsyncHandle *handle, + GnomeVFSResult result, + gpointer data) +{ + DownloadInfo *info = data; + struct _imgcache *img; + + if (images_cache == NULL) { + images_cache = g_hash_table_new (g_str_hash, g_str_equal); + } + + img = g_new (struct _imgcache, 1); + img->buffer = info->buffer; + img->bufsize = info->bufsize; + + g_hash_table_insert (images_cache, info->uri, img); + g_free (info); +} + +/* The way this behaves is a workaround for ximian bug 10235: loading + * the image into gtkhtml progressively will result in garbage being + * drawn, so we wait until we've read the whole thing and then write + * it all at once. + */ +static void +read_callback (GnomeVFSAsyncHandle *handle, + GnomeVFSResult result, + gpointer buffer, + GnomeVFSFileSize bytes_requested, + GnomeVFSFileSize bytes_read, + gpointer data) +{ + DownloadInfo *info = data; + + if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF) { + gtk_html_stream_close (info->stream, GTK_HTML_STREAM_ERROR); + gnome_vfs_async_close (handle, close_callback, info); + } else if (bytes_read == 0) { + gtk_html_stream_write (info->stream, info->buffer, info->bufsize); + gtk_html_stream_close (info->stream, GTK_HTML_STREAM_OK); + gnome_vfs_async_close (handle, close_callback, info); + } else { + bytes_read += info->ptr - info->buffer; + info->bufsize += 4096; + info->buffer = g_realloc (info->buffer, info->bufsize); + info->ptr = info->buffer + bytes_read; + gnome_vfs_async_read (handle, info->ptr, 4095, read_callback, info); + } +} + +static void +open_callback (GnomeVFSAsyncHandle *handle, + GnomeVFSResult result, + DownloadInfo *info) +{ + if (result != GNOME_VFS_OK) { + gtk_html_stream_close (info->stream, GTK_HTML_STREAM_ERROR); + g_free (info->uri); + g_free (info); + return; + } + + info->bufsize = 4096; + info->buffer = info->ptr = g_new (char, info->bufsize); + gnome_vfs_async_read (handle, info->buffer, 4095, read_callback, info); +} + +static void e_summary_url_clicked (GtkHTML *html, const char *url, ESummary *summary) @@ -316,52 +387,6 @@ e_summary_url_clicked (GtkHTML *html, protocol_listener->listener (summary, url, protocol_listener->closure); } -static char * -e_read_file_with_length (const char *filename, - size_t *length) -{ - int fd, ret; - struct stat stat_buf; - char *buf; - size_t bytes_read, size; - - g_return_val_if_fail (filename != NULL, NULL); - - fd = open (filename, O_RDONLY); - g_return_val_if_fail (fd != -1, NULL); - - fstat (fd, &stat_buf); - size = stat_buf.st_size; - buf = g_new (char, size + 1); - - bytes_read = 0; - while (bytes_read < size) { - ssize_t rc; - - rc = read (fd, buf + bytes_read, size - bytes_read); - if (rc < 0) { - if (errno != EINTR) { - close (fd); - g_free (buf); - - return NULL; - } - } else if (rc == 0) { - break; - } else { - bytes_read += rc; - } - } - - buf[bytes_read] = '\0'; - - if (length) { - *length = bytes_read; - } - - return buf; -} - static void e_summary_url_requested (GtkHTML *html, const char *url, @@ -369,6 +394,8 @@ e_summary_url_requested (GtkHTML *html, ESummary *summary) { char *filename; + GnomeVFSAsyncHandle *handle; + DownloadInfo *info; struct _imgcache *img = NULL; if (strncasecmp (url, "file:", 5) == 0) { @@ -387,28 +414,19 @@ e_summary_url_requested (GtkHTML *html, if (images_cache != NULL) { img = g_hash_table_lookup (images_cache, filename); - } else { - images_cache = g_hash_table_new (g_str_hash, g_str_equal); } if (img == NULL) { - size_t length; - char *contents; + info = g_new (DownloadInfo, 1); + info->stream = stream; + info->uri = filename; - contents = e_read_file_with_length (filename, &length); - if (contents == NULL) { - return; - } - - img = g_new (struct _imgcache, 1); - img->buffer = contents; - img->bufsize = length; - - g_hash_table_insert (images_cache, g_strdup (filename), img); + gnome_vfs_async_open (&handle, filename, GNOME_VFS_OPEN_READ, + (GnomeVFSAsyncOpenCallback) open_callback, info); + } else { + gtk_html_stream_write (stream, img->buffer, img->bufsize); + gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); } - - gtk_html_stream_write (stream, img->buffer, img->bufsize); - gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); } static void |