[tracker] TrackerCrawler: Add check-directory-contents signal.



commit a3b9dbb66525a84cd87ae1f4a934b090c1593302
Author: Carlos Garnacho <carlos lanedo com>
Date:   Fri Sep 11 13:26:22 2009 +0200

    TrackerCrawler: Add check-directory-contents signal.
    
    This signal contains both the folder and its children (in a GList), the return
    value will tell TrackerCrawler whether to keep iterating through that folder
    or discard it.

 src/libtracker-miner/tracker-crawler.c    |   50 ++++++++++++++++++++---------
 src/libtracker-miner/tracker-crawler.h    |    3 ++
 src/libtracker-miner/tracker-marshal.list |    1 +
 3 files changed, 39 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-crawler.c b/src/libtracker-miner/tracker-crawler.c
index 0330242..d8eaeeb 100644
--- a/src/libtracker-miner/tracker-crawler.c
+++ b/src/libtracker-miner/tracker-crawler.c
@@ -70,6 +70,7 @@ struct TrackerCrawlerPrivate {
 enum {
 	CHECK_DIRECTORY,
 	CHECK_FILE,
+	CHECK_DIRECTORY_CONTENTS,
 	FINISHED,
 	LAST_SIGNAL
 };
@@ -88,6 +89,9 @@ typedef struct {
 static void     crawler_finalize        (GObject         *object);
 static gboolean check_defaults          (TrackerCrawler  *crawler,
 					 GFile           *file);
+static gboolean check_contents_defaults (TrackerCrawler  *crawler,
+					 GFile           *file,
+					 GList           *contents);
 static void     file_enumerate_next     (GFileEnumerator *enumerator,
 					 EnumeratorData  *ed);
 static void     file_enumerate_children (TrackerCrawler  *crawler,
@@ -107,6 +111,7 @@ tracker_crawler_class_init (TrackerCrawlerClass *klass)
 
 	crawler_class->check_directory = check_defaults;
 	crawler_class->check_file      = check_defaults;
+	crawler_class->check_directory_contents = check_contents_defaults;
 
 	signals[CHECK_DIRECTORY] =
 		g_signal_new ("check-directory",
@@ -130,6 +135,16 @@ tracker_crawler_class_init (TrackerCrawlerClass *klass)
 			      G_TYPE_BOOLEAN,
 			      1,
 			      G_TYPE_FILE);
+	signals[CHECK_DIRECTORY_CONTENTS] =
+		g_signal_new ("check-directory-contents",
+			      G_TYPE_FROM_CLASS (klass),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (TrackerCrawlerClass, check_directory_contents),
+			      tracker_accumulator_check_file,
+			      NULL,
+			      tracker_marshal_BOOLEAN__OBJECT_POINTER,
+			      G_TYPE_BOOLEAN,
+			      2, G_TYPE_FILE, G_TYPE_POINTER);
 	signals[FINISHED] =
 		g_signal_new ("finished",
 			      G_TYPE_FROM_CLASS (klass),
@@ -195,13 +210,21 @@ crawler_finalize (GObject *object)
 	G_OBJECT_CLASS (tracker_crawler_parent_class)->finalize (object);
 }
 
-static gboolean 
+static gboolean
 check_defaults (TrackerCrawler *crawler,
 		GFile          *file)
 {
 	return TRUE;
 }
 
+static gboolean
+check_contents_defaults (TrackerCrawler  *crawler,
+			 GFile           *file,
+			 GList           *contents)
+{
+	return TRUE;
+}
+
 TrackerCrawler *
 tracker_crawler_new (void)
 {
@@ -416,27 +439,24 @@ enumerator_data_process (EnumeratorData *ed)
 	TrackerCrawler *crawler;
 	GHashTableIter iter;
 	EnumeratorChildData *cd;
+	GList *children;
+	gboolean use;
 
 	crawler = ed->crawler;
 
-#ifdef FIX
-	GList *l;
-
-	/* Ignore directory if its contents match something we should ignore */
-	for (l = crawler->private->ignored_directories_with_content; l; l = l->next) {
-		if (g_hash_table_lookup (ed->children, l->data)) {
-			gchar *path;
+	g_hash_table_iter_init (&iter, ed->children);
 
-			path = g_file_get_path (ed->parent);
+	while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &cd)) {
+		children = g_list_prepend (children, cd->child);
+	}
 
-			crawler->private->directories_ignored++;
-			g_debug ("Ignoring directory '%s' since it contains a file named '%s'", path, (gchar *) l->data);
-			g_free (path);
+	g_signal_emit (crawler, signals[CHECK_DIRECTORY_CONTENTS], 0, ed->parent, children, &use);
 
-			return;
-		}
+	if (!use) {
+		/* Directory was ignored based on its content */
+		crawler->private->directories_ignored++;
+		return;
 	}
-#endif
 
 	g_hash_table_iter_init (&iter, ed->children);
 
diff --git a/src/libtracker-miner/tracker-crawler.h b/src/libtracker-miner/tracker-crawler.h
index 6801d7a..c3e730a 100644
--- a/src/libtracker-miner/tracker-crawler.h
+++ b/src/libtracker-miner/tracker-crawler.h
@@ -49,6 +49,9 @@ struct TrackerCrawlerClass {
 					  GFile          *file);
 	gboolean (* check_file)          (TrackerCrawler *crawler,
 					  GFile          *file);
+	gboolean (* check_directory_contents) (TrackerCrawler *crawler,
+					       GFile          *file,
+					       GList          *contents);
 	void     (* finished)            (TrackerCrawler *crawler,
 					  guint           directories_found, 
 					  guint           directories_ignored, 
diff --git a/src/libtracker-miner/tracker-marshal.list b/src/libtracker-miner/tracker-marshal.list
index 265178b..d586289 100644
--- a/src/libtracker-miner/tracker-marshal.list
+++ b/src/libtracker-miner/tracker-marshal.list
@@ -5,4 +5,5 @@ VOID:DOUBLE,UINT,UINT,UINT,UINT
 VOID:STRING,STRING,DOUBLE
 VOID:STRING,DOUBLE
 BOOL:OBJECT,OBJECT
+BOOL:OBJECT,POINTER
 BOOL:OBJECT



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