[evolution-rss] refine opml import
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-rss] refine opml import
- Date: Wed, 21 Apr 2010 20:49:06 +0000 (UTC)
commit 0aa656f8154debd29efb4c7d0dc171a59f745f8a
Author: Lucian Langa <lucilanga gnome org>
Date: Wed Apr 21 23:39:42 2010 +0300
refine opml import
TODO | 2 +
src/misc.c | 3 +-
src/network-soup.c | 4 +-
src/parser.c | 20 ++++++++++
src/rss-config-factory.c | 72 ++++++++---------------------------
src/rss.c | 92 +++++++++++++++++++++++++++++++++++++---------
src/rss.h | 3 +-
7 files changed, 118 insertions(+), 78 deletions(-)
---
diff --git a/TODO b/TODO
index 37e5971..57e790c 100644
--- a/TODO
+++ b/TODO
@@ -37,3 +37,5 @@
* do not mark folders as feeds (icon)
* require gtkhtml-editor separate package (?)
* option to download enclosures (limit to certain size)
+ * split rss feed
+ * possibly completely disable messagefiltering at setup_feed
diff --git a/src/misc.c b/src/misc.c
index 8e075e0..adb662b 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -534,11 +534,10 @@ feed_is_new(gchar *file_name, gchar *needle)
if (fr) {
while (fgets(rfeed, 511, fr) != NULL) {
- if (strstr(rfeed, tmpneedle)) {
+ if (g_strstr_len(rfeed, -1, tmpneedle)) {
occ=1;
break;
}
- memset(rfeed, 0, 512);
}
fclose(fr);
}
diff --git a/src/network-soup.c b/src/network-soup.c
index 73cafa1..f6dce95 100644
--- a/src/network-soup.c
+++ b/src/network-soup.c
@@ -70,7 +70,7 @@ typedef struct {
gchar *url;
} STNET;
-#define DOWNLOAD_QUEUE_SIZE 5
+#define DOWNLOAD_QUEUE_SIZE 15
guint net_qid = 0; // net queue dispatcher
guint net_queue_run_count = 0; //downloads in progress
@@ -749,7 +749,7 @@ net_queue_dispatcher(void)
STNET *_stnet;
guint qlen = g_queue_get_length(rf->stqueue);
- dp("net queue size:%d messages processing:%d\n",
+ d("que len:%d workers:%d\n",
g_queue_get_length(rf->stqueue),
net_queue_run_count);
diff --git a/src/parser.c b/src/parser.c
index 5a46ef6..121ed8c 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -24,6 +24,7 @@
#include <libxml/HTMLparser.h>
#include <libxml/HTMLtree.h>
#include <libxml/debugXML.h>
+#include <mail/mail-ops.h>
#if (DATASERVER_VERSION >= 2031001)
#include <camel/camel.h>
#else
@@ -1063,6 +1064,14 @@ parse_channel_line(xmlNode *top, gchar *feed_name, char *main_date)
}
+void
+refresh_mail_folder(CamelFolder *mail_folder)
+{
+ mail_refresh_folder(mail_folder, NULL, NULL);
+ camel_folder_sync(mail_folder, FALSE, NULL);
+ camel_folder_thaw(mail_folder);
+}
+
gchar *
update_channel(RDF *r)
{
@@ -1079,6 +1088,8 @@ update_channel(RDF *r)
GtkWidget *progress = r->progress;
gchar *buf, *safes, *feed_dir, *feed_name;
gchar *uid, *msg;
+ gboolean freeze = FALSE;
+ CamelFolder *mail_folder;
safes = encode_rfc2047(chn_name);
sender = g_strdup_printf("%s <%s>", safes, chn_name);
@@ -1097,6 +1108,7 @@ update_channel(RDF *r)
for (i=0; NULL != (el = g_array_index(item, xmlNodePtr, i)); i++) {
update_sr_message();
+ update_progress_text(chn_name);
if (rf->cancel) goto out;
if (progress) {
@@ -1127,6 +1139,12 @@ update_channel(RDF *r)
else
CF->full_path = g_strdup(chn_name);
+ if (!freeze) {
+ mail_folder = check_feed_folder(CF->full_path);
+ camel_folder_freeze(mail_folder);
+ freeze = TRUE;
+ }
+
subj = g_strdup(CF->subj);
while (gtk_events_pending())
@@ -1151,6 +1169,8 @@ update_channel(RDF *r)
} else
free_cf(CF);
}
+ refresh_mail_folder(mail_folder);
+ camel_object_unref(mail_folder);
out: g_free(sender);
if (fr) fclose(fr);
diff --git a/src/rss-config-factory.c b/src/rss-config-factory.c
index 59c5166..cdc2cd3 100644
--- a/src/rss-config-factory.c
+++ b/src/rss-config-factory.c
@@ -71,6 +71,8 @@ static guint feed_html = 0;
guint ccurrent = 0, ctotal = 0;
GList *flist = NULL;
gchar *strbuf;
+GtkWidget *import_progress;
+GtkWidget *import_dialog = NULL;
extern rssfeed *rf;
extern guint upgrade;
@@ -849,14 +851,11 @@ store_redraw(GtkTreeView *data)
g_return_val_if_fail(data, FALSE);
#if GTK_VERSION >= 2019007
- g_return_val_if_fail(
- gtk_widget_get_realized(
- GTK_WIDGET(data)),
- FALSE);
+ if (!gtk_widget_get_realized(GTK_WIDGET(data)))
+ return FALSE;
#else
- g_return_val_if_fail(
- GTK_WIDGET_REALIZED(data),
- FALSE);
+ if (!GTK_WIDGET_REALIZED(data))
+ return FALSE;
#endif
if (!store_redrawing) {
@@ -1582,7 +1581,8 @@ import_one_feed(gchar *url, gchar *title, gchar *prefix)
feed->feed_url = g_strdup(url);
feed->feed_name = decode_html_entities(title);
feed->prefix = g_strdup(prefix);
- /* we'll get rid of this as soon as we fetch unblocking */
+ rf->progress_bar = import_progress;
+ rf->progress_dialog = import_dialog;
if (g_hash_table_find(
rf->hr,
check_if_match,
@@ -1639,9 +1639,7 @@ import_opml(gchar *file)
guint type = 0; //file type
gchar *what = NULL;
gchar *msg, *tmp, *maintitle = NULL;
- GtkWidget *import_dialog = NULL;
GtkWidget *import_label;
- GtkWidget *import_progress;
float fr;
xmlNode *src = (xmlNode *)xmlParseFile (file);
@@ -1693,7 +1691,7 @@ import_opml(gchar *file)
0);
gtk_widget_show_all(import_dialog);
g_free(msg);
- if ((src=src->children)) {
+ if ((src = src->children)) {
if (!g_ascii_strcasecmp((char *)src->name, "rdf")) {
while (src) {
src=src->children;
@@ -1725,9 +1723,9 @@ import_opml(gchar *file)
d("total:%d\n", total);
}
}
+ g_object_set_data((GObject *)import_progress, "total", GINT_TO_POINTER(total));
+ g_object_set_data((GObject *)import_progress, "label", import_label);
src = doc;
- //we'll be safer this way
- rf->import = 1;
name = NULL;
while (gtk_events_pending ())
gtk_main_iteration ();
@@ -1827,43 +1825,19 @@ import_opml(gchar *file)
rsstitle = (gchar *)xmlGetProp(
src,
(xmlChar *)"title");
- gtk_label_set_text(
- GTK_LABEL(import_label),
- (gchar *)rsstitle);
-#if GTK_VERSION >= 2006000
- gtk_label_set_ellipsize (
- GTK_LABEL (import_label),
- PANGO_ELLIPSIZE_START);
-#endif
- gtk_label_set_justify(
- GTK_LABEL(import_label),
- GTK_JUSTIFY_CENTER);
- dp("rssprefix:%s rssurl:%s rsstitle:%s\n",
+ dp("rssprefix:%s|rssurl:%s|rsstitle:%s|\n",
rssprefix,
rssurl, rsstitle);
import_one_feed(
rssurl,
rsstitle,
rssprefix);
- dp("import done\n");
+ rf->import++;
+ d("queued.\n");
if (rssurl) xmlFree(rssurl);
if (rsstitle) xmlFree(rsstitle);
-fail: while (gtk_events_pending ())
- gtk_main_iteration ();
- current++;
- fr = ((current*100)/total);
- if (fr < 100)
- gtk_progress_bar_set_fraction(
- (GtkProgressBar *)import_progress,
- fr/100);
- what = g_strdup_printf(
- _("%2.0f%% done"), fr);
- gtk_progress_bar_set_text(
- (GtkProgressBar *)import_progress,
- what);
- g_free(what);
- g_free(rssprefix);
+fail: g_free(rssprefix);
}
xmlFree(prop);
// }
@@ -1895,26 +1869,14 @@ fail: while (gtk_events_pending ())
if (name) xmlFree(name);
if (url) xmlFree(url);
- while (gtk_events_pending ())
- gtk_main_iteration ();
- current++;
- fr = ((current*100)/total);
- gtk_progress_bar_set_fraction(
- (GtkProgressBar *)import_progress, fr/100);
- what = g_strdup_printf(_("%2.0f%% done"), fr);
- gtk_progress_bar_set_text(
- (GtkProgressBar *)import_progress, what);
- g_free(what);
- while (gtk_events_pending ())
- gtk_main_iteration ();
}
}
while (gtk_events_pending ())
gtk_main_iteration ();
-out: rf->import = 0;
+out: //rf->import = 0;
if (maintitle) xmlFree(maintitle);
if (doc) xmlFree(doc);
- gtk_widget_destroy(import_dialog);
+// gtk_widget_destroy(import_dialog);
}
static void
diff --git a/src/rss.c b/src/rss.c
index 5c8d7c9..74751e5 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -439,6 +439,48 @@ statuscb(NetStatusType status, gpointer statusdata, gpointer data)
}
void
+update_progress_text(gchar *title)
+{
+ GtkWidget *label;
+
+ if (!rf->progress_bar)
+ return;
+
+ label = g_object_get_data(rf->progress_bar, "label");
+ if (label) {
+ gtk_label_set_text(
+ GTK_LABEL(label), title);
+ gtk_label_set_ellipsize (
+ GTK_LABEL (label),
+ PANGO_ELLIPSIZE_START);
+ gtk_label_set_justify(
+ GTK_LABEL(label),
+ GTK_JUSTIFY_CENTER);
+ }
+}
+
+void
+update_progress_bar(guint current)
+{
+ gdouble fr;
+ gchar *what;
+ guint total;
+ guint val;
+
+ g_return_if_fail(rf->progress_bar != NULL);
+
+ total = GPOINTER_TO_INT(g_object_get_data(rf->progress_bar, "total"));
+ val = total - current;
+ fr = ((val*100)/total);
+ if (fr < 100)
+ gtk_progress_bar_set_fraction(rf->progress_bar, fr/100);
+ what = g_strdup_printf(_("%2.0f%% done"), fr);
+ gtk_progress_bar_set_text(rf->progress_bar, what);
+ g_free(what);
+}
+
+
+void
browser_write(gchar *string, gint length, gchar *base)
{
gchar *str = string;
@@ -3214,14 +3256,14 @@ prepare_hashes(void)
g_free,
NULL);
if (rf->hrdel_unread == NULL)
- rf->hrdel_unread =
+ rf->hrdel_unread =
g_hash_table_new_full(
g_str_hash,
g_str_equal,
g_free,
NULL);
if (rf->hrdel_notpresent == NULL)
- rf->hrdel_notpresent =
+ rf->hrdel_notpresent =
g_hash_table_new_full(
g_str_hash,
g_str_equal,
@@ -3274,6 +3316,9 @@ finish_setup_feed(
#endif
gpointer crc_feed = gen_md5(feed->feed_url);
+ if (rf->cancel_all)
+ goto out;
+
r = g_new0 (RDF, 1);
r->shown = TRUE;
@@ -3408,7 +3453,10 @@ add:
feed->prefix ? feed->prefix : "",
feed->feed_name,
NULL);
- gchar *b = g_build_path(G_DIR_SEPARATOR_S, r->title, NULL);
+ gchar *b = g_build_path(
+ G_DIR_SEPARATOR_S,
+ r->title,
+ NULL);
update_feed_folder(b, a, 0);
//r->title = feed->feed_name;
r->title = a;
@@ -3421,10 +3469,11 @@ add:
feed->prefix ? feed->prefix : "",
feed->feed_name,
NULL);
- gchar *b = g_build_path(G_DIR_SEPARATOR_S, r->title, NULL);
- g_print("update_feed_folder\n");
+ gchar *b = g_build_path(
+ G_DIR_SEPARATOR_S,
+ r->title,
+ NULL);
update_feed_folder(b, a, 0);
- g_print("update_feed_folder done\n");
g_free(a);
g_free(b);
}
@@ -3432,10 +3481,19 @@ add:
store_redraw(GTK_TREE_VIEW(rf->treeview));
save_gconf_feed();
-
if (feed->validate)
display_feed(r);
+ if (rf->import) {
+ rf->import--;
+ update_progress_bar(rf->import);
+ if (!rf->import) {
+ gtk_widget_destroy(rf->progress_dialog);
+ rf->progress_bar = NULL;
+ rf->progress_dialog = NULL;
+ }
+ }
+
/* folder might not be created yet */
real_name = g_strdup_printf(
"%s" G_DIR_SEPARATOR_S "%s",
@@ -4214,7 +4272,7 @@ lookup_original_folder(gchar *folder, gboolean *found)
tmp = extract_main_folder(folder);
if (tmp) {
ofolder = g_hash_table_lookup(rf->feed_folders, tmp);
- dp("result ofolder:%s\n", ofolder);
+ d("result ofolder:%s\n", ofolder);
if (ofolder) {
g_free(tmp);
if (found) *found = TRUE;
@@ -5701,8 +5759,6 @@ create_mail(create_feed *CF)
mail_folder = check_feed_folder(CF->full_path);
camel_object_ref(mail_folder);
- camel_folder_freeze(mail_folder);
-
info = camel_message_info_new(NULL);
camel_message_info_set_flags(info, CAMEL_MESSAGE_SEEN, 1);
@@ -5870,13 +5926,12 @@ create_mail(create_feed *CF)
filter_uids = g_ptr_array_sized_new(1);
g_ptr_array_add(filter_uids, appended_uid);
mail_filter_on_demand (mail_folder, filter_uids);
-/*FIXME do not how to free this
+/*FIXME do not know how to free this
g_object_weak_ref((GObject *)filter_uids, free_filter_uids, NULL);*/
}
- mail_refresh_folder(mail_folder, NULL, NULL);
- camel_folder_sync(mail_folder, FALSE, NULL);
- camel_folder_thaw(mail_folder);
- camel_operation_end(NULL);
+ //FIXME too lasy to write a separate function
+ if (!rf->import)
+ mail_refresh_folder(mail_folder, NULL, NULL);
camel_object_unref(rtext);
camel_object_unref(new);
camel_message_info_free(info);
@@ -6093,10 +6148,9 @@ finish_attachment (SoupSession *soup_sess,
user_data->CF->feed_fname,
user_data->CF->feed_uri);
free_cf(user_data->CF);
- g_free(user_data->url);
- g_free(user_data);
}
}
+ g_free(user_data);
if (net_queue_run_count) net_queue_run_count--;
if (!net_qid)
@@ -6287,6 +6341,8 @@ display_folder_icon(GtkTreeStore *tree_store, gchar *key)
gint i=0, size;
gint *sizes;
+ g_return_val_if_fail(mod != NULL, FALSE);
+
pixbuf = gdk_pixbuf_new_from_file(img_file, NULL);
if (pixbuf) {
@@ -6452,7 +6508,7 @@ fetch_image_redraw(gchar *url, gchar *link, gpointer data)
tmpurl)) {
goto working;
}
- g_print("fetch_image_redraw() tmpurl:%s\n", tmpurl);
+ d("fetch_image_redraw() tmpurl:%s\n", tmpurl);
stream = rss_cache_get(tmpurl);
if (!stream) {
d("image cache MISS\n");
diff --git a/src/rss.h b/src/rss.h
index 63b7697..1da759b 100644
--- a/src/rss.h
+++ b/src/rss.h
@@ -152,7 +152,7 @@ typedef struct _rssfeed {
#endif
gboolean setup;
gboolean pending;
- gboolean import; //import going on
+ guint import; //import going on
gboolean autoupdate; //feed is currently auto fetched
guint feed_queue;
gboolean cancel; //cancelation signal
@@ -418,6 +418,7 @@ void migrate_crc_md5(const char *name, gchar *url);
void free_cf(create_feed *CF);
gchar *generate_safe_chn_name(gchar *chn_name);
void update_sr_message(void);
+void update_progress_text(gchar *title);
void update_feed_image(RDF *r);
void update_status_icon(const char *channel, gchar *title);
void cancel_comments_session(SoupSession *sess);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]