[tracker/pushplugin] Restyling, several bugfixes, please squash this



commit 21c174d1c9555bcedbf794b40b03c7f9c038cf8e
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Sep 21 16:20:00 2009 +0200

    Restyling, several bugfixes, please squash this

 src/plugins/evolution/tracker-evolution-plugin.c |  543 ++++++++++++----------
 1 files changed, 293 insertions(+), 250 deletions(-)
---
diff --git a/src/plugins/evolution/tracker-evolution-plugin.c b/src/plugins/evolution/tracker-evolution-plugin.c
index 13e9eab..6aaa9d5 100644
--- a/src/plugins/evolution/tracker-evolution-plugin.c
+++ b/src/plugins/evolution/tracker-evolution-plugin.c
@@ -44,6 +44,20 @@
 #include <camel/camel-db.h>
 #include <camel/camel-offline-store.h>
 #include <camel/camel-session.h>
+#include <camel/camel-url.h>
+#include <camel/camel-stream.h>
+#include <camel/camel-stream-mem.h>
+#include <camel/camel-multipart.h>
+#include <camel/camel-multipart-encrypted.h>
+#include <camel/camel-multipart-signed.h>
+#include <camel/camel-medium.h>
+#include <camel/camel-gpg-context.h>
+#include <camel/camel-smime-context.h>
+#include <camel/camel-string-utils.h>
+#include <camel/camel-stream-filter.h>
+#include <camel/camel-stream-null.h>
+#include <camel/camel-mime-filter-charset.h>
+#include <camel/camel-mime-filter-windows.h>
 
 #include <mail/mail-config.h>
 #include <mail/mail-session.h>
@@ -74,18 +88,17 @@
  * reads, never writes). We hope that's sufficient for not having to get our
  * code involved in Camel's cruel inneryard of having to lock the db_r ptr. */
 
-#define TRACKER_SERVICE			"org.freedesktop.Tracker1"
-
-#define MAX_BEFORE_SEND 50
-#define NIE_DATASOURCE 			       TRACKER_NIE_PREFIX "DataSource"
-#define NIE_DATASOURCE_P 		       TRACKER_NIE_PREFIX "dataSource"
+#define MAX_BEFORE_SEND			50
+#define QUEUED_SETS_PER_MAINLOOP 	2
 
-#define RDF_PREFIX	TRACKER_RDF_PREFIX
-#define NMO_PREFIX	TRACKER_NMO_PREFIX
-#define NCO_PREFIX	TRACKER_NCO_PREFIX
-#define NAO_PREFIX	TRACKER_NAO_PREFIX
+#define TRACKER_SERVICE			"org.freedesktop.Tracker1"
 
-#define DATASOURCE_URN			       "urn:nepomuk:datasource:1cb1eb90-1241-11de-8c30-0800200c9a66"
+#define NIE_DATASOURCE			TRACKER_NIE_PREFIX "DataSource"
+#define RDF_PREFIX			TRACKER_RDF_PREFIX
+#define NMO_PREFIX			TRACKER_NMO_PREFIX
+#define NCO_PREFIX			TRACKER_NCO_PREFIX
+#define NAO_PREFIX			TRACKER_NAO_PREFIX
+#define DATASOURCE_URN			"urn:nepomuk:datasource:1cb1eb90-1241-11de-8c30-0800200c9a66"
 
 G_DEFINE_TYPE (TrackerEvolutionPlugin, tracker_evolution_plugin, G_TYPE_OBJECT)
 
@@ -148,14 +161,26 @@ typedef struct {
 	GHashTable *registered_stores;
 	GList *registered_clients;
 	EAccountList *accounts;
-	DBusGConnection *connection;
 } TrackerEvolutionPluginPrivate;
 
+typedef struct {
+	TrackerSparqlBuilder *sparql;
+	TrackerEvolutionPlugin *self;
+} QueuedSet;
+
+typedef struct {
+	IntroductionInfo *intro_info;
+	CamelStore *store;
+	CamelDB *cdb_r;
+	CamelFolderInfo *iter;
+} TryAgainInfo;
+
 enum {
 	PROP_0,
 	PROP_CONNECTION
 };
 
+static GQueue *many_queue = NULL;
 static DBusGProxy *dbus_proxy = NULL;
 static TrackerEvolutionPlugin *manager = NULL;
 static GStaticRecMutex glock = G_STATIC_REC_MUTEX_INIT;
@@ -167,8 +192,57 @@ static void register_account (TrackerEvolutionPlugin *self, EAccount *account);
 static void unregister_account (TrackerEvolutionPlugin *self, EAccount *account);
 int e_plugin_lib_enable (EPluginLib *ep, int enable);
 
-
 /* First a bunch of helper functions. */
+#if 0
+static ssize_t
+camel_stream_format_text (CamelDataWrapper *dw, CamelStream *stream)
+{
+	CamelStreamFilter *filter_stream;
+	CamelMimeFilterCharset *filter;
+	const char *charset = "UTF-8"; /* I default to UTF-8, like it or not */
+	CamelMimeFilterWindows *windows = NULL;
+	ssize_t bytes = -1;
+
+	if (dw->mime_type && (charset = camel_content_type_param 
+			(dw->mime_type, "charset")) && 
+		g_ascii_strncasecmp(charset, "iso-8859-", 9) == 0) 
+	{
+		CamelStream *null;
+
+		/* Since a few Windows mailers like to claim they sent
+		* out iso-8859-# encoded text when they really sent
+		* out windows-cp125#, do some simple sanity checking
+		* before we move on... */
+
+		null = camel_stream_null_new();
+		filter_stream = camel_stream_filter_new_with_stream(null);
+		camel_object_unref(null);
+		windows = (CamelMimeFilterWindows *)camel_mime_filter_windows_new(charset);
+		camel_stream_filter_add (filter_stream, (CamelMimeFilter *)windows);
+		camel_data_wrapper_decode_to_stream (dw, (CamelStream *)filter_stream);
+		camel_stream_flush ((CamelStream *)filter_stream);
+		camel_object_unref (filter_stream);
+		charset = camel_mime_filter_windows_real_charset (windows);
+	}
+
+	filter_stream = camel_stream_filter_new_with_stream (stream);
+
+	if ((filter = camel_mime_filter_charset_new_convert (charset, "UTF-8"))) {
+		camel_stream_filter_add (filter_stream, (CamelMimeFilter *) filter);
+		camel_object_unref (filter);
+	}
+
+	bytes = camel_data_wrapper_decode_to_stream (dw, (CamelStream *)filter_stream);
+	camel_stream_flush ((CamelStream *)filter_stream);
+	camel_object_unref (filter_stream);
+
+	if (windows)
+		camel_object_unref(windows);
+
+	return bytes;
+}
+
+#endif
 
 static void
 get_email_and_fullname (const gchar *line, gchar **email, gchar **fullname)
@@ -196,29 +270,6 @@ get_email_and_fullname (const gchar *line, gchar **email, gchar **fullname)
 	}
 }
 
-static GList *
-get_recipient_list (const gchar *str)
-{
-	GList *list = NULL;
-	gchar **arr;
-	gint i;
-
-	if (!str) {
-		return NULL;
-	}
-
-	arr = g_strsplit (str, ",", -1);
-
-	for (i = 0; arr[i]; i++) {
-		g_strstrip (arr[i]);
-		list = g_list_prepend (list, g_strdup (arr[i]));
-	}
-
-	g_strfreev (arr);
-
-	return g_list_reverse (list);
-}
-
 static void
 folder_registry_free (FolderRegistry *registry)
 {
@@ -281,7 +332,8 @@ process_fields (TrackerSparqlBuilder *sparql, gchar *uid, guint flags,
                 gchar *sent, gchar *subject, gchar *from, gchar *to, 
                 gchar *cc, gchar *size, CamelFolder *folder, gchar *uri)
 {
-	GList *list, *l;
+	gchar **arr;
+	guint i;
 
 	tracker_sparql_builder_subject_iri (sparql, DATASOURCE_URN);
 	tracker_sparql_builder_predicate (sparql, "rdf:type");
@@ -305,43 +357,55 @@ process_fields (TrackerSparqlBuilder *sparql, gchar *uid, guint flags,
 	tracker_sparql_builder_predicate (sparql, "nie:isStoredAs");
 	tracker_sparql_builder_object_iri (sparql, uri);
 
-	tracker_sparql_builder_predicate_iri (sparql, NIE_DATASOURCE_P);
+	tracker_sparql_builder_predicate (sparql, "nie:dataSource");
 	tracker_sparql_builder_object_iri (sparql, DATASOURCE_URN);
 
-//	g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_UID));
-//	g_ptr_array_add (values_temp, g_strdup (uid));
+	if (size && g_utf8_validate (size, -1, NULL)) {
+		tracker_sparql_builder_predicate (sparql, "nie:byteSize");
+		tracker_sparql_builder_object_string (sparql, size);
+	}
 
-//	g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_SEEN));
-//	g_ptr_array_add (values_temp, g_strdup ((flags & CAMEL_MESSAGE_SEEN) ? "True" : "False"));
+	if (subject && g_utf8_validate (subject, -1, NULL)) {
+		tracker_sparql_builder_predicate (sparql, "nmo:messageSubject");
+		tracker_sparql_builder_object_string (sparql, subject);
+	}
 
-//	g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_JUNK));
-//	g_ptr_array_add (values_temp, g_strdup ((flags & CAMEL_MESSAGE_JUNK) ? "True" : "False"));
+	if (sent && g_utf8_validate (sent, -1, NULL)) {
+		tracker_sparql_builder_predicate (sparql, "nmo:receivedDate");
+		tracker_sparql_builder_object_string (sparql, sent);
+	}
 
-//	g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_DELETED));
-//	g_ptr_array_add (values_temp, g_strdup ((flags & CAMEL_MESSAGE_DELETED) ? "True" : "False"));
+	tracker_sparql_builder_predicate (sparql, "nmo:isDeleted");
+	tracker_sparql_builder_object_boolean (sparql, (flags & CAMEL_MESSAGE_DELETED));
 
-//	g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_ANSWERED));
-//	g_ptr_array_add (values_temp, g_strdup ((flags & CAMEL_MESSAGE_ANSWERED) ? "True" : "False"));
+	tracker_sparql_builder_predicate (sparql, "nmo:isAnswered");
+	tracker_sparql_builder_object_boolean (sparql, (flags & CAMEL_MESSAGE_ANSWERED));
 
-//	g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_FLAGGED));
-//	g_ptr_array_add (values_temp, g_strdup ((flags & CAMEL_MESSAGE_FLAGGED) ? "True" : "False"));
+	tracker_sparql_builder_predicate (sparql, "nmo:isFlagged");
+	tracker_sparql_builder_object_boolean (sparql, (flags & CAMEL_MESSAGE_FLAGGED));
 
-//	g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_FORWARDED));
-//	g_ptr_array_add (values_temp, g_strdup ((flags & CAMEL_MESSAGE_FORWARDED) ? "True" : "False"));
+	tracker_sparql_builder_predicate (sparql, "nmo:isRead");
+	tracker_sparql_builder_object_boolean (sparql, (flags & CAMEL_MESSAGE_SEEN));
 
+	/*
+	g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_UID));
+	g_ptr_array_add (values_temp, g_strdup (uid));
 
-	if (subject && g_utf8_validate (subject, -1, NULL)) {
-		tracker_sparql_builder_subject_iri (sparql, uri);
-		tracker_sparql_builder_predicate (sparql, "nmo:messageSubject");
-		tracker_sparql_builder_object_string (sparql, subject);
-	}
+	g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_JUNK));
+	g_ptr_array_add (values_temp, g_strdup ((flags & CAMEL_MESSAGE_JUNK) ? "True" : "False"));
+
+	g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_FORWARDED));
+	g_ptr_array_add (values_temp, g_strdup ((flags & CAMEL_MESSAGE_FORWARDED) ? "True" : "False"));
+	*/
+
+	if (to && (arr = g_strsplit (to, ",", -1)) != NULL) {;
+	 for (i = 0; arr[i]; i++) {
+		g_strstrip (arr[i]);
 
-	list = get_recipient_list (to);
-	for (l = list; l; l = l->next) {
-		if (l->data && g_utf8_validate (l->data, -1, NULL)) {
+		if (arr[i] && g_utf8_validate (arr[i], -1, NULL)) {
 			gchar *email_uri, *email = NULL, *fullname = NULL;
 
-			get_email_and_fullname (l->data, &email, &fullname);
+			get_email_and_fullname (arr[i], &email, &fullname);
 
 			email_uri = tracker_uri_printf_escaped ("mailto:%s";, email); 
 
@@ -375,9 +439,9 @@ process_fields (TrackerSparqlBuilder *sparql, gchar *uid, guint flags,
 			g_free (email_uri);
 			g_free (email);
 		}
-		g_free (l->data);
+	 }
+	 g_strfreev (arr);
 	}
-	g_list_free (list);
 
 	if (from && g_utf8_validate (from, -1, NULL)) {
 		gchar *email_uri, *email = NULL, *fullname = NULL;
@@ -417,17 +481,13 @@ process_fields (TrackerSparqlBuilder *sparql, gchar *uid, guint flags,
 		g_free (email);
 	}
 
-//	if (size && g_utf8_validate (size, -1, NULL)) {
-//		g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_SIZE));
-//		g_ptr_array_add (values_temp, g_strdup (size));
-//	}
-
-	list = get_recipient_list (cc);
-	for (l = list; l; l = l->next) {
-		if (l->data && g_utf8_validate (l->data, -1, NULL)) {
+	if (cc && (arr = g_strsplit (cc, ",", -1)) != NULL) {
+	 for (i = 0; arr[i]; i++) {
+		g_strstrip (arr[i]);
+		if (arr[i] && g_utf8_validate (arr[i], -1, NULL)) {
 			gchar *email_uri, *email = NULL, *fullname = NULL;
 
-			get_email_and_fullname (l->data, &email, &fullname);
+			get_email_and_fullname (arr[i], &email, &fullname);
 
 			email_uri = tracker_uri_printf_escaped ("mailto:%s";, email); 
 
@@ -461,26 +521,66 @@ process_fields (TrackerSparqlBuilder *sparql, gchar *uid, guint flags,
 			g_free (email_uri);
 			g_free (email);
 		} 
-		g_free (l->data);
+	 }
+	 g_strfreev (arr);
 	}
-	g_list_free (list);
 
-	if (sent && g_utf8_validate (sent, -1, NULL)) {
-		tracker_sparql_builder_subject_iri (sparql, uri);
-		tracker_sparql_builder_predicate (sparql, "nmo:receivedDate");
-		tracker_sparql_builder_object_string (sparql, sent);
-	}
+#if 0
+	if (folder) {
+		gchar *filen = camel_folder_get_filename (folder, uid, NULL);
+		if (filen) {
+			if (g_file_test (filen, G_FILE_TEST_EXISTS)) {
+				CamelMimeMessage *mime = camel_folder_get_message (folder, uid, NULL);
+				if (mime) {
+					CamelDataWrapper *containee;
+					containee = camel_medium_get_content_object (CAMEL_MEDIUM (mime));
+
+					if (CAMEL_IS_MULTIPART (containee)) {
+						guint i, parts = camel_multipart_get_number (CAMEL_MULTIPART (containee));
+						for (i = 0; i < parts; i++) {
+							CamelMimePart *tpart = camel_multipart_get_part (CAMEL_MULTIPART (containee), i);
+							CamelContentType *type;
+
+							type = camel_mime_part_get_content_type (tpart);
+							if (camel_content_type_is (type, "text", "*")) {
+								CamelStream *stream = camel_stream_mem_new ();
+								CamelDataWrapper *wrapper;
+								CamelStreamMem *mem = (CamelStreamMem *) stream;
+								gssize bytes = -1;
+
+								wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (tpart));
+								if (!wrapper) {
+									wrapper = camel_data_wrapper_new (); 
+									camel_medium_set_content_object (CAMEL_MEDIUM (tpart), wrapper);
+									camel_object_unref (wrapper);
+								} 
+
+								if (wrapper->stream) {
+									camel_stream_reset (wrapper->stream);
+
+									if (camel_content_type_is (wrapper->mime_type, "text", "plain"))
+										bytes = camel_stream_format_text (wrapper, stream);
+									else
+										bytes = camel_data_wrapper_decode_to_stream (wrapper, stream);
+
+									if (bytes > 0 && g_utf8_validate ((gchar *) mem->buffer->data, -1, NULL)) {
+										tracker_sparql_builder_subject_iri (sparql, uri);
+										tracker_sparql_builder_predicate (sparql, "nie:plainTextContent");
+										tracker_sparql_builder_object_string (sparql, (gchar *) mem->buffer->data);
+									}
+								}
 
-//	if (folder) {
-//		gchar *filen = camel_folder_get_filename (folder, uid, NULL);
-//		if (filen) {
-//			if (g_file_test (filen, G_FILE_TEST_EXISTS)) {
-//				g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_FILE));
-//				g_ptr_array_add (values_temp, filen);
-//			} else
-//				g_free (filen);
-//		}
-//	}
+								camel_object_unref (stream);
+							}
+						}
+					}
+					camel_object_unref (mime);
+				}
+			}
+			g_free (filen);
+		}
+	}
+#endif
 }
 
 /* When new messages arrive to- or got deleted from the summary, called in
@@ -512,8 +612,9 @@ on_folder_summary_changed (CamelFolder *folder,
 	/* the uid_added member contains the added-to-the-summary items */
 
 	if (changes->uid_added && changes->uid_added->len > 0) {
-		for (i = 0; i < changes->uid_added->len; i++)
+		for (i = 0; i < changes->uid_added->len; i++) {
 			g_ptr_array_add (merged, changes->uid_added->pdata[i]);
+		}
 	}
 
 	/* the uid_changed member contains the changed-in-the-summary items */
@@ -530,8 +631,9 @@ on_folder_summary_changed (CamelFolder *folder,
 				}
 			}
 
-			if (!found)
+			if (!found) {
 				g_ptr_array_add (merged, changes->uid_changed->pdata[i]);
+			}
 		}
 	}
 
@@ -546,8 +648,9 @@ on_folder_summary_changed (CamelFolder *folder,
 
 			linfo = camel_folder_summary_uid (summary, merged->pdata[i]);
 
-			if (linfo)
+			if (linfo) {
 				uid = (gchar *) camel_message_info_uid (linfo);
+			}
 
 			if (linfo && uid) {
 				gchar *uri;
@@ -560,7 +663,8 @@ on_folder_summary_changed (CamelFolder *folder,
 				flags =   (guint)   camel_message_info_flags (linfo);
 
 				/* Camel returns a time_t, I think a uint64 is the best fit here */
-				sent = g_strdup_printf ("%"G_GUINT64_FORMAT, (guint64) camel_message_info_date_sent (linfo));
+				sent = g_strdup_printf ("%"G_GUINT64_FORMAT, 
+				                        (guint64) camel_message_info_date_sent (linfo));
 
 				/* Camel returns a uint32, so %u */
 				size = g_strdup_printf ("%u", camel_message_info_size (linfo));
@@ -664,15 +768,6 @@ on_folder_summary_changed (CamelFolder *folder,
 
 /* Info about this many_queue can be found in introduce_walk_folders_in_folder */
 
-#define QUEUED_SETS_PER_MAINLOOP 2
-
-typedef struct {
-	TrackerSparqlBuilder *sparql;
-	TrackerEvolutionPlugin *self;
-} QueuedSet;
-
-static GQueue *many_queue = NULL;
-
 static void
 queued_set_free (QueuedSet *queued_set)
 {
@@ -1009,8 +1104,10 @@ introduce_store_deal_with_deleted (TrackerEvolutionPlugin *self,
 	guint i, ret;
 	gchar *em_uri = em_uri_from_camel (account_uri);
 
-	query = sqlite3_mprintf ("SELECT uid, mailbox FROM Deletes WHERE modified > %" G_GUINT64_FORMAT, 
-				 info->last_checkout);
+	query = sqlite3_mprintf ("SELECT uid, mailbox "
+	                         "FROM Deletes "
+	                         "WHERE modified > %" G_GUINT64_FORMAT, 
+	                         info->last_checkout);
 
 	/* This creates a thread apparently */
 	cdb_r = camel_db_clone (store->cdb_r, NULL);
@@ -1142,7 +1239,9 @@ get_last_deleted_time (TrackerEvolutionPlugin *self)
 
 			cdb_r = camel_db_clone (store->cdb_r, NULL);
 
-			query = sqlite3_mprintf ("SELECT time FROM Deletes ORDER BY time LIMIT 1");
+			query = sqlite3_mprintf ("SELECT time "
+			                         "FROM Deletes "
+			                         "ORDER BY time LIMIT 1");
 
 			ret = sqlite3_prepare_v2 (cdb_r->db, query, -1, &stmt, NULL);
 
@@ -1198,14 +1297,17 @@ register_on_get_folder (gchar *uri, CamelFolder *folder, gpointer user_data)
 	}
 
 	hook_id = camel_object_hook_event (folder, "folder_changed", 
-					   CAMEL_CALLBACK (on_folder_summary_changed), 
-					   registry->hook_info);
+	                                   CAMEL_CALLBACK (on_folder_summary_changed), 
+	                                   registry->hook_info);
 	registry->hook_info->hook_id = hook_id;
 
-	g_hash_table_replace (priv->registered_folders, &hook_id, 
-			      registry);
-	g_hash_table_replace (priv->cached_folders, g_strdup (iter->full_name), 
-			      folder);
+	g_hash_table_replace (priv->registered_folders,
+	                      &hook_id, 
+	                      registry);
+
+	g_hash_table_replace (priv->cached_folders, 
+	                      g_strdup (iter->full_name), 
+	                      folder);
 
 	not_ready:
 
@@ -1233,11 +1335,12 @@ register_walk_folders_in_folder (TrackerEvolutionPlugin *self,
 
 	if (!priv->registered_folders) {
 		priv->registered_folders = g_hash_table_new_full (g_int_hash, g_int_equal,
-								  (GDestroyNotify) NULL,
-								  (GDestroyNotify) folder_registry_free);
+		                                                  (GDestroyNotify) NULL,
+		                                                  (GDestroyNotify) folder_registry_free);
+
 		priv->cached_folders = g_hash_table_new_full (g_str_hash, g_str_equal,
-							      (GDestroyNotify) g_free,
-							      (GDestroyNotify) NULL);
+		                                              (GDestroyNotify) g_free,
+		                                              (GDestroyNotify) NULL);
 	}
 
 	g_static_rec_mutex_unlock (priv->mutex);
@@ -1257,11 +1360,12 @@ register_walk_folders_in_folder (TrackerEvolutionPlugin *self,
 		 * integrated with the Evolution UI application */
 
 		mail_get_folder (iter->uri, 0, register_on_get_folder, info, 
-				 mail_msg_unordered_push);
+		                 mail_msg_unordered_push);
 
 		if (iter->child) {
-			register_walk_folders_in_folder (self, iter->child, store, 
-							 account_uri);
+			register_walk_folders_in_folder (self, iter->child, 
+			                                 store, 
+			                                 account_uri);
 		}
 
 		iter = iter->next;
@@ -1311,11 +1415,12 @@ unregister_on_get_folder (gchar *uri, CamelFolder *folder, gpointer user_data)
 	g_object_unref (info->self);
 	g_free (info);
 }
+
 static void
 unregister_walk_folders_in_folder (TrackerEvolutionPlugin *self, 
-				   CamelFolderInfo *titer, 
-				   CamelStore *store, 
-				   gchar *account_uri)
+                                   CamelFolderInfo *titer, 
+                                   CamelStore *store, 
+                                   gchar *account_uri)
 {
 	/* Recursively walks all the folders in store */
 
@@ -1330,11 +1435,12 @@ unregister_walk_folders_in_folder (TrackerEvolutionPlugin *self,
 		 * integrated with the Evolution UI application */
 
 		mail_get_folder (titer->uri, 0, unregister_on_get_folder, info, 
-				 mail_msg_unordered_push);
+		                 mail_msg_unordered_push);
 
 		if (titer->child) {
-			unregister_walk_folders_in_folder (self, titer->child, store, 
-							   account_uri);
+			unregister_walk_folders_in_folder (self, titer->child,
+			                                   store, 
+			                                   account_uri);
 		}
 
 		titer = titer->next;
@@ -1359,13 +1465,6 @@ client_registry_info_copy (ClientRegistry *info)
 
 /* For info about this try-again stuff, look at on_got_folderinfo_introduce */
 
-typedef struct {
-	IntroductionInfo *intro_info;
-	CamelStore *store;
-	CamelDB *cdb_r;
-	CamelFolderInfo *iter;
-} TryAgainInfo;
-
 static gboolean
 try_again (gpointer user_data)
 {
@@ -1374,11 +1473,11 @@ try_again (gpointer user_data)
 		IntroductionInfo *intro_info = info->intro_info;
 
 		introduce_walk_folders_in_folder (intro_info->self, 
-						  info->iter,
-						  info->store, 
-						  info->cdb_r,
-						  intro_info->account_uri, 
-						  intro_info->info);
+		                                  info->iter,
+		                                  info->store, 
+		                                  info->cdb_r,
+		                                  intro_info->account_uri, 
+		                                  intro_info->info);
 
 		return FALSE;
 	}
@@ -1405,8 +1504,8 @@ try_again_d (gpointer user_data)
 
 static gboolean
 on_got_folderinfo_introduce (CamelStore *store, 
-			     CamelFolderInfo *iter, 
-			     void *data)
+                             CamelFolderInfo *iter, 
+                             void *data)
 {
 	TryAgainInfo *info = g_new0 (TryAgainInfo, 1);
 
@@ -1438,8 +1537,8 @@ on_got_folderinfo_introduce (CamelStore *store,
 
 	if (register_count != 0) {
 		g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, 10,
-					    try_again, info, 
-					    try_again_d);
+		                            try_again, info, 
+		                            try_again_d);
 	} else {
 		try_again (info);
 		try_again_d (info);
@@ -1450,8 +1549,8 @@ on_got_folderinfo_introduce (CamelStore *store,
 
 static void
 introduce_account_to (TrackerEvolutionPlugin *self, 
-		      EAccount *account, 
-		      ClientRegistry *info)
+                      EAccount *account, 
+                      ClientRegistry *info)
 {
 	CamelProvider *provider;
 	CamelStore *store;
@@ -1500,7 +1599,7 @@ introduce_account_to (TrackerEvolutionPlugin *self,
 
 static void
 introduce_account_to_all (TrackerEvolutionPlugin *self, 
-			  EAccount *account)
+                          EAccount *account)
 {
 	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (self);
 	GList *copy = priv->registered_clients;
@@ -1515,13 +1614,14 @@ introduce_account_to_all (TrackerEvolutionPlugin *self,
 
 static void
 introduce_accounts_to (TrackerEvolutionPlugin *self, 
-		       ClientRegistry *info)
+                       ClientRegistry *info)
 {
 	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (self);
 	EIterator *it;
 
-	for (it = e_list_get_iterator (E_LIST (priv->accounts)); e_iterator_is_valid (it); e_iterator_next (it))
+	for (it = e_list_get_iterator (E_LIST (priv->accounts)); e_iterator_is_valid (it); e_iterator_next (it)) {
 		introduce_account_to (self, (EAccount *) e_iterator_get (it), info);
+	}
 
 	g_object_unref (it);
 }
@@ -1541,7 +1641,8 @@ register_client (TrackerEvolutionPlugin *self)
 		return;
 	}
 
-	query = "SELECT ?c WHERE { <" DATASOURCE_URN "> nie:contentLastModified ?c }";
+	query = "SELECT ?c "
+		"WHERE { <" DATASOURCE_URN "> nie:contentLastModified ?c }";
 
 	results = tracker_resources_sparql_query (client, query, &error);
 
@@ -1570,7 +1671,8 @@ register_client (TrackerEvolutionPlugin *self)
 
 	if (info->last_checkout < too_old) {
 
-		send_sparql_update ("DELETE { ?s a rdfs:Resource } WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }");
+		send_sparql_update ("DELETE { ?s a rdfs:Resource } "
+		                    "WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }");
 		send_sparql_commit (FALSE);
 
 		info->last_checkout = 0;
@@ -1587,7 +1689,7 @@ register_client (TrackerEvolutionPlugin *self)
 
 static void
 on_folder_created (CamelStore *store, void *event_data, 
-		   StoreRegistry *registry)
+                   StoreRegistry *registry)
 {
 	unregister_account (registry->self, registry->account);
 	register_account (registry->self, registry->account);
@@ -1596,8 +1698,8 @@ on_folder_created (CamelStore *store, void *event_data,
 
 static void
 on_folder_deleted (CamelStore *store, 
-		   void *event_data, 
-		   StoreRegistry *registry)
+                   void *event_data, 
+                   StoreRegistry *registry)
 {
 	unregister_account (registry->self, registry->account);
 	register_account (registry->self, registry->account);
@@ -1606,8 +1708,8 @@ on_folder_deleted (CamelStore *store,
 
 static void
 on_folder_renamed (CamelStore *store, 
-		   CamelRenameInfo *info, 
-		   StoreRegistry *registry)
+                   CamelRenameInfo *info, 
+                   StoreRegistry *registry)
 {
 	unregister_account (registry->self, registry->account);
 	register_account (registry->self, registry->account);
@@ -1616,8 +1718,8 @@ on_folder_renamed (CamelStore *store,
 
 static StoreRegistry*
 store_registry_new (gpointer co, 
-		    EAccount *account, 
-		    TrackerEvolutionPlugin *self)
+                    EAccount *account, 
+                    TrackerEvolutionPlugin *self)
 {
 	StoreRegistry *registry = g_slice_new (StoreRegistry);
 
@@ -1640,8 +1742,8 @@ store_registry_free (StoreRegistry *registry)
 
 static gboolean
 on_got_folderinfo_register (CamelStore *store, 
-			    CamelFolderInfo *iter, 
-			    void *data)
+                            CamelFolderInfo *iter, 
+                            void *data)
 {
 	RegisterInfo *reg_info = data;
 	TrackerEvolutionPlugin *self = reg_info->self;
@@ -1657,29 +1759,29 @@ on_got_folderinfo_register (CamelStore *store,
 
 	if (!priv->registered_stores) {
 		priv->registered_stores = g_hash_table_new_full (g_int_hash, g_int_equal,
-								 (GDestroyNotify) NULL,
-								 (GDestroyNotify) store_registry_free);
+		                                                 (GDestroyNotify) NULL,
+		                                                 (GDestroyNotify) store_registry_free);
 	}
 
 	/* Hook up catching folder changes in the store */
 	registry = store_registry_new (store, account, self);
 	hook_id = camel_object_hook_event (store, "folder_created", 
-					   CAMEL_CALLBACK (on_folder_created), 
-					   registry);
+	                                   CAMEL_CALLBACK (on_folder_created), 
+	                                   registry);
 	registry->hook_id = hook_id;
 	g_hash_table_replace (priv->registered_stores, &hook_id, registry);
 
 	registry = store_registry_new (store, account, self);
 	hook_id = camel_object_hook_event (store, "folder_renamed", 
-					   CAMEL_CALLBACK (on_folder_renamed), 
-					   registry);
+	                                   CAMEL_CALLBACK (on_folder_renamed), 
+	                                   registry);
 	registry->hook_id = hook_id;
 	g_hash_table_replace (priv->registered_stores, &hook_id, registry);
 
 	registry = store_registry_new (store, account, self);
 	hook_id = camel_object_hook_event (store, "folder_deleted", 
-					   CAMEL_CALLBACK (on_folder_deleted), 
-					   registry);
+	                                   CAMEL_CALLBACK (on_folder_deleted), 
+	                                   registry);
 	registry->hook_id = hook_id;
 	g_hash_table_replace (priv->registered_stores, &hook_id, registry);
 
@@ -1698,7 +1800,7 @@ on_got_folderinfo_register (CamelStore *store,
 
 static void
 register_account (TrackerEvolutionPlugin *self,
-		  EAccount *account)
+                  EAccount *account)
 {
 	CamelProvider *provider;
 	CamelStore *store;
@@ -1737,8 +1839,8 @@ register_account (TrackerEvolutionPlugin *self,
 
 static gboolean
 on_got_folderinfo_unregister (CamelStore *store, 
-			      CamelFolderInfo *titer,
-			      void *data)
+                              CamelFolderInfo *titer,
+                              void *data)
 {
 	RegisterInfo *reg_info = data;
 	TrackerEvolutionPlugin *self = reg_info->self;
@@ -1771,7 +1873,7 @@ on_got_folderinfo_unregister (CamelStore *store,
 
 static void
 unregister_account (TrackerEvolutionPlugin *self,
-		    EAccount *account)
+                    EAccount *account)
 {
 	CamelProvider *provider;
 	CamelStore *store;
@@ -1808,8 +1910,8 @@ unregister_account (TrackerEvolutionPlugin *self,
 
 static void
 on_account_added (EAccountList *list, 
-		  EAccount *account, 
-		  TrackerEvolutionPlugin *self)
+                  EAccount *account, 
+                  TrackerEvolutionPlugin *self)
 {
 	register_account (self, account);
 	introduce_account_to_all (self, account);
@@ -1817,16 +1919,16 @@ on_account_added (EAccountList *list,
 
 static void
 on_account_removed (EAccountList *list,
-		    EAccount *account,
-		    TrackerEvolutionPlugin *self)
+                    EAccount *account,
+                    TrackerEvolutionPlugin *self)
 {
 	unregister_account (self, account);
 }
 
 static void
 on_account_changed (EAccountList *list, 
-		    EAccount *account,
-		    TrackerEvolutionPlugin *self)
+                    EAccount *account,
+                    TrackerEvolutionPlugin *self)
 {
 	unregister_account (self, account);
 	register_account (self, account);
@@ -1850,16 +1952,16 @@ disable_plugin (void)
 
 static void
 list_names_reply_cb (DBusGProxy     *proxy,
-		     DBusGProxyCall *call,
-		     gpointer        user_data)
+                     DBusGProxyCall *call,
+                     gpointer        user_data)
 {
 	GError *error = NULL;
 	GStrv names = NULL;
 	guint i = 0;
 
 	dbus_g_proxy_end_call (proxy, call, &error,
-			       G_TYPE_STRV, &names,
-			       G_TYPE_INVALID);
+	                       G_TYPE_STRV, &names,
+	                       G_TYPE_INVALID);
 
 	if (error) {
 		g_warning ("%s", error->message);
@@ -1927,25 +2029,25 @@ enable_plugin (void)
 	client = tracker_connect (FALSE, G_MAXINT);
 
 	manager = g_object_new (TRACKER_TYPE_EVOLUTION_PLUGIN, 
-				"connection", connection, NULL);
+	                        "connection", connection, NULL);
 
 	dbus_proxy = dbus_g_proxy_new_for_name (connection, 
-						DBUS_SERVICE_DBUS,
-						DBUS_PATH_DBUS,
-						DBUS_INTERFACE_DBUS);
+	                                        DBUS_SERVICE_DBUS,
+	                                        DBUS_PATH_DBUS,
+	                                        DBUS_INTERFACE_DBUS);
 
 	dbus_g_proxy_add_signal (dbus_proxy, "NameOwnerChanged",
-				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
-				 G_TYPE_INVALID);
+	                         G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
+	                         G_TYPE_INVALID);
 
 	dbus_g_proxy_connect_signal (dbus_proxy, "NameOwnerChanged",
-				     G_CALLBACK (name_owner_changed_cb),
-				     NULL, NULL);
+	                             G_CALLBACK (name_owner_changed_cb),
+	                             NULL, NULL);
 
 	dbus_g_proxy_begin_call (dbus_proxy, "ListNames",
-				 list_names_reply_cb, NULL, NULL,
-				 G_TYPE_INVALID,
-				 G_TYPE_INVALID);
+	                         list_names_reply_cb, NULL, NULL,
+	                         G_TYPE_INVALID,
+	                         G_TYPE_INVALID);
 
 	error_handler:
 
@@ -1994,9 +2096,6 @@ tracker_evolution_plugin_finalize (GObject *plugin)
 
 	g_object_unref (priv->accounts);
 
-	if (priv->connection)
-		dbus_g_connection_unref (priv->connection);
-
 	g_static_rec_mutex_unlock (priv->mutex);
 
 	g_slice_free (GStaticRecMutex, priv->mutex);
@@ -2004,52 +2103,7 @@ tracker_evolution_plugin_finalize (GObject *plugin)
 	G_OBJECT_CLASS (tracker_evolution_plugin_parent_class)->finalize (plugin);
 }
 
-static void 
-tracker_evolution_plugin_set_connection (TrackerEvolutionPlugin *plugin, 
-					 DBusGConnection *connection)
-{
-	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (plugin);
-
-	if (priv->connection)
-		dbus_g_connection_unref (priv->connection);
 
-	priv->connection = dbus_g_connection_ref (connection);
-}
-
-static void
-tracker_evolution_plugin_set_property (GObject     *plugin,
-				      guint         prop_id,
-				      const GValue *value,
-				      GParamSpec   *pspec)
-{
-	switch (prop_id) {
-	case PROP_CONNECTION:
-		tracker_evolution_plugin_set_connection (TRACKER_EVOLUTION_PLUGIN (plugin),
-							 g_value_get_pointer (value));
-		break;
-	default:
-		G_OBJECT_WARN_INVALID_PROPERTY_ID (plugin, prop_id, pspec);
-	}
-}
-
-static void
-tracker_evolution_plugin_get_property (GObject   *plugin,
-				      guint       prop_id,
-				      GValue     *value,
-				      GParamSpec *pspec)
-{
-	TrackerEvolutionPluginPrivate *priv;
-
-	priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (plugin);
-
-	switch (prop_id) {
-	case PROP_CONNECTION:
-		g_value_set_pointer (value, priv->connection);
-		break;
-	default:
-		G_OBJECT_WARN_INVALID_PROPERTY_ID (plugin, prop_id, pspec);
-	}
-}
 
 static void
 tracker_evolution_plugin_class_init (TrackerEvolutionPluginClass *klass)
@@ -2057,16 +2111,6 @@ tracker_evolution_plugin_class_init (TrackerEvolutionPluginClass *klass)
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
 	object_class->finalize = tracker_evolution_plugin_finalize;
-	object_class->set_property = tracker_evolution_plugin_set_property;
-	object_class->get_property = tracker_evolution_plugin_get_property;
-
-	g_object_class_install_property (object_class,
-					 PROP_CONNECTION,
-					 g_param_spec_pointer ("connection",
-							       "DBus connection",
-							       "DBus connection",
-							       G_PARAM_READWRITE |
-							       G_PARAM_CONSTRUCT));
 
 	g_type_class_add_private (object_class, sizeof (TrackerEvolutionPluginPrivate));
 }
@@ -2082,7 +2126,6 @@ tracker_evolution_plugin_init (TrackerEvolutionPlugin *plugin)
 
 	g_static_rec_mutex_lock (priv->mutex);
 
-
 	priv->cached_folders = NULL;
 	priv->registered_folders = NULL;
 	priv->registered_stores = NULL;
@@ -2098,9 +2141,9 @@ tracker_evolution_plugin_init (TrackerEvolutionPlugin *plugin)
 	g_object_unref (it);
 
 	g_signal_connect (priv->accounts, "account-added", 
-			  G_CALLBACK (on_account_added), plugin);
+	                  G_CALLBACK (on_account_added), plugin);
 	g_signal_connect (priv->accounts, "account-removed", 
-			  G_CALLBACK (on_account_removed), plugin);
+	                  G_CALLBACK (on_account_removed), plugin);
 	g_signal_connect (priv->accounts, "account-changed", 
-			  G_CALLBACK (on_account_changed), plugin);
+	                  G_CALLBACK (on_account_changed), plugin);
 }



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