[gnome-packagekit/glib2: 67/79] mo



commit 7ba3e7e123b826116445c4d44235d45cd6fba0e4
Author: Richard Hughes <richard hughsie com>
Date:   Sun Oct 4 09:34:45 2009 +0100

    mo

 src/gpk-modal-dialog.c |   29 ++++++++++++++---------------
 src/gpk-modal-dialog.h |    2 +-
 src/gpk-self-test.c    |    2 +-
 src/gpk-service-pack.c |   35 +++++++++++++++++------------------
 4 files changed, 33 insertions(+), 35 deletions(-)
---
diff --git a/src/gpk-modal-dialog.c b/src/gpk-modal-dialog.c
index 0f19522..c4ff62d 100644
--- a/src/gpk-modal-dialog.c
+++ b/src/gpk-modal-dialog.c
@@ -390,11 +390,12 @@ gpk_modal_dialog_make_progressbar_pulse (GpkModalDialog *dialog)
  * gpk_modal_dialog_set_percentage:
  **/
 gboolean
-gpk_modal_dialog_set_percentage (GpkModalDialog *dialog, guint percentage)
+gpk_modal_dialog_set_percentage (GpkModalDialog *dialog, gint percentage)
 {
 	GtkProgressBar *progress_bar;
 
 	g_return_val_if_fail (GPK_IS_CLIENT_DIALOG (dialog), FALSE);
+	g_return_val_if_fail (percentage <= 100, FALSE);
 
 	egg_debug ("setting percentage: %u", percentage);
 
@@ -405,7 +406,7 @@ gpk_modal_dialog_set_percentage (GpkModalDialog *dialog, guint percentage)
 	}
 
 	/* either pulse or set percentage */
-	if (percentage == -1)
+	if (percentage < 0)
 		gpk_modal_dialog_make_progressbar_pulse (dialog);
 	else
 		gtk_progress_bar_set_fraction (progress_bar, (gfloat) percentage / 100.0);
@@ -902,8 +903,8 @@ gpk_modal_dialog_test (EggTest *test)
 {
 	GtkResponseType button;
 	GpkModalDialog *dialog = NULL;
-//	GPtrArray *list;
-//	gchar *id;
+	GPtrArray *array;
+	PkItemPackage *item;
 
 	if (!egg_test_start (test, "GpkModalDialog"))
 		return;
@@ -916,16 +917,14 @@ gpk_modal_dialog_test (EggTest *test)
 	else
 		egg_test_failed (test, NULL);
 
-#if 0
 	/* set some packages */
-	list = g_ptr_array_new_with_free_func_xxx ();
-	id = pk_package_id_new_from_list ("totem", "0.0.1", "i386", "fedora-newkey");
-	g_ptr_array_add_xxxwithrecount (list, PK_INFO_ENUM_INSTALLED, id, "Totem is a music player for GNOME");
-	g_ptr_array_add_xxxwithrecount (list, PK_INFO_ENUM_AVAILABLE, id, "Amarok is a music player for KDE");
-	gpk_modal_dialog_set_package_list (dialog, list);
-	g_free (id);
-	g_object_unref (list);
-#endif
+	array = g_ptr_array_new_with_free_func ((GDestroyNotify) pk_item_package_unref);
+	item = pk_item_package_new (PK_INFO_ENUM_INSTALLED, "totem;001;i386;fedora", "Totem is a music player for GNOME");
+	g_ptr_array_add (array, item);
+	item = pk_item_package_new (PK_INFO_ENUM_AVAILABLE, "totem;001;i386;fedora", "Amarok is a music player for KDE");
+	g_ptr_array_add (array, item);
+	gpk_modal_dialog_set_package_list (dialog, array);
+	g_ptr_array_unref (array);
 
 	/************************************************************/
 	egg_test_title (test, "help button");
@@ -960,7 +959,7 @@ gpk_modal_dialog_test (EggTest *test)
 	gpk_modal_dialog_setup (dialog, GPK_MODAL_DIALOG_PAGE_PROGRESS, 0);
 	gpk_modal_dialog_set_title (dialog, "Refresh cache");
 	gpk_modal_dialog_set_image_status (dialog, PK_STATUS_ENUM_REFRESH_CACHE);
-	gpk_modal_dialog_set_percentage (dialog, 101);
+	gpk_modal_dialog_set_percentage (dialog, -1);
 	gpk_modal_dialog_present (dialog);
 	gpk_modal_dialog_run (dialog);
 	egg_test_success (test, NULL);
@@ -985,7 +984,7 @@ gpk_modal_dialog_test (EggTest *test)
 	gpk_modal_dialog_set_title (dialog, "Button press test");
 	gpk_modal_dialog_set_message (dialog, "Please press close");
 	gpk_modal_dialog_set_image_status (dialog, PK_STATUS_ENUM_INSTALL);
-	gpk_modal_dialog_set_percentage (dialog, 101);
+	gpk_modal_dialog_set_percentage (dialog, -1);
 	gpk_modal_dialog_present (dialog);
 	button = gpk_modal_dialog_run (dialog);
 	if (button == GTK_RESPONSE_CLOSE)
diff --git a/src/gpk-modal-dialog.h b/src/gpk-modal-dialog.h
index 6ed411b..899c649 100644
--- a/src/gpk-modal-dialog.h
+++ b/src/gpk-modal-dialog.h
@@ -106,7 +106,7 @@ gboolean	 gpk_modal_dialog_set_message		(GpkModalDialog		*dialog,
 gboolean	 gpk_modal_dialog_set_action		(GpkModalDialog		*dialog,
 							 const gchar		*action);
 gboolean	 gpk_modal_dialog_set_percentage	(GpkModalDialog		*dialog,
-							 guint			 percentage);
+							 gint			 percentage);
 gboolean	 gpk_modal_dialog_set_remaining		(GpkModalDialog		*dialog,
 							 guint			 remaining);
 gboolean	 gpk_modal_dialog_set_image		(GpkModalDialog		*dialog,
diff --git a/src/gpk-self-test.c b/src/gpk-self-test.c
index 6e84de9..1d8d936 100644
--- a/src/gpk-self-test.c
+++ b/src/gpk-self-test.c
@@ -50,7 +50,6 @@ main (int argc, char **argv)
 	/* tests go here */
 	egg_markdown_test (test);
 	egg_string_test (test);
-	gpk_task_test (test);
 	gpk_enum_test (test);
 	gpk_common_test (test);
 //	gpk_dbus_test (test);
@@ -58,6 +57,7 @@ main (int argc, char **argv)
 	gpk_error_test (test);
 //	gpk_client_test (test);
 	gpk_modal_dialog_test (test);
+	gpk_task_test (test);
 
 	return egg_test_finish (test);
 }
diff --git a/src/gpk-service-pack.c b/src/gpk-service-pack.c
index 8d34a56..3fa3490 100644
--- a/src/gpk-service-pack.c
+++ b/src/gpk-service-pack.c
@@ -134,24 +134,6 @@ gpk_pack_widgets_activate (gboolean enable)
 	gtk_widget_set_sensitive (widget, enable);
 }
 
-#if 0
-/**
- * gpk_pack_package_cb:
- **/
-static void
-gpk_pack_package_cb (PkServicePack *pack, const PkItemPackage *item, gpointer data)
-{
-	GtkProgressBar *progress_bar;
-	gchar *text;
-
-	progress_bar = GTK_PROGRESS_BAR (gtk_builder_get_object (builder, "progressbar_percentage"));
-	/* TRANSLATORS: This is the package name that is being downloaded */
-	text = g_strdup_printf ("%s: %s-%s.%s", _("Downloading"), "xxx", item->package_id->version, item->package_id->arch);
-	gtk_progress_bar_set_text (progress_bar, text);
-	g_free (text);
-}
-#endif
-
 /**
  * gpk_pack_percentage_pulse_cb:
  **/
@@ -393,16 +375,33 @@ gpk_pack_progress_cb (PkProgress *progress, PkProgressType type, gpointer userda
 {
 	PkStatusEnum status;
 	gint percentage;
+	GtkProgressBar *progress_bar;
+	gchar *text;
+	gchar **split;
+	gchar *package_id;
 
 	g_object_get (progress,
 		      "status", &status,
 		      "percentage", &percentage,
+		      "package-id", &package_id,
 		      NULL);
 
 	if (type == PK_PROGRESS_TYPE_STATUS) {
 		egg_debug ("now %s", pk_status_enum_to_text (status));
 	} else if (type == PK_PROGRESS_TYPE_PERCENTAGE) {
 		gpk_pack_set_percentage (percentage);
+	} else if (type == PK_PROGRESS_TYPE_PACKAGE_ID) {
+		progress_bar = GTK_PROGRESS_BAR (gtk_builder_get_object (builder, "progressbar_percentage"));
+		split = pk_package_id_split (package_id);
+		/* TRANSLATORS: This is the package name that is being downloaded */
+		text = g_strdup_printf ("%s: %s-%s.%s",
+					_("Downloading"),
+					split[PK_PACKAGE_ID_NAME],
+					split[PK_PACKAGE_ID_VERSION],
+					split[PK_PACKAGE_ID_ARCH]);
+		gtk_progress_bar_set_text (progress_bar, text);
+		g_free (text);
+		g_strfreev (split);
 	}
 }
 



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