[tracker/direct-access: 84/158] libtracker-bus: Implement import{_async}()



commit a753e888ea80a6cf82bad50318a3756f0f7b97b2
Author: Martyn Russell <martyn lanedo com>
Date:   Tue Jul 20 17:26:53 2010 +0100

    libtracker-bus: Implement import{_async}()
    
    tracker-import: Use new libtracker-sparql API

 src/libtracker-bus/tracker-bus.vala |   12 ++++++++++
 src/tracker-utils/tracker-import.c  |   39 ++++++++++++++++++----------------
 2 files changed, 33 insertions(+), 18 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index c6fbde3..350fb2b 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -25,6 +25,11 @@ private interface Tracker.Bus.Resources : GLib.Object {
 	public abstract void sparql_update (string query) throws DBus.Error;
 	[DBus (name = "SparqlUpdate")]
 	public abstract async void sparql_update_async (string query) throws DBus.Error;
+
+	[DBus (name = "Load")]
+	public abstract void import (string uri) throws DBus.Error;
+	[DBus (name = "Load")]
+	public abstract async void import_async (string uri) throws DBus.Error;
 }
 
 [DBus (name = "org.freedesktop.Tracker1.Statistics")]
@@ -103,6 +108,13 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 		yield resources_object.sparql_update_async (sparql);
 	}
 
+	public override void import (File file, Cancellable? cancellable = null) throws GLib.Error {
+		resources_object.import (file.get_uri ());
+	}
+	public async override void import_async (File file, Cancellable? cancellable = null) throws GLib.Error {
+		yield resources_object.import_async (file.get_uri ());
+	}
+
 	public override Sparql.Cursor? statistics (Cancellable? cancellable = null) throws GLib.Error {
 		string[,] results = statistics_object.Get ();
 		return new Tracker.Bus.ArrayCursor ((owned) results, results.length[0], results.length[1]);
diff --git a/src/tracker-utils/tracker-import.c b/src/tracker-utils/tracker-import.c
index 3b78906..7e7c03b 100644
--- a/src/tracker-utils/tracker-import.c
+++ b/src/tracker-utils/tracker-import.c
@@ -29,8 +29,7 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
-#include <libtracker-client/tracker-client.h>
-#include <libtracker-common/tracker-common.h>
+#include <libtracker-sparql/tracker-sparql.h>
 
 #define ABOUT	  \
 	"Tracker " PACKAGE_VERSION "\n"
@@ -60,9 +59,10 @@ static GOptionEntry   entries[] = {
 int
 main (int argc, char **argv)
 {
-	TrackerClient   *client;
-	GOptionContext  *context;
-	gchar          **p;
+	TrackerSparqlConnection *connection;
+	GOptionContext *context;
+        GError *error = NULL;
+	gchar **p;
 
 	setlocale (LC_ALL, "");
 
@@ -102,33 +102,36 @@ main (int argc, char **argv)
 
 	g_option_context_free (context);
 
-	client = tracker_client_new (0, G_MAXINT);
+	g_type_init ();
 
-	if (!client) {
-		g_printerr ("%s\n",
-		            _("Could not establish a D-Bus connection to Tracker"));
+	if (!g_thread_supported ()) {
+		g_thread_init (NULL);
+	}
+
+	connection = tracker_sparql_connection_get (&error);
+
+	if (!connection) {
+		g_printerr ("%s: %s\n",
+		            _("Could not establish a connection to Tracker"),
+		            error ? error->message : _("No error given"));
+		g_clear_error (&error);
 		return EXIT_FAILURE;
 	}
 
 	for (p = filenames; *p; p++) {
 		GError *error = NULL;
-		GFile  *file;
-		gchar  *uri;
+		GFile *file;
 
 		g_print ("%s:'%s'\n",
 		         _("Importing Turtle file"),
 		         *p);
 
 		file = g_file_new_for_commandline_arg (*p);
-		uri = g_file_get_uri (file);
-
-		tracker_resources_load (client, uri, &error);
-
+		tracker_sparql_connection_import (connection, file, NULL, &error);
 		g_object_unref (file);
-		g_free (uri);
 
 		if (error) {
-			g_printerr ("%s, %s\n",
+			g_printerr ("  %s, %s\n",
 			            _("Unable to import Turtle file"),
 			            error->message);
 
@@ -140,7 +143,7 @@ main (int argc, char **argv)
 		g_print ("\n");
 	}
 
-	g_object_unref (client);
+	g_object_unref (connection);
 
 	return EXIT_SUCCESS;
 }



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