#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>


gchar *ar[] = {"http://rss.slashdot.org/Slashdot/slashdot",
               "http://maemo.org/news/planet-maemo/rss.xml",
               "http://feeds.feedburner.com/FreelanceSwitch?format=xml",
               "http://www.gnome.org/",
               "http://feeds.delicious.com/v2/rss/?count=15",
               "http://planet.gnome.org/rss20.xml", NULL};

static void
downloaded (GObject *source_object, GAsyncResult *res, gpointer userdata)
{
	gchar *uri;
	gchar *contents;
	gsize size;
	GFile *file;
	GError *error;

	file = G_FILE (source_object);
	uri = g_file_get_uri (file);
	contents = NULL;
	error = NULL;

	if (g_file_load_contents_finish (file, res, &contents, &size, NULL, &error) == FALSE) {
		g_warning ("Unable to download %s: %s", uri, error->message);
		g_error_free (error);
	} else {
		g_debug("Downloaded %s", uri);
	}

	g_free (uri);
	g_object_unref (file);

	if (contents != NULL)
		g_free (contents);

}

static gboolean
download()
{
	gchar **i = ar;

	while (*i) {
		GFile *file;
		file = g_file_new_for_uri (*i);
		g_debug("Starting download of : %s", *i);
		g_file_load_contents_async (file, NULL, downloaded, NULL);
		i++;
	}
	return TRUE;
}

int
main ()
{
	g_type_init ();

	g_timeout_add_seconds (3, download, NULL);
	g_main_loop_run (g_main_loop_new (NULL, FALSE));
	exit (0);

}
