[gnome-packagekit/glib2: 31/79] moo
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-packagekit/glib2: 31/79] moo
- Date: Tue, 6 Oct 2009 09:47:20 +0000 (UTC)
commit e4068746bf53d1596b2b3362a5a76f4a274b29be
Author: Richard Hughes <richard hughsie com>
Date: Fri Sep 18 23:31:55 2009 +0100
moo
src/gpk-application.c | 8 +-
src/gpk-dbus-task.c | 18 +-
src/gpk-dbus.c | 5 +-
src/gpk-desktop.c | 6 +-
src/gpk-dialog.c | 5 +-
src/gpk-helper-run.c | 3 +-
src/gpk-service-pack.c | 5 +-
src/gpk-update-viewer.c | 14 +-
src/gpk-watch.c | 547 +++++++++++++++++++++++++----------------------
9 files changed, 313 insertions(+), 298 deletions(-)
---
diff --git a/src/gpk-application.c b/src/gpk-application.c
index bc8b2b3..3f08ea8 100644
--- a/src/gpk-application.c
+++ b/src/gpk-application.c
@@ -1321,7 +1321,7 @@ gpk_application_run_installed (GpkApplication *application)
gchar **package_ids = NULL;
/* get the package list and filter on INSTALLED */
- array = g_ptr_array_new ();
+ array = g_ptr_array_new_with_free_func (g_free);
list = pk_results_get_package_array (application->priv->client_primary);
len = list->len;
for (i=0; i<len; i++) {
@@ -1343,8 +1343,7 @@ gpk_application_run_installed (GpkApplication *application)
out:
g_strfreev (package_ids);
g_object_unref (list);
- g_ptr_array_foreach (array, (GFunc) g_free, NULL);
- g_ptr_array_free (array, TRUE);
+ g_ptr_array_unref (array);
}
/**
@@ -3378,8 +3377,7 @@ gpk_application_files_cb (PkClient *client, const gchar *package_id,
gtk_widget_destroy (GTK_WIDGET (dialog));
g_free (title);
- g_ptr_array_foreach (array, (GFunc) g_free, NULL);
- g_ptr_array_free (array, TRUE);
+ g_ptr_array_unref (array);
g_strfreev (files);
g_free (id);
out:
diff --git a/src/gpk-dbus-task.c b/src/gpk-dbus-task.c
index e7863e4..41e78e8 100644
--- a/src/gpk-dbus-task.c
+++ b/src/gpk-dbus-task.c
@@ -1289,7 +1289,7 @@ gpk_dbus_task_install_package_files_native_check (GpkDbusTask *task, GPtrArray *
GFile *file;
/* check if any files are non-native and need to be copied */
- array_missing = g_ptr_array_new ();
+ 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).
@@ -1393,8 +1393,7 @@ gpk_dbus_task_install_package_files_native_check (GpkDbusTask *task, GPtrArray *
}
out:
g_free (cache_path);
- g_ptr_array_foreach (array_missing, (GFunc) g_free, NULL);
- g_ptr_array_free (array_missing, TRUE);
+ g_ptr_array_unref (array_missing);
return ret;
}
@@ -1457,7 +1456,7 @@ gpk_dbus_task_install_package_files_check_exists (GpkDbusTask *task, GPtrArray *
const gchar *title;
gchar *message;
- array_missing = g_ptr_array_new ();
+ array_missing = g_ptr_array_new_with_free_func (g_free)
/* find missing */
for (i=0; i<array->len; i++) {
@@ -1494,8 +1493,7 @@ gpk_dbus_task_install_package_files_check_exists (GpkDbusTask *task, GPtrArray *
}
out:
- g_ptr_array_foreach (array_missing, (GFunc) g_free, NULL);
- g_ptr_array_free (array_missing, TRUE);
+ g_ptr_array_unref (array_missing);
return ret;
}
@@ -1550,7 +1548,7 @@ gpk_dbus_task_install_package_files_check_type (GpkDbusTask *task, GPtrArray *ar
GError *error_local = NULL;
gchar **supported_types;
- array_unknown = g_ptr_array_new ();
+ 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);
@@ -1613,8 +1611,7 @@ gpk_dbus_task_install_package_files_check_type (GpkDbusTask *task, GPtrArray *ar
out:
g_strfreev (supported_types);
- g_ptr_array_foreach (array_unknown, (GFunc) g_free, NULL);
- g_ptr_array_free (array_unknown, TRUE);
+ g_ptr_array_unref (array_unknown);
return ret;
}
@@ -1870,8 +1867,7 @@ gpk_dbus_task_install_package_files (GpkDbusTask *task, gchar **files_rel)
/* wait for async reply */
out:
- g_ptr_array_foreach (array, (GFunc) g_free, NULL);
- g_ptr_array_free (array, TRUE);
+ g_ptr_array_unref (array);
if (error != NULL)
g_error_free (error);
}
diff --git a/src/gpk-dbus.c b/src/gpk-dbus.c
index 0adb6d5..6806f31 100644
--- a/src/gpk-dbus.c
+++ b/src/gpk-dbus.c
@@ -492,7 +492,7 @@ gpk_dbus_init (GpkDbus *dbus)
dbus->priv = GPK_DBUS_GET_PRIVATE (dbus);
dbus->priv->timeout_tmp = -1;
dbus->priv->gconf_client = gconf_client_get_default ();
- dbus->priv->array = g_ptr_array_new ();
+ dbus->priv->array = g_ptr_array_new_with_free_func (g_object_unref)
dbus->priv->x11 = gpk_x11_new ();
/* find out PIDs on the session bus */
@@ -521,8 +521,7 @@ gpk_dbus_finalize (GObject *object)
dbus = GPK_DBUS (object);
g_return_if_fail (dbus->priv != NULL);
- g_ptr_array_foreach (dbus->priv->array, (GFunc) g_object_unref, NULL);
- g_ptr_array_free (dbus->priv->array, TRUE);
+ g_ptr_array_unref (dbus->priv->array);
g_object_unref (dbus->priv->gconf_client);
g_object_unref (dbus->priv->x11);
g_object_unref (dbus->priv->proxy_session_pid);
diff --git a/src/gpk-desktop.c b/src/gpk-desktop.c
index a290dde..c4fd549 100644
--- a/src/gpk-desktop.c
+++ b/src/gpk-desktop.c
@@ -267,10 +267,8 @@ gpk_desktop_guess_best_file (PkDesktop *desktop, const gchar *package)
best_file = g_strdup (g_ptr_array_index (array, max_index));
egg_debug ("using %s", best_file);
out:
- if (array != NULL) {
- g_ptr_array_foreach (array, (GFunc) g_free, NULL);
- g_ptr_array_free (array, TRUE);
- }
+ if (array != NULL)
+ g_ptr_array_unref (array);
return best_file;
}
diff --git a/src/gpk-dialog.c b/src/gpk-dialog.c
index 7a5aab0..b75c023 100644
--- a/src/gpk-dialog.c
+++ b/src/gpk-dialog.c
@@ -56,7 +56,7 @@ gpk_dialog_package_id_name_join_locale (gchar **package_ids)
gchar **split;
length = g_strv_length (package_ids);
- array = g_ptr_array_new ();
+ array = g_ptr_array_new_with_free_func (g_free);
for (i=0; i<length; i++) {
split = pk_package_id_split (package_ids[i]);
if (split == NULL) {
@@ -73,8 +73,7 @@ gpk_dialog_package_id_name_join_locale (gchar **package_ids)
/* TRANSLATORS: This is when we have over 5 items, and we're not interested in detail */
text = g_strdup (_("many packages"));
}
- g_ptr_array_foreach (array, (GFunc) g_free, NULL);
- g_ptr_array_free (array, TRUE);
+ g_ptr_array_unref (array);
return text;
}
diff --git a/src/gpk-helper-run.c b/src/gpk-helper-run.c
index e4afdb2..eac0d77 100644
--- a/src/gpk-helper-run.c
+++ b/src/gpk-helper-run.c
@@ -347,8 +347,7 @@ gpk_helper_run_add_package_ids (GpkHelperRun *helper, gchar **package_ids)
if (ret)
added++;
}
- g_ptr_array_foreach (array, (GFunc) g_free, NULL);
- g_ptr_array_free (array, TRUE);
+ g_ptr_array_unref (array);
}
g_strfreev (parts);
}
diff --git a/src/gpk-service-pack.c b/src/gpk-service-pack.c
index 9cb77e9..e4f410d 100644
--- a/src/gpk-service-pack.c
+++ b/src/gpk-service-pack.c
@@ -268,7 +268,7 @@ gpk_pack_resolve_package_ids (gchar **package, GError **error)
gchar *package_id;
length = g_strv_length (package);
- array = g_ptr_array_new ();
+ array = g_ptr_array_new_with_free_func (g_free);
/* for each package, resolve to a package_id */
for (i=0; i<length; i++) {
@@ -303,8 +303,7 @@ gpk_pack_resolve_package_ids (gchar **package, GError **error)
out:
/* free temp array */
- g_ptr_array_foreach (array, (GFunc) g_free, NULL);
- g_ptr_array_free (array, TRUE);
+ g_ptr_array_unref (array);
return package_ids;
}
diff --git a/src/gpk-update-viewer.c b/src/gpk-update-viewer.c
index 969509e..5073172 100644
--- a/src/gpk-update-viewer.c
+++ b/src/gpk-update-viewer.c
@@ -434,8 +434,7 @@ out:
/* get rid of the array, and free the contents */
if (array != NULL) {
- g_ptr_array_foreach (array, (GFunc) g_free, NULL);
- g_ptr_array_free (array, TRUE);
+ g_ptr_array_unref (array);
}
}
@@ -1187,7 +1186,7 @@ gpk_update_viewer_get_uris (const gchar *url_string)
guint length;
gint i;
- array = g_ptr_array_new ();
+ array = g_ptr_array_new_with_free_func (g_free);
urls = g_strsplit (url_string, ";", 0);
length = g_strv_length (urls);
@@ -1300,8 +1299,7 @@ gpk_update_viewer_populate_details (const PkUpdateDetailObj *item)
title = ngettext ("For more information about this update please visit this website:",
"For more information about this update please visit these websites:", array->len);
gpk_update_viewer_add_description_link_item (text_buffer, &iter, title, array);
- g_ptr_array_foreach (array, (GFunc) g_free, NULL);
- g_ptr_array_free (array, TRUE);
+ g_ptr_array_unref (array);
}
if (!egg_strzero (item->bugzilla_url)) {
array = gpk_update_viewer_get_uris (item->bugzilla_url);
@@ -1309,8 +1307,7 @@ gpk_update_viewer_populate_details (const PkUpdateDetailObj *item)
title = ngettext ("For more information about bugs fixed by this update please visit this website:",
"For more information about bugs fixed by this update please visit these websites:", array->len);
gpk_update_viewer_add_description_link_item (text_buffer, &iter, title, array);
- g_ptr_array_foreach (array, (GFunc) g_free, NULL);
- g_ptr_array_free (array, TRUE);
+ g_ptr_array_unref (array);
}
if (!egg_strzero (item->cve_url)) {
array = gpk_update_viewer_get_uris (item->cve_url);
@@ -1318,8 +1315,7 @@ gpk_update_viewer_populate_details (const PkUpdateDetailObj *item)
title = ngettext ("For more information about this security update please visit this website:",
"For more information about this security update please visit these websites:", array->len);
gpk_update_viewer_add_description_link_item (text_buffer, &iter, title, array);
- g_ptr_array_foreach (array, (GFunc) g_free, NULL);
- g_ptr_array_free (array, TRUE);
+ g_ptr_array_unref (array);
}
/* reboot */
diff --git a/src/gpk-watch.c b/src/gpk-watch.c
index 4731079..6714a42 100644
--- a/src/gpk-watch.c
+++ b/src/gpk-watch.c
@@ -68,8 +68,7 @@ struct GpkWatchPrivate
NotifyNotification *notification_cached_messages;
GpkInhibit *inhibit;
GpkModalDialog *dialog;
- PkClient *client_primary;
- PkControl *pconnection;
+ PkClient *client;
PkTransactionList *tlist;
PkRestartEnum restart;
GConfClient *gconf_client;
@@ -78,6 +77,8 @@ struct GpkWatchPrivate
gboolean hide_warning;
EggConsoleKit *console;
GCancellable *cancellable;
+ GPtrArray *array_progress;
+ gchar *transaction_id;
};
typedef struct {
@@ -163,7 +164,7 @@ gpk_watch_get_restart_required_tooltip (GpkWatch *watch)
}
/* join */
- text = g_strdup_printf ("%s\n%s", title, message);
+ text = g_strdup_printf ("%s%s", title, message);
goto out;
}
@@ -183,34 +184,34 @@ static gboolean
gpk_watch_refresh_tooltip (GpkWatch *watch)
{
guint i;
- PkTransactionListItem *item;
- guint length;
+ PkProgress *progress;
guint len;
- GString *status;
+ GString *string;
+ PkStatusEnum status;
const gchar *trailer;
- const gchar *localised_status;
gchar *text;
+ GPtrArray *array;
g_return_val_if_fail (GPK_IS_WATCH (watch), FALSE);
- status = g_string_new ("");
- length = pk_transaction_list_get_size (watch->priv->tlist);
- egg_debug ("refresh tooltip %i", length);
- if (length == 0) {
+ string = g_string_new ("");
+ array = watch->priv->array_progress;
+ egg_debug ("refresh tooltip %i", array->len);
+ if (array->len == 0) {
/* any restart required? */
text = gpk_watch_get_restart_required_tooltip (watch);
if (text != NULL) {
- g_string_append (status, text);
+ g_string_append (string, text);
}
g_free (text);
/* do we have any cached messages to show? */
len = watch->priv->cached_messages->len;
if (len > 0) {
- if (status->len > 0)
- g_string_append_c (status, '\n');
- g_string_append_printf (status, ngettext ("%i message from the package manager",
+ if (string->len > 0)
+ g_string_append_c (string, '\n');
+ g_string_append_printf (string, ngettext ("%i message from the package manager",
"%i messages from the package manager", len), len);
goto out;
}
@@ -218,32 +219,30 @@ gpk_watch_refresh_tooltip (GpkWatch *watch)
egg_debug ("nothing to show");
goto out;
}
- for (i=0; i<length; i++) {
- item = pk_transaction_list_get_item (watch->priv->tlist, i);
- if (item == NULL) {
- egg_warning ("not found item %i", i);
- break;
- }
- localised_status = gpk_status_enum_to_localised_text (item->status);
+ for (i=0; i<array->len; i++) {
+ progress = g_ptr_array_index (array, i);
+ g_object_get (progress,
+ "status", &status,
+ NULL);
/* should we display the text */
- g_string_append_printf (status, "%s\n", localised_status);
+ g_string_append_printf (string, "%s", gpk_status_enum_to_localised_text (status));
/* don't fill the screen with a giant tooltip */
if (i > GPK_WATCH_MAXIMUM_TOOLTIP_LINES) {
/* TRANSLATORS: if the menu won't fit, inform the user there are a few more things waiting */
trailer = ngettext ("(%i more task)", "(%i more tasks)", i - GPK_WATCH_MAXIMUM_TOOLTIP_LINES);
- g_string_append_printf (status, "%s\n", trailer);
+ g_string_append_printf (string, "%s", trailer);
break;
}
}
- if (status->len == 0)
- g_string_append (status, "Doing something...");
+ if (string->len == 0)
+ g_string_append (string, "Doing something...");
else
- g_string_set_size (status, status->len-1);
+ g_string_set_size (string, string->len-1);
out:
- gtk_status_icon_set_tooltip_text (watch->priv->status_icon, status->str);
- g_string_free (status, TRUE);
+ gtk_status_icon_set_tooltip_text (watch->priv->status_icon, string->str);
+ g_string_free (string, TRUE);
return TRUE;
}
@@ -257,42 +256,45 @@ gpk_watch_task_list_to_status_bitfield (GpkWatch *watch)
gboolean active;
gboolean watch_active;
guint i;
- guint length;
- PkBitfield status = 0;
- PkTransactionListItem *item;
+ PkBitfield bitfield = 0;
+ PkStatusEnum status;
+ PkProgress *progress;
+ gchar *transaction_id;
+ GPtrArray *array;
- g_return_val_if_fail (GPK_IS_WATCH (watch), PK_STATUS_ENUM_UNKNOWN);
+ g_return_val_if_fail (GPK_IS_WATCH (watch), 0);
/* shortcut */
- length = pk_transaction_list_get_size (watch->priv->tlist);
- if (length == 0)
+ array = watch->priv->array_progress;
+ if (array->len == 0)
goto out;
/* do we watch active transactions */
watch_active = gconf_client_get_bool (watch->priv->gconf_client, GPK_CONF_WATCH_ACTIVE_TRANSACTIONS, NULL);
/* add each status to a list */
- for (i=0; i<length; i++) {
- item = pk_transaction_list_get_item (watch->priv->tlist, i);
- if (item == NULL) {
- egg_warning ("not found item %i", i);
- break;
- }
+ for (i=0; i<array->len; i++) {
+ progress = g_ptr_array_index (array, i);
/* only show an icon for this if the application isn't still on the bus */
- g_object_get (item->monitor, "caller-active", &active, NULL);
+ g_object_get (progress,
+ "caller-active", &active,
+ "status", &status,
+ "transaction-id", &transaction_id,
+ NULL);
/* if we failed to get data, assume bad things happened */
if (!ret)
active = TRUE;
/* add to bitfield calculation */
- egg_debug ("%s %s (active:%i)", item->tid, pk_status_enum_to_text (item->status), active);
+ egg_debug ("%s %s (active:%i)", transaction_id, pk_status_enum_to_text (status), active);
if (!active || watch_active)
- pk_bitfield_add (status, item->status);
+ pk_bitfield_add (bitfield, status);
+ g_free (transaction_id);
}
out:
- return status;
+ return bitfield;
}
/**
@@ -381,18 +383,6 @@ out:
}
/**
- * gpk_watch_task_list_changed_cb:
- **/
-static void
-gpk_watch_task_list_changed_cb (PkTransactionList *tlist, GpkWatch *watch)
-{
- g_return_if_fail (GPK_IS_WATCH (watch));
-
- gpk_watch_refresh_icon (watch);
- gpk_watch_refresh_tooltip (watch);
-}
-
-/**
* gpk_watch_libnotify_cb:
**/
static void
@@ -419,6 +409,7 @@ gpk_watch_libnotify_cb (NotifyNotification *notification, gchar *action, gpointe
static void
gpk_watch_task_list_finished_cb (PkTransactionList *tlist, PkClient *client, PkExitEnum exit_enum, guint runtime, GpkWatch *watch)
{
+xxx
guint i;
gboolean ret;
gboolean value;
@@ -557,6 +548,7 @@ out:
static void
gpk_watch_error_code_cb (PkTransactionList *tlist, PkClient *client, PkErrorCodeEnum error_code, const gchar *details, GpkWatch *watch)
{
+xxx
gboolean ret;
GError *error = NULL;
const gchar *title;
@@ -575,7 +567,7 @@ gpk_watch_error_code_cb (PkTransactionList *tlist, PkClient *client, PkErrorCode
/* do we ignore this error? */
if (is_active) {
- egg_debug ("client active so leaving error %s\n%s", title, details);
+ egg_debug ("client active so leaving error %s%s", title, details);
return;
}
@@ -584,7 +576,7 @@ gpk_watch_error_code_cb (PkTransactionList *tlist, PkClient *client, PkErrorCode
error_code == PK_ERROR_ENUM_NO_NETWORK ||
error_code == PK_ERROR_ENUM_PROCESS_KILL ||
error_code == PK_ERROR_ENUM_TRANSACTION_CANCELLED) {
- egg_debug ("error ignored %s\n%s", title, details);
+ egg_debug ("error ignored %s%s", title, details);
return;
}
@@ -670,6 +662,7 @@ out:
static void
gpk_watch_message_cb (PkTransactionList *tlist, PkClient *client, PkMessageEnum message, const gchar *details, GpkWatch *watch)
{
+xxx
gboolean ret;
GError *error = NULL;
gboolean value;
@@ -785,8 +778,8 @@ gpk_watch_show_about_cb (GtkMenuItem *item, gpointer data)
if (!strcmp (translators, "translator-credits"))
translators = NULL;
- license_trans = g_strconcat (_(license[0]), "\n\n", _(license[1]), "\n\n",
- _(license[2]), "\n\n", _(license[3]), "\n", NULL);
+ license_trans = g_strconcat (_(license[0]), "", _(license[1]), "",
+ _(license[2]), "", _(license[3]), "", NULL);
gtk_about_dialog_set_url_hook (gpk_watch_about_dialog_url_cb, NULL, NULL);
gtk_about_dialog_set_email_hook (gpk_watch_about_dialog_url_cb, (gpointer) "mailto:";, NULL);
@@ -956,50 +949,6 @@ out_build:
}
/**
- * gpk_watch_get_role_text:
- **/
-static gchar *
-gpk_watch_get_role_text (PkClient *client)
-{
- const gchar *role_text;
- gchar *text;
- gchar *message;
- PkRoleEnum role;
- GError *error = NULL;
- gboolean ret;
-
- /* get role and text */
- ret = pk_client_get_role (client, &role, &text, &error);
- if (!ret) {
- egg_warning ("failed to get role: %s", error->message);
- g_error_free (error);
- return NULL;
- }
-
- /* backup */
- role_text = gpk_role_enum_to_localised_present (role);
-
- if (!egg_strzero (text) && role != PK_ROLE_ENUM_UPDATE_PACKAGES)
- message = g_strdup_printf ("%s: %s", role_text, text);
- else
- message = g_strdup_printf ("%s", role_text);
- g_free (text);
-
- return message;
-}
-
-/**
- * gpk_watch_progress_changed_cb:
- **/
-static void
-gpk_watch_progress_changed_cb (PkClient *client, guint percentage, guint subpercentage,
- guint elapsed, guint remaining, GpkWatch *watch)
-{
- gpk_modal_dialog_set_percentage (watch->priv->dialog, percentage);
- gpk_modal_dialog_set_remaining (watch->priv->dialog, remaining);
-}
-
-/**
* gpk_watch_set_status:
**/
static gboolean
@@ -1038,24 +987,31 @@ gpk_watch_set_status (GpkWatch *watch, PkStatusEnum status)
}
/**
- * gpk_watch_status_changed_cb:
+ * gpk_watch_lookup_progress_from_transaction_id:
**/
-static void
-gpk_watch_status_changed_cb (PkClient *client, PkStatusEnum status, GpkWatch *watch)
+static PkProgress *
+gpk_watch_lookup_progress_from_transaction_id (GpkWatch *watch, const gchar *transaction_id)
{
- gpk_watch_set_status (watch, status);
-}
-
-/**
- * gpk_watch_package_cb:
- **/
-static void
-gpk_watch_package_cb (PkClient *client, const PkItemPackage *item, GpkWatch *watch)
-{
- gchar *text;
- text = gpk_package_id_format_twoline (item->package_id, item->summary);
- gpk_modal_dialog_set_message (watch->priv->dialog, text);
- g_free (text);
+ GPtrArray *array;
+ guint i;
+ gchar *tid_tmp;
+ gboolean ret;
+ PkProgress *progress;
+
+ array = watch->priv->array_progress;
+ for (i=0; i<array->length; i++) {
+ progress = g_ptr_array_index (array, i);
+ g_object_get (progress,
+ "transaction-id", &tid_tmp,
+ NULL);
+ ret = (g_strcmp0 (transaction_id, tid_tmp) == 0);
+ g_free (tid_tmp);
+ if (ret)
+ goto out;
+ }
+ progress = NULL;
+out:
+ return progress;
}
/**
@@ -1064,60 +1020,44 @@ gpk_watch_package_cb (PkClient *client, const PkItemPackage *item, GpkWatch *wat
static gboolean
gpk_watch_monitor_tid (GpkWatch *watch, const gchar *tid)
{
- PkStatusEnum status;
- gboolean ret;
gboolean allow_cancel;
- gchar *text;
+ gboolean ret;
gchar *package_id = NULL;
+ gchar *text;
guint percentage;
- guint subpercentage;
- guint elapsed;
- guint remaining;
+ guint remaining_time;
GError *error = NULL;
+ PkProgress *progress;
PkRoleEnum role;
+ PkStatusEnum status;
- ret = pk_client_set_tid (watch->priv->client_primary, tid, &error);
- if (!ret) {
- egg_warning ("could not set tid: %s", error->message);
- g_error_free (error);
- return FALSE;
+ g_free (watch->priv->transaction_id);
+ watch->priv->transaction_id = g_strdup (tid);
+
+ /* find progress */
+ progress = gpk_watch_lookup_progress_from_transaction_id (watch, transaction_id);
+ if (progress == NULL) {
+ egg_warning ("could not find: %s", transaction_id);
+ return;
}
/* fill in role */
- text = gpk_watch_get_role_text (watch->priv->client_primary);
- gpk_modal_dialog_set_title (watch->priv->dialog, text);
- g_free (text);
+ gpk_modal_dialog_set_title (watch->priv->dialog, gpk_role_enum_to_localised_present (role));
/* coldplug */
- ret = pk_client_get_status (watch->priv->client_primary, &status, NULL);
- /* no such transaction? */
- if (!ret) {
- egg_warning ("could not get status");
- return FALSE;
- }
+ g_object_get (progress,
+ "role", &role,
+ "status", &status,
+ "allow-cancel", &allow_cancel,
+ "percentage", &percentage,
+ "remaining-time", &remaining_time,
+ "package-id", &package_id,
+ NULL);
/* are we cancellable? */
- pk_client_get_allow_cancel (watch->priv->client_primary, &allow_cancel, NULL);
gpk_modal_dialog_set_allow_cancel (watch->priv->dialog, allow_cancel);
-
- /* coldplug */
- ret = pk_client_get_progress (watch->priv->client_primary,
- &percentage, &subpercentage, &elapsed, &remaining, NULL);
- if (ret) {
- gpk_watch_progress_changed_cb (watch->priv->client_primary, percentage,
- subpercentage, elapsed, remaining, watch);
- } else {
- egg_warning ("GetProgress failed");
- gpk_watch_progress_changed_cb (watch->priv->client_primary,
- -1, -1, 0, 0, watch);
- }
-
- /* get the role */
- ret = pk_client_get_role (watch->priv->client_primary, &role, NULL, &error);
- if (!ret) {
- egg_warning ("failed to get role: %s", error->message);
- g_error_free (error);
- }
+ gpk_modal_dialog_set_percentage (watch->priv->dialog, percentage);
+ gpk_modal_dialog_set_remaining (watch->priv->dialog, remaining_time);
/* setup the UI */
if (role == PK_ROLE_ENUM_SEARCH_NAME ||
@@ -1134,17 +1074,12 @@ gpk_watch_monitor_tid (GpkWatch *watch, const gchar *tid)
gpk_watch_set_status (watch, status);
/* do the best we can, and get the last package */
- ret = pk_client_get_package (watch->priv->client_primary, &package_id, NULL);
- if (ret) {
- 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_item_package_unref (item);
- }
+ text = gpk_package_id_format_twoline (package_id, NULL);
+ gpk_modal_dialog_set_message (watch->priv->dialog, text);
gpk_modal_dialog_present (watch->priv->dialog);
-
+ g_free (package_id);
+ g_free (text);
return TRUE;
}
@@ -1172,59 +1107,56 @@ gpk_watch_menu_job_status_cb (GtkMenuItem *item, GpkWatch *watch)
/**
* gpk_watch_populate_menu_with_jobs:
**/
-static guint
+static void
gpk_watch_populate_menu_with_jobs (GpkWatch *watch, GtkMenu *menu)
{
guint i;
- PkTransactionListItem *item;
+ PkProgress *progress;
GtkWidget *widget;
GtkWidget *image;
PkRoleEnum role;
PkStatusEnum status;
- const gchar *localised_status;
- const gchar *localised_role;
const gchar *icon_name;
gchar *text;
- guint length;
+ gchar *transaction_id;
+ GPtrArray *array;
g_return_val_if_fail (GPK_IS_WATCH (watch), 0);
- length = pk_transaction_list_get_size (watch->priv->tlist);
- if (length == 0)
+ array = watch->priv->array_progress;
+ if (array->len == 0)
goto out;
/* do a menu item for each job */
- for (i=0; i<length; i++) {
- item = pk_transaction_list_get_item (watch->priv->tlist, i);
- if (item == NULL) {
- egg_warning ("not found item %i", i);
- break;
- }
- g_object_get (item->monitor,
+ for (i=0; i<array->len; i++) {
+ progress = g_ptr_array_index (array, i);
+ g_object_get (progress,
"role", &role,
"status", &status,
- NULL_;
- localised_role = gpk_role_enum_to_localised_present (role);
- localised_status = gpk_status_enum_to_localised_text (status);
+ "transaction-id", &transaction_id,
+ NULL);
- icon_name = gpk_status_enum_to_icon_name (item->status);
- text = g_strdup_printf ("%s (%s)", localised_role, localised_status);
+ icon_name = gpk_status_enum_to_icon_name (status);
+ text = g_strdup_printf ("%s (%s)",
+ gpk_role_enum_to_localised_present (role),
+ gpk_status_enum_to_localised_text (status));
/* add a job */
widget = gtk_image_menu_item_new_with_mnemonic (text);
/* we need the job ID so we know what transaction to show */
- g_object_set_data (G_OBJECT (widget), "tid", (gpointer) item->tid);
+ g_object_set_data (G_OBJECT (widget), "tid", (gpointer) transaction_id);
image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (widget), image);
g_signal_connect (G_OBJECT (widget), "activate",
G_CALLBACK (gpk_watch_menu_job_status_cb), watch);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), widget);
+ g_free (transaction_id);
g_free (text);
}
out:
- return length;
+ return;
}
/**
@@ -1295,7 +1227,7 @@ gpk_watch_activate_status_cb (GtkStatusIcon *status_icon, GpkWatch *watch)
egg_debug ("icon left clicked");
/* add jobs as drop down */
- len = gpk_watch_populate_menu_with_jobs (watch, menu);
+ gpk_watch_populate_menu_with_jobs (watch, menu);
/* any messages to show? */
len = watch->priv->cached_messages->len;
@@ -1562,66 +1494,183 @@ gpk_watch_gconf_key_changed_cb (GConfClient *client, guint cnxn_id, GConfEntry *
}
/**
- * gpk_watch_allow_cancel_cb:
+ * gpk_watch_button_close_cb:
**/
static void
-gpk_watch_allow_cancel_cb (PkClient *client, gboolean allow_cancel, GpkWatch *watch)
+gpk_watch_button_close_cb (GtkWidget *widget, GpkWatch *watch)
{
- gpk_modal_dialog_set_allow_cancel (watch->priv->dialog, allow_cancel);
+ /* close, don't abort */
+ gpk_modal_dialog_close (watch->priv->dialog);
}
/**
- * gpk_watch_finished_cb:
+ * gpk_watch_button_cancel_cb:
**/
static void
-gpk_watch_finished_cb (PkClient *client, PkExitEnum exit_enum, guint runtime, GpkWatch *watch)
+gpk_watch_button_cancel_cb (GtkWidget *widget, GpkWatch *watch)
{
- g_return_if_fail (GPK_IS_WATCH (watch));
+ /* we might have a transaction running */
+ g_cancellable_cancel (watch->priv->cancellable);
+}
+
+/**
+ * gpk_watch_notify_connected_cb:
+ **/
+static void
+gpk_watch_notify_connected_cb (PkControl *control, GParamSpec *pspec, gpointer data)
+{
+ gboolean connected;
+ g_object_get (control, "connected", &connected, NULL);
+ if (connected) {
+ gpk_watch_refresh_icon (watch);
+ gpk_watch_refresh_tooltip (watch);
+ gpk_watch_set_proxies (watch);
+ } else {
+ gtk_status_icon_set_visible (watch->priv->status_icon, FALSE);
+ }
+}
+
+/**
+ * gpk_watch_adopt_cb:
+ **/
+static void
+gpk_watch_adopt_cb (PkClient *client, GAsyncResult *res, gpointer user_data)
+{
+ GError *error = NULL;
+ PkResults *results = NULL;
+ PkExitEnum exit_enum;
+ gchar *transaction_id = NULL;
+
+ /* get the results */
+ results = pk_client_generic_finish (client, res, &error);
+ if (results == NULL) {
+ egg_warning ("failed to adopt: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* get data about the transaction */
+ g_object_get (results,
+ "transaction-id", &transaction_id,
+ NULL);
+
+ /* is not the watched transaction */
+ if (g_strcmp0 (transaction_id, progress->priv->transaction_id) != 0)
+ goto out;
/* stop spinning */
gpk_modal_dialog_set_percentage (watch->priv->dialog, 100);
/* autoclose if success */
- if (exit_enum == PK_EXIT_ENUM_SUCCESS) {
+ exit_enum = pk_results_get_exit_code (results);
+ if (exit_enum == PK_EXIT_ENUM_SUCCESS)
gpk_modal_dialog_close (watch->priv->dialog);
- }
+out:
+ g_free (transaction_id);
+ if (results != NULL)
+ g_object_unref (results);
}
/**
- * gpk_watch_button_close_cb:
+ * gpk_watch_progress_cb:
**/
static void
-gpk_watch_button_close_cb (GtkWidget *widget, GpkWatch *watch)
+gpk_watch_progress_cb (PkProgress *progress, PkProgressType type, gpointer user_data)
{
- /* close, don't abort */
- gpk_modal_dialog_close (watch->priv->dialog);
+ PkStatusEnum status;
+ guint percentage;
+ gboolean allow_cancel;
+ gchar *package_id;
+ gchar *transaction_id;
+ GPtrArray *array;
+ guint i;
+ gboolean ret = FALSE;
+ PkProgress *progress_tmp;
+ guint remaining_time;
+ gchar *text;
+
+ /* add if not already in list */
+ array = watch->priv->array_progress;
+ for (i=0; i<array->length; i++) {
+ progress = g_ptr_array_index (array, i);
+ if (progress_tmp == progress)
+ ret = TRUE;
+ }
+ if (!ret)
+ g_ptr_array_add (array, g_object_ref (progress));
+
+ /* get data */
+ g_object_get (progress,
+ "status", &status,
+ "percentage", &percentage,
+ "allow-cancel", &allow_cancel,
+ "package-id", &package_id,
+ "remaining-time", &remaining_time,
+ "transaction-id", &transaction_id,
+ NULL);
+
+ /* refresh both */
+ gpk_watch_refresh_icon (watch);
+ gpk_watch_refresh_tooltip (watch);
+
+ /* is not the watched transaction */
+ if (g_strcmp0 (transaction_id, progress->priv->transaction_id) != 0)
+ goto out;
+
+ if (type == PK_PROGRESS_TYPE_PACKAGE_ID) {
+ text = gpk_package_id_format_twoline (package_id, NULL);
+ gpk_modal_dialog_set_message (watch->priv->dialog, text);
+ } else if (type == PK_PROGRESS_TYPE_PERCENTAGE) {
+ gpk_modal_dialog_set_percentage (watch->priv->dialog, percentage);
+ } else if (type == PK_PROGRESS_TYPE_REMAINING_TIME) {
+ gpk_modal_dialog_set_remaining (watch->priv->dialog, remaining_time);
+ } else if (type == PK_PROGRESS_TYPE_ALLOW_CANCEL) {
+ gpk_modal_dialog_set_allow_cancel (watch->priv->dialog, allow_cancel);
+ } else if (type == PK_PROGRESS_TYPE_STATUS) {
+ gpk_watch_set_status (watch, status);
+ }
+out:
+ g_free (text);
+ g_free (package_id);
+ g_free (transaction_id);
}
/**
- * gpk_watch_button_cancel_cb:
+ * gpk_watch_transaction_list_added_cb:
**/
static void
-gpk_watch_button_cancel_cb (GtkWidget *widget, GpkWatch *watch)
+gpk_watch_transaction_list_added_cb (PkTransactionList *tlist, const gchar *transaction_id, GpkWatch *watch)
{
- /* we might have a transaction running */
- g_cancellable_cancel (watch->priv->cancellable);
+ PkProgress *progress;
+
+ /* find progress */
+ progress = gpk_watch_lookup_progress_from_transaction_id (watch, transaction_id);
+ if (progress != NULL) {
+ egg_warning ("already added: %s", transaction_id);
+ return;
+ }
+ egg_debug ("added: %s", transaction_id);
+ pk_client_adopt_async (watch->priv->client, transaction_id, NULL,
+ (PkProgressCallback) gpk_watch_progress_cb, watch,
+ (GAsyncReadyCallback) gpk_watch_adopt_cb, watch);
}
/**
- * gpk_watch_connection_changed_cb:
+ * gpk_watch_transaction_list_removed_cb:
**/
static void
-gpk_watch_connection_changed_cb (PkControl *pconnection, gboolean connected, GpkWatch *watch)
+gpk_watch_transaction_list_removed_cb (PkTransactionList *tlist, const gchar *transaction_id, GpkWatch *watch)
{
- g_return_if_fail (GPK_IS_WATCH (watch));
- egg_debug ("connected=%i", connected);
- if (connected) {
- gpk_watch_refresh_icon (watch);
- gpk_watch_refresh_tooltip (watch);
- gpk_watch_set_proxies (watch);
- } else {
- gtk_status_icon_set_visible (watch->priv->status_icon, FALSE);
+ PkProgress *progress;
+
+ /* find progress */
+ progress = gpk_watch_lookup_progress_from_transaction_id (watch, transaction_id);
+ if (progress == NULL) {
+ egg_warning ("could not find: %s", transaction_id);
+ return;
}
+ egg_debug ("removed: %s", transaction_id);
+ g_ptr_array_remove_fast (watch->priv->array_progress, progress);
}
/**
@@ -1634,30 +1683,19 @@ gpk_watch_init (GpkWatch *watch)
watch->priv = GPK_WATCH_GET_PRIVATE (watch);
watch->priv->error_details = NULL;
watch->priv->notification_cached_messages = NULL;
+ watch->priv->transaction_id = NULL;
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->array_progress = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
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_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",
- G_CALLBACK (gpk_watch_finished_cb), watch);
- g_signal_connect (watch->priv->client_primary, "progress-changed",
- G_CALLBACK (gpk_watch_progress_changed_cb), watch);
- g_signal_connect (watch->priv->client_primary, "status-changed",
- G_CALLBACK (gpk_watch_status_changed_cb), watch);
- g_signal_connect (watch->priv->client_primary, "package",
- G_CALLBACK (gpk_watch_package_cb), watch);
- g_signal_connect (watch->priv->client_primary, "allow-cancel",
- G_CALLBACK (gpk_watch_allow_cancel_cb), watch);
-
+ watch->priv->client = pk_client_new ();
watch->priv->dialog = gpk_modal_dialog_new ();
gpk_modal_dialog_set_window_icon (watch->priv->dialog, "pk-package-installed");
g_signal_connect (watch->priv->dialog, "cancel",
@@ -1669,6 +1707,10 @@ gpk_watch_init (GpkWatch *watch)
watch->priv->control = pk_control_new ();
g_signal_connect (watch->priv->control, "locked",
G_CALLBACK (gpk_watch_locked_cb), watch);
+ g_signal_connect (watch->priv->control, "notify::connected",
+ G_CALLBACK (gpk_watch_notify_connected_cb), watch);
+ if (pk_connection_valid (watch->priv->control))
+ gpk_watch_connection_changed_cb (watch->priv->control, TRUE, watch);
/* do session inhibit */
watch->priv->inhibit = gpk_inhibit_new ();
@@ -1680,22 +1722,10 @@ gpk_watch_init (GpkWatch *watch)
"activate", G_CALLBACK (gpk_watch_activate_status_cb), watch, 0);
watch->priv->tlist = pk_transaction_list_new ();
- g_signal_connect (watch->priv->tlist, "changed",
- G_CALLBACK (gpk_watch_task_list_changed_cb), watch);
- g_signal_connect (watch->priv->tlist, "status-changed",
- G_CALLBACK (gpk_watch_task_list_changed_cb), watch);
- g_signal_connect (watch->priv->tlist, "finished",
- G_CALLBACK (gpk_watch_task_list_finished_cb), watch);
- g_signal_connect (watch->priv->tlist, "error-code",
- G_CALLBACK (gpk_watch_error_code_cb), watch);
- g_signal_connect (watch->priv->tlist, "message",
- G_CALLBACK (gpk_watch_message_cb), watch);
-
- watch->priv->pconnection = pk_control_new ();
- g_signal_connect (watch->priv->pconnection, "connection-changed",
- G_CALLBACK (gpk_watch_connection_changed_cb), watch);
- if (pk_connection_valid (watch->priv->pconnection))
- gpk_watch_connection_changed_cb (watch->priv->pconnection, TRUE, watch);
+ g_signal_connect (watch->priv->tlist, "added",
+ G_CALLBACK (gpk_watch_transaction_list_added_cb), watch);
+ g_signal_connect (watch->priv->tlist, "removed",
+ G_CALLBACK (gpk_watch_transaction_list_removed_cb), watch);
/* watch proxy keys */
gconf_client_add_dir (watch->priv->gconf_client, GPK_WATCH_GCONF_PROXY_HTTP,
@@ -1730,19 +1760,20 @@ gpk_watch_finalize (GObject *object)
if (watch->priv->set_proxy_timeout != 0)
g_source_remove (watch->priv->set_proxy_timeout);
- 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);
- g_object_unref (watch->priv->tlist);
+ g_free (watch->priv->transaction_id);
+ g_object_unref (watch->priv->cancellable);
+ g_object_unref (watch->priv->client);
+ g_object_unref (watch->priv->console);
g_object_unref (watch->priv->control);
- g_object_unref (watch->priv->pconnection);
- g_object_unref (watch->priv->gconf_client);
- 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_unref (watch->priv->gconf_client);
+ g_object_unref (watch->priv->inhibit);
+ g_object_unref (watch->priv->status_icon);
+ g_object_unref (watch->priv->tlist);
+ g_ptr_array_unref (watch->priv->array_progress);
+ g_ptr_array_unref (watch->priv->cached_messages);
+ g_ptr_array_unref (watch->priv->restart_package_names);
G_OBJECT_CLASS (gpk_watch_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]