[tracker/rss-enclosures] tracker-miner-rss: Fixed compiler errors and use new libtracker-sparql



commit 52c46829dbd10b568bbf237a220f62eaf8e1d2b8
Author: Martyn Russell <martyn lanedo com>
Date:   Tue Jul 20 13:12:48 2010 +0100

    tracker-miner-rss: Fixed compiler errors and use new libtracker-sparql

 src/miners/rss/Makefile.am         |    4 +-
 src/miners/rss/tracker-miner-rss.c |  188 +++++++++++++++++++++--------------
 src/miners/rss/tracker-miner-rss.h |    2 +
 3 files changed, 117 insertions(+), 77 deletions(-)
---
diff --git a/src/miners/rss/Makefile.am b/src/miners/rss/Makefile.am
index 89185c9..2c042b4 100644
--- a/src/miners/rss/Makefile.am
+++ b/src/miners/rss/Makefile.am
@@ -9,7 +9,7 @@ INCLUDES =								\
 	-DTRACKER_COMPILATION						\
 	-I$(top_srcdir)/src						\
 	-I$(top_builddir)/src						\
-	-I$(top_builddir)/src/libtracker-client				\
+	-I$(top_builddir)/src/libtracker-sparql				\
 	$(WARN_CFLAGS)							\
 	$(GMODULE_CFLAGS)						\
 	$(DBUS_CFLAGS)							\
@@ -28,7 +28,7 @@ tracker_miner_rss_SOURCES =						\
 	wrap-feed-enclosure.c
 
 tracker_miner_rss_LDADD =						\
-	$(top_builddir)/src/libtracker-client/libtracker-client- TRACKER_API_VERSION@.la \
+	$(top_builddir)/src/libtracker-sparql/libtracker-sparql- TRACKER_API_VERSION@.la \
 	$(top_builddir)/src/libtracker-miner/libtracker-miner- TRACKER_API_VERSION@.la	\
 	$(top_builddir)/src/libtracker-common/libtracker-common.la	\
 	$(LIBGRSS_LIBS)							\
diff --git a/src/miners/rss/tracker-miner-rss.c b/src/miners/rss/tracker-miner-rss.c
index b106722..8dd2a9c 100644
--- a/src/miners/rss/tracker-miner-rss.c
+++ b/src/miners/rss/tracker-miner-rss.c
@@ -34,14 +34,15 @@
 
 #define TRACKER_MINER_RSS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_MINER_RSS, TrackerMinerRSSPrivate))
 
-#define TRACKER_DBUS_OBJECT_FEED    TRACKER_DBUS_OBJECT "/Resources/Classes/mfo/FeedChannel"
 #define TRACKER_DBUS_INTERFACE_FEED TRACKER_DBUS_INTERFACE_RESOURCES ".Class"
+#define TRACKER_DBUS_OBJECT_FEED    TRACKER_DBUS_OBJECT_RESOURCES "/Classes/mfo/FeedChannel"
 
 typedef struct _TrackerMinerRSSPrivate TrackerMinerRSSPrivate;
 
 struct _TrackerMinerRSSPrivate {
 	gboolean paused;
 	gboolean stopped;
+	gchar *last_status;
 
 	FeedsPool *pool;
 	gint now_fetching;
@@ -71,6 +72,7 @@ tracker_miner_rss_finalize (GObject *object)
 	priv = TRACKER_MINER_RSS_GET_PRIVATE (object);
 
 	priv->stopped = TRUE;
+	g_free (priv->last_status);
 	g_object_unref (priv->pool);
 
 	G_OBJECT_CLASS (tracker_miner_rss_parent_class)->finalize (object);
@@ -142,7 +144,7 @@ tracker_miner_rss_init (TrackerMinerRSS *object)
 	}
 
 	proxy = dbus_g_proxy_new_for_name (connection,
-	                                   TRACKER_DBUS_SERVICE,
+	                                   TRACKER_DBUS_SERVICE, /* org.freedesktop.Tracker1 */
 	                                   TRACKER_DBUS_OBJECT_FEED,
 	                                   TRACKER_DBUS_INTERFACE_FEED);
 
@@ -163,8 +165,6 @@ tracker_miner_rss_init (TrackerMinerRSS *object)
 	g_signal_connect (priv->pool, "feed-ready", G_CALLBACK (feed_fetched), object);
 	priv->now_fetching = 0;
 
-	g_object_set (object, "progress", 0.0, "status", _("Initializing"), NULL);
-
 	g_message ("Listening for feed changes on D-Bus interface...");
 	g_message ("  Path:'%s'", TRACKER_DBUS_OBJECT_FEED);
 
@@ -184,7 +184,7 @@ verify_channel_update (GObject      *source,
 
 	error = NULL;
 
-	tracker_miner_execute_update_finish (TRACKER_MINER (source), result, &error);
+	tracker_sparql_connection_update_finish (TRACKER_SPARQL_CONNECTION (source), result, &error);
 	if (error != NULL) {
 		g_critical ("Could not update channel information, %s", error->message);
 		g_error_free (error);
@@ -222,11 +222,12 @@ update_updated_interval (TrackerMinerRSS *miner,
 	tracker_sparql_builder_object_date (sparql, now);
 	tracker_sparql_builder_insert_close (sparql);
 
-	tracker_miner_execute_update (TRACKER_MINER (miner),
-	                              tracker_sparql_builder_get_result (sparql),
-	                              NULL,
-	                              verify_channel_update,
-	                              NULL);
+        tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (miner)),
+                                                tracker_sparql_builder_get_result (sparql),
+                                                G_PRIORITY_DEFAULT,
+                                                NULL,
+                                                verify_channel_update,
+                                                NULL);
 	g_object_unref (sparql);
 }
 
@@ -400,7 +401,7 @@ verify_item_insertion (GObject      *source,
 	item = user_data;
 
 	error = NULL;
-	tracker_miner_execute_update_finish (TRACKER_MINER (source), result, &error);
+	tracker_sparql_connection_update_finish (TRACKER_SPARQL_CONNECTION (source), result, &error);
 
 	if (error != NULL) {
 		g_critical ("Could not insert feed information, %s", error->message);
@@ -425,32 +426,40 @@ item_verify_reply_cb (GObject      *source_object,
 	const gchar *tmp_string;
 	gdouble latitude;
 	gdouble longitude;
+	TrackerSparqlCursor *cursor;
 	GError *error;
 	TrackerSparqlBuilder *sparql;
 	FeedItem *item;
 	FeedChannel *feed;
 	TrackerMinerRSS *miner;
-	TrackerResultIterator *response;
 
 	miner = TRACKER_MINER_RSS (source_object);
 	item = user_data;
 
 	error = NULL;
-	response = tracker_miner_execute_sparql_finish (TRACKER_MINER (source_object),
-	                                                res,
-	                                                &error);
+	cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (source_object),
+                                                         res,
+                                                         &error);
 
 	if (error != NULL) {
 		g_message ("Could not verify feed existance, %s", error->message);
 		g_object_unref (item);
 		g_error_free (error);
+		if (cursor) {
+			g_object_unref (cursor);
+		}
+		return;
+	}
+
+	if (!tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+		g_message ("No data in query response??");
+		g_object_unref (cursor);
 		return;
 	}
 
-	tracker_result_iterator_next (response);
-	tmp_string = tracker_result_iterator_value (response, 0);
+	tmp_string = tracker_sparql_cursor_get_string (cursor, 0, NULL);
 	if (g_strcmp0 (tmp_string, "1") == 0) {
-		g_object_unref (item);
+		g_object_unref (cursor);
 		return;
 	}
 
@@ -545,12 +554,14 @@ item_verify_reply_cb (GObject      *source_object,
 
 	tracker_sparql_builder_insert_close (sparql);
 
-	tracker_miner_execute_update (TRACKER_MINER (miner),
-	                              tracker_sparql_builder_get_result (sparql),
-	                              NULL,
-	                              verify_item_insertion,
-	                              item);
+	tracker_sparql_connection_update_async (tracker_miner_get_connection (TRACKER_MINER (miner)),
+                                                tracker_sparql_builder_get_result (sparql),
+                                                G_PRIORITY_DEFAULT,
+                                                NULL,
+                                                verify_item_insertion,
+                                                NULL);
 
+	g_object_unref (cursor);
 	g_object_unref (sparql);
 }
 
@@ -583,11 +594,11 @@ check_if_save (TrackerMinerRSS *miner,
 	                         url,
 	                         wrap_feed_channel_get_subject (wfeed));
 
-	tracker_miner_execute_sparql (TRACKER_MINER (miner),
-	                              query,
-	                              NULL,
-	                              item_verify_reply_cb,
-	                              item);
+	tracker_sparql_connection_query_async (tracker_miner_get_connection (TRACKER_MINER (miner)),
+                                               query,
+                                               NULL,
+                                               item_verify_reply_cb,
+                                               item);
 	g_free (query);
 }
 
@@ -598,14 +609,14 @@ mandatory_enclosures_collected (GObject      *source_object,
 {
 	const gchar *url;
 	GError *error;
-	TrackerResultIterator *response;
+	TrackerSparqlCursor *cursor;
 	FeedEnclosure *enclosure;
 	WrapFeedChannel *feed;
 
 	error = NULL;
-	response = tracker_miner_execute_sparql_finish (TRACKER_MINER (source_object),
-	                                                res,
-	                                                &error);
+	cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (source_object),
+	                                                 res,
+	                                                 &error);
 
 	if (error != NULL) {
 		g_message ("Could not verify mandatory enclosures, %s", error->message);
@@ -615,8 +626,8 @@ mandatory_enclosures_collected (GObject      *source_object,
 
 	feed = user_data;
 
-	while (tracker_result_iterator_next (response)) {
-		url = tracker_result_iterator_value (response, 0);
+	while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+		url = tracker_sparql_cursor_get_string (cursor, 0, NULL);
 		if (url == NULL)
 			continue;
 
@@ -637,11 +648,11 @@ check_mandatory_enclosures (TrackerMinerRSS *miner,
 	                         "?e mfo:remoteLink ?r . ?r nie:url ?u }",
 				 wrap_feed_channel_get_subject (feed));
 
-	tracker_miner_execute_sparql (TRACKER_MINER (miner),
-				      query,
-				      NULL,
-				      mandatory_enclosures_collected,
-				      feed);
+	tracker_sparql_connection_query_async (tracker_miner_get_connection (TRACKER_MINER (miner)),
+                                               query,
+                                               NULL,
+                                               mandatory_enclosures_collected,
+                                               feed);
 
 	g_free (query);
 }
@@ -663,6 +674,9 @@ feed_fetched (FeedsPool   *pool,
 	priv = TRACKER_MINER_RSS_GET_PRIVATE (miner);
 
 	priv->now_fetching--;
+
+	g_debug ("Feed fetched, %d remaining", priv->now_fetching);
+
 	if (priv->now_fetching <= 0) {
 		priv->now_fetching = 0;
 		g_object_set (miner, "progress", 1.0, "status", "Idle", NULL);
@@ -689,71 +703,89 @@ feeds_retrieve_cb (GObject      *source_object,
                    GAsyncResult *res,
                    gpointer      user_data)
 {
-	gint interval;
-	int int_value;
+	gint count;
 	const gchar *str;
 	GList *channels;
 	GError *error;
 	TrackerMinerRSSPrivate *priv;
-	TrackerResultIterator *response;
+	TrackerSparqlCursor *cursor;
 	WrapFeedChannel *chan;
 
-	error = NULL;
-	response = tracker_miner_execute_sparql_finish (TRACKER_MINER (source_object),
-	                                                res,
-	                                                &error);
+	cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (source_object),
+	                                                 res,
+	                                                 &error);
 
 	if (error != NULL) {
 		g_message ("Could not retrieve feeds, %s", error->message);
 		g_error_free (error);
+		if (cursor) {
+			g_object_unref (cursor);
+		}
 		return;
 	}
 
 	channels = NULL;
+	count = 0;
+
+	g_message ("Found feeds");
 
-	while (tracker_result_iterator_next (response)) {
-		str = tracker_result_iterator_value (response, 2);
-		chan = wrap_feed_channel_new (TRACKER_MINER_RSS (source_object), (gchar*) str);
-		str = tracker_result_iterator_value (response, 0);
-		feed_channel_set_source (FEED_CHANNEL (chan), (gchar*) str);
+	while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+		gint int_val;
+		const gchar *source;
+		const gchar *interval;
+		const gchar *subject;
+
+		count++;
+
+		subject = tracker_sparql_cursor_get_string (cursor, 2, NULL);
+		chan = wrap_feed_channel_new (TRACKER_MINER_RSS (source_object), (gchar*) subject);
+
+		source = tracker_sparql_cursor_get_string (cursor, 0, NULL);
+		feed_channel_set_source (FEED_CHANNEL (chan), (gchar*) source);
 
 		/* TODO How to manage feeds with an update mfo:updateInterval == 0 ?
 		 * Here the interval is forced to be at least 1 minute, but perhaps those
 		 * elements are to be considered "disabled"
 		 */
-		str = tracker_result_iterator_value (response, 1);
-		interval = strtoull (str, NULL, 10);
-		if (interval <= 0)
-			interval = 1;
-		feed_channel_set_update_interval (FEED_CHANNEL (chan), interval);
+		str = tracker_sparql_cursor_get_string (cursor, 1, NULL);
+		int_val = strtoull (str, NULL, 10);
+		if (int_val <= 0)
+			int_val = 1;
+		feed_channel_set_update_interval (FEED_CHANNEL (chan), int_val);
 
-		str = tracker_result_iterator_value (response, 3);
+		str = tracker_sparql_cursor_get_string (cursor, 3, NULL);
 		if (str != NULL && strcmp (str, "") != 0) {
-			int_value = strtoull (str, NULL, 10);
-			if (int_value > 0)
-				wrap_feed_channel_set_feeds_expiry (chan, int_value);
+			int_val = strtoull (str, NULL, 10);
+			if (int_val > 0)
+				wrap_feed_channel_set_feeds_expiry (chan, int_val);
 		}
 
-		str = tracker_result_iterator_value (response, 4);
+		str = tracker_sparql_cursor_get_string (cursor, 4, NULL);
 		if (str != NULL && strcmp (str, "") != 0)
 			wrap_feed_channel_set_download_enclosures (chan, strcmp (str, "true") == 0);
 
-		str = tracker_result_iterator_value (response, 5);
+		str = tracker_sparql_cursor_get_string (cursor, 5, NULL);
 		if (str != NULL && strcmp (str, "") != 0)
 			wrap_feed_channel_set_enclosures_saving_path (chan, (gchar*) str);
 
-		str = tracker_result_iterator_value (response, 6);
+		str = tracker_sparql_cursor_get_string (cursor, 6, NULL);
 		if (str != NULL && strcmp (str, "") != 0) {
-			int_value = strtoull (str, NULL, 10);
-			if (int_value > 0)
-				wrap_feed_channel_set_enclosures_maxsize (chan, int_value);
+			int_val = strtoull (str, NULL, 10);
+			if (int_val > 0)
+				wrap_feed_channel_set_enclosures_maxsize (chan, int_val);
 		}
 
 		channels = g_list_prepend (channels, chan);
 	}
 
-	priv = TRACKER_MINER_RSS_GET_PRIVATE (source_object);
+	priv = TRACKER_MINER_RSS_GET_PRIVATE (user_data);
 	feeds_pool_listen (priv->pool, channels);
+
+	g_object_unref (cursor);
+
+	if (count == 0) {
+		g_object_set (user_data, "progress", 1.0, "status", "Idle", NULL);
+	}
 }
 
 static void
@@ -773,11 +805,11 @@ retrieve_and_schedule_feeds (TrackerMinerRSS *miner)
 	         "OPTIONAL { ?settings mfo:downloadPath ?path } . "
 	         "OPTIONAL { ?settings mfo:maxSize ?msize } }";
 
-	tracker_miner_execute_sparql (TRACKER_MINER (miner),
-	                              sparql,
-	                              NULL,
-	                              feeds_retrieve_cb,
-	                              NULL);
+	tracker_sparql_connection_query_async (tracker_miner_get_connection (TRACKER_MINER (miner)),
+                                               sparql,
+                                               NULL,
+                                               feeds_retrieve_cb,
+                                               miner);
 }
 
 static const gchar *
@@ -801,8 +833,6 @@ miner_started (TrackerMiner *miner)
 	priv = TRACKER_MINER_RSS_GET_PRIVATE (miner);
 	retrieve_and_schedule_feeds (TRACKER_MINER_RSS (miner));
 	feeds_pool_switch (priv->pool, TRUE);
-
-	g_object_set (miner, "status", "Idle", NULL);
 }
 
 static void
@@ -822,6 +852,12 @@ miner_paused (TrackerMiner *miner)
 
 	priv = TRACKER_MINER_RSS_GET_PRIVATE (miner);
 	feeds_pool_switch (priv->pool, FALSE);
+
+	/* Save last status */
+	g_free (priv->last_status);
+	g_object_get (miner, "status", &priv->last_status, NULL);
+
+	/* Set paused */
 	g_object_set (miner, "status", "Paused", NULL);
 }
 
@@ -832,5 +868,7 @@ miner_resumed (TrackerMiner *miner)
 
 	priv = TRACKER_MINER_RSS_GET_PRIVATE (miner);
 	feeds_pool_switch (priv->pool, TRUE);
-	g_object_set (miner, "status", "Idle", NULL);
+
+	/* Resume */
+	g_object_set (miner, "status", priv->last_status ? priv->last_status : "Idle", NULL);
 }
diff --git a/src/miners/rss/tracker-miner-rss.h b/src/miners/rss/tracker-miner-rss.h
index 3977a4a..e46f23a 100644
--- a/src/miners/rss/tracker-miner-rss.h
+++ b/src/miners/rss/tracker-miner-rss.h
@@ -23,6 +23,8 @@
 
 #include <libtracker-miner/tracker-miner.h>
 
+#include <libtracker-sparql/tracker-sparql.h>
+
 G_BEGIN_DECLS
 
 #define TRACKER_TYPE_MINER_RSS         (tracker_miner_rss_get_type())



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