[tracker] Tracker-status: Also provide info about tracker-store status.



commit e993ba5758e8acac58463b806352792071bc06b1
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Mar 29 17:18:39 2010 +0200

    Tracker-status: Also provide info about tracker-store status.

 src/tracker-utils/Makefile.am      |    2 +-
 src/tracker-utils/tracker-status.c |   95 ++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletions(-)
---
diff --git a/src/tracker-utils/Makefile.am b/src/tracker-utils/Makefile.am
index 1733e12..5bacff4 100644
--- a/src/tracker-utils/Makefile.am
+++ b/src/tracker-utils/Makefile.am
@@ -54,7 +54,7 @@ tracker_import_SOURCES = tracker-import.c
 tracker_import_LDADD = $(libs)
 
 dbus_sources = 								\
-	tracker-miner-client.h
+	tracker-busy-notifier-client.h
 
 %-client.h: $(top_srcdir)/data/dbus/%.xml
 	$(AM_V_GEN)$(DBUSBINDINGTOOL) --mode=glib-client --output=$@ --prefix=$(subst -,_,$*) $^
diff --git a/src/tracker-utils/tracker-status.c b/src/tracker-utils/tracker-status.c
index c2cb46c..80bc157 100644
--- a/src/tracker-utils/tracker-status.c
+++ b/src/tracker-utils/tracker-status.c
@@ -33,6 +33,7 @@
 #include <libtracker-miner/tracker-miner.h>
 
 #include "tracker-miner-client.h"
+#include "tracker-busy-notifier-client.h"
 
 #define ABOUT	  \
 	"Tracker " PACKAGE_VERSION "\n"
@@ -44,6 +45,9 @@
 	"\n" \
 	"  http://www.gnu.org/licenses/gpl.txt\n";
 
+static DBusGConnection *connection = NULL;
+static DBusGProxy *proxy = NULL;
+
 static GMainLoop *main_loop;
 static GHashTable *miners_progress;
 static GHashTable *miners_status;
@@ -270,6 +274,51 @@ miner_print_state (TrackerMinerManager *manager,
 }
 
 static void
+store_print_state (void)
+{
+	GError *error = NULL;
+	gdouble progress;
+	gchar *status;
+	gchar time_str[64];
+
+	org_freedesktop_Tracker1_BusyNotifier_get_progress (proxy, &progress, &error);
+
+	if (error) {
+		g_critical ("Couldn't retrieve tracker-store progress: %s\n", error->message);
+		return;
+	}
+
+	org_freedesktop_Tracker1_BusyNotifier_get_status (proxy, &status, &error);
+
+	if (error) {
+		g_critical ("Couldn't retrieve tracker-store status: %s\n", error->message);
+		return;
+	}
+
+	if (detailed) {
+		struct tm *local_time;
+		time_t now;
+		size_t len;
+
+		now = time ((time_t *) NULL);
+		local_time = localtime (&now);
+		len = strftime (time_str,
+		                sizeof (time_str) - 1,
+		                "%d %b %Y, %H:%M:%S:",
+		                local_time);
+		time_str[len] = '\0';
+	} else {
+		time_str[0] = '\0';
+	}
+
+	g_print ("%s: %s  %3.0f%%  %s\n",
+	         _("Store"),
+	         time_str,
+	         progress * 100,
+	         status ? status : "");
+}
+
+static void
 manager_miner_progress_cb (TrackerMinerManager *manager,
                            const gchar         *miner_name,
                            const gchar         *status,
@@ -293,6 +342,15 @@ manager_miner_progress_cb (TrackerMinerManager *manager,
 }
 
 static void
+store_progress_cb (TrackerMinerManager *manager,
+                   const gchar         *status,
+                   gdouble              progress)
+{
+	store_print_state ();
+}
+
+
+static void
 manager_miner_paused_cb (TrackerMinerManager *manager,
                          const gchar         *miner_name)
 {
@@ -332,6 +390,37 @@ miners_progress_destroy_notify (gpointer data)
 	g_slice_free (GValue, value);
 }
 
+static gboolean
+init_store_proxy (void)
+{
+	GError *error = NULL;
+
+	if (connection && proxy) {
+		return TRUE;
+	}
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+	if (error) {
+		g_critical ("Could not connect to the D-Bus session bus, %s",
+		            error ? error->message : "no error given.");
+		g_clear_error (&error);
+		return FALSE;
+	}
+
+	proxy = dbus_g_proxy_new_for_name (connection,
+	                                   "org.freedesktop.Tracker1",
+	                                   "/org/freedesktop/Tracker1/BusyNotifier",
+	                                   "org.freedesktop.Tracker1.BusyNotifier");
+
+	dbus_g_proxy_add_signal (proxy,
+	                         "Progress",
+	                         G_TYPE_STRING,
+	                         G_TYPE_DOUBLE,
+	                         G_TYPE_INVALID);
+	return TRUE;
+}
+
 gint
 main (gint argc, gchar *argv[])
 {
@@ -589,6 +678,9 @@ main (gint argc, gchar *argv[])
 		}
 	}
 
+	init_store_proxy ();
+	store_print_state ();
+
 	g_slist_foreach (miners_available, (GFunc) g_free, NULL);
 	g_slist_free (miners_available);
 
@@ -609,6 +701,9 @@ main (gint argc, gchar *argv[])
 	                  G_CALLBACK (manager_miner_paused_cb), NULL);
 	g_signal_connect (manager, "miner-resumed",
 	                  G_CALLBACK (manager_miner_resumed_cb), NULL);
+	dbus_g_proxy_connect_signal (proxy, "Progress",
+	                             G_CALLBACK (store_progress_cb),
+	                             NULL, NULL);
 
 	initialize_signal_handler ();
 



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