[evolution-rss] try to refetch missing images on message load
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-rss] try to refetch missing images on message load
- Date: Wed, 16 Mar 2011 15:32:41 +0000 (UTC)
commit 5ff62d4abf8bfd433c4a136246788ee614727712
Author: Lucian Langa <lucilanga gnome org>
Date: Wed Mar 16 16:52:46 2011 +0200
try to refetch missing images on message load
src/rss-image.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
src/rss-image.h | 3 ++-
src/rss.c | 3 ++-
3 files changed, 46 insertions(+), 5 deletions(-)
---
diff --git a/src/rss-image.c b/src/rss-image.c
index 76d9e13..1051048 100644
--- a/src/rss-image.c
+++ b/src/rss-image.c
@@ -43,6 +43,8 @@ gchar *pixfile;
char *pixfilebuf;
gsize pixfilelen;
extern GHashTable *icons;
+GHashTable *missing;
+
void
#if LIBSOUP_VERSION < 2003000
finish_image_feedback (SoupMessage *msg, FEED_IMAGE *user_data);
@@ -51,7 +53,7 @@ finish_image_feedback (SoupSession *soup_sess, SoupMessage *msg, FEED_IMAGE *use
#endif
void
-rss_load_images(void)
+rss_init_images(void)
{
/* load transparency */
pixfile = g_build_filename (EVOLUTION_ICONDIR,
@@ -66,6 +68,12 @@ rss_load_images(void)
}
void
+rss_finish_images(void)
+{
+ g_hash_table_destroy(missing);
+}
+
+void
update_feed_image(RDF *r)
{
GError *err = NULL;
@@ -280,6 +288,21 @@ finish_image_feedback (SoupSession *soup_sess, SoupMessage *msg, FEED_IMAGE *use
CamelStream *stream = NULL;
stream = rss_cache_add(user_data->url);
finish_image(soup_sess, msg, stream);
+ if (!missing)
+ missing = g_hash_table_new_full(
+ g_str_hash, g_str_equal, g_free, NULL);
+
+ if (503 == msg->status_code || //handle this timedly fasion
+ 404 == msg->status_code || //NOT FOUND
+ 400 == msg->status_code || //bad request
+ 2 == msg->status_code || //STATUS_CANT_RESOLVE
+ 1 == msg->status_code || //TIMEOUT (CANCELLED) ?
+ 7 == msg->status_code ||// STATUS_IO_ERROR
+ msg->response_body->length) { //ZERO SIZE
+ g_hash_table_insert(missing,
+ g_strdup(user_data->url), GINT_TO_POINTER(1));
+ }
+
if (user_data->data == current_pobject)
#if EVOLUTION_VERSION >= 23190
em_format_queue_redraw((EMFormat *)user_data->data);
@@ -546,7 +569,7 @@ verify_image(gchar *uri, EMFormatHTML *format)
gchar *result = NULL;
gchar *duri = NULL;
- g_return_val_if_fail(uri != NULL, NULL);
+ if (!uri) return NULL;
if (strstr(uri, "img:"))
duri = decode_image_cache_filename(uri);
@@ -555,7 +578,22 @@ verify_image(gchar *uri, EMFormatHTML *format)
duri = g_strdup(uri);
}
- if (!g_file_test(duri, G_FILE_TEST_EXISTS)) {
+ if (!missing)
+ missing = g_hash_table_new_full(
+ g_str_hash, g_str_equal, g_free, g_free);
+
+ if (g_file_test(duri, G_FILE_TEST_EXISTS)) {
+ struct stat st;
+ g_stat(duri, &st);
+ if (st.st_size == 83) {
+ if (g_hash_table_lookup(missing, g_path_get_basename (duri)))
+ goto out;
+ g_unlink(duri);
+ d("retrying file:%s\n", duri);
+ }
+ }
+
+out: if (!g_file_test(duri, G_FILE_TEST_EXISTS)) {
camel_url_decode((gchar *)uri);
//FIXME lame method of extracting data cache path
//there must be a function in camel for getting data cache path
@@ -674,6 +712,7 @@ fetch_image_redraw(gchar *url, gchar *link, gpointer data)
cache_file = rss_cache_get_filename(intern);
d("fetch_image_redraw() tmpurl:%s, intern: %s\n",
tmpurl, cache_file);
+
if (!g_file_test (cache_file, G_FILE_TEST_EXISTS)) {
d("image cache MISS\n");
if (data) {
diff --git a/src/rss-image.h b/src/rss-image.h
index 204b6d3..b0e04ba 100644
--- a/src/rss-image.h
+++ b/src/rss-image.h
@@ -24,7 +24,8 @@ typedef struct _FEED_IMAGE {
gpointer data;
} FEED_IMAGE;
-void rss_load_images(void);
+void rss_init_images(void);
+void rss_finish_images(void);
gboolean display_folder_icon(GtkTreeStore *store, gchar *key);
gchar *decode_image_cache_filename(gchar *name);
void
diff --git a/src/rss.c b/src/rss.c
index 2888c9e..5283e49 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -4567,7 +4567,7 @@ void org_gnome_cooly_rss_startup(void *ep, ESEventTargetUpgrade *t)
}
custom_feed_timeout();
- rss_load_images();
+ rss_init_images();
}
/* check if rss folders exists and create'em otherwise */
@@ -4798,6 +4798,7 @@ rss_finalize(void)
g_print(".done\n");
if (rf->mozembed)
gtk_widget_destroy(rf->mozembed);
+ rss_finish_images();
/* guint render = GPOINTER_TO_INT(
gconf_client_get_int(rss_gconf,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]