[gnome-software] When getting the size for the package, get the size of *all* of the sources
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] When getting the size for the package, get the size of *all* of the sources
- Date: Wed, 23 Oct 2013 14:49:13 +0000 (UTC)
commit 25e5b6b60a67ae8dcedc70b5faf509957ae08f51
Author: Richard Hughes <richard hughsie com>
Date: Wed Oct 23 15:18:48 2013 +0100
When getting the size for the package, get the size of *all* of the sources
src/gs-app.c | 4 +
src/plugins/gs-plugin-packagekit-refine.c | 98 ++++++++++++++++++-----------
2 files changed, 66 insertions(+), 36 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index faa2655..b8e5641 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -264,6 +264,10 @@ gs_app_to_string (GsApp *app)
g_string_append_printf (str, "\tfeatured-pixbuf:\t%p\n", priv->featured_pixbuf);
if (priv->install_date != 0)
g_string_append_printf (str, "\tinstall-date:\t%lu\n", priv->install_date);
+ if (priv->size != 0) {
+ g_string_append_printf (str, "\tsize:\t%" G_GUINT64_FORMAT "k\n",
+ priv->size / 1024);
+ }
if (priv->related->len > 0)
g_string_append_printf (str, "\trelated:\t%i\n", priv->related->len);
if (priv->history->len > 0)
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index b08d8cb..0a2490d 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -420,6 +420,55 @@ gs_pk_compare_ids (const gchar *package_id1, const gchar *package_id2)
}
/**
+ * gs_plugin_packagekit_refine_details_app:
+ */
+static void
+gs_plugin_packagekit_refine_details_app (GsPlugin *plugin,
+ GPtrArray *array,
+ GsApp *app)
+{
+ GPtrArray *source_ids;
+ PkDetails *details;
+ const gchar *package_id;
+ gchar *desc;
+ guint i;
+ guint j;
+ guint64 size = 0;
+
+ source_ids = gs_app_get_source_ids (app);
+ for (j = 0; j < source_ids->len; j++) {
+ package_id = g_ptr_array_index (source_ids, j);
+ for (i = 0; i < array->len; i++) {
+ /* right package? */
+ details = g_ptr_array_index (array, i);
+ if (!gs_pk_compare_ids (package_id,
+ pk_details_get_package_id (details)) != 0) {
+ continue;
+ }
+ if (gs_app_get_licence (app) == NULL)
+ gs_app_set_licence (app, pk_details_get_license (details));
+ if (gs_app_get_url (app, GS_APP_URL_KIND_HOMEPAGE) == NULL) {
+ gs_app_set_url (app,
+ GS_APP_URL_KIND_HOMEPAGE,
+ pk_details_get_url (details));
+ }
+ size += pk_details_get_size (details);
+ if (gs_app_get_description (app) == NULL &&
+ g_getenv ("GNOME_SOFTWARE_USE_PKG_DESCRIPTIONS") != NULL) {
+ desc = gs_pk_format_desc (pk_details_get_description (details));
+ gs_app_set_description (app, desc);
+ g_free (desc);
+ }
+ break;
+ }
+ }
+
+ /* the size is the size of all sources */
+ if (size > 0 && gs_app_get_size (app) == 0)
+ gs_app_set_size (app, size);
+}
+
+/**
* gs_plugin_packagekit_refine_details:
*/
static gboolean
@@ -430,27 +479,28 @@ gs_plugin_packagekit_refine_details (GsPlugin *plugin,
{
GList *l;
GPtrArray *array = NULL;
+ GPtrArray *package_ids;
+ GPtrArray *source_ids;
GsApp *app;
- PkDetails *details;
PkResults *results = NULL;
- const gchar **package_ids;
const gchar *package_id;
gboolean ret = TRUE;
- gchar *desc;
- guint i = 0;
- guint size;
+ guint i;
- size = g_list_length (list);
- package_ids = g_new0 (const gchar *, size + 1);
+ package_ids = g_ptr_array_new_with_free_func (g_free);
for (l = list; l != NULL; l = l->next) {
app = GS_APP (l->data);
- package_id = gs_app_get_source_id_default (app);
- package_ids[i++] = package_id;
+ source_ids = gs_app_get_source_ids (app);
+ for (i = 0; i < source_ids->len; i++) {
+ package_id = g_ptr_array_index (source_ids, i);
+ g_ptr_array_add (package_ids, g_strdup (package_id));
+ }
}
+ g_ptr_array_add (package_ids, NULL);
/* get any details */
results = pk_client_get_details (plugin->priv->client,
- (gchar **) package_ids,
+ (gchar **) package_ids->pdata,
cancellable,
gs_plugin_packagekit_progress_cb, plugin,
error);
@@ -463,38 +513,14 @@ gs_plugin_packagekit_refine_details (GsPlugin *plugin,
array = pk_results_get_details_array (results);
for (l = list; l != NULL; l = l->next) {
app = GS_APP (l->data);
- package_id = gs_app_get_source_id_default (app);
- for (i = 0; i < array->len; i++) {
- /* right package? */
- details = g_ptr_array_index (array, i);
- if (!gs_pk_compare_ids (package_id,
- pk_details_get_package_id (details)) != 0) {
- continue;
- }
- if (gs_app_get_licence (app) == NULL)
- gs_app_set_licence (app, pk_details_get_license (details));
- if (gs_app_get_url (app, GS_APP_URL_KIND_HOMEPAGE) == NULL) {
- gs_app_set_url (app,
- GS_APP_URL_KIND_HOMEPAGE,
- pk_details_get_url (details));
- }
- if (gs_app_get_size (app) == 0)
- gs_app_set_size (app, pk_details_get_size (details));
- if (gs_app_get_description (app) == NULL &&
- g_getenv ("GNOME_SOFTWARE_USE_PKG_DESCRIPTIONS") != NULL) {
- desc = gs_pk_format_desc (pk_details_get_description (details));
- gs_app_set_description (app, desc);
- g_free (desc);
- }
- break;
- }
+ gs_plugin_packagekit_refine_details_app (plugin, array, app);
}
out:
if (array != NULL)
g_ptr_array_unref (array);
if (results != NULL)
g_object_unref (results);
- g_free (package_ids);
+ g_ptr_array_unref (package_ids);
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]