[gnome-software/wip/william/update-all: 72/75] Update apps individually as a fallback



commit 43e1cd864355a96a9fdaba0ce3ee4c0f021f8db8
Author: William Hua <william hua canonical com>
Date:   Wed Apr 6 14:43:59 2016 +0100

    Update apps individually as a fallback

 src/gs-plugin-loader.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 8dc7914..614ae97 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -25,6 +25,7 @@
 #include <glib/gi18n.h>
 #include <appstream-glib.h>
 
+#include "gs-plugin-loader-sync.h"
 #include "gs-plugin-loader.h"
 #include "gs-plugin.h"
 #include "gs-utils.h"
@@ -3881,6 +3882,47 @@ gs_plugin_loader_offline_update_finish (GsPluginLoader *plugin_loader,
 
 /******************************************************************************/
 
+typedef struct {
+       GList                   *apps;
+       GAsyncReadyCallback      callback;
+       gpointer                 user_data;
+} GsPluginLoaderUpdateAllState;
+
+/**
+ * gs_plugin_loader_update_all_remaining_cb:
+ *
+ * Finish up by updating all remaining apps that weren't done by any
+ * gs_plugin_update_all() call.
+ **/
+static void
+gs_plugin_loader_update_all_remaining_cb (GObject *source_object,
+                                          GAsyncResult *res,
+                                          gpointer user_data)
+{
+       GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
+       GsPluginLoaderUpdateAllState *state = user_data;
+       GsApp *app;
+       GList *i;
+
+       for (i = state->apps; i != NULL; i = i->next) {
+               app = i->data;
+
+               if (gs_app_get_state (app) == AS_APP_STATE_UPDATABLE_LIVE) {
+                       gs_plugin_loader_app_action (plugin_loader,
+                                                    app,
+                                                    GS_PLUGIN_LOADER_ACTION_UPDATE,
+                                                    NULL,
+                                                    NULL);
+               }
+       }
+
+       if (state->callback != NULL)
+               state->callback (source_object, res, state->user_data);
+
+       g_list_free_full (state->apps, g_object_unref);
+       g_free (state);
+}
+
 /**
  * gs_plugin_loader_update_all_async:
  *
@@ -3894,15 +3936,22 @@ gs_plugin_loader_update_all_async (GsPluginLoader *plugin_loader,
                                    GAsyncReadyCallback callback,
                                    gpointer user_data)
 {
+       GsPluginLoaderUpdateAllState *state;
+
        g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
        g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
 
+       state = g_new (GsPluginLoaderUpdateAllState, 1);
+       state->apps = g_list_copy_deep (apps, (GCopyFunc) g_object_ref, NULL);
+       state->callback = callback;
+       state->user_data = user_data;
+
        gs_plugin_loader_iterate_app_list_async (plugin_loader,
                                                 "gs_plugin_update_all",
                                                 apps,
                                                 cancellable,
-                                                callback,
-                                                user_data);
+                                                gs_plugin_loader_update_all_remaining_cb,
+                                                state);
 }
 
 /**


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