Ejemplo n.º 1
0
/**
 * grss_feeds_store_switch:
 * @store: a #GrssFeedsStore.
 * @run: %TRUE to run the @store, %FALSE to stop.
 *
 * This is to permit the @store to auto-update itself: it creates an internal
 * #GrssFeedsPool and listens for his signals, so to implement the whole loop
 * fetch-parse-save trasparently.
 */
void
grss_feeds_store_switch (GrssFeedsStore *store, gboolean run)
{
	GList *channels;

	if (store->priv->running == run)
		return;

	if (run == TRUE) {
		if (store->priv->pool == NULL) {
			store->priv->pool = grss_feeds_pool_new ();
			g_signal_connect (store->priv->pool, "feed-ready", G_CALLBACK (feed_fetched), store);
		}

		channels = grss_feeds_store_get_channels (store);
		grss_feeds_pool_listen (store->priv->pool, channels);
		grss_feeds_pool_switch (store->priv->pool, TRUE);
	}
	else {
		if (store->priv->pool != NULL)
			grss_feeds_pool_switch (store->priv->pool, FALSE);
	}

	store->priv->running = run;
}
Ejemplo n.º 2
0
/**
 * grss_feeds_pool_listen:
 * @pool: a #GrssFeedsPool.
 * @feeds: (element-type GrssFeedChannel): a list of #GrssFeedChannel.
 *
 * To set the list of feeds to be managed by the pool. The previous list, if
 * any, is invalidated. After invokation to the function, grss_feeds_pool_switch()
 * must be call to run the auto-fetching (always, also if previous state was
 * "running").
 * The list in @feeds can be freed after calling this; linked #GrssFeedChannel
 * are g_object_ref'd here.
 */
void
grss_feeds_pool_listen (GrssFeedsPool *pool, GList *feeds)
{
	gboolean original_status;

	original_status = pool->priv->running;
	grss_feeds_pool_switch (pool, FALSE);
	remove_currently_listened (pool);
	create_listened (pool, feeds);
	grss_feeds_pool_switch (pool, original_status);
}
Ejemplo n.º 3
0
static void
grss_feeds_pool_finalize (GObject *obj)
{
	GrssFeedsPool *pool;

	pool = GRSS_FEEDS_POOL (obj);
	grss_feeds_pool_switch (pool, FALSE);
	remove_currently_listened (pool);
	g_object_unref (pool->priv->parser);
	g_object_unref (pool->priv->soupsession);
}
Ejemplo n.º 4
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);
}