[gnome-software/wip/william/update-all: 5/6] Implement gs_plugin_update_all for apt plugin



commit 1f81f7d022ff9b64c8698d50507eec65a15e6d11
Author: William Hua <william hua canonical com>
Date:   Wed Apr 6 18:25:04 2016 +0100

    Implement gs_plugin_update_all for apt plugin

 src/plugins/gs-plugin-apt.c |   89 +++++++++++++++++++++++++++++++++---------
 1 files changed, 70 insertions(+), 19 deletions(-)
---
diff --git a/src/plugins/gs-plugin-apt.c b/src/plugins/gs-plugin-apt.c
index 8a80cda..53e08b6 100644
--- a/src/plugins/gs-plugin-apt.c
+++ b/src/plugins/gs-plugin-apt.c
@@ -625,7 +625,17 @@ notify_unity_launcher (GsApp *app, const gchar *transaction_path)
 }
 
 static gboolean
-aptd_transaction (GsPlugin *plugin, const gchar *method, GsApp *app, GError **error)
+app_is_ours (GsApp *app)
+{
+       const gchar *management_plugin = gs_app_get_management_plugin (app);
+
+       // FIXME: Since appstream marks all packages as owned by PackageKit and we are replacing PackageKit 
we need to accept those packages
+       return g_strcmp0 (management_plugin, "PackageKit") == 0 ||
+              g_strcmp0 (management_plugin, "dpkg") == 0;
+}
+
+static gboolean
+aptd_transaction (GsPlugin *plugin, const gchar *method, GsApp *app, GList *apps, GError **error)
 {
        g_autoptr(GDBusConnection) conn = NULL;
        GVariant *parameters;
@@ -634,6 +644,10 @@ aptd_transaction (GsPlugin *plugin, const gchar *method, GsApp *app, GError **er
        g_autoptr(GMainLoop) loop = NULL;
        guint property_signal, finished_signal;
        TransactionData data;
+       GPtrArray *related;
+       GsApp *app_tmp;
+       GList *i;
+       guint j;
 
        conn = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
        if (conn == NULL)
@@ -641,10 +655,29 @@ aptd_transaction (GsPlugin *plugin, const gchar *method, GsApp *app, GError **er
 
        if (g_strcmp0 (method, "InstallFile") == 0)
                parameters = g_variant_new ("(sb)", gs_app_get_origin (app), TRUE);
-       else if (app != NULL) {
+       else if (app != NULL || apps != NULL) {
                GVariantBuilder builder;
-               g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")),
-               g_variant_builder_add (&builder, "s", gs_app_get_source_default (app));
+               g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
+
+               if (app != NULL)
+                       g_variant_builder_add (&builder, "s", gs_app_get_source_default (app));
+
+               for (i = apps; i != NULL; i = i->next) {
+                       if (gs_app_get_kind (i->data) == AS_APP_KIND_OS_UPDATE) {
+                               related = gs_app_get_related (i->data);
+
+                               for (j = 0; j < related->len; j++) {
+                                       app_tmp = g_ptr_array_index (related, j);
+                                       g_variant_builder_add (&builder, "s", gs_app_get_source_default 
(app_tmp));
+                               }
+
+                               continue;
+                       }
+
+                       if (app_is_ours (i->data))
+                               g_variant_builder_add (&builder, "s", gs_app_get_source_default (i->data));
+               }
+
                parameters = g_variant_new ("(as)", &builder);
        } else
                parameters = g_variant_new ("()");
@@ -722,16 +755,6 @@ aptd_transaction (GsPlugin *plugin, const gchar *method, GsApp *app, GError **er
        return TRUE;
 }
 
-static gboolean
-app_is_ours (GsApp *app)
-{
-       const gchar *management_plugin = gs_app_get_management_plugin (app);
-
-       // FIXME: Since appstream marks all packages as owned by PackageKit and we are replacing PackageKit 
we need to accept those packages
-       return g_strcmp0 (management_plugin, "PackageKit") == 0 ||
-              g_strcmp0 (management_plugin, "dpkg") == 0;
-}
-
 gboolean
 gs_plugin_app_install (GsPlugin *plugin,
                       GsApp *app,
@@ -749,9 +772,9 @@ gs_plugin_app_install (GsPlugin *plugin,
        gs_app_set_state (app, AS_APP_STATE_INSTALLING);
 
        if (g_strcmp0 (gs_app_get_management_plugin (app), "PackageKit") == 0)
-               success = aptd_transaction (plugin, "InstallPackages", app, error);
+               success = aptd_transaction (plugin, "InstallPackages", app, NULL, error);
        else if (g_strcmp0 (gs_app_get_management_plugin (app), "dpkg") == 0)
-               success = aptd_transaction (plugin, "InstallFile", app, error);
+               success = aptd_transaction (plugin, "InstallFile", app, NULL, error);
 
        if (success)
                gs_app_set_state (app, AS_APP_STATE_INSTALLED);
@@ -774,7 +797,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
                return TRUE;
 
        gs_app_set_state (app, AS_APP_STATE_REMOVING);
-       if (aptd_transaction (plugin, "RemovePackages", app, error))
+       if (aptd_transaction (plugin, "RemovePackages", app, NULL, error))
                gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
        else {
                gs_app_set_state (app, AS_APP_STATE_INSTALLED);
@@ -794,7 +817,7 @@ gs_plugin_refresh (GsPlugin *plugin,
        if ((flags & GS_PLUGIN_REFRESH_FLAGS_UPDATES) == 0)
                return TRUE;
 
-       return aptd_transaction (plugin, "UpdateCache", NULL, error);
+       return aptd_transaction (plugin, "UpdateCache", NULL, NULL, error);
 }
 
 gboolean
@@ -843,7 +866,7 @@ gs_plugin_app_update (GsPlugin *plugin,
                return TRUE;
 
        gs_app_set_state (app, AS_APP_STATE_INSTALLING);
-       if (aptd_transaction (plugin, "UpgradePackages", app, error))
+       if (aptd_transaction (plugin, "UpgradePackages", app, NULL, error))
                gs_app_set_state (app, AS_APP_STATE_INSTALLED);
        else {
                gs_app_set_state (app, AS_APP_STATE_UPDATABLE_LIVE);
@@ -854,6 +877,34 @@ gs_plugin_app_update (GsPlugin *plugin,
 }
 
 gboolean
+gs_plugin_update_all (GsPlugin *plugin,
+                     GList *apps,
+                     GCancellable *cancellable,
+                     GError **error)
+{
+       GList *i;
+
+       for (i = apps; i != NULL; i = i->next)
+               gs_app_set_state (i->data, AS_APP_STATE_INSTALLING);
+
+       if (aptd_transaction (plugin, "UpgradePackages", NULL, apps, error)) {
+               plugin->priv->installed_packages = g_list_concat (plugin->priv->installed_packages,
+                                                                 plugin->priv->updatable_packages);
+               plugin->priv->updatable_packages = NULL;
+
+               for (i = apps; i != NULL; i = i->next)
+                       gs_app_set_state (i->data, AS_APP_STATE_INSTALLED);
+
+               return TRUE;
+       } else {
+               for (i = apps; i != NULL; i = i->next)
+                       gs_app_set_state (i->data, AS_APP_STATE_UPDATABLE_LIVE);
+
+               return FALSE;
+       }
+}
+
+gboolean
 gs_plugin_launch (GsPlugin *plugin,
                  GsApp *app,
                  GCancellable *cancellable,


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