[gnome-software/gnome-3-16] packagekit: Make sure progress gets correctly associated with an app



commit 2842edb3f01bb7081075aba7c138065c47b675d4
Author: Kalev Lember <klember redhat com>
Date:   Thu Jul 30 10:53:24 2015 +0200

    packagekit: Make sure progress gets correctly associated with an app
    
    Make sure that we keep track which app we're installing, so that instead
    of having a global progress, we can have one for each app.
    
    This fixes a case where installing two or more apps at the same time
    would lead to the second apps progress bar moving while the first app is
    installed, and vice versa.

 src/plugins/gs-plugin-packagekit.c |   74 +++++++++++++++++++++++++++++-------
 1 files changed, 60 insertions(+), 14 deletions(-)
---
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index 1ffc131..b3a33c1 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -66,6 +66,11 @@ gs_plugin_destroy (GsPlugin *plugin)
        g_object_unref (plugin->priv->task);
 }
 
+typedef struct {
+       GsApp           *app;
+       GsPlugin        *plugin;
+} ProgressData;
+
 /**
  * gs_plugin_packagekit_progress_cb:
  **/
@@ -74,7 +79,8 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
                                  PkProgressType type,
                                  gpointer user_data)
 {
-       GsPlugin *plugin = GS_PLUGIN (user_data);
+       ProgressData *data = (ProgressData *) user_data;
+       GsPlugin *plugin = data->plugin;
 
        if (type == PK_PROGRESS_TYPE_STATUS) {
                GsPluginStatus plugin_status;
@@ -102,7 +108,7 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
                              "percentage", &percentage,
                              NULL);
                if (percentage >= 0 && percentage <= 100)
-                       gs_plugin_progress_update (plugin, NULL, percentage);
+                       gs_plugin_progress_update (plugin, data->app, percentage);
        }
 }
 
@@ -116,8 +122,12 @@ gs_plugin_add_installed (GsPlugin *plugin,
                         GError **error)
 {
        PkBitfield filter;
+       ProgressData data;
        _cleanup_object_unref_ PkResults *results = NULL;
 
+       data.app = NULL;
+       data.plugin = plugin;
+
        /* update UI as this might take some time */
        gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
 
@@ -131,7 +141,7 @@ gs_plugin_add_installed (GsPlugin *plugin,
        results = pk_client_get_packages (PK_CLIENT(plugin->priv->task),
                                          filter,
                                          cancellable,
-                                         gs_plugin_packagekit_progress_cb, plugin,
+                                         gs_plugin_packagekit_progress_cb, &data,
                                          error);
        if (results == NULL)
                return FALSE;
@@ -154,10 +164,14 @@ gs_plugin_add_sources_related (GsPlugin *plugin,
        GsApp *app;
        GsApp *app_tmp;
        PkBitfield filter;
+       ProgressData data;
        const gchar *id;
        gboolean ret = TRUE;
        _cleanup_object_unref_ PkResults *results = NULL;
 
+       data.app = NULL;
+       data.plugin = plugin;
+
        gs_profile_start (plugin->profile, "packagekit::add-sources-related");
        filter = pk_bitfield_from_enums (PK_FILTER_ENUM_INSTALLED,
                                         PK_FILTER_ENUM_NEWEST,
@@ -167,7 +181,7 @@ gs_plugin_add_sources_related (GsPlugin *plugin,
        results = pk_client_get_packages (PK_CLIENT(plugin->priv->task),
                                           filter,
                                           cancellable,
-                                          gs_plugin_packagekit_progress_cb, plugin,
+                                          gs_plugin_packagekit_progress_cb, &data,
                                           error);
        if (results == NULL) {
                ret = FALSE;
@@ -210,12 +224,16 @@ gs_plugin_add_sources (GsPlugin *plugin,
 {
        PkBitfield filter;
        PkRepoDetail *rd;
+       ProgressData data;
        const gchar *id;
        guint i;
        _cleanup_hashtable_unref_ GHashTable *hash = NULL;
        _cleanup_object_unref_ PkResults *results = NULL;
        _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
 
+       data.app = NULL;
+       data.plugin = plugin;
+
        /* ask PK for the repo details */
        filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NOT_SOURCE,
                                         PK_FILTER_ENUM_NOT_SUPPORTED,
@@ -224,7 +242,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
        results = pk_client_get_repo_list (PK_CLIENT(plugin->priv->task),
                                           filter,
                                           cancellable,
-                                          gs_plugin_packagekit_progress_cb, plugin,
+                                          gs_plugin_packagekit_progress_cb, &data,
                                           error);
        if (results == NULL)
                return FALSE;
@@ -266,15 +284,19 @@ gs_plugin_app_source_enable (GsPlugin *plugin,
                             GCancellable *cancellable,
                             GError **error)
 {
+       ProgressData data;
        _cleanup_object_unref_ PkResults *results = NULL;
 
+       data.app = NULL;
+       data.plugin = plugin;
+
        /* do sync call */
        gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
        results = pk_client_repo_enable (PK_CLIENT (plugin->priv->task),
                                         gs_app_get_origin (app),
                                         TRUE,
                                         cancellable,
-                                        gs_plugin_packagekit_progress_cb, plugin,
+                                        gs_plugin_packagekit_progress_cb, &data,
                                         error);
        return results != NULL;
 }
@@ -290,6 +312,7 @@ gs_plugin_app_install (GsPlugin *plugin,
 {
        GPtrArray *addons;
        GPtrArray *source_ids;
+       ProgressData data;
        const gchar *package_id;
        guint i, j;
        _cleanup_object_unref_ PkError *error_code = NULL;
@@ -297,6 +320,9 @@ gs_plugin_app_install (GsPlugin *plugin,
        _cleanup_ptrarray_unref_ GPtrArray *array_package_ids = NULL;
        _cleanup_strv_free_ gchar **package_ids = NULL;
 
+       data.app = app;
+       data.plugin = plugin;
+
        /* only process this app if was created by this plugin */
        if (g_strcmp0 (gs_app_get_management_plugin (app), "PackageKit") != 0)
                return TRUE;
@@ -324,7 +350,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                results = pk_task_install_packages_sync (plugin->priv->task,
                                                         package_ids,
                                                         cancellable,
-                                                        gs_plugin_packagekit_progress_cb, plugin,
+                                                        gs_plugin_packagekit_progress_cb, &data,
                                                         error);
                if (results == NULL) {
                        gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
@@ -391,7 +417,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                results = pk_task_install_packages_sync (plugin->priv->task,
                                                         (gchar **) array_package_ids->pdata,
                                                         cancellable,
-                                                        gs_plugin_packagekit_progress_cb, plugin,
+                                                        gs_plugin_packagekit_progress_cb, &data,
                                                         error);
                if (results == NULL)
                        return FALSE;
@@ -410,7 +436,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                results = pk_task_install_files_sync (plugin->priv->task,
                                                      package_ids,
                                                      cancellable,
-                                                     gs_plugin_packagekit_progress_cb, plugin,
+                                                     gs_plugin_packagekit_progress_cb, &data,
                                                      error);
                if (results == NULL)
                        return FALSE;
@@ -450,15 +476,19 @@ gs_plugin_app_source_disable (GsPlugin *plugin,
                              GCancellable *cancellable,
                              GError **error)
 {
+       ProgressData data;
        _cleanup_object_unref_ PkResults *results = NULL;
 
+       data.app = NULL;
+       data.plugin = plugin;
+
        /* do sync call */
        gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
        results = pk_client_repo_enable (PK_CLIENT (plugin->priv->task),
                                         gs_app_get_id (app),
                                         FALSE,
                                         cancellable,
-                                        gs_plugin_packagekit_progress_cb, plugin,
+                                        gs_plugin_packagekit_progress_cb, &data,
                                         error);
        return results != NULL;
 }
@@ -473,9 +503,13 @@ gs_plugin_app_source_remove (GsPlugin *plugin,
                             GError **error)
 {
 #if PK_CHECK_VERSION(0,9,1)
+       ProgressData data;
        _cleanup_error_free_ GError *error_local = NULL;
        _cleanup_object_unref_ PkResults *results = NULL;
 
+       data.app = NULL;
+       data.plugin = plugin;
+
        /* do sync call */
        gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
        results = pk_client_repo_remove (PK_CLIENT (plugin->priv->task),
@@ -483,7 +517,7 @@ gs_plugin_app_source_remove (GsPlugin *plugin,
                                         gs_app_get_id (app),
                                         TRUE,
                                         cancellable,
-                                        gs_plugin_packagekit_progress_cb, plugin,
+                                        gs_plugin_packagekit_progress_cb, &data,
                                         &error_local);
        if (results == NULL) {
                /* fall back to disabling it */
@@ -509,12 +543,16 @@ gs_plugin_app_remove (GsPlugin *plugin,
 {
        const gchar *package_id;
        GPtrArray *source_ids;
+       ProgressData data;
        guint i;
        guint cnt = 0;
        _cleanup_object_unref_ PkError *error_code = NULL;
        _cleanup_object_unref_ PkResults *results = NULL;
        _cleanup_strv_free_ gchar **package_ids = NULL;
 
+       data.app = NULL;
+       data.plugin = plugin;
+
        /* only process this app if was created by this plugin */
        if (g_strcmp0 (gs_app_get_management_plugin (app), "PackageKit") != 0)
                return TRUE;
@@ -555,7 +593,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
                                                package_ids,
                                                TRUE, FALSE,
                                                cancellable,
-                                               gs_plugin_packagekit_progress_cb, plugin,
+                                               gs_plugin_packagekit_progress_cb, &data,
                                                error);
        if (results == NULL)
                return FALSE;
@@ -588,8 +626,12 @@ gs_plugin_add_search_files (GsPlugin *plugin,
                             GError **error)
 {
        PkBitfield filter;
+       ProgressData data;
        _cleanup_object_unref_ PkResults *results = NULL;
 
+       data.app = NULL;
+       data.plugin = plugin;
+
        /* do sync call */
        gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
        filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST,
@@ -599,7 +641,7 @@ gs_plugin_add_search_files (GsPlugin *plugin,
                                          filter,
                                          search,
                                          cancellable,
-                                         gs_plugin_packagekit_progress_cb, plugin,
+                                         gs_plugin_packagekit_progress_cb, &data,
                                          error);
        if (results == NULL)
                return FALSE;
@@ -619,8 +661,12 @@ gs_plugin_add_search_what_provides (GsPlugin *plugin,
                                     GError **error)
 {
        PkBitfield filter;
+       ProgressData data;
        _cleanup_object_unref_ PkResults *results = NULL;
 
+       data.app = NULL;
+       data.plugin = plugin;
+
        /* do sync call */
        gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
        filter = pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST,
@@ -630,7 +676,7 @@ gs_plugin_add_search_what_provides (GsPlugin *plugin,
                                           filter,
                                           search,
                                           cancellable,
-                                          gs_plugin_packagekit_progress_cb, plugin,
+                                          gs_plugin_packagekit_progress_cb, &data,
                                           error);
        if (results == NULL)
                return FALSE;


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