[libgrss] Added feed_channel_new_from_file() function



commit 6614921cf7468a760ab85ded393d962301a61454
Author: Roberto Guido <bob4mail gmail com>
Date:   Tue May 25 14:14:16 2010 +0200

    Added feed_channel_new_from_file() function

 TODO               |    1 +
 src/feed-channel.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/feed-channel.h |    1 +
 src/feeds-pool.c   |    7 ++++---
 4 files changed, 53 insertions(+), 3 deletions(-)
---
diff --git a/TODO b/TODO
index 1de148e..45ddd16 100644
--- a/TODO
+++ b/TODO
@@ -7,5 +7,6 @@
 - namespace OpenSearch (http://a9.com/-/spec/opensearchrss/1.0/)
 
 - add implementation of PubSubHubBub publisher
+- add a FeedsPool mode in which filter already parsed and exposed items for each cycle
 - use libedataserver/EAccount to describe people found in feeds
 - use libchamplain/ChamplainPoint to describe GeoRSS coordinates
diff --git a/src/feed-channel.c b/src/feed-channel.c
index 3ad8dbc..3598c4d 100644
--- a/src/feed-channel.c
+++ b/src/feed-channel.c
@@ -121,6 +121,53 @@ feed_channel_new ()
 }
 
 /**
+ * feed_channel_new_from_file:
+ * @path: path of the file to parse
+ *
+ * Allocates a new #FeedChannel and init it with contents found in specified
+ * file
+ *
+ * Return value: a #FeedChannel, or NULL if the file in @path is not a valid
+ * document
+ */
+FeedChannel*
+feed_channel_new_from_file (const gchar *path)
+{
+	GList *items;
+	GList *iter;
+	xmlDocPtr doc;
+	FeedParser *parser;
+	FeedChannel *ret;
+
+	/*
+		TODO	This function is quite inefficent because parses all
+			the feed with a FeedParser and then trash obtained
+			FeedItems. Perhaps a more aimed function in
+			FeedParser would help...
+	*/
+
+	ret = NULL;
+	doc = file_to_xml (path);
+
+	if (doc != NULL) {
+		ret = g_object_new (FEED_CHANNEL_TYPE, NULL);
+		parser = feed_parser_new ();
+		items = feed_parser_parse (parser, ret, doc, NULL);
+
+		if (items != NULL) {
+			for (iter = items; iter; iter = g_list_next (iter))
+				g_object_unref (iter->data);
+			g_list_free (items);
+		}
+
+		g_object_unref (parser);
+		xmlFreeDoc (doc);
+	}
+
+	return ret;
+}
+
+/**
  * feed_channel_set_source:
  * @channel: a #FeedChannel
  * @source: URL of the feed
diff --git a/src/feed-channel.h b/src/feed-channel.h
index a7bd36f..6f15462 100644
--- a/src/feed-channel.h
+++ b/src/feed-channel.h
@@ -45,6 +45,7 @@ typedef struct {
 GType		feed_channel_get_type			(void) G_GNUC_CONST;
 
 FeedChannel*	feed_channel_new			();
+FeedChannel*	feed_channel_new_from_file		(const gchar *path);
 
 void		feed_channel_set_source			(FeedChannel *channel, gchar *source);
 const gchar*	feed_channel_get_source			(FeedChannel *channel);
diff --git a/src/feeds-pool.c b/src/feeds-pool.c
index 154fddb..931f509 100644
--- a/src/feeds-pool.c
+++ b/src/feeds-pool.c
@@ -131,9 +131,10 @@ feeds_pool_class_init (FeedsPoolClass *klass)
 	 * @items: list of #FeedItem obtained parsing the feed
 	 *
 	 * Emitted when a #FeedChannel assigned to the @pool has been fetched
-	 * and parsed. If @items may be NULL, if an error occourred while
-	 * fetching and/or parsing. List of @items is freed, and his elements
-	 * are unref'd, when signal ends
+	 * and parsed. All parsed items are exposed in the array, with no
+	 * regards about previously existing elements. @items may be NULL, if
+	 * an error occourred while fetching and/or parsing. List of @items
+	 * is freed, and his elements are unref'd, when signal ends
 	 */
 	signals [FEED_READY] = g_signal_new ("feed-ready", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0,
 	                                     NULL, NULL, feed_marshal_VOID__OBJECT_POINTER,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]