[tracker/miner-rss: 3/3] tracker-miner-rss: Resyling, added logging capability, and relative -v (verbosity), added check call



commit 95830d1cb466154fb916f789ef0bdd8ca12da21d
Author: Michele Tameni <michele tameni it>
Date:   Wed Mar 10 10:11:45 2010 +0100

    tracker-miner-rss: Resyling, added logging capability, and relative -v (verbosity),
    added check callbacks when saving contents

 configure.ac                                       |   10 +-
 data/Makefile.am                                   |    2 +-
 data/miners/Makefile.am                            |    4 +-
 ...eds.desktop.in => tracker-miner-rss.desktop.in} |    2 +-
 data/tracker-miner-rss.desktop.in.in               |    4 +-
 src/tracker-miner-rss/Makefile.am                  |    2 +-
 src/tracker-miner-rss/tracker-main.c               |   64 +++-
 src/tracker-miner-rss/tracker-miner-rss.c          |  361 ++++++++++++--------
 src/tracker-miner-rss/tracker-miner-rss.h          |   19 +-
 9 files changed, 296 insertions(+), 172 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f0b264a..1dc3485 100644
--- a/configure.ac
+++ b/configure.ac
@@ -786,14 +786,14 @@ AM_CONDITIONAL(USING_KMAIL_MINER, test "x$enable_kmail_miner" = "xyes")
 
 AC_ARG_ENABLE([miner_rss],
               AS_HELP_STRING([--enable-miner-rss],
-		             [enable miner rss [[default=auto]]]),,
-	      [enable_miner_rss=auto])
+                             [enable miner rss [[default=auto]]]),,
+              [enable_miner_rss=auto])
 
 if test "x$enable_miner_rss" != "xno" ; then
    PKG_CHECK_MODULES(LIBGRSS,
-	             [libgrss-0 >= $LIBGRSS_REQUIRED],
-		     [have_libgrss=yes],
-		     [have_libgrss=no])
+                     [libgrss-0 >= $LIBGRSS_REQUIRED],
+                     [have_libgrss=yes],
+                     [have_libgrss=no])
 
    AC_SUBST(LIBGRSS_CFLAGS)
    AC_SUBST(LIBGRSS_LIBS)
diff --git a/data/Makefile.am b/data/Makefile.am
index c3e682d..e1a45ee 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -17,7 +17,7 @@ tracker-miner-fs.desktop.in: tracker-miner-fs.desktop.in.in
 
 if USING_MINER_RSS
 tracker-miner-rss.desktop.in: tracker-miner-rss.desktop.in.in
-	@sed -e "s|@libexecdir[ ]|${libexecdir}|" 	\
+	@$(SED) -e "s|@libexecdir[ ]|${libexecdir}|" 	\
 	     -e "s|@VERSION[ ]|${VERSION}|" $< > $@
 endif
 
diff --git a/data/miners/Makefile.am b/data/miners/Makefile.am
index efc8cb7..b435f45 100644
--- a/data/miners/Makefile.am
+++ b/data/miners/Makefile.am
@@ -5,7 +5,7 @@ desktop_in_files = \
 	tracker-miner-files.desktop.in
 
 if USING_MINER_RSS
-desktop_in_files +=	tracker-miner-feeds.desktop.in
+desktop_in_files +=	tracker-miner-rss.desktop.in
 endif
 
 tracker_minersdir = $(datadir)/tracker/miners
@@ -15,7 +15,7 @@ tracker_miners_DATA = \
 	tracker-miner-files.desktop
 
 if USING_MINER_RSS
-tracker_miners_DATA += 	tracker-miner-feeds.desktop
+tracker_miners_DATA += 	tracker-miner-rss.desktop
 endif
 
 @INTLTOOL_DESKTOP_RULE@
diff --git a/data/miners/tracker-miner-feeds.desktop.in b/data/miners/tracker-miner-rss.desktop.in
similarity index 56%
rename from data/miners/tracker-miner-feeds.desktop.in
rename to data/miners/tracker-miner-rss.desktop.in
index 77f00df..0c5007b 100644
--- a/data/miners/tracker-miner-feeds.desktop.in
+++ b/data/miners/tracker-miner-rss.desktop.in
@@ -1,6 +1,6 @@
 [Desktop Entry]
 Encoding=UTF-8
 _Name=RSS/ATOM Feeds
-_Comment=RSS/ATOM feed miner
+_Comment=Fetch RSS/ATOM Feeds
 DBusName=org.freedesktop.Tracker1.Miner.RSS
 DBusPath=/org/freedesktop/Tracker1/Miner/RSS
\ No newline at end of file
diff --git a/data/tracker-miner-rss.desktop.in.in b/data/tracker-miner-rss.desktop.in.in
index e01fc59..b270917 100644
--- a/data/tracker-miner-rss.desktop.in.in
+++ b/data/tracker-miner-rss.desktop.in.in
@@ -1,6 +1,6 @@
 [Desktop Entry]
 Encoding=UTF-8
-Name=RSS
-Comment=RSS feeds fetcher
+Name=RSS/ATOM Feeds
+Comment=Fetch RSS/ATOM Feeds
 DBusName=org.freedesktop.Tracker1.Miner.RSS
 DBusPath=/org/freedesktop/Tracker1/Miner/RSS
\ No newline at end of file
diff --git a/src/tracker-miner-rss/Makefile.am b/src/tracker-miner-rss/Makefile.am
index 750bcd4..ad8cc8a 100644
--- a/src/tracker-miner-rss/Makefile.am
+++ b/src/tracker-miner-rss/Makefile.am
@@ -17,7 +17,7 @@ INCLUDES =								\
 libexec_PROGRAMS = tracker-miner-rss
 
 tracker_miner_rss_SOURCES =						\
-	tracker-main.c						\
+	tracker-main.c							\
 	tracker-miner-rss.h						\
 	tracker-miner-rss.c
 
diff --git a/src/tracker-miner-rss/tracker-main.c b/src/tracker-miner-rss/tracker-main.c
index 921f705..8411aba 100644
--- a/src/tracker-miner-rss/tracker-main.c
+++ b/src/tracker-miner-rss/tracker-main.c
@@ -3,32 +3,82 @@
  *                          Michele Tameni <michele amdplanet it>
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
+ * modify it under the terms of the GNU General Public
  * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
+ * General Public License for more details.
  *
- * You should have received a copy of the GNU Lesser General Public
+ * You should have received a copy of the GNU General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA  02110-1301, USA.
  */
 
+#include "config.h"
+
 #include <stdlib.h>
+
+#include <locale.h>
+#include <glib/gi18n.h>
+
+#include <libtracker-common/tracker-common.h>
+
 #include "tracker-miner-rss.h"
 
+static gint verbosity = -1;
+
+static GOptionEntry entries[] = {
+	{ "verbosity", 'v', 0,
+	  G_OPTION_ARG_INT, &verbosity,
+	  N_("Logging, 0 = errors only, "
+	  "1 = minimal, 2 = detailed and 3 = debug (default=0)"),
+	  NULL },
+	{ NULL }
+};
+
 int
-main () {
+main (int argc, char **argv)
+{
+	gchar *log_filename;
+	GMainLoop *loop;
+	GOptionContext *context;
 	TrackerMinerRSS *miner;
 
 	g_type_init ();
 	g_thread_init (NULL);
+
+	setlocale (LC_ALL, "");
+
+	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+	tzset ();
+
+	/* Translators: this messagge will apper immediately after the
+	 * usage string - Usage: COMMAND <THIS_MESSAGE>
+	 */
+	context = g_option_context_new (_("- start the feeds indexer"));
+	g_option_context_add_main_entries (context, entries, NULL);
+	g_option_context_parse (context, &argc, &argv, NULL);
+	g_option_context_free (context);
+
+	tracker_log_init (verbosity, &log_filename);
+	g_print ("Starting log:\n  File:'%s'\n", log_filename);
+	g_free (log_filename);
+
 	miner = g_object_new (TRACKER_TYPE_MINER_RSS, "name", "RSS", NULL);
 	tracker_miner_start (TRACKER_MINER (miner));
-	g_main_loop_run (g_main_loop_new (NULL, FALSE));
-	exit (0);
+
+	loop = g_main_loop_new (NULL, FALSE);
+	g_main_loop_run (loop);
+
+	tracker_log_shutdown ();
+	g_main_loop_unref (loop);
+	g_object_unref (miner);
+
+	return 0;
 }
diff --git a/src/tracker-miner-rss/tracker-miner-rss.c b/src/tracker-miner-rss/tracker-miner-rss.c
index d15b9b8..914e086 100644
--- a/src/tracker-miner-rss/tracker-miner-rss.c
+++ b/src/tracker-miner-rss/tracker-miner-rss.c
@@ -3,61 +3,66 @@
  *                          Michele Tameni <michele amdplanet it>
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
+ * modify it under the terms of the GNU General Public
  * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
+ * General Public License for more details.
  *
- * You should have received a copy of the GNU Lesser General Public
+ * You should have received a copy of the GNU General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA  02110-1301, USA.
  */
 
-#include "tracker-miner-rss.h"
-
 #include <stdio.h>
-#include <dbus/dbus-glib.h>
-#include <libtracker-miner/tracker-miner.h>
-#include <libtracker-common/tracker-sparql-builder.h>
 #include <libgrss.h>
+#include <dbus/dbus-glib.h>
+
+#include <glib/gi18n.h>
+
+#include "tracker-miner-rss.h"
+
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_MINER_RSS, TrackerMinerRSSPrivate))
 
-#define TRACKER_MINER_RSS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER_RSS, TrackerMinerRSSPrivate))
+typedef struct _TrackerMinerRSSPrivate TrackerMinerRSSPrivate;
 
-struct TrackerMinerRSSPrivate {
-	gboolean	paused;
-	gboolean	stopped;
+struct _TrackerMinerRSSPrivate {
+	gboolean paused;
+	gboolean stopped;
 
-	FeedsPool	*pool;
-	int		now_fetching;
+	FeedsPool *pool;
+	gint now_fetching;
 };
 
-static void tracker_miner_rss_started (TrackerMiner *miner);
-static void tracker_miner_rss_stopped (TrackerMiner *miner);
-static void tracker_miner_rss_paused (TrackerMiner *miner);
-static void tracker_miner_rss_resumed (TrackerMiner *miner);
-static void retrieve_and_schedule_feeds (TrackerMinerRSS *miner);
-static void update_updated_interval (TrackerMinerRSS *miner, gchar *uri, time_t *now);
-static void change_status (FeedsPool *pool, FeedChannel *feed, gpointer user_data);
-static void feed_fetched (FeedsPool *pool, FeedChannel *feed, GList *items, gpointer user_data);
-static gchar* get_message_subject (FeedItem *item);
-static const gchar* get_message_url (FeedItem *item);
+static void        tracker_miner_rss_started   (TrackerMiner    *miner);
+static void        tracker_miner_rss_stopped   (TrackerMiner    *miner);
+static void        tracker_miner_rss_paused    (TrackerMiner    *miner);
+static void        tracker_miner_rss_resumed   (TrackerMiner    *miner);
+static void        retrieve_and_schedule_feeds (TrackerMinerRSS *miner);
+static void        change_status               (FeedsPool       *pool,
+                                                FeedChannel     *feed,
+                                                gpointer         user_data);
+static void        feed_fetched                (FeedsPool       *pool,
+                                                FeedChannel     *feed,
+                                                GList           *items,
+                                                gpointer         user_data);
+static const gchar *get_message_url            (FeedItem        *item);
 
 G_DEFINE_TYPE (TrackerMinerRSS, tracker_miner_rss, TRACKER_TYPE_MINER)
 
 static void
 tracker_miner_rss_finalize (GObject *object)
 {
-	TrackerMinerRSS *rss;
+	TrackerMinerRSSPrivate *priv;
 
-	rss = TRACKER_MINER_RSS (object);
+	priv = GET_PRIV (object);
 
-	rss->priv->stopped = TRUE;
-	g_object_unref (rss->priv->pool);
+	priv->stopped = TRUE;
+	g_object_unref (priv->pool);
 
 	G_OBJECT_CLASS (tracker_miner_rss_parent_class)->finalize (object);
 }
@@ -68,38 +73,39 @@ tracker_miner_rss_class_init (TrackerMinerRSSClass *klass)
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 	TrackerMinerClass *miner_class = TRACKER_MINER_CLASS (klass);
 
-	g_type_class_add_private (object_class, sizeof (TrackerMinerRSSPrivate));
 	object_class->finalize = tracker_miner_rss_finalize;
 
 	miner_class->started = tracker_miner_rss_started;
 	miner_class->stopped = tracker_miner_rss_stopped;
 	miner_class->paused  = tracker_miner_rss_paused;
 	miner_class->resumed = tracker_miner_rss_resumed;
+
+	g_type_class_add_private (object_class, sizeof (TrackerMinerRSSPrivate));
 }
 
 static void
-subjects_added_cb (DBusGProxy *proxy, gchar **subjects, gpointer user_data)
+subjects_added_cb (DBusGProxy *proxy,
+                   gchar     **subjects,
+                   gpointer    user_data)
 {
 	TrackerMinerRSS *miner;
 
 	miner = TRACKER_MINER_RSS (user_data);
 
-	/*
-		TODO	Add only the channels added?
-	*/
+	/* TODO Add only the channels added? */
 	retrieve_and_schedule_feeds (miner);
 }
 
 static void
-subjects_removed_cb (DBusGProxy *proxy, gchar **subjects, gpointer user_data)
+subjects_removed_cb (DBusGProxy *proxy,
+                     gchar     **subjects,
+                     gpointer    user_data)
 {
 	TrackerMinerRSS *miner;
 
 	miner = TRACKER_MINER_RSS (user_data);
 
-	/*
-		TODO	Remove only the channels removed?
-	*/
+	/* TODO Remove only the channels removed? */
 	retrieve_and_schedule_feeds (miner);
 }
 
@@ -107,19 +113,11 @@ static void
 tracker_miner_rss_init (TrackerMinerRSS *object)
 {
 	DBusGProxy *wrap;
-
-	object->priv = TRACKER_MINER_RSS_GET_PRIVATE (object);
-
-	object->priv->pool = feeds_pool_new ();
-	g_signal_connect (object->priv->pool, "feed-fetching", G_CALLBACK (change_status), object);
-	g_signal_connect (object->priv->pool, "feed-ready", G_CALLBACK (feed_fetched), object);
-	object->priv->now_fetching = 0;
-
-	g_object_set (object, "progress", 0.0, "status", "Initializing", NULL);
+	TrackerMinerRSSPrivate *priv;
 
 	wrap = dbus_g_proxy_new_for_name (dbus_g_bus_get (DBUS_BUS_SESSION, NULL),
 	                                  "org.freedesktop.Tracker1",
-					  "/org/freedesktop/Tracker1/Resources/Classes/mfo/FeedChannel",
+	                                  "/org/freedesktop/Tracker1/Resources/Classes/mfo/FeedChannel",
 	                                  "org.freedesktop.Tracker1.Resources.Class");
 
 	if (wrap == NULL) {
@@ -127,6 +125,15 @@ tracker_miner_rss_init (TrackerMinerRSS *object)
 		return;
 	}
 
+	priv = GET_PRIV (object);
+
+	priv->pool = feeds_pool_new ();
+	g_signal_connect (priv->pool, "feed-fetching", G_CALLBACK (change_status), 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);
+
 	dbus_g_proxy_add_signal (wrap, "SubjectsAdded", G_TYPE_STRV, G_TYPE_INVALID);
 	dbus_g_proxy_connect_signal (wrap, "SubjectsAdded", G_CALLBACK (subjects_added_cb), object, NULL);
 
@@ -135,14 +142,31 @@ tracker_miner_rss_init (TrackerMinerRSS *object)
 }
 
 static void
-update_updated_interval (TrackerMinerRSS *miner, gchar *uri, time_t *now)
+verify_channel_update (GObject      *source,
+                       GAsyncResult *result,
+                       gpointer      user_data)
+{
+	GError *error;
+
+	error = NULL;
+
+	tracker_miner_execute_update_finish (TRACKER_MINER (source), result, &error);
+	if (error != NULL) {
+		g_critical ("Unable to update information about channel: %s", error->message);
+		g_error_free (error);
+	}
+}
+
+static void
+update_updated_interval (TrackerMinerRSS *miner,
+                         gchar           *uri,
+                         time_t          *now)
 {
 	TrackerSparqlBuilder *sparql;
 
-	/*
-		I hope there will be soon a SPARQL command to just update a
-		value instead to delete and re-insert it
-	*/
+	/* I hope there will be soon a SPARQL command to just update a
+	 * value instead to delete and re-insert it
+	 */
 
 	sparql = tracker_sparql_builder_new_update ();
 	tracker_sparql_builder_delete_open (sparql, NULL);
@@ -162,35 +186,63 @@ update_updated_interval (TrackerMinerRSS *miner, gchar *uri, time_t *now)
 	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, NULL, NULL);
+	tracker_miner_execute_update (TRACKER_MINER (miner),
+	                              tracker_sparql_builder_get_result (sparql),
+	                              NULL,
+	                              verify_channel_update,
+	                              NULL);
 	g_object_unref (sparql);
 }
 
 static void
-change_status (FeedsPool *pool, FeedChannel *feed, gpointer user_data)
+change_status (FeedsPool   *pool,
+               FeedChannel *feed,
+               gpointer     user_data)
 {
-	int avail;
-	double prog;
+	gint avail;
+	gdouble prog;
 	TrackerMinerRSS *miner;
+	TrackerMinerRSSPrivate *priv;
+
+	g_message ("Fetching %s", feed_channel_get_source (feed));
+
+	miner = TRACKER_MINER_RSS (user_data);
+	priv = GET_PRIV (miner);
+	avail = feeds_pool_get_listened_num (priv->pool);
+
+	priv->now_fetching++;
+	if (priv->now_fetching > avail)
+		priv->now_fetching = avail;
 
-	miner = (TrackerMinerRSS*) user_data;
-	avail = feeds_pool_get_listened_num (miner->priv->pool);
+	prog = ((gdouble) priv->now_fetching) / ((gdouble) avail);
+	g_object_set (miner, "progress", prog, "status", _("Fetching..."), NULL);
+}
+
+static void
+verify_item_insertion (GObject      *source,
+                       GAsyncResult *result,
+                       gpointer      user_data)
+{
+	GError *error;
 
-	miner->priv->now_fetching++;
-	if (miner->priv->now_fetching > avail)
-		miner->priv->now_fetching = avail;
+	error = NULL;
 
-	prog = (double) miner->priv->now_fetching / (double) avail;
-	g_object_set (miner, "progress", prog, "status", "Fetching...", NULL);
+	tracker_miner_execute_update_finish (TRACKER_MINER (source), result, &error);
+	if (error != NULL) {
+		g_critical ("Unable to create new item: %s", error->message);
+		g_error_free (error);
+	}
 }
 
 static void
-item_verify_reply_cb (GObject *source_object, GAsyncResult *res, gpointer data)
+item_verify_reply_cb (GObject      *source_object,
+                      GAsyncResult *res,
+                      gpointer      user_data)
 {
 	time_t t;
 	gchar *uri;
-	gchar *subject;
 	gchar **values;
+	const gchar *url;
 	gdouble latitude;
 	gdouble longitude;
 	const gchar *tmp_string;
@@ -203,26 +255,29 @@ item_verify_reply_cb (GObject *source_object, GAsyncResult *res, gpointer data)
 	gboolean has_geopoint;
 
 	miner = TRACKER_MINER_RSS (source_object);
-	response = tracker_miner_execute_sparql_finish (TRACKER_MINER (source_object), res, &error);
+	error = NULL;
+	response = tracker_miner_execute_sparql_finish (TRACKER_MINER (source_object),
+	                                                res,
+	                                                &error);
 
-	if (response == NULL) {
-		g_warning ("Unable to verify item: %s\n", error->message);
+	if (error != NULL) {
+		g_warning ("Unable to verify item existance: %s\n", error->message);
 		g_error_free (error);
 		return;
 	}
 
-	values = (gchar**) g_ptr_array_index (response, 0);
-	if (strcmp (values [0], "1") == 0)
+	values = g_ptr_array_index (response, 0);
+	if (g_strcmp0 (values[0], "1") == 0)
 		return;
 
-	item = data;
+	item = user_data;
 
-	subject = get_message_subject (item);
+	url = get_message_url (item);
 
 	sparql = tracker_sparql_builder_new_update ();
 
 	has_geopoint = feed_item_get_geo_point (item, &latitude, &longitude);
-	tracker_sparql_builder_insert_open (sparql, subject);
+	tracker_sparql_builder_insert_open (sparql, url);
 
 	if (has_geopoint) {
 		tracker_sparql_builder_subject (sparql, "_:location");
@@ -253,24 +308,22 @@ item_verify_reply_cb (GObject *source_object, GAsyncResult *res, gpointer data)
 	tmp_string = feed_item_get_title (item);
 	if (tmp_string != NULL) {
 		tracker_sparql_builder_predicate (sparql, "nie:title");
-		tracker_sparql_builder_object_string (sparql, tmp_string);
+		tracker_sparql_builder_object_unvalidated (sparql, tmp_string);
 	}
 
 	tmp_string = feed_item_get_description (item);
 	if (tmp_string != NULL) {
 		tracker_sparql_builder_predicate (sparql, "nmo:plainTextMessageContent");
-		tracker_sparql_builder_object_string (sparql, tmp_string);
+		tracker_sparql_builder_object_unvalidated (sparql, tmp_string);
 	}
 
-	tmp_string = get_message_url (item);
-	if (tmp_string != NULL) {
+	if (url != NULL) {
 		tracker_sparql_builder_predicate (sparql, "nie:url");
-		tracker_sparql_builder_object_string (sparql, tmp_string);
+		tracker_sparql_builder_object_unvalidated (sparql, url);
 	}
 
-	/*
-		nmo:receivedDate and mfo:downloadedTime are the same? Ask for the MFO maintainer
-	*/
+	/* TODO nmo:receivedDate and mfo:downloadedTime are the same?
+	 *      Ask for the MFO maintainer */
 
 	t = time (NULL);
 
@@ -288,20 +341,24 @@ item_verify_reply_cb (GObject *source_object, GAsyncResult *res, gpointer data)
 	tracker_sparql_builder_object_boolean (sparql, FALSE);
 
 	feed = feed_item_get_parent (item);
-	uri = (gchar*) g_object_get_data (G_OBJECT (feed), "subject");
+	uri = g_object_get_data (G_OBJECT (feed), "subject");
 	tracker_sparql_builder_predicate (sparql, "nmo:communicationChannel");
 	tracker_sparql_builder_object_iri (sparql, uri);
 
 	tracker_sparql_builder_insert_close (sparql);
 
-	tracker_miner_execute_update (TRACKER_MINER (miner), tracker_sparql_builder_get_result (sparql), NULL, NULL, NULL);
+	tracker_miner_execute_update (TRACKER_MINER (miner),
+	                              tracker_sparql_builder_get_result (sparql),
+	                              NULL,
+	                              verify_item_insertion,
+	                              NULL);
 
 	g_object_unref (sparql);
-	g_free (subject);
 }
 
 static void
-check_if_save (TrackerMinerRSS *miner, FeedItem *item)
+check_if_save (TrackerMinerRSS *miner,
+               FeedItem        *item)
 {
 	FeedChannel *feed;
 	gchar *query;
@@ -310,28 +367,40 @@ check_if_save (TrackerMinerRSS *miner, FeedItem *item)
 
 	url = get_message_url (item);
 	feed = feed_item_get_parent (item);
-	communication_channel = (gchar*) g_object_get_data (G_OBJECT (feed), "subject");
-
-	query = g_strdup_printf ("ASK { ?message a mfo:FeedMessage; nie:url \"%s\"; nmo:communicationChannel <%s> }",
-	                        url, communication_channel);
-	tracker_miner_execute_sparql (TRACKER_MINER (miner), query, NULL, item_verify_reply_cb, item);
+	communication_channel = g_object_get_data (G_OBJECT (feed), "subject");
+
+	query = g_strdup_printf ("ASK { ?message a mfo:FeedMessage; "
+	                         "nie:url \"%s\"; nmo:communicationChannel <%s> }",
+	                         url,
+	                         communication_channel);
+
+	tracker_miner_execute_sparql (TRACKER_MINER (miner),
+	                              query,
+	                              NULL,
+	                              item_verify_reply_cb,
+	                              item);
 	g_free (query);
 }
 
 static void
-feed_fetched (FeedsPool *pool, FeedChannel *feed, GList *items, gpointer user_data)
+feed_fetched (FeedsPool   *pool,
+              FeedChannel *feed,
+              GList       *items,
+              gpointer     user_data)
 {
 	gchar *uri;
 	time_t now;
 	GList *iter;
 	FeedItem *item;
 	TrackerMinerRSS *miner;
+	TrackerMinerRSSPrivate *priv;
 
-	miner = (TrackerMinerRSS*) user_data;
+	miner = TRACKER_MINER_RSS (user_data);
+	priv = GET_PRIV (miner);
 
-	miner->priv->now_fetching--;
-	if (miner->priv->now_fetching <= 0) {
-		miner->priv->now_fetching = 0;
+	priv->now_fetching--;
+	if (priv->now_fetching <= 0) {
+		priv->now_fetching = 0;
 		g_object_set (miner, "progress", 1.0, "status", "Idle", NULL);
 	}
 
@@ -339,31 +408,35 @@ feed_fetched (FeedsPool *pool, FeedChannel *feed, GList *items, gpointer user_da
 		return;
 
 	now = time (NULL);
-	uri = (gchar*) g_object_get_data (G_OBJECT (feed), "subject");
+	uri = g_object_get_data (G_OBJECT (feed), "subject");
 	update_updated_interval (miner, uri, &now);
 
-	for (iter = items; iter; iter = g_list_next (iter)) {
-		item = (FeedItem*) iter->data;
+	for (iter = items; iter; iter = iter->next) {
+		item = iter->data;
 		check_if_save (miner, item);
 	}
 }
 
 static void
-feeds_retrieve_cb (GObject *source_object, GAsyncResult *res, gpointer data)
+feeds_retrieve_cb (GObject      *source_object,
+                   GAsyncResult *res,
+                   gpointer      user_data)
 {
-	int interval;
-	register int i;
+	gint interval;
+	guint i;
 	gchar **values;
 	GList *channels;
 	const GPtrArray *response;
 	GError *error;
-	TrackerMinerRSS *miner;
+	TrackerMinerRSSPrivate *priv;
 	FeedChannel *chan;
 
-	miner = TRACKER_MINER_RSS (source_object);
-	response = tracker_miner_execute_sparql_finish (TRACKER_MINER (source_object), res, &error);
+	error = NULL;
+	response = tracker_miner_execute_sparql_finish (TRACKER_MINER (source_object),
+	                                                res,
+	                                                &error);
 
-	if (response == NULL) {
+	if (error != NULL) {
 		g_warning ("Unable to retrieve list of feeds: %s\n", error->message);
 		g_error_free (error);
 		return;
@@ -372,17 +445,19 @@ feeds_retrieve_cb (GObject *source_object, GAsyncResult *res, gpointer data)
 	channels = NULL;
 
 	for (i = 0; i < response->len; i++) {
-		values = (gchar**) g_ptr_array_index (response, i);
+		values = g_ptr_array_index (response, i);
 
 		chan = feed_channel_new ();
-		g_object_set_data_full (G_OBJECT (chan), "subject", g_strdup (values [2]), g_free);
+		g_object_set_data_full (G_OBJECT (chan),
+		                        "subject",
+		                        g_strdup (values [2]),
+		                        g_free);
 		feed_channel_set_source (chan, values [0]);
 
-		/*
-			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"
-		*/
+		/* 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);
 		if (interval <= 0)
 			interval = 1;
@@ -391,31 +466,31 @@ feeds_retrieve_cb (GObject *source_object, GAsyncResult *res, gpointer data)
 		channels = g_list_prepend (channels, chan);
 	}
 
-	feeds_pool_listen (miner->priv->pool, channels);
+	priv = GET_PRIV (source_object);
+	feeds_pool_listen (priv->pool, channels);
 }
 
 static void
 retrieve_and_schedule_feeds (TrackerMinerRSS *miner)
 {
-	gchar *sparql;
+	const gchar *sparql;
 
-	sparql = g_strdup_printf ("SELECT ?chanUrl ?interval ?chanUrn WHERE		\
-	                           { ?chanUrn a mfo:FeedChannel .			\
-	                             ?chanUrn mfo:feedSettings ?settings .		\
-	                             ?chanUrn nie:url ?chanUrl .			\
-	                             ?settings mfo:updateInterval ?interval }");
+	sparql = "SELECT ?chanUrl ?interval ?chanUrn WHERE "
+	         "{ ?chanUrn a mfo:FeedChannel . "
+	         "?chanUrn mfo:feedSettings ?settings . "
+	         "?chanUrn nie:url ?chanUrl . "
+	         "?settings mfo:updateInterval ?interval }";
 
-	tracker_miner_execute_sparql (TRACKER_MINER (miner), sparql, NULL, feeds_retrieve_cb, NULL);
-	g_free (sparql);
-}
+	tracker_miner_execute_sparql (TRACKER_MINER (miner),
+	                              sparql,
+	                              NULL,
+	                              feeds_retrieve_cb,
+	                              NULL);
 
-static gchar*
-get_message_subject (FeedItem *item)
-{
-	return g_strdup_printf ("rss://%s", feed_item_get_id (item));
 }
 
-static const gchar*
+static
+const gchar *
 get_message_url (FeedItem *item)
 {
 	const gchar *url;
@@ -429,13 +504,13 @@ get_message_url (FeedItem *item)
 static void
 tracker_miner_rss_started (TrackerMiner *miner)
 {
-	TrackerMinerRSS *rss;
+	TrackerMinerRSSPrivate *priv;
 
 	g_object_set (miner, "progress", 0.0, "status", "Initializing", NULL);
 
-	rss = TRACKER_MINER_RSS (miner);
-	retrieve_and_schedule_feeds (rss);
-	feeds_pool_switch (rss->priv->pool, TRUE);
+	priv = GET_PRIV (miner);
+	retrieve_and_schedule_feeds (TRACKER_MINER_RSS (miner));
+	feeds_pool_switch (priv->pool, TRUE);
 
 	g_object_set (miner, "status", "Idle", NULL);
 }
@@ -443,29 +518,29 @@ tracker_miner_rss_started (TrackerMiner *miner)
 static void
 tracker_miner_rss_stopped (TrackerMiner *miner)
 {
-	TrackerMinerRSS *rss;
+	TrackerMinerRSSPrivate *priv;
 
-	rss = TRACKER_MINER_RSS (miner);
-	feeds_pool_switch (rss->priv->pool, FALSE);
+	priv = GET_PRIV (miner);
+	feeds_pool_switch (priv->pool, FALSE);
 	g_object_set (miner, "progress", 1.0, "status", "Idle", NULL);
 }
 
 static void
 tracker_miner_rss_paused (TrackerMiner *miner)
 {
-	TrackerMinerRSS *rss;
+	TrackerMinerRSSPrivate *priv;
 
-	rss = TRACKER_MINER_RSS (miner);
-	feeds_pool_switch (rss->priv->pool, FALSE);
-	g_object_set (miner, "progress", 1.0, "status", "Paused", NULL);
+	priv = GET_PRIV (miner);
+	feeds_pool_switch (priv->pool, FALSE);
+	g_object_set (miner, "status", "Paused", NULL);
 }
 
 static void
 tracker_miner_rss_resumed (TrackerMiner *miner)
 {
-	TrackerMinerRSS *rss;
+	TrackerMinerRSSPrivate *priv;
 
-	rss = TRACKER_MINER_RSS (miner);
-	feeds_pool_switch (rss->priv->pool, TRUE);
-	g_object_set (miner, "progress", 1.0, "status", "Idle", NULL);
+	priv = GET_PRIV (miner);
+	feeds_pool_switch (priv->pool, TRUE);
+	g_object_set (miner, "status", "Idle", NULL);
 }
diff --git a/src/tracker-miner-rss/tracker-miner-rss.h b/src/tracker-miner-rss/tracker-miner-rss.h
index dffb206..3977a4a 100644
--- a/src/tracker-miner-rss/tracker-miner-rss.h
+++ b/src/tracker-miner-rss/tracker-miner-rss.h
@@ -3,16 +3,16 @@
  *                          Michele Tameni <michele amdplanet it>
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
+ * modify it under the terms of the GNU General Public
  * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
+ * General Public License for more details.
  *
- * You should have received a copy of the GNU Lesser General Public
+ * You should have received a copy of the GNU General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA  02110-1301, USA.
@@ -32,17 +32,16 @@ G_BEGIN_DECLS
 #define TRACKER_IS_MINER_RSS_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c),  TRACKER_TYPE_MINER_RSS))
 #define TRACKER_MINER_RSS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_MINER_RSS, TrackerMinerRSSClass))
 
-typedef struct TrackerMinerRSS        TrackerMinerRSS;
-typedef struct TrackerMinerRSSPrivate TrackerMinerRSSPrivate;
+typedef struct _TrackerMinerRSS TrackerMinerRSS;
+typedef struct _TrackerMinerRSSClass TrackerMinerRSSClass;
 
-struct TrackerMinerRSS {
+struct _TrackerMinerRSS {
 	TrackerMiner parent;
-	TrackerMinerRSSPrivate *priv;
 };
 
-typedef struct {
+struct _TrackerMinerRSSClass {
 	TrackerMinerClass parent;
-} TrackerMinerRSSClass;
+};
 
 GType    tracker_miner_rss_get_type         (void) G_GNUC_CONST;
 



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