Patch - add tracker search engine to Nautilus



Attached is patch and two files to add tracker support to nautilus search.

(the two files go in nautilus/libnautilus-private if anyone wants a play)

If you have a pre release version of Tracker installed then you must delete the ~/.Tracker folder and then install the latest version of tracker from Gnome CVS (cvs name "tracker").

If successfully installed, Nautilus will automatically launch the tracker daemon via dbus activation. It will then proceed to index your home folder which might take a long time (to index a subset of your home folder instead run the tracker daemon manually with the root folder to index as a command line parameter - EG trackerd /home/jamie/documents. You should then edit the tracker.cfg file in ~/.Tracker and set "WatchDirectoryRoots=/home/jamie/documents;" so that all subsequent activations of the tracker daemon only watches/indexes those roots).

Tracker and Nautilus runs together like a dream so happy hunting!

--
Mr Jamie McCracken
http://www.advogato.org/person/jamiemcc/
Index: configure.in
===================================================================
RCS file: /cvs/gnome/nautilus/configure.in,v
retrieving revision 1.652
diff -u -r1.652 configure.in
--- configure.in	20 Dec 2005 15:34:53 -0000	1.652
+++ configure.in	16 Jan 2006 01:56:33 -0000
@@ -20,6 +20,7 @@
 m4_define(startup_notification_minver, 0.8)
 m4_define(exif_minver,                 0.5.12)
 m4_define(beagle_minver,               0.0.12)
+m4_define(tracker_minver,              0.0.1)
 
 AC_INIT(nautilus, 2.13.4,
         [http://bugzilla.gnome.org/enter_bug.cgi?product=nautilus])
@@ -230,6 +231,27 @@
 dnl ==========================================================================
 dnl search implementations
 dnl ****************************
+
+AM_CONDITIONAL(HAVE_TRACKER, false)
+
+dnl libtracker checking
+			    			  
+AC_ARG_ENABLE(tracker, [  --disable-tracker     build without tracker support])
+msg_tracker=no
+if test "x$enable_tracker" != "xno"; then
+	PKG_CHECK_MODULES(TRACKER, tracker >= tracker_minver, [
+		  	  AM_CONDITIONAL(HAVE_TRACKER, true)
+			  AC_DEFINE(HAVE_TRACKER, 1, [Define to enable tracker support])
+			  ]
+                          msg_tracker=yes,
+	          	  [AM_CONDITIONAL(HAVE_TRACKER, false)])
+        AC_SUBST(TRACKER_CFLAGS)
+	AC_SUBST(TRACKER_LIBS)
+fi
+
+dnl ==========================================================================
+
+
 AM_CONDITIONAL(HAVE_BEAGLE, false)
 
 dnl libbeagle checking
@@ -396,6 +418,7 @@
 	prefix:                 ${prefix}
 	source code location:	${srcdir}
 	compiler:		${CC}
+	tracker support:	$msg_tracker
 	beagle support:		$msg_beagle
 
 	profiling support:      ${profiling_support}
Index: libnautilus-private/Makefile.am
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/Makefile.am,v
retrieving revision 1.250
diff -u -r1.250 Makefile.am
--- libnautilus-private/Makefile.am	12 Dec 2005 18:37:44 -0000	1.250
+++ libnautilus-private/Makefile.am	16 Jan 2006 01:56:33 -0000
@@ -8,6 +8,7 @@
 	-I$(top_srcdir)/cut-n-paste-code		\
 	$(CORE_CFLAGS)					\
 	$(DISABLE_DEPRECATED_CFLAGS)			\
+	$(TRACKER_CFLAGS)				\
 	$(BEAGLE_CFLAGS)				\
 	-DDATADIR=\""$(datadir)"\" 			\
 	-DSYSCONFDIR=\""$(sysconfdir)"\" 			\
@@ -29,6 +30,7 @@
 libnautilus_private_la_LIBADD =		\
 	$(dependency_static_libs)	\
 	$(BEAGLE_LIBS)			\
+	$(TRACKER_LIBS)			\
 	$(top_builddir)/libnautilus-extension/libnautilus-extension.la \
 	$(CORE_LIBS)			\
 	$(NULL)
@@ -211,6 +213,14 @@
 libnautilus_private_la_SOURCES += $(BEAGLE_SOURCES)
 endif
 
+TRACKER_SOURCES = \
+	nautilus-search-engine-tracker.c \
+	nautilus-search-engine-tracker.h
+
+if HAVE_TRACKER
+libnautilus_private_la_SOURCES += $(TRACKER_SOURCES)
+endif
+
 $(lib_LTLIBRARIES): $(dependency_static_libs)
 
 $(nautilus_metafile_server_idl_sources): nautilus_metafile_server_idl_stamp
@@ -247,6 +257,7 @@
 	nautilus-marshal.list		\
 	$(schema_in_files)              \
 	$(BEAGLE_SOURCES)		\
+	$(TRACKER_SOURCES)		\
 	$(NULL)
 
 CLEANFILES = \
Index: libnautilus-private/nautilus-search-engine.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-search-engine.c,v
retrieving revision 1.2
diff -u -r1.2 nautilus-search-engine.c
--- libnautilus-private/nautilus-search-engine.c	12 Dec 2005 16:59:10 -0000	1.2
+++ libnautilus-private/nautilus-search-engine.c	16 Jan 2006 01:56:33 -0000
@@ -25,6 +25,7 @@
 #include "nautilus-search-engine.h"
 #include "nautilus-search-engine-beagle.h"
 #include "nautilus-search-engine-simple.h"
+#include "nautilus-search-engine-tracker.h"
 
 #include <eel/eel-gtk-macros.h>
 
@@ -125,6 +126,13 @@
 {
 	NautilusSearchEngine *engine;
 	
+#ifdef HAVE_TRACKER
+	engine = nautilus_search_engine_tracker_new ();
+	if (engine) {
+		return engine;
+	}
+#endif
+
 #ifdef HAVE_BEAGLE
 	engine = nautilus_search_engine_beagle_new ();
 	if (engine) {
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
 * Copyright (C) 2005 Mr Jamie McCracken
 *
 * Nautilus 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.
 *
 * Nautilus 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 program; see the file COPYING.  If not,
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Jamie McCracken <jamiemcc gnome org>
 *
 */

#include <config.h>
#include "nautilus-search-engine-tracker.h"
#include <tracker.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <eel/eel-gtk-macros.h>
#include <eel/eel-glib-extensions.h>



struct NautilusSearchEngineTrackerDetails {
	NautilusQuery 	*query;
	TrackerClient 	*client;
	gboolean 	query_pending;
};


static void  nautilus_search_engine_tracker_class_init       (NautilusSearchEngineTrackerClass *class);
static void  nautilus_search_engine_tracker_init             (NautilusSearchEngineTracker      *engine);

G_DEFINE_TYPE (NautilusSearchEngineTracker,
	       nautilus_search_engine_tracker,
	       NAUTILUS_TYPE_SEARCH_ENGINE);

static NautilusSearchEngineClass *parent_class = NULL;

static void
finalize (GObject *object)
{
	NautilusSearchEngineTracker *tracker;

	tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (object);
	
	if (tracker->details->query) {
		g_object_unref (tracker->details->query);
		tracker->details->query = NULL;
	}

	tracker_disconnect (tracker->details->client);

	g_free (tracker->details);

	EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
}


static void
search_callback (char **results, GError *error, gpointer user_data)
{
	NautilusSearchEngineTracker *tracker;
	char **results_p;
	GList *hit_uris;
	
	tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (user_data);
	hit_uris = NULL;

	tracker->details->query_pending = FALSE;

	if (error) {
		nautilus_search_engine_error ( NAUTILUS_SEARCH_ENGINE (tracker), error->message);
		g_error_free (error);
		return;
	}

	if (!results) {
		return;
	}
	
	for (results_p = results; *results_p; results_p++) {
		
		char *uri;

		uri = gnome_vfs_get_uri_from_local_path ((char *)*results_p);
		if (uri) {
			hit_uris = g_list_prepend (hit_uris, (char *)uri);
		}
	}

	nautilus_search_engine_hits_added (NAUTILUS_SEARCH_ENGINE (tracker), hit_uris);
	nautilus_search_engine_finished (NAUTILUS_SEARCH_ENGINE (tracker));
	g_strfreev  (results);
	eel_g_list_free_deep (hit_uris);

}


static void
nautilus_search_engine_tracker_start (NautilusSearchEngine *engine)
{
	NautilusSearchEngineTracker *tracker;
	GList 	*mimetypes, *l;
	char 	*search_text, *location, *location_uri;
	char 	**mimes;
	int 	i, mime_count;

	tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (engine);

	if (tracker->details->query_pending) {
		return;
	}

	if (tracker->details->query == NULL) {
		return;
	}
	
	search_text = nautilus_query_get_text (tracker->details->query);

	mimetypes = nautilus_query_get_mime_types (tracker->details->query);

	location_uri = nautilus_query_get_location (tracker->details->query);

	if (location_uri) {
		location =  gnome_vfs_get_local_path_from_uri (location_uri);
		g_free (location_uri);
	} else {
		location = NULL;
	}

	mime_count  = g_list_length (mimetypes);

	i = 0;

	/* convert list into array */
	if (mime_count > 0) {

		mimes = g_new (char *, (mime_count + 1));
		
		for (l = mimetypes; l != NULL; l = l->next) {
			mimes[i] = g_strdup (l->data);
			i++;
		}

		mimes[mime_count] = NULL;			

		if (location) {
			tracker_search_metadata_by_text_and_mime_and_location_async (tracker->details->client,
										     search_text, (const char **)mimes, location,
										     search_callback, 
										     tracker);
			g_free (location);
		} else {
			tracker_search_metadata_by_text_and_mime_async (tracker->details->client, 
									search_text, (const char**)mimes, 
									search_callback,
									tracker);
		}

		g_strfreev (mimes);
		

	} else {
		if (location) {
			tracker_search_metadata_by_text_and_location_async (tracker->details->client,
									    search_text, 
									    location, 
								 	    search_callback,
									    tracker);
			g_free (location);
		} else {
			tracker_search_metadata_by_text_async (tracker->details->client, 
							       search_text, 
							       search_callback,
							       tracker);
		}
		
	}

	tracker->details->query_pending = TRUE;
	g_free (search_text);
	eel_g_list_free_deep (mimetypes);
}

static void
nautilus_search_engine_tracker_stop (NautilusSearchEngine *engine)
{
	NautilusSearchEngineTracker *tracker;

	tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (engine);

	if (tracker->details->query && tracker->details->query_pending) {
		tracker_cancel_last_call (tracker->details->client);
		tracker->details->query_pending = FALSE;
	}
}

static gboolean
nautilus_search_engine_tracker_is_indexed (NautilusSearchEngine *engine)
{
	return TRUE;
}

static void
nautilus_search_engine_tracker_set_query (NautilusSearchEngine *engine, NautilusQuery *query)
{
	NautilusSearchEngineTracker *tracker;

	tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (engine);

	if (query) {
		g_object_ref (query);
	}

	if (tracker->details->query) {
		g_object_unref (tracker->details->query);
	}

	tracker->details->query = query;
}

static void
nautilus_search_engine_tracker_class_init (NautilusSearchEngineTrackerClass *class)
{
	GObjectClass *gobject_class;
	NautilusSearchEngineClass *engine_class;

	parent_class = g_type_class_peek_parent (class);

	gobject_class = G_OBJECT_CLASS (class);
	gobject_class->finalize = finalize;

	engine_class = NAUTILUS_SEARCH_ENGINE_CLASS (class);
	engine_class->set_query = nautilus_search_engine_tracker_set_query;
	engine_class->start = nautilus_search_engine_tracker_start;
	engine_class->stop = nautilus_search_engine_tracker_stop;
	engine_class->is_indexed = nautilus_search_engine_tracker_is_indexed;
}

static void
nautilus_search_engine_tracker_init (NautilusSearchEngineTracker *engine)
{
	engine->details = g_new0 (NautilusSearchEngineTrackerDetails, 1);
}


NautilusSearchEngine *
nautilus_search_engine_tracker_new (void)
{
	NautilusSearchEngineTracker *engine;
	TrackerClient *tracker_client;

	tracker_client =  tracker_connect (FALSE);

	if (!tracker_client) {
		return NULL;
	}

	engine = g_object_new (NAUTILUS_TYPE_SEARCH_ENGINE_TRACKER, NULL);

	engine->details->client = tracker_client;

	engine->details->query_pending = FALSE;

	return NAUTILUS_SEARCH_ENGINE (engine);
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
 * Copyright (C) 2005 Mr Jamie McCracken
 *
 * Nautilus 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.
 *
 * Nautilus 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 program; see the file COPYING.  If not,
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Jamie McCracken (jamiemcc gnome org)
 *
 */

#ifndef NAUTILUS_SEARCH_ENGINE_TRACKER_H
#define NAUTILUS_SEARCH_ENGINE_TRACKER_H

#include <libnautilus-private/nautilus-search-engine.h>

#define NAUTILUS_TYPE_SEARCH_ENGINE_TRACKER		(nautilus_search_engine_tracker_get_type ())
#define NAUTILUS_SEARCH_ENGINE_TRACKER(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_SEARCH_ENGINE_TRACKER, NautilusSearchEngineTracker))
#define NAUTILUS_SEARCH_ENGINE_TRACKER_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_SEARCH_ENGINE_TRACKER, NautilusSearchEngineTrackerClass))
#define NAUTILUS_IS_SEARCH_ENGINE_TRACKER(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_SEARCH_ENGINE_TRACKER))
#define NAUTILUS_IS_SEARCH_ENGINE_TRACKER_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_SEARCH_ENGINE_TRACKER))
#define NAUTILUS_SEARCH_ENGINE_TRACKER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_SEARCH_ENGINE_TRACKER, NautilusSearchEngineTrackerClass))

typedef struct NautilusSearchEngineTrackerDetails NautilusSearchEngineTrackerDetails;

typedef struct NautilusSearchEngineTracker {
	NautilusSearchEngine parent;
	NautilusSearchEngineTrackerDetails *details;
} NautilusSearchEngineTracker;

typedef struct {
	NautilusSearchEngineClass parent_class;
} NautilusSearchEngineTrackerClass;

GType nautilus_search_engine_tracker_get_type (void);

NautilusSearchEngine* nautilus_search_engine_tracker_new (void);

#endif /* NAUTILUS_SEARCH_ENGINE_TRACKER_H */


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