[tracker/pushplugin] Estimates for the progress



commit c361e7a05a93fbd5ba1297e57e5129085fd3ff9e
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Sep 22 15:05:44 2009 +0200

    Estimates for the progress

 src/plugins/evolution/tracker-evolution-plugin.c |  199 +++++++++++++++++-----
 1 files changed, 160 insertions(+), 39 deletions(-)
---
diff --git a/src/plugins/evolution/tracker-evolution-plugin.c b/src/plugins/evolution/tracker-evolution-plugin.c
index 0f88659..82a72b3 100644
--- a/src/plugins/evolution/tracker-evolution-plugin.c
+++ b/src/plugins/evolution/tracker-evolution-plugin.c
@@ -164,6 +164,9 @@ typedef struct {
 	TrackerClient *client;
 	DBusGProxy *dbus_proxy;
 	DBusGConnection *connection;
+	time_t last_time;
+	gboolean resuming, paused;
+	guint total_popped;
 } TrackerEvolutionPluginPrivate;
 
 typedef struct {
@@ -748,6 +751,12 @@ on_folder_summary_changed (CamelFolder *folder,
 
 				send_sparql_update (info->self, tracker_sparql_builder_get_result (sparql));
 
+
+				g_object_set (info->self, "progress", 
+				              (gdouble) (merged->len - i) / merged->len,
+				              "status", _("Updating"), 
+				              NULL);
+
 				g_object_unref (sparql);
 
 				g_free (uri);
@@ -784,6 +793,11 @@ on_folder_summary_changed (CamelFolder *folder,
 
 	send_sparql_commit (info->self, TRUE);
 
+	g_object_set (info->self, "progress", 
+	              1.0,
+	              "status", _("Updating"), 
+	              NULL);
+
 	g_free (em_uri);
 }
 
@@ -796,6 +810,22 @@ queued_set_free (QueuedSet *queued_set)
 	g_slice_free (QueuedSet, queued_set);
 }
 
+static void
+clean_many_queue (void)
+{
+	gint i;
+
+	if (!many_queue) {
+		return;
+	}
+
+	for (i = 0; i < many_queue->length; i++) {
+		QueuedSet *remove_candidate;
+		remove_candidate = g_queue_peek_nth (many_queue, i);
+		queued_set_free (g_queue_pop_nth (many_queue, i));
+	}
+}
+
 static gboolean 
 many_idle_handler (gpointer user_data)
 {
@@ -823,21 +853,38 @@ many_idle_handler (gpointer user_data)
 		
 		if (priv->client) {
 			const gchar *query;
+			guint len = g_queue_get_length (many_queue);
 
 			query = tracker_sparql_builder_get_result (queued_set->sparql);
+			priv->total_popped++;
+
+			if (priv->total_popped > len) {
+				priv->total_popped = 0;
+			}
+
+			if (len > 0) {
+				g_object_set (user_data, "progress", 
+				              (gdouble) (len - priv->total_popped) / len,
+				              "status", _("Updating"), 
+				              NULL);
+			} else {
+				g_object_set (user_data, "progress", 
+				              1.0,
+				              "status", _("Updating"), 
+				              NULL);
+			}
 
 			send_sparql_update (user_data, query);
 		} else {
-			gint i;
-			
 			/* Performance improvement: remove all that had 
 			 * this disconnected registrar from the queue */
-			
-			for (i = 0; i < many_queue->length; i++) {
-				QueuedSet *remove_candidate;
-				remove_candidate = g_queue_peek_nth (many_queue, i);
-				queued_set_free (g_queue_pop_nth (many_queue, i));
-			}
+
+			g_object_set (user_data, "progress", 
+			              1.0,  
+			              "status", _("Finishing"), 
+			              NULL);
+
+			clean_many_queue ();
 		}
 
 		queued_set_free (queued_set);
@@ -1656,38 +1703,49 @@ register_client (TrackerEvolutionPlugin *self)
 	guint64 too_old = get_last_deleted_time (self);
 	ClientRegistry *info = g_slice_new0 (ClientRegistry);
 	GError *error = NULL;
-	GPtrArray *results;
-	const gchar *query;
-	guint i;
 
 	if (!priv->client) {
 		return;
 	}
 
-	query = "SELECT ?c "
-		"WHERE { <" DATASOURCE_URN "> nie:contentLastModified ?c }";
+	priv->total_popped = 0;
 
-	results = tracker_resources_sparql_query (priv->client, query, &error);
+	if (!priv->resuming) {
+		GPtrArray *results;
+		const gchar *query;
+		guint i;
 
-	if (error) {
-		g_warning ("%s\n", error->message);
-		g_error_free (error);
-		return;
-	}
+		query = "SELECT ?c "
+			"WHERE { <" DATASOURCE_URN "> nie:contentLastModified ?c }";
 
-	if (!results) {
-		info->last_checkout = 0;
-	} else {
+		results = tracker_resources_sparql_query (priv->client, query, &error);
 
-		for (i = 0; i < results->len; i++) {
-			const gchar **str = g_ptr_array_index (results, i);
-			info->last_checkout = (guint64) tracker_string_to_date (str[0]);
-			break;
+		if (error) {
+			g_warning ("%s\n", error->message);
+			g_error_free (error);
+			return;
 		}
-	}
 
-	g_ptr_array_foreach (results, (GFunc) g_strfreev, NULL);
-	g_ptr_array_free (results, TRUE);
+		if (!results) {
+			info->last_checkout = 0;
+		} else {
+
+			for (i = 0; i < results->len; i++) {
+				const gchar **str = g_ptr_array_index (results, i);
+				info->last_checkout = (guint64) tracker_string_to_date (str[0]);
+				break;
+			}
+		}
+
+		g_ptr_array_foreach (results, (GFunc) g_strfreev, NULL);
+		g_ptr_array_free (results, TRUE);
+	} else {
+		/* This happens in case of resume, for example (which is just a 
+		 * complete restart. So we just get the same E-mails that we had
+		 * already) */
+
+		info->last_checkout = priv->last_time;
+	}
 
 	/* If registrar's modseq is too old, send Cleanup (). This means that
 	 * we tell it to start over (it must invalidate what it has). */
@@ -1701,6 +1759,8 @@ register_client (TrackerEvolutionPlugin *self)
 		info->last_checkout = 0;
 	}
 
+	priv->last_time = info->last_checkout;
+
 	introduce_accounts_to (self, info);
 
 	priv->registered_clients = 
@@ -2125,6 +2185,10 @@ tracker_evolution_plugin_init (TrackerEvolutionPlugin *plugin)
 
 	g_static_rec_mutex_lock (priv->mutex);
 
+	priv->last_time = 0;
+	priv->resuming = FALSE;
+	priv->paused = FALSE;
+
 	priv->cached_folders = NULL;
 	priv->registered_folders = NULL;
 	priv->registered_stores = NULL;
@@ -2178,19 +2242,31 @@ dbus_connect_closure (gpointer data, GClosure *closure)
 
 
 static void
-miner_started (TrackerMiner *miner)
+listnames_fini (gpointer data)
 {
-	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (miner);
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (data);
 
 	dbus_g_proxy_connect_signal (priv->dbus_proxy, "NameOwnerChanged",
 	                             G_CALLBACK (name_owner_changed_cb),
-	                             g_object_ref (miner),
+	                             g_object_ref (data),
 	                             dbus_connect_closure);
 
+	g_object_unref (data);
+}
+
+static void
+miner_started (TrackerMiner *miner)
+{
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (miner);
+
+	if (!priv->client) {
+		priv->client = tracker_connect (FALSE, G_MAXINT);
+	}
+
 	dbus_g_proxy_begin_call (priv->dbus_proxy, "ListNames",
 	                         list_names_reply_cb, 
 	                         g_object_ref (miner),
-	                         (GDestroyNotify) g_object_unref,
+	                         listnames_fini,
 	                         G_TYPE_INVALID,
 	                         G_TYPE_INVALID);
 
@@ -2214,22 +2290,67 @@ miner_paused (TrackerMiner *miner)
 {
 	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (miner);
 
-	// Pause 
+	/* We don't really pause, we just completely stop */
 
 	dbus_g_proxy_disconnect_signal (priv->dbus_proxy, "NameOwnerChanged",
 	                                G_CALLBACK (name_owner_changed_cb),
 	                                miner);
+
+	/* We'll just get rid of all that are in the current queue */
+
+	clean_many_queue ();
+
+	priv->paused = TRUE;
+
+	if (priv->client) {
+		tracker_disconnect (priv->client);
+
+		/* By setting this to NULL, events will still be catched by our
+		 * handlers, but the send_sparql_* calls will just ignore it. 
+		 * This is fine as a solution (at least for now). It allows us
+		 * to avoid having to unregister everything and risk the chance
+		 * of missing something (like a folder or account creation). */
+
+		priv->client = NULL;
+	}
+
 }
 
 static void
-miner_resumed (TrackerMiner *miner)
+resuming_fini (gpointer data)
 {
-	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (miner);
-
-	// Resume
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (data);
+	priv->resuming = FALSE;
 
 	dbus_g_proxy_connect_signal (priv->dbus_proxy, "NameOwnerChanged",
 	                             G_CALLBACK (name_owner_changed_cb),
-	                             g_object_ref (miner),
+	                             g_object_ref (data),
 	                             dbus_connect_closure);
+
+	g_object_unref (data);
+}
+
+static void
+miner_resumed (TrackerMiner *miner)
+{
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (miner);
+
+	/* We don't really resume, we just completely restart */
+
+	priv->resuming = TRUE;
+	priv->paused = FALSE;
+	priv->total_popped = 0;
+
+	if (!priv->client) {
+		priv->client = tracker_connect (FALSE, G_MAXINT);
+	}
+
+	g_object_set (miner,  "progress", 0.0,  "status", _("Resuming"), NULL);
+
+	dbus_g_proxy_begin_call (priv->dbus_proxy, "ListNames",
+	                         list_names_reply_cb, 
+	                         g_object_ref (miner),
+	                         resuming_fini,
+	                         G_TYPE_INVALID,
+	                         G_TYPE_INVALID);
 }



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