[tracker/libtracker-miner] Add tracker-miner-discover to find DBus miner services



commit a9e3113dbb460ad24ebf17cf32883165cedfe53d
Author: Martyn Russell <martyn lanedo com>
Date:   Fri Aug 21 11:28:20 2009 +0100

    Add tracker-miner-discover to find DBus miner services
    
    This also makes use of tracker-crawler to find .service files in the
    DBus services directory, the debugging from tracker-crawler was
    unavoidable so the g_debug and g_message statements have been moved to
    tracker-miner-process instead so it can decide if it wants to print
    found/ignored things.
    
    Also the tracker-crawler finished signal now includes WAS_INTERRUPTED
    boolean so we know if it was stopped prematurely.

 src/libtracker-miner/Makefile.am              |    3 +
 src/libtracker-miner/tracker-crawler.c        |   60 +---
 src/libtracker-miner/tracker-marshal.list     |    2 +-
 src/libtracker-miner/tracker-miner-discover.c |  157 +++++++
 src/libtracker-miner/tracker-miner-discover.h |   33 ++
 src/libtracker-miner/tracker-miner-process.c  |   31 ++
 src/tracker-utils/Makefile.am                 |   25 +-
 src/tracker-utils/tracker-status.c            |  546 +++++--------------------
 8 files changed, 356 insertions(+), 501 deletions(-)
---
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index daa4396..bc97147 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -4,6 +4,7 @@ SUBDIRS = . test
 
 INCLUDES =						\
 	-DSHAREDIR=\""$(datadir)"\"			\
+	-DDBUS_SERVICES_DIR=\""$(DBUS_SERVICES_DIR)"\"	\
 	-DG_LOG_DOMAIN=\"Tracker\"			\
 	-DTRACKER_COMPILATION				\
 	-DI_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE	\
@@ -31,6 +32,8 @@ libtracker_miner_la_SOURCES = 				\
 	tracker-miner-dbus.h				\
 	tracker-miner.c					\
 	tracker-miner.h					\
+	tracker-miner-discover.c			\
+	tracker-miner-discover.h			\
 	tracker-miner-process.c				\
 	tracker-miner-process.h				\
 	tracker-monitor.c				\
diff --git a/src/libtracker-miner/tracker-crawler.c b/src/libtracker-miner/tracker-crawler.c
index a7d7c67..b571b37 100644
--- a/src/libtracker-miner/tracker-crawler.c
+++ b/src/libtracker-miner/tracker-crawler.c
@@ -128,9 +128,10 @@ tracker_crawler_class_init (TrackerCrawlerClass *klass)
 			      G_SIGNAL_RUN_LAST,
 			      G_STRUCT_OFFSET (TrackerCrawlerClass, finished),
 			      NULL, NULL,
-			      tracker_marshal_VOID__UINT_UINT_UINT_UINT,
+			      tracker_marshal_VOID__BOOLEAN_UINT_UINT_UINT_UINT,
 			      G_TYPE_NONE,
-			      4,
+			      5,
+			      G_TYPE_BOOLEAN,
 			      G_TYPE_UINT,
 			      G_TYPE_UINT,
 			      G_TYPE_UINT,
@@ -218,30 +219,16 @@ static gboolean
 process_file (TrackerCrawler *crawler,
 	      GFile	     *file)
 {
-	gchar *path;
 	gboolean should_process = TRUE;
 
 	g_signal_emit (crawler, signals[PROCESS_FILE], 0, file, &should_process);
 
-	path = g_file_get_path (file);
-
 	crawler->private->files_found++;
 
-	if (should_process) {
-		g_debug ("Found  :'%s' (%d)",
-			 path,
-			 crawler->private->enumerations);
-
-	} else {
-		g_debug ("Ignored:'%s' (%d)",
-			 path,
-			 crawler->private->enumerations);
-
+	if (!should_process) {
 		crawler->private->files_ignored++;
 	}
 
-	g_free (path);
-	
 	return should_process;
 }
 
@@ -249,31 +236,18 @@ static gboolean
 process_directory (TrackerCrawler *crawler,
 		   GFile	  *file)
 {
-	gchar *path;
 	gboolean should_process = TRUE;
 
 	g_signal_emit (crawler, signals[PROCESS_DIRECTORY], 0, file, &should_process);
 
-	path = g_file_get_path (file);
-
 	crawler->private->directories_found++;
 
 	if (should_process) {
-		g_debug ("Found  :'%s' (%d)",
-			 path,
-			 crawler->private->enumerations);
-
 		file_enumerate_children (crawler, file);
 	} else {
-		g_debug ("Ignored:'%s' (%d)",
-			 path,
-			 crawler->private->enumerations);
-
 		crawler->private->directories_ignored++;
 	}
 
-	g_free (path);
-
 	return should_process;
 }
 
@@ -614,10 +588,9 @@ tracker_crawler_start (TrackerCrawler *crawler,
 	file = g_file_new_for_path (path);
 
 	if (!g_file_query_exists (file, NULL)) {
-		g_message ("NOT crawling directory %s:'%s' - path does not exist",
-			   recurse ? "recursively" : "non-recursively",
-			   path);
-
+		/* g_debug ("NOT crawling directory %s:'%s' - path does not exist", */
+		/* 	 recurse ? "recursively" : "non-recursively", */
+		/* 	 path); */
 		
 		g_object_unref (file);
 
@@ -628,10 +601,10 @@ tracker_crawler_start (TrackerCrawler *crawler,
 		return TRUE;
 	}
 
-	g_message ("Crawling directory %s:'%s'",
-		   recurse ? "recursively" : "non-recursively",
-		   path);
-
+	/* g_debug ("Crawling directory %s:'%s'", */
+	/* 	 recurse ? "recursively" : "non-recursively", */
+	/* 	 path); */
+	
 	/* Time the event */
 	if (priv->timer) {
 		g_timer_destroy (priv->timer);
@@ -668,16 +641,6 @@ tracker_crawler_stop (TrackerCrawler *crawler)
 
 	priv = crawler->private;
 
-	g_message ("%s crawling files in %4.4f seconds",
-		   priv->is_finished ? "Finished" : "Stopped",
-		   g_timer_elapsed (priv->timer, NULL));
-	g_message ("  Found %d directories, ignored %d directories",
-		   priv->directories_found,
-		   priv->directories_ignored);
-	g_message ("  Found %d files, ignored %d files",
-		   priv->files_found,
-		   priv->files_ignored);
-
 	priv->is_running = FALSE;
 
 	if (priv->idle_id) {
@@ -691,6 +654,7 @@ tracker_crawler_stop (TrackerCrawler *crawler)
 	}
 
 	g_signal_emit (crawler, signals[FINISHED], 0,
+		       !priv->is_finished,
 		       priv->directories_found,
 		       priv->directories_ignored,
 		       priv->files_found,
diff --git a/src/libtracker-miner/tracker-marshal.list b/src/libtracker-miner/tracker-marshal.list
index 1cd2675..58ef3c3 100644
--- a/src/libtracker-miner/tracker-marshal.list
+++ b/src/libtracker-miner/tracker-marshal.list
@@ -1,6 +1,6 @@
 VOID:OBJECT,BOOLEAN
 VOID:OBJECT,OBJECT,BOOLEAN,BOOLEAN
-VOID:UINT,UINT,UINT,UINT
+VOID:BOOLEAN,UINT,UINT,UINT,UINT
 VOID:DOUBLE,UINT,UINT,UINT,UINT
 VOID:STRING,DOUBLE
 BOOL:OBJECT,OBJECT
diff --git a/src/libtracker-miner/tracker-miner-discover.c b/src/libtracker-miner/tracker-miner-discover.c
new file mode 100644
index 0000000..8d5aba5
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-discover.c
@@ -0,0 +1,157 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009, 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.
+ */
+
+#include "config.h"
+
+#include <libtracker-common/tracker-dbus.h>
+#include <libtracker-common/tracker-type-utils.h>
+
+#include "tracker-crawler.h"
+#include "tracker-miner.h"
+#include "tracker-miner-discover.h"
+
+GSList *
+tracker_miner_discover_get_available (void)
+{
+	DBusGConnection *connection;
+	DBusGProxy *gproxy;
+	GSList *list;
+	GError *error = NULL;
+	gchar **p, **result;
+	
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+	if (!connection) {
+		g_critical ("Could not connect to the DBus session bus, %s",
+			    error ? error->message : "no error given.");
+		g_clear_error (&error);
+		return NULL;
+	}
+
+	/* The definitions below (DBUS_SERVICE_DBUS, etc) are
+	 * predefined for us to just use (dbus_g_proxy_...)
+	 */
+	gproxy = dbus_g_proxy_new_for_name (connection,
+					    DBUS_SERVICE_DBUS,
+					    DBUS_PATH_DBUS,
+					    DBUS_INTERFACE_DBUS);
+
+	if (!gproxy) {
+		g_critical ("Could not get proxy for DBus service");
+		return NULL;
+	}
+
+	if (!dbus_g_proxy_call (gproxy, "ListNames", &error, 
+				G_TYPE_INVALID, 
+				G_TYPE_STRV, &result, 
+				G_TYPE_INVALID)) {
+		g_critical ("Could not get a list of names registered on the session bus, %s",
+			    error ? error->message : "no error given");
+		g_clear_error (&error);
+		g_object_unref (gproxy);
+		return NULL;
+	}
+
+	g_object_unref (gproxy);
+
+	list = NULL;
+
+	if (result) {
+		for (p = result; *p; p++) {
+			if (g_str_has_prefix (*p, TRACKER_MINER_DBUS_NAME_PREFIX)) {
+				list = g_slist_prepend (list, g_strdup (*p));
+			}
+		}
+
+		list = g_slist_reverse (list);
+
+		g_strfreev (result);
+	}
+
+	return list;
+}
+
+static gboolean
+crawler_process_file_cb (TrackerCrawler *crawler,
+			 GFile          *file,
+			 gpointer        user_data)
+{
+	gchar *basename;
+
+	basename = g_file_get_basename (file);
+
+	if (g_str_has_prefix (basename, TRACKER_MINER_DBUS_NAME_PREFIX)) {
+		GSList **list = user_data;
+
+		*list = g_slist_prepend (*list, g_file_get_path (file));
+
+		g_free (basename);
+		
+		return TRUE;
+	} 
+
+	g_free (basename);
+
+	return FALSE;
+}
+
+static void
+crawler_finished_cb (TrackerCrawler *crawler,
+		     gboolean        was_interrupted,
+		     guint           directories_found, 
+		     guint           directories_ignored, 
+		     guint           files_found, 
+		     guint           files_ignored,
+		     gpointer        user_data)
+{
+	g_main_loop_quit (user_data);
+}
+
+GSList *
+tracker_miner_discover_get_all (void)
+{
+	GSList *list = NULL;
+	GMainLoop *main_loop;
+	TrackerCrawler *crawler;
+
+	crawler = tracker_crawler_new ();
+	if (!crawler) {
+		g_critical ("Couldn't create TrackerCrawler object");
+		return NULL;
+	}
+
+	main_loop = g_main_loop_new (NULL, FALSE);
+
+	g_signal_connect (crawler, "process-file", 
+			  G_CALLBACK (crawler_process_file_cb),
+			  &list);
+	g_signal_connect (crawler, "finished", 
+			  G_CALLBACK (crawler_finished_cb),
+			  main_loop);
+
+	/* Go through service files */
+	tracker_crawler_start (crawler, DBUS_SERVICES_DIR, TRUE);
+
+	g_main_loop_run (main_loop);
+
+	g_object_unref (crawler);
+
+	return g_slist_reverse (list);
+}
diff --git a/src/libtracker-miner/tracker-miner-discover.h b/src/libtracker-miner/tracker-miner-discover.h
new file mode 100644
index 0000000..8695dc4
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-discover.h
@@ -0,0 +1,33 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009, 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.
+ */
+
+#ifndef __TRACKER_MINER_DISCOVER_H__
+#define __TRACKER_MINER_DISCOVER_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+GSList *tracker_miner_discover_get_available (void);
+GSList *tracker_miner_discover_get_all       (void);
+
+G_END_DECLS
+
+#endif /* __TRACKER_MINER_DISCOVER_H__ */
diff --git a/src/libtracker-miner/tracker-miner-process.c b/src/libtracker-miner/tracker-miner-process.c
index 7ff1cbf..b5ca455 100644
--- a/src/libtracker-miner/tracker-miner-process.c
+++ b/src/libtracker-miner/tracker-miner-process.c
@@ -129,6 +129,7 @@ static gboolean       crawler_process_directory_cb (TrackerCrawler      *crawler
 						    GFile               *file,
 						    gpointer             user_data);
 static void           crawler_finished_cb          (TrackerCrawler      *crawler,
+						    gboolean             was_interrupted,
 						    guint                directories_found,
 						    guint                directories_ignored,
 						    guint                files_found,
@@ -1015,18 +1016,28 @@ crawler_process_file_cb (TrackerCrawler *crawler,
 			 gpointer	 user_data)
 {
 	TrackerMinerProcess *process;
+	gchar *path;
 	gboolean should_process;
 
 	process = user_data;
+
+	path = g_file_get_path (file);
+
 	should_process = should_process_file (process, file, FALSE);
 
 	if (should_process) {
+		g_debug ("Found  :'%s'", path);
+
 		/* Add files in queue to our queues to send to the indexer */
 		g_queue_push_tail (process->private->items_created,
 				   g_object_ref (file));
 		item_queue_handlers_set_up (process);
+	} else {
+		g_debug ("Ignored:'%s'", path);
 	}
 
+	g_free (path);
+
 	return should_process;
 }
 
@@ -1036,18 +1047,25 @@ crawler_process_directory_cb (TrackerCrawler *crawler,
 			      gpointer	      user_data)
 {
 	TrackerMinerProcess *process;
+	gchar *path;
 	gboolean should_process;
 	gboolean add_monitor = TRUE;
 
 	process = user_data;
+
+	path = g_file_get_path (file);
 	should_process = should_process_file (process, file, TRUE);
 
 	if (should_process) {
+		g_debug ("Found  :'%s'", path);
+
 		/* FIXME: Do we add directories to the queue? */
 		g_queue_push_tail (process->private->items_created,
 				   g_object_ref (file));
 
 		item_queue_handlers_set_up (process);
+	} else {
+		g_debug ("Ignored:'%s'", path);
 	}
 
 	g_signal_emit (process, signals[MONITOR_DIRECTORY], 0, file, &add_monitor);
@@ -1057,11 +1075,14 @@ crawler_process_directory_cb (TrackerCrawler *crawler,
 		tracker_monitor_add (process->private->monitor, file);
 	}
 
+	g_free (path);
+
 	return should_process;
 }
 
 static void
 crawler_finished_cb (TrackerCrawler *crawler,
+		     gboolean        was_interrupted,
 		     guint	     directories_found,
 		     guint	     directories_ignored,
 		     guint	     files_found,
@@ -1083,6 +1104,16 @@ crawler_finished_cb (TrackerCrawler *crawler,
 	process->private->total_files_found += files_found;
 	process->private->total_files_ignored += files_ignored;
 
+	g_message ("%s crawling files after %2.2f seconds",
+		   was_interrupted ? "Stoped" : "Finished",
+		   g_timer_elapsed (process->private->timer, NULL));
+	g_message ("  Found %d directories, ignored %d directories",
+		   directories_found,
+		   directories_ignored);
+	g_message ("  Found %d files, ignored %d files",
+		   files_found,
+		   files_ignored);
+
 	/* Proceed to next thing to process */
 	process_continue (process);
 }
diff --git a/src/tracker-utils/Makefile.am b/src/tracker-utils/Makefile.am
index 455ca47..5ea9416 100644
--- a/src/tracker-utils/Makefile.am
+++ b/src/tracker-utils/Makefile.am
@@ -6,28 +6,31 @@ INCLUDES =								\
 	-DTRACKER_COMPILATION						\
 	-I$(top_srcdir)/src						\
 	$(WARN_CFLAGS)							\
+	$(GTHREAD_CFLAGS)						\
 	$(GLIB2_CFLAGS)							\
 	$(GCOV_CFLAGS)							\
 	$(GIO_CFLAGS)							\
 	$(DBUS_CFLAGS)
 
 libs = 									\
-	$(top_builddir)/src/libtracker/libtrackerclient- TRACKER_API_VERSION@.la	\
-	$(top_builddir)/src/libtracker-common/libtracker-common.la	\
+	$(top_builddir)/src/libtracker-miner/libtracker-miner.la	\
 	$(top_builddir)/src/libtracker-db/libtracker-db.la		\
+	$(top_builddir)/src/libtracker-common/libtracker-common.la	\
+	$(top_builddir)/src/libtracker/libtrackerclient- TRACKER_API_VERSION@.la \
 	$(GIO_LIBS)							\
 	$(GCOV_LIBS)							\
+	$(GTHREAD_LIBS)							\
 	$(GLIB2_LIBS)
 
-bin_PROGRAMS = 							\
-	tracker-search 						\
-	tracker-stats						\
-	tracker-tag						\
-	tracker-status						\
-	tracker-info						\
-	tracker-processes					\
-	tracker-sparql						\
-	tracker-import
+bin_PROGRAMS = 								\
+	tracker-import							\
+	tracker-info							\
+	tracker-processes						\
+	tracker-search 							\
+	tracker-sparql							\
+	tracker-stats							\
+	tracker-status							\
+	tracker-tag
 
 tracker_search_SOURCES = tracker-search.c
 tracker_search_LDADD = $(libs)
diff --git a/src/tracker-utils/tracker-status.c b/src/tracker-utils/tracker-status.c
index c20d396..52e804d 100644
--- a/src/tracker-utils/tracker-status.c
+++ b/src/tracker-utils/tracker-status.c
@@ -1,6 +1,5 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
- * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
  * Copyright (C) 2008, Nokia
  *
  * This library is free software; you can redistribute it and/or
@@ -32,23 +31,16 @@
 
 #include <libtracker/tracker.h>
 
-#define TRACKER_TYPE_G_STRV_ARRAY  (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRV))
+#include <libtracker-miner/tracker-miner-discover.h>
 
-#define DETAIL_MAX_WIDTH 30
+#define TRACKER_TYPE_G_STRV_ARRAY  (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRV))
 
-#define g_marshal_value_peek_boolean(v)  g_value_get_boolean (v)
-#define g_marshal_value_peek_string(v)	 (char*) g_value_get_string (v)
-#define g_marshal_value_peek_int(v)      g_value_get_int (v)
-#define g_marshal_value_peek_double(v)   g_value_get_double (v)
+/* #define g_marshal_value_peek_boolean(v)  g_value_get_boolean (v) */
+/* #define g_marshal_value_peek_string(v)	 (char*) g_value_get_string (v) */
+/* #define g_marshal_value_peek_int(v)      g_value_get_int (v) */
+/* #define g_marshal_value_peek_double(v)   g_value_get_double (v) */
 
 static GMainLoop *main_loop;
-static gchar     *last_state;   
-static gboolean   last_initial_index;
-static gboolean   last_in_merge;
-static gboolean   last_is_paused_manually;
-static gboolean   last_is_paused_for_bat;
-static gboolean   last_is_paused_for_io;
-static gboolean   last_is_indexing_enabled;
 
 static gboolean   follow;
 static gboolean   detailed;
@@ -65,350 +57,6 @@ static GOptionEntry entries[] = {
 	{ NULL }
 };
 
-static gchar *
-seconds_to_string (gdouble  seconds_elapsed,
-		   gboolean short_string)
-{
-	GString *s;
-	gchar	*str;
-	gdouble  total;
-	gint	 days, hours, minutes, seconds;
-
-	g_return_val_if_fail (seconds_elapsed >= 0.0, g_strdup (_("less than one second")));
-
-	total	 = seconds_elapsed;
-
-	seconds  = (gint) total % 60;
-	total	/= 60;
-	minutes  = (gint) total % 60;
-	total	/= 60;
-	hours	 = (gint) total % 24;
-	days	 = (gint) total / 24;
-
-	s = g_string_new ("");
-
-	if (short_string) {
-		if (days) {
-			g_string_append_printf (s, " %dd", days);
-		}
-
-		if (hours) {
-			g_string_append_printf (s, " %2.2dh", hours);
-		}
-
-		if (minutes) {
-			g_string_append_printf (s, " %2.2dm", minutes);
-		}
-
-		if (seconds) {
-			g_string_append_printf (s, " %2.2ds", seconds);
-		}
-	} else {
-		if (days) {
-			g_string_append_printf (s, " %d day%s",
-						days,
-						days == 1 ? "" : "s");
-		}
-
-		if (hours) {
-			g_string_append_printf (s, " %2.2d hour%s",
-						hours,
-						hours == 1 ? "" : "s");
-		}
-
-		if (minutes) {
-			g_string_append_printf (s, " %2.2d minute%s",
-						minutes,
-						minutes == 1 ? "" : "s");
-		}
-
-		if (seconds) {
-			g_string_append_printf (s, " %2.2d second%s",
-						seconds,
-						seconds == 1 ? "" : "s");
-		}
-	}
-
-	str = g_string_free (s, FALSE);
-
-	if (str[0] == '\0') {
-		g_free (str);
-		str = g_strdup (_("less than one second"));
-	} else {
-		g_strchug (str);
-	}
-
-	return str;
-}
-
-static gchar *
-seconds_estimate_to_string (gdouble  seconds_elapsed,
-			    gboolean short_string,
-			    guint    items_done,
-			    guint    items_remaining)
-{
-	gdouble per_item;
-	gdouble total;
-
-	g_return_val_if_fail (seconds_elapsed >= 0.0, g_strdup (_("unknown time")));
-
-	/* We don't want division by 0 or if total is 0 because items
-	 * remaining is 0 then, equally pointless.
-	 */
-	if (items_done < 1 ||
-	    items_remaining < 1) {
-		return g_strdup (_("unknown time"));
-	}
-
-	per_item = seconds_elapsed / items_done;
-	total = per_item * items_remaining;
-
-	return seconds_to_string (total, short_string);
-}
-
-static void
-index_service_stats_updated (DBusGProxy *proxy,
-                             GPtrArray  *new_stats,
-                             gpointer    user_data)
-{
-	gint i;
-	
-	g_print ("%s:\n", _("Statistics have been updated"));
-
-	for (i = 0; i < new_stats->len; i++) {
-                const gchar **p;
-                const gchar  *service_type = NULL;
-		gchar        *str;
-                
-                p = g_ptr_array_index (new_stats, i);
-                
-                service_type = p[0];
-		
-                if (!service_type) {
-                        continue;
-                }
-		
-		str = g_strdup_printf (_("Updating '%s' with new count:%s"), 
-				       service_type,
-				       p[1]);
-		g_print ("  %s\n", str);
-		g_free (str);
-        }
-}
-
-static void
-index_progress_changed (DBusGProxy  *proxy,
-			const gchar *current_service,
-			const gchar *uri,
-			gint	     items_processed,
-			gint	     items_remaining,
-			gint	     items_total,
-			gdouble      seconds_elapsed,
-			gpointer     user_data)
-{
-	gchar *str1, *str2, *str3;
-
-	str1 = seconds_estimate_to_string (seconds_elapsed,
-					   TRUE,
-					   items_processed,
-					   items_remaining);
-	str2 = seconds_to_string (seconds_elapsed, TRUE);
-
-	str3 = g_strdup_printf (_("Processed %d/%d, current service:'%s', %s left, %s elapsed"),
-				items_processed,
-				items_total,
-				current_service,
-				str1,
-				str2);
-
-	g_free (str2);
-	g_free (str1);
-
-	g_print ("%s\n", str3);
-	g_free (str3);
-
-	if (detailed && uri && *uri) {
-		gchar *str;
-
-		str = g_strdup_printf (_("Last file to be indexed was '%s'"),
-				       uri);
-		g_print ("  %s\n", str);
-		g_free (str);
-	}
-}
-
-static void
-index_state_changed (DBusGProxy  *proxy,
-		     const gchar *state,
-		     gboolean	  initial_index,
-		     gboolean	  in_merge,
-		     gboolean	  is_paused_manually,
-		     gboolean	  is_paused_for_bat,
-		     gboolean	  is_paused_for_io,
-		     gboolean	  is_indexing_enabled,
-		     gpointer     user_data)
-{
-	static gboolean first_change = TRUE;
-	gchar *str;
-	
-	str = g_strdup_printf (_( "Tracker status changed from '%s' --> '%s'"), 
-			       last_state ? last_state : _("None"), 
-			       state);
-	g_print ("%s\n", str);
-	g_free (str);
-
-	if (detailed) {
-		if (first_change || last_initial_index != initial_index) {
-			g_print ("  %-*.*s: %s\n",
-				 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
-				 _("Initial index"),
-				 initial_index ? _("yes") : _("no"));			
-		}
-		
-		if (first_change || last_in_merge != in_merge) {
-			g_print ("  %-*.*s: %s\n",
-				 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
-				 _("In merge"),
-				 in_merge ? _("yes") : _("no"));
-		}
-
-		if (first_change || last_is_paused_manually != is_paused_manually) {
-			g_print ("  %-*.*s: %s\n",
-				 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
-				 _("Is paused manually"),
-				 is_paused_manually ? _("yes") : _("no"));
-		}
-
-		if (first_change || last_is_paused_for_bat != is_paused_for_bat) {
-			g_print ("  %-*.*s: %s\n",
-				 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
-				 _("Is paused for low battery"),
-				 is_paused_for_bat ? _("yes") : _("no"));
-		}
-
-		if (first_change || last_is_paused_for_io != is_paused_for_io) {
-			g_print ("  %-*.*s: %s\n",
-				 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
-				 _("Is paused for IO"),
-				 is_paused_for_io ? _("yes") : _("no"));
-		}
-
-		if (first_change || last_is_indexing_enabled != is_indexing_enabled) {
-			g_print ("  %-*.*s: %s\n",
-				 DETAIL_MAX_WIDTH, DETAIL_MAX_WIDTH,
-				 _("Is indexing enabled"),
-				 is_indexing_enabled ? _("yes") : _("no"));
-		}
-	}
-
-	/* Remember last details so we don't spam the same crap each
-	 * time to console, only updates.
-	 */
-	g_free (last_state);
-	last_state = g_strdup (state);
-
-	last_initial_index = initial_index;
-	last_in_merge = in_merge;
-	last_is_paused_manually = is_paused_manually;
-	last_is_paused_for_bat = is_paused_for_bat;
-	last_is_paused_for_io = is_paused_for_io;
-	last_is_indexing_enabled = is_indexing_enabled;
-	
-	first_change = FALSE;
-}
-
-/* Taken from tracker-applet */
-static void
-tracker_VOID__STRING_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN (GClosure	   *closure,
-							      GValue	   *return_value,
-							      guint	    n_param_values,
-							      const GValue *param_values,
-							      gpointer	    invocation_hint,
-							      gpointer	    marshal_data)
-{
-	typedef void (*GMarshalFunc_VOID__STRING_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN) (gpointer	  data1,
-											   gpointer	  arg_1,
-											   gboolean	  arg_2,
-											   gboolean	  arg_3,
-											   gboolean	  arg_4,
-											   gboolean	  arg_5,
-											   gboolean	  arg_6,
-											   gboolean	  arg_7,
-											   gpointer	  data2);
-	register GMarshalFunc_VOID__STRING_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN callback;
-	register GCClosure *cc = (GCClosure*) closure;
-	register gpointer data1, data2;
-	
-	g_return_if_fail (n_param_values == 8);
-	
-	if (G_CCLOSURE_SWAP_DATA (closure))
-	{
-		data1 = closure->data;
-		data2 = g_value_peek_pointer (param_values + 0);
-	}
-	else
-	{
-		data1 = g_value_peek_pointer (param_values + 0);
-		data2 = closure->data;
-	}
-	callback = (GMarshalFunc_VOID__STRING_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN) (marshal_data ? marshal_data : cc->callback);
-	
-	callback (data1,
-		  g_marshal_value_peek_string (param_values + 1),
-		  g_marshal_value_peek_boolean (param_values + 2),
-		  g_marshal_value_peek_boolean (param_values + 3),
-		  g_marshal_value_peek_boolean (param_values + 4),
-		  g_marshal_value_peek_boolean (param_values + 5),
-		  g_marshal_value_peek_boolean (param_values + 6),
-		  g_marshal_value_peek_boolean (param_values + 7),
-		  data2);
-}
-
-/* VOID:STRING,STRING,INT,INT,INT,DOUBLE (tracker-marshal.list:2) */
-static void
-tracker_VOID__STRING_STRING_INT_INT_INT_DOUBLE (GClosure     *closure,
-						GValue       *return_value G_GNUC_UNUSED,
-						guint         n_param_values,
-						const GValue *param_values,
-						gpointer      invocation_hint G_GNUC_UNUSED,
-						gpointer      marshal_data)
-{
-	typedef void (*GMarshalFunc_VOID__STRING_STRING_INT_INT_INT_DOUBLE) (gpointer     data1,
-									     gpointer     arg_1,
-									     gpointer     arg_2,
-									     gint         arg_3,
-									     gint         arg_4,
-									     gint         arg_5,
-									     gdouble      arg_6,
-									     gpointer     data2);
-	register GMarshalFunc_VOID__STRING_STRING_INT_INT_INT_DOUBLE callback;
-	register GCClosure *cc = (GCClosure*) closure;
-	register gpointer data1, data2;
-	
-	g_return_if_fail (n_param_values == 7);
-	
-	if (G_CCLOSURE_SWAP_DATA (closure))
-	{
-		data1 = closure->data;
-		data2 = g_value_peek_pointer (param_values + 0);
-	}
-	else
-	{
-		data1 = g_value_peek_pointer (param_values + 0);
-		data2 = closure->data;
-	}
-	callback = (GMarshalFunc_VOID__STRING_STRING_INT_INT_INT_DOUBLE) (marshal_data ? marshal_data : cc->callback);
-	
-	callback (data1,
-		  g_marshal_value_peek_string (param_values + 1),
-		  g_marshal_value_peek_string (param_values + 2),
-		  g_marshal_value_peek_int (param_values + 3),
-		  g_marshal_value_peek_int (param_values + 4),
-		  g_marshal_value_peek_int (param_values + 5),
-		  g_marshal_value_peek_double (param_values + 6),
-		  data2);
-}
-
 static void
 signal_handler (int signo)
 {
@@ -428,7 +76,7 @@ signal_handler (int signo)
 	default:
 		if (g_strsignal (signo)) {
 			g_print ("\n");
-			g_print ("Received signal:%d->'%s'",
+			g_print ("Received signal:%d->'%s'\n",
 				 signo,
 				 g_strsignal (signo));
 		}
@@ -439,26 +87,25 @@ signal_handler (int signo)
 static void
 initialize_signal_handler (void)
 {
-#ifndef G_OS_WIN32
 	struct sigaction act;
-	sigset_t	 empty_mask;
+	sigset_t empty_mask;
 
 	sigemptyset (&empty_mask);
 	act.sa_handler = signal_handler;
-	act.sa_mask    = empty_mask;
-	act.sa_flags   = 0;
+	act.sa_mask = empty_mask;
+	act.sa_flags = 0;
 
 	sigaction (SIGTERM, &act, NULL);
-	sigaction (SIGINT,  &act, NULL);
-	sigaction (SIGHUP,  &act, NULL);
-#endif /* G_OS_WIN32 */
+	sigaction (SIGINT, &act, NULL);
+	sigaction (SIGHUP, &act, NULL);
 }
 
 gint
 main (gint argc, gchar *argv[])
 {
 	GOptionContext *context;
-	TrackerClient  *client;
+	DBusGProxy *proxy;
+	TrackerClient *client;
 
 	setlocale (LC_ALL, "");
 
@@ -471,6 +118,12 @@ main (gint argc, gchar *argv[])
 	g_option_context_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
+	g_type_init ();
+	
+	if (!g_thread_supported ()) {
+		g_thread_init (NULL);
+	}
+	
 	client = tracker_connect (FALSE, -1);
 
 	if (!client) {
@@ -480,6 +133,17 @@ main (gint argc, gchar *argv[])
 		return EXIT_FAILURE;
 	}
 
+	GSList *list;
+	list = tracker_miner_discover_get_available ();
+	g_print ("Found %d names\n", g_slist_length (list));
+	g_slist_foreach (list, (GFunc) g_free, NULL);
+	g_slist_free (list);
+
+	list = tracker_miner_discover_get_all ();
+	g_print ("Found %d total\n", g_slist_length (list));
+	g_slist_foreach (list, (GFunc) g_free, NULL);
+	g_slist_free (list);
+
 	if (!follow) {
 		GError *error = NULL;
 		gchar *state;
@@ -504,83 +168,83 @@ main (gint argc, gchar *argv[])
 			g_print ("%s\n", str);
 			g_free (str);
 		}
-	} else {
-		DBusGProxy *proxy;
-
-		g_print ("Press Ctrl+C to end follow of Tracker state\n");
-
-		proxy = client->proxy_statistics;
-
-		/* Set signal handlers */
-		dbus_g_object_register_marshaller (tracker_VOID__STRING_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN,
-						   G_TYPE_NONE,
-						   G_TYPE_STRING,
-						   G_TYPE_BOOLEAN,
-						   G_TYPE_BOOLEAN,
-						   G_TYPE_BOOLEAN,
-						   G_TYPE_BOOLEAN,
-						   G_TYPE_BOOLEAN,
-						   G_TYPE_BOOLEAN,
-						   G_TYPE_INVALID);
-		dbus_g_object_register_marshaller (tracker_VOID__STRING_STRING_INT_INT_INT_DOUBLE,
-						   G_TYPE_NONE,
-						   G_TYPE_STRING,
-						   G_TYPE_STRING,
-						   G_TYPE_INT,
-						   G_TYPE_INT,
-						   G_TYPE_INT,
-						   G_TYPE_DOUBLE,
-						   G_TYPE_INVALID);
-	
-		dbus_g_proxy_add_signal (proxy,
-					 "IndexStateChange",
-					 G_TYPE_STRING,
-					 G_TYPE_BOOLEAN,
-					 G_TYPE_BOOLEAN,
-					 G_TYPE_BOOLEAN,
-					 G_TYPE_BOOLEAN,
-					 G_TYPE_BOOLEAN,
-					 G_TYPE_BOOLEAN,
-					 G_TYPE_INVALID);
-		dbus_g_proxy_add_signal (proxy,
-					 "IndexProgress",
-					 G_TYPE_STRING,
-					 G_TYPE_STRING,
-					 G_TYPE_INT,
-					 G_TYPE_INT,
-					 G_TYPE_INT,
-					 G_TYPE_DOUBLE,
-					 G_TYPE_INVALID);
-		dbus_g_proxy_add_signal (proxy,
-					 "ServiceStatisticsUpdated",
-					 TRACKER_TYPE_G_STRV_ARRAY,
-					 G_TYPE_INVALID);
-				
-		dbus_g_proxy_connect_signal (proxy,
-					     "IndexStateChange",
-					     G_CALLBACK (index_state_changed),
-					     NULL,
-					     NULL);
-		dbus_g_proxy_connect_signal (proxy,
-					     "IndexProgress",
-					     G_CALLBACK (index_progress_changed),
-					     NULL,
-					     NULL);
-		dbus_g_proxy_connect_signal (proxy,
-					     "ServiceStatisticsUpdated",
-					     G_CALLBACK (index_service_stats_updated),
-					     NULL,
-					     NULL);
-
-		initialize_signal_handler ();
-			
-		main_loop = g_main_loop_new (NULL, FALSE);
-		g_main_loop_run (main_loop);
-		g_main_loop_unref (main_loop);
 
-		g_free (last_state);
+		tracker_disconnect (client);
+
+		return EXIT_SUCCESS;
 	}
 
+	g_print ("Press Ctrl+C to end follow of Tracker state\n");
+	
+	proxy = client->proxy_statistics;
+	
+	/* Set signal handlers */
+	/* dbus_g_object_register_marshaller (tracker_VOID__STRING_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN, */
+	/* 				   G_TYPE_NONE, */
+	/* 				   G_TYPE_STRING, */
+	/* 				   G_TYPE_BOOLEAN, */
+	/* 				   G_TYPE_BOOLEAN, */
+	/* 				   G_TYPE_BOOLEAN, */
+	/* 				   G_TYPE_BOOLEAN, */
+	/* 				   G_TYPE_BOOLEAN, */
+	/* 				   G_TYPE_BOOLEAN, */
+	/* 				   G_TYPE_INVALID); */
+	/* dbus_g_object_register_marshaller (tracker_VOID__STRING_STRING_INT_INT_INT_DOUBLE, */
+	/* 				   G_TYPE_NONE, */
+	/* 				   G_TYPE_STRING, */
+	/* 				   G_TYPE_STRING, */
+	/* 				   G_TYPE_INT, */
+	/* 				   G_TYPE_INT, */
+	/* 				   G_TYPE_INT, */
+	/* 				   G_TYPE_DOUBLE, */
+	/* 				   G_TYPE_INVALID); */
+	
+	/* dbus_g_proxy_add_signal (proxy, */
+	/* 			 "IndexStateChange", */
+	/* 				 G_TYPE_STRING, */
+	/* 			 G_TYPE_BOOLEAN, */
+	/* 			 G_TYPE_BOOLEAN, */
+	/* 			 G_TYPE_BOOLEAN, */
+	/* 			 G_TYPE_BOOLEAN, */
+	/* 			 G_TYPE_BOOLEAN, */
+	/* 			 G_TYPE_BOOLEAN, */
+	/* 			 G_TYPE_INVALID); */
+	/* dbus_g_proxy_add_signal (proxy, */
+	/* 			 "IndexProgress", */
+	/* 			 G_TYPE_STRING, */
+	/* 			 G_TYPE_STRING, */
+	/* 			 G_TYPE_INT, */
+	/* 			 G_TYPE_INT, */
+	/* 			 G_TYPE_INT, */
+	/* 			 G_TYPE_DOUBLE, */
+	/* 			 G_TYPE_INVALID); */
+	/* dbus_g_proxy_add_signal (proxy, */
+	/* 			 "ServiceStatisticsUpdated", */
+	/* 			 TRACKER_TYPE_G_STRV_ARRAY, */
+	/* 			 G_TYPE_INVALID); */
+	
+	/* dbus_g_proxy_connect_signal (proxy, */
+	/* 			     "IndexStateChange", */
+	/* 			     G_CALLBACK (index_state_changed), */
+	/* 			     NULL, */
+	/* 			     NULL); */
+	/* dbus_g_proxy_connect_signal (proxy, */
+	/* 			     "IndexProgress", */
+	/* 			     G_CALLBACK (index_progress_changed), */
+	/* 			     NULL, */
+	/* 			     NULL); */
+	/* dbus_g_proxy_connect_signal (proxy, */
+	/* 			     "ServiceStatisticsUpdated", */
+	/* 			     G_CALLBACK (index_service_stats_updated), */
+	/* 			     NULL, */
+	/* 			     NULL); */
+	
+	initialize_signal_handler ();
+	
+	main_loop = g_main_loop_new (NULL, FALSE);
+	g_main_loop_run (main_loop);
+	g_main_loop_unref (main_loop);
+	
 	tracker_disconnect (client);
 
 	return EXIT_SUCCESS;



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