[gnome-software] Do not use gs_plugin_progress_update() in plugins



commit 6ba961878f74291cf1ab12147621169aac9a4530
Author: Richard Hughes <richard hughsie com>
Date:   Thu Apr 21 10:40:19 2016 +0100

    Do not use gs_plugin_progress_update() in plugins
    
    The GsApp already does a idle property notify and so we don't need to idle
    this twice.

 src/gs-plugin.c                    |   32 --------------------------
 src/gs-plugin.h                    |    3 --
 src/plugins/gs-plugin-limba.c      |    4 +-
 src/plugins/gs-plugin-packagekit.c |    7 +----
 src/plugins/gs-plugin-xdg-app.c    |   43 ++++++-----------------------------
 5 files changed, 12 insertions(+), 77 deletions(-)
---
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 3373f33..3754026 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -523,38 +523,6 @@ gs_plugin_status_update (GsPlugin *plugin, GsApp *app, GsPluginStatus status)
 }
 
 /**
- * gs_plugin_progress_update_cb:
- **/
-static gboolean
-gs_plugin_progress_update_cb (gpointer user_data)
-{
-       GsPluginStatusHelper *helper = (GsPluginStatusHelper *) user_data;
-
-       gs_app_set_progress (helper->app, helper->percentage);
-       g_object_unref (helper->app);
-       g_slice_free (GsPluginStatusHelper, helper);
-       return FALSE;
-}
-
-/**
- * gs_plugin_progress_update:
- **/
-void
-gs_plugin_progress_update (GsPlugin *plugin, GsApp *app, guint percentage)
-{
-       GsPluginStatusHelper *helper;
-
-       if (app == NULL)
-               return;
-
-       helper = g_slice_new0 (GsPluginStatusHelper);
-       helper->plugin = plugin;
-       helper->percentage = percentage;
-       helper->app = g_object_ref (app);
-       g_idle_add (gs_plugin_progress_update_cb, helper);
-}
-
-/**
  * gs_plugin_app_launch_cb:
  **/
 static gboolean
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 1171d12..076a09c 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -175,9 +175,6 @@ void                 gs_plugin_cache_add                    (GsPlugin       *plugin,
 void            gs_plugin_status_update                (GsPlugin       *plugin,
                                                         GsApp          *app,
                                                         GsPluginStatus  status);
-void            gs_plugin_progress_update              (GsPlugin       *plugin,
-                                                        GsApp          *app,
-                                                        guint           percentage);
 gboolean        gs_plugin_app_launch                   (GsPlugin       *plugin,
                                                         GsApp          *app,
                                                         GError         **error);
diff --git a/src/plugins/gs-plugin-limba.c b/src/plugins/gs-plugin-limba.c
index dce1184..3ba41bd 100644
--- a/src/plugins/gs-plugin-limba.c
+++ b/src/plugins/gs-plugin-limba.c
@@ -152,7 +152,7 @@ gs_plugin_installer_progress_cb (LiInstaller *inst, guint percentage, const gcha
        if (id != NULL)
                return;
 
-       gs_plugin_progress_update (helper->plugin, helper->app, percentage);
+       gs_app_set_progress (helper->app, percentage);
 }
 
 /**
@@ -169,7 +169,7 @@ gs_plugin_manager_progress_cb (LiManager *mgr, guint percentage, const gchar *id
        if (id != NULL)
                return;
 
-       gs_plugin_progress_update (helper->plugin, helper->app, percentage);
+       gs_app_set_progress (helper->app, percentage);
 }
 
 /**
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index 5241fb0..f991c89 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -110,12 +110,9 @@ gs_plugin_packagekit_progress_cb (PkProgress *progress,
                        gs_plugin_status_update (plugin, NULL, plugin_status);
 
        } else if (type == PK_PROGRESS_TYPE_PERCENTAGE) {
-               gint percentage;
-               g_object_get (progress,
-                             "percentage", &percentage,
-                             NULL);
+               gint percentage = pk_progress_get_percentage (progress);
                if (percentage >= 0 && percentage <= 100)
-                       gs_plugin_progress_update (plugin, data->app, percentage);
+                       gs_app_set_progress (data->app, percentage);
        }
 }
 
diff --git a/src/plugins/gs-plugin-xdg-app.c b/src/plugins/gs-plugin-xdg-app.c
index 5634713..e4f8307 100644
--- a/src/plugins/gs-plugin-xdg-app.c
+++ b/src/plugins/gs-plugin-xdg-app.c
@@ -438,11 +438,6 @@ gs_plugin_xdg_app_create_installed (GsPlugin *plugin,
        return g_object_ref (app);
 }
 
-typedef struct {
-       GsApp           *app;
-       GsPlugin        *plugin;
-} GsPluginHelper;
-
 /**
  * gs_plugin_xdg_app_progress_cb:
  */
@@ -452,10 +447,8 @@ gs_plugin_xdg_app_progress_cb (const gchar *status,
                               gboolean estimating,
                               gpointer user_data)
 {
-       GsPluginHelper *helper = (GsPluginHelper *) user_data;
-       if (helper->app == NULL)
-               return;
-       gs_plugin_progress_update (helper->plugin, helper->app, progress);
+       GsApp *app = GS_APP (user_data);
+       gs_app_set_progress (app, progress);
 }
 
 /**
@@ -616,7 +609,6 @@ gs_plugin_refresh (GsPlugin *plugin,
                   GError **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
-       GsPluginHelper helper;
        guint i;
        g_autoptr(GPtrArray) xrefs = NULL;
 
@@ -631,9 +623,6 @@ gs_plugin_refresh (GsPlugin *plugin,
        if ((flags & GS_PLUGIN_REFRESH_FLAGS_PAYLOAD) == 0)
                return TRUE;
 
-       /* use helper: FIXME: new()&ref? */
-       helper.plugin = plugin;
-
        /* get all the updates available from all remotes */
        xrefs = xdg_app_installation_list_installed_refs_for_update (priv->installation,
                                                                     cancellable,
@@ -647,7 +636,6 @@ gs_plugin_refresh (GsPlugin *plugin,
 
                /* try to create a GsApp so we can do progress reporting */
                app = gs_plugin_xdg_app_create_installed (plugin, xref, NULL);
-               helper.app = app;
 
                /* fetch but do not deploy */
                g_debug ("pulling update for %s",
@@ -658,7 +646,7 @@ gs_plugin_refresh (GsPlugin *plugin,
                                                     xdg_app_ref_get_name (XDG_APP_REF (xref)),
                                                     xdg_app_ref_get_arch (XDG_APP_REF (xref)),
                                                     xdg_app_ref_get_branch (XDG_APP_REF (xref)),
-                                                    gs_plugin_xdg_app_progress_cb, &helper,
+                                                    gs_plugin_xdg_app_progress_cb, app,
                                                     cancellable, error);
                if (xref2 == NULL)
                        return FALSE;
@@ -1228,16 +1216,11 @@ gs_plugin_app_remove (GsPlugin *plugin,
                      GError **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
-       GsPluginHelper helper;
 
        /* only process this app if was created by this plugin */
        if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
                return TRUE;
 
-       /* use helper: FIXME: new()&ref? */
-       helper.app = app;
-       helper.plugin = plugin;
-
        /* remove */
        gs_app_set_state (app, AS_APP_STATE_REMOVING);
        if (!xdg_app_installation_uninstall (priv->installation,
@@ -1245,7 +1228,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
                                             gs_app_get_xdgapp_name (app),
                                             gs_app_get_xdgapp_arch (app),
                                             gs_app_get_xdgapp_branch (app),
-                                            gs_plugin_xdg_app_progress_cb, &helper,
+                                            gs_plugin_xdg_app_progress_cb, app,
                                             cancellable, error)) {
                gs_app_set_state_recover (app);
                return FALSE;
@@ -1266,7 +1249,6 @@ gs_plugin_app_install (GsPlugin *plugin,
                       GError **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
-       GsPluginHelper helper;
        g_autoptr(XdgAppInstalledRef) xref = NULL;
 
        /* only process this app if was created by this plugin */
@@ -1277,10 +1259,6 @@ gs_plugin_app_install (GsPlugin *plugin,
        if (!gs_plugin_xdg_app_refine_app (plugin, app, 0, cancellable, error))
                return FALSE;
 
-       /* use helper: FIXME: new()&ref? */
-       helper.app = app;
-       helper.plugin = plugin;
-
        /* install */
        gs_app_set_state (app, AS_APP_STATE_INSTALLING);
 
@@ -1316,7 +1294,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                                                             gs_app_get_xdgapp_name (runtime),
                                                             gs_app_get_xdgapp_arch (runtime),
                                                             gs_app_get_xdgapp_branch (runtime),
-                                                            gs_plugin_xdg_app_progress_cb, &helper,
+                                                            gs_plugin_xdg_app_progress_cb, app,
                                                             cancellable, error);
                        if (xref == NULL) {
                                gs_app_set_state_recover (runtime);
@@ -1336,7 +1314,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                xref = xdg_app_installation_install_bundle (priv->installation,
                                                            file,
                                                            gs_plugin_xdg_app_progress_cb,
-                                                           &helper,
+                                                           app,
                                                            cancellable, error);
        } else {
                g_debug ("installing %s", gs_app_get_id (app));
@@ -1346,7 +1324,7 @@ gs_plugin_app_install (GsPlugin *plugin,
                                                     gs_app_get_xdgapp_name (app),
                                                     gs_app_get_xdgapp_arch (app),
                                                     gs_app_get_xdgapp_branch (app),
-                                                    gs_plugin_xdg_app_progress_cb, &helper,
+                                                    gs_plugin_xdg_app_progress_cb, app,
                                                     cancellable, error);
        }
        if (xref == NULL) {
@@ -1369,17 +1347,12 @@ gs_plugin_update_app (GsPlugin *plugin,
                      GError **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
-       GsPluginHelper helper;
        g_autoptr(XdgAppInstalledRef) xref = NULL;
 
        /* only process this app if was created by this plugin */
        if (g_strcmp0 (gs_app_get_management_plugin (app), plugin->name) != 0)
                return TRUE;
 
-       /* use helper: FIXME: new()&ref? */
-       helper.app = app;
-       helper.plugin = plugin;
-
        /* install */
        gs_app_set_state (app, AS_APP_STATE_INSTALLING);
        xref = xdg_app_installation_update (priv->installation,
@@ -1388,7 +1361,7 @@ gs_plugin_update_app (GsPlugin *plugin,
                                            gs_app_get_xdgapp_name (app),
                                            gs_app_get_xdgapp_arch (app),
                                            gs_app_get_xdgapp_branch (app),
-                                           gs_plugin_xdg_app_progress_cb, &helper,
+                                           gs_plugin_xdg_app_progress_cb, app,
                                            cancellable, error);
        if (xref == NULL) {
                gs_app_set_state_recover (app);


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