[tracker/rss-enclosures] tracker-miner-rss: using tracker_miner_ignore_next_update() when saving enclosures



commit 66a5c3ce0f0dce11a5ce2af2dca2859e93fe45ae
Author: Roberto Guido <bob4mail gmail com>
Date:   Sun Jun 27 00:44:19 2010 +0200

    tracker-miner-rss: using tracker_miner_ignore_next_update() when saving enclosures
                       aligned to Steroids API

 src/miners/rss/tracker-miner-rss.c   |   97 +++++++++++++++++----------------
 src/miners/rss/wrap-feed-enclosure.c |   26 ++-------
 2 files changed, 55 insertions(+), 68 deletions(-)
---
diff --git a/src/miners/rss/tracker-miner-rss.c b/src/miners/rss/tracker-miner-rss.c
index f5daf57..b106722 100644
--- a/src/miners/rss/tracker-miner-rss.c
+++ b/src/miners/rss/tracker-miner-rss.c
@@ -282,9 +282,8 @@ manage_enclosure (TrackerMinerRSS *miner,
 	int size;
 	const gchar *path;
 
-	if (wrap_feed_channel_get_download_enclosures (feed) == FALSE) {
+	if (wrap_feed_channel_get_download_enclosures (feed) == FALSE)
 		return;
-	}
 
 	size = wrap_feed_channel_get_enclosures_maxsize (feed);
 	if (size > 0 && (feed_enclosure_get_length (enclosure) * 1024) > size)
@@ -317,8 +316,10 @@ queue_enclosures (TrackerMinerRSS      *miner,
 		enc = iter->data;
 
 		tmp_string = feed_enclosure_get_url (enc);
-		if (tmp_string == NULL)
+		if (tmp_string == NULL) {
+			g_message ("Enclosure without URL, skipping");
 			continue;
+		}
 
 		rsubject = g_strdup_printf ("_:enclosurefile%d", num);
 		subject = g_strdup_printf ("_:enclosure%d", num);
@@ -416,21 +417,20 @@ item_verify_reply_cb (GObject      *source_object,
 {
 	int i;
 	int enclosures_num;
+	gboolean has_geopoint;
 	time_t t;
-	gchar **values;
 	gchar *enclosure_ref;
 	const gchar *uri;
 	const gchar *url;
 	const gchar *tmp_string;
 	gdouble latitude;
 	gdouble longitude;
-	const GPtrArray *response;
 	GError *error;
 	TrackerSparqlBuilder *sparql;
 	FeedItem *item;
 	FeedChannel *feed;
 	TrackerMinerRSS *miner;
-	gboolean has_geopoint;
+	TrackerResultIterator *response;
 
 	miner = TRACKER_MINER_RSS (source_object);
 	item = user_data;
@@ -447,8 +447,9 @@ item_verify_reply_cb (GObject      *source_object,
 		return;
 	}
 
-	values = g_ptr_array_index (response, 0);
-	if (g_strcmp0 (values[0], "1") == 0) {
+	tracker_result_iterator_next (response);
+	tmp_string = tracker_result_iterator_value (response, 0);
+	if (g_strcmp0 (tmp_string, "1") == 0) {
 		g_object_unref (item);
 		return;
 	}
@@ -464,12 +465,20 @@ item_verify_reply_cb (GObject      *source_object,
 
 	has_geopoint = feed_item_get_geo_point (item, &latitude, &longitude);
 
-	if (has_geopoint) {
+	tracker_sparql_builder_insert_open (sparql, "_:message");
+	tracker_sparql_builder_subject (sparql, "_:message");
+	tracker_sparql_builder_predicate (sparql, "a");
+	tracker_sparql_builder_object (sparql, "mfo:FeedMessage");
+	tracker_sparql_builder_predicate (sparql, "a");
+	tracker_sparql_builder_object (sparql, "nfo:RemoteDataObject");
+
+	if (has_geopoint == TRUE) {
 		g_message ("  Geopoint, using longitude:%f, latitude:%f",
 		           longitude, latitude);
 
-		tracker_sparql_builder_insert_open (sparql, "_:location");
-		tracker_sparql_builder_subject (sparql, "_:location");
+		tracker_sparql_builder_predicate (sparql, "mlo:location");
+
+		tracker_sparql_builder_object_blank_open (sparql);
 		tracker_sparql_builder_predicate (sparql, "a");
 		tracker_sparql_builder_object (sparql, "mlo:GeoLocation");
 		tracker_sparql_builder_predicate (sparql, "mlo:asGeoPoint");
@@ -482,18 +491,8 @@ item_verify_reply_cb (GObject      *source_object,
 		tracker_sparql_builder_predicate (sparql, "mlo:longitude");
 		tracker_sparql_builder_object_double (sparql, longitude);
 		tracker_sparql_builder_object_blank_close (sparql);
-	}
 
-	tracker_sparql_builder_insert_open (sparql, "_:message");
-	tracker_sparql_builder_subject (sparql, "_:message");
-	tracker_sparql_builder_predicate (sparql, "a");
-	tracker_sparql_builder_object (sparql, "mfo:FeedMessage");
-	tracker_sparql_builder_predicate (sparql, "a");
-	tracker_sparql_builder_object (sparql, "nfo:RemoteDataObject");
-
-	if (has_geopoint == TRUE) {
-		tracker_sparql_builder_predicate (sparql, "mlo:location");
-		tracker_sparql_builder_object (sparql, "_:location");
+		tracker_sparql_builder_object_blank_close (sparql);
 	}
 
 	tmp_string = feed_item_get_title (item);
@@ -597,10 +596,9 @@ mandatory_enclosures_collected (GObject      *source_object,
                                 GAsyncResult *res,
                                 gpointer      user_data)
 {
-	int i;
-	gchar **values;
-	const GPtrArray *response;
+	const gchar *url;
 	GError *error;
+	TrackerResultIterator *response;
 	FeedEnclosure *enclosure;
 	WrapFeedChannel *feed;
 
@@ -617,9 +615,12 @@ mandatory_enclosures_collected (GObject      *source_object,
 
 	feed = user_data;
 
-	for (i = 0; i < response->len; i++) {
-		values = g_ptr_array_index (response, i);
-		enclosure = feed_enclosure_new (values [0]);
+	while (tracker_result_iterator_next (response)) {
+		url = tracker_result_iterator_value (response, 0);
+		if (url == NULL)
+			continue;
+
+		enclosure = feed_enclosure_new ((gchar*) url);
 		download_enclosure_now (TRACKER_MINER_RSS (source_object), enclosure, feed);
 	}
 }
@@ -689,13 +690,12 @@ feeds_retrieve_cb (GObject      *source_object,
                    gpointer      user_data)
 {
 	gint interval;
-	guint i;
 	int int_value;
-	gchar **values;
+	const gchar *str;
 	GList *channels;
-	const GPtrArray *response;
 	GError *error;
 	TrackerMinerRSSPrivate *priv;
+	TrackerResultIterator *response;
 	WrapFeedChannel *chan;
 
 	error = NULL;
@@ -711,37 +711,40 @@ feeds_retrieve_cb (GObject      *source_object,
 
 	channels = NULL;
 
-	g_message ("Found %d feeds", response->len);
-
-		for (i = 0; i < response->len; i++) {
-			values = g_ptr_array_index (response, i);
-
-		chan = wrap_feed_channel_new (TRACKER_MINER_RSS (source_object), values [2]);
-		feed_channel_set_source (FEED_CHANNEL (chan), values [0]);
+	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);
 
 		/* 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"
 		 */
-		interval = strtoull (values [1], NULL, 10);
+		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);
 
-		if (values [3] != NULL && strcmp (values [3], "") != 0) {
-			int_value = strtoull (values [3], NULL, 10);
+		str = tracker_result_iterator_value (response, 3);
+		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);
 		}
 
-		if (values [4] != NULL && strcmp (values [4], "") != 0)
-			wrap_feed_channel_set_download_enclosures (chan, strcmp (values [4], "true") == 0);
+		str = tracker_result_iterator_value (response, 4);
+		if (str != NULL && strcmp (str, "") != 0)
+			wrap_feed_channel_set_download_enclosures (chan, strcmp (str, "true") == 0);
 
-		if (values [5] != NULL && strcmp (values [5], "") != 0)
-			wrap_feed_channel_set_enclosures_saving_path (chan, values [5]);
+		str = tracker_result_iterator_value (response, 5);
+		if (str != NULL && strcmp (str, "") != 0)
+			wrap_feed_channel_set_enclosures_saving_path (chan, (gchar*) str);
 
-		if (values [6] != NULL && strcmp (values [6], "") != 0) {
-			int_value = strtoull (values [6], NULL, 10);
+		str = tracker_result_iterator_value (response, 6);
+		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);
 		}
diff --git a/src/miners/rss/wrap-feed-enclosure.c b/src/miners/rss/wrap-feed-enclosure.c
index 5108f9e..62112bf 100644
--- a/src/miners/rss/wrap-feed-enclosure.c
+++ b/src/miners/rss/wrap-feed-enclosure.c
@@ -163,33 +163,17 @@ get_local_node_query (WrapFeedEnclosure *enclosure)
 }
 
 static gboolean
-notify_miner_fs (const gchar *path)
+notify_miner_fs (TrackerMiner *miner, const gchar *path)
 {
-	gboolean ret;
-	const gchar **params;
-	GError *error;
-	DBusGConnection *connection;
-	DBusGProxy *proxy;
-
-	connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
-	proxy = dbus_g_proxy_new_for_name (connection,
-	                                   "org.freedesktop.Tracker1.Miner.Files",
-	                                   "/org/freedesktop/Tracker1/Miner/Files",
-	                                   "org.freedesktop.Tracker1.Miner");
+	gchar **params;
 
 	params = g_new0 (const gchar*, 2);
 	params [0] = path;
 
-	error = NULL;
-	ret = dbus_g_proxy_call (proxy, "IgnoreNextUpdate", &error,
-				 G_TYPE_STRV, params, G_TYPE_INVALID, G_TYPE_INVALID);
-
-	if (ret == FALSE)
-		g_warning ("Unable to notify miner-fs about incoming enclosure saving: %s.", error->message);
+	tracker_miner_ignore_next_update (miner, params);
 
 	g_free (params);
-	dbus_g_connection_unref (connection);
-	return ret;
+	return TRUE;
 }
 
 static void
@@ -258,7 +242,7 @@ enclosure_node_set (GObject      *source,
 		if (path == NULL)
 			return;
 
-		if (notify_miner_fs (path) == FALSE)
+		if (notify_miner_fs (TRACKER_MINER (source), path) == FALSE)
 			return;
 
 		fd = fopen (path, "w+");



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