/** * 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; }
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); }