Exemplo n.º 1
0
static GList*
feeds_xbel_group_handler_parse (GrssFeedsGroupHandler *self, xmlDocPtr doc, GError **error)
{
	int i;
	gchar *str;
	xmlNodePtr cur;
	xmlNodePtr subnode;
	GList *items;
	xmlXPathObjectPtr xpathObj;
	xmlXPathContextPtr xpathCtx;
	GrssFeedChannel *channel;

	items = NULL;

	xpathCtx = xmlXPathNewContext (doc);

	/*
		TODO	This XPath query may be improved to check only "bookmark" tags into the main "xbel"
	*/
	xpathObj = xmlXPathEvalExpression (BAD_CAST"//bookmark", xpathCtx);

	for (i = 0; i < xpathObj->nodesetval->nodeNr; ++i) {
		cur = xpathObj->nodesetval->nodeTab [i];

		if (cur->type == XML_ELEMENT_NODE) {
			str = (gchar*) xmlGetProp (cur, BAD_CAST"href");

			if (str != NULL && strlen (str) != 0) {
				channel = grss_feed_channel_new ();

				grss_feed_channel_set_source (channel, str);
				xmlFree (str);

				if (cur->children != NULL && strcmp ((gchar*) cur->children->name, "title") == 0) {
					subnode = cur->children;
					str = (gchar*) xmlNodeListGetString (doc, subnode->xmlChildrenNode, TRUE);
					if (str != NULL) {
						grss_feed_channel_set_title (channel, str);
						g_free (str);
					}
				}

				items = g_list_prepend (items, channel);
			}
		}
	}

	xmlXPathFreeObject (xpathObj);
	xmlXPathFreeContext (xpathCtx);

	if (items != NULL)
		items = g_list_reverse (items);
	return items;
}
Exemplo n.º 2
0
int main ()
{
	GError *error;
	GList *iter;
	GList *list;
	GrssFeedChannel *feed;
	GrssFeedItem *item;
	GrssFeedsPublisher *publisher;

	g_type_init ();

	list = NULL;

	feed = grss_feed_channel_new ();
	grss_feed_channel_set_title (feed, "Test Feed");
	grss_feed_channel_set_homepage (feed, "http://example.com");
	grss_feed_channel_set_description (feed, "A test feed");
	grss_feed_channel_set_publish_time (feed, time (NULL));

	item = grss_feed_item_new (feed);
	grss_feed_item_set_title (item, "A big news!");
	grss_feed_item_set_description (item, "Something incredible happening!");
	grss_feed_item_set_source (item, "http://slashdot.org");
	list = g_list_prepend (list, item);

	item = grss_feed_item_new (feed);
	grss_feed_item_set_title (item, "libgrss released");
	grss_feed_item_set_description (item, "A new version of the best Glib-based RSS management library has been released");
	grss_feed_item_set_source (item, "http://live.gnome.org/Libgrss");
	list = g_list_prepend (list, item);

	item = grss_feed_item_new (feed);
	grss_feed_item_set_title (item, "A new commit in libgrss");
	grss_feed_item_set_description (item, "Some commit happens on libgrss git repository");
	grss_feed_item_set_source (item, "http://git.gnome.org/browse/libgrss");
	list = g_list_prepend (list, item);

	error = NULL;
	publisher = grss_feeds_publisher_new ();
	if (grss_feeds_publisher_publish_file (publisher, feed, list, "file:///tmp/test.xml", &error) == FALSE) {
		printf ("Unable to write file: %s\n", error->message);
		g_error_free (error);
	}

	for (iter = list; iter; iter = g_list_next (iter))
		g_object_unref (iter->data);

	g_list_free (list);
	g_object_unref (feed);
	exit (0);
}
Exemplo n.º 3
0
int main ()
{
	register int i;
	gchar *example_feeds [] = {
		"http://rss.slashdot.org/Slashdot/slashdot",
		"http://planet.gnome.org/atom.xml",
		"http://news.gnome.org/atom.xml",
		"http://lwn.net/headlines/rss",
		NULL
	};
	GList *iter;
	GList *list;
	GrssFeedChannel *feed;
	GrssFeedsPool *pool;

	list = NULL;

	for (i = 0; example_feeds [i] != NULL; i++) {
		feed = grss_feed_channel_new ();
		grss_feed_channel_set_source (feed, example_feeds [i]);
		grss_feed_channel_set_update_interval (feed, i + 1);
		list = g_list_prepend (list, feed);
	}

	list = g_list_reverse (list);

	pool = grss_feeds_pool_new ();
	grss_feeds_pool_listen (pool, list);
	grss_feeds_pool_switch (pool, TRUE);

	g_signal_connect (pool, "feed-ready", G_CALLBACK (feed_fetched), NULL);

	g_main_run (g_main_loop_new (NULL, FALSE));

	for (iter = list; iter; iter = g_list_next (iter))
		g_object_unref (iter->data);

	g_object_unref (pool);
	exit (0);
}