[tracker/external-crawler: 3/27] libtracker-miner: FileSystem _new() now takes GFile for root
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/external-crawler: 3/27] libtracker-miner: FileSystem _new() now takes GFile for root
- Date: Fri, 6 Jun 2014 13:56:33 +0000 (UTC)
commit 9dfeee81feaae810769578559ca3b8c494eb35e0
Author: Martyn Russell <martyn lanedo com>
Date: Wed Apr 30 16:59:05 2014 +0100
libtracker-miner: FileSystem _new() now takes GFile for root
If NULL is passed, then it defaults to the behaviour before, which is to use
file:/// as the root node
src/libtracker-miner/tracker-file-notifier.c | 2 +-
src/libtracker-miner/tracker-file-system.c | 86 ++++++++++++++++++---
src/libtracker-miner/tracker-file-system.h | 3 +-
tests/libtracker-miner/tracker-file-system-test.c | 2 +-
4 files changed, 80 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-file-notifier.c b/src/libtracker-miner/tracker-file-notifier.c
index 1162ed9..fb4afbd 100644
--- a/src/libtracker-miner/tracker-file-notifier.c
+++ b/src/libtracker-miner/tracker-file-notifier.c
@@ -1473,7 +1473,7 @@ tracker_file_notifier_init (TrackerFileNotifier *notifier)
}
/* Initialize filesystem and register properties */
- priv->file_system = tracker_file_system_new ();
+ priv->file_system = tracker_file_system_new (NULL);
priv->timer = g_timer_new ();
priv->stopped = TRUE;
diff --git a/src/libtracker-miner/tracker-file-system.c b/src/libtracker-miner/tracker-file-system.c
index 28a5a09..7d9a236 100644
--- a/src/libtracker-miner/tracker-file-system.c
+++ b/src/libtracker-miner/tracker-file-system.c
@@ -33,6 +33,7 @@ static GHashTable *properties = NULL;
struct _TrackerFileSystemPrivate {
GNode *file_tree;
+ GFile *root;
};
struct _FileNodeProperty {
@@ -54,10 +55,15 @@ struct _NodeLookupData {
GNode *node;
};
+enum {
+ PROP_0,
+ PROP_ROOT,
+};
+
static GQuark quark_file_node = 0;
-static void file_weak_ref_notify (gpointer user_data,
- GObject *prev_location);
+static void file_weak_ref_notify (gpointer user_data,
+ GObject *prev_location);
G_DEFINE_TYPE (TrackerFileSystem, tracker_file_system, G_TYPE_OBJECT)
@@ -158,13 +164,13 @@ file_node_data_new (TrackerFileSystem *file_system,
}
static FileNodeData *
-file_node_data_root_new (void)
+file_node_data_root_new (GFile *root)
{
FileNodeData *data;
data = g_slice_new0 (FileNodeData);
- data->uri_prefix = g_strdup ("file:///");
- data->file = g_file_new_for_uri (data->uri_prefix);
+ data->uri_prefix = g_file_get_uri (root);
+ data->file = g_object_ref (root);
data->properties = g_array_new (FALSE, TRUE, sizeof (FileNodeProperty));
data->file_type = G_FILE_TYPE_DIRECTORY;
data->shallow = TRUE;
@@ -337,7 +343,7 @@ file_tree_free_node_foreach (GNode *node,
/* TrackerFileSystem implementation */
static void
-tracker_file_system_finalize (GObject *object)
+file_system_finalize (GObject *object)
{
TrackerFileSystemPrivate *priv;
@@ -350,15 +356,69 @@ tracker_file_system_finalize (GObject *object)
NULL);
g_node_destroy (priv->file_tree);
+ if (!priv->root) {
+ g_object_unref (priv->root);
+ }
+
G_OBJECT_CLASS (tracker_file_system_parent_class)->finalize (object);
}
static void
+file_system_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerFileSystemPrivate *priv;
+
+ priv = TRACKER_FILE_SYSTEM (object)->priv;
+
+ switch (prop_id) {
+ case PROP_ROOT:
+ g_value_set_object (value, priv->root);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+file_system_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerFileSystemPrivate *priv;
+
+ priv = TRACKER_FILE_SYSTEM (object)->priv;
+
+ switch (prop_id) {
+ case PROP_ROOT:
+ priv->root = g_value_dup_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
tracker_file_system_class_init (TrackerFileSystemClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = tracker_file_system_finalize;
+ object_class->finalize = file_system_finalize;
+ object_class->get_property = file_system_get_property;
+ object_class->set_property = file_system_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_ROOT,
+ g_param_spec_object ("root",
+ "Root URL",
+ "The root GFile for the indexing tree",
+ G_TYPE_FILE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (object_class,
sizeof (TrackerFileSystemPrivate));
@@ -377,14 +437,20 @@ tracker_file_system_init (TrackerFileSystem *file_system)
TRACKER_TYPE_FILE_SYSTEM,
TrackerFileSystemPrivate);
- root_data = file_node_data_root_new ();
+ if (priv->root == NULL) {
+ priv->root = g_file_new_for_uri ("file:///");
+ }
+
+ root_data = file_node_data_root_new (priv->root);
priv->file_tree = g_node_new (root_data);
}
TrackerFileSystem *
-tracker_file_system_new (void)
+tracker_file_system_new (GFile *root)
{
- return g_object_new (TRACKER_TYPE_FILE_SYSTEM, NULL);
+ return g_object_new (TRACKER_TYPE_FILE_SYSTEM,
+ "root", root,
+ NULL);
}
static void
diff --git a/src/libtracker-miner/tracker-file-system.h b/src/libtracker-miner/tracker-file-system.h
index 978cf9c..a27a449 100644
--- a/src/libtracker-miner/tracker-file-system.h
+++ b/src/libtracker-miner/tracker-file-system.h
@@ -54,7 +54,8 @@ typedef gboolean (* TrackerFileSystemTraverseFunc) (GFile *file,
GType tracker_file_system_get_type (void) G_GNUC_CONST;
-TrackerFileSystem * tracker_file_system_new (void);
+TrackerFileSystem *
+ tracker_file_system_new (GFile *root);
GFile * tracker_file_system_get_file (TrackerFileSystem *file_system,
GFile *file,
diff --git a/tests/libtracker-miner/tracker-file-system-test.c
b/tests/libtracker-miner/tracker-file-system-test.c
index 968919d..c7919a7 100644
--- a/tests/libtracker-miner/tracker-file-system-test.c
+++ b/tests/libtracker-miner/tracker-file-system-test.c
@@ -42,7 +42,7 @@ static void
test_common_context_setup (TestCommonContext *fixture,
gconstpointer data)
{
- fixture->file_system = tracker_file_system_new ();
+ fixture->file_system = tracker_file_system_new (NULL);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]