[tracker/tracker-0.10] tracker-control: Do not start tracker-store when requesting status



commit 9de2ac5ed2f28a25a89ffa1b3e9e67d253bae541
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Mon Mar 21 14:31:33 2011 +0100

    tracker-control: Do not start tracker-store when requesting status

 src/tracker-control/tracker-control-status.c |   99 +++++++++++++++-----------
 1 files changed, 57 insertions(+), 42 deletions(-)
---
diff --git a/src/tracker-control/tracker-control-status.c b/src/tracker-control/tracker-control-status.c
index cffdc5b..a21c7de 100644
--- a/src/tracker-control/tracker-control-status.c
+++ b/src/tracker-control/tracker-control-status.c
@@ -45,8 +45,9 @@ static gboolean list_common_statuses;
 #define STATUS_OPTIONS_ENABLED() \
 	(status || follow || list_common_statuses)
 
-/* Make sure our statuses are translated (all from libtracker-miner except one) */
-static const gchar *statuses[7] = {
+/* Make sure our statuses are translated (most from libtracker-miner) */
+static const gchar *statuses[8] = {
+	N_("Unavailable"), /* generic */
 	N_("Initializing"),
 	N_("Processingâ?¦"),
 	N_("Fetchingâ?¦"), /* miner/rss */
@@ -211,29 +212,11 @@ static void
 store_print_state (const gchar *status,
                    gdouble      progress)
 {
-	gchar *operation = NULL;
-	gchar *operation_status = NULL;
 	gchar time_str[64];
-	gchar *progress_str;
 	struct tm *local_time;
 	time_t now;
 	size_t len;
 
-	if (status && strstr (status, "-")) {
-		gchar **status_split;
-
-		status_split = g_strsplit (status, "-", 2);
-		if (status_split[0] && status_split[1]) {
-			operation = status_split[0];
-			operation_status = status_split[1];
-			/* Free the array, not the contents */
-			g_free (status_split);
-		} else {
-			/* Free everything */
-			g_strfreev (status_split);
-		}
-	}
-
 	now = time ((time_t *) NULL);
 	local_time = localtime (&now);
 	len = strftime (time_str,
@@ -242,24 +225,49 @@ store_print_state (const gchar *status,
 	                local_time);
 	time_str[len] = '\0';
 
-	if (progress > 0.0 && progress < 1.0) {
-		progress_str = g_strdup_printf ("%-3.0f%%", progress * 100);
-	} else {
-		progress_str = g_strdup_printf ("â??   ");
-	}
+	if (status) {
+		gchar *operation = NULL;
+		gchar *operation_status = NULL;
+		gchar *progress_str;
+
+		if (strstr (status, "-")) {
+			gchar **status_split;
+
+			status_split = g_strsplit (status, "-", 2);
+			if (status_split[0] && status_split[1]) {
+				operation = status_split[0];
+				operation_status = status_split[1];
+				/* Free the array, not the contents */
+				g_free (status_split);
+			} else {
+				/* Free everything */
+				g_strfreev (status_split);
+			}
+		}
 
-	g_print ("%s  %s  %-*.*s    %s %s\n",
-	         time_str,
-	         progress_str,
-	         longest_miner_name_length + paused_length,
-	         longest_miner_name_length + paused_length,
-	         operation ? _(operation) : _(status),
-	         operation_status ? "-" : "",
-	         operation_status ? _(operation_status) : "");
+		if (progress > 0.0 && progress < 1.0) {
+			progress_str = g_strdup_printf ("%-3.0f%%", progress * 100);
+		} else {
+			progress_str = g_strdup_printf ("â??   ");
+		}
 
-	g_free (progress_str);
-	g_free (operation);
-	g_free (operation_status);
+		g_print ("%s  %s  %-*.*s    %s %s\n",
+		         time_str,
+		         progress_str ? progress_str : "    ",
+		         longest_miner_name_length + paused_length,
+		         longest_miner_name_length + paused_length,
+		         (operation ? _(operation) : _(status)),
+		         operation_status ? "-" : "",
+		         operation_status ? _(operation_status) : "");
+
+		g_free (progress_str);
+		g_free (operation);
+		g_free (operation_status);
+	} else {
+		g_print ("%s        %s\n",
+		         time_str,
+		         _("Unavailable"));		
+	}
 }
 
 static void
@@ -269,6 +277,15 @@ store_get_and_print_state (void)
 	const gchar *status = NULL;
 	gdouble progress = -1.0;
 	GError *error = NULL;
+	gchar *owner;
+
+	owner = g_dbus_proxy_get_name_owner (proxy);
+	if (!owner) {
+		/* Name is not owned yet, store is not running */
+		store_print_state (NULL, -1);
+		return;
+	}
+	g_free (owner);
 
 	/* Status */
 	v_status = g_dbus_proxy_call_sync (proxy,
@@ -279,15 +296,15 @@ store_get_and_print_state (void)
 	                                   NULL,
 	                                   &error);
 
-	g_variant_get (v_status, "(&s)", &status);
-
-	if (!status || error) {
+	if (!v_status || error) {
 		g_critical ("Could not retrieve tracker-store status: %s",
 		            error ? error->message : "no error given");
 		g_clear_error (&error);
 		return;
 	}
 
+	g_variant_get (v_status, "(&s)", &status);
+
 	/* Progress */
 	v_progress = g_dbus_proxy_call_sync (proxy,
 	                                     "GetProgress",
@@ -411,7 +428,7 @@ store_init (void)
 	}
 
 	proxy = g_dbus_proxy_new_sync (connection,
-	                               G_DBUS_PROXY_FLAGS_NONE,
+	                               G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
 	                               NULL,
 	                               "org.freedesktop.Tracker1",
 	                               "/org/freedesktop/Tracker1/Status",
@@ -496,8 +513,6 @@ tracker_control_status_run (void)
 
 		g_print ("\n");
 
-		return;
-
 		g_print ("%s:\n", _("Miners"));
 
 		for (l = miners_available; l; l = l->next) {



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