[gnome-software] Move getting the update details from packagekit to packagekit-refine



commit cf0ef509c16e2635e3df7dc7e52e9e1835640e7b
Author: Richard Hughes <richard hughsie com>
Date:   Thu Sep 12 14:49:49 2013 +0100

    Move getting the update details from packagekit to packagekit-refine
    
    This allows us to refine a set of packages that did not originate from GetUpdates.

 po/POTFILES.in                            |    1 +
 src/plugins/gs-plugin-packagekit-refine.c |   91 ++++++++++++++++++++++-
 src/plugins/gs-plugin-packagekit.c        |  115 ++++------------------------
 3 files changed, 108 insertions(+), 99 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 7e012e3..84ed23f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -15,4 +15,5 @@ src/gs-shell-updates.c
 src/gs-utils.c
 src/plugins/gs-plugin-hardcoded-menu-spec.c
 src/plugins/gs-plugin-packagekit.c
+src/plugins/gs-plugin-packagekit-refine.c
 [type: gettext/glade]src/popular-tile.ui
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 2379244..1e7cbe4 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -25,6 +25,7 @@
 #include <packagekit-glib2/packagekit.h>
 
 #include <gs-plugin.h>
+#include <glib/gi18n.h>
 
 struct GsPluginPrivate {
        PkClient                *client;
@@ -213,6 +214,7 @@ gs_plugin_packagekit_refine_packages (GsPlugin *plugin,
                }
        }
 out:
+       g_free (package_ids);
        if (packages != NULL)
                g_ptr_array_unref (packages);
        if (error_code != NULL)
@@ -290,6 +292,73 @@ out:
 /**
  * gs_plugin_refine:
  */
+static gboolean
+gs_plugin_packagekit_refine_updatedetails (GsPlugin *plugin,
+                                          GList *list,
+                                          GCancellable *cancellable,
+                                          GError **error)
+{
+       const gchar *package_id;
+       gboolean ret = TRUE;
+       const gchar **package_ids;
+       GList *l;
+       GPtrArray *array = NULL;
+       GsApp *app;
+       guint i = 0;
+       guint size;
+       PkResults *results = NULL;
+       PkUpdateDetail *update_detail;
+
+       size = g_list_length (list);
+       package_ids = g_new0 (const gchar *, size + 1);
+       for (l = list; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               package_id = gs_app_get_metadata_item (app, "PackageKit::package-id");
+               package_ids[i++] = package_id;
+       }
+
+       /* get any update details */
+       results = pk_client_get_update_detail (plugin->priv->client,
+                                              (gchar **) package_ids,
+                                              cancellable,
+                                              gs_plugin_packagekit_progress_cb, plugin,
+                                              error);
+       if (results == NULL) {
+               ret = FALSE;
+               goto out;
+       }
+
+       /* set the update details for the update */
+       array = pk_results_get_update_detail_array (results);
+       for (l = list; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               package_id = gs_app_get_metadata_item (app, "PackageKit::package-id");
+               for (i = 0; i < array->len; i++) {
+                       /* right package? */
+                       update_detail = g_ptr_array_index (array, i);
+                       if (g_strcmp0 (package_id, pk_update_detail_get_package_id (update_detail)) != 0)
+                               continue;
+                       gs_app_set_update_details (app, pk_update_detail_get_update_text (update_detail));
+                       break;
+               }
+               if (gs_app_get_update_details (app) == NULL) {
+                       /* TRANSLATORS: this is where update details either are
+                        * no longer available or were never provided in the first place */
+                       gs_app_set_update_details (app, _("No update details were provided"));
+               }
+       }
+out:
+       if (array != NULL)
+               g_ptr_array_unref (array);
+       if (results != NULL)
+               g_object_unref (results);
+       g_free (package_ids);
+       return ret;
+}
+
+/**
+ * gs_plugin_refine:
+ */
 gboolean
 gs_plugin_refine (GsPlugin *plugin,
                  GList *list,
@@ -301,6 +370,7 @@ gs_plugin_refine (GsPlugin *plugin,
        GsApp *app;
        const gchar *tmp;
        GList *resolve_all = NULL;
+       GList *updatedetails_all = NULL;
 
        /* can we resolve in one go? */
        for (l = list; l != NULL; l = l->next) {
@@ -316,7 +386,6 @@ gs_plugin_refine (GsPlugin *plugin,
                                                            resolve_all,
                                                            cancellable,
                                                            error);
-               g_list_free (resolve_all);
        }
 
        /* add any missing ratings data */
@@ -335,6 +404,26 @@ gs_plugin_refine (GsPlugin *plugin,
                if (!ret)
                        goto out;
        }
+
+       /* any update details missing? */
+       for (l = list; l != NULL; l = l->next) {
+               app = GS_APP (l->data);
+               if (gs_app_get_state (app) != GS_APP_STATE_UPDATABLE)
+                       continue;
+               if (gs_app_get_update_details (app) != NULL)
+                       continue;
+               if (gs_app_get_metadata_item (app, "PackageKit::package-id") == NULL)
+                       continue;
+               updatedetails_all = g_list_prepend (updatedetails_all, app);
+       }
+       if (updatedetails_all != NULL) {
+               ret = gs_plugin_packagekit_refine_updatedetails (plugin,
+                                                                updatedetails_all,
+                                                                cancellable,
+                                                                error);
+       }
 out:
+       g_list_free (resolve_all);
+       g_list_free (updatedetails_all);
        return ret;
 }
diff --git a/src/plugins/gs-plugin-packagekit.c b/src/plugins/gs-plugin-packagekit.c
index 62c6ef0..719478b 100644
--- a/src/plugins/gs-plugin-packagekit.c
+++ b/src/plugins/gs-plugin-packagekit.c
@@ -323,75 +323,6 @@ out:
 }
 
 /**
- * gs_plugin_packagekit_add_updates_results:
- */
-static gboolean
-gs_plugin_packagekit_add_updates_results (GsPlugin *plugin,
-                                         GList **list,
-                                         PkResults *results,
-                                         GError **error)
-{
-       gboolean ret = TRUE;
-       gchar *package_id;
-       gchar **split;
-       gchar *update_text;
-       GPtrArray *array = NULL;
-       GsApp *app;
-       guint i;
-       PkError *error_code = NULL;
-       PkUpdateDetail *update_detail;
-
-       /* check error code */
-       error_code = pk_results_get_error_code (results);
-       if (error_code != NULL) {
-               ret = FALSE;
-               g_set_error (error,
-                            GS_PLUGIN_ERROR,
-                            GS_PLUGIN_ERROR_FAILED,
-                            "failed to get-update-details: %s, %s",
-                            pk_error_enum_to_string (pk_error_get_code (error_code)),
-                            pk_error_get_details (error_code));
-               goto out;
-       }
-
-       /* get data */
-       array = pk_results_get_update_detail_array (results);
-       if (array->len == 0) {
-               ret = FALSE;
-               g_set_error_literal (error,
-                                    GS_PLUGIN_ERROR,
-                                    GS_PLUGIN_ERROR_FAILED,
-                                    "no update details were returned");
-               goto out;
-       }
-       for (i = 0; i < array->len; i++) {
-               update_detail = g_ptr_array_index (array, i);
-               g_object_get (update_detail,
-                             "package-id", &package_id,
-                             "update-text", &update_text,
-                             NULL);
-               split = pk_package_id_split (package_id);
-               app = gs_app_new (NULL);
-               gs_app_set_source (app, split[PK_PACKAGE_ID_NAME]);
-               gs_app_set_update_details (app, update_text);
-               gs_app_set_update_version (app, split[PK_PACKAGE_ID_VERSION]);
-               gs_app_set_management_plugin (app, "PackageKit");
-               gs_app_set_state (app, GS_APP_STATE_UPDATABLE);
-               gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
-               gs_plugin_add_app (list, app);
-               g_free (package_id);
-               g_free (update_text);
-               g_strfreev (split);
-       }
-out:
-       if (error_code != NULL)
-               g_object_unref (error_code);
-       if (array != NULL)
-               g_ptr_array_unref (array);
-       return ret;
-}
-
-/**
  * gs_plugin_add_updates:
  */
 gboolean
@@ -401,11 +332,12 @@ gs_plugin_add_updates (GsPlugin *plugin,
                       GError **error)
 {
        gboolean ret = TRUE;
-       gchar **package_ids = NULL;
+       GPtrArray *array = NULL;
+       GsApp *app;
+       guint i;
        PkBitfield filter;
-       PkPackageSack *sack = NULL;
+       PkPackage *pkg;
        PkResults *results = NULL;
-       PkResults *results2 = NULL;
 
        /* update UI as this might take some time */
        gs_plugin_status_update (plugin, NULL, GS_PLUGIN_STATUS_WAITING);
@@ -424,36 +356,23 @@ gs_plugin_add_updates (GsPlugin *plugin,
                goto out;
        }
 
-       /* get update details */
-       sack = pk_results_get_package_sack (results);
-       if (pk_package_sack_get_size (sack) == 0)
-               goto out;
-       package_ids = pk_package_sack_get_ids (sack);
-       results2 = pk_client_get_update_detail (PK_CLIENT (plugin->priv->task),
-                                               package_ids,
-                                               cancellable,
-                                               gs_plugin_packagekit_progress_cb, plugin,
-                                               error);
-       if (results2 == NULL) {
-               ret = FALSE;
-               goto out;
-       }
-
        /* add results */
-       ret = gs_plugin_packagekit_add_updates_results (plugin,
-                                                       list,
-                                                       results2,
-                                                       error);
-       if (!ret)
-               goto out;
+       array = pk_results_get_package_array (results);
+       for (i = 0; i < array->len; i++) {
+               pkg = g_ptr_array_index (array, i);
+               app = gs_app_new (NULL);
+               gs_app_set_source (app, pk_package_get_name (pkg));
+               gs_app_set_update_version (app, pk_package_get_version (pkg));
+               gs_app_set_management_plugin (app, "PackageKit");
+               gs_app_set_state (app, GS_APP_STATE_UPDATABLE);
+               gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
+               gs_plugin_add_app (list, app);
+       }
 out:
-       g_strfreev (package_ids);
-       if (sack != NULL)
-               g_object_unref (sack);
        if (results != NULL)
                g_object_unref (results);
-       if (results2 != NULL)
-               g_object_unref (results2);
+       if (array != NULL)
+               g_ptr_array_unref (array);
        return ret;
 }
 


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