[tracker/direct-access: 55/90] libtracker-sparql: Added statistics{_async} virtual methods



commit 6cbad6787bef1ccc2364b149a8b30ab8cc53934e
Author: Martyn Russell <martyn lanedo com>
Date:   Tue Jul 20 17:06:15 2010 +0100

    libtracker-sparql: Added statistics{_async} virtual methods
    
    libtracker-bus: Implement d-bus version of statistics API
    tracker-stats: Reworked to use libtracker-sparql

 src/tracker-utils/tracker-stats.c |   69 +++++++++++++++++++------------------
 1 files changed, 35 insertions(+), 34 deletions(-)
---
diff --git a/src/tracker-utils/tracker-stats.c b/src/tracker-utils/tracker-stats.c
index 3b215c1..7b5d9f5 100644
--- a/src/tracker-utils/tracker-stats.c
+++ b/src/tracker-utils/tracker-stats.c
@@ -28,7 +28,7 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
-#include <libtracker-client/tracker-client.h>
+#include <libtracker-sparql/tracker-sparql.h>
 
 #define ABOUT	  \
 	"Tracker " PACKAGE_VERSION "\n"
@@ -50,33 +50,13 @@ static GOptionEntry entries[] = {
 	{ NULL }
 };
 
-static void
-get_meta_table_data (gpointer value)
-{
-	gchar **meta;
-	gchar **p;
-	gint    i;
-
-	meta = value;
-
-	for (p = meta, i = 0; *p; p++, i++) {
-		if (i == 0) {
-			g_print ("  %s", *p);
-		} else {
-			g_print (" = %s", *p);
-		}
-	}
-
-	g_print ("\n");
-}
-
 int
 main (int argc, char **argv)
 {
-	TrackerClient  *client;
+	TrackerSparqlConnection *connection;
+	TrackerSparqlCursor *cursor;
 	GOptionContext *context;
-	GPtrArray      *array;
-	GError         *error = NULL;
+	GError *error = NULL;
 
 	setlocale (LC_ALL, "");
 
@@ -99,37 +79,58 @@ main (int argc, char **argv)
 
 	g_option_context_free (context);
 
-	client = tracker_client_new (0, G_MAXINT);
+	g_type_init ();
+
+	if (!g_thread_supported ()) {
+		g_thread_init (NULL);
+	}
 
-	if (!client) {
-		g_printerr ("%s\n",
-		            _("Could not establish a D-Bus connection to Tracker"));
+	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;
 	}
 
-	array = tracker_statistics_get (client, &error);
+        cursor = tracker_sparql_connection_statistics (connection, NULL, &error);
 
 	if (error) {
 		g_printerr ("%s, %s\n",
 		            _("Could not get Tracker statistics"),
 		            error->message);
 		g_error_free (error);
-
 		return EXIT_FAILURE;
 	}
 
-	if (!array) {
+	if (!cursor) {
 		g_print ("%s\n",
 		         _("No statistics available"));
 	} else {
+                gint count = 0;
+
 		g_print ("%s\n",
 		         _("Statistics:"));
 
-		g_ptr_array_foreach (array, (GFunc) get_meta_table_data, NULL);
-		g_ptr_array_free (array, TRUE);
+                while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+                        g_print ("  %s = %s\n",
+                                 tracker_sparql_cursor_get_string (cursor, 0, NULL),
+                                 tracker_sparql_cursor_get_string (cursor, 1, NULL));
+                        count++;
+                }
+
+                if (count == 0) {
+                        g_print ("  %s\n", _("None"));
+                }
+
+                g_print ("\n");
+
+                g_object_unref (cursor);
 	}
 
-	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]