[gnome-software/gnome-3-20] Return all update descriptions newer than the installed version
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/gnome-3-20] Return all update descriptions newer than the installed version
- Date: Mon, 25 Apr 2016 12:59:44 +0000 (UTC)
commit 8b9cdf994a535433ba5f25016e1bf9d4d49c609d
Author: Richard Hughes <richard hughsie com>
Date: Mon Apr 25 13:39:58 2016 +0100
Return all update descriptions newer than the installed version
src/plugins/gs-appstream.c | 101 +++++++++++++++++++++++++++++++++++++-------
1 files changed, 85 insertions(+), 16 deletions(-)
---
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index b8ccb84..5c04ae2 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -365,6 +365,89 @@ gs_refine_item_management_plugin (GsApp *app, AsApp *item)
}
/**
+ * gs_appstream_refine_app_updates:
+ */
+static gboolean
+gs_appstream_refine_app_updates (GsPlugin *plugin,
+ GsApp *app,
+ AsApp *item,
+ GError **error)
+{
+ AsRelease *rel;
+ AsUrgencyKind urgency_best = AS_URGENCY_KIND_UNKNOWN;
+ GPtrArray *releases;
+ guint i;
+ g_autoptr(GPtrArray) updates_list = NULL;
+
+ /* make a list of valid updates */
+ updates_list = g_ptr_array_new ();
+ releases = as_app_get_releases (item);
+ for (i = 0; i < releases->len; i++) {
+ rel = g_ptr_array_index (releases, i);
+
+ /* is newer than what's installed */
+ if (as_utils_vercmp (as_release_get_version (rel),
+ gs_app_get_version (app)) < 0)
+ continue;
+
+ /* use the 'worst' urgency, e.g. critical over enhancement */
+ if (as_release_get_urgency (rel) > urgency_best)
+ urgency_best = as_release_get_urgency (rel);
+
+ /* add updates with a description */
+ if (as_release_get_description (rel, NULL) == NULL)
+ continue;
+ g_ptr_array_add (updates_list, rel);
+ }
+
+ /* only set if known */
+ if (urgency_best != AS_URGENCY_KIND_UNKNOWN)
+ gs_app_set_update_urgency (app, urgency_best);
+
+ /* no prefix on each release */
+ if (updates_list->len == 1) {
+ g_autofree gchar *desc = NULL;
+ rel = g_ptr_array_index (updates_list, 0);
+ desc = as_markup_convert (as_release_get_description (rel, NULL),
+ AS_MARKUP_CONVERT_FORMAT_SIMPLE,
+ error);
+ if (desc == NULL)
+ return FALSE;
+ gs_app_set_update_details (app, desc);
+
+ /* get the descriptions with a version prefix */
+ } else if (updates_list->len > 1) {
+ g_autoptr(GString) update_desc = g_string_new ("");
+ for (i = 0; i < updates_list->len; i++) {
+ g_autofree gchar *desc = NULL;
+ rel = g_ptr_array_index (updates_list, i);
+ desc = as_markup_convert (as_release_get_description (rel, NULL),
+ AS_MARKUP_CONVERT_FORMAT_SIMPLE,
+ error);
+ if (desc == NULL)
+ return FALSE;
+ g_string_append_printf (update_desc,
+ "<b>Version %s:</b>\n%s\n\n",
+ as_release_get_version (rel),
+ desc);
+ }
+
+ /* remove trailing newlines */
+ if (update_desc->len > 2)
+ g_string_truncate (update_desc, update_desc->len - 2);
+ gs_app_set_update_details (app, update_desc->str);
+ }
+
+ /* newest release only */
+ rel = as_app_get_release_default (item);
+ if (rel != NULL)
+ gs_app_set_update_version (app, as_release_get_version (rel));
+
+ /* success */
+ return TRUE;
+}
+
+/**
* gs_appstream_refine_app:
*/
gboolean
@@ -373,7 +456,6 @@ gs_appstream_refine_app (GsPlugin *plugin,
AsApp *item,
GError **error)
{
- AsRelease *rel;
GHashTable *urls;
GPtrArray *pkgnames;
GPtrArray *kudos;
@@ -554,21 +636,8 @@ gs_appstream_refine_app (GsPlugin *plugin,
}
/* is there any update information */
- rel = as_app_get_release_default (item);
- if (rel != NULL) {
- tmp = as_release_get_description (rel, NULL);
- if (tmp != NULL) {
- g_autofree gchar *desc = NULL;
- desc = as_markup_convert (tmp,
- AS_MARKUP_CONVERT_FORMAT_SIMPLE,
- error);
- if (desc == NULL)
- return FALSE;
- gs_app_set_update_details (app, desc);
- }
- gs_app_set_update_urgency (app, as_release_get_urgency (rel));
- gs_app_set_update_version (app, as_release_get_version (rel));
- }
+ if (!gs_appstream_refine_app_updates (plugin, app, item, error))
+ return FALSE;
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]