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



commit 7e49ce5ce2be3cd3b761a26ad7ce6db771ce4d0c
Author: Richard Hughes <richard hughsie com>
Date:   Thu Sep 17 19:57:26 2009 +0100

    moo

 src/Makefile.am               |    6 -
 src/gpk-application.c         |    4 -
 src/gpk-check-update.c        |   13 +---
 src/gpk-dbus-task.c           |    2 +-
 src/gpk-dialog.c              |    2 +-
 src/gpk-firmware.c            |    2 +-
 src/gpk-helper-deps-install.c |  196 ---------------------------------------
 src/gpk-helper-deps-install.h |   65 -------------
 src/gpk-helper-deps-remove.c  |  183 ------------------------------------
 src/gpk-helper-deps-remove.h  |   65 -------------
 src/gpk-helper-deps-update.c  |  204 -----------------------------------------
 src/gpk-helper-deps-update.h  |   65 -------------
 src/gpk-task.c                |  139 ++++++++++++----------------
 src/gpk-update-viewer.c       |    1 -
 src/gpk-watch.c               |   88 +++++++-----------
 15 files changed, 100 insertions(+), 935 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 1117562..2e1ecf2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -82,12 +82,6 @@ libgpkshared_a_SOURCES =				\
 	gpk-modal-dialog.h				\
 	gpk-helper-run.c				\
 	gpk-helper-run.h				\
-	gpk-helper-deps-remove.c			\
-	gpk-helper-deps-remove.h			\
-	gpk-helper-deps-install.c			\
-	gpk-helper-deps-install.h			\
-	gpk-helper-deps-update.c			\
-	gpk-helper-deps-update.h			\
 	gpk-helper-chooser.c				\
 	gpk-helper-chooser.h				\
 	gpk-gnome.c					\
diff --git a/src/gpk-application.c b/src/gpk-application.c
index ee2c40a..ca9497a 100644
--- a/src/gpk-application.c
+++ b/src/gpk-application.c
@@ -45,8 +45,6 @@
 #include "gpk-cell-renderer-uri.h"
 #include "gpk-desktop.h"
 #include "gpk-helper-run.h"
-#include "gpk-helper-deps-remove.h"
-#include "gpk-helper-deps-install.h"
 
 static void     gpk_application_finalize   (GObject	    *object);
 
@@ -103,8 +101,6 @@ struct GpkApplicationPrivate
 	GPtrArray		*package_list;
 	GtkWidget		*image_status;
 	GpkHelperRun		*helper_run;
-	GpkHelperDepsRemove	*helper_deps_remove;
-	GpkHelperDepsInstall	*helper_deps_install;
 #if !PK_CHECK_VERSION(0,5,2)
 	gboolean		 dep_check_info_only; /* bodge to tell apart the differing uses of GetDepends */
 #endif
diff --git a/src/gpk-check-update.c b/src/gpk-check-update.c
index 0bc57af..52e8d32 100644
--- a/src/gpk-check-update.c
+++ b/src/gpk-check-update.c
@@ -1074,17 +1074,6 @@ out:
 }
 
 /**
- * gpk_check_update_query_updates_idle_cb:
- **/
-static gboolean
-gpk_check_update_query_updates_idle_cb (GpkCheckUpdate *cupdate)
-{
-	egg_debug ("idle cb");
-	gpk_check_update_query_updates (cupdate);
-	return FALSE;
-}
-
-/**
  * gpk_check_update_query_updates_changed_cb:
  **/
 static gboolean
@@ -1210,7 +1199,7 @@ gpk_check_update_auto_get_updates_cb (GpkAutoRefresh *arefresh, GpkCheckUpdate *
 
 	/* show the icon at login time */
 	egg_debug ("login cb");
-	g_idle_add ((GSourceFunc) gpk_check_update_query_updates_idle_cb, cupdate);
+	gpk_check_update_query_updates (cupdate);
 }
 
 /**
diff --git a/src/gpk-dbus-task.c b/src/gpk-dbus-task.c
index 4b95991..d8a9648 100644
--- a/src/gpk-dbus-task.c
+++ b/src/gpk-dbus-task.c
@@ -2333,7 +2333,7 @@ skip_checks:
 			goto out;
 		}
 		g_ptr_array_add (list, item_new);
-		pk_package_item_free (item_new);
+		pk_item_package_unref (item_new);
 		g_strfreev (parts);
 	}
 
diff --git a/src/gpk-dialog.c b/src/gpk-dialog.c
index d7b5faf..7a5aab0 100644
--- a/src/gpk-dialog.c
+++ b/src/gpk-dialog.c
@@ -106,7 +106,7 @@ gpk_dialog_package_list_to_list_store (GPtrArray *list)
 		split = pk_package_id_split (item->package_id);
 		icon = gpk_desktop_guess_icon_name (desktop, split[0]);
 		if (icon == NULL)
-			icon = gpk_info_enum_to_icon_name (PK_INFO_ENUM_INSTALLED);
+			icon = gpk_info_enum_to_icon_name (item->info);
 
 		gtk_list_store_append (store, &iter);
 		gtk_list_store_set (store, &iter,
diff --git a/src/gpk-firmware.c b/src/gpk-firmware.c
index ebaff6e..4c2900c 100644
--- a/src/gpk-firmware.c
+++ b/src/gpk-firmware.c
@@ -391,7 +391,7 @@ gpk_firmware_timeout_cb (gpointer data)
 		item = gpk_firmware_check_available (firmware, req->filename);
 		if (item != NULL) {
 			g_ptr_array_add (firmware->priv->packages_found, item);
-			pk_package_item_free (item);
+			pk_item_package_unref (item);
 		}
 	}
 
diff --git a/src/gpk-task.c b/src/gpk-task.c
index 83a3e04..b6d23a3 100644
--- a/src/gpk-task.c
+++ b/src/gpk-task.c
@@ -23,6 +23,7 @@
 
 #include <glib/gi18n.h>
 #include <packagekit-glib2/packagekit.h>
+#include <gconf/gconf-client.h>
 
 #include "egg-debug.h"
 
@@ -30,6 +31,7 @@
 #include "gpk-gnome.h"
 #include "gpk-common.h"
 #include "gpk-enum.h"
+#include "gpk-dialog.h"
 
 static void     gpk_task_finalize	(GObject     *object);
 
@@ -43,6 +45,7 @@ static void     gpk_task_finalize	(GObject     *object);
 struct _GpkTaskPrivate
 {
 	gpointer		 user_data;
+	GConfClient		*gconf_client;
 	GtkWindow		*parent_window;
 	GtkWindow		*current_window;
 	GtkBuilder		*builder_untrusted;
@@ -336,98 +339,74 @@ out:
 }
 
 /**
- * gpk_task_simulate_question_type_to_text:
- **/
-static const gchar *
-gpk_task_simulate_question_type_to_text (PkInfoEnum info)
-{
-	if (info == PK_INFO_ENUM_REMOVING) {
-		/* TRANSLATORS: When processing, we might have to remove other dependencies */
-		return _("The following packages have to be removed:");
-	}
-
-	if (info == PK_INFO_ENUM_INSTALLING) {
-		/* TRANSLATORS: When processing, we might have to install other dependencies */
-		return _("The following packages have to be installed:");
-	}
-
-	if (info == PK_INFO_ENUM_UPDATING) {
-		/* TRANSLATORS: When processing, we might have to update other dependencies */
-		return _("The following packages have to be updated:");
-	}
-
-	if (info == PK_INFO_ENUM_REINSTALLING) {
-		/* TRANSLATORS: When processing, we might have to reinstall other dependencies */
-		return _("The following packages have to be reinstalled:");
-	}
-
-	if (info == PK_INFO_ENUM_DOWNGRADING) {
-		/* TRANSLATORS: When processing, we might have to downgrade other dependencies */
-		return _("The following packages have to be downgraded:");
-	}
-
-	/* do not show */
-	return NULL;
-}
-
-/**
  * gpk_task_simulate_question:
  **/
 static void
 gpk_task_simulate_question (PkTask *task, guint request, PkResults *results)
 {
-	guint i;
-	guint len;
-	const gchar *package_id;
-	const gchar *title;
-	gchar *printable;
-	gchar *summary;
-	PkPackage *package;
-	PkPackageSack *sack;
-	PkInfoEnum info;
-	PkInfoEnum info_last = PK_INFO_ENUM_UNKNOWN;
+	gboolean ret;
+	GPtrArray *array = NULL;
 	GpkTaskPrivate *priv = GPK_TASK(task)->priv;
+	PkRoleEnum role;
+	guint inputs;
+	const gchar *title;
+	const gchar *message;
+
+	/* get data about the transaction */
+	g_object_get (results,
+		      "role", &role,
+		      "inputs", &inputs,
+		      NULL);
+
+	/* allow skipping of deps except when we remove other packages */
+	if (role != PK_ROLE_ENUM_REMOVE_PACKAGES) {
+		/* have we previously said we don't want to be shown the confirmation */
+		ret = gconf_client_get_bool (priv->gconf_client, GPK_CONF_SHOW_DEPENDS, NULL);
+		if (!ret) {
+			egg_debug ("we've said we don't want the dep dialog");
+			pk_task_user_accepted (PK_TASK(task), priv->request);
+			goto out;
+		}
+	}
+
+	/* per-role messages */
+	title = _("Additional software required");
+	if (role == PK_ROLE_ENUM_INSTALL_PACKAGES) {
+		message = ngettext ("To install this package, additional software also has to be installed.",
+				    "To install these packages, additional software also has to be installed.", inputs);
+	} else if (role == PK_ROLE_ENUM_REMOVE_PACKAGES) {
+		message = ngettext ("To remove this package, additional software also has to be removed.",
+				    "To remove these packages, additional software also has to be removed.", inputs);
+	} else if (role == PK_ROLE_ENUM_UPDATE_PACKAGES) {
+		message = ngettext ("To update this package, additional software also has to be installed.",
+				    "To update these packages, additional software also has to be installed.", inputs);
+	} else if (role == PK_ROLE_ENUM_INSTALL_FILES) {
+		message = ngettext ("To install this file, additional software also has to be installed.",
+				    "To install these file, additional software also has to be installed.", inputs);
+	}
 
 	/* save the current request */
 	priv->request = request;
 
 	/* get data */
-	sack = pk_results_get_package_sack (results);
-
-	/* print data */
-	len = pk_package_sack_get_size (sack);
-	for (i=0; i<len; i++) {
-		package = pk_package_sack_get_index (sack, i);
-		g_object_get (package,
-			      "info", &info,
-			      "summary", &summary,
-			      NULL);
-		/* new header */
-		if (info != info_last) {
-			title = gpk_task_simulate_question_type_to_text (info);
-			g_print ("%s\n", title);
-			info_last = info;
-		}
-		package_id = pk_package_get_id (package);
-		printable = pk_package_id_to_printable (package_id);
-		g_print (" %s\t%s\n", printable, summary);
+	array = pk_results_get_package_array (results);
 
-		g_free (summary);
-		g_free (printable);
-		g_object_unref (package);
-	}
+	priv->current_window = GTK_WINDOW (gtk_message_dialog_new (priv->parent_window, GTK_DIALOG_DESTROY_WITH_PARENT,
+								   GTK_MESSAGE_INFO, GTK_BUTTONS_CANCEL, "%s", title));
+	gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (priv->current_window), "%s", message);
+	gpk_dialog_embed_package_list_widget (GTK_DIALOG(priv->current_window), array);
+	gpk_dialog_embed_do_not_show_widget (GTK_DIALOG(priv->current_window), GPK_CONF_SHOW_DEPENDS);
+	/* TRANSLATORS: this is button text */
+	gtk_dialog_add_button (GTK_DIALOG(priv->current_window), _("Continue"), GTK_RESPONSE_YES);
+
+	/* set icon name */
+	gtk_window_set_icon_name (priv->current_window, GPK_ICON_SOFTWARE_INSTALLER);
 
-	/* TRANSLATORS: ask the user if the proposed changes are okay */
-//	ret = gpk_console_get_prompt (_("Proceed with changes?"), FALSE);
-//	if (ret) {
-//		pk_task_user_accepted (task, request);
-//	} else {
-//		/* TRANSLATORS: tell the user we didn't do anything */
-//		g_print ("%s\n", _("The transaction did not proceed."));
-		pk_task_user_declined (task, request);
-//	}
-
-	g_object_unref (sack);
+	g_signal_connect (priv->current_window, "response", G_CALLBACK (gpk_task_dialog_response_cb), task);
+	gtk_widget_show_all (GTK_WIDGET(priv->current_window));
+out:
+	if (array != NULL)
+		g_ptr_array_unref (array);
 }
 
 /**
@@ -579,6 +558,7 @@ gpk_task_init (GpkTask *task)
 	task->priv->request = 0;
 	task->priv->parent_window = NULL;
 	task->priv->current_window = NULL;
+	task->priv->gconf_client = gconf_client_get_default ();
 
 	/* setup dialogs ahead of time */
 	gpk_task_setup_dialog_untrusted (task);
@@ -598,6 +578,7 @@ gpk_task_finalize (GObject *object)
 	g_object_unref (task->priv->builder_untrusted);
 	g_object_unref (task->priv->builder_signature);
 	g_object_unref (task->priv->builder_eula);
+	g_object_unref (task->priv->gconf_client);
 
 	G_OBJECT_CLASS (gpk_task_parent_class)->finalize (object);
 }
diff --git a/src/gpk-update-viewer.c b/src/gpk-update-viewer.c
index fcec96b..b12f6a2 100644
--- a/src/gpk-update-viewer.c
+++ b/src/gpk-update-viewer.c
@@ -49,7 +49,6 @@
 #include "gpk-cell-renderer-restart.h"
 #include "gpk-cell-renderer-spinner.h"
 #include "gpk-enum.h"
-#include "gpk-helper-deps-update.h"
 
 #define GPK_UPDATE_VIEWER_AUTO_QUIT_TIMEOUT	10 /* seconds */
 #define GPK_UPDATE_VIEWER_AUTO_RESTART_TIMEOUT	60 /* seconds */
diff --git a/src/gpk-watch.c b/src/gpk-watch.c
index 64c23cf..f8f3ea8 100644
--- a/src/gpk-watch.c
+++ b/src/gpk-watch.c
@@ -70,13 +70,14 @@ struct GpkWatchPrivate
 	GpkModalDialog		*dialog;
 	PkClient		*client_primary;
 	PkControl		*pconnection;
-	PkTransactionList		*tlist;
+	PkTransactionList	*tlist;
 	PkRestartEnum		 restart;
 	GConfClient		*gconf_client;
 	guint			 set_proxy_timeout;
 	gchar			*error_details;
 	gboolean		 hide_warning;
 	EggConsoleKit		*console;
+	GCancellable		*cancellable;
 };
 
 typedef struct {
@@ -471,7 +472,6 @@ gpk_watch_task_list_finished_cb (PkTransactionList *tlist, PkClient *client, PkE
 		/* if more important than what we are already showing, then update the icon */
 		restart = pk_client_get_require_restart (client);
 		if (restart > watch->priv->restart) {
-#if PK_CHECK_VERSION(0,5,0)
 			/* list packages requiring this */
 			array = pk_client_get_require_restart_list (client);
 			if (array == NULL) {
@@ -505,14 +505,6 @@ gpk_watch_task_list_finished_cb (PkTransactionList *tlist, PkClient *client, PkE
 			}
 			g_object_unref (array);
 no_data:
-#else
-			/* list packages requiring this */
-			array = pk_client_get_require_restart_list (client);
-			for (i=0; i<array->len; i++) {
-				id = g_ptr_array_index (array, i);
-				g_ptr_array_add (watch->priv->restart_package_names, g_strdup (id->name));
-			}
-#endif
 			/* save new restart */
 			watch->priv->restart = restart;
 		}
@@ -967,7 +959,6 @@ gpk_watch_menu_show_messages_cb (GtkMenuItem *item, gpointer data)
 
 	gtk_widget_hide (main_window);
 
-	g_ptr_array_foreach (watch->priv->cached_messages, (GFunc) gpk_watch_cached_message_free, NULL);
 	g_ptr_array_set_size (watch->priv->cached_messages, 0);
 
 	g_object_unref (list_store);
@@ -1133,8 +1124,7 @@ gpk_watch_monitor_tid (GpkWatch *watch, const gchar *tid)
 	} else {
 		egg_warning ("GetProgress failed");
 		gpk_watch_progress_changed_cb (watch->priv->client_primary,
-						-1,
-						-1, 0, 0, watch);
+						-1, -1, 0, 0, watch);
 	}
 
 	/* get the role */
@@ -1161,13 +1151,11 @@ gpk_watch_monitor_tid (GpkWatch *watch, const gchar *tid)
 	/* do the best we can, and get the last package */
 	ret = pk_client_get_package (watch->priv->client_primary, &package_id, NULL);
 	if (ret) {
-		gchar *id;
 		PkItemPackage *item;
-
 		item = pk_package_item_new (PK_INFO_ENUM_UNKNOWN, package_id, NULL);
 		egg_warning ("package_id=%s", package_id);
 		gpk_watch_package_cb (watch->priv->client_primary, item, watch);
-		pk_package_item_free (item);
+		pk_item_package_unref (item);
 	}
 
 	gpk_modal_dialog_present (watch->priv->dialog);
@@ -1229,11 +1217,7 @@ gpk_watch_populate_menu_with_jobs (GpkWatch *watch, GtkMenu *menu)
 		localised_status = gpk_status_enum_to_localised_text (item->status);
 
 		icon_name = gpk_status_enum_to_icon_name (item->status);
-		if (!egg_strzero (item->text) &&
-		    item->role != PK_ROLE_ENUM_UPDATE_PACKAGES)
-			text = g_strdup_printf ("%s %s (%s)", localised_role, item->text, localised_status);
-		else
-			text = g_strdup_printf ("%s (%s)", localised_role, localised_status);
+		text = g_strdup_printf ("%s (%s)", localised_role, localised_status);
 
 		/* add a job */
 		widget = gtk_image_menu_item_new_with_mnemonic (text);
@@ -1514,6 +1498,28 @@ out:
 }
 
 /**
+ * gpk_watch_set_proxy_cb:
+ **/
+static void
+gpk_watch_set_proxy_cb (GObject *object, GAsyncResult *res, GpkWatch *watch)
+{
+	PkControl *control = PK_CONTROL (object);
+	GError *error = NULL;
+	gboolean ret;
+
+	/* we can run again */
+	watch->priv->set_proxy_timeout = 0;
+
+	/* get the result */
+	ret = pk_control_set_proxy_finish (control, res, &error);
+	if (!ret) {
+		egg_warning ("failed to set proxies: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+}
+
+/**
  * gpk_watch_set_proxies_ratelimit:
  **/
 static gboolean
@@ -1521,10 +1527,6 @@ gpk_watch_set_proxies_ratelimit (GpkWatch *watch)
 {
 	gchar *proxy_http;
 	gchar *proxy_ftp;
-	gboolean ret;
-	GError *error = NULL;
-
-	g_return_val_if_fail (GPK_IS_WATCH (watch), FALSE);
 
 	/* debug so we can catch polling */
 	egg_debug ("polling check");
@@ -1533,17 +1535,10 @@ gpk_watch_set_proxies_ratelimit (GpkWatch *watch)
 	proxy_ftp = gpk_watch_get_proxy_ftp (watch);
 
 	egg_debug ("set proxy_http=%s, proxy_ftp=%s", proxy_http, proxy_ftp);
-	ret = pk_control_set_proxy (watch->priv->control, proxy_http, proxy_ftp, &error);
-	if (!ret) {
-		egg_warning ("setting proxy failed: %s", error->message);
-		g_error_free (error);
-	}
-
+	pk_control_set_proxy_async (watch->priv->control, proxy_http, proxy_ftp, watch->priv->cancellable,
+				    (GAsyncReadyCallback) gpk_watch_set_proxy_cb, watch);
 	g_free (proxy_http);
 	g_free (proxy_ftp);
-
-	/* we can run again */
-	watch->priv->set_proxy_timeout = 0;
 	return FALSE;
 }
 
@@ -1617,15 +1612,8 @@ gpk_watch_button_close_cb (GtkWidget *widget, GpkWatch *watch)
 static void
 gpk_watch_button_cancel_cb (GtkWidget *widget, GpkWatch *watch)
 {
-	gboolean ret;
-	GError *error = NULL;
-
 	/* we might have a transaction running */
-	ret = g_cancellable_cancel (watch->priv->client_primary, &error);
-	if (!ret) {
-		egg_warning ("failed to cancel client: %s", error->message);
-		g_error_free (error);
-	}
+	g_cancellable_cancel (watch->priv->cancellable);
 }
 
 /**
@@ -1658,13 +1646,14 @@ gpk_watch_init (GpkWatch *watch)
 	watch->priv->restart = PK_RESTART_ENUM_NONE;
 	watch->priv->hide_warning = FALSE;
 	watch->priv->console = egg_console_kit_new ();
+	watch->priv->cancellable = g_cancellable_new ();
 
 	watch->priv->gconf_client = gconf_client_get_default ();
 
 	watch->priv->status_icon = gtk_status_icon_new ();
 	watch->priv->set_proxy_timeout = 0;
-	watch->priv->cached_messages = g_ptr_array_new ();
-	watch->priv->restart_package_names = g_ptr_array_new ();
+	watch->priv->cached_messages = g_ptr_array_new_with_free_func ((GDestroyNotify) gpk_watch_cached_message_free);
+	watch->priv->restart_package_names = g_ptr_array_new_with_free_func (g_free);
 
 	watch->priv->client_primary = pk_client_new ();
 	g_signal_connect (watch->priv->client_primary, "finished",
@@ -1750,14 +1739,8 @@ gpk_watch_finalize (GObject *object)
 	if (watch->priv->set_proxy_timeout != 0)
 		g_source_remove (watch->priv->set_proxy_timeout);
 
-	/* free cached messages */
-	g_ptr_array_foreach (watch->priv->cached_messages, (GFunc) gpk_watch_cached_message_free, NULL);
-	g_ptr_array_free (watch->priv->cached_messages, TRUE);
-
-	/* free cached restart names */
-	g_ptr_array_foreach (watch->priv->restart_package_names, (GFunc) g_free, NULL);
-	g_ptr_array_free (watch->priv->restart_package_names, TRUE);
-
+	g_ptr_array_unref (watch->priv->cached_messages);
+	g_ptr_array_unref (watch->priv->restart_package_names);
 	g_free (watch->priv->error_details);
 	g_object_unref (watch->priv->status_icon);
 	g_object_unref (watch->priv->inhibit);
@@ -1768,6 +1751,7 @@ gpk_watch_finalize (GObject *object)
 	g_object_unref (watch->priv->client_primary);
 	g_object_unref (watch->priv->dialog);
 	g_object_unref (watch->priv->console);
+	g_object_unref (watch->priv->cancellable);
 
 	G_OBJECT_CLASS (gpk_watch_parent_class)->finalize (object);
 }



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