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



commit b2ea92d11d9df0d8f186331fd1308eeee6cb22ba
Author: Richard Hughes <richard hughsie com>
Date:   Fri Sep 18 14:45:51 2009 +0100

    moo

 src/gpk-application.c   |    6 +-
 src/gpk-common.c        |    2 +-
 src/gpk-common.h        |    2 +-
 src/gpk-dbus-task.c     |    8 +-
 src/gpk-firmware.c      |  448 ++++++++++++++++++++++++-----------------------
 src/gpk-hardware.c      |   95 ++++++----
 src/gpk-update-viewer.c |    4 +-
 7 files changed, 300 insertions(+), 265 deletions(-)
---
diff --git a/src/gpk-application.c b/src/gpk-application.c
index ca9497a..bc8b2b3 100644
--- a/src/gpk-application.c
+++ b/src/gpk-application.c
@@ -1915,7 +1915,7 @@ gpk_application_button_apply_cb (GtkWidget *widget, GpkApplication *application)
 
 	g_return_if_fail (GPK_IS_APPLICATION (application));
 
-	package_ids = pk_package_list_to_strv (application->priv->package_list);
+	package_ids = pk_package_array_to_strv (application->priv->package_list);
 	if (application->priv->action == PK_ACTION_INSTALL) {
 
 		/* install */
@@ -2906,7 +2906,7 @@ gpk_application_deps_remove_event_cb (GpkHelperDepsRemove *helper_deps_remove, G
 	}
 
 	/* actually remove packages this time */
-	package_ids = pk_package_list_to_strv (application->priv->package_list);
+	package_ids = pk_package_array_to_strv (application->priv->package_list);
 	ret = pk_client_remove_packages (application->priv->client_primary, package_ids, TRUE, FALSE, &error);
 	if (!ret) {
 		egg_warning ("cannot remove packages: %s", error->message);
@@ -2937,7 +2937,7 @@ gpk_application_deps_install_event_cb (GpkHelperDepsInstall *helper_deps_install
 	}
 
 	/* actually remove packages this time */
-	package_ids = pk_package_list_to_strv (application->priv->package_list);
+	package_ids = pk_package_array_to_strv (application->priv->package_list);
 #if PK_CHECK_VERSION(0,5,0)
 	ret = pk_client_install_packages (application->priv->client_primary, TRUE, package_ids, &error);
 #else
diff --git a/src/gpk-common.c b/src/gpk-common.c
index 3289871..265498c 100644
--- a/src/gpk-common.c
+++ b/src/gpk-common.c
@@ -51,7 +51,7 @@
 static gboolean small_form_factor_mode = FALSE;
 
 gchar **
-pk_package_list_to_strv (GPtrArray *array)
+pk_package_array_to_strv (GPtrArray *array)
 {
 	const PkItemPackage *item;
 	gchar **results;
diff --git a/src/gpk-common.h b/src/gpk-common.h
index e383b7f..987b2b8 100644
--- a/src/gpk-common.h
+++ b/src/gpk-common.h
@@ -114,7 +114,7 @@ gboolean	 gpk_window_set_parent_xid		(GtkWindow	*window,
 							 guint32	 xid);
 GPtrArray	*pk_strv_to_ptr_array			(gchar		**array)
 							 G_GNUC_WARN_UNUSED_RESULT;
-gchar		**pk_package_list_to_strv		(GPtrArray	*array);
+gchar		**pk_package_array_to_strv		(GPtrArray	*array);
 
 G_END_DECLS
 
diff --git a/src/gpk-dbus-task.c b/src/gpk-dbus-task.c
index d8a9648..e7863e4 100644
--- a/src/gpk-dbus-task.c
+++ b/src/gpk-dbus-task.c
@@ -853,7 +853,7 @@ skip_checks:
 		}
 
 		/* convert to data */
-		task->priv->package_ids = pk_package_list_to_strv (list);
+		task->priv->package_ids = pk_package_array_to_strv (list);
 
 		/* install these packages with deps */
 		g_idle_add ((GSourceFunc) gpk_dbus_task_install_package_ids_dep_check_idle_cb, task);
@@ -2366,7 +2366,7 @@ skip_checks:
 
 skip_checks2:
 	/* install with deps */
-	task->priv->package_ids = pk_package_list_to_strv (list);
+	task->priv->package_ids = pk_package_array_to_strv (list);
 	gpk_dbus_task_install_package_ids_dep_check (task);
 out:
 	if (list != NULL)
@@ -2774,7 +2774,7 @@ skip_checks:
 
 skip_checks2:
 	/* convert to list of package id's */
-	task->priv->package_ids = pk_package_list_to_strv (list);
+	task->priv->package_ids = pk_package_array_to_strv (list);
 	gpk_dbus_task_install_package_ids_dep_check (task);
 
 out:
@@ -2915,7 +2915,7 @@ skip_checks:
 
 skip_checks2:
 	/* convert to list of package id's */
-	task->priv->package_ids = pk_package_list_to_strv (list);
+	task->priv->package_ids = pk_package_array_to_strv (list);
 	gpk_dbus_task_install_package_ids_dep_check (task);
 
 out:
diff --git a/src/gpk-firmware.c b/src/gpk-firmware.c
index 4c2900c..91f8f19 100644
--- a/src/gpk-firmware.c
+++ b/src/gpk-firmware.c
@@ -88,6 +88,9 @@ typedef struct {
 
 G_DEFINE_TYPE (GpkFirmware, gpk_firmware, G_TYPE_OBJECT)
 
+static void gpk_firmware_install_file (GpkFirmware *firmware);
+static void gpk_firmware_ignore_devices (GpkFirmware *firmware);
+
 /**
  * gpk_firmware_subsystem_can_replug:
  **/
@@ -169,32 +172,6 @@ gpk_firmware_request_free (GpkFirmwareRequest *req)
 	g_free (req);
 }
 
-/**
- * gpk_firmware_install_file:
- **/
-static gboolean
-gpk_firmware_install_file (GpkFirmware *firmware)
-{
-	gboolean ret;
-	GError *error = NULL;
-	gchar **package_ids;
-
-	/* install all of the firmware files */
-	package_ids = pk_package_list_to_strv (firmware->priv->packages_found);
-#if PK_CHECK_VERSION(0,5,0)
-	ret = pk_client_install_packages (firmware->priv->client, TRUE, package_ids, &error);
-#else
-	ret = pk_client_install_packages (firmware->priv->client, package_ids, &error);
-#endif
-	if (!ret) {
-		egg_warning ("failed to install provide file: %s", error->message);
-		g_error_free (error);
-		goto out;
-	}
-out:
-	g_strfreev (package_ids);
-	return ret;
-}
 
 /**
  * gpk_firmware_rebind:
@@ -250,6 +227,195 @@ out:
 }
 
 /**
+ * gpk_firmware_libnotify_cb:
+ **/
+static void
+gpk_firmware_libnotify_cb (NotifyNotification *notification, gchar *action, gpointer data)
+{
+	GpkFirmware *firmware = GPK_FIRMWARE (data);
+	gboolean ret;
+	GError *error = NULL;
+
+	if (g_strcmp0 (action, "install-firmware") == 0) {
+		gpk_firmware_install_file (firmware);
+	} else if (g_strcmp0 (action, "ignore-devices") == 0) {
+		gpk_firmware_ignore_devices (firmware);
+	} else if (g_strcmp0 (action, "restart-now") == 0) {
+		ret = egg_console_kit_restart (firmware->priv->consolekit, &error);
+		if (!ret) {
+			egg_warning ("failed to reset: %s", error->message);
+			g_error_free (error);
+		}
+	} else {
+		egg_warning ("unknown action id: %s", action);
+	}
+}
+
+/**
+ * gpk_firmware_require_restart:
+ **/
+static void
+gpk_firmware_require_restart (GpkFirmware *firmware)
+{
+	const gchar *message;
+	gboolean can_restart = FALSE;
+	gboolean ret;
+	GError *error = NULL;
+	NotifyNotification *notification;
+
+	/* TRANSLATORS: we need to restart so the new hardware can re-request the firmware */
+	message = _("You will need to restart this computer before the hardware will work correctly.");
+
+	/* TRANSLATORS: title of libnotify bubble */
+	notification = notify_notification_new (_("Additional software was installed"), message, "help-browser", NULL);
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
+	notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
+
+	/* only show the restart button if we can restart */
+	egg_console_kit_can_restart (firmware->priv->consolekit, &can_restart, NULL);
+	if (can_restart) {
+		notify_notification_add_action (notification, "restart-now",
+						/* TRANSLATORS: button label */
+						_("Restart now"), gpk_firmware_libnotify_cb, firmware, NULL);
+	}
+
+	/* show the bubble */
+	ret = notify_notification_show (notification, &error);
+	if (!ret) {
+		egg_warning ("error: %s", error->message);
+		g_error_free (error);
+	}
+}
+
+/**
+ * gpk_firmware_require_replug:
+ **/
+static void
+gpk_firmware_require_replug (GpkFirmware *firmware)
+{
+	const gchar *message;
+	gboolean ret;
+	GError *error = NULL;
+	NotifyNotification *notification;
+
+	/* TRANSLATORS: we need to remove an replug so the new hardware can re-request the firmware */
+	message = _("You will need to remove and then reinsert the hardware before it will work correctly.");
+
+	/* TRANSLATORS: title of libnotify bubble */
+	notification = notify_notification_new (_("Additional software was installed"), message, "help-browser", NULL);
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
+	notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
+
+	/* show the bubble */
+	ret = notify_notification_show (notification, &error);
+	if (!ret) {
+		egg_warning ("error: %s", error->message);
+		g_error_free (error);
+	}
+}
+
+/**
+ * gpk_firmware_require_nothing:
+ **/
+static void
+gpk_firmware_require_nothing (GpkFirmware *firmware)
+{
+	const gchar *message;
+	gboolean ret;
+	GError *error = NULL;
+	NotifyNotification *notification;
+
+	/* TRANSLATORS: we need to remove an replug so the new hardware can re-request the firmware */
+	message = _("Your hardware has been set up and is now ready to use.");
+
+	/* TRANSLATORS: title of libnotify bubble */
+	notification = notify_notification_new (_("Additional software was installed"), message, "help-browser", NULL);
+	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
+	notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
+
+	/* show the bubble */
+	ret = notify_notification_show (notification, &error);
+	if (!ret) {
+		egg_warning ("error: %s", error->message);
+		g_error_free (error);
+	}
+}
+
+/**
+ * gpk_hardware_install_packages_cb:
+ **/
+static void
+gpk_hardware_install_packages_cb (GObject *object, GAsyncResult *res, GpkFirmware *firmware)
+{
+	PkClient *client = PK_CLIENT (object);
+	GError *error = NULL;
+	PkResults *results = NULL;
+	GPtrArray *array = NULL;
+	gboolean restart = FALSE;
+	const GpkFirmwareRequest *req;
+	gboolean ret;
+	guint i;
+
+	/* get the results */
+	results = pk_client_generic_finish (client, res, &error);
+	if (results == NULL) {
+		egg_warning ("failed to install file: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* go through all the requests, and find the worst type */
+	array = firmware->priv->array_requested;
+	for (i=0; i<array->len; i++) {
+		req = g_ptr_array_index (array, i);
+		ret = gpk_firmware_subsystem_can_replug (req->subsystem);
+		if (!ret) {
+			restart = TRUE;
+			break;
+		}
+	}
+
+	/* can we just rebind the device */
+	ret = g_file_test (GPK_FIRMWARE_DEVICE_REBIND_PROGRAM, G_FILE_TEST_EXISTS);
+	if (ret) {
+		ret = gpk_firmware_rebind (firmware);
+		if (ret) {
+			gpk_firmware_require_nothing (firmware);
+			goto out;
+		}
+	} else {
+		/* give the user the correct message */
+		if (restart)
+			gpk_firmware_require_restart (firmware);
+		else
+			gpk_firmware_require_replug (firmware);
+	}
+
+	/* clear array */
+	g_ptr_array_set_size (firmware->priv->array_requested, 0);
+out:
+	if (array != NULL)
+		g_ptr_array_unref (array);
+	if (results != NULL)
+		g_object_unref (results);
+}
+
+/**
+ * gpk_firmware_install_file:
+ **/
+static void
+gpk_firmware_install_file (GpkFirmware *firmware)
+{
+	gchar **package_ids;
+
+	/* 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);
+	g_strfreev (package_ids);
+}
+
+/**
  * gpk_firmware_ignore_devices:
  **/
 static void
@@ -301,31 +467,6 @@ out:
 }
 
 /**
- * gpk_firmware_libnotify_cb:
- **/
-static void
-gpk_firmware_libnotify_cb (NotifyNotification *notification, gchar *action, gpointer data)
-{
-	GpkFirmware *firmware = GPK_FIRMWARE (data);
-	gboolean ret;
-	GError *error = NULL;
-
-	if (g_strcmp0 (action, "install-firmware") == 0) {
-		gpk_firmware_install_file (firmware);
-	} else if (g_strcmp0 (action, "ignore-devices") == 0) {
-		gpk_firmware_ignore_devices (firmware);
-	} else if (g_strcmp0 (action, "restart-now") == 0) {
-		ret = egg_console_kit_restart (firmware->priv->consolekit, &error);
-		if (!ret) {
-			egg_warning ("failed to reset: %s", error->message);
-			g_error_free (error);
-		}
-	} else {
-		egg_warning ("unknown action id: %s", action);
-	}
-}
-
-/**
  * gpk_firmware_check_available:
  * @firmware: This class instance
  * @filename: Firmware to search for
@@ -333,37 +474,60 @@ gpk_firmware_libnotify_cb (NotifyNotification *notification, gchar *action, gpoi
 static PkItemPackage *
 gpk_firmware_check_available (GpkFirmware *firmware, const gchar *filename)
 {
-	gboolean ret;
 	guint length = 0;
-	GPtrArray *list = NULL;
+	GPtrArray *array = NULL;
 	GError *error = NULL;
 	PkItemPackage *item = NULL;
 	PkBitfield filter;
+	PkResults *results;
 
 	/* search for newest not installed package */
 	filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NOT_INSTALLED, PK_FILTER_ENUM_NEWEST, -1);
-	ret = pk_client_search_file (firmware->priv->client, filter, filename, &error);
-	if (!ret) {
+	results = pk_client_search_file (firmware->priv->client, filter, filename, NULL, NULL, NULL, &error);
+	if (results == NULL) {
 		egg_warning ("failed to search file %s: %s", filename, error->message);
 		g_error_free (error);
 		goto out;
 	}
 
 	/* make sure we have one package */
-	list = pk_results_get_package_array (firmware->priv->client);
-	if (list->len == 0)
+	array = pk_results_get_package_array (results);
+	if (array->len == 0)
 		egg_debug ("no package providing %s found", filename);
-	else if (list->len != 1)
+	else if (array->len != 1)
 		egg_warning ("not one package providing %s found (%i)", filename, length);
 	else
-		item = pk_package_item_copy (g_ptr_array_index (list, 0));
+		item = pk_item_package_ref (g_ptr_array_index (array, 0));
 out:
-	if (list != NULL)
-		g_object_unref (list);
+	if (array != NULL)
+		g_object_unref (array);
+	if (results != NULL)
+		g_object_unref (results);
 	return item;
 }
 
 /**
+ * gpk_firmware_remove_duplicate:
+ **/
+static void
+gpk_firmware_remove_duplicate (GPtrArray *array)
+{
+	guint i, j;
+	const gchar *val;
+	const gchar *val_tmp;
+
+	/* remove each duplicate entry */
+	for (i=0; i<array->len; i++) {
+		val = g_ptr_array_index (array, i);
+		for (j=i+1; j<array->len; j++) {
+			val_tmp = g_ptr_array_index (array, j);
+			if (g_strcmp0 (val_tmp, val) == 0)
+				g_ptr_array_remove_index_fast (array, j);
+		}
+	}
+}
+
+/**
  * gpk_firmware_timeout_cb:
  **/
 static gboolean
@@ -402,9 +566,9 @@ gpk_firmware_timeout_cb (gpointer data)
 	}
 
 	/* check we don't want the same package more than once */
-	pk_item_list_remove_duplicate (firmware->priv->packages_found);
+	gpk_firmware_remove_duplicate (firmware->priv->packages_found);
 
-	/* have we got any models to list */
+	/* have we got any models to array */
 	for (i=0; i<array->len; i++) {
 		req = g_ptr_array_index (array, i);
 		if (req->model != NULL) {
@@ -568,6 +732,7 @@ gpk_firmware_udev_text_decode (const gchar *data)
 	return decode;
 }
 
+#if 0
 /**
  * gpk_firmware_error_code_cb:
  **/
@@ -590,150 +755,7 @@ gpk_firmware_error_code_cb (PkClient *client, PkErrorCodeEnum code, const gchar
 	gpk_error_dialog (gpk_error_enum_to_localised_text (code),
 			  gpk_error_enum_to_localised_message (code), details);
 }
-
-/**
- * gpk_firmware_require_restart:
- **/
-static void
-gpk_firmware_require_restart (GpkFirmware *firmware)
-{
-	const gchar *message;
-	gboolean can_restart = FALSE;
-	gboolean ret;
-	GError *error = NULL;
-	NotifyNotification *notification;
-
-	/* TRANSLATORS: we need to restart so the new hardware can re-request the firmware */
-	message = _("You will need to restart this computer before the hardware will work correctly.");
-
-	/* TRANSLATORS: title of libnotify bubble */
-	notification = notify_notification_new (_("Additional software was installed"), message, "help-browser", NULL);
-	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
-	notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
-
-	/* only show the restart button if we can restart */
-	egg_console_kit_can_restart (firmware->priv->consolekit, &can_restart, NULL);
-	if (can_restart) {
-		notify_notification_add_action (notification, "restart-now",
-						/* TRANSLATORS: button label */
-						_("Restart now"), gpk_firmware_libnotify_cb, firmware, NULL);
-	}
-
-	/* show the bubble */
-	ret = notify_notification_show (notification, &error);
-	if (!ret) {
-		egg_warning ("error: %s", error->message);
-		g_error_free (error);
-	}
-}
-
-/**
- * gpk_firmware_require_replug:
- **/
-static void
-gpk_firmware_require_replug (GpkFirmware *firmware)
-{
-	const gchar *message;
-	gboolean ret;
-	GError *error = NULL;
-	NotifyNotification *notification;
-
-	/* TRANSLATORS: we need to remove an replug so the new hardware can re-request the firmware */
-	message = _("You will need to remove and then reinsert the hardware before it will work correctly.");
-
-	/* TRANSLATORS: title of libnotify bubble */
-	notification = notify_notification_new (_("Additional software was installed"), message, "help-browser", NULL);
-	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
-	notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
-
-	/* show the bubble */
-	ret = notify_notification_show (notification, &error);
-	if (!ret) {
-		egg_warning ("error: %s", error->message);
-		g_error_free (error);
-	}
-}
-
-/**
- * gpk_firmware_require_nothing:
- **/
-static void
-gpk_firmware_require_nothing (GpkFirmware *firmware)
-{
-	const gchar *message;
-	gboolean ret;
-	GError *error = NULL;
-	NotifyNotification *notification;
-
-	/* TRANSLATORS: we need to remove an replug so the new hardware can re-request the firmware */
-	message = _("Your hardware has been set up and is now ready to use.");
-
-	/* TRANSLATORS: title of libnotify bubble */
-	notification = notify_notification_new (_("Additional software was installed"), message, "help-browser", NULL);
-	notify_notification_set_timeout (notification, NOTIFY_EXPIRES_NEVER);
-	notify_notification_set_urgency (notification, NOTIFY_URGENCY_LOW);
-
-	/* show the bubble */
-	ret = notify_notification_show (notification, &error);
-	if (!ret) {
-		egg_warning ("error: %s", error->message);
-		g_error_free (error);
-	}
-}
-
-/**
- * gpk_firmware_finished_cb:
- **/
-static void
-gpk_firmware_finished_cb (PkClient *client, PkExitEnum exit_enum, guint runtime, GpkFirmware *firmware)
-{
-	PkRoleEnum role;
-	gboolean restart = FALSE;
-	const GpkFirmwareRequest *req;
-	GPtrArray *array;
-	gboolean ret;
-	guint i;
-
-	pk_client_get_role (client, &role, NULL, NULL);
-	egg_debug ("role: %s, exit: %s", pk_role_enum_to_text (role), pk_exit_enum_to_text (exit_enum));
-
-	/* tell the user we installed okay */
-	if (exit_enum == PK_EXIT_ENUM_SUCCESS && role == PK_ROLE_ENUM_INSTALL_PACKAGES) {
-
-		/* go through all the requests, and find the worst type */
-		array = firmware->priv->array_requested;
-		for (i=0; i<array->len; i++) {
-			req = g_ptr_array_index (array, i);
-			ret = gpk_firmware_subsystem_can_replug (req->subsystem);
-			if (!ret) {
-				restart = TRUE;
-				break;
-			}
-		}
-
-		/* can we just rebind the device */
-		ret = g_file_test (GPK_FIRMWARE_DEVICE_REBIND_PROGRAM, G_FILE_TEST_EXISTS);
-		if (ret) {
-			ret = gpk_firmware_rebind (firmware);
-			if (ret) {
-				gpk_firmware_require_nothing (firmware);
-				goto out;
-			}
-		} else {
-			/* give the user the correct message */
-			if (restart)
-				gpk_firmware_require_restart (firmware);
-			else
-				gpk_firmware_require_replug (firmware);
-		}
-
-		/* clear array */
-		g_ptr_array_foreach (firmware->priv->array_requested, (GFunc) gpk_firmware_request_free, NULL);
-		g_ptr_array_set_size (firmware->priv->array_requested, 0);
-	}
-out:
-	return;
-}
+#endif
 
 /**
  * gpk_firmware_get_device:
@@ -969,17 +991,12 @@ gpk_firmware_init (GpkFirmware *firmware)
 
 	firmware->priv = GPK_FIRMWARE_GET_PRIVATE (firmware);
 	firmware->priv->timeout_id = 0;
-	firmware->priv->packages_found = g_ptr_array_new_with_free_func_xxx ();
-	firmware->priv->array_requested = g_ptr_array_new ();
+	firmware->priv->packages_found = g_ptr_array_new_with_free_func ((GDestroyNotify) pk_item_package_unref);
+	firmware->priv->array_requested = g_ptr_array_new_with_free_func ((GDestroyNotify) gpk_firmware_request_free);
 	firmware->priv->gconf_client = gconf_client_get_default ();
 	firmware->priv->consolekit = egg_console_kit_new ();
 	firmware->priv->client = pk_client_new ();
 
-	g_signal_connect (firmware->priv->client, "error-code",
-			  G_CALLBACK (gpk_firmware_error_code_cb), firmware);
-	g_signal_connect (firmware->priv->client, "finished",
-			  G_CALLBACK (gpk_firmware_finished_cb), firmware);
-
 	/* setup watch for new hardware */
 	file = g_file_new_for_path (GPK_FIRMWARE_MISSING_DIR);
 	firmware->priv->monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, &error);
@@ -1015,8 +1032,7 @@ gpk_firmware_finalize (GObject *object)
 	firmware = GPK_FIRMWARE (object);
 
 	g_return_if_fail (firmware->priv != NULL);
-	g_ptr_array_foreach (firmware->priv->array_requested, (GFunc) gpk_firmware_request_free, NULL);
-	g_ptr_array_free (firmware->priv->array_requested, TRUE);
+	g_ptr_array_unref (firmware->priv->array_requested);
 	g_ptr_array_unref (firmware->priv->packages_found);
 	g_object_unref (firmware->priv->client);
 	g_object_unref (firmware->priv->gconf_client);
diff --git a/src/gpk-hardware.c b/src/gpk-hardware.c
index 706c680..c104888 100644
--- a/src/gpk-hardware.c
+++ b/src/gpk-hardware.c
@@ -57,6 +57,7 @@ static void     gpk_hardware_finalize	(GObject	  *object);
 
 struct GpkHardwarePrivate
 {
+	PkClient		*client;
 	GConfClient		*gconf_client;
 	DBusGConnection		*connection;
 	DBusGProxy		*proxy;
@@ -66,32 +67,38 @@ struct GpkHardwarePrivate
 
 G_DEFINE_TYPE (GpkHardware, gpk_hardware, G_TYPE_OBJECT)
 
+
 /**
- * gpk_hardware_install_package:
+ * gpk_hardware_install_packages_cb:
  **/
-static gboolean
-gpk_hardware_install_package (GpkHardware *hardware)
+static void
+gpk_hardware_install_packages_cb (GObject *object, GAsyncResult *res, GpkHardware *hardware)
 {
+	PkClient *client = PK_CLIENT (object);
 	GError *error = NULL;
-	PkClient *client = NULL;
-	gboolean ret;
-
-	client = pk_client_new ();
+	PkResults *results = NULL;
 
-	/* FIXME: this needs to be async and connect up to the repo signature stuff */
-#if PK_CHECK_VERSION(0,5,0)
-	ret = pk_client_install_packages (client, TRUE, hardware->priv->package_ids, &error);
-#else
-	ret = pk_client_install_packages (client, hardware->priv->package_ids, &error);
-#endif
-	if (!ret) {
-		egg_warning ("failed to install package: %s", error->message);
+	/* get the results */
+	results = pk_client_generic_finish (client, res, &error);
+	if (results == NULL) {
+		egg_warning ("failed to install file: %s", error->message);
 		g_error_free (error);
-		error = NULL;
+		goto out;
 	}
+out:
+	if (results != NULL)
+		g_object_unref (results);
+}
 
-	g_object_unref (client);
-	return ret;
+/**
+ * gpk_hardware_install_package:
+ **/
+static void
+gpk_hardware_install_package (GpkHardware *hardware)
+{
+	/* FIXME: this needs to be async and connect up to the repo signature stuff */
+	pk_client_install_packages_async (hardware->priv->client, TRUE, hardware->priv->package_ids, NULL, NULL, NULL,
+					  (GAsyncReadyCallback) gpk_hardware_install_packages_cb, hardware);
 }
 
 /**
@@ -113,46 +120,45 @@ gpk_hardware_libnotify_cb (NotifyNotification *notification, gchar *action, gpoi
 }
 
 /**
- * gpk_hardware_check_for_driver_available:
+ * gpk_hardware_what_provides_cb:
  **/
 static void
-gpk_hardware_check_for_driver_available (GpkHardware *hardware, const gchar *udi)
+gpk_hardware_what_provides_cb (GObject *object, GAsyncResult *res, GpkHardware *hardware)
 {
+	PkClient *client = PK_CLIENT (object);
+	GError *error = NULL;
+	PkResults *results = NULL;
 	gboolean ret;
 	gchar *message = NULL;
 	gchar *body = NULL;
 	NotifyNotification *notification;
-	GError *error = NULL;
 	gchar *package = NULL;
-	GPtrArray *list = NULL;
+	GPtrArray *array = NULL;
 	const PkItemPackage *item = NULL;
-	PkClient *client = NULL;
 
-	client = pk_client_new ();
-	ret = pk_client_what_provides (client, pk_bitfield_value (PK_FILTER_ENUM_NOT_INSTALLED),
-				       PK_PROVIDES_ENUM_HARDWARE_DRIVER, udi, &error);
-	if (!ret) {
-		egg_warning ("Error calling pk_client_what_provides :%s", error->message);
+	/* get the results */
+	results = pk_client_generic_finish (client, res, &error);
+	if (results == NULL) {
+		egg_warning ("failed to get provides: %s", error->message);
 		g_error_free (error);
-		error = NULL;
 		goto out;
 	}
 
 	/* If there are no driver packages available just return */
-	list = pk_results_get_package_array (client);
-	if (list->len == 0) {
+	array = pk_results_get_package_array (results);
+	if (array->len == 0) {
 		egg_debug ("no drivers available");
 		goto out;
 	}
 
 	/* only install the first one? */
-	item = g_ptr_array_index (list, 0);
+	item = g_ptr_array_index (array, 0);
 	package = gpk_package_id_format_oneline (item->package_id, item->summary);
 
-	/* save list */
+	/* save array */
 	if (hardware->priv->package_ids != NULL)
 		g_strfreev (hardware->priv->package_ids);
-	hardware->priv->package_ids = pk_package_list_to_strv (list);
+	hardware->priv->package_ids = pk_package_array_to_strv (array);
 
 	/* TODO: tell the user what hardware, NOT JUST A UDI */
 	/* TRANSLATORS: we can install an extra package so this hardware works, e.g. firmware */
@@ -173,14 +179,25 @@ gpk_hardware_check_for_driver_available (GpkHardware *hardware, const gchar *udi
 		egg_warning ("error: %s", error->message);
 		g_error_free (error);
 	}
-
 out:
 	g_free (package);
 	g_free (message);
 	g_free (body);
-	if (list != NULL)
-		g_object_unref (list);
-	g_object_unref (client);
+	if (array != NULL)
+		g_ptr_array_unref (array);
+	if (results != NULL)
+		g_object_unref (results);
+}
+
+/**
+ * gpk_hardware_check_for_driver_available:
+ **/
+static void
+gpk_hardware_check_for_driver_available (GpkHardware *hardware, const gchar *udi)
+{
+	pk_client_what_provides_async (hardware->priv->client, pk_bitfield_value (PK_FILTER_ENUM_NOT_INSTALLED),
+				       PK_PROVIDES_ENUM_HARDWARE_DRIVER, udi, NULL, NULL, NULL,
+				       (GAsyncReadyCallback) gpk_hardware_what_provides_cb, hardware);
 }
 
 static gboolean
@@ -246,6 +263,7 @@ gpk_hardware_init (GpkHardware *hardware)
 		egg_debug ("hardware driver checking disabled in GConf");
 		return;
 	}
+	hardware->priv->client = pk_client_new ();
 
 	hardware->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
 	if (error != NULL) {
@@ -293,6 +311,7 @@ gpk_hardware_finalize (GObject *object)
 
 	g_return_if_fail (hardware->priv != NULL);
 	g_object_unref (hardware->priv->gconf_client);
+	g_object_unref (hardware->priv->client);
 	g_strfreev (hardware->priv->package_ids);
 
 	G_OBJECT_CLASS (gpk_hardware_parent_class)->finalize (object);
diff --git a/src/gpk-update-viewer.c b/src/gpk-update-viewer.c
index b12f6a2..969509e 100644
--- a/src/gpk-update-viewer.c
+++ b/src/gpk-update-viewer.c
@@ -1441,7 +1441,7 @@ gpk_update_viewer_finished_get_details_cb (GPtrArray *list)
 	gboolean ret;
 	gchar **package_ids;
 	GError *error = NULL;
-	package_ids = pk_package_list_to_strv (list);
+	package_ids = pk_package_array_to_strv (list);
 
 	/* get the details of all the packages */
 	ret = pk_client_get_details (client_primary, package_ids, &error);
@@ -1465,7 +1465,7 @@ gpk_update_viewer_finished_get_update_details_cb (GPtrArray *list)
 	gboolean ret;
 	gchar **package_ids;
 	GError *error = NULL;
-	package_ids = pk_package_list_to_strv (list);
+	package_ids = pk_package_array_to_strv (list);
 
 	/* get the details of all the packages */
 	ret = pk_client_get_update_detail (client_primary, package_ids, &error);



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