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



commit 6cffca9b636cde0ebe8fbf88ca226a52ed3f1749
Author: Richard Hughes <richard hughsie com>
Date:   Tue Sep 22 14:23:06 2009 +0100

    moo

 src/gpk-dbus-task.c |  678 +++++++++++----------------------------------------
 src/gpk-firmware.c  |    6 +-
 src/gpk-repo.c      |   43 ++--
 src/gpk-watch.c     |   68 +----
 4 files changed, 173 insertions(+), 622 deletions(-)
---
diff --git a/src/gpk-dbus-task.c b/src/gpk-dbus-task.c
index 4249b18..29e5bfd 100644
--- a/src/gpk-dbus-task.c
+++ b/src/gpk-dbus-task.c
@@ -59,7 +59,6 @@ static void	gpk_dbus_task_install_files (GpkDbusTask *task);
 #define GPK_DBUS_TASK_FINISHED_AUTOCLOSE_DELAY	10 /* seconds */
 
 typedef enum {
-	GPK_DBUS_TASK_ROLE_IS_INSTALLED,
 	GPK_DBUS_TASK_ROLE_SEARCH_FILE,
 	GPK_DBUS_TASK_ROLE_INSTALL_PACKAGE_FILES,
 	GPK_DBUS_TASK_ROLE_INSTALL_PROVIDE_FILES,
@@ -106,6 +105,7 @@ struct _GpkDbusTaskPrivate
 	gchar			**package_ids;
 	gchar			**files;
 	PkErrorCodeEnum		 last_exit_code;
+	GCancellable		*cancellable;
 };
 
 G_DEFINE_TYPE (GpkDbusTask, gpk_dbus_task, G_TYPE_OBJECT)
@@ -174,7 +174,8 @@ gpk_dbus_task_set_timestamp (GpkDbusTask *task, guint32 timestamp)
 	return TRUE;
 }
 
-static void gpk_dbus_task_install_package_files_internal (GpkDbusTask *task, gboolean trusted);
+static void gpk_dbus_task_install_package_files_internal (GpkDbusTask *task);
+static void gpk_dbus_task_install_package_ids (GpkDbusTask *task);
 
 /**
  * gpk_dbus_task_chooser_event_cb:
@@ -287,37 +288,50 @@ gpk_dbus_task_error_msg (GpkDbusTask *task, const gchar *title, GError *error)
 }
 
 /**
+ * gpk_dbus_task_install_packages_cb:
+ **/
+static void
+gpk_dbus_task_install_packages_cb (GObject *object, GAsyncResult *res, GpkDbusTask *task)
+{
+	PkClient *client = PK_CLIENT (object);
+	GError *error = NULL;
+	PkResults *results = NULL;
+
+	/* get the results */
+	results = pk_client_generic_finish (client, res, &error);
+	if (results == NULL) {
+		/* TRANSLATORS: error: failed to install, detailed error follows */
+		gpk_dbus_task_error_msg (task, _("Failed to install package"), error);
+		error = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_INTERNAL_ERROR, "%s", error->message);
+		dbus_g_method_return_error (task->priv->context, error);
+		g_error_free (error);
+		goto out;
+	}
+out:
+	if (results != NULL)
+		g_object_unref (results);
+}
+
+/**
  * gpk_dbus_task_install_package_ids:
  * @task: a valid #GpkDbusTask instance
  **/
 static void
 gpk_dbus_task_install_package_ids (GpkDbusTask *task)
 {
-	gboolean ret;
-	GError *error = NULL;
-	GError *error_local = NULL;
-
 	gpk_modal_dialog_setup (task->priv->dialog, GPK_MODAL_DIALOG_PAGE_PROGRESS, GPK_MODAL_DIALOG_PACKAGE_PADDING);
 	/* TRANSLATORS: title: installing packages */
 	gpk_modal_dialog_set_title (task->priv->dialog, _("Installing packages"));
 	if (task->priv->show_progress)
 		gpk_modal_dialog_present (task->priv->dialog);
 
-	ret = pk_client_install_packages (task->priv->client, TRUE, task->priv->package_ids, &error_local);
-	if (!ret) {
-		/* TRANSLATORS: error: failed to install, detailed error follows */
-		gpk_dbus_task_error_msg (task, _("Failed to install package"), error_local);
-		error = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_INTERNAL_ERROR, "%s", error_local->message);
-		dbus_g_method_return_error (task->priv->context, error);
-		goto out;
-	}
-out:
-	if (error != NULL)
-		g_error_free (error);
-	if (error_local != NULL)
-		g_error_free (error_local);
+	/* install async */
+	pk_client_install_packages_async (task->priv->client, TRUE, task->priv->package_ids, NULL, NULL, NULL,
+					  (GAsyncReadyCallback) gpk_dbus_task_install_packages_cb, task);
 }
 
+#if 0
+
 /**
  * gpk_dbus_task_error_from_exit_enum:
  **/
@@ -347,7 +361,6 @@ out:
 	return error;
 }
 
-
 /**
  * gpk_dbus_task_finished_cb:
  **/
@@ -379,14 +392,6 @@ gpk_dbus_task_finished_cb (PkClient *client, PkExitEnum exit_enum, guint runtime
 	/* stop spinning */
 	gpk_modal_dialog_set_percentage (task->priv->dialog, 100);
 
-	/* we failed because we're handling the auth, just ignore */
-	if (client == task->priv->client &&
-	    (exit_enum == PK_EXIT_ENUM_KEY_REQUIRED ||
-	     exit_enum == PK_EXIT_ENUM_EULA_REQUIRED)) {
-		egg_debug ("ignoring primary sig-required or eula");
-		goto out;
-	}
-
 	if (exit_enum != PK_EXIT_ENUM_SUCCESS) {
 
 		/* show finished? */
@@ -537,17 +542,6 @@ gpk_dbus_task_finished_cb (PkClient *client, PkExitEnum exit_enum, guint runtime
 		goto out;
 	}
 
-	/* IsInstalled */
-	if (task->priv->role == GPK_DBUS_TASK_ROLE_IS_INSTALLED) {
-		list = pk_results_get_package_array (task->priv->client);
-
-		/* one or more entry? */
-		ret = (list->len > 0);
-		egg_warning ("doing async return");
-		dbus_g_method_return (task->priv->context, ret);
-		goto out;
-	}
-
 	/* SearchFile */
 	if (task->priv->role == GPK_DBUS_TASK_ROLE_SEARCH_FILE) {
 		list = pk_results_get_package_array (task->priv->client);
@@ -657,6 +651,7 @@ out:
 	if (list != NULL)
 		g_object_unref (list);
 }
+#endif
 
 /**
  * gpk_dbus_task_set_status:
@@ -708,6 +703,7 @@ gpk_dbus_task_set_status (GpkDbusTask *task, PkStatusEnum status)
 	return TRUE;
 }
 
+#if 0
 /**
  * gpk_dbus_task_progress_changed_cb:
  **/
@@ -814,6 +810,7 @@ gpk_dbus_task_allow_cancel_cb (PkClient *client, gboolean allow_cancel, GpkDbusT
 {
 	gpk_modal_dialog_set_allow_cancel (task->priv->dialog, allow_cancel);
 }
+#endif
 
 /**
  * gpk_dbus_task_button_close_cb:
@@ -836,36 +833,43 @@ gpk_dbus_task_button_cancel_cb (GtkWidget *widget, GpkDbusTask *task)
 }
 
 /**
- * gpk_dbus_task_install_package_files_internal:
+ * gpk_dbus_task_install_files_cb:
  **/
 static void
-gpk_dbus_task_install_package_files_internal (GpkDbusTask *task, gboolean trusted)
+gpk_dbus_task_install_files_cb (GObject *object, GAsyncResult *res, GpkDbusTask *task)
 {
-	gboolean ret;
+	PkClient *client = PK_CLIENT (object);
 	GError *error = NULL;
-	GError *error_local = NULL;
+	PkResults *results = NULL;
 	guint length;
 	const gchar *title;
 
-	/* FIXME: we need to move this into PkClient sooner or later */
-	task->priv->last_exit_code = PK_ERROR_ENUM_UNKNOWN;
-
-	/* install local file */
-	ret = pk_client_install_files (task->priv->client, trusted, task->priv->files, &error_local);
-	if (!ret) {
+	/* get the results */
+	results = pk_client_generic_finish (client, res, &error);
+	if (results == NULL) {
+		/* TRANSLATORS: error: failed to install, detailed error follows */
 		length = g_strv_length (task->priv->files);
-		/* TRANSLATORS: title: detailed internal error why the file install failed */
 		title = ngettext ("Failed to install file", "Failed to install files", length);
-		gpk_dbus_task_error_msg (task, title, error_local);
-		error = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_INTERNAL_ERROR, "%s", error_local->message);
+		gpk_dbus_task_error_msg (task, title, error);
+		error = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_INTERNAL_ERROR, "%s", error->message);
 		dbus_g_method_return_error (task->priv->context, error);
+		g_error_free (error);
 		goto out;
 	}
 out:
-	if (error != NULL)
-		g_error_free (error);
-	if (error_local != NULL)
-		g_error_free (error_local);
+	if (results != NULL)
+		g_object_unref (results);
+}
+
+/**
+ * gpk_dbus_task_install_package_files_internal:
+ **/
+static void
+gpk_dbus_task_install_package_files_internal (GpkDbusTask *task)
+{
+	/* install async */
+	pk_client_install_files_async (task->priv->client, TRUE, task->priv->files, NULL, NULL, NULL,
+				       (GAsyncReadyCallback) gpk_dbus_task_install_files_cb, task);
 }
 
 /**
@@ -908,265 +912,6 @@ gpk_dbus_task_ptr_array_to_bullets (GPtrArray *array, const gchar *prefix)
 }
 
 /**
- * gpk_dbus_task_install_package_files_get_user_temp:
- *
- * Return (and create if does not exist) a temporary directory
- * that is writable only by the user, and readable by root.
- *
- * Return value: the temp directory, or %NULL for create error
- **/
-static gchar *
-gpk_dbus_task_install_package_files_get_user_temp (GpkDbusTask *task, const gchar *subfolder, GError **error)
-{
-	GFile *file;
-	gboolean ret;
-	gchar *path = NULL;
-
-	/* build path in home folder */
-	path = g_build_filename (g_get_home_dir (), ".PackageKit", subfolder, NULL);
-
-	/* find if exists */
-	file = g_file_new_for_path (path);
-	ret = g_file_query_exists (file, NULL);
-	if (ret)
-		goto out;
-
-	/* create as does not exist */
-	ret = g_file_make_directory_with_parents (file, NULL, error);
-	g_object_unref (file);
-	if (!ret) {
-		/* return nothing.. */
-		g_free (path);
-		path = NULL;
-	}
-out:
-	return path;
-}
-
-GMainLoop *_loop = NULL;
-
-/**
- * gpk_dbus_task_install_package_files_ready_callback:
- **/
-static void
-gpk_dbus_task_install_package_files_ready_callback (GObject *source_object, GAsyncResult *res, GpkDbusTask *task)
-{
-	gboolean ret;
-	GError *error_local = NULL;
-
-	g_return_if_fail (GPK_IS_DBUS_TASK (task));
-
-	ret = g_file_copy_finish (G_FILE (source_object), res, &error_local);
-	if (!ret) {
-		egg_warning ("failed to copy file: %s", error_local->message);
-		g_error_free (error_local);
-	}
-
-	g_main_loop_quit (_loop);
-}
-
-/**
- * gpk_dbus_task_install_package_files_progress_callback:
- **/
-static void
-gpk_dbus_task_install_package_files_progress_callback (goffset current_num_bytes, goffset total_num_bytes, GpkDbusTask *task)
-{
-	guint percentage;
-	g_return_if_fail (GPK_IS_DBUS_TASK (task));
-	percentage = (current_num_bytes * 100) / total_num_bytes;
-	gpk_modal_dialog_set_percentage (task->priv->dialog, percentage);
-}
-
-/**
- * gpk_dbus_task_install_package_files_copy_non_native:
- *
- * Copy the new file into a new file that can be read by packagekitd, and
- * that can't be written into by other users.
- *
- * Return value: the new file path, or %NULL for copy error
- **/
-static gchar *
-gpk_dbus_task_install_package_files_copy_non_native (GpkDbusTask *task, const gchar *filename, GError **error)
-{
-	GFile *file = NULL;
-	GFile *dest = NULL;
-	gchar *basename = NULL;
-	gchar *dest_path = NULL;
-	gchar *new_path = NULL;
-	gchar *cache_path = NULL;
-	GError *error_local = NULL;
-
-	/* create the non FUSE temp directory */
-	cache_path = gpk_dbus_task_install_package_files_get_user_temp (task, "native-cache", &error_local);
-	if (cache_path == NULL) {
-		*error = g_error_new (1, 0, "failed to create temp directory: %s", error_local->message);
-		g_error_free (error_local);
-		goto out;
-	}
-
-	/* get the final location */
-	file = g_file_new_for_path (filename);
-	basename = g_file_get_basename (file);
-	dest_path = g_build_filename (cache_path, basename, NULL);
-
-	/* copy the file */
-	dest = g_file_new_for_path (dest_path);
-	g_file_copy_async (file, dest, G_FILE_COPY_OVERWRITE, 0, NULL,
-			   (GFileProgressCallback) gpk_dbus_task_install_package_files_progress_callback, task,
-			   (GAsyncReadyCallback) gpk_dbus_task_install_package_files_ready_callback, task);
-	_loop = g_main_loop_new (NULL, FALSE);
-	g_main_loop_run (_loop);
-	g_main_loop_unref (_loop);
-
-	/* return the modified file item */
-	new_path = g_strdup (dest_path);
-
-out:
-	if (file != NULL)
-		g_object_unref (file);
-	if (dest != NULL)
-		g_object_unref (dest);
-	g_free (basename);
-	g_free (cache_path);
-	g_free (dest_path);
-	return new_path;
-}
-
-/**
- * gpk_dbus_task_install_package_files_native_check:
- *
- * Allow the user to confirm the package copy to ~/.PackageKit/native-cache
- * as we cannot access FUSE mounts as the root user.
- *
- * Return value: %TRUE if the method succeeded
- **/
-static gboolean
-gpk_dbus_task_install_package_files_native_check (GpkDbusTask *task, GPtrArray *array, GError **error)
-{
-	guint i;
-	const gchar *data;
-	gchar *cache_path = NULL;
-	gchar *filename;
-	gboolean ret;
-	gboolean native;
-	GPtrArray *array_missing;
-	const gchar *message_part;
-	const gchar *title;
-	gchar *message;
-	GtkResponseType button;
-	GError *error_local = NULL;
-	GFile *file;
-
-	/* check if any files are non-native and need to be copied */
-	array_missing = g_ptr_array_new_with_free_func (g_free);
-	for (i=0; i<array->len; i++) {
-		data = (const gchar *) g_ptr_array_index (array, i);
-		/* if file is non-native, it's on a FUSE mount (probably created by GVFS).
-		 * See https://bugzilla.redhat.com/show_bug.cgi?id=456094 */
-		file = g_file_new_for_path (data);
-		native = g_file_is_native (file);
-		g_object_unref (file);
-		if (!native) {
-			egg_debug ("%s is non-native", data);
-			g_ptr_array_add (array_missing, g_strdup (data));
-		}
-	}
-
-	/* optional */
-	ret = gconf_client_get_bool (task->priv->gconf_client, GPK_CONF_SHOW_COPY_CONFIRM, NULL);
-	if (ret && array_missing->len > 0) {
-		/* TRANSLATORS: title: we have to copy the private files to a public location */
-		title = ngettext ("Do you want to copy this file?",
-				  "Do you want to copy these files?", array_missing->len);
-		/* TRANSLATORS: message: explain to the user what we are doing */
-		message_part = ngettext ("This package file has to be copied from a private directory so it can be installed:",
-					 "Several package files have to be copied from a private directory so they can be installed:",
-					 array_missing->len);
-		message = gpk_dbus_task_ptr_array_to_bullets (array_missing, message_part);
-
-		/* show UI */
-		gpk_modal_dialog_setup (task->priv->dialog, GPK_MODAL_DIALOG_PAGE_CONFIRM, 0);
-		gpk_modal_dialog_set_title (task->priv->dialog, title);
-		gpk_modal_dialog_set_message (task->priv->dialog, message);
-		gpk_modal_dialog_set_image (task->priv->dialog, "dialog-warning");
-		/* TRANSLATORS: button: copy file from one directory to another */
-		gpk_modal_dialog_set_action (task->priv->dialog, ngettext ("Copy file", "Copy files", array_missing->len));
-		gpk_modal_dialog_set_help_id (task->priv->dialog, "dialog-installing-private-files");
-		g_free (message);
-
-		gpk_modal_dialog_present_with_time (task->priv->dialog, task->priv->timestamp);
-		button = gpk_modal_dialog_run (task->priv->dialog);
-		/* did we click no or exit the window? */
-		if (button != GTK_RESPONSE_OK) {
-			*error = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_CANCELLED, "Aborted the copy");
-			ret = FALSE;
-			goto out;
-		}
-	}
-
-	/* setup UI */
-	if (array_missing->len > 0) {
-		/* TRANSLATORS: title: we are about to copy files, which may take a few seconds */
-		title = ngettext ("Copying file",
-				  "Copying files", array_missing->len);
-		gpk_modal_dialog_setup (task->priv->dialog, GPK_MODAL_DIALOG_PAGE_PROGRESS, 0);
-		gpk_modal_dialog_set_title (task->priv->dialog, title);
-		gpk_modal_dialog_set_help_id (task->priv->dialog, "dialog-installing-private-files");
-		gpk_modal_dialog_present_with_time (task->priv->dialog, task->priv->timestamp);
-	}
-
-	/* now we have the okay to copy the files, do so */
-	ret = TRUE;
-	for (i=0; i<array->len; i++) {
-		data = (const gchar *) g_ptr_array_index (array, i);
-
-		/* check we are not on FUSE */
-		file = g_file_new_for_path (data);
-		native = g_file_is_native (file);
-		g_object_unref (file);
-		if (!native) {
-			/* copy the file */
-			filename = gpk_dbus_task_install_package_files_copy_non_native (task, data, &error_local);
-			if (filename == NULL) {
-				*error = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_FAILED, "failed to copy file %s: %s", data, error_local->message);
-				ret = FALSE;
-				break;
-			}
-
-			/* show progress */
-			gpk_modal_dialog_set_message (task->priv->dialog, filename);
-
-			/* swap data in array */
-			g_free (array->pdata[i]);
-			array->pdata[i] = g_strdup (filename);
-			g_free (filename);
-		}
-	}
-
-	/* did we fail to copy the files */
-	if (!ret) {
-		/* TRANSLATORS: title: tell the user we failed */
-		title = ngettext ("The file could not be copied",
-				  "The files could not be copied", array_missing->len);
-
-		/* show UI */
-		gpk_modal_dialog_setup (task->priv->dialog, GPK_MODAL_DIALOG_PAGE_WARNING, 0);
-		gpk_modal_dialog_set_title (task->priv->dialog, title);
-		gpk_modal_dialog_set_message (task->priv->dialog, error_local->message);
-		gpk_modal_dialog_present_with_time (task->priv->dialog, task->priv->timestamp);
-		gpk_modal_dialog_run (task->priv->dialog);
-		*error = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_FAILED, "files not copied");
-		ret = FALSE;
-		g_error_free (error_local);
-		goto out;
-	}
-out:
-	g_free (cache_path);
-	g_ptr_array_unref (array_missing);
-	return ret;
-}
-
-/**
  * gpk_dbus_task_install_package_files_verify:
  *
  * Allow the user to confirm the action
@@ -1208,183 +953,6 @@ out:
 }
 
 /**
- * gpk_dbus_task_install_package_files_check_exists:
- *
- * Skip files that are not present
- *
- * Return value: %TRUE if the method succeeded
- **/
-static gboolean
-gpk_dbus_task_install_package_files_check_exists (GpkDbusTask *task, GPtrArray *array, GError **error)
-{
-	guint i;
-	const gchar *data;
-	gboolean ret;
-	GPtrArray *array_missing;
-	const gchar *message_part;
-	const gchar *title;
-	gchar *message;
-
-	array_missing = g_ptr_array_new_with_free_func (g_free)
-
-	/* find missing */
-	for (i=0; i<array->len; i++) {
-		data = (const gchar *) g_ptr_array_index (array, i);
-		ret = g_file_test (data, G_FILE_TEST_EXISTS);
-		if (!ret)
-			g_ptr_array_add (array_missing, g_strdup (data));
-	}
-
-	/* warn, set error and quit */
-	ret = TRUE;
-	if (array_missing->len > 0) {
-		/* TRANSLATORS: title: we couldn't find the file -- very hard to get this */
-		title = ngettext ("File was not found!",
-				  "Files were not found!", array_missing->len);
-
-		/* TRANSLATORS: message: explain what went wrong */
-		message_part = ngettext ("The following file was not found:",
-					 "The following files were not found:", array_missing->len);
-		message = gpk_dbus_task_ptr_array_to_bullets (array_missing, message_part);
-
-		/* show UI */
-		gpk_modal_dialog_setup (task->priv->dialog, GPK_MODAL_DIALOG_PAGE_WARNING, 0);
-		gpk_modal_dialog_set_title (task->priv->dialog, title);
-		gpk_modal_dialog_set_message (task->priv->dialog, message);
-		gpk_modal_dialog_present_with_time (task->priv->dialog, task->priv->timestamp);
-		gpk_modal_dialog_run (task->priv->dialog);
-
-		g_free (message);
-
-		ret = FALSE;
-		*error = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_FAILED, "some files did not exist");
-		goto out;
-	}
-
-out:
-	g_ptr_array_unref (array_missing);
-	return ret;
-}
-
-/**
- * gpk_dbus_task_install_package_files_check_type_get_content_type:
- **/
-static gchar *
-gpk_dbus_task_install_package_files_check_type_get_content_type (const gchar *filename, GError **error)
-{
-	GError *error_local = NULL;
-	GFile *file;
-	GFileInfo *info;
-	gchar *content_type = NULL;
-
-	/* get file info synchronously */
-	file = g_file_new_for_path (filename);
-	info = g_file_query_info (file, "standard::content-type", G_FILE_QUERY_INFO_NONE, NULL, &error_local);
-	if (info == NULL) {
-		*error = g_error_new (1, 0, "failed to get file attributes for %s: %s", filename, error_local->message);
-		g_error_free (error_local);
-		goto out;
-	}
-
-	/* get content type as string */
-	content_type = g_file_info_get_attribute_as_string (info, "standard::content-type");
-out:
-	if (info != NULL)
-		g_object_unref (info);
-	g_object_unref (file);
-	return content_type;
-}
-
-/**
- * gpk_dbus_task_install_package_files_check_type:
- *
- * Skip files that are not present
- *
- * Return value: %TRUE if the method succeeded
- **/
-static gboolean
-gpk_dbus_task_install_package_files_check_type (GpkDbusTask *task, GPtrArray *array, GError **error)
-{
-	guint i;
-	guint j;
-	const gchar *data;
-	gboolean ret = FALSE;
-	GPtrArray *array_unknown;
-	const gchar *message_part;
-	const gchar *title;
-	gchar *message;
-	gchar *content_type;
-	GError *error_local = NULL;
-	gchar **supported_types;
-
-	array_unknown = g_ptr_array_new_with_free_func (g_free)
-
-	/* get mime types supported by the backend */
-	supported_types = pk_control_get_mime_types (task->priv->control, &error_local);
-	if (supported_types == NULL) {
-		*error = g_error_new (1, 0, "failed to get supported types for the backend: %s", error_local->message);
-		g_error_free (error_local);
-		goto out;
-	}
-
-	/* find invalid files */
-	for (i=0; i<array->len; i++) {
-		data = (const gchar *) g_ptr_array_index (array, i);
-
-		/* get content type for this file */
-		content_type = gpk_dbus_task_install_package_files_check_type_get_content_type (data, error);
-		if (content_type == NULL)
-			goto out;
-		egg_warning ("content_type=%s", content_type);
-
-		/* can we support this one? */
-		ret = FALSE;
-		for (j=0; supported_types[j] != NULL; j++) {
-			if (g_strcmp0 (supported_types[j], content_type) == 0) {
-				ret = TRUE;
-				break;
-			}
-		}
-		g_free (content_type);
-
-		/* we can't handle the content type :-( */
-		if (!ret)
-			g_ptr_array_add (array_unknown, g_strdup (data));
-	}
-
-	/* warn, set error and quit */
-	ret = TRUE;
-	if (array_unknown->len > 0) {
-		/* TRANSLATORS: title: we couldn't find the file -- very hard to get this */
-		title = ngettext ("File was not recognised!",
-				  "Files were not recognised!", array_unknown->len);
-
-		/* TRANSLATORS: message: the backend would not be able to handle the mime-type */
-		message_part = ngettext ("The following file is not recognised by the packaging system:",
-					 "The following files are not recognised by the packaging system:", array_unknown->len);
-		message = gpk_dbus_task_ptr_array_to_bullets (array_unknown, message_part);
-
-		/* show UI */
-		gpk_modal_dialog_setup (task->priv->dialog, GPK_MODAL_DIALOG_PAGE_WARNING, 0);
-		gpk_modal_dialog_set_title (task->priv->dialog, title);
-		gpk_modal_dialog_set_message (task->priv->dialog, message);
-		gpk_modal_dialog_present_with_time (task->priv->dialog, task->priv->timestamp);
-		gpk_modal_dialog_run (task->priv->dialog);
-
-		g_free (message);
-
-		ret = FALSE;
-		*error = g_error_new (GPK_DBUS_ERROR, GPK_DBUS_ERROR_FAILED, "some files were not recognised");
-		goto out;
-	}
-
-out:
-	g_strfreev (supported_types);
-	g_ptr_array_unref (array_unknown);
-	return ret;
-}
-
-/**
  * gpk_dbus_task_confirm_action:
  * @task: a valid #GpkDbusTask instance
  **/
@@ -1423,35 +991,81 @@ gpk_dbus_task_confirm_action (GpkDbusTask *task, const gchar *title, const gchar
 }
 
 /**
- * gpk_dbus_task_is_installed:
+ * pk_client_test_progress_cb:
  **/
-void
-gpk_dbus_task_is_installed (GpkDbusTask *task, const gchar *package_name)
+static void
+pk_client_test_progress_cb (PkProgress *progress, PkProgressType type, GpkDbusTask *task)
+{
+	if (type == PK_PROGRESS_TYPE_PACKAGE_ID)
+		egg_debug ("_package");
+	if (type == PK_PROGRESS_TYPE_PERCENTAGE)
+		egg_debug ("_progress");
+	if (type == PK_PROGRESS_TYPE_SUBPERCENTAGE)
+		egg_debug ("_progress");
+	if (type == PK_PROGRESS_TYPE_ALLOW_CANCEL)
+		egg_debug ("_allow_cancel");
+	if (type == PK_PROGRESS_TYPE_STATUS)
+		egg_debug ("_status");
+}
+
+/**
+ * pk_client_test_resolve_cb:
+ **/
+static void
+pk_client_test_resolve_cb (PkClient *client, GAsyncResult *res, GpkDbusTask *task)
 {
-	gboolean ret;
 	GError *error = NULL;
-	GError *error_local = NULL;
-	gchar **package_names = NULL;
+	GError *error_dbus = NULL;
+	PkResults *results = NULL;
+	PkExitEnum exit_enum;
+	GPtrArray *array;
+	gboolean ret;
 
-	task->priv->role = GPK_DBUS_TASK_ROLE_IS_INSTALLED;
+	/* 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 resolve: %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 */
-	package_names = g_strsplit (package_name, "|", 1);
-	egg_warning ("package_name=%s", package_name);
-	ret = pk_client_resolve (task->priv->client, pk_bitfield_value (PK_FILTER_ENUM_INSTALLED), package_names, &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);
+	/* 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));
+		dbus_g_method_return_error (task->priv->context, error_dbus);
 		goto out;
 	}
 
-	/* wait for async reply... */
+	/* one or more entry? */
+	array = pk_results_get_package_array (results);
+	ret = (array->len > 0);
+	egg_debug ("doing async return");
+	dbus_g_method_return (task->priv->context, ret);
 out:
+	if (array != NULL)
+		g_ptr_array_unref (array);
+	if (results != NULL)
+		g_object_unref (results);
+}
+
+/**
+ * gpk_dbus_task_is_installed:
+ **/
+void
+gpk_dbus_task_is_installed (GpkDbusTask *task, const gchar *package_name)
+{
+	gchar **package_names = NULL;
+
+	/* 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);
 	g_strfreev (package_names);
-	if (error != NULL)
-		g_error_free (error);
-	if (error_local != NULL)
-		g_error_free (error_local);
 }
 
 /**
@@ -1498,7 +1112,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, TRUE);
+	gpk_dbus_task_install_package_files_internal (task);
 }
 
 /**
@@ -1518,7 +1132,6 @@ gpk_dbus_task_install_package_files (GpkDbusTask *task, gchar **files_rel)
 	GError *error = NULL;
 	gboolean ret;
 	GPtrArray *array;
-//	const gchar *title;
 
 	g_return_if_fail (GPK_IS_DBUS_TASK (task));
 	g_return_if_fail (files_rel != NULL);
@@ -1534,27 +1147,6 @@ gpk_dbus_task_install_package_files (GpkDbusTask *task, gchar **files_rel)
 		}
 	}
 
-	/* check all files exist and are readable by the local user */
-	ret = gpk_dbus_task_install_package_files_check_exists (task, array, &error);
-	if (!ret) {
-		dbus_g_method_return_error (task->priv->context, error);
-		goto out;
-	}
-
-	/* check all files can be handled by the backend */
-	ret = gpk_dbus_task_install_package_files_check_type (task, array, &error);
-	if (!ret) {
-		dbus_g_method_return_error (task->priv->context, error);
-		goto out;
-	}
-
-	/* check all files exist and are readable by the local user */
-	ret = gpk_dbus_task_install_package_files_native_check (task, array, &error);
-	if (!ret) {
-		dbus_g_method_return_error (task->priv->context, error);
-		goto out;
-	}
-
 	/* check for deps */
 	task->priv->files = pk_ptr_array_to_strv (array);
 	gpk_dbus_task_install_files_internal (task);
@@ -2747,6 +2339,7 @@ gpk_dbus_task_init (GpkDbusTask *task)
 	task->priv->parent_icon_name = NULL;
 	task->priv->error_details = NULL;
 	task->priv->context = NULL;
+	task->priv->cancellable = g_cancellable_new ();
 	task->priv->exit = PK_EXIT_ENUM_FAILED;
 	task->priv->show_confirm_search = TRUE;
 	task->priv->show_confirm_deps = TRUE;
@@ -2795,6 +2388,7 @@ gpk_dbus_task_init (GpkDbusTask *task)
 	task->priv->roles = pk_control_get_properties (task->priv->control, NULL, NULL);
 
 	task->priv->client = pk_client_new ();
+#if 0
 	g_signal_connect (task->priv->client, "finished",
 			  G_CALLBACK (gpk_dbus_task_finished_cb), task);
 	g_signal_connect (task->priv->client, "progress-changed",
@@ -2807,6 +2401,7 @@ gpk_dbus_task_init (GpkDbusTask *task)
 			  G_CALLBACK (gpk_dbus_task_package_cb), task);
 	g_signal_connect (task->priv->client, "allow-cancel",
 			  G_CALLBACK (gpk_dbus_task_allow_cancel_cb), task);
+#endif
 
 	/* used for icons and translations */
 	task->priv->desktop = pk_desktop_new ();
@@ -2841,6 +2436,7 @@ gpk_dbus_task_finalize (GObject *object)
 	g_object_unref (task->priv->dialog);
 	g_object_unref (task->priv->vendor);
 	g_object_unref (task->priv->language);
+	g_object_unref (task->priv->cancellable);
 	g_object_unref (task->priv->helper_run);
 	g_object_unref (task->priv->helper_chooser);
 
@@ -2891,7 +2487,7 @@ gpk_dbus_task_test (gpointer data)
 	if (task != NULL)
 		egg_test_success (test, NULL);
 	else
-		egg_test_failed (test, NULL);
+		egg_warning (NULL);
 
 	/************************************************************/
 	egg_test_title (test, "convert tag to lang");
@@ -2899,7 +2495,7 @@ gpk_dbus_task_test (gpointer data)
 	if (g_strcmp0 (lang, "mn") == 0)
 		egg_test_success (test, NULL);
 	else
-		egg_test_failed (test, "lang '%s'", lang);
+		egg_warning ("lang '%s'", lang);
 	g_free (lang);
 
 	/************************************************************/
@@ -2908,7 +2504,7 @@ gpk_dbus_task_test (gpointer data)
 	if (g_strcmp0 (language, "Mongolian") == 0)
 		egg_test_success (test, NULL);
 	else
-		egg_test_failed (test, "language '%s'", language);
+		egg_warning ("language '%s'", language);
 	g_free (language);
 
 	/************************************************************/
@@ -2917,7 +2513,7 @@ gpk_dbus_task_test (gpointer data)
 	if (ret)
 		egg_test_success (test, NULL);
 	else
-		egg_test_failed (test, "failed to identify trusted");
+		egg_warning ("failed to identify trusted");
 
 	/************************************************************/
 	egg_test_title (test, "test trusted path");
@@ -2925,7 +2521,7 @@ gpk_dbus_task_test (gpointer data)
 	if (!ret)
 		egg_test_success (test, NULL);
 	else
-		egg_test_failed (test, "identify untrusted as trusted!");
+		egg_warning ("identify untrusted as trusted!");
 
 	/************************************************************/
 	egg_test_title (test, "get package for exec");
@@ -2933,7 +2529,7 @@ gpk_dbus_task_test (gpointer data)
 	if (g_strcmp0 (package, "totem") == 0)
 		egg_test_success (test, NULL);
 	else
-		egg_test_failed (test, "package '%s'", package);
+		egg_warning ("package '%s'", package);
 	g_free (package);
 
 	/************************************************************/
@@ -2942,7 +2538,7 @@ gpk_dbus_task_test (gpointer data)
 	if (ret)
 		egg_test_success (test, NULL);
 	else
-		egg_test_failed (test, "failed to set exec");
+		egg_warning ("failed to set exec");
 
 #if 0
 	/************************************************************/
diff --git a/src/gpk-firmware.c b/src/gpk-firmware.c
index 91f8f19..abcc9d4 100644
--- a/src/gpk-firmware.c
+++ b/src/gpk-firmware.c
@@ -342,10 +342,10 @@ gpk_firmware_require_nothing (GpkFirmware *firmware)
 }
 
 /**
- * gpk_hardware_install_packages_cb:
+ * gpk_firmware_install_packages_cb:
  **/
 static void
-gpk_hardware_install_packages_cb (GObject *object, GAsyncResult *res, GpkFirmware *firmware)
+gpk_firmware_install_packages_cb (GObject *object, GAsyncResult *res, GpkFirmware *firmware)
 {
 	PkClient *client = PK_CLIENT (object);
 	GError *error = NULL;
@@ -411,7 +411,7 @@ gpk_firmware_install_file (GpkFirmware *firmware)
 	/* install all of the firmware files */
 	package_ids = pk_package_array_to_strv (firmware->priv->packages_found);
 	pk_client_install_packages_async (firmware->priv->client, TRUE, package_ids, NULL, NULL, NULL,
-					  (GAsyncReadyCallback) gpk_hardware_install_packages_cb, firmware);
+					  (GAsyncReadyCallback) gpk_firmware_install_packages_cb, firmware);
 	g_strfreev (package_ids);
 }
 
diff --git a/src/gpk-repo.c b/src/gpk-repo.c
index d04a7b6..702b0dd 100644
--- a/src/gpk-repo.c
+++ b/src/gpk-repo.c
@@ -25,15 +25,11 @@
 #include <locale.h>
 
 #include <gtk/gtk.h>
-//#include <math.h>
-//#include <string.h>
-//#include <dbus/dbus-glib.h>
 #include <gconf/gconf-client.h>
 #include <packagekit-glib2/packagekit.h>
 #include <unique/unique.h>
 
 #include "egg-debug.h"
-//#include "egg-string.h"
 
 #include "gpk-gnome.h"
 #include "gpk-common.h"
@@ -230,7 +226,8 @@ gpk_repo_repo_enable_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 //	PkClient *client = PK_CLIENT (object);
 	GError *error = NULL;
 	PkResults *results = NULL;
-	PkExitEnum exit_enum;
+	PkItemErrorCode *error_item = NULL;
+	GtkWindow *window;
 
 	/* get the results */
 	results = pk_client_generic_finish (client, res, &error);
@@ -240,13 +237,19 @@ gpk_repo_repo_enable_cb (GObject *object, GAsyncResult *res, gpointer user_data)
 		goto out;
 	}
 
-	/* get results */
-	exit_enum = pk_results_get_exit_code (results);
-	if (exit_enum != PK_EXIT_ENUM_SUCCESS) {
-		egg_warning ("failed to set repo: %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 set repo: %s, %s", pk_error_enum_to_text (error_item->code), error_item->details);
+		window = GTK_WINDOW (gtk_builder_get_object (builder, "dialog_repo"));
+		/* TRANSLATORS: for one reason or another, we could not enable or disable a software source */
+		gpk_error_dialog_modal (window, _("Failed to change status"),
+					gpk_error_enum_to_localised_text (error_item->code), error_item->details);
 		goto out;
 	}
 out:
+	if (error_item != NULL)
+		pk_item_error_code_unref (error_item);
 	if (results != NULL)
 		g_object_unref (results);
 }
@@ -351,10 +354,9 @@ gpk_repo_get_repo_list_cb (GObject *object, GAsyncResult *res, gpointer user_dat
 //	PkClient *client = PK_CLIENT (object);
 	GError *error = NULL;
 	PkResults *results = NULL;
-	PkExitEnum exit_enum;
+	PkItemErrorCode *error_item = NULL;
 	GtkTreeView *treeview;
 	GtkTreeModel *model;
-	PkItemErrorCode *item_error;
 	GtkWindow *window;
 	GPtrArray *array = NULL;
 	guint i;
@@ -369,21 +371,14 @@ gpk_repo_get_repo_list_cb (GObject *object, GAsyncResult *res, gpointer user_dat
 		goto out;
 	}
 
-	/* get results */
-	exit_enum = pk_results_get_exit_code (results);
-	if (exit_enum != PK_EXIT_ENUM_SUCCESS) {
-		egg_warning ("failed to get repo list: %s", pk_exit_enum_to_text (exit_enum));
-		item_error = pk_results_get_error_code (results);
-
+	/* check error code */
+	error_item = pk_results_get_error_code (results);
+	if (error_item != NULL) {
+		egg_warning ("failed to get repo list: %s, %s", pk_error_enum_to_text (error_item->code), error_item->details);
 		window = GTK_WINDOW (gtk_builder_get_object (builder, "dialog_repo"));
 		/* TRANSLATORS: for one reason or another, we could not get the list of sources */
 		gpk_error_dialog_modal (window, _("Failed to get the list of sources"),
-					gpk_error_enum_to_localised_text (item_error->code), item_error->details);
-//		/* TRANSLATORS: for one reason or another, we could not enable or disable a software source */
-//		gpk_error_dialog_modal (window, _("Failed to change status"),
-//					gpk_error_enum_to_localised_text (item_error->code), item_error->details);
-
-		pk_item_error_code_unref (item_error);
+					gpk_error_enum_to_localised_text (error_item->code), error_item->details);
 		goto out;
 	}
 
@@ -410,6 +405,8 @@ gpk_repo_get_repo_list_cb (GObject *object, GAsyncResult *res, gpointer user_dat
 	/* sort */
 	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(list_store), REPO_COLUMN_TEXT, GTK_SORT_ASCENDING);
 out:
+	if (error_item != NULL)
+		pk_item_error_code_unref (error_item);
 	if (array != NULL)
 		g_ptr_array_unref (array);
 	if (results != NULL)
diff --git a/src/gpk-watch.c b/src/gpk-watch.c
index afdb18a..f669132 100644
--- a/src/gpk-watch.c
+++ b/src/gpk-watch.c
@@ -1329,42 +1329,23 @@ pk_watch_process_messages_cb (PkItemMessage *item, GpkWatch *watch)
 }
 
 /**
- * pk_watch_process_error_code_cb:
+ * pk_watch_process_error_code:
  **/
 static void
-pk_watch_process_error_code_cb (PkItemErrorCode *item, GpkWatch *watch)
+pk_watch_process_error_code (GpkWatch *watch, PkItemErrorCode *item)
 {
 	gboolean ret;
 	GError *error = NULL;
 	const gchar *title;
 	gchar *title_prefix = NULL;
 	const gchar *message;
-	gboolean caller_active = FALSE;
 	gboolean value;
 	NotifyNotification *notification;
-	PkResults *results = PK_RESULTS (item->user_data);
-	PkProgress *progress = NULL;
 
 	g_return_if_fail (GPK_IS_WATCH (watch));
 
 	title = gpk_error_enum_to_localised_text (item->code);
 
-	/* get progress data about the transaction */
-	g_object_get (results,
-		      "progress", &progress,
-		      NULL);
-
-	/* if the client dbus connection is still active */
-	g_object_get (progress,
-		      "caller-active", &caller_active,
-		      NULL);
-
-	/* do we ignore this error? */
-	if (caller_active) {
-		egg_debug ("client active so leaving error %s%s", title, item->details);
-		goto out;
-	}
-
 	/* ignore some errors */
 	if (item->code == PK_ERROR_ENUM_NOT_SUPPORTED ||
 	    item->code == PK_ERROR_ENUM_NO_NETWORK ||
@@ -1406,17 +1387,6 @@ pk_watch_process_error_code_cb (PkItemErrorCode *item, GpkWatch *watch)
 	}
 out:
 	g_free (title_prefix);
-	if (progress != NULL)
-		g_object_unref (progress);
-}
-
-/**
- * pk_watch_set_error_code_userdata_cb:
- **/
-static void
-pk_watch_set_error_code_userdata_cb (PkItemErrorCode *item, PkResults *results)
-{
-	item->user_data = results;
 }
 
 /**
@@ -1470,10 +1440,10 @@ gpk_watch_adopt_cb (PkClient *client, GAsyncResult *res, GpkWatch *watch)
 	GPtrArray *array;
 	guint elapsed_time;
 	NotifyNotification *notification;
-	PkExitEnum exit_enum;
 	PkProgress *progress = NULL;
 	PkResults *results = NULL;
 	PkRoleEnum role;
+	PkItemErrorCode *error_item = NULL;
 
 	/* get the results */
 	results = pk_client_generic_finish (client, res, &error);
@@ -1492,6 +1462,8 @@ gpk_watch_adopt_cb (PkClient *client, GAsyncResult *res, GpkWatch *watch)
 	/* get data */
 	g_object_get (progress,
 		      "transaction-id", &transaction_id,
+		      "caller-active", &caller_active,
+		      "elapsed-time", &elapsed_time,
 		      NULL);
 
 	/* is not the watched transaction */
@@ -1502,25 +1474,20 @@ gpk_watch_adopt_cb (PkClient *client, GAsyncResult *res, GpkWatch *watch)
 	gpk_modal_dialog_set_percentage (watch->priv->dialog, 100);
 
 	/* autoclose if success */
-	exit_enum = pk_results_get_exit_code (results);
-	if (exit_enum == PK_EXIT_ENUM_SUCCESS)
+	error_item = pk_results_get_error_code (results);
+	if (error_item == NULL)
 		gpk_modal_dialog_close (watch->priv->dialog);
 
 	/* process messages */
-	if (exit_enum == PK_EXIT_ENUM_SUCCESS) {
+	if (error_item == NULL) {
 		array = pk_results_get_message_array (results);
 		g_ptr_array_foreach (array, (GFunc) pk_watch_process_messages_cb, watch);
 		g_ptr_array_unref (array);
 	}
 
-	/* process errors */
-	if (exit_enum != PK_EXIT_ENUM_SUCCESS) {
-		array = pk_results_get_error_code_array (results);
-		g_ptr_array_foreach (array, (GFunc) pk_watch_set_error_code_userdata_cb, results);
-		g_ptr_array_foreach (array, (GFunc) pk_watch_process_error_code_cb, watch);
-		g_ptr_array_unref (array);
-		goto out;
-	}
+	/* only process errors if caller is no longer on the bus */
+	if (error_item != NULL && !caller_active)
+		pk_watch_process_error_code (watch, error_item);
 
 	/* process restarts */
 	if (role == PK_ROLE_ENUM_UPDATE_PACKAGES ||
@@ -1538,17 +1505,6 @@ gpk_watch_adopt_cb (PkClient *client, GAsyncResult *res, GpkWatch *watch)
 		goto out;
 	}
 
-	/* get progress data about the transaction */
-	g_object_get (results,
-		      "progress", &progress,
-		      NULL);
-
-	/* if the client dbus connection is still active */
-	g_object_get (progress,
-		      "caller-active", &caller_active,
-		      "elapsed-time", &elapsed_time,
-		      NULL);
-
 	/* is it worth showing a UI? */
 	if (elapsed_time < 3000) {
 		egg_debug ("no notification, too quick");
@@ -1588,6 +1544,8 @@ gpk_watch_adopt_cb (PkClient *client, GAsyncResult *res, GpkWatch *watch)
 	}
 out:
 	g_free (transaction_id);
+	if (error_item != NULL)
+		pk_item_error_code_unref (error_item);
 	if (progress != NULL)
 		g_object_unref (progress);
 	if (results != NULL)



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