[tracker/crash-aware-extractor: 1/2] libtracker-miner: Add tracker_decorator_fs_prepend_file()



commit 26ee1130e6ed48b315a7d44bed3a8f96aea2e7e7
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jul 23 23:48:04 2014 +0200

    libtracker-miner: Add tracker_decorator_fs_prepend_file()
    
    This is a convenience function that retrieves the tracker:id for the
    file nie:url and prepends it for processing.

 .../libtracker-miner/libtracker-miner-sections.txt |    1 +
 src/libtracker-miner/tracker-decorator-fs.c        |   50 ++++++++++++++++++++
 src/libtracker-miner/tracker-decorator-fs.h        |    3 +
 3 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/libtracker-miner/libtracker-miner-sections.txt 
b/docs/reference/libtracker-miner/libtracker-miner-sections.txt
index 241681f..42f38d6 100644
--- a/docs/reference/libtracker-miner/libtracker-miner-sections.txt
+++ b/docs/reference/libtracker-miner/libtracker-miner-sections.txt
@@ -58,6 +58,7 @@ tracker_decorator_info_get_type
 <TITLE>TrackerDecoratorFS</TITLE>
 TrackerDecoratorFS
 TrackerDecoratorFSClass
+tracker_decorator_fs_prepend_file
 <SUBSECTION Standard>
 TRACKER_DECORATOR_FS
 TRACKER_DECORATOR_FS_CLASS
diff --git a/src/libtracker-miner/tracker-decorator-fs.c b/src/libtracker-miner/tracker-decorator-fs.c
index 1916ea8..69d16bc 100644
--- a/src/libtracker-miner/tracker-decorator-fs.c
+++ b/src/libtracker-miner/tracker-decorator-fs.c
@@ -227,3 +227,53 @@ tracker_decorator_fs_init (TrackerDecoratorFS *decorator)
 {
        decorator->priv = TRACKER_DECORATOR_FS_GET_PRIVATE (decorator);
 }
+
+/**
+ * tracker_decorator_fs_prepend_file:
+ * @decorator: a #TrackerDecoratorFS
+ * @file: a #GFile to process
+ *
+ * Prepends a file for processing.
+ *
+ * Returns: the tracker:id of the element corresponding to the file
+ *
+ * Since: 1.2
+ **/
+gint
+tracker_decorator_fs_prepend_file (TrackerDecoratorFS *decorator,
+                                   GFile              *file)
+{
+       TrackerSparqlConnection *sparql_conn;
+       TrackerSparqlCursor *cursor;
+       gchar *query, *uri;
+       gint id, class_id;
+
+       g_return_val_if_fail (TRACKER_IS_DECORATOR_FS (decorator), 0);
+       g_return_val_if_fail (G_IS_FILE (file), 0);
+
+       uri = g_file_get_uri (file);
+       query = g_strdup_printf ("SELECT tracker:id(?urn) tracker:id(?type) {"
+                                "  ?urn a ?type; nie:url \"%s\" "
+                                "}", uri);
+       g_free (uri);
+
+       sparql_conn = tracker_miner_get_connection (TRACKER_MINER (decorator));
+       cursor = tracker_sparql_connection_query (sparql_conn, query,
+                                                 NULL, NULL);
+       g_free (query);
+
+       if (!cursor)
+               return 0;
+
+       if (!tracker_sparql_cursor_next (cursor, NULL, NULL))
+               return 0;
+
+       id = tracker_sparql_cursor_get_integer (cursor, 0);
+       class_id = tracker_sparql_cursor_get_integer (cursor, 1);
+
+       tracker_decorator_prepend_id (TRACKER_DECORATOR (decorator),
+                                     id, class_id);
+       g_object_unref (cursor);
+
+       return id;
+}
diff --git a/src/libtracker-miner/tracker-decorator-fs.h b/src/libtracker-miner/tracker-decorator-fs.h
index 984c813..2afc205 100644
--- a/src/libtracker-miner/tracker-decorator-fs.h
+++ b/src/libtracker-miner/tracker-decorator-fs.h
@@ -65,6 +65,9 @@ struct _TrackerDecoratorFSClass {
 
 GType              tracker_decorator_fs_get_type (void) G_GNUC_CONST;
 
+gint               tracker_decorator_fs_prepend_file (TrackerDecoratorFS *decorator,
+                                                      GFile              *file);
+
 G_END_DECLS
 
 #endif /* __LIBTRACKER_MINER_DECORATOR_FS_H__ */


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