[tracker/pushplugin] Refactoring the Evolution push plugin to use TrackerMiner API
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/pushplugin] Refactoring the Evolution push plugin to use TrackerMiner API
- Date: Thu, 17 Sep 2009 15:53:13 +0000 (UTC)
commit 15fca94bc9d5239a325dc1ba74f4f01ec6b86c1a
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Sep 17 17:51:24 2009 +0200
Refactoring the Evolution push plugin to use TrackerMiner API
This branch will be rebased
This commit will be squashed
src/libtracker-common/tracker-sparql-builder.vala | 5 +
src/plugins/evolution/Makefile.am | 8 +-
src/plugins/evolution/tracker-evolution-plugin.c | 943 ++++++++++----------
src/plugins/evolution/tracker-evolution-plugin.h | 5 -
src/plugins/evolution/tracker-evolution-plugin.xml | 11 -
5 files changed, 500 insertions(+), 472 deletions(-)
---
diff --git a/src/libtracker-common/tracker-sparql-builder.vala b/src/libtracker-common/tracker-sparql-builder.vala
index 765d866..2892f1f 100644
--- a/src/libtracker-common/tracker-sparql-builder.vala
+++ b/src/libtracker-common/tracker-sparql-builder.vala
@@ -45,6 +45,11 @@ public class Tracker.SparqlBuilder : Object {
states += State.UPDATE;
}
+ public void drop_graph (string iri)
+ {
+ str.append ("DROP GRAPH <%s>\n".printf (iri));
+ }
+
public void insert_open ()
requires (state == State.UPDATE)
{
diff --git a/src/plugins/evolution/Makefile.am b/src/plugins/evolution/Makefile.am
index 4a91918..a10dfda 100644
--- a/src/plugins/evolution/Makefile.am
+++ b/src/plugins/evolution/Makefile.am
@@ -54,17 +54,17 @@ libtracker_module_evolution_daemon_module_la_LIBADD = \
liborg_freedesktop_Tracker_evolution_plugin_la_SOURCES = \
tracker-evolution-plugin.c \
tracker-evolution-plugin.h \
- tracker-evolution-common.h \
- tracker-evolution-plugin-glue.h
+ tracker-evolution-common.h
liborg_freedesktop_Tracker_evolution_plugin_la_LDFLAGS = -module -avoid-version
-liborg_freedesktop_Tracker_evolution_plugin_la_LDLIBS = \
+liborg_freedesktop_Tracker_evolution_plugin_la_LIBADD = \
+ $(top_builddir)/src/libtracker-client/libtracker-client- TRACKER_API_VERSION@.la \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
$(EVOLUTION_PLUGIN_LIBS) \
$(DBUS_LIBS) \
$(GCOV_LIBS)
dbus_sources = \
- tracker-evolution-plugin-glue.h \
tracker-evolution-registrar-glue.h
%-glue.h: %.xml
diff --git a/src/plugins/evolution/tracker-evolution-plugin.c b/src/plugins/evolution/tracker-evolution-plugin.c
index 5ea9a8a..e4fd627 100644
--- a/src/plugins/evolution/tracker-evolution-plugin.c
+++ b/src/plugins/evolution/tracker-evolution-plugin.c
@@ -55,8 +55,13 @@
#include <libedataserver/e-account.h>
#include <libedataserver/e-account-list.h>
+#include <libtracker-client/tracker.h>
+#include <libtracker-common/tracker-sparql-builder.h>
+#include <libtracker-common/tracker-ontology.h>
+#include <libtracker-common/tracker-utils.h>
+#include <libtracker-common/tracker-type-utils.h>
+
#include "tracker-evolution-plugin.h"
-#include "tracker-evolution-plugin-glue.h"
/* This runs in-process of evolution (in the mailer, as a EPlugin). It has
* access to the CamelSession using the external variable 'session'. The header
@@ -69,7 +74,18 @@
* 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 MAX_BEFORE_SEND 2000
+#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 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)
@@ -92,9 +108,6 @@ G_DEFINE_TYPE (TrackerEvolutionPlugin, tracker_evolution_plugin, G_TYPE_OBJECT)
typedef struct {
guint64 last_checkout;
- DBusGProxy *registrar;
- guint signal;
- gchar *sender;
} ClientRegistry;
typedef struct {
@@ -129,14 +142,13 @@ typedef struct {
} RegisterInfo;
typedef struct {
- DBusGConnection *connection;
- GHashTable *registrars;
GStaticRecMutex *mutex;
GHashTable *registered_folders;
GHashTable *cached_folders;
GHashTable *registered_stores;
GList *registered_clients;
EAccountList *accounts;
+ DBusGConnection *connection;
} TrackerEvolutionPluginPrivate;
enum {
@@ -148,17 +160,42 @@ static DBusGProxy *dbus_proxy = NULL;
static TrackerEvolutionPlugin *manager = NULL;
static GStaticRecMutex glock = G_STATIC_REC_MUTEX_INIT;
static guint register_count = 0;
+static TrackerClient *client = NULL;
/* Prototype declarations */
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);
-static void metadata_set_many (TrackerEvolutionPlugin *self, GStrv subjects, GPtrArray *predicates, GPtrArray *values);
-static void metadata_unset_many (TrackerEvolutionPlugin *self, GStrv subjects);
/* First a bunch of helper functions. */
+static void
+get_email_and_fullname (const gchar *line, gchar **email, gchar **fullname)
+{
+ gchar *ptr = g_utf8_strchr (line, -1, '<');
+
+ if (ptr) {
+ gchar *holder;
+
+ holder = g_strdup (line);
+ ptr = g_utf8_strchr (holder, -1, '<');
+ *ptr = '\0';
+ ptr++;
+ *fullname = holder;
+ holder = ptr;
+ ptr = g_utf8_strchr (ptr, -1, '>');
+ if (ptr) {
+ *ptr = '\0';
+ }
+ *email = g_strdup (holder);
+
+ } else {
+ *email = g_strdup (line);
+ *fullname = NULL;
+ }
+}
+
static GList *
get_recipient_list (const gchar *str)
{
@@ -210,92 +247,239 @@ folder_registry_new (const gchar *account_uri,
}
static void
-process_fields (GPtrArray *predicates_temp,
- GPtrArray *values_temp,
- gchar *uid,
- guint flags,
- gchar *sent,
- gchar *subject,
- gchar *from,
- gchar *to,
- gchar *cc,
- gchar *size,
- CamelFolder *folder)
+on_replied (GError *error, gpointer user_data) { }
+
+static void
+send_sparql_update (const gchar *sparql)
+{
+ if (client) {
+ tracker_resources_batch_sparql_update_async (client, sparql,
+ on_replied, NULL);
+ }
+}
+
+static void
+send_sparql_commit (gboolean update)
+{
+ if (client) {
+ if (update) {
+ gchar *update = g_strdup_printf ("DELETE { <" DATASOURCE_URN "> nie:contentLastModified ?d } "
+ "WHERE { <" DATASOURCE_URN "> a nie:InformationElement ; nie:contentLastModified ?d } \n"
+ "INSERT { <" DATASOURCE_URN "> nie:contentLastModified \"%s\" }",
+ tracker_date_to_string (time(NULL)));
+ tracker_resources_batch_sparql_update (client, update, NULL);
+ g_free (update);
+ }
+
+ tracker_resources_batch_commit_async (client, on_replied, NULL);
+ }
+}
+
+static void
+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;
- g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_UID));
- g_ptr_array_add (values_temp, g_strdup (uid));
+ tracker_sparql_builder_subject_iri (sparql, DATASOURCE_URN);
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object_iri (sparql, NIE_DATASOURCE);
+
+ /* for contentLastModified */
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nie:InformationElement");
+
+ tracker_sparql_builder_subject_iri (sparql, uri);
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nmo:Email");
+
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nmo:MailboxDataObject");
+
+ tracker_sparql_builder_predicate (sparql, "tracker:available");
+ tracker_sparql_builder_object_boolean (sparql, TRUE);
+
+ /* The URI of the InformationElement should be a UUID URN */
+ tracker_sparql_builder_predicate (sparql, "nie:isStoredAs");
+ tracker_sparql_builder_object_iri (sparql, uri);
- 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"));
+ tracker_sparql_builder_predicate_iri (sparql, NIE_DATASOURCE_P);
+ tracker_sparql_builder_object_iri (sparql, DATASOURCE_URN);
- 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_UID));
+// g_ptr_array_add (values_temp, g_strdup (uid));
- 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"));
+// 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"));
- 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"));
+// 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_FLAGGED));
- g_ptr_array_add (values_temp, g_strdup ((flags & CAMEL_MESSAGE_FLAGGED) ? "True" : "False"));
+// 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"));
- 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"));
+// 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"));
+
+// 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"));
+
+// 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 (subject && g_utf8_validate (subject, -1, NULL)) {
- g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_SUBJECT));
- g_ptr_array_add (values_temp, g_strdup (subject));
+ tracker_sparql_builder_subject_iri (sparql, uri);
+ tracker_sparql_builder_predicate (sparql, "nmo:messageSubject");
+ tracker_sparql_builder_object_string (sparql, subject);
}
list = get_recipient_list (to);
for (l = list; l; l = l->next) {
if (l->data && g_utf8_validate (l->data, -1, NULL)) {
- g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_TO));
- g_ptr_array_add (values_temp, l->data);
+ gchar *email_uri, *email = NULL, *fullname = NULL;
+
+ get_email_and_fullname (l->data, &email, &fullname);
+
+ email_uri = tracker_uri_printf_escaped ("mailto:%s", email);
+
+ tracker_sparql_builder_subject_iri (sparql, email_uri);
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nco:EmailAddress");
+
+ tracker_sparql_builder_subject_iri (sparql, email_uri);
+ tracker_sparql_builder_predicate (sparql, "nco:emailAddress");
+ tracker_sparql_builder_object_string (sparql, email);
+
+ tracker_sparql_builder_subject_iri (sparql, uri);
+ tracker_sparql_builder_predicate (sparql, "nmo:to");
+
+ tracker_sparql_builder_object_blank_open (sparql);
+
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nco:Contact");
+
+ if (fullname) {
+ tracker_sparql_builder_predicate (sparql, "nco:fullname");
+ tracker_sparql_builder_object_string (sparql, fullname);
+ g_free (fullname);
+ }
+
+ tracker_sparql_builder_predicate (sparql, "nco:hasEmailAddress");
+ tracker_sparql_builder_object_iri (sparql, email_uri);
+
+ tracker_sparql_builder_object_blank_close (sparql);
+
+ g_free (email_uri);
+ g_free (email);
} else
g_free (l->data);
}
g_list_free (list);
if (from && g_utf8_validate (from, -1, NULL)) {
- g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_FROM));
- g_ptr_array_add (values_temp, g_strdup (from));
- }
+ gchar *email_uri, *email = NULL, *fullname = NULL;
+
+ get_email_and_fullname (from, &email, &fullname);
+
+ email_uri = tracker_uri_printf_escaped ("mailto:%s", email);
+
+ tracker_sparql_builder_subject_iri (sparql, email_uri);
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nco:EmailAddress");
- 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));
+ tracker_sparql_builder_subject_iri (sparql, email_uri);
+ tracker_sparql_builder_predicate (sparql, "nco:emailAddress");
+ tracker_sparql_builder_object_string (sparql, email);
+
+ tracker_sparql_builder_subject_iri (sparql, uri);
+ tracker_sparql_builder_predicate (sparql, "nmo:from");
+
+ tracker_sparql_builder_object_blank_open (sparql);
+
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nco:Contact");
+
+ if (fullname) {
+ tracker_sparql_builder_predicate (sparql, "nco:fullname");
+ tracker_sparql_builder_object_string (sparql, fullname);
+ g_free (fullname);
+ }
+
+ tracker_sparql_builder_predicate (sparql, "nco:hasEmailAddress");
+ tracker_sparql_builder_object_iri (sparql, email_uri);
+
+ tracker_sparql_builder_object_blank_close (sparql);
+
+ g_free (email_uri);
+ 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)) {
- g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_CC));
- g_ptr_array_add (values_temp, l->data);
+ gchar *email_uri, *email = NULL, *fullname = NULL;
+
+ get_email_and_fullname (l->data, &email, &fullname);
+
+ email_uri = tracker_uri_printf_escaped ("mailto:%s", email);
+
+ tracker_sparql_builder_subject_iri (sparql, email_uri);
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nco:EmailAddress");
+
+ tracker_sparql_builder_subject_iri (sparql, email_uri);
+ tracker_sparql_builder_predicate (sparql, "nco:emailAddress");
+ tracker_sparql_builder_object_string (sparql, email);
+
+ tracker_sparql_builder_subject_iri (sparql, uri);
+ tracker_sparql_builder_predicate (sparql, "nmo:cc");
+
+ tracker_sparql_builder_object_blank_open (sparql);
+
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nco:Contact");
+
+ if (fullname) {
+ tracker_sparql_builder_predicate (sparql, "nco:fullname");
+ tracker_sparql_builder_object_string (sparql, fullname);
+ g_free (fullname);
+ }
+
+ tracker_sparql_builder_predicate (sparql, "nco:hasEmailAddress");
+ tracker_sparql_builder_object_iri (sparql, email_uri);
+
+ tracker_sparql_builder_object_blank_close (sparql);
+
+ g_free (email_uri);
+ g_free (email);
} else
g_free (l->data);
}
g_list_free (list);
if (sent && g_utf8_validate (sent, -1, NULL)) {
- g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_SENT));
- g_ptr_array_add (values_temp, g_strdup (sent));
+ tracker_sparql_builder_subject_iri (sparql, uri);
+ tracker_sparql_builder_predicate (sparql, "nmo:receivedDate");
+ tracker_sparql_builder_object_string (sparql, sent);
}
- 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);
- }
- }
+// 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);
+// }
+// }
}
/* When new messages arrive to- or got deleted from the summary, called in
@@ -310,7 +494,6 @@ on_folder_summary_changed (CamelFolder *folder,
gpointer user_data)
{
OnSummaryChangedInfo *info = user_data;
- TrackerEvolutionPlugin *self = info->self;
CamelFolderSummary *summary;
gchar *account_uri = info->account_uri;
GPtrArray *merged;
@@ -352,20 +535,11 @@ on_folder_summary_changed (CamelFolder *folder,
}
if (merged->len > 0) {
- GPtrArray *predicates_array = g_ptr_array_new ();
- GPtrArray *values_array = g_ptr_array_new ();
- gchar **subjects = (gchar **) g_malloc0 (sizeof (gchar *) * merged->len + 1);
- guint y;
-
- y = 0;
for (i = 0; i< merged->len; i++) {
gchar *subject, *to, *from, *cc, *uid = NULL, *sent, *size;
guint flags;
- gchar **values, **predicates;
CamelMessageInfo *linfo;
- GPtrArray *values_temp = g_ptr_array_new ();
- GPtrArray *predicates_temp = g_ptr_array_new ();
const CamelTag *ctags;
const CamelFlag *cflags;
@@ -375,7 +549,8 @@ on_folder_summary_changed (CamelFolder *folder,
uid = (gchar *) camel_message_info_uid (linfo);
if (linfo && uid) {
- guint j, max;
+ gchar *uri;
+ TrackerSparqlBuilder *sparql;
subject = (gchar *) camel_message_info_subject (linfo);
to = (gchar *) camel_message_info_to (linfo);
@@ -389,74 +564,70 @@ on_folder_summary_changed (CamelFolder *folder,
/* Camel returns a uint32, so %u */
size = g_strdup_printf ("%u", camel_message_info_size (linfo));
- process_fields (predicates_temp, values_temp, uid,
- flags, sent, subject, from, to, cc,
- size, folder);
+ /* This is not a path but a URI, don't use the
+ * OS's directory separator here */
+
+ uri = g_strdup_printf ("%s%s/%s",
+ em_uri,
+ camel_folder_get_full_name (folder),
+ uid);
+
+ sparql = tracker_sparql_builder_new_update ();
+
+ tracker_sparql_builder_drop_graph (sparql, uri);
+
+ tracker_sparql_builder_insert_open (sparql);
+
+ process_fields (sparql, uid, flags, sent, subject,
+ from, to, cc, size, folder, uri);
+
+ tracker_sparql_builder_subject_iri (sparql, uri);
cflags = camel_message_info_user_flags (linfo);
while (cflags) {
- g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_TAG));
- g_ptr_array_add (values_temp, g_strdup_printf ("%s=True", cflags->name));
+ tracker_sparql_builder_predicate (sparql, "nao:hasTag");
+ tracker_sparql_builder_object_blank_open (sparql);
+
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nao:Tag");
+
+ tracker_sparql_builder_predicate (sparql, "nao:prefLabel");
+ tracker_sparql_builder_object_string (sparql, cflags->name);
+ tracker_sparql_builder_object_blank_close (sparql);
+
cflags = cflags->next;
}
ctags = camel_message_info_user_tags (linfo);
while (ctags) {
- g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_TAG));
- g_ptr_array_add (values_temp, g_strdup_printf ("%s=%s", ctags->name, ctags->value));
- ctags = ctags->next;
- }
+ tracker_sparql_builder_predicate (sparql, "nao:hasProperty");
+ tracker_sparql_builder_object_blank_open (sparql);
- if (values_temp->len != predicates_temp->len)
- g_critical ("values_temp->len != predicates_temp->len");
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nao:Property");
- max = MIN (values_temp->len, predicates_temp->len);
+ tracker_sparql_builder_predicate (sparql, "nao:propertyName");
+ tracker_sparql_builder_object_string (sparql, ctags->name);
+
+ tracker_sparql_builder_predicate (sparql, "nao:propertyValue");
+ tracker_sparql_builder_object_string (sparql, ctags->value);
- values = (gchar **) g_malloc0 (sizeof (gchar*) * max + 1);
- predicates = (gchar **) g_malloc0 (sizeof (gchar*) * max + 1);
-
- for (j = 0; j < max; j++) {
- predicates[j] = predicates_temp->pdata[j];
- values[j] = values_temp->pdata[j];
+ tracker_sparql_builder_object_blank_close (sparql);
+ ctags = ctags->next;
}
- predicates[j] = NULL;
- values[j] = NULL;
-
- g_ptr_array_add (values_array, values);
- g_ptr_array_add (predicates_array, predicates);
-
- /* This is not a path but a URI, don't use the
- * OS's directory separator here */
+ tracker_sparql_builder_insert_close (sparql);
- subjects[y] = g_strdup_printf ("%s%s/%s",
- em_uri,
- camel_folder_get_full_name (folder),
- uid);
+ send_sparql_update (tracker_sparql_builder_get_result (sparql));
- g_ptr_array_free (predicates_temp, TRUE);
- g_ptr_array_free (values_temp, TRUE);
+ g_object_unref (sparql);
- y++;
+ g_free (uri);
}
if (linfo)
camel_message_info_free (linfo);
}
-
- subjects[y] = NULL;
-
- /* This goes to all currently registered registrars */
-
- metadata_set_many (self, subjects, predicates_array, values_array);
-
- g_strfreev (subjects);
- for (i = 0; i < values_array->len; i++)
- g_strfreev (values_array->pdata[i]);
- g_ptr_array_free (values_array, TRUE);
- for (i = 0; i < predicates_array->len; i++)
- g_strfreev (predicates_array->pdata[i]);
- g_ptr_array_free (predicates_array, TRUE);
}
g_ptr_array_free (merged, TRUE);
@@ -464,26 +635,27 @@ on_folder_summary_changed (CamelFolder *folder,
/* the uid_removed member contains the removed-from-the-summary items */
if (changes->uid_removed && changes->uid_removed->len > 0) {
- gchar **subjects = (gchar **) g_malloc0 (sizeof (gchar *) * changes->uid_removed->len + 1);
+ GString *sparql = g_string_new ("DELETE { ");
for (i = 0; i< changes->uid_removed->len; i++) {
/* This is not a path but a URI, don't use the OS's
* directory separator here */
- subjects[i] = g_strdup_printf ("%s%s/%s", em_uri,
- camel_folder_get_full_name (folder),
- (char*) changes->uid_removed->pdata[i]);
+ g_string_append_printf (sparql, "<%s%s/%s> a rdfs:Resource ",
+ em_uri,
+ camel_folder_get_full_name (folder),
+ (char*) changes->uid_removed->pdata[i]);
}
- subjects[i] = NULL;
+ g_string_append_c (sparql, '}');
- /* This goes to all currently registered registrars */
+ send_sparql_update (sparql->str);
+ g_string_free (sparql, TRUE);
+ }
- metadata_unset_many (self, subjects);
+ send_sparql_commit (TRUE);
- g_strfreev (subjects);
- }
g_free (em_uri);
}
@@ -492,12 +664,8 @@ on_folder_summary_changed (CamelFolder *folder,
#define QUEUED_SETS_PER_MAINLOOP 2
typedef struct {
- GStrv subjects;
- GPtrArray *values_array;
- GPtrArray *predicates_array;
- DBusGProxy *registrar;
+ TrackerSparqlBuilder *sparql;
TrackerEvolutionPlugin *self;
- gchar *sender;
} QueuedSet;
static GQueue *many_queue = NULL;
@@ -505,18 +673,8 @@ static GQueue *many_queue = NULL;
static void
queued_set_free (QueuedSet *queued_set)
{
- guint i;
-
- g_strfreev (queued_set->subjects);
- for (i = 0; i < queued_set->values_array->len; i++)
- g_strfreev (queued_set->values_array->pdata[i]);
- g_ptr_array_free (queued_set->values_array, TRUE);
- for (i = 0; i < queued_set->predicates_array->len; i++)
- g_strfreev (queued_set->predicates_array->pdata[i]);
- g_ptr_array_free (queued_set->predicates_array, TRUE);
- g_object_unref (queued_set->registrar);
+ g_object_unref (queued_set->sparql);
g_object_unref (queued_set->self);
- g_free (queued_set->sender);
g_slice_free (QueuedSet, queued_set);
}
@@ -524,7 +682,7 @@ queued_set_free (QueuedSet *queued_set)
static gboolean
many_idle_handler (gpointer user_data)
{
- QueuedSet *queued_set;
+ QueuedSet *queued_set = NULL;
gint popped;
g_return_val_if_fail (QUEUED_SETS_PER_MAINLOOP > 0, FALSE);
@@ -536,9 +694,7 @@ many_idle_handler (gpointer user_data)
for (queued_set = g_queue_pop_head (many_queue), popped = 1;
queued_set != NULL && popped < QUEUED_SETS_PER_MAINLOOP;
queued_set = g_queue_pop_head (many_queue), popped++) {
- TrackerEvolutionPlugin *self = queued_set->self;
- TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (self);
-
+
/* During initial introduction the client-registrar might
* decide to crash, disconnect, stop listening. That
* would result in critical warnings so we start ignoring
@@ -547,15 +703,8 @@ many_idle_handler (gpointer user_data)
* We nonetheless need to handle these items to clean up
* the queue properly, of course. */
- if (priv->registrars && g_hash_table_lookup (priv->registrars, queued_set->sender)) {
- dbus_g_proxy_call_no_reply (queued_set->registrar,
- "SetMany",
- G_TYPE_STRV, queued_set->subjects,
- TRACKER_TYPE_G_STRV_ARRAY, queued_set->predicates_array,
- TRACKER_TYPE_G_STRV_ARRAY, queued_set->values_array,
- G_TYPE_UINT, (guint) time (NULL),
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ if (client) {
+ send_sparql_update (tracker_sparql_builder_get_result (queued_set->sparql));
} else {
gint i;
@@ -564,18 +713,18 @@ many_idle_handler (gpointer user_data)
for (i = 0; i < many_queue->length; i++) {
QueuedSet *remove_candidate;
-
remove_candidate = g_queue_peek_nth (many_queue, i);
-
- if (remove_candidate->registrar == queued_set->registrar) {
- queued_set_free (g_queue_pop_nth (many_queue, i));
- }
+ queued_set_free (g_queue_pop_nth (many_queue, i));
}
}
queued_set_free (queued_set);
}
+ if (!queued_set) {
+ send_sparql_commit (TRUE);
+ }
+
return queued_set ? TRUE : FALSE;
}
@@ -609,10 +758,11 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
gchar *em_uri = em_uri_from_camel (account_uri);
while (iter) {
- guint i, ret = SQLITE_OK;
+ guint ret = SQLITE_OK;
gchar *query;
sqlite3_stmt *stmt = NULL;
gboolean more = TRUE;
+ TrackerSparqlBuilder *sparql = NULL;
/* This query is the culprint of the functionality: it fetches
* all the metadata from the summary table where modified is
@@ -642,15 +792,11 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
ret = sqlite3_prepare_v2 (cdb_r->db, query, -1, &stmt, NULL);
while (more) {
- GPtrArray *subjects_a = g_ptr_array_new ();
- GPtrArray *predicates_array = g_ptr_array_new ();
- GPtrArray *values_array = g_ptr_array_new ();
guint count = 0;
more = FALSE;
while (ret == SQLITE_OK || ret == SQLITE_BUSY || ret == SQLITE_ROW) {
- gchar **values, **predicates;
gchar *subject, *to, *from, *cc, *sent, *uid, *size;
gchar *part, *label, *p;
guint flags;
@@ -670,10 +816,10 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
uid = (gchar *) sqlite3_column_text (stmt, 0);
if (uid) {
- GPtrArray *predicates_temp = g_ptr_array_new ();
- GPtrArray *values_temp = g_ptr_array_new ();
CamelFolder *folder;
guint max = 0, j;
+ gchar *uri;
+ gboolean opened = FALSE;
flags = (guint ) sqlite3_column_int (stmt, 1);
size = (gchar *) sqlite3_column_text (stmt, 8);
@@ -687,8 +833,20 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
folder = g_hash_table_lookup (priv->cached_folders, iter->full_name);
- process_fields (predicates_temp, values_temp, uid, flags, sent,
- subject, from, to, cc, size, folder);
+ uri = g_strdup_printf ("%s%s/%s", em_uri,
+ iter->full_name, uid);
+
+ if (!sparql) {
+ sparql = tracker_sparql_builder_new_update ();
+ }
+
+ tracker_sparql_builder_drop_graph (sparql, uri);
+
+ tracker_sparql_builder_insert_open (sparql);
+
+ process_fields (sparql, uid, flags, sent,
+ subject, from, to, cc, size,
+ folder, uri);
g_static_rec_mutex_unlock (priv->mutex);
@@ -700,13 +858,24 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
if (part[j] == ' ') {
part[j] = 0;
- g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_TAG));
- g_ptr_array_add (values_temp, g_strdup_printf ("%s=True", label));
+
+ if (!opened) {
+ tracker_sparql_builder_subject_iri (sparql, uri);
+ opened = TRUE;
+ }
+
+ tracker_sparql_builder_predicate (sparql, "nao:hasTag");
+ tracker_sparql_builder_object_blank_open (sparql);
+
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nao:Tag");
+
+ tracker_sparql_builder_predicate (sparql, "nao:prefLabel");
+ tracker_sparql_builder_object_string (sparql, label);
+ tracker_sparql_builder_object_blank_close (sparql);
label = &(part[j+1]);
}
}
- g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_TAG));
- g_ptr_array_add (values_temp, g_strdup (label));
}
g_free (p);
@@ -720,41 +889,32 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
EXTRACT_STRING (value)
if (name && g_utf8_validate (name, -1, NULL) &&
value && g_utf8_validate (value, -1, NULL)) {
- g_ptr_array_add (predicates_temp, g_strdup (TRACKER_EVOLUTION_PREDICATE_TAG));
- g_ptr_array_add (values_temp, g_strdup_printf ("%s=%s", name, value));
- }
- g_free(name);
- g_free(value);
- }
- g_free (p);
- if (values_temp->len != predicates_temp->len)
- g_critical ("values_temp->len != predicates_temp->len");
-
- max = MIN (values_temp->len, predicates_temp->len);
-
- values = (gchar **) g_malloc0 (sizeof (gchar*) * max + 1);
- predicates = (gchar **) g_malloc0 (sizeof (gchar*) * max + 1);
-
- for (j = 0; j < max; j++) {
- predicates[j] = predicates_temp->pdata[j];
- values[j] = values_temp->pdata[j];
- }
+ if (!opened) {
+ tracker_sparql_builder_subject_iri (sparql, uri);
+ opened = TRUE;
+ }
- predicates[j] = NULL;
- values[j] = NULL;
+ tracker_sparql_builder_predicate (sparql, "nao:hasProperty");
+ tracker_sparql_builder_object_blank_open (sparql);
- /* This is not a path but a URI, don't use the
- * OS's directory separator here */
+ tracker_sparql_builder_predicate (sparql, "rdf:type");
+ tracker_sparql_builder_object (sparql, "nao:Property");
- g_ptr_array_add (subjects_a, g_strdup_printf ("%s%s/%s", em_uri,
- iter->full_name, uid));
+ tracker_sparql_builder_predicate (sparql, "nao:propertyName");
+ tracker_sparql_builder_object_string (sparql, name);
+
+ tracker_sparql_builder_predicate (sparql, "nao:propertyValue");
+ tracker_sparql_builder_object_string (sparql, value);
- g_ptr_array_add (predicates_array, predicates);
- g_ptr_array_add (values_array, values);
+ tracker_sparql_builder_object_blank_close (sparql);
+ }
+ g_free(name);
+ g_free(value);
+ }
+ g_free (p);
- g_ptr_array_free (predicates_temp, TRUE);
- g_ptr_array_free (values_temp, TRUE);
+ tracker_sparql_builder_insert_close (sparql);
count++;
}
@@ -776,15 +936,10 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
}
- if (count > 0) {
- gchar **subjects;
+ if (count > 0 && sparql) {
QueuedSet *queued_set;
gboolean start_handler = FALSE;
- subjects = (gchar **) g_malloc0 (sizeof (gchar *) * subjects_a->len + 1);
- for (i = 0; i < subjects_a->len; i++)
- subjects[i] = g_ptr_array_index (subjects_a, i);
- subjects[i] = NULL;
/* The many_queue stuff:
* Why is this? Ah! Good question and glad you ask.
@@ -795,12 +950,10 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
queued_set = g_slice_new (QueuedSet);
- queued_set->subjects = subjects;
- queued_set->predicates_array = predicates_array;
- queued_set->values_array = values_array;
- queued_set->registrar = g_object_ref (info->registrar);
+ queued_set->sparql = sparql; /* Keep ref */
+ sparql = NULL;
+
queued_set->self = g_object_ref (self);
- queued_set->sender = g_strdup (info->sender);
if (!many_queue) {
many_queue = g_queue_new ();
@@ -814,19 +967,11 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
start_many_handler ();
}
- } else {
-
- for (i = 0; i < values_array->len; i++)
- g_strfreev (values_array->pdata[i]);
- g_ptr_array_free (values_array, TRUE);
-
- for (i = 0; i < predicates_array->len; i++)
- g_strfreev (predicates_array->pdata[i]);
- g_ptr_array_free (predicates_array, TRUE);
+ } else if (sparql) {
+ g_object_unref (sparql);
+ sparql = NULL;
}
- g_ptr_array_free (subjects_a, TRUE);
-
}
sqlite3_finalize (stmt);
@@ -919,27 +1064,26 @@ introduce_store_deal_with_deleted (TrackerEvolutionPlugin *self,
}
if (count > 0) {
- gchar **subjects;
+ GString *sparql = g_string_new ("DELETE { ");
+
+ for (i = 0; i < subjects_a->len; i++) {
+ g_string_append_printf (sparql, "<%s> a rdfs:Resource ",
+ (gchar *) g_ptr_array_index (subjects_a, i));
+ }
- subjects = (gchar **) g_malloc0 (sizeof (gchar *) * subjects_a->len + 1);
- for (i = 0; i < subjects_a->len; i++)
- subjects[i] = g_ptr_array_index (subjects_a, i);
- subjects[i] = NULL;
+ g_string_append_c (sparql, '}');
- dbus_g_proxy_call_no_reply (info->registrar,
- "UnsetMany",
- G_TYPE_STRV, subjects,
- G_TYPE_UINT, (guint) time (NULL),
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ send_sparql_update (sparql->str);
+ g_string_free (sparql, TRUE);
- g_strfreev (subjects);
}
g_ptr_array_free (subjects_a, TRUE);
}
+ send_sparql_commit (TRUE);
+
sqlite3_finalize (stmt);
sqlite3_free (query);
@@ -1195,10 +1339,6 @@ unregister_walk_folders_in_folder (TrackerEvolutionPlugin *self,
static void
client_registry_info_free (ClientRegistry *info)
{
- if (info->signal != 0) /* known (see below) */
- g_signal_handler_disconnect (info->registrar, info->signal);
- g_object_unref (info->registrar);
- g_free (info->sender);
g_slice_free (ClientRegistry, info);
}
@@ -1207,10 +1347,7 @@ client_registry_info_copy (ClientRegistry *info)
{
ClientRegistry *ninfo = g_slice_new0 (ClientRegistry);
- ninfo->signal = 0; /* known */
- ninfo->sender = g_strdup (info->sender);
ninfo->last_checkout = info->last_checkout;
- ninfo->registrar = g_object_ref (info->registrar);
return ninfo;
}
@@ -1385,99 +1522,64 @@ introduce_accounts_to (TrackerEvolutionPlugin *self,
}
static void
-register_client (TrackerEvolutionPlugin *self,
- guint64 last_checkout,
- DBusGProxy *registrar,
- gchar *sender,
- guint dsignal)
+register_client (TrackerEvolutionPlugin *self)
{
TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (self);
guint64 too_old = get_last_deleted_time (self);
ClientRegistry *info = g_slice_new0 (ClientRegistry);
+ GError *error = NULL;
+ GPtrArray *results;
+ const gchar *query;
+ guint i;
- info->sender = g_strdup (sender);
- info->signal = dsignal;
- info->registrar = g_object_ref (registrar);
-
- /* If registrar's modseq is too old, send Cleanup (). This means that
- * we tell it to start over (it must invalidate what it has). */
-
- if (last_checkout < too_old) {
- dbus_g_proxy_call_no_reply (registrar,
- "Cleanup",
- G_TYPE_UINT, (guint) time (NULL),
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- info->last_checkout = 0;
- } else {
- info->last_checkout = last_checkout;
+ if (!client) {
+ return;
}
- introduce_accounts_to (self, info);
-
- priv->registered_clients =
- g_list_prepend (priv->registered_clients, info);
+ query = "SELECT ?c WHERE { <"DATASOURCE_URN "> nie:contentLastModified ?c }";
-}
-
-
-static void
-metadata_set_many (TrackerEvolutionPlugin *self,
- GStrv subjects,
- GPtrArray *predicates,
- GPtrArray *values)
-{
- TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (self);
- GHashTableIter iter;
- gpointer key, value;
+ results = tracker_resources_sparql_query (client, query, &error);
- g_static_rec_mutex_lock (priv->mutex);
+ if (error) {
+ g_warning ("%s\n", error->message);
+ g_error_free (error);
+ return;
+ }
- g_hash_table_iter_init (&iter, priv->registrars);
+ if (!results) {
+ info->last_checkout = 0;
+ } else {
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- DBusGProxy *registrar = value;
-
- dbus_g_proxy_call_no_reply (registrar,
- "SetMany",
- G_TYPE_STRV, subjects,
- TRACKER_TYPE_G_STRV_ARRAY, predicates,
- TRACKER_TYPE_G_STRV_ARRAY, values,
- G_TYPE_UINT, (guint) time (NULL),
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ for (i = 0; i < results->len; i++) {
+ const gchar **str = g_ptr_array_index (results, i);
+ info->last_checkout = (guint64) tracker_string_to_date (str[0]);
+ break;
+ }
}
- g_static_rec_mutex_unlock (priv->mutex);
-}
+ g_ptr_array_foreach (results, (GFunc) g_strfreev, NULL);
+ g_ptr_array_free (results, TRUE);
-static void
-metadata_unset_many (TrackerEvolutionPlugin *self,
- GStrv subjects)
-{
- TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (self);
- GHashTableIter iter;
- gpointer key, value;
+ /* If registrar's modseq is too old, send Cleanup (). This means that
+ * we tell it to start over (it must invalidate what it has). */
- g_static_rec_mutex_lock (priv->mutex);
+ if (info->last_checkout < too_old) {
- g_hash_table_iter_init (&iter, priv->registrars);
+ send_sparql_update ("DELETE { ?s a rdfs:Resource } WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }");
+ send_sparql_commit (FALSE);
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- DBusGProxy *registrar = value;
-
- dbus_g_proxy_call_no_reply (registrar,
- "UnsetMany",
- G_TYPE_STRV, subjects,
- G_TYPE_UINT, (guint) time (NULL),
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ info->last_checkout = 0;
}
- g_static_rec_mutex_unlock (priv->mutex);
+ introduce_accounts_to (self, info);
+
+ priv->registered_clients =
+ g_list_prepend (priv->registered_clients, info);
}
+
+
static void
on_folder_created (CamelStore *store, void *event_data,
StoreRegistry *registry)
@@ -1729,27 +1831,69 @@ on_account_changed (EAccountList *list,
static void
disable_plugin (void)
{
+ if (client) {
+ tracker_disconnect (client);
+ client = NULL;
+ }
+
+ if (dbus_proxy) {
+ g_object_unref (dbus_proxy);
+ dbus_proxy = NULL;
+ }
+}
+
+
+static void
+list_names_reply_cb (DBusGProxy *proxy,
+ DBusGProxyCall *call,
+ gpointer user_data)
+{
GError *error = NULL;
- guint result;
+ GStrv names = NULL;
+ guint i = 0;
- org_freedesktop_DBus_release_name (dbus_proxy, TRACKER_EVOLUTION_MANAGER_SERVICE,
- &result, &error);
+ dbus_g_proxy_end_call (proxy, call, &error,
+ G_TYPE_STRV, &names,
+ G_TYPE_INVALID);
- if (!error) {
- if (manager) {
- g_object_unref (manager);
- manager = NULL;
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ if (names)
+ g_strfreev (names);
+ return;
+ }
+
+ while (names[i] != NULL) {
+ if (g_strcmp0 (names[i], TRACKER_SERVICE) == 0) {
+ register_client (manager);
+ break;
}
+ i++;
+ }
+
+ g_strfreev (names);
+}
+
- if (dbus_proxy) {
- g_object_unref (dbus_proxy);
- dbus_proxy = NULL;
+static void
+name_owner_changed_cb (DBusGProxy *proxy,
+ gchar *name,
+ gchar *old_owner,
+ gchar *new_owner,
+ gpointer user_data)
+{
+ if (g_strcmp0 (name, TRACKER_SERVICE) == 0) {
+ if (tracker_is_empty_string (new_owner) && !tracker_is_empty_string (old_owner)) {
+ if (client) {
+ tracker_disconnect (client);
+ client = NULL;
+ }
}
- } else {
- g_warning ("Could not setup DBus, ReleaseName of %s: %s\n",
- TRACKER_EVOLUTION_MANAGER_SERVICE, error->message);
- g_error_free (error);
+ if (tracker_is_empty_string (old_owner) && !tracker_is_empty_string (new_owner)) {
+ register_client (manager);
+ }
}
}
@@ -1758,57 +1902,42 @@ enable_plugin (void)
{
DBusGConnection *connection;
GError *error = NULL;
- guint result;
- if (dbus_proxy && manager)
- return;
-
- if ((dbus_proxy && !manager) || (!dbus_proxy && manager))
+ if (client || dbus_proxy) {
disable_plugin ();
+ }
- if ((dbus_proxy && !manager) || (!dbus_proxy && manager))
- return;
+ if (manager) {
+ g_object_unref (manager);
+ }
connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (error)
goto error_handler;
+ client = tracker_connect (FALSE, G_MAXINT);
+
+ manager = g_object_new (TRACKER_TYPE_EVOLUTION_PLUGIN,
+ "connection", connection, NULL);
+
dbus_proxy = dbus_g_proxy_new_for_name (connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
- if (!org_freedesktop_DBus_request_name (dbus_proxy, TRACKER_EVOLUTION_MANAGER_SERVICE,
- DBUS_NAME_FLAG_DO_NOT_QUEUE,
- &result, &error)) {
-
- g_warning ("Could not setup DBus, failed at RequestName for %s\n",
- TRACKER_EVOLUTION_MANAGER_SERVICE);
-
- goto error_handler;
- }
-
- if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+ dbus_g_proxy_add_signal (dbus_proxy, "NameOwnerChanged",
+ G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
+ G_TYPE_INVALID);
- g_warning ("Could not setup DBus, can't become primary owner of %s\n",
- TRACKER_EVOLUTION_MANAGER_SERVICE);
+ dbus_g_proxy_connect_signal (dbus_proxy, "NameOwnerChanged",
+ G_CALLBACK (name_owner_changed_cb),
+ NULL, NULL);
- goto error_handler;
- }
-
- if (error)
- goto error_handler;
-
- manager = g_object_new (TRACKER_TYPE_EVOLUTION_PLUGIN,
- "connection", connection, NULL);
-
- dbus_g_object_type_install_info (G_OBJECT_TYPE (manager),
- &dbus_glib_tracker_evolution_plugin_object_info);
-
- dbus_g_connection_register_g_object (connection,
- TRACKER_EVOLUTION_MANAGER_PATH,
- G_OBJECT (manager));
+ dbus_g_proxy_begin_call (dbus_proxy, "ListNames",
+ list_names_reply_cb, NULL, NULL,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
error_handler:
@@ -1819,84 +1948,6 @@ enable_plugin (void)
}
}
-static gboolean
-do_remove_or_not (gpointer key, gpointer value, gpointer user_data)
-{
- if (user_data == value)
- return TRUE;
-
- return FALSE;
-}
-
-static void
-service_gone (DBusGProxy *lproxy, TrackerEvolutionPlugin *plugin)
-{
- TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (plugin);
- GList *copy = priv->registered_clients;
- GList *to_delete = NULL;
-
- g_static_rec_mutex_lock (priv->mutex);
-
- g_hash_table_foreach_remove (priv->registrars,
- do_remove_or_not,
- lproxy);
-
- while (copy) {
- ClientRegistry *creg = copy->data;
- if (creg->registrar == lproxy)
- to_delete = g_list_prepend (to_delete, copy);
- copy = g_list_next (copy);
- }
-
- copy = to_delete;
- while (copy) {
- GList *node = copy->data;
- ClientRegistry *creg = node->data;
- priv->registered_clients = g_list_delete_link (priv->registered_clients, node);
- client_registry_info_free (creg);
- copy = g_list_next (copy);
- }
-
- g_list_free (to_delete);
-
- g_static_rec_mutex_unlock (priv->mutex);
-}
-
-void
-tracker_evolution_plugin_register (TrackerEvolutionPlugin *plugin,
- gchar *registrar_path,
- guint last_checkout,
- DBusGMethodInvocation *context,
- GError *derror)
-{
- TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (plugin);
- gchar *sender;
- DBusGProxy *registrar;
- guint dsignal;
-
- g_static_rec_mutex_lock (priv->mutex);
-
- sender = dbus_g_method_get_sender (context);
-
- registrar = dbus_g_proxy_new_for_name (priv->connection, sender,
- registrar_path,
- TRACKER_EVOLUTION_REGISTRAR_INTERFACE);
-
- g_hash_table_replace (priv->registrars, g_strdup (sender),
- registrar);
-
- dsignal = g_signal_connect (registrar, "destroy",
- G_CALLBACK (service_gone),
- plugin);
-
- g_static_rec_mutex_unlock (priv->mutex);
-
- /* Passing uint64 over DBus ain't working :-\ */
- register_client (plugin, (guint64) last_checkout, registrar, sender, dsignal);
-
- dbus_g_method_return (context);
-}
-
int
e_plugin_lib_enable (EPluginLib *ep, int enabled)
@@ -1921,12 +1972,6 @@ tracker_evolution_plugin_finalize (GObject *plugin)
g_static_rec_mutex_lock (priv->mutex);
- g_list_foreach (priv->registered_clients,
- (GFunc) client_registry_info_free,
- NULL);
-
- g_list_free (priv->registered_clients);
-
if (priv->registered_folders) {
g_hash_table_destroy (priv->registered_folders);
g_hash_table_destroy (priv->cached_folders);
@@ -1941,8 +1986,6 @@ tracker_evolution_plugin_finalize (GObject *plugin)
g_object_unref (priv->accounts);
- g_hash_table_destroy (priv->registrars);
-
if (priv->connection)
dbus_g_connection_unref (priv->connection);
@@ -2031,10 +2074,6 @@ tracker_evolution_plugin_init (TrackerEvolutionPlugin *plugin)
g_static_rec_mutex_lock (priv->mutex);
- priv->registrars = g_hash_table_new_full (g_str_hash, g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_object_unref);
-
priv->cached_folders = NULL;
priv->registered_folders = NULL;
diff --git a/src/plugins/evolution/tracker-evolution-plugin.h b/src/plugins/evolution/tracker-evolution-plugin.h
index 3f59936..0494843 100644
--- a/src/plugins/evolution/tracker-evolution-plugin.h
+++ b/src/plugins/evolution/tracker-evolution-plugin.h
@@ -49,11 +49,6 @@ struct TrackerEvolutionPluginClass {
GType tracker_evolution_plugin_get_type (void);
-void tracker_evolution_plugin_register (TrackerEvolutionPlugin *object,
- gchar *registrar_path,
- guint last_modseq,
- DBusGMethodInvocation *context,
- GError *derror);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]