[gnome-software: 5/9] Fix showing the apps queued for installation in the installed page




commit 0f053e9d0ab34f124e8f747a337503811f306a4e
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Thu Feb 15 23:11:51 2018 +0100

    Fix showing the apps queued for installation in the installed page
    
    For showing the apps that are queued for installation in the installed
    page, we need to make sure the apps have the information required for
    them to be shown, and thus they need to be refined with the flags that
    the installed page needs.
    
    This patch gets the list of pending apps from the plugin loader and then
    runs the refine action on them; and when the refine is done, the apps
    are added to the page.
    
    (Rebased from downstream Endless OS by Philip Withnall)

 src/gs-installed-page.c | 98 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 64 insertions(+), 34 deletions(-)
---
diff --git a/src/gs-installed-page.c b/src/gs-installed-page.c
index 978cd66c0..97f4744c1 100644
--- a/src/gs-installed-page.c
+++ b/src/gs-installed-page.c
@@ -462,24 +462,10 @@ filter_app_kinds_cb (GsApp    *app,
        }
 }
 
-static void
-gs_installed_page_load (GsInstalledPage *self)
+static GsPluginRefineFlags
+gs_installed_page_get_refine_flags (GsInstalledPage *self)
 {
        GsPluginRefineFlags flags;
-       g_autoptr(GsAppQuery) query = NULL;
-       g_autoptr(GsPluginJob) plugin_job = NULL;
-
-       if (self->waiting)
-               return;
-       self->waiting = TRUE;
-
-       /* remove old entries */
-       gs_widget_remove_all (self->list_box_install_in_progress, gs_installed_page_remove_all_cb);
-       gs_widget_remove_all (self->list_box_install_apps, gs_installed_page_remove_all_cb);
-       gs_widget_remove_all (self->list_box_install_system_apps, gs_installed_page_remove_all_cb);
-       gs_widget_remove_all (self->list_box_install_addons, gs_installed_page_remove_all_cb);
-       gs_widget_remove_all (self->list_box_install_web_apps, gs_installed_page_remove_all_cb);
-       update_groups (self);
 
        flags = GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON |
                GS_PLUGIN_REFINE_FLAGS_REQUIRE_HISTORY |
@@ -496,9 +482,30 @@ gs_installed_page_load (GsInstalledPage *self)
        if (should_show_installed_size (self))
                flags |= GS_PLUGIN_REFINE_FLAGS_REQUIRE_SIZE;
 
+       return flags;
+}
+
+static void
+gs_installed_page_load (GsInstalledPage *self)
+{
+       g_autoptr(GsAppQuery) query = NULL;
+       g_autoptr(GsPluginJob) plugin_job = NULL;
+
+       if (self->waiting)
+               return;
+       self->waiting = TRUE;
+
+       /* remove old entries */
+       gs_widget_remove_all (self->list_box_install_in_progress, gs_installed_page_remove_all_cb);
+       gs_widget_remove_all (self->list_box_install_apps, gs_installed_page_remove_all_cb);
+       gs_widget_remove_all (self->list_box_install_system_apps, gs_installed_page_remove_all_cb);
+       gs_widget_remove_all (self->list_box_install_addons, gs_installed_page_remove_all_cb);
+       gs_widget_remove_all (self->list_box_install_web_apps, gs_installed_page_remove_all_cb);
+       update_groups (self);
+
        /* get installed apps */
        query = gs_app_query_new ("is-installed", GS_APP_QUERY_TRISTATE_TRUE,
-                                 "refine-flags", flags,
+                                 "refine-flags", gs_installed_page_get_refine_flags (self),
                                  "filter-func", filter_app_kinds_cb,
                                  NULL);
        plugin_job = gs_plugin_job_list_apps_new (query, GS_PLUGIN_LIST_APPS_FLAGS_INTERACTIVE);
@@ -670,39 +677,62 @@ gs_installed_page_has_app (GsInstalledPage *self,
 }
 
 static void
-gs_installed_page_pending_apps_changed_cb (GsPluginLoader *plugin_loader,
-                                           GsInstalledPage *self)
+gs_installed_page_pending_apps_refined_cb (GObject *source,
+                                          GAsyncResult *res,
+                                          gpointer user_data)
 {
-       GsApp *app;
-       guint i;
-       guint cnt = 0;
-       g_autoptr(GsAppList) pending = NULL;
+       GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
+       GsInstalledPage *self = GS_INSTALLED_PAGE (user_data);
+       guint pending_apps_count = 0;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GsAppList) list = gs_plugin_loader_job_process_finish (plugin_loader,
+                                                                        res,
+                                                                        &error);
+       if (list == NULL) {
+               if (!g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_CANCELLED))
+                       g_warning ("failed to refine pending apps: %s", error->message);
+               return;
+       }
 
-       /* add new apps to the list */
-       pending = gs_plugin_loader_get_pending (plugin_loader);
-       for (i = 0; i < gs_app_list_length (pending); i++) {
-               app = gs_app_list_index (pending, i);
+       for (guint i = 0; i < gs_app_list_length (list); ++i) {
+               GsApp *app = gs_app_list_index (list, i);
+               if (gs_app_is_installed (app))
+                       continue;
 
                /* never show OS upgrades, we handle the scheduling and
                 * cancellation in GsUpgradeBanner */
                if (gs_app_get_kind (app) == AS_COMPONENT_KIND_OPERATING_SYSTEM)
                        continue;
 
-               /* do not to add pending apps more than once. */
-               if (gs_installed_page_has_app (self, app) == FALSE)
-                       gs_installed_page_add_app (self, pending, app);
+               if (gs_app_get_state (app) == GS_APP_STATE_AVAILABLE)
+                       gs_app_set_state (app, GS_APP_STATE_QUEUED_FOR_INSTALL);
 
-               /* incremement the label */
-               cnt++;
+               ++pending_apps_count;
+               if (!gs_installed_page_has_app (self, app))
+                       gs_installed_page_add_app (self, list, app);
        }
 
        /* update the number of on-going operations */
-       if (cnt != self->pending_apps_counter) {
-               self->pending_apps_counter = cnt;
+       if (pending_apps_count != self->pending_apps_counter) {
+               self->pending_apps_counter = pending_apps_count;
                g_object_notify (G_OBJECT (self), "counter");
        }
 }
 
+static void
+gs_installed_page_pending_apps_changed_cb (GsPluginLoader *plugin_loader,
+                                           GsInstalledPage *self)
+{
+       g_autoptr(GsAppList) pending = gs_plugin_loader_get_pending (plugin_loader);
+       g_autoptr(GsPluginJob) plugin_job = gs_plugin_job_refine_new (pending,
+                                                                     gs_installed_page_get_refine_flags 
(self));
+       gs_plugin_job_set_interactive (plugin_job, FALSE);
+       gs_plugin_loader_job_process_async (self->plugin_loader, plugin_job,
+                                           self->cancellable,
+                                           gs_installed_page_pending_apps_refined_cb,
+                                           self);
+}
+
 static gboolean
 gs_installed_page_setup (GsPage *page,
                          GsShell *shell,


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