[tracker/miner-wakeup: 3/9] Add DBus method to request a file to be indexed.



commit b40694652d401895c8958e66e1e4a330244783f2
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Aug 19 15:03:43 2010 +0200

    Add DBus method to request a file to be indexed.

 data/dbus/tracker-miner-files-index.xml   |    4 +
 src/miners/fs/tracker-miner-files-index.c |  108 +++++++++++++++++++++++++++++
 src/miners/fs/tracker-miner-files-index.h |    7 ++-
 3 files changed, 118 insertions(+), 1 deletions(-)
---
diff --git a/data/dbus/tracker-miner-files-index.xml b/data/dbus/tracker-miner-files-index.xml
index edee281..cc024e0 100644
--- a/data/dbus/tracker-miner-files-index.xml
+++ b/data/dbus/tracker-miner-files-index.xml
@@ -6,5 +6,9 @@
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg type="as" name="mime_types" direction="in" />
     </method>
+    <method name="IndexFiles">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="s" name="file_uri" direction="in" />
+    </method>
   </interface>
 </node>
diff --git a/src/miners/fs/tracker-miner-files-index.c b/src/miners/fs/tracker-miner-files-index.c
index 003c171..77af08f 100644
--- a/src/miners/fs/tracker-miner-files-index.c
+++ b/src/miners/fs/tracker-miner-files-index.c
@@ -277,3 +277,111 @@ tracker_miner_files_index_reindex_mime_types (TrackerMinerFilesIndex  *object,
 	g_string_free (query, TRUE);
 	g_object_unref (connection);
 }
+
+void
+tracker_miner_files_index_index_files (TrackerMinerFilesIndex    *object,
+                                       gchar                     *file_uri,
+                                       DBusGMethodInvocation     *context,
+                                       GError                   **error)
+{
+	TrackerMinerFilesIndexPrivate *priv;
+	TrackerConfig *config;
+	guint request_id;
+	GFile *file, *parent;
+	GError *err;
+
+	tracker_dbus_async_return_if_fail (file_uri != NULL, context);
+
+	request_id = tracker_dbus_get_next_request_id ();
+	tracker_dbus_request_new (request_id, context, "%s()", __FUNCTION__);
+
+	priv = TRACKER_MINER_FILES_INDEX_GET_PRIVATE (object);
+	file = g_file_new_for_uri (file_uri);
+	parent = g_file_get_parent (file);
+
+	g_object_get (priv->files_miner,
+	              "config", &config,
+	              NULL);
+
+	if (parent) {
+		gboolean found = FALSE;
+		GSList *l;
+
+		if (!tracker_miner_files_check_directory (parent,
+		                                          tracker_config_get_index_recursive_directories (config),
+		                                          tracker_config_get_index_single_directories (config),
+		                                          tracker_config_get_ignored_directory_paths (config),
+		                                          tracker_config_get_ignored_directory_patterns (config))) {
+			err = g_error_new_literal (1, 0, "File is not eligible to be indexed");
+			dbus_g_method_return_error (context, err);
+			tracker_dbus_request_success (request_id, context);
+
+			g_error_free (err);
+
+			return;
+		}
+
+		l = tracker_config_get_index_recursive_directories (config);
+
+		while (l && !found) {
+			GFile *dir;
+
+			dir = g_file_new_for_path ((gchar *) l->data);
+
+			if (g_file_equal (parent, dir) ||
+			    g_file_has_prefix (parent, dir)) {
+				found = TRUE;
+			}
+
+			g_object_unref (dir);
+			l = l->next;
+		}
+
+		l = tracker_config_get_index_single_directories (config);
+
+		while (l && !found) {
+			GFile *dir;
+
+			dir = g_file_new_for_path ((gchar *) l->data);
+
+			if (g_file_equal (parent, dir)) {
+				found = TRUE;
+			}
+
+			g_object_unref (dir);
+			l = l->next;
+		}
+
+		if (!found) {
+			err = g_error_new_literal (1, 0, "File is not eligible to be indexed");
+			dbus_g_method_return_error (context, err);
+			tracker_dbus_request_success (request_id, context);
+
+			g_error_free (err);
+
+			return;
+		}
+
+		g_object_unref (parent);
+	}
+
+	if (!tracker_miner_files_check_file (file,
+	                                     tracker_config_get_ignored_file_paths (config),
+	                                     tracker_config_get_ignored_file_patterns (config))) {
+		err = g_error_new_literal (1, 0, "File is not eligible to be indexed");
+		dbus_g_method_return_error (context, err);
+		tracker_dbus_request_success (request_id, context);
+
+		g_error_free (err);
+
+		return;
+	}
+
+	tracker_miner_fs_file_add (TRACKER_MINER_FS (priv->files_miner), file, TRUE);
+
+	tracker_dbus_request_success (request_id, context);
+	dbus_g_method_return (context);
+
+	g_object_unref (file);
+	g_object_unref (config);
+}
diff --git a/src/miners/fs/tracker-miner-files-index.h b/src/miners/fs/tracker-miner-files-index.h
index c5f0532..94309d4 100644
--- a/src/miners/fs/tracker-miner-files-index.h
+++ b/src/miners/fs/tracker-miner-files-index.h
@@ -50,11 +50,16 @@ struct TrackerMinerFilesIndexClass {
 
 GType                     tracker_miner_files_index_get_type           (void);
 TrackerMinerFilesIndex   *tracker_miner_files_index_new                (TrackerMinerFiles         *miner_files);
-void                      tracker_miner_files_index_reindex_mime_types (TrackerMinerFilesIndex  *object,
+void                      tracker_miner_files_index_reindex_mime_types (TrackerMinerFilesIndex    *object,
 	                                                                gchar                    **mime_types,
 	                                                                DBusGMethodInvocation     *context,
                                                                         GError                   **error);
 
+void                      tracker_miner_files_index_index_files        (TrackerMinerFilesIndex    *object,
+	                                                                gchar                     *file_uri,
+	                                                                DBusGMethodInvocation     *context,
+	                                                                GError                   **error);
+
 G_END_DECLS
 
 #endif /* __TRACKER_STORE_MINER_FILES_INDEX_H__ */



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