[evolution-rss] show feed comments images
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-rss] show feed comments images
- Date: Mon, 17 May 2010 21:20:51 +0000 (UTC)
commit 1de1bc259c35ead88371bf855b5f3c77e917bee6
Author: Lucian Langa <lucilanga gnome org>
Date: Mon May 17 21:10:27 2010 +0300
show feed comments images
src/fetch.c | 1 +
src/parser.c | 52 +++++++++++------
src/parser.h | 3 +
src/rss-cache.c | 6 ++
src/rss-cache.h | 1 +
src/rss-config-factory.c | 2 -
src/rss.c | 138 ++++++++++++++++++----------------------------
src/rss.h | 1 +
8 files changed, 99 insertions(+), 105 deletions(-)
---
diff --git a/src/fetch.c b/src/fetch.c
index d7e451e..cbf05af 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -72,6 +72,7 @@ error:
//fetch feed
//FIXME gio callback hardcoded
+// data - also used as key in key_session when track = 1
gboolean
fetch_unblocking(gchar *url, NetStatusCallback cb, gpointer data,
diff --git a/src/parser.c b/src/parser.c
index 7e474c0..b8f5885 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -25,6 +25,7 @@
#include <libxml/HTMLtree.h>
#include <libxml/debugXML.h>
#include <mail/mail-ops.h>
+#include <mail/em-format-html.h>
#if (DATASERVER_VERSION >= 2031001)
#include <camel/camel.h>
#else
@@ -856,6 +857,38 @@ tree_walk (xmlNodePtr root, RDF *r)
return r->title;
}
+xmlChar *
+process_images(gchar *text, gchar *link, EMFormatHTML *format)
+{
+ xmlChar *buff = NULL;
+ guint size = 0;
+ xmlDoc *src = (xmlDoc *)parse_html_sux (text, strlen(text));
+ if (src) {
+ xmlNode *doc = (xmlNode *)src;
+ while ((doc = html_find(doc, (gchar *)"img"))) {
+ gchar *name = NULL;
+ xmlChar *url = xmlGetProp(doc, (xmlChar *)"src");
+ if (url) {
+ if (name = fetch_image_redraw((gchar *)url, link, format)) {
+ gchar *tmp = g_strconcat(
+ "file://",
+ name, NULL);
+ g_free(name);
+ xmlSetProp(
+ doc, (xmlChar *)"src",
+ (xmlChar *)tmp);
+ g_free(tmp);
+ }
+ xmlFree(url);
+ }
+ }
+ xmlDocDumpMemory(src, &buff, (int*)&size);
+ xmlFree(src);
+ return buff;
+ }
+ return g_strdup(text);
+}
+
create_feed *
parse_channel_line(xmlNode *top, gchar *feed_name, char *main_date, gchar **article_uid)
{
@@ -1021,24 +1054,7 @@ parse_channel_line(xmlNode *top, gchar *feed_name, char *main_date, gchar **arti
g_free(b);
if (feed_name) {
- xmlDoc *src = (xmlDoc *)parse_html_sux (tmp, strlen(tmp));
- if (src) {
- xmlNode *doc = (xmlNode *)src;
-
- while ((doc = html_find(doc, (gchar *)"img"))) {
- gchar *name = NULL;
- xmlChar *url = xmlGetProp(doc, (xmlChar *)"src");
- if (url) {
- if ((name = fetch_image((gchar *)url, link))) {
- xmlSetProp(doc, (xmlChar *)"src", (xmlChar *)name);
- g_free(name);
- }
- xmlFree(url);
- }
- }
- xmlDocDumpMemory(src, &buff, (int*)&size);
- xmlFree(src);
- }
+ buff = process_images(tmp, link, NULL);
g_free(tmp);
b = (gchar *)buff;
} else
diff --git a/src/parser.h b/src/parser.h
index 0d6d947..12e2a46 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -19,6 +19,8 @@
#ifndef __PARSER_H__
#define __PARSER_H__
+#include <mail/em-format-html.h>
+
gchar *update_channel(RDF *r);
xmlDoc *rss_html_url_decode(const char *html, int len);
const char *layer_find (xmlNodePtr node, const char *match, const char *fail);
@@ -55,6 +57,7 @@ gchar *media_rss(xmlNode *node, gchar *search, gchar *fail);
gchar *dublin_core_rss(xmlNode *node, gchar *fail);
void syndication_rss(void);
gchar *wfw_rss(xmlNode *node, gchar *fail);
+xmlChar *process_images(gchar *text, gchar *link, EMFormatHTML *format);
#endif /*__RSS_H__*/
diff --git a/src/rss-cache.c b/src/rss-cache.c
index 5ae4178..90692bf 100644
--- a/src/rss-cache.c
+++ b/src/rss-cache.c
@@ -99,6 +99,12 @@ rss_cache_get(gchar *url)
return camel_data_cache_get(cache, HTTP_CACHE_PATH, url, NULL);
}
+gchar*
+rss_cache_get_filename(gchar *url)
+{
+ return camel_data_cache_get_filename(cache, HTTP_CACHE_PATH, url, NULL);
+}
+
CamelStream*
rss_cache_add(gchar *url)
{
diff --git a/src/rss-cache.h b/src/rss-cache.h
index 288d070..24e6f0c 100644
--- a/src/rss-cache.h
+++ b/src/rss-cache.h
@@ -24,5 +24,6 @@
void rss_cache_init(void);
CamelStream *rss_cache_get(gchar *url);
+gchar *rss_cache_get_filename(gchar *url);
char* rss_cache_get_path(int create, const char *path);
CamelStream* rss_cache_add(gchar *url);
diff --git a/src/rss-config-factory.c b/src/rss-config-factory.c
index dc57ee3..e7cf1a2 100644
--- a/src/rss-config-factory.c
+++ b/src/rss-config-factory.c
@@ -3340,9 +3340,7 @@ rss_folder_factory (EPlugin *epl, EConfigHookItemFactoryData *data)
goto out;
ofolder = lookup_original_folder(folder, &found);
- g_print("ofolder:%s\n", ofolder);
key = lookup_key(ofolder);
- g_print("key:%s\n", key);
if (!key) {
g_free(ofolder);
goto out;
diff --git a/src/rss.c b/src/rss.c
index 405ada9..f1f55c4 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -274,7 +274,7 @@ gint browser_fill = 0; //how much data currently written to browser
gchar *process_feed(RDF *r);
gboolean display_feed(RDF *r);
gchar *display_doc (RDF *r);
-gchar *display_comments (RDF *r);
+gchar *display_comments (RDF *r, EMFormatHTML *format);
void check_folders(void);
CamelMimePart *file_to_message(const char *name);
void check_feed_age(void);
@@ -301,7 +301,7 @@ void fetch_comments(gchar *url, EMFormatHTML *stream);
guint fallback_engine(void);
-gchar *print_comments(gchar *url, gchar *stream);
+gchar *print_comments(gchar *url, gchar *stream, EMFormatHTML *format);
static void refresh_cb (GtkWidget *button, EMFormatHTMLPObject *pobject);
void dup_auth_data(gchar *origurl, gchar *url);
gboolean display_folder_icon(GtkTreeStore *store, gchar *key);
@@ -331,7 +331,6 @@ finish_create_icon_stream (SoupSession *soup_sess,
void webkit_set_history(gchar *base);
gboolean show_webkit(GtkWidget *webkit);
void sync_folders(void);
-gchar *fetch_image_redraw(gchar *url, gchar *link, gpointer data);
gchar *verify_image(gchar *uri, EMFormatHTML *format);
GtkTreeStore *evolution_store = NULL;
@@ -2942,7 +2941,7 @@ render_body: if (category)
frame_colour & 0xffffff,
content_colour & 0xEDECEB & 0xffffff,
text_colour & 0xffffff);
- result = print_comments(comments, commstream);
+ result = print_comments(comments, commstream, (EMFormatHTML *)t->format);
g_free(commstream);
rfrclsid = g_strdup_printf ("org-gnome-rss-controls-%d",
org_gnome_rss_controls_counter_id);
@@ -4199,7 +4198,7 @@ refresh_cb (GtkWidget *button, EMFormatHTMLPObject *pobject)
}
gchar *
-print_comments(gchar *url, gchar *stream)
+print_comments(gchar *url, gchar *stream, EMFormatHTML *format)
{
RDF *r = NULL;
xmlDocPtr doc;
@@ -4220,7 +4219,7 @@ print_comments(gchar *url, gchar *stream)
r->cache = doc;
r->uri = url;
- return display_comments (r);
+ return display_comments (r, format);
}
return NULL;
}
@@ -6679,68 +6678,9 @@ gchar *
fetch_image_redraw(gchar *url, gchar *link, gpointer data)
{
GError *err = NULL;
- CamelStream *stream = NULL;
gchar *tmpurl = NULL;
FEED_IMAGE *fi = NULL;
- gchar *result;
-
- g_return_val_if_fail(url != NULL, NULL);
-
- if (strstr(url, "://") == NULL) {
- if (strstr(url, "http:") == NULL)
- return NULL;
- if (*url == '.') //test case when url begins with ".."
- tmpurl = g_strconcat(g_path_get_dirname(link), "/", url, NULL);
- else {
- if (*url == '/')
- tmpurl = g_strconcat(get_server_from_uri(link), "/", url, NULL);
- else //url is relative (does not begin with / or .)
- tmpurl = g_strconcat(g_path_get_dirname(link), "/", url, NULL);
- }
- } else {
- tmpurl = g_strdup(url);
- }
- if (g_hash_table_find(rf->key_session,
- check_key_match,
- tmpurl)) {
- goto working;
- }
- d("fetch_image_redraw() tmpurl:%s\n", tmpurl);
- stream = rss_cache_get(tmpurl);
- if (!stream) {
- d("image cache MISS\n");
- fi = g_new0(FEED_IMAGE, 1);
- fi->url = g_strdup(tmpurl);
- fi->data = data;
- fetch_unblocking(tmpurl,
- textcb,
- g_strdup(tmpurl),
- (gpointer)finish_image_feedback,
- fi,
- 1,
- &err);
- if (err) {
- result = NULL;
- goto error;
- }
- } else {
- d("image cache HIT\n");
- }
-
-working:result = rss_cache_get_path(FALSE, tmpurl);
-error: g_free(tmpurl);
- return result;
-}
-
-
-// constructs url from @base in case url is relative
-gchar *
-fetch_image(gchar *url, gchar *link)
-{
- GError *err = NULL;
- CamelStream *stream = NULL;
- gchar *tmpurl = NULL;
- gchar *result, *safe;
+ gchar *result, *safe, *cache_file;
g_return_val_if_fail(url != NULL, NULL);
@@ -6753,8 +6693,7 @@ fetch_image(gchar *url, gchar *link)
if (*url == '/')
tmpurl = g_strconcat(
get_server_from_uri(link),
- "/",
- url, NULL);
+ "/", url, NULL);
else //url is relative (does not begin with / or .)
tmpurl = g_strconcat(
g_path_get_dirname(link),
@@ -6763,33 +6702,59 @@ fetch_image(gchar *url, gchar *link)
} else {
tmpurl = g_strdup(url);
}
+
+ if (!tmpurl)
+ return NULL;
+
safe = g_compute_checksum_for_string (
- G_CHECKSUM_SHA1, tmpurl, -1);
- stream = rss_cache_get(safe);
- if (!stream) {
+ G_CHECKSUM_SHA1, tmpurl, -1);
+ if (g_hash_table_find(rf->key_session,
+ check_key_match,
+ tmpurl)) {
+ goto working;
+ }
+ d("fetch_image_redraw() tmpurl:%s, safe url:%s\n", tmpurl, safe);
+ cache_file = rss_cache_get_filename(safe);
+ if (!g_file_test (cache_file, G_FILE_TEST_EXISTS)) {
d("image cache MISS\n");
- stream = rss_cache_add(safe);
- } else
- d("image cache HIT\n");
-
- fetch_unblocking(tmpurl,
+ if (data) {
+ fi = g_new0(FEED_IMAGE, 1);
+ fi->url = g_strdup(safe);
+ fi->data = data;
+ fetch_unblocking(tmpurl,
+ textcb,
+ g_strdup(tmpurl),
+ (gpointer)finish_image_feedback,
+ fi,
+ 1,
+ &err);
+ } else {
+ CamelStream *stream = rss_cache_add(safe);
+ fetch_unblocking(tmpurl,
textcb,
NULL,
(gpointer)finish_image,
stream,
0,
&err);
- if (err) {
- g_free(tmpurl);
- g_free(safe);
- return NULL;
+ }
+ if (err) {
+ result = NULL;
+ g_free(cache_file);
+ goto error;
+ }
+ } else {
+ d("image cache HIT\n");
}
- result = rss_cache_get_path(FALSE, safe);
- g_free(tmpurl);
+ g_free(cache_file);
+
+working:result = rss_cache_get_path(FALSE, safe);
+error: g_free(tmpurl);
g_free(safe);
return result;
}
+
//migrates old feed data files from crc naming
//to md5 naming while preserving content
//
@@ -6885,17 +6850,20 @@ update_comments(RDF *r)
free_cf(CF);
}
commcnt=i;
-scomments=comments->str;
+ scomments=comments->str;
g_string_free(comments, FALSE);
return scomments;
}
gchar *
-display_comments (RDF *r)
+display_comments (RDF *r, EMFormatHTML *format)
{
+ gchar *tmp;
xmlNodePtr root = xmlDocGetRootElement (r->cache);
if (tree_walk (root, r)) {
gchar *comments = update_comments(r);
+ tmp = process_images(comments, r->uri, format);
+ g_free(comments);
if (r->maindate)
g_free(r->maindate);
g_array_free(r->item, TRUE);
@@ -6904,7 +6872,7 @@ display_comments (RDF *r)
g_free(r->type);
if (r)
g_free(r);
- return comments;
+ return tmp;
}
return NULL;
}
diff --git a/src/rss.h b/src/rss.h
index 295ac6b..3b8fc2d 100644
--- a/src/rss.h
+++ b/src/rss.h
@@ -420,6 +420,7 @@ gchar *decode_utf8_entities(gchar *str);
gchar *decode_html_entities(gchar *str);
gchar *get_real_channel_name(gchar *uri, gchar *failed);
gchar *fetch_image(gchar *url, gchar *link);
+gchar *fetch_image_redraw(gchar *url, gchar *link, gpointer data);
void create_mail(create_feed *CF);
void migrate_crc_md5(const char *name, gchar *url);
void free_cf(create_feed *CF);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]