[gnome-packagekit/glib2: 36/79] moo



commit 1f7c9b1a785824709cd8f18c44e990792aa8a307
Author: Richard Hughes <richard hughsie com>
Date:   Tue Sep 22 14:51:40 2009 +0100

    moo

 src/gpk-dbus-task.c |  127 +++++++++++++++++++++++++++++++--------------------
 src/gpk-log.c       |   17 +++----
 src/gpk-task.c      |   11 +++--
 3 files changed, 92 insertions(+), 63 deletions(-)
---
diff --git a/src/gpk-dbus-task.c b/src/gpk-dbus-task.c
index 29e5bfd..274147a 100644
--- a/src/gpk-dbus-task.c
+++ b/src/gpk-dbus-task.c
@@ -59,13 +59,11 @@ static void	gpk_dbus_task_install_files (GpkDbusTask *task);
 #define GPK_DBUS_TASK_FINISHED_AUTOCLOSE_DELAY	10 /* seconds */
 
 typedef enum {
-	GPK_DBUS_TASK_ROLE_SEARCH_FILE,
 	GPK_DBUS_TASK_ROLE_INSTALL_PACKAGE_FILES,
 	GPK_DBUS_TASK_ROLE_INSTALL_PROVIDE_FILES,
 	GPK_DBUS_TASK_ROLE_INSTALL_MIME_TYPES,
 	GPK_DBUS_TASK_ROLE_INSTALL_GSTREAMER_RESOURCES,
 	GPK_DBUS_TASK_ROLE_INSTALL_FONTCONFIG_RESOURCES,
-	GPK_DBUS_TASK_ROLE_INSTALL_PACKAGE_NAMES,
 	GPK_DBUS_TASK_ROLE_INSTALL_CATALOGS,
 	GPK_DBUS_TASK_ROLE_UNKNOWN
 } GpkDbusTaskRole;
@@ -174,7 +172,7 @@ gpk_dbus_task_set_timestamp (GpkDbusTask *task, guint32 timestamp)
 	return TRUE;
 }
 
-static void gpk_dbus_task_install_package_files_internal (GpkDbusTask *task);
+static void gpk_dbus_task_install_files_internal (GpkDbusTask *task);
 static void gpk_dbus_task_install_package_ids (GpkDbusTask *task);
 
 /**
@@ -537,24 +535,11 @@ gpk_dbus_task_finished_cb (PkClient *client, PkExitEnum exit_enum, guint runtime
 		}
 
 		/* done! */
-		egg_warning ("doing async return");
+		egg_debug ("doing async return");
 		dbus_g_method_return (task->priv->context, TRUE); /* FIXME: we send true? */
 		goto out;
 	}
 
-	/* SearchFile */
-	if (task->priv->role == GPK_DBUS_TASK_ROLE_SEARCH_FILE) {
-		list = pk_results_get_package_array (task->priv->client);
-
-		/* one or more entry? */
-		len = list->len;
-		if (len > 0)
-			name = g_ptr_array_index (list, 0)->id->name;
-		egg_warning ("doing async return");
-		dbus_g_method_return (task->priv->context, (len > 0), name);
-		goto out;
-	}
-
 	/* InstallPackageNames */
 	if (task->priv->role == GPK_DBUS_TASK_ROLE_INSTALL_PACKAGE_NAMES &&
 	    role == PK_ROLE_ENUM_RESOLVE) {
@@ -862,10 +847,10 @@ out:
 }
 
 /**
- * gpk_dbus_task_install_package_files_internal:
+ * gpk_dbus_task_install_files_internal:
  **/
 static void
-gpk_dbus_task_install_package_files_internal (GpkDbusTask *task)
+gpk_dbus_task_install_files_internal (GpkDbusTask *task)
 {
 	/* install async */
 	pk_client_install_files_async (task->priv->client, TRUE, task->priv->files, NULL, NULL, NULL,
@@ -991,10 +976,10 @@ gpk_dbus_task_confirm_action (GpkDbusTask *task, const gchar *title, const gchar
 }
 
 /**
- * pk_client_test_progress_cb:
+ * gpk_dbus_task_progress_cb:
  **/
 static void
-pk_client_test_progress_cb (PkProgress *progress, PkProgressType type, GpkDbusTask *task)
+gpk_dbus_task_progress_cb (PkProgress *progress, PkProgressType type, GpkDbusTask *task)
 {
 	if (type == PK_PROGRESS_TYPE_PACKAGE_ID)
 		egg_debug ("_package");
@@ -1009,17 +994,17 @@ pk_client_test_progress_cb (PkProgress *progress, PkProgressType type, GpkDbusTa
 }
 
 /**
- * pk_client_test_resolve_cb:
+ * gpk_dbus_task_resolve_cb:
  **/
 static void
-pk_client_test_resolve_cb (PkClient *client, GAsyncResult *res, GpkDbusTask *task)
+gpk_dbus_task_resolve_cb (PkClient *client, GAsyncResult *res, GpkDbusTask *task)
 {
 	GError *error = NULL;
 	GError *error_dbus = NULL;
 	PkResults *results = NULL;
-	PkExitEnum exit_enum;
 	GPtrArray *array;
 	gboolean ret;
+	PkItemErrorCode *error_item = NULL;
 
 	/* get the results */
 	results = pk_client_generic_finish (client, res, &error);
@@ -1031,11 +1016,11 @@ pk_client_test_resolve_cb (PkClient *client, GAsyncResult *res, GpkDbusTask *tas
 		goto out;
 	}
 
-	/* failed to get data */
-	exit_enum = pk_results_get_exit_code (results);
-	if (exit_enum != PK_EXIT_ENUM_SUCCESS) {
-		egg_warning ("failed to resolve success: %s", pk_exit_enum_to_text (exit_enum));
-		error_dbus = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_INTERNAL_ERROR, "failed to resolve: %s", pk_exit_enum_to_text (exit_enum));
+	/* check error code */
+	error_item = pk_results_get_error_code (results);
+	if (error_item != NULL) {
+		egg_warning ("failed to resolve: %s, %s", pk_error_enum_to_text (error_item->code), error_item->details);
+		error_dbus = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_INTERNAL_ERROR, "failed to resolve: %s", error_item->details);
 		dbus_g_method_return_error (task->priv->context, error_dbus);
 		goto out;
 	}
@@ -1046,6 +1031,8 @@ pk_client_test_resolve_cb (PkClient *client, GAsyncResult *res, GpkDbusTask *tas
 	egg_debug ("doing async return");
 	dbus_g_method_return (task->priv->context, ret);
 out:
+	if (error_item != NULL)
+		pk_item_error_code_unref (error_item);
 	if (array != NULL)
 		g_ptr_array_unref (array);
 	if (results != NULL)
@@ -1063,38 +1050,80 @@ gpk_dbus_task_is_installed (GpkDbusTask *task, const gchar *package_name)
 	/* get the package list for the installed packages */
 	package_names = g_strsplit (package_name, "|", 1);
 	pk_client_resolve_async (task->priv->client, pk_bitfield_value (PK_FILTER_ENUM_INSTALLED), package_names, NULL,
-				 (PkProgressCallback) pk_client_test_progress_cb, task,
-				 (GAsyncReadyCallback) pk_client_test_resolve_cb, task);
+				 (PkProgressCallback) gpk_dbus_task_progress_cb, task,
+				 (GAsyncReadyCallback) gpk_dbus_task_resolve_cb, task);
 	g_strfreev (package_names);
 }
 
 /**
- * gpk_dbus_task_search_file:
+ * gpk_dbus_task_search_file_cb:
  **/
-void
-gpk_dbus_task_search_file (GpkDbusTask *task, const gchar *search_file)
+static void
+gpk_dbus_task_search_file_cb (PkClient *client, GAsyncResult *res, GpkDbusTask *task)
 {
-	gboolean ret;
 	GError *error = NULL;
-	GError *error_local = NULL;
+	GError *error_dbus = NULL;
+	PkResults *results = NULL;
+	GPtrArray *array;
+	PkItemErrorCode *error_item = NULL;
+	gchar **split = NULL;
+	const PkItemPackage *item;
 
-	task->priv->role = GPK_DBUS_TASK_ROLE_SEARCH_FILE;
+	/* get the results */
+	results = pk_client_generic_finish (client, res, &error);
+	if (results == NULL) {
+		error_dbus = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_INTERNAL_ERROR, "failed to search file: %s", error->message);
+		dbus_g_method_return_error (task->priv->context, error_dbus);
+		egg_warning ("failed to resolve: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
 
-	/* get the package list for the installed packages */
-	egg_warning ("package_name=%s", search_file);
-	ret = pk_client_search_file (task->priv->client, pk_bitfield_value (PK_FILTER_ENUM_INSTALLED), search_file, &error_local);
-	if (!ret) {
-		error = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_INTERNAL_ERROR, "failed to get installed status: %s", error_local->message);
-		dbus_g_method_return_error (task->priv->context, error);
+	/* check error code */
+	error_item = pk_results_get_error_code (results);
+	if (error_item != NULL) {
+		egg_warning ("failed to resolve: %s, %s", pk_error_enum_to_text (error_item->code), error_item->details);
+		error_dbus = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_INTERNAL_ERROR, "failed to search file: %s", error_item->details);
+		dbus_g_method_return_error (task->priv->context, error_dbus);
+		goto out;
+	}
+
+	/* one or more entry? */
+	array = pk_results_get_package_array (results);
+	if (array->len == 0) {
+		egg_warning ("no packages");
+		error_dbus = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_INTERNAL_ERROR, "failed to find any packages");
+		dbus_g_method_return_error (task->priv->context, error_dbus);
 		goto out;
 	}
 
-	/* wait for async reply... */
+	/* get first item */
+	item = g_ptr_array_index (array, 0);
+	split = pk_package_id_split (item->package_id);
+
+	egg_debug ("doing async return");
+	dbus_g_method_return (task->priv->context, (item->info == PK_INFO_ENUM_INSTALLED), split[PK_PACKAGE_ID_NAME]);
 out:
-	if (error != NULL)
-		g_error_free (error);
-	if (error_local != NULL)
-		g_error_free (error_local);
+	g_strfreev (split);
+	if (error_item != NULL)
+		pk_item_error_code_unref (error_item);
+	if (array != NULL)
+		g_ptr_array_unref (array);
+	if (results != NULL)
+		g_object_unref (results);
+}
+
+/**
+ * gpk_dbus_task_search_file:
+ **/
+void
+gpk_dbus_task_search_file (GpkDbusTask *task, const gchar *search_file)
+{
+	/* get the package list for the installed packages */
+	egg_warning ("package_name=%s", search_file);
+	pk_client_search_file_async (task->priv->client, pk_bitfield_value (PK_FILTER_ENUM_INSTALLED), search_file, NULL,
+				     (PkProgressCallback) gpk_dbus_task_progress_cb, task,
+				     (GAsyncReadyCallback) gpk_dbus_task_search_file_cb, task);
 }
 
 /**
@@ -1112,7 +1141,7 @@ gpk_dbus_task_install_files (GpkDbusTask *task)
 	if (task->priv->show_progress)
 		gpk_modal_dialog_present_with_time (task->priv->dialog, task->priv->timestamp);
 
-	gpk_dbus_task_install_package_files_internal (task);
+	gpk_dbus_task_install_files_internal (task);
 }
 
 /**
diff --git a/src/gpk-log.c b/src/gpk-log.c
index bcc3745..861ca8d 100644
--- a/src/gpk-log.c
+++ b/src/gpk-log.c
@@ -25,9 +25,6 @@
 #include <glib/gi18n.h>
 
 #include <gtk/gtk.h>
-//#include <math.h>
-//#include <string.h>
-//#include <dbus/dbus-glib.h>
 #include <locale.h>
 #include <sys/types.h>
 #include <pwd.h>
@@ -37,11 +34,9 @@
 #include <unique/unique.h>
 
 #include "egg-debug.h"
-//#include "egg-string.h"
 
 #include "gpk-common.h"
 #include "gpk-gnome.h"
-//#include "gpk-enum.h"
 
 static GtkBuilder *builder = NULL;
 static GtkListStore *list_store = NULL;
@@ -563,7 +558,7 @@ gpk_log_get_old_transactions_cb (GObject *object, GAsyncResult *res, gpointer us
 //	PkClient *client = PK_CLIENT (object);
 	GError *error = NULL;
 	PkResults *results = NULL;
-	PkExitEnum exit_enum;
+	PkItemErrorCode *error_item = NULL;
 
 	/* get the results */
 	results = pk_client_generic_finish (client, res, &error);
@@ -573,10 +568,10 @@ gpk_log_get_old_transactions_cb (GObject *object, GAsyncResult *res, gpointer us
 		goto out;
 	}
 
-	/* get results */
-	exit_enum = pk_results_get_exit_code (results);
-	if (exit_enum != PK_EXIT_ENUM_SUCCESS) {
-		egg_warning ("failed to get old transactions: %s", pk_exit_enum_to_text (exit_enum));
+	/* check error code */
+	error_item = pk_results_get_error_code (results);
+	if (error_item != NULL) {
+		egg_warning ("failed to get old transactions: %s, %s", pk_error_enum_to_text (error_item->code), error_item->details);
 		goto out;
 	}
 
@@ -586,6 +581,8 @@ gpk_log_get_old_transactions_cb (GObject *object, GAsyncResult *res, gpointer us
 	transactions = pk_results_get_transaction_array (results);
 	gpk_log_refilter ();
 out:
+	if (error_item != NULL)
+		pk_item_error_code_unref (error_item);
 	if (results != NULL)
 		g_object_unref (results);
 }
diff --git a/src/gpk-task.c b/src/gpk-task.c
index b6d23a3..b39c97e 100644
--- a/src/gpk-task.c
+++ b/src/gpk-task.c
@@ -608,10 +608,10 @@ gpk_task_test_install_packages_cb (GObject *object, GAsyncResult *res, EggTest *
 	GpkTask *task = GPK_TASK (object);
 	GError *error = NULL;
 	PkResults *results;
-	PkExitEnum exit_enum;
 	GPtrArray *packages;
 	const PkItemPackage *item;
 	guint i;
+	PkItemErrorCode *error_item = NULL;
 
 	/* get the results */
 	results = pk_task_generic_finish (GPK_TASK (task), res, &error);
@@ -621,9 +621,10 @@ gpk_task_test_install_packages_cb (GObject *object, GAsyncResult *res, EggTest *
 		goto out;
 	}
 
-	exit_enum = pk_results_get_exit_code (results);
-	if (exit_enum != GPK_EXIT_ENUM_SUCCESS)
-		egg_test_failed (test, "failed to resolve success: %s", pk_exit_enum_to_text (exit_enum));
+	/* check error code */
+	error_item = pk_results_get_error_code (results);
+	if (error_item != NULL)
+		egg_test_failed (test, "failed to resolve success: %s", error_item->details);
 
 	packages = pk_results_get_package_array (results);
 	if (packages == NULL)
@@ -642,6 +643,8 @@ gpk_task_test_install_packages_cb (GObject *object, GAsyncResult *res, EggTest *
 
 	egg_debug ("results exit enum = %s", pk_exit_enum_to_text (exit_enum));
 out:
+	if (error_item != NULL)
+		pk_item_error_code_unref (error_item);
 	if (results != NULL)
 		g_object_unref (results);
 	egg_test_loop_quit (test);



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