[tracker/libtracker-sparql-porting: 14/34] tracker-stats: Reworked to use libtracker-sparql



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

    tracker-stats: Reworked to use libtracker-sparql

 src/tracker-utils/tracker-stats.c |   79 ++++++++++++++++++-------------------
 1 files changed, 39 insertions(+), 40 deletions(-)
---
diff --git a/src/tracker-utils/tracker-stats.c b/src/tracker-utils/tracker-stats.c
index 3b215c1..f6c9ecb 100644
--- a/src/tracker-utils/tracker-stats.c
+++ b/src/tracker-utils/tracker-stats.c
@@ -28,12 +28,12 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
-#include <libtracker-client/tracker-client.h>
+#include <libtracker-sparql/tracker-sparql.h>
 
-#define ABOUT	  \
+#define ABOUT \
 	"Tracker " PACKAGE_VERSION "\n"
 
-#define LICENSE	  \
+#define LICENSE \
 	"This program is free software and comes without any warranty.\n" \
 	"It is licensed under version 2 or later of the General Public " \
 	"License which can be viewed at:\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,56 @@ 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);
+	}
+
+	connection = tracker_sparql_connection_get (&error);
 
-	if (!client) {
-		g_printerr ("%s\n",
-		            _("Could not establish a D-Bus connection to Tracker"));
+	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) {
-		g_print ("%s\n",
-		         _("No statistics available"));
+	if (!cursor) {
+		g_print ("%s\n", _("No statistics available"));
 	} else {
-		g_print ("%s\n",
-		         _("Statistics:"));
+		gint count = 0;
+
+		g_print ("%s\n", _("Statistics:"));
+
+		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_ptr_array_foreach (array, (GFunc) get_meta_table_data, NULL);
-		g_ptr_array_free (array, TRUE);
+		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]