Re: [Evolution-hackers] [Evolution] Beagle and Tracker, letting Evolution feed those beasts RDF triples instead



On Tue, 2008-12-09 at 19:59 +0100, Philip Van Hoof wrote:
 
> > I'm writing a plugin that will implement the "Manager" class as
> > described here. Tracker will then implement being a "Registrar".
> > 
> > http://live.gnome.org/Evolution/Metadata

> A experience developer should get a quite good idea of what will be
> needed in Evolution:
> 
> Keeping timestamps around foreach message so that I can do a variation
> of camel_db_read_message_info_records that accepts a "since" timestamp.
> 
> For example:
> 
> camel_db_message_infos_that_changed_since (db, since, callback, userd)

[CUT]

> Let me know what you guys think ...

So, here's the patch (on Tracker's trunk, as we'll probably be shipping
this Evolution plugin as part of Tracker) of what I have so far.

The DBus stuff ain't connected yet with the Evolution hooks. I have,
however, already implemented the basic structure of iterating over each
and every message in Evolution: starts at foreach_message_in_accounts

If you follow that a little bit, you'll see the call for 
camel_db_read_message_info_records which is the one that I meant in my
last E-mail about camel_db_message_infos_that_changed_since things.


-- 
Philip Van Hoof, freelance software developer
home: me at pvanhoof dot be 
gnome: pvanhoof at gnome dot org 
http://pvanhoof.be/blog
http://codeminded.be
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 2683)
+++ src/Makefile.am	(working copy)
@@ -28,6 +28,10 @@
 build_libtrackergtk = libtracker-gtk
 endif
 
+if HAVE_EVOPLUG
+build_evoplug = tracker-evolution-plugin
+endif
+
 SUBDIRS = 					\
 	libstemmer				\
 	$(build_qdbm)				\
@@ -44,7 +48,8 @@
 	$(build_libtrackergtk)			\
 	$(build_tracker_applet)			\
 	$(build_tracker_search_tool)		\
-	$(build_tracker_preferences)
+	$(build_tracker_preferences)		\
+	$(build_evoplug)
 
 DIST_SUBDIRS = 					\
 	libstemmer				\
@@ -62,4 +67,5 @@
 	libtracker-gtk				\
 	tracker-applet	 			\
 	tracker-search-tool			\
-	tracker-preferences
+	tracker-preferences			\
+	tracker-evolution-plugin
Index: src/tracker-evolution-plugin/tracker-evolution-plugin.h
===================================================================
--- src/tracker-evolution-plugin/tracker-evolution-plugin.h	(revision 0)
+++ src/tracker-evolution-plugin/tracker-evolution-plugin.h	(revision 0)
@@ -0,0 +1,59 @@
+#ifndef __THUMBNAIL_MANAGER_H__
+#define __THUMBNAIL_MANAGER_H__
+
+/*
+ * This file is part of hildon-thumbnail package
+ *
+ * Copyright (C) 2005 Nokia Corporation.  All Rights reserved.
+ *
+ * Contact: Marius Vollmer <marius vollmer nokia com>
+ * Author: Philip Van Hoof <philip codeminded be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#define MANAGER_SERVICE      "org.gnome.evolution"
+#define MANAGER_PATH         "/org/gnome/evolution/metadata/Manager"
+#define MANAGER_INTERFACE    "org.gnome.evolution.metadata.Manager"
+#define REGISTRAR_INTERFACE   "org.gnome.evolution.metadata.Registrar"
+
+#define TRACKER_TYPE_EVOLUTION_PLUGIN          (tracker_evolution_plugin_get_type())
+#define TRACKER_EVOLUTION_PLUGIN(o)            (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_EVOLUTION_PLUGIN, TrackerEvolutionPlugin))
+#define TRACKER_EVOLUTION_PLUGIN_CLASS(c)      (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_EVOLUTION_PLUGIN, TrackerEvolutionPluginClass))
+#define TRACKER_EVOLUTION_PLUGIN_GET_CLASS(o)  (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_EVOLUTION_PLUGIN, TrackerEvolutionPluginClass))
+
+G_BEGIN_DECLS
+
+typedef struct TrackerEvolutionPlugin TrackerEvolutionPlugin;
+typedef struct TrackerEvolutionPluginClass TrackerEvolutionPluginClass;
+
+struct TrackerEvolutionPlugin {
+	GObject parent;
+};
+
+struct TrackerEvolutionPluginClass {
+	GObjectClass parent;
+};
+
+GType tracker_evolution_plugin_get_type (void);
+
+void tracker_evolution_plugin_register  (TrackerEvolutionPlugin *object, 
+										 guint64 last_checkout, 
+										 DBusGMethodInvocation *context);
+
+G_END_DECLS
+
+#endif
Index: src/tracker-evolution-plugin/tracker-evolution-plugin.xml
===================================================================
--- src/tracker-evolution-plugin/tracker-evolution-plugin.xml	(revision 0)
+++ src/tracker-evolution-plugin/tracker-evolution-plugin.xml	(revision 0)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<node name="/">
+  <interface name="org.gnome.evolution.metadata.Manager">  
+    <method name="Register">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="t" name="last_checkout" direction="in" />
+    </method>
+  </interface>
+</node>
+
Index: src/tracker-evolution-plugin/liborg-freedesktop-Tracker-evolution-plugin.eplug.xml
===================================================================
--- src/tracker-evolution-plugin/liborg-freedesktop-Tracker-evolution-plugin.eplug.xml	(revision 0)
+++ src/tracker-evolution-plugin/liborg-freedesktop-Tracker-evolution-plugin.eplug.xml	(revision 0)
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<e-plugin-list>
+	<e-plugin id="org.freedesktop.Tracker.evolution_plugin" 
+		type="shlib"
+		location="+EVOPLUG_INSTALL_DIR+/liborg-gnome-sa-junk-plugin.so"
+		domain="+GETTEXT_PACKAGE+"
+		localedir="+LOCALEDIR+"
+		_name="TrackerEvolutionPlugin">
+
+		<_description>Enables support for Tracker.</_description>
+
+		<author name="Philip Van Hoof" email="philip codeminded be"/>
+
+		<!-- hook into the Junk mail filtering -->
+		<hook class="org.gnome.evolution.mail.junk:1.0">
+			<group id="EMJunk" >
+				<item   name="SpamAssassin" 
+				        check_junk="org_freedesktop_Tracker_check_junk" 
+				        report_junk="org_freedesktop_Tracker_report_junk" 
+					report_non_junk="org_freedesktop_Tracker_report_non_junk" 
+					commit_reports="org_freedesktop_Tracker_commit_reports"
+					validate_binary="org_freedesktop_Tracker_validate_binary"/>
+			</group>
+		</hook>
+
+		<!-- hook into the 'mail properties' menu -->
+		<hook class="org.gnome.evolution.mail.config:1.0">
+			<group target="prefs" id="org.gnome.evolution.mail.prefs">
+				<item type="section_table" path="50.tracker/10.options" _label="Tracker Options"/>
+				<item type="item_table" path="50.tracker/20.options" factory="org_freedesktop_Tracker_use_tracker"/>
+			</group>
+		</hook>
+
+		<hook class="org.gnome.evolution.mail.config:1.0">
+			<group target="account" id="org.gnome.evolution.mail.config.accountWizard" 
+				commit="backup_restore_commit" abort="backup_restore_abort">
+				<item type="page" path="0.startup_page.10" factory="backup_restore_page"/>
+			</group>
+		</hook>
+
+	</e-plugin>
+</e-plugin-list>
Index: src/tracker-evolution-plugin/Makefile.am
===================================================================
--- src/tracker-evolution-plugin/Makefile.am	(revision 0)
+++ src/tracker-evolution-plugin/Makefile.am	(revision 0)
@@ -0,0 +1,61 @@
+INCLUDES =						\
+	-I$(top_srcdir)					\
+	-DGETTEXT_PACKAGE="\"$(GETTEXT_PACKAGE)\""	\
+	-DLOCALEDIR="\"$(LOCALEDIR)\""			\
+	$(DBUS_CFLAGS)					\
+	$(EVOPLUG_CFLAGS)
+
+%.eplug.in: %.eplug.xml
+	LC_ALL=C $(INTLTOOL_MERGE) -x -u /tmp $< $@
+
+%.eplug: %.eplug.in
+	sed -e "s%+PLUGIN_INSTALL_DIR+%$(EVOPLUG_INSTALL_DIR)%" \
+	-e "s%+GETTEXT_PACKAGE+%$(GETTEXT_PACKAGE)%" \
+	-e "s%+LOCALEDIR+%$(LOCALEDIR)%" \
+	$< > $@
+
+eplugindir = $(EVOPLUG_INSTALL_DIR)
+
+eplugin_DATA = liborg-freedesktop-Tracker-evolution-plugin.eplug
+
+eplugin_LTLIBRARIES = liborg-freedesktop-Tracker-evolution-plugin.la
+
+liborg_freedesktop_Tracker_evolution_plugin_la_SOURCES = 		\
+	tracker-evolution-plugin.c 			 		\
+	tracker-evolution-plugin.h					\
+	$(marshal_sources)						\
+	$(dbus_sources)
+
+liborg_freedesktop_Tracker_evolution_plugin_la_LDFLAGS = -module -avoid-version
+liborg_freedesktop_Tracker_evolution_plugin_la_LDLIBS = 		\
+	$(EVOPLUG_LIBS)							\
+	$(DBUS_LIBS)
+
+dbus_sources = 								\
+	tracker-evolution-plugin-glue.h
+
+%-glue.h: %.xml
+	$(DBUSBINDINGTOOL) --mode=glib-server --output=$@ --prefix=$(subst -,_,$*) $^
+
+tracker-evolution-marshal.h: tracker-evolution-marshal.list
+	$(GLIB_GENMARSHAL) $< --prefix=tracker_evolution_marshal --header > $@ 
+
+tracker-evolution-marshal.c: tracker-evolution-marshal.list
+	$(GLIB_GENMARSHAL) $< --prefix=tracker_evolution_marshal --body > $@
+
+marshal_sources =							\
+	tracker-evolution-marshal.h					\
+	tracker-evolution-marshal.c
+
+BUILT_SOURCES = 							\
+	$(dbus_sources)							\
+	$(marshal_sources)						\
+	$(eplugin_DATA)
+
+CLEANFILES = $(BUILT_SOURCES) \
+	liborg-freedesktop-Tracker-evolution-plugin.eplug
+
+EXTRA_DIST = 								\
+	$(BUILT_SOURCES)						\
+	tracker-evolution-marshal.list			\
+	org-freedesktop-Tracker-evolution-plugin.eplug.xml
Index: src/tracker-evolution-plugin/tracker-evolution-plugin.c
===================================================================
--- src/tracker-evolution-plugin/tracker-evolution-plugin.c	(revision 0)
+++ src/tracker-evolution-plugin/tracker-evolution-plugin.c	(revision 0)
@@ -0,0 +1,691 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * 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
+ * General Public License for more details.
+ *
+ * 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.
+ *
+ * Authors:
+ *  Philip Van Hoof <philip codeminded be>
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <signal.h>
+#include <string.h>
+#include <pthread.h>
+#include <signal.h>
+#include <time.h>
+
+#include <dbus/dbus-glib-bindings.h>
+
+#include <camel/camel-mime-message.h>
+#include <camel/camel-i18n.h>
+#include <mail/em-junk-hook.h>
+#include <mail/em-utils.h>
+#include <camel/camel-store.h>
+#include <camel/camel-db.h>
+#include <mail/mail-session.h>
+#include <e-util/e-config.h>
+#include <libedataserver/e-account.h>
+#include <libedataserver/e-account-list.h>
+
+#include <gtk/gtk.h>
+
+#include <gconf/gconf-client.h>
+
+#include "tracker-evolution-plugin.h"
+#include "tracker-evolution-plugin-glue.h"
+
+#define DIRKEY "/apps/evolution/mail/Tracker"
+#define DIRKEY_LENGTH (G_N_ELEMENTS (DIRKEY) - 1)
+
+static gboolean enabled = TRUE;
+static DBusGProxy *proxy = NULL;
+static GObject *object = NULL;
+
+#define TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_EVOLUTION_PLUGIN, TrackerEvolutionPluginPrivate))
+
+G_DEFINE_TYPE (TrackerEvolutionPlugin, tracker_evolution_plugin, G_TYPE_OBJECT)
+
+#define TRACKER_TYPE_G_STRV_ARRAY   (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRV))
+
+#ifndef dbus_g_method_get_sender
+gchar* dbus_g_method_get_sender (DBusGMethodInvocation *context);
+#endif
+
+typedef struct {
+	DBusGConnection *connection;
+	GHashTable *registrars;
+	GMutex *mutex;
+} TrackerEvolutionPluginPrivate;
+
+enum {
+	PROP_0,
+	PROP_CONNECTION
+};
+
+
+static void
+tracker_evolution_plugin_finalize (GObject *object)
+{
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (object);
+
+	g_hash_table_destroy (priv->registrars);
+	g_mutex_free (priv->mutex);
+
+	G_OBJECT_CLASS (tracker_evolution_plugin_parent_class)->finalize (object);
+}
+
+static void 
+tracker_evolution_plugin_set_connection (TrackerEvolutionPlugin *object, DBusGConnection *connection)
+{
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (object);
+	priv->connection = connection;
+}
+
+
+static void
+tracker_evolution_plugin_set_property (GObject      *object,
+		      guint         prop_id,
+		      const GValue *value,
+		      GParamSpec   *pspec)
+{
+	switch (prop_id) {
+	case PROP_CONNECTION:
+		tracker_evolution_plugin_set_connection (TRACKER_EVOLUTION_PLUGIN (object),
+						 g_value_get_pointer (value));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+	}
+}
+
+static void
+tracker_evolution_plugin_get_property (GObject    *object,
+			      guint       prop_id,
+			      GValue     *value,
+			      GParamSpec *pspec)
+{
+	TrackerEvolutionPluginPrivate *priv;
+
+	priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (object);
+
+	switch (prop_id) {
+	case PROP_CONNECTION:
+		g_value_set_pointer (value, priv->connection);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+	}
+}
+
+static void
+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));
+}
+
+static void
+tracker_evolution_plugin_init (TrackerEvolutionPlugin *object)
+{
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (object);
+
+	priv->mutex = g_mutex_new ();
+	priv->registrars = g_hash_table_new_full (g_str_hash, g_str_equal,
+						  (GDestroyNotify) g_free, 
+						  (GDestroyNotify) g_object_unref);
+}
+
+static int 
+for_message_in_folder_dbus (gpointer data, int ncol, char **colvalues, char **colnames)
+{
+	static int a = 0;
+
+	if (a > 100) {
+		/* Yield per 100 */
+		g_main_context_iteration (NULL, FALSE);
+		a = 0;
+	}
+
+	a++;
+}
+
+static void
+foreach_message_in_folder (CamelFolderInfo *iter, CamelStore *store, CamelDBSelectCB func, gpointer user_data)
+{
+	while (iter) {
+		CamelException ex;
+
+		camel_exception_init (&ex);
+
+		camel_db_read_message_info_records (store->cdb_r, iter->full_name, 
+						    NULL, func, &ex);
+
+		camel_exception_clear (&ex);
+
+		if (iter->child) {
+			foreach_message_in_folder (iter->child, store, func, user_data);
+		}
+
+		/* Yield per folder */
+		g_main_context_iteration (NULL, FALSE);
+
+		iter = iter->next;
+	}
+
+	/* Yield per account */
+	g_main_context_iteration (NULL, FALSE);
+
+}
+
+static void
+foreach_message_in_account (EAccount *account, CamelDBSelectCB func, gpointer user_data)
+{
+	CamelProvider *provider;
+	CamelStore *store;
+	CamelFolderInfo *iter = NULL;
+	CamelException ex;
+	char *uri;
+
+	if (!account->enabled ||!(uri = account->source->url))
+		return;
+
+	camel_exception_init (&ex);
+	if (!(provider = camel_provider_get(uri, &ex))) {
+		camel_exception_clear (&ex);
+		return;
+	}
+
+	if (!(provider->flags & CAMEL_PROVIDER_IS_STORAGE))
+		return;
+
+	if (!(store = (CamelStore *) camel_session_get_service (session, uri, CAMEL_PROVIDER_STORE, &ex))) {
+		camel_exception_clear (&ex);
+		return;
+	}
+
+	iter = camel_store_get_folder_info (store, "", CAMEL_STORE_FOLDER_INFO_FAST | CAMEL_STORE_FOLDER_INFO_NO_VIRTUAL |
+		CAMEL_STORE_FOLDER_INFO_RECURSIVE, &ex);
+
+	foreach_message_in_folder (iter, store, func, user_data);
+
+	camel_folder_info_free (iter);
+
+	camel_object_unref (store);
+}
+
+
+
+static void
+foreach_message_in_accounts (CamelDBSelectCB func)
+{
+	EAccountList *accounts;
+	GConfClient *gconf;
+
+	gconf = gconf_client_get_default ();
+	accounts = e_account_list_new (gconf);
+
+	if (accounts) {
+		gboolean changed = FALSE;
+		EIterator *it;
+
+		for (it = e_list_get_iterator (E_LIST (accounts)); e_iterator_is_valid (it); e_iterator_next (it)) {
+			EAccount *account = (EAccount *) e_iterator_get (it);
+			foreach_message_in_account (account, func, NULL);
+		}
+
+		g_object_unref (it);
+		g_object_unref (accounts);
+	}
+
+	g_object_unref (gconf);
+
+}
+
+
+static void
+dbus_cb_void_none (DBusGProxy     *proxy,
+		   DBusGProxyCall *call,
+		   gpointer        user_data)
+{
+	GError *error = NULL;
+
+	dbus_g_proxy_end_call (proxy, call, &error,
+			       G_TYPE_INVALID);
+
+	if (error) {
+		g_warning ("%s", error->message);
+		g_error_free (error);
+		return;
+	}
+}
+
+static void
+metadata_set (const gchar *subject, GStrv predicates, GStrv values)
+{
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (object);
+	GHashTableIter iter;
+	gpointer key, value;
+
+	g_mutex_lock (priv->mutex);
+
+	g_hash_table_iter_init (&iter, priv->registrars);
+
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
+		DBusGProxy *registrar = value;
+
+		dbus_g_proxy_begin_call (registrar,
+					 "Set",
+					 dbus_cb_void_none,
+					 NULL, 
+					 NULL,
+					 G_TYPE_STRING, subject,
+					 G_TYPE_STRV, predicates,
+					 G_TYPE_STRV, values,
+					 G_TYPE_INVALID);
+	}
+
+	g_mutex_unlock (priv->mutex);
+
+}
+
+
+static void
+metadata_set_many (GStrv subjects, GPtrArray *predicates, GPtrArray *values)
+{
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (object);
+	GHashTableIter iter;
+	gpointer key, value;
+
+	g_mutex_lock (priv->mutex);
+
+	g_hash_table_iter_init (&iter, priv->registrars);
+
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
+		DBusGProxy *registrar = value;
+
+		dbus_g_proxy_begin_call (registrar,
+					 "SetMany",
+					 dbus_cb_void_none,
+					 NULL, 
+					 NULL,
+					 G_TYPE_STRV, subjects,
+					 TRACKER_TYPE_G_STRV_ARRAY, predicates,
+					 TRACKER_TYPE_G_STRV_ARRAY, values,
+					 G_TYPE_INVALID);
+	}
+
+	g_mutex_unlock (priv->mutex);
+}
+
+
+static void
+metadata_unset (const gchar *subject)
+{
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (object);
+	GHashTableIter iter;
+	gpointer key, value;
+
+	g_mutex_lock (priv->mutex);
+
+	g_hash_table_iter_init (&iter, priv->registrars);
+
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
+		DBusGProxy *registrar = value;
+
+		dbus_g_proxy_begin_call (registrar,
+					 "Unset",
+					 dbus_cb_void_none,
+					 NULL, 
+					 NULL,
+					 G_TYPE_STRING, subject,
+					 G_TYPE_INVALID);
+	}
+
+	g_mutex_unlock (priv->mutex);
+
+}
+
+
+static void
+metadata_unset_many (GStrv subjects)
+{
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (object);
+	GHashTableIter iter;
+	gpointer key, value;
+
+	g_mutex_lock (priv->mutex);
+
+	g_hash_table_iter_init (&iter, priv->registrars);
+
+	while (g_hash_table_iter_next (&iter, &key, &value)) {
+		DBusGProxy *registrar = value;
+
+		dbus_g_proxy_begin_call (registrar,
+					 "UnsetMany",
+					 dbus_cb_void_none,
+					 NULL, 
+					 NULL,
+					 G_TYPE_STRV, subjects,
+					 G_TYPE_INVALID);
+	}
+
+	g_mutex_unlock (priv->mutex);
+
+}
+
+
+gboolean
+org_freedesktop_Tracker_check_junk(EPlugin *ep, EMJunkHookTarget *target)
+{
+	CamelMimeMessage *msg = target->m;
+	const char *sub = camel_mime_message_get_subject (msg);
+
+	g_print ("\ncheck?? %s\n", sub);
+
+	return TRUE;
+}
+
+void
+org_freedesktop_Tracker_report_junk (EPlugin *ep, EMJunkHookTarget *target)
+{
+	CamelMimeMessage *msg = target->m;
+	const char *sub = camel_mime_message_get_subject (msg);
+
+	g_print ("\nreport junk?? %s\n", sub);
+}
+
+void
+org_freedesktop_Tracker_non_junk (EPlugin *ep, EMJunkHookTarget *target)
+{
+	CamelMimeMessage *msg = target->m;
+	const char *sub = camel_mime_message_get_subject (msg);
+
+	g_print ("\nreport no junk?? %s\n", sub);
+
+}
+
+void
+org_freedesktop_Tracker_commit_reports (EPlugin *ep)
+{
+}
+
+void *
+org_freedesktop_Tracker_validate_binary (EPlugin *ep)
+{
+	return "1";
+}
+
+
+
+static void
+disable_plugin (void) 
+{
+	if (proxy) {
+		g_object_unref (proxy);
+		proxy = NULL;
+	}
+
+	if (object) {
+		g_object_unref (object);
+		object = NULL;
+	}
+}
+
+static void
+enable_plugin (void)
+{
+	DBusGConnection *connection;
+	GError *error = NULL;
+	guint result;
+
+	if (proxy && object)
+		return;
+
+	if ((proxy && !object) || (!proxy && object))
+		disable_plugin ();
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+	if (error)
+		goto error_handler;
+
+	proxy = dbus_g_proxy_new_for_name (connection, 
+					   DBUS_SERVICE_DBUS,
+					   DBUS_PATH_DBUS,
+					   DBUS_INTERFACE_DBUS);
+
+	org_freedesktop_DBus_request_name (proxy, MANAGER_SERVICE,
+					   DBUS_NAME_FLAG_DO_NOT_QUEUE,
+					   &result, &error);
+
+	if (error)
+		goto error_handler;
+
+	object = g_object_new (TRACKER_TYPE_EVOLUTION_PLUGIN, 
+			       "connection", connection,
+			       NULL);
+
+	dbus_g_object_type_install_info (G_OBJECT_TYPE (object), 
+					 &dbus_glib_tracker_evolution_plugin_object_info);
+
+	dbus_g_connection_register_g_object (connection, 
+					     MANAGER_PATH, 
+					     object);
+
+	error_handler:
+
+	if (error) {
+		g_critical ("Could not setup DBus, %s\n", error->message);
+		g_error_free (error);
+	}
+
+}
+
+static void
+setting_notify (GConfClient *gconf,
+		guint        cnxn_id,
+		GConfEntry  *entry,
+		void        *data)
+{
+	const char *key;
+	GConfValue *value;
+
+	value = gconf_entry_get_value (entry);
+
+	if (value == NULL) {
+		return;
+	}
+
+	key = gconf_entry_get_key (entry);
+	g_return_if_fail (key != NULL);
+
+	g_return_if_fail (!strncmp (key, DIRKEY, DIRKEY_LENGTH));
+	key += DIRKEY_LENGTH;
+
+	g_return_if_fail (*key == '/');
+	++key;
+
+	if (strcmp (key, "enable_support") == 0) {
+		if (gconf_value_get_bool (value))
+			enable_plugin ();
+		else
+			disable_plugin ();
+	}
+}
+
+
+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 *proxy, TrackerEvolutionPlugin *object)
+{
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (object);
+
+	g_mutex_lock (priv->mutex);
+
+	g_hash_table_foreach_remove (priv->registrars, 
+				     do_remove_or_not,
+				     proxy);
+
+	g_mutex_unlock (priv->mutex);
+}
+
+void 
+tracker_tracker_evolution_plugin_register  (TrackerEvolutionPlugin *object, 
+					    guint64 last_checkout, 
+					    DBusGMethodInvocation *context)
+{
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (object);
+	DBusGProxy *mime_proxy;
+	gchar *sender;
+	gchar *path;
+	guint len;
+	guint i;
+
+	g_mutex_lock (priv->mutex);
+
+	sender = dbus_g_method_get_sender (context);
+	path = g_strdup_printf ("/%s", sender);
+
+	len = strlen (path);
+
+	/* Not sure if this path stuff makes any sense ... but it works */
+
+	for (i = 0; i< len; i++) {
+		if (path[i] == '.')
+			path[i] = '/';
+	}
+
+	mime_proxy = dbus_g_proxy_new_for_name (priv->connection, sender, 
+						path,
+						REGISTRAR_INTERFACE);
+
+	g_free (path);
+
+	g_hash_table_replace (priv->registrars, g_strdup (sender), mime_proxy);
+
+	g_signal_connect (mime_proxy, "destroy",
+			  G_CALLBACK (service_gone),
+			  object);
+
+	g_mutex_unlock (priv->mutex);
+
+	dbus_g_method_return (context);
+}
+
+
+int
+e_plugin_lib_enable (EPluginLib *ep, int enable)
+{
+	GConfClient *gconf;
+	guint result;
+
+	if (enable != 1 || enabled == TRUE) {
+		return 0;
+	}
+
+	enabled = TRUE;
+	gconf = gconf_client_get_default();
+
+	gconf_client_add_dir (gconf,
+			      DIRKEY,
+			      GCONF_CLIENT_PRELOAD_ONELEVEL,
+			      NULL);
+
+	gconf_client_notify_add (gconf,
+				 DIRKEY,
+				 setting_notify,
+				 NULL, NULL, NULL);
+
+	enabled = gconf_client_get_bool (gconf,
+		DIRKEY "/enable_support", NULL);
+
+
+	if (enabled)
+		enable_plugin ();
+	else
+		disable_plugin ();
+
+	g_object_unref (gconf);
+
+	return 0;
+}
+
+
+static void
+enable_cb (GtkWidget *widget, gpointer data)
+{
+	gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+	GConfClient *gconf = gconf_client_get_default();
+
+	gconf_client_set_bool (gconf, data, active, NULL);
+
+	g_object_unref (gconf);
+}
+
+
+GtkWidget *
+org_freedesktop_Tracker_use_tracker (struct _EPlugin *epl, struct _EConfigHookItemFactoryData *data)
+{
+	GtkWidget *check;
+	guint i = ((GtkTable *)data->parent)->nrows;
+
+	if (data->old)
+		return data->old;
+
+	check = gtk_check_button_new_with_mnemonic (_("Enable Tracker support"));
+
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), enabled);
+
+	g_signal_connect (GTK_TOGGLE_BUTTON (check), 
+			  "toggled", G_CALLBACK (enable_cb), 
+			  "/apps/evolution/mail/Tracker/enable_support");
+
+	gtk_table_attach((GtkTable *)data->parent, check, 0, 1, i, i+1, 0, 0, 0, 0);
+	gtk_widget_show (check);
+	return (GtkWidget *)check;
+}
+
+
Index: src/tracker-evolution-plugin/tracker-evolution-marshal.list
===================================================================
Index: configure.ac
===================================================================
--- configure.ac	(revision 2683)
+++ configure.ac	(working copy)
@@ -118,6 +118,8 @@
 LIBGSF_REQUIRED=1.13
 EXEMPI_REQUIRED=1.99.2
 HILDON_THUMBNAIL_REQUIRED=3.0.10
+EVO_REQUIRED=2.25.3
+EDS_REQUIRED=2.25.3
 
 # Library Checks
 PKG_CHECK_MODULES(GLIB2, [glib-2.0 >= $GLIB_REQUIRED])
@@ -170,6 +172,24 @@
 
 AM_CONDITIONAL(HAVE_GCONF, test "$have_gconf" = "yes")
 
+# Check for Evolution's plugin system
+PKG_CHECK_MODULES(EVOPLUG, [
+	evolution-plugin >= $EVO_REQUIRED
+	evolution-data-server-1.2 >= $EDS_REQUIRED], 
+	have_evoplug=yes, have_evoplug=no)
+AC_SUBST(EVOPLUG_CFLAGS)
+AC_SUBST(EVOPLUG_LIBS)
+
+if test x$have_evoplug == "xyes"; then
+EVOPLUG_INSTALL_DIR=`$PKG_CONFIG evolution-plugin --variable=plugindir`
+else
+EVOPLUG_INSTALL_DIR=/dev/null
+fi
+
+AC_SUBST(EVOPLUG_INSTALL_DIR)
+
+AM_CONDITIONAL(HAVE_EVOPLUG, test "$have_evoplug" = "yes")
+
 # Check we have the DBUS binding tool we need
 AC_PATH_PROG(DBUSBINDINGTOOL, dbus-binding-tool)
 if test -z $DBUSBINDINGTOOL; then
@@ -1210,6 +1230,7 @@
 	src/tracker-search-tool/Makefile
 	src/tracker-search-tool/tracker-search-tool.desktop.in
 	src/tracker-utils/Makefile
+	src/tracker-evolution-plugin/Makefile
 	tests/common/Makefile
 	tests/libtracker-common/Makefile
 	tests/libtracker-db/Makefile


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