[tracker] Improve code of evolution push module



commit d1c72814f0508db4b820b3915292cb8800b3d2bb
Author: Martyn Russell <martyn imendio com>
Date:   Mon Apr 27 11:50:41 2009 +0100

    Improve code of evolution push module
    
    This patch also fixes the coding style in places and replaces some
    strchr() calls for the utf8 equivalent.
---
 src/plugins/evolution/Makefile.am                 |    1 +
 src/plugins/evolution/tracker-evolution-indexer.c |  145 ++++++++++-----------
 src/plugins/kmail/Makefile.am                     |    1 +
 src/plugins/rss/Makefile.am                       |    1 +
 4 files changed, 74 insertions(+), 74 deletions(-)

diff --git a/src/plugins/evolution/Makefile.am b/src/plugins/evolution/Makefile.am
index dbc9209..ce448c7 100644
--- a/src/plugins/evolution/Makefile.am
+++ b/src/plugins/evolution/Makefile.am
@@ -4,6 +4,7 @@ INCLUDES =								\
 	-I$(top_srcdir)/src						\
 	-DGETTEXT_PACKAGE="\"$(GETTEXT_PACKAGE)\""			\
 	-DLOCALEDIR="\"$(localedir)\""					\
+	-DG_LOG_DOMAIN=\"Tracker\"					\
 	-DTRACKER_COMPILATION						\
 	$(WARN_CFLAGS)							\
 	$(DBUS_CFLAGS)							\
diff --git a/src/plugins/evolution/tracker-evolution-indexer.c b/src/plugins/evolution/tracker-evolution-indexer.c
index 213d5c1..624d4b9 100644
--- a/src/plugins/evolution/tracker-evolution-indexer.c
+++ b/src/plugins/evolution/tracker-evolution-indexer.c
@@ -130,16 +130,13 @@ tracker_evolution_indexer_init (TrackerEvolutionIndexer *object)
 {
 }
 
-
 #if 0
 static void
 extract_mime_parts (GMimeObject *object,
 		    gpointer     user_data)
 {
-	const gchar *message_subject = user_data;
-	gchar *subject = NULL;
-	const gchar *disposition, *filename;
 	GMimePart *part;
+	const gchar *disposition, *filename;
 
 	if (GMIME_IS_MESSAGE_PART (object)) {
 		GMimeMessage *message;
@@ -185,8 +182,7 @@ extract_mime_parts (GMimeObject *object,
 		 * Evolution can cope with as URI for an attachment (I don't 
 		 * think it can cope with any attachment URI, btw). */
 
-		subject = g_strdup_printf ("%s/%s", message_subject, 
-					   filename);
+		subject = g_strdup_printf ("%s/%s", user_data, filename);
 
 		tracker_data_insert_statement (subject, 
 					       "File:Path", 
@@ -222,7 +218,8 @@ get_object_encoding (GMimeObject *object)
 		return NULL;
 	}
 
-	start_encoding += strlen ("charset=");
+	/* Length of "charset=" */
+	start_encoding += 8;
 
 	if (start_encoding[0] == '"') {
 		/* encoding is quoted */
@@ -269,11 +266,11 @@ get_email_and_fullname (const gchar *line, gchar **email, gchar **fullname)
 
 static void
 perform_set (TrackerEvolutionIndexer *object, 
-	     const gchar *subject, 
-	     const GStrv predicates, 
-	     const GStrv values)
+	     const gchar             *subject, 
+	     const GStrv              predicates, 
+	     const GStrv              values)
 {
-	guint i = 0;
+	guint i;
 
 	if (!tracker_data_query_resource_exists (DATASOURCE_URN, NULL)) {
 		tracker_data_insert_statement (DATASOURCE_URN, RDF_PREFIX "type",
@@ -289,8 +286,7 @@ perform_set (TrackerEvolutionIndexer *object,
 	tracker_data_insert_statement (subject, NIE_DATASOURCE_P,
 		                       DATASOURCE_URN);
 
-	while (predicates [i] != NULL && values[i] != NULL) {
-
+	for (i = 0; predicates[i] && values[i]; i++) {
 		/* TODO: TRACKER_EVOLUTION_PREDICATE_JUNK (!)
 		 *       TRACKER_EVOLUTION_PREDICATE_ANSWERED
 		 *       TRACKER_EVOLUTION_PREDICATE_FLAGGED
@@ -303,9 +299,7 @@ perform_set (TrackerEvolutionIndexer *object,
 		 * set. Perhaps when we merge this to that branch that we can 
 		 * improve this situation. */
 
-
 #if 0
-
 		/* Disabling this as I can't find any version of GMime-2.0 that
 		 * wont crash on any of my test E-mails. Going to ask Garnacho
 		 * to migrate to GMime-2.4 with his old Evolution support. */
@@ -315,36 +309,40 @@ perform_set (TrackerEvolutionIndexer *object,
 			GMimeParser *parser;
 			GMimeMessage *message;
 			gint fd;
-			gchar *text, *orig_text, *ptr, *encoding;
-			gchar *path = g_strdup (values[i]);
-			off_t offset = 0;
+			gchar *text, *orig_text, *p, *encoding;
+			gchar *path;
+			off_t offset;
 			gboolean is_html;
 
-			ptr = strstr (path, "/!");
-			if (ptr) {
-				offset = (off_t) atol (ptr+2);
-				*ptr = '\0';
+			path = g_strdup (values[i]);
+
+			p = strstr (path, "/!");
+			if (p) {
+				offset = (off_t) atol (p + 2);
+				*p = '\0';
+			} else {
+				offset = 0;
 			}
 
 			fd = tracker_file_open (path, FALSE);
-
 			g_free (path);
 
-			if (fd == -1) 
-				goto cont;
+			if (fd == -1) {
+				continue;
+			}
 
 			stream = g_mime_stream_fs_new_with_bounds (fd, offset, -1);
 
 			if (!stream) {
-				close (fd);
-				goto cont;
+				tracker_file_close (fd);
+				continue;
 			}
 
 			parser = g_mime_parser_new_with_stream (stream);
 
 			if (!parser) {
 				g_object_unref (stream);
-				goto cont;
+				continue;
 			}
 
 			g_mime_parser_set_scan_from (parser, FALSE);
@@ -354,7 +352,7 @@ perform_set (TrackerEvolutionIndexer *object,
 			if (!message) {
 				g_object_unref (parser);
 				g_object_unref (stream);
-				goto cont;
+				continue;
 			}
 
 			g_mime_message_foreach_part (message,
@@ -364,14 +362,14 @@ perform_set (TrackerEvolutionIndexer *object,
 			orig_text = g_mime_message_get_body (message, TRUE, &is_html);
 
 			if (orig_text) {
-
 				encoding = get_object_encoding (GMIME_OBJECT (message));
 
 				if (encoding) {
 					text = g_convert (text, -1, "utf8", encoding, NULL, NULL, NULL);
 					g_free (orig_text);
-				} else
+				} else {
 					text = orig_text;
+				}
 
 				tracker_data_insert_statement (subject, 
 							       METADATA_EMAIL_TEXT, 
@@ -390,11 +388,12 @@ perform_set (TrackerEvolutionIndexer *object,
 		if (g_strcmp0 (predicates[i], TRACKER_EVOLUTION_PREDICATE_TAG) == 0) {
 			gchar *key, *value;
 
-			if (!values[i] || strlen (values[i]) < 1)
-				goto cont;
+			if (tracker_is_empty_string (values[i])) {
+				continue;
+			}
 
 			key = g_strdup (values[i]);
-			value = strchr (key, '=');
+			value = g_utf8_strchr (key, -1, '=');
 
 			if (value) {
 				*value = '\0';
@@ -481,18 +480,16 @@ perform_set (TrackerEvolutionIndexer *object,
 			g_free (email_uri);
 			g_free (email);
 		}
-
-		cont:
-
-		i++;
 	}
 
 }
 
 static void 
 perform_unset (TrackerEvolutionIndexer *object, 
-	       const gchar *subject)
+	       const gchar             *subject)
 {
+	g_message ("Evolution Plugin is deleting subject:'%s'", subject);
+
 	tracker_data_delete_resource (subject); 
 }
 
@@ -501,6 +498,7 @@ perform_cleanup (TrackerEvolutionIndexer *object)
 {
 	GError *error = NULL;
 
+	g_message ("Evolution Plugin is deleting all items");
 	tracker_data_update_sparql ("DELETE { ?s ?p ?o } WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }", &error);
 
 	if (error) {
@@ -512,22 +510,22 @@ perform_cleanup (TrackerEvolutionIndexer *object)
 static void
 set_stored_last_modseq (guint last_modseq)
 {
+	g_message ("Evolution Plugin is setting last modseq to:%d", last_modseq);
 	tracker_data_manager_set_db_option_int ("EvolutionLastModseq", (gint) last_modseq);
 }
 
 void
 tracker_evolution_indexer_set (TrackerEvolutionIndexer *object, 
-			       const gchar *subject, 
-			       const GStrv predicates,
-			       const GStrv values,
-			       const guint modseq,
-			       DBusGMethodInvocation *context,
-			       GError *derror)
+			       const gchar             *subject, 
+			       const GStrv              predicates,
+			       const GStrv              values,
+			       const guint              modseq,
+			       DBusGMethodInvocation   *context,
+			       GError                  *derror)
 {
 	dbus_async_return_if_fail (subject != NULL, context);
 
 	if (predicates && values) {
-
 		dbus_async_return_if_fail (g_strv_length (predicates) == 
 					   g_strv_length (values), context);
 
@@ -541,15 +539,15 @@ tracker_evolution_indexer_set (TrackerEvolutionIndexer *object,
 
 void
 tracker_evolution_indexer_set_many (TrackerEvolutionIndexer *object, 
-				    const GStrv subjects, 
-				    const GPtrArray *predicates,
-				    const GPtrArray *values,
-				    const guint modseq,
-				    DBusGMethodInvocation *context,
-				    GError *derror)
+				    const GStrv              subjects, 
+				    const GPtrArray         *predicates,
+				    const GPtrArray         *values,
+				    const guint              modseq,
+				    DBusGMethodInvocation   *context,
+				    GError                  *derror)
 {
 	guint len;
-	guint i = 0, amount = 0;
+	guint i, amount = 0;
 
 	dbus_async_return_if_fail (subjects != NULL, context);
 	dbus_async_return_if_fail (predicates != NULL, context);
@@ -562,7 +560,7 @@ tracker_evolution_indexer_set_many (TrackerEvolutionIndexer *object,
 
 	tracker_data_begin_transaction ();
 
-	while (subjects[i] != NULL) {
+	for (i = 0; subjects[i] != NULL; i++) {
 		GStrv preds = g_ptr_array_index (predicates, i);
 		GStrv vals = g_ptr_array_index (values, i);
 
@@ -575,8 +573,6 @@ tracker_evolution_indexer_set_many (TrackerEvolutionIndexer *object,
 			tracker_data_begin_transaction ();
 			amount = 0;
 		}
-
-		i++;
 	}
 
 	set_stored_last_modseq (modseq);
@@ -588,19 +584,18 @@ tracker_evolution_indexer_set_many (TrackerEvolutionIndexer *object,
 
 void
 tracker_evolution_indexer_unset_many (TrackerEvolutionIndexer *object, 
-				      const GStrv subjects, 
-				      const guint modseq,
-				      DBusGMethodInvocation *context,
-				      GError *derror)
+				      const GStrv              subjects, 
+				      const guint              modseq,
+				      DBusGMethodInvocation   *context,
+				      GError                  *derror)
 {
-	guint i = 0, amount = 0;
+	guint i, amount = 0;
 
 	dbus_async_return_if_fail (subjects != NULL, context);
 
 	tracker_data_begin_transaction ();
 
-	while (subjects[i] != NULL) {
-
+	for (i = 0; subjects[i]; i++) {
 		perform_unset (object, subjects[i]);
 
 		amount++;
@@ -610,8 +605,6 @@ tracker_evolution_indexer_unset_many (TrackerEvolutionIndexer *object,
 			tracker_data_begin_transaction ();
 			amount = 0;
 		}
-
-		i++;
 	}
 
 	set_stored_last_modseq (modseq);
@@ -623,10 +616,10 @@ tracker_evolution_indexer_unset_many (TrackerEvolutionIndexer *object,
 
 void
 tracker_evolution_indexer_unset (TrackerEvolutionIndexer *object, 
-				 const gchar *subject, 
-				 const guint modseq,
-				 DBusGMethodInvocation *context,
-				 GError *derror)
+				 const gchar             *subject, 
+				 const guint              modseq,
+				 DBusGMethodInvocation   *context,
+				 GError                  *derror)
 {
 	dbus_async_return_if_fail (subject != NULL, context);
 
@@ -637,12 +630,11 @@ tracker_evolution_indexer_unset (TrackerEvolutionIndexer *object,
 
 void
 tracker_evolution_indexer_cleanup (TrackerEvolutionIndexer *object, 
-				   const guint modseq,
-				   DBusGMethodInvocation *context,
-				   GError *derror)
+				   const guint              modseq,
+				   DBusGMethodInvocation   *context,
+				   GError                  *derror)
 {
 	perform_cleanup (object);
-
 	set_stored_last_modseq (modseq);
 
 	dbus_g_method_return (context);
@@ -654,6 +646,8 @@ tracker_push_module_init (TrackerConfig *config)
 	GError *error = NULL;
 	DBusGConnection *connection;
 
+	g_message ("Evolution Plugin is initializing");
+
 	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
 
 	if (!error) {
@@ -676,6 +670,9 @@ tracker_push_module_init (TrackerConfig *config)
 void
 tracker_push_module_shutdown (void)
 {
-	if (idx_indexer)
+	g_message ("Evolution Plugin is shutting down");
+
+	if (idx_indexer) {
 		g_object_unref (idx_indexer);
+	}
 }
diff --git a/src/plugins/kmail/Makefile.am b/src/plugins/kmail/Makefile.am
index 5a3e5e9..d64a95a 100644
--- a/src/plugins/kmail/Makefile.am
+++ b/src/plugins/kmail/Makefile.am
@@ -3,6 +3,7 @@ include $(top_srcdir)/Makefile.decl
 INCLUDES = -I$(top_srcdir)/src						\
 	-DGETTEXT_PACKAGE="\"$(GETTEXT_PACKAGE)\""			\
 	-DLOCALEDIR="\"$(localedir)\""					\
+	-DG_LOG_DOMAIN=\"Tracker\"					\
 	-DTRACKER_COMPILATION						\
 	$(WARN_CFLAGS)							\
 	$(DBUS_CFLAGS)							\
diff --git a/src/plugins/rss/Makefile.am b/src/plugins/rss/Makefile.am
index 712040d..1f26c1b 100644
--- a/src/plugins/rss/Makefile.am
+++ b/src/plugins/rss/Makefile.am
@@ -3,6 +3,7 @@ include $(top_srcdir)/Makefile.decl
 INCLUDES = -I$(top_srcdir)/src						\
 	-DGETTEXT_PACKAGE="\"$(GETTEXT_PACKAGE)\""			\
 	-DLOCALEDIR="\"$(localedir)\""					\
+	-DG_LOG_DOMAIN=\"Tracker\"					\
 	-DTRACKER_COMPILATION						\
 	$(WARN_CFLAGS)							\
 	$(DBUS_CFLAGS)							\



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