[packagekit] packagekit: Branch 'master' - 2 commits

Richard Hughes hughsient at kemper.freedesktop.org
Tue Oct 23 14:13:34 PDT 2007


 client/pk-console.c       |   59 ++++++++++------
 libpackagekit/pk-client.c |  167 ++++++++--------------------------------------
 libpackagekit/pk-client.h |   11 +--
 src/pk-backend-internal.h |    9 +-
 src/pk-backend.c          |   99 +++++++++++++--------------
 src/pk-engine.c           |  121 +++++----------------------------
 src/pk-engine.h           |    5 +
 src/pk-interface.xml      |   22 ++----
 src/pk-marshal.list       |    2 
 9 files changed, 163 insertions(+), 332 deletions(-)

New commits:
commit 36437250b2058dfb30f7430f8147cf36aff60020
Merge: 0a6535d... 7c8859a...
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 23 22:10:34 2007 +0100

    Merge branch 'progress'

commit 7c8859ab633ab2e9077021b36c264dab4f595f79
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Oct 23 18:01:26 2007 +0100

    switch the discrete GetPercentage and
    GetSubPercentage to a GetProgress method
    that allows us to report remaining and elapsed time
    into the UI

diff --git a/client/pk-console.c b/client/pk-console.c
index 5aa1e1a..8805194 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -179,12 +179,18 @@ pk_console_repo_detail_cb (PkClient *client, const gchar *repo_id,
  * pk_console_draw_progress_bar:
  **/
 static void
-pk_console_draw_progress_bar (guint percentage)
+pk_console_draw_progress_bar (guint percentage, guint remaining_time)
 {
 	guint i;
 	guint progress = (gint) (PROGRESS_BAR_SIZE * (gfloat) (percentage) / 100);
 	guint remaining = PROGRESS_BAR_SIZE - progress;
 
+	/* have we already been spinning? */
+	if (timer_id != 0) {
+		g_source_remove (timer_id);
+		timer_id = 0;
+	}
+
 	/* we need to do an extra line */
 	printed_bar = TRUE;
 
@@ -196,25 +202,17 @@ pk_console_draw_progress_bar (guint percentage)
 		g_print (".");
 	}
 	g_print ("]  %3i%%", percentage);
+	if (remaining_time != 0) {
+		g_print (" (%i seconds)", remaining_time);
+	} else {
+		g_print ("                  ");
+	}
 	if (percentage == 100) {
 		g_print ("\n");
 	}
 }
 
 /**
- * pk_console_percentage_changed_cb:
- **/
-static void
-pk_console_percentage_changed_cb (PkClient *client, guint percentage, gpointer data)
-{
-	if (is_console == TRUE) {
-		pk_console_draw_progress_bar (percentage);
-	} else {
-		g_print ("%i%%\n", percentage);
-	}
-}
-
-/**
  * pk_console_pulse_bar:
  **/
 static gboolean
@@ -261,12 +259,17 @@ pk_console_pulse_bar (PulseState *pulse_state)
 }
 
 /**
- * pk_console_no_percentage_updates_cb:
+ * pk_console_draw_progress_bar:
  **/
 static void
-pk_console_no_percentage_updates_cb (PkClient *client, gpointer data)
+pk_console_draw_pulse_bar (void)
 {
 	static PulseState pulse_state;
+
+	/* have we already got zero percent? */
+	if (timer_id != 0) {
+		return;
+	}
 	has_output = FALSE;
 	if (is_console == TRUE) {
 		pulse_state.position = 1;
@@ -275,6 +278,24 @@ pk_console_no_percentage_updates_cb (PkClient *client, gpointer data)
 	}
 }
 
+/**
+ * pk_console_progress_changed_cb:
+ **/
+static void
+pk_console_progress_changed_cb (PkClient *client, guint percentage, guint subpercentage,
+				guint elapsed, guint remaining, gpointer data)
+{
+	if (is_console == TRUE) {
+		if (percentage == PK_CLIENT_PERCENTAGE_INVALID) {
+			pk_console_draw_pulse_bar ();
+		} else {
+			pk_console_draw_progress_bar (percentage, remaining);
+		}
+	} else {
+		g_print ("%i%%\n", percentage);
+	}
+}
+
 const gchar *summary =
 	"PackageKit Console Interface\n"
 	"\n"
@@ -750,10 +771,8 @@ main (int argc, char *argv[])
 			  G_CALLBACK (pk_console_update_detail_cb), NULL);
 	g_signal_connect (client, "repo-detail",
 			  G_CALLBACK (pk_console_repo_detail_cb), NULL);
-	g_signal_connect (client, "percentage-changed",
-			  G_CALLBACK (pk_console_percentage_changed_cb), NULL);
-	g_signal_connect (client, "no-percentage-updates",
-			  G_CALLBACK (pk_console_no_percentage_updates_cb), NULL);
+	g_signal_connect (client, "progress-changed",
+			  G_CALLBACK (pk_console_progress_changed_cb), NULL);
 	g_signal_connect (client, "finished",
 			  G_CALLBACK (pk_console_finished_cb), NULL);
 	g_signal_connect (client, "error-code",
diff --git a/libpackagekit/pk-client.c b/libpackagekit/pk-client.c
index c382d52..19619ed 100644
--- a/libpackagekit/pk-client.c
+++ b/libpackagekit/pk-client.c
@@ -74,12 +74,10 @@ typedef enum {
 	PK_CLIENT_DESCRIPTION,
 	PK_CLIENT_ERROR_CODE,
 	PK_CLIENT_FINISHED,
-	PK_CLIENT_NO_PERCENTAGE_UPDATES,
 	PK_CLIENT_PACKAGE,
-	PK_CLIENT_PERCENTAGE_CHANGED,
+	PK_CLIENT_PROGRESS_CHANGED,
 	PK_CLIENT_UPDATES_CHANGED,
 	PK_CLIENT_REQUIRE_RESTART,
-	PK_CLIENT_SUB_PERCENTAGE_CHANGED,
 	PK_CLIENT_TRANSACTION,
 	PK_CLIENT_TRANSACTION_STATUS_CHANGED,
 	PK_CLIENT_UPDATE_DETAIL,
@@ -271,13 +269,12 @@ pk_client_finished_cb (DBusGProxy  *proxy,
 }
 
 /**
- * pk_client_percentage_changed_cb:
+ * pk_client_progress_changed_cb:
  */
 static void
-pk_client_percentage_changed_cb (DBusGProxy  *proxy,
-			         const gchar *tid,
-			         guint	      percentage,
-			         PkClient    *client)
+pk_client_progress_changed_cb (DBusGProxy  *proxy, const gchar *tid,
+			       guint percentage, guint subpercentage,
+			       guint elapsed, guint remaining, PkClient *client)
 {
 	g_return_if_fail (client != NULL);
 	g_return_if_fail (PK_IS_CLIENT (client));
@@ -289,55 +286,9 @@ pk_client_percentage_changed_cb (DBusGProxy  *proxy,
 	}
 
 	if (pk_transaction_id_equal (tid, client->priv->tid) == TRUE) {
-		pk_debug ("emit percentage-changed %i", percentage);
-		g_signal_emit (client , signals [PK_CLIENT_PERCENTAGE_CHANGED], 0, percentage);
-	}
-}
-
-/**
- * pk_client_sub_percentage_changed_cb:
- */
-static void
-pk_client_sub_percentage_changed_cb (DBusGProxy  *proxy,
-				     const gchar *tid,
-			             guint	  percentage,
-			             PkClient    *client)
-{
-	g_return_if_fail (client != NULL);
-	g_return_if_fail (PK_IS_CLIENT (client));
-
-	/* check to see if we have been assigned yet */
-	if (client->priv->tid == NULL) {
-		pk_debug ("ignoring tid:%s as we are not yet assigned", tid);
-		return;
-	}
-
-	if (pk_transaction_id_equal (tid, client->priv->tid) == TRUE) {
-		pk_debug ("emit sub-percentage-changed %i", percentage);
-		g_signal_emit (client, signals [PK_CLIENT_SUB_PERCENTAGE_CHANGED], 0, percentage);
-	}
-}
-
-/**
- * pk_client_no_percentage_updates_cb:
- */
-static void
-pk_client_no_percentage_updates_cb (DBusGProxy  *proxy,
-			            const gchar *tid,
-				    PkClient    *client)
-{
-	g_return_if_fail (client != NULL);
-	g_return_if_fail (PK_IS_CLIENT (client));
-
-	/* check to see if we have been assigned yet */
-	if (client->priv->tid == NULL) {
-		pk_debug ("ignoring tid:%s as we are not yet assigned", tid);
-		return;
-	}
-
-	if (pk_transaction_id_equal (tid, client->priv->tid) == TRUE) {
-		pk_debug ("emit no-percentage-updates");
-		g_signal_emit (client , signals [PK_CLIENT_NO_PERCENTAGE_UPDATES], 0);
+		pk_debug ("emit progress-changed %i, %i, %i, %i", percentage, subpercentage, elapsed, remaining);
+		g_signal_emit (client , signals [PK_CLIENT_PROGRESS_CHANGED], 0,
+			       percentage, subpercentage, elapsed, remaining);
 	}
 }
 
@@ -708,54 +659,16 @@ pk_client_get_package (PkClient *client, gchar **package)
 }
 
 /**
- * pk_client_get_percentage:
- **/
-gboolean
-pk_client_get_percentage (PkClient *client, guint *percentage)
-{
-	gboolean ret;
-	GError *error;
-
-	g_return_val_if_fail (client != NULL, FALSE);
-	g_return_val_if_fail (percentage != NULL, FALSE);
-	g_return_val_if_fail (PK_IS_CLIENT (client), FALSE);
-	g_return_val_if_fail (client->priv->tid != NULL, FALSE);
-
-	/* check to see if we have a valid transaction */
-	if (client->priv->tid == NULL) {
-		pk_warning ("Transaction ID not set");
-		return FALSE;
-	}
-
-	error = NULL;
-	ret = dbus_g_proxy_call (client->priv->proxy, "GetPercentage", &error,
-				 G_TYPE_STRING, client->priv->tid,
-				 G_TYPE_INVALID,
-				 G_TYPE_UINT, percentage,
-				 G_TYPE_INVALID);
-	if (error != NULL) {
-		pk_debug ("ERROR: %s", error->message);
-		g_error_free (error);
-	}
-	if (ret == FALSE) {
-		/* abort as the DBUS method failed */
-		pk_warning ("GetPercentage failed!");
-		return FALSE;
-	}
-	return TRUE;
-}
-
-/**
- * pk_client_get_sub_percentage:
+ * pk_client_get_progress:
  **/
 gboolean
-pk_client_get_sub_percentage (PkClient *client, guint *percentage)
+pk_client_get_progress (PkClient *client, guint *percentage, guint *subpercentage,
+			guint *elapsed, guint *remaining)
 {
 	gboolean ret;
 	GError *error;
 
 	g_return_val_if_fail (client != NULL, FALSE);
-	g_return_val_if_fail (percentage != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_CLIENT (client), FALSE);
 	g_return_val_if_fail (client->priv->tid != NULL, FALSE);
 
@@ -766,10 +679,13 @@ pk_client_get_sub_percentage (PkClient *client, guint *percentage)
 	}
 
 	error = NULL;
-	ret = dbus_g_proxy_call (client->priv->proxy, "GetSubPercentage", &error,
+	ret = dbus_g_proxy_call (client->priv->proxy, "GetProgress", &error,
 				 G_TYPE_STRING, client->priv->tid,
 				 G_TYPE_INVALID,
 				 G_TYPE_UINT, percentage,
+				 G_TYPE_UINT, subpercentage,
+				 G_TYPE_UINT, elapsed,
+				 G_TYPE_UINT, remaining,
 				 G_TYPE_INVALID);
 	if (error != NULL) {
 		pk_debug ("ERROR: %s", error->message);
@@ -777,7 +693,7 @@ pk_client_get_sub_percentage (PkClient *client, guint *percentage)
 	}
 	if (ret == FALSE) {
 		/* abort as the DBUS method failed */
-		pk_warning ("GetSubPercentage failed!");
+		pk_warning ("GetProgress failed!");
 		return FALSE;
 	}
 	return TRUE;
@@ -2247,21 +2163,11 @@ pk_client_class_init (PkClientClass *klass)
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
 			      0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
 			      G_TYPE_NONE, 0);
-	signals [PK_CLIENT_PERCENTAGE_CHANGED] =
-		g_signal_new ("percentage-changed",
+	signals [PK_CLIENT_PROGRESS_CHANGED] =
+		g_signal_new ("progress-changed",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
-			      G_TYPE_NONE, 1, G_TYPE_UINT);
-	signals [PK_CLIENT_SUB_PERCENTAGE_CHANGED] =
-		g_signal_new ("sub-percentage-changed",
-			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
-			      G_TYPE_NONE, 1, G_TYPE_UINT);
-	signals [PK_CLIENT_NO_PERCENTAGE_UPDATES] =
-		g_signal_new ("no-percentage-updates",
-			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
-			      G_TYPE_NONE, 0);
+			      0, NULL, NULL, pk_marshal_VOID__UINT_UINT_UINT_UINT,
+			      G_TYPE_NONE, 4, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
 	signals [PK_CLIENT_PACKAGE] =
 		g_signal_new ("package",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
@@ -2390,9 +2296,10 @@ pk_client_init (PkClient *client)
 	/* use PolicyKit */
 	client->priv->polkit = pk_polkit_client_new ();
 
-	/* PercentageChanged et al */
-	dbus_g_object_register_marshaller (pk_marshal_VOID__STRING_UINT,
-					   G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID);
+	/* ProgressChanged */
+	dbus_g_object_register_marshaller (pk_marshal_VOID__STRING_UINT_UINT_UINT_UINT,
+					   G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT,
+					   G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID);
 
 	/* Locked */
 	dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOOLEAN,
@@ -2442,20 +2349,10 @@ pk_client_init (PkClient *client)
 	dbus_g_proxy_connect_signal (proxy, "Finished",
 				     G_CALLBACK (pk_client_finished_cb), client, NULL);
 
-	dbus_g_proxy_add_signal (proxy, "PercentageChanged",
-				 G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID);
-	dbus_g_proxy_connect_signal (proxy, "PercentageChanged",
-				     G_CALLBACK (pk_client_percentage_changed_cb), client, NULL);
-
-	dbus_g_proxy_add_signal (proxy, "SubPercentageChanged",
-				 G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID);
-	dbus_g_proxy_connect_signal (proxy, "SubPercentageChanged",
-				     G_CALLBACK (pk_client_sub_percentage_changed_cb), client, NULL);
-
-	dbus_g_proxy_add_signal (proxy, "NoPercentageUpdates",
-				 G_TYPE_STRING, G_TYPE_INVALID);
-	dbus_g_proxy_connect_signal (proxy, "NoPercentageUpdates",
-				     G_CALLBACK (pk_client_no_percentage_updates_cb), client, NULL);
+	dbus_g_proxy_add_signal (proxy, "ProgressChanged",
+				 G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_INVALID);
+	dbus_g_proxy_connect_signal (proxy, "ProgressChanged",
+				     G_CALLBACK (pk_client_progress_changed_cb), client, NULL);
 
 	dbus_g_proxy_add_signal (proxy, "TransactionStatusChanged",
 				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
@@ -2540,12 +2437,8 @@ pk_client_finalize (GObject *object)
 	/* disconnect signal handlers */
 	dbus_g_proxy_disconnect_signal (client->priv->proxy, "Finished",
 				        G_CALLBACK (pk_client_finished_cb), client);
-	dbus_g_proxy_disconnect_signal (client->priv->proxy, "PercentageChanged",
-				        G_CALLBACK (pk_client_percentage_changed_cb), client);
-	dbus_g_proxy_disconnect_signal (client->priv->proxy, "SubPercentageChanged",
-				        G_CALLBACK (pk_client_sub_percentage_changed_cb), client);
-	dbus_g_proxy_disconnect_signal (client->priv->proxy, "NoPercentageUpdates",
-				        G_CALLBACK (pk_client_no_percentage_updates_cb), client);
+	dbus_g_proxy_disconnect_signal (client->priv->proxy, "ProgressChanged",
+				        G_CALLBACK (pk_client_progress_changed_cb), client);
 	dbus_g_proxy_disconnect_signal (client->priv->proxy, "TransactionStatusChanged",
 				        G_CALLBACK (pk_client_transaction_status_changed_cb), client);
 	dbus_g_proxy_disconnect_signal (client->priv->proxy, "UpdatesChanged",
diff --git a/libpackagekit/pk-client.h b/libpackagekit/pk-client.h
index 6d7c1f2..2cd993b 100644
--- a/libpackagekit/pk-client.h
+++ b/libpackagekit/pk-client.h
@@ -36,6 +36,8 @@ G_BEGIN_DECLS
 #define PK_IS_CLIENT_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), PK_TYPE_CLIENT))
 #define PK_CLIENT_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), PK_TYPE_CLIENT, PkClientClass))
 
+#define PK_CLIENT_PERCENTAGE_INVALID	101
+
 typedef struct PkClientPrivate PkClientPrivate;
 
 typedef struct
@@ -66,10 +68,11 @@ gboolean	 pk_client_get_status			(PkClient	*client,
 gboolean	 pk_client_get_role			(PkClient	*client,
 							 PkRoleEnum	*role,
 							 gchar		**package_id);
-gboolean	 pk_client_get_percentage		(PkClient	*client,
-							 guint		*percentage);
-gboolean	 pk_client_get_sub_percentage		(PkClient	*client,
-							 guint		*percentage);
+gboolean	 pk_client_get_progress			(PkClient	*client,
+							 guint		*percentage,
+							 guint		*subpercentage,
+							 guint		*elapsed,
+							 guint		*remaining);
 gboolean	 pk_client_get_package			(PkClient	*client,
 							 gchar		**package_id);
 gboolean	 pk_client_cancel			(PkClient	*client);
diff --git a/src/pk-backend-internal.h b/src/pk-backend-internal.h
index 128c87d..8ac23d9 100644
--- a/src/pk-backend-internal.h
+++ b/src/pk-backend-internal.h
@@ -110,10 +110,11 @@ gboolean	 pk_backend_get_status			(PkBackend	*backend,
 gboolean	 pk_backend_get_role			(PkBackend	*backend,
 							 PkRoleEnum	*role,
 							 const gchar	**package_id);
-gboolean	 pk_backend_get_percentage		(PkBackend	*backend,
-							 guint		*percentage);
-gboolean	 pk_backend_get_sub_percentage		(PkBackend	*backend,
-							 guint		*percentage);
+gboolean	 pk_backend_get_progress		(PkBackend	*backend,
+							 guint		*percentage,
+							 guint		*subpercentage,
+							 guint		*elapsed,
+							 guint		*remaining);
 gboolean	 pk_backend_get_package			(PkBackend	*backend,
 							 gchar		**package_id);
 
diff --git a/src/pk-backend.c b/src/pk-backend.c
index bc49cb5..9a40c0f 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -82,6 +82,7 @@ struct _PkBackendPrivate
 	/* needed for gui coldplugging */
 	guint			 last_percentage;
 	guint			 last_subpercentage;
+	guint			 last_remaining;
 	gchar			*last_package;
 	PkThreadList		*thread_list;
 	gulong			 signal_finished;
@@ -91,9 +92,7 @@ struct _PkBackendPrivate
 
 enum {
 	PK_BACKEND_TRANSACTION_STATUS_CHANGED,
-	PK_BACKEND_PERCENTAGE_CHANGED,
-	PK_BACKEND_SUB_PERCENTAGE_CHANGED,
-	PK_BACKEND_NO_PERCENTAGE_UPDATES,
+	PK_BACKEND_PROGRESS_CHANGED,
 	PK_BACKEND_DESCRIPTION,
 	PK_BACKEND_PACKAGE,
 	PK_BACKEND_UPDATE_DETAIL,
@@ -614,13 +613,37 @@ pk_backend_not_implemented_yet (PkBackend *backend, const gchar *method)
 }
 
 /**
+ * pk_backend_emit_progress_changed:
+ **/
+static gboolean
+pk_backend_emit_progress_changed (PkBackend *backend)
+{
+	guint percentage;
+	guint subpercentage;
+	guint elapsed;
+	guint remaining;
+
+	g_return_val_if_fail (backend != NULL, FALSE);
+	g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
+
+	percentage = backend->priv->last_percentage;
+	subpercentage = backend->priv->last_subpercentage;
+	elapsed = pk_time_get_elapsed (backend->priv->time);
+	remaining = backend->priv->last_remaining;
+
+	pk_debug ("emit progress %i, %i, %i, %i",
+		  percentage, subpercentage, elapsed, remaining);
+	g_signal_emit (backend, signals [PK_BACKEND_PROGRESS_CHANGED], 0,
+		       percentage, subpercentage, elapsed, remaining);
+	return TRUE;
+}
+
+/**
  * pk_backend_change_percentage:
  **/
 gboolean
 pk_backend_change_percentage (PkBackend *backend, guint percentage)
 {
-	guint remaining;
-
 	g_return_val_if_fail (backend != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
 
@@ -631,11 +654,11 @@ pk_backend_change_percentage (PkBackend *backend, guint percentage)
 	pk_time_add_data (backend->priv->time, percentage);
 
 	/* TODO: lets try this */
-	remaining = pk_time_get_remaining (backend->priv->time);
-	pk_debug ("this will take ~%i seconds", remaining);
+	backend->priv->last_remaining = pk_time_get_remaining (backend->priv->time);
+	pk_debug ("this will now take ~%i seconds", backend->priv->last_remaining);
 
-	pk_debug ("emit percentage-changed %i", percentage);
-	g_signal_emit (backend, signals [PK_BACKEND_PERCENTAGE_CHANGED], 0, percentage);
+	/* emit the progress changed signal */
+	pk_backend_emit_progress_changed (backend);
 	return TRUE;
 }
 
@@ -651,8 +674,8 @@ pk_backend_change_sub_percentage (PkBackend *backend, guint percentage)
 	/* save in case we need this from coldplug */
 	backend->priv->last_subpercentage = percentage;
 
-	pk_debug ("emit sub-percentage-changed %i", percentage);
-	g_signal_emit (backend, signals [PK_BACKEND_SUB_PERCENTAGE_CHANGED], 0, percentage);
+	/* emit the progress changed signal */
+	pk_backend_emit_progress_changed (backend);
 	return TRUE;
 }
 
@@ -730,38 +753,21 @@ pk_backend_update_detail (PkBackend *backend, const gchar *package_id,
 	return TRUE;
 }
 
-
 /**
- * pk_backend_get_percentage:
+ * pk_backend_get_progress:
  **/
 gboolean
-pk_backend_get_percentage (PkBackend *backend, guint *percentage)
+pk_backend_get_progress (PkBackend *backend,
+			 guint *percentage, guint *subpercentage,
+			 guint *elapsed, guint *remaining)
 {
 	g_return_val_if_fail (backend != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
 
-	/* no data yet... */
-	if (backend->priv->last_percentage == PK_BACKEND_PERCENTAGE_INVALID) {
-		return FALSE;
-	}
 	*percentage = backend->priv->last_percentage;
-	return TRUE;
-}
-
-/**
- * pk_backend_get_sub_percentage:
- **/
-gboolean
-pk_backend_get_sub_percentage (PkBackend *backend, guint *percentage)
-{
-	g_return_val_if_fail (backend != NULL, FALSE);
-	g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
-
-	/* no data yet... */
-	if (backend->priv->last_subpercentage == PK_BACKEND_PERCENTAGE_INVALID) {
-		return FALSE;
-	}
-	*percentage = backend->priv->last_subpercentage;
+	*subpercentage = backend->priv->last_subpercentage;
+	*elapsed = pk_time_get_elapsed (backend->priv->time);
+	*remaining = backend->priv->last_remaining;
 	return TRUE;
 }
 
@@ -1019,8 +1025,8 @@ pk_backend_no_percentage_updates (PkBackend *backend)
 	/* invalidate previous percentage */
 	backend->priv->last_percentage = PK_BACKEND_PERCENTAGE_INVALID;
 
-	pk_debug ("emit no-percentage-updates");
-	g_signal_emit (backend, signals [PK_BACKEND_NO_PERCENTAGE_UPDATES], 0);
+	/* emit the progress changed signal */
+	pk_backend_emit_progress_changed (backend);
 	return TRUE;
 }
 
@@ -1709,16 +1715,11 @@ pk_backend_class_init (PkBackendClass *klass)
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
 			      0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
 			      G_TYPE_NONE, 1, G_TYPE_UINT);
-	signals [PK_BACKEND_PERCENTAGE_CHANGED] =
-		g_signal_new ("percentage-changed",
+	signals [PK_BACKEND_PROGRESS_CHANGED] =
+		g_signal_new ("progress-changed",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
-			      G_TYPE_NONE, 1, G_TYPE_UINT);
-	signals [PK_BACKEND_SUB_PERCENTAGE_CHANGED] =
-		g_signal_new ("sub-percentage-changed",
-			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
-			      G_TYPE_NONE, 1, G_TYPE_UINT);
+			      0, NULL, NULL, pk_marshal_VOID__UINT_UINT_UINT_UINT,
+			      G_TYPE_NONE, 4, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
 	signals [PK_BACKEND_PACKAGE] =
 		g_signal_new ("package",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
@@ -1767,11 +1768,6 @@ pk_backend_class_init (PkBackendClass *klass)
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
 			      0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
 			      G_TYPE_NONE, 1, G_TYPE_UINT);
-	signals [PK_BACKEND_NO_PERCENTAGE_UPDATES] =
-		g_signal_new ("no-percentage-updates",
-			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
-			      G_TYPE_NONE, 0);
 	signals [PK_BACKEND_ALLOW_INTERRUPT] =
 		g_signal_new ("allow-interrupt",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
@@ -1810,6 +1806,7 @@ pk_backend_init (PkBackend *backend)
 	backend->priv->xcached_value = NULL;
 	backend->priv->last_percentage = PK_BACKEND_PERCENTAGE_INVALID;
 	backend->priv->last_subpercentage = PK_BACKEND_PERCENTAGE_INVALID;
+	backend->priv->last_remaining = 0;
 	backend->priv->last_package = NULL;
 	backend->priv->role = PK_ROLE_ENUM_UNKNOWN;
 	backend->priv->status = PK_STATUS_ENUM_UNKNOWN;
diff --git a/src/pk-engine.c b/src/pk-engine.c
index b912680..11cbaa7 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -78,9 +78,7 @@ struct PkEnginePrivate
 enum {
 	PK_ENGINE_TRANSACTION_LIST_CHANGED,
 	PK_ENGINE_TRANSACTION_STATUS_CHANGED,
-	PK_ENGINE_PERCENTAGE_CHANGED,
-	PK_ENGINE_SUB_PERCENTAGE_CHANGED,
-	PK_ENGINE_NO_PERCENTAGE_UPDATES,
+	PK_ENGINE_PROGRESS_CHANGED,
 	PK_ENGINE_PACKAGE,
 	PK_ENGINE_TRANSACTION,
 	PK_ENGINE_ERROR_CODE,
@@ -239,10 +237,11 @@ pk_engine_transaction_status_changed_cb (PkBackend *backend, PkStatusEnum status
 }
 
 /**
- * pk_engine_percentage_changed_cb:
+ * pk_engine_progress_changed_cb:
  **/
 static void
-pk_engine_percentage_changed_cb (PkBackend *backend, guint percentage, PkEngine *engine)
+pk_engine_progress_changed_cb (PkBackend *backend, guint percentage, guint subpercentage,
+			       guint elapsed, guint remaining, PkEngine *engine)
 {
 	PkTransactionItem *item;
 
@@ -254,50 +253,10 @@ pk_engine_percentage_changed_cb (PkBackend *backend, guint percentage, PkEngine
 		pk_warning ("could not find backend");
 		return;
 	}
-	pk_debug ("emitting percentage-changed tid:%s %i", item->tid, percentage);
-	g_signal_emit (engine, signals [PK_ENGINE_PERCENTAGE_CHANGED], 0, item->tid, percentage);
-	pk_engine_reset_timer (engine);
-}
-
-/**
- * pk_engine_sub_percentage_changed_cb:
- **/
-static void
-pk_engine_sub_percentage_changed_cb (PkBackend *backend, guint percentage, PkEngine *engine)
-{
-	PkTransactionItem *item;
-
-	g_return_if_fail (engine != NULL);
-	g_return_if_fail (PK_IS_ENGINE (engine));
-
-	item = pk_transaction_list_get_from_backend (engine->priv->transaction_list, backend);
-	if (item == NULL) {
-		pk_warning ("could not find backend");
-		return;
-	}
-	pk_debug ("emitting sub-percentage-changed tid:%s %i", item->tid, percentage);
-	g_signal_emit (engine, signals [PK_ENGINE_SUB_PERCENTAGE_CHANGED], 0, item->tid, percentage);
-	pk_engine_reset_timer (engine);
-}
-
-/**
- * pk_engine_no_percentage_updates_cb:
- **/
-static void
-pk_engine_no_percentage_updates_cb (PkBackend *backend, PkEngine *engine)
-{
-	PkTransactionItem *item;
-
-	g_return_if_fail (engine != NULL);
-	g_return_if_fail (PK_IS_ENGINE (engine));
-
-	item = pk_transaction_list_get_from_backend (engine->priv->transaction_list, backend);
-	if (item == NULL) {
-		pk_warning ("could not find backend");
-		return;
-	}
-	pk_debug ("emitting no-percentage-updates tid:%s", item->tid);
-	g_signal_emit (engine, signals [PK_ENGINE_NO_PERCENTAGE_UPDATES], 0, item->tid);
+	pk_debug ("emitting percentage-changed tid:%s %i, %i, %i, %i",
+		  item->tid, percentage, subpercentage, elapsed, remaining);
+	g_signal_emit (engine, signals [PK_ENGINE_PROGRESS_CHANGED], 0,
+		       item->tid, percentage, subpercentage, elapsed, remaining);
 	pk_engine_reset_timer (engine);
 }
 
@@ -674,12 +633,8 @@ pk_engine_backend_new (PkEngine *engine)
 	/* connect up signals */
 	g_signal_connect (backend, "transaction-status-changed",
 			  G_CALLBACK (pk_engine_transaction_status_changed_cb), engine);
-	g_signal_connect (backend, "percentage-changed",
-			  G_CALLBACK (pk_engine_percentage_changed_cb), engine);
-	g_signal_connect (backend, "sub-percentage-changed",
-			  G_CALLBACK (pk_engine_sub_percentage_changed_cb), engine);
-	g_signal_connect (backend, "no-percentage-updates",
-			  G_CALLBACK (pk_engine_no_percentage_updates_cb), engine);
+	g_signal_connect (backend, "progress-changed",
+			  G_CALLBACK (pk_engine_progress_changed_cb), engine);
 	g_signal_connect (backend, "package",
 			  G_CALLBACK (pk_engine_package_cb), engine);
 	g_signal_connect (backend, "update-detail",
@@ -2099,38 +2054,12 @@ pk_engine_get_role (PkEngine *engine, const gchar *tid,
 }
 
 /**
- * pk_engine_get_percentage:
- **/
-gboolean
-pk_engine_get_percentage (PkEngine *engine, const gchar *tid, guint *percentage, GError **error)
-{
-	PkTransactionItem *item;
-	gboolean ret;
-
-	g_return_val_if_fail (engine != NULL, FALSE);
-	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
-
-	/* find pre-requested transaction id */
-	item = pk_transaction_list_get_from_tid (engine->priv->transaction_list, tid);
-	if (item == NULL) {
-		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NO_SUCH_TRANSACTION,
-			     "No tid:%s", tid);
-		return FALSE;
-	}
-	ret = pk_backend_get_percentage (item->backend, percentage);
-	if (ret == FALSE) {
-		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_INVALID_STATE,
-			     "No percentage data available");
-		return FALSE;
-	}
-	return TRUE;
-}
-
-/**
- * pk_engine_get_sub_percentage:
+ * pk_engine_get_progress:
  **/
 gboolean
-pk_engine_get_sub_percentage (PkEngine *engine, const gchar *tid, guint *percentage, GError **error)
+pk_engine_get_progress (PkEngine *engine, const gchar *tid,
+			guint *percentage, guint *subpercentage,
+			guint *elapsed, guint *remaining, GError **error)
 {
 	PkTransactionItem *item;
 	gboolean ret;
@@ -2145,10 +2074,10 @@ pk_engine_get_sub_percentage (PkEngine *engine, const gchar *tid, guint *percent
 			     "No tid:%s", tid);
 		return FALSE;
 	}
-	ret = pk_backend_get_sub_percentage (item->backend, percentage);
+	ret = pk_backend_get_progress (item->backend, percentage, subpercentage, elapsed, remaining);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_INVALID_STATE,
-			     "No sub-percentage data available");
+			     "No progress data available");
 		return FALSE;
 	}
 	return TRUE;
@@ -2371,21 +2300,11 @@ pk_engine_class_init (PkEngineClass *klass)
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
 			      0, NULL, NULL, pk_marshal_VOID__STRING_STRING,
 			      G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);
-	signals [PK_ENGINE_PERCENTAGE_CHANGED] =
-		g_signal_new ("percentage-changed",
+	signals [PK_ENGINE_PROGRESS_CHANGED] =
+		g_signal_new ("progress-changed",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, pk_marshal_VOID__STRING_UINT,
-			      G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_UINT);
-	signals [PK_ENGINE_SUB_PERCENTAGE_CHANGED] =
-		g_signal_new ("sub-percentage-changed",
-			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, pk_marshal_VOID__STRING_UINT,
-			      G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_UINT);
-	signals [PK_ENGINE_NO_PERCENTAGE_UPDATES] =
-		g_signal_new ("no-percentage-updates",
-			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
-			      0, NULL, NULL, g_cclosure_marshal_VOID__STRING,
-			      G_TYPE_NONE, 1, G_TYPE_STRING);
+			      0, NULL, NULL, pk_marshal_VOID__STRING_UINT_UINT_UINT_UINT,
+			      G_TYPE_NONE, 5, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
 	signals [PK_ENGINE_PACKAGE] =
 		g_signal_new ("package",
 			      G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
diff --git a/src/pk-engine.h b/src/pk-engine.h
index 05f0b81..57b3002 100644
--- a/src/pk-engine.h
+++ b/src/pk-engine.h
@@ -194,9 +194,12 @@ gboolean	 pk_engine_get_filters			(PkEngine	*engine,
 							 GError		**error);
 guint		 pk_engine_get_seconds_idle		(PkEngine	*engine);
 
-gboolean	 pk_engine_get_percentage		(PkEngine	*engine,
+gboolean	 pk_engine_get_progress			(PkEngine	*engine,
 							 const gchar	*tid,
 							 guint		*percentage,
+							 guint		*subpercentage,
+							 guint		*elapsed,
+							 guint		*remaining,
 							 GError		**error);
 gboolean	 pk_engine_get_sub_percentage		(PkEngine	*engine,
 							 const gchar	*tid,
diff --git a/src/pk-interface.xml b/src/pk-interface.xml
index 824ba7b..4627814 100644
--- a/src/pk-interface.xml
+++ b/src/pk-interface.xml
@@ -89,16 +89,12 @@
       <arg type="s" name="tid" direction="out"/>
       <arg type="s" name="status" direction="out"/> <!-- invalid,setup,download,install,update,exit -->
     </signal>
-    <signal name="PercentageChanged"> <!-- progress of the whole transaction -->
+    <signal name="ProgressChanged"> <!-- progress of the whole transaction -->
       <arg type="s" name="tid" direction="out"/>
       <arg type="u" name="percentage" direction="out"/>
-    </signal>
-    <signal name="SubPercentageChanged"> <!-- progress of the intervidual transaction -->
-      <arg type="s" name="tid" direction="out"/>
-      <arg type="u" name="percentage" direction="out"/>
-    </signal>
-    <signal name="NoPercentageUpdates"> <!-- if we are not emmitting PercentageChanged, the UI has to spin -->
-      <arg type="s" name="tid" direction="out"/>
+      <arg type="u" name="subpercentage" direction="out"/>
+      <arg type="u" name="elapsed" direction="out"/>
+      <arg type="u" name="remaining" direction="out"/>
     </signal>
     <signal name="Package">
       <arg type="s" name="tid" direction="out"/>
@@ -203,15 +199,13 @@
       <arg type="s" name="status" direction="out"/> <!-- query,download,install,exit -->
       <arg type="s" name="package_id" direction="out"/> <!-- what we are doing the action to, or NULL -->
     </method>
-    <method name="GetPercentage">
-      <!-- throws NoSuchTransaction -->
-      <arg type="s" name="tid" direction="in"/>
-      <arg type="u" name="percentage" direction="out"/>
-    </method>
-    <method name="GetSubPercentage">
+    <method name="GetProgress">
       <!-- throws NoSuchTransaction -->
       <arg type="s" name="tid" direction="in"/>
       <arg type="u" name="percentage" direction="out"/>
+      <arg type="u" name="subpercentage" direction="out"/>
+      <arg type="u" name="elapsed" direction="out"/>
+      <arg type="u" name="remaining" direction="out"/>
     </method>
     <method name="GetPackage">
       <!-- throws NoSuchTransaction -->
diff --git a/src/pk-marshal.list b/src/pk-marshal.list
index c8470c3..d8ccd58 100644
--- a/src/pk-marshal.list
+++ b/src/pk-marshal.list
@@ -2,6 +2,8 @@ VOID:UINT,STRING,STRING
 VOID:UINT,STRING
 VOID:UINT,STRING,UINT
 VOID:UINT,UINT
+VOID:UINT,UINT,UINT,UINT
+VOID:STRING,UINT,UINT,UINT,UINT
 VOID:STRING
 VOID:STRING,BOOL
 VOID:STRING,UINT


More information about the PackageKit mailing list