[gnome-software/155-allow-some-markup-in-release-notes-in-appdata: 57/60] GsApp: Store update-details as markup
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/155-allow-some-markup-in-release-notes-in-appdata: 57/60] GsApp: Store update-details as markup
- Date: Tue, 16 Nov 2021 16:43:43 +0000 (UTC)
commit f21fc3e0d83a41c71db2e9567c1205d4b27c160f
Author: Milan Crha <mcrha redhat com>
Date: Tue Nov 16 17:33:35 2021 +0100
GsApp: Store update-details as markup
Add related API to make is clear what the update details format is.
lib/gs-app.c | 62 +++++++++++++++++++++++--------
lib/gs-app.h | 10 +++--
lib/gs-appstream.c | 4 +-
plugins/dummy/gs-plugin-dummy.c | 8 ++--
plugins/dummy/gs-self-test.c | 2 +-
plugins/flatpak/gs-flatpak-transaction.c | 2 +-
plugins/flatpak/gs-flatpak.c | 2 +-
plugins/flatpak/gs-self-test.c | 10 ++---
plugins/fwupd/gs-fwupd-app.c | 2 +-
plugins/fwupd/gs-plugin-fwupd.c | 4 +-
plugins/fwupd/gs-self-test.c | 2 +-
plugins/packagekit/gs-plugin-packagekit.c | 4 +-
src/gs-app-details-page.c | 2 +-
src/gs-app-row.c | 2 +-
14 files changed, 76 insertions(+), 40 deletions(-)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 512aa2cf9..be346de83 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -91,7 +91,7 @@ typedef struct
gchar *origin_hostname;
gchar *update_version;
gchar *update_version_ui;
- gchar *update_details;
+ gchar *update_details_markup;
AsUrgencyKind update_urgency;
GsAppPermissions update_permissions;
gchar *management_plugin;
@@ -573,8 +573,8 @@ gs_app_to_string_append (GsApp *app, GString *str)
gs_app_kv_lpad (str, "update-version", priv->update_version);
if (priv->update_version_ui != NULL)
gs_app_kv_lpad (str, "update-version-ui", priv->update_version_ui);
- if (priv->update_details != NULL)
- gs_app_kv_lpad (str, "update-details", priv->update_details);
+ if (priv->update_details_markup != NULL)
+ gs_app_kv_lpad (str, "update-details-markup", priv->update_details_markup);
if (priv->update_urgency != AS_URGENCY_KIND_UNKNOWN) {
gs_app_kv_printf (str, "update-urgency", "%u",
priv->update_urgency);
@@ -3101,40 +3101,72 @@ gs_app_set_update_version (GsApp *app, const gchar *update_version)
}
/**
- * gs_app_get_update_details:
+ * gs_app_get_update_details_markup:
* @app: a #GsApp
*
- * Gets the multi-line description for the update.
+ * Gets the multi-line description for the update as a Pango markup.
*
* Returns: a string, or %NULL for unset
*
- * Since: 3.22
+ * Since: 42.0
**/
const gchar *
-gs_app_get_update_details (GsApp *app)
+gs_app_get_update_details_markup (GsApp *app)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
g_return_val_if_fail (GS_IS_APP (app), NULL);
- return priv->update_details;
+ return priv->update_details_markup;
}
/**
- * gs_app_set_update_details:
+ * gs_app_set_update_details_markup:
* @app: a #GsApp
- * @update_details: a string
+ * @markup: a Pango markup
*
- * Sets the multi-line description for the update.
+ * Sets the multi-line description for the update as markup.
*
- * Since: 3.22
+ * See: gs_app_set_update_details_text()
+ *
+ * Since: 42.0
**/
void
-gs_app_set_update_details (GsApp *app, const gchar *update_details)
+gs_app_set_update_details_markup (GsApp *app,
+ const gchar *markup)
{
GsAppPrivate *priv = gs_app_get_instance_private (app);
g_autoptr(GMutexLocker) locker = NULL;
g_return_if_fail (GS_IS_APP (app));
locker = g_mutex_locker_new (&priv->mutex);
- _g_set_str (&priv->update_details, update_details);
+ _g_set_str (&priv->update_details_markup, markup);
+}
+
+/**
+ * gs_app_set_update_details_text:
+ * @app: a #GsApp
+ * @text: a text without Pango markup
+ *
+ * Sets the multi-line description for the update as text,
+ * escaping the @text to be safe for a Pango markup.
+ *
+ * See: gs_app_set_update_details_markup()
+ *
+ * Since: 42.0
+ **/
+void
+gs_app_set_update_details_text (GsApp *app,
+ const gchar *text)
+{
+ GsAppPrivate *priv = gs_app_get_instance_private (app);
+ g_autoptr(GMutexLocker) locker = NULL;
+ g_return_if_fail (GS_IS_APP (app));
+ locker = g_mutex_locker_new (&priv->mutex);
+ if (text == NULL) {
+ _g_set_str (&priv->update_details_markup, NULL);
+ } else {
+ gchar *markup = g_markup_escape_text (text, -1);
+ g_free (priv->update_details_markup);
+ priv->update_details_markup = markup;
+ }
}
/**
@@ -5097,7 +5129,7 @@ gs_app_finalize (GObject *object)
g_free (priv->description);
g_free (priv->update_version);
g_free (priv->update_version_ui);
- g_free (priv->update_details);
+ g_free (priv->update_details_markup);
g_free (priv->management_plugin);
g_hash_table_unref (priv->metadata);
g_ptr_array_unref (priv->categories);
diff --git a/lib/gs-app.h b/lib/gs-app.h
index ac5c82529..8936e287f 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -351,9 +351,13 @@ const gchar *gs_app_get_update_version (GsApp *app);
const gchar *gs_app_get_update_version_ui (GsApp *app);
void gs_app_set_update_version (GsApp *app,
const gchar *update_version);
-const gchar *gs_app_get_update_details (GsApp *app);
-void gs_app_set_update_details (GsApp *app,
- const gchar *update_details);
+const gchar *gs_app_get_update_details_markup
+ (GsApp *app);
+void gs_app_set_update_details_markup
+ (GsApp *app,
+ const gchar *markup);
+void gs_app_set_update_details_text (GsApp *app,
+ const gchar *text);
AsUrgencyKind gs_app_get_update_urgency (GsApp *app);
void gs_app_set_update_urgency (GsApp *app,
AsUrgencyKind update_urgency);
diff --git a/lib/gs-appstream.c b/lib/gs-appstream.c
index 0ec332ab4..357df2fcf 100644
--- a/lib/gs-appstream.c
+++ b/lib/gs-appstream.c
@@ -591,7 +591,7 @@ gs_appstream_refine_app_updates (GsApp *app,
g_autofree gchar *desc = NULL;
n = xb_node_query_first (release, "description", NULL);
desc = gs_appstream_format_description (n, NULL);
- gs_app_set_update_details (app, desc);
+ gs_app_set_update_details_markup (app, desc);
/* get the descriptions with a version prefix */
} else if (updates_list->len > 1) {
@@ -619,7 +619,7 @@ gs_appstream_refine_app_updates (GsApp *app,
if (update_desc->len > 2)
g_string_truncate (update_desc, update_desc->len - 2);
if (update_desc->len > 0)
- gs_app_set_update_details (app, update_desc->str);
+ gs_app_set_update_details_markup (app, update_desc->str);
}
/* if there is no already set update version use the newest */
diff --git a/plugins/dummy/gs-plugin-dummy.c b/plugins/dummy/gs-plugin-dummy.c
index d6febfeff..f2f71f6bd 100644
--- a/plugins/dummy/gs-plugin-dummy.c
+++ b/plugins/dummy/gs-plugin-dummy.c
@@ -367,7 +367,7 @@ gs_plugin_add_updates (GsPlugin *plugin,
app = gs_app_new ("chiron.desktop");
gs_app_set_name (app, GS_APP_QUALITY_NORMAL, "Chiron");
gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "A teaching application");
- gs_app_set_update_details (app, "Do not crash when using libvirt.");
+ gs_app_set_update_details_text (app, "Do not crash when using libvirt.");
gs_app_set_update_urgency (app, AS_URGENCY_KIND_HIGH);
gs_app_add_icon (app, ic);
gs_app_set_kind (app, AS_COMPONENT_KIND_DESKTOP_APP);
@@ -380,7 +380,7 @@ gs_plugin_add_updates (GsPlugin *plugin,
app = gs_app_new (NULL);
gs_app_set_name (app, GS_APP_QUALITY_NORMAL, "libvirt-glib-devel");
gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "Development files for libvirt");
- gs_app_set_update_details (app, "Fix several memory leaks.");
+ gs_app_set_update_details_text (app, "Fix several memory leaks.");
gs_app_set_update_urgency (app, AS_URGENCY_KIND_LOW);
gs_app_set_kind (app, AS_COMPONENT_KIND_GENERIC);
gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_PACKAGE);
@@ -396,7 +396,7 @@ gs_plugin_add_updates (GsPlugin *plugin,
app = gs_app_new (NULL);
gs_app_set_name (app, GS_APP_QUALITY_NORMAL, "chiron-libs");
gs_app_set_summary (app, GS_APP_QUALITY_NORMAL, "library for chiron");
- gs_app_set_update_details (app, "Do not crash when using libvirt.");
+ gs_app_set_update_details_text (app, "Do not crash when using libvirt.");
gs_app_set_update_urgency (app, AS_URGENCY_KIND_HIGH);
gs_app_set_kind (app, AS_COMPONENT_KIND_GENERIC);
gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_PACKAGE);
@@ -412,7 +412,7 @@ gs_plugin_add_updates (GsPlugin *plugin,
proxy = gs_app_new ("proxy.desktop");
gs_app_set_name (proxy, GS_APP_QUALITY_NORMAL, "Proxy");
gs_app_set_summary (proxy, GS_APP_QUALITY_NORMAL, "A proxy app");
- gs_app_set_update_details (proxy, "Update all related apps.");
+ gs_app_set_update_details_text (proxy, "Update all related apps.");
gs_app_set_update_urgency (proxy, AS_URGENCY_KIND_HIGH);
gs_app_add_icon (proxy, ic);
gs_app_set_kind (proxy, AS_COMPONENT_KIND_DESKTOP_APP);
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index 92d054f1e..f1fd4f22b 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -270,7 +270,7 @@ gs_plugins_dummy_updates_func (GsPluginLoader *plugin_loader)
g_assert_cmpstr (gs_app_get_id (app), ==, "chiron.desktop");
g_assert_cmpint (gs_app_get_kind (app), ==, AS_COMPONENT_KIND_DESKTOP_APP);
g_assert_cmpint (gs_app_get_state (app), ==, GS_APP_STATE_UPDATABLE_LIVE);
- g_assert_cmpstr (gs_app_get_update_details (app), ==, "Do not crash when using libvirt.");
+ g_assert_cmpstr (gs_app_get_update_details_markup (app), ==, "Do not crash when using libvirt.");
g_assert_cmpint (gs_app_get_update_urgency (app), ==, AS_URGENCY_KIND_HIGH);
/* get the virtual non-apps OS update */
diff --git a/plugins/flatpak/gs-flatpak-transaction.c b/plugins/flatpak/gs-flatpak-transaction.c
index 08baef74b..cbad44170 100644
--- a/plugins/flatpak/gs-flatpak-transaction.c
+++ b/plugins/flatpak/gs-flatpak-transaction.c
@@ -630,7 +630,7 @@ _transaction_operation_done (FlatpakTransaction *transaction,
break;
case FLATPAK_TRANSACTION_OPERATION_UPDATE:
gs_app_set_version (app, gs_app_get_update_version (app));
- gs_app_set_update_details (app, NULL);
+ gs_app_set_update_details_markup (app, NULL);
gs_app_set_update_urgency (app, AS_URGENCY_KIND_UNKNOWN);
gs_app_set_update_version (app, NULL);
/* force getting the new runtime */
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index cafe1f549..4523430dc 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -1816,7 +1816,7 @@ gs_flatpak_add_updates (GsFlatpak *self, GsAppList *list,
g_debug ("%s has a downloaded update %s->%s",
flatpak_ref_get_name (FLATPAK_REF (xref)),
commit, latest_commit);
- gs_app_set_update_details (main_app, NULL);
+ gs_app_set_update_details_markup (main_app, NULL);
gs_app_set_update_version (main_app, NULL);
gs_app_set_update_urgency (main_app, AS_URGENCY_KIND_UNKNOWN);
gs_app_set_size_download (main_app, 0);
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index 13e2bb7b4..0c7e5031f 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -386,7 +386,7 @@ gs_plugins_flatpak_app_with_runtime_func (GsPluginLoader *plugin_loader)
g_assert_cmpstr (gs_app_get_origin_hostname (app), ==, "localhost");
g_assert_cmpstr (gs_app_get_version (app), ==, "1.2.3");
g_assert_cmpstr (gs_app_get_update_version (app), ==, NULL);
- g_assert_cmpstr (gs_app_get_update_details (app), ==, NULL);
+ g_assert_cmpstr (gs_app_get_update_details_markup (app), ==, NULL);
g_assert_cmpint (gs_app_get_update_urgency (app), ==, AS_URGENCY_KIND_UNKNOWN);
/* check runtime */
@@ -1233,7 +1233,7 @@ flatpak_bundle_or_ref_helper (GsPluginLoader *plugin_loader,
g_assert_cmpint (gs_app_get_state (app), ==, GS_APP_STATE_INSTALLED);
g_assert_cmpstr (gs_app_get_version (app), ==, "1.2.3");
g_assert_cmpstr (gs_app_get_update_version (app), ==, NULL);
- g_assert_cmpstr (gs_app_get_update_details (app), ==, NULL);
+ g_assert_cmpstr (gs_app_get_update_details_markup (app), ==, NULL);
/* search for the application */
g_object_unref (plugin_job);
@@ -1468,7 +1468,7 @@ gs_plugins_flatpak_app_update_func (GsPluginLoader *plugin_loader)
g_assert_cmpint (gs_app_get_state (app), ==, GS_APP_STATE_INSTALLED);
g_assert_cmpstr (gs_app_get_version (app), ==, "1.2.3");
g_assert_cmpstr (gs_app_get_update_version (app), ==, NULL);
- g_assert_cmpstr (gs_app_get_update_details (app), ==, NULL);
+ g_assert_cmpstr (gs_app_get_update_details_markup (app), ==, NULL);
/* switch to the new repo */
g_assert_true (unlink (repo_path) == 0);
@@ -1511,7 +1511,7 @@ gs_plugins_flatpak_app_update_func (GsPluginLoader *plugin_loader)
app = gs_app_list_lookup (list_updates, "*/flatpak/test/org.test.Chiron/*");
g_assert_nonnull (app);
g_assert_cmpint (gs_app_get_state (app), ==, GS_APP_STATE_UPDATABLE_LIVE);
- g_assert_cmpstr (gs_app_get_update_details (app), ==, "Version 1.2.4:\nThis is best.");
+ g_assert_cmpstr (gs_app_get_update_details_markup (app), ==, "Version 1.2.4:\nThis is best.");
g_assert_cmpstr (gs_app_get_update_version (app), ==, "1.2.4");
/* care about signals */
@@ -1546,7 +1546,7 @@ gs_plugins_flatpak_app_update_func (GsPluginLoader *plugin_loader)
g_assert_cmpint (gs_app_get_state (app), ==, GS_APP_STATE_INSTALLED);
g_assert_cmpstr (gs_app_get_version (app), ==, "1.2.4");
g_assert_cmpstr (gs_app_get_update_version (app), ==, NULL);
- g_assert_cmpstr (gs_app_get_update_details (app), ==, NULL);
+ g_assert_cmpstr (gs_app_get_update_details_markup (app), ==, NULL);
g_assert_true (gs_app_get_progress (app) == GS_APP_PROGRESS_UNKNOWN ||
gs_app_get_progress (app) == 100);
g_assert_true (got_progress_installing);
diff --git a/plugins/fwupd/gs-fwupd-app.c b/plugins/fwupd/gs-fwupd-app.c
index 122e11354..fee07ab07 100644
--- a/plugins/fwupd/gs-fwupd-app.c
+++ b/plugins/fwupd/gs-fwupd-app.c
@@ -269,7 +269,7 @@ gs_fwupd_app_set_from_release (GsApp *app, FwupdRelease *rel)
g_autofree gchar *tmp = NULL;
tmp = as_markup_convert_simple (fwupd_release_get_description (rel), NULL);
if (tmp != NULL)
- gs_app_set_update_details (app, tmp);
+ gs_app_set_update_details_text (app, tmp);
}
#if FWUPD_CHECK_VERSION(1,3,3)
if (fwupd_release_get_detach_image (rel) != NULL) {
diff --git a/plugins/fwupd/gs-plugin-fwupd.c b/plugins/fwupd/gs-plugin-fwupd.c
index f467e9339..237524216 100644
--- a/plugins/fwupd/gs-plugin-fwupd.c
+++ b/plugins/fwupd/gs-plugin-fwupd.c
@@ -640,7 +640,7 @@ gs_plugin_add_updates (GsPlugin *plugin,
}
if (update_desc->len > 2) {
g_string_truncate (update_desc, update_desc->len - 2);
- gs_app_set_update_details (app, update_desc->str);
+ gs_app_set_update_details_text (app, update_desc->str);
}
}
gs_app_list_add (list, app);
@@ -1137,7 +1137,7 @@ gs_plugin_file_to_app (GsPlugin *plugin,
/* we *might* have no update view for local files */
gs_app_set_version (app, gs_app_get_update_version (app));
gs_app_set_description (app, GS_APP_QUALITY_LOWEST,
- gs_app_get_update_details (app));
+ gs_app_get_update_details_markup (app));
gs_app_list_add (list, app);
}
return TRUE;
diff --git a/plugins/fwupd/gs-self-test.c b/plugins/fwupd/gs-self-test.c
index f5f222b6c..bf24fd23d 100644
--- a/plugins/fwupd/gs-self-test.c
+++ b/plugins/fwupd/gs-self-test.c
@@ -50,7 +50,7 @@ gs_plugins_fwupd_func (GsPluginLoader *plugin_loader)
g_assert_cmpstr (gs_app_get_description (app), ==,
"This is the first paragraph in the example "
"cab file.\n\nThis is the second paragraph.");
- g_assert_cmpstr (gs_app_get_update_details (app), ==,
+ g_assert_cmpstr (gs_app_get_update_details_markup (app), ==,
"Latest firmware release.");
/* seems wrong, but this is only set if the update is available */
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index 71c8307ed..f03ecec8b 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -1105,7 +1105,7 @@ gs_plugin_packagekit_refine_updatedetails (GsPluginPackagekit *self,
tmp = pk_update_detail_get_update_text (update_detail);
desc = gs_plugin_packagekit_fixup_update_description (tmp);
if (desc != NULL)
- gs_app_set_update_details (app, desc);
+ gs_app_set_update_details_markup (app, desc);
break;
}
}
@@ -1335,7 +1335,7 @@ static gboolean
gs_plugin_refine_requires_update_details (GsApp *app, GsPluginRefineFlags flags)
{
const gchar *tmp;
- tmp = gs_app_get_update_details (app);
+ tmp = gs_app_get_update_details_markup (app);
if (tmp != NULL)
return FALSE;
return (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_UPDATE_DETAILS) > 0;
diff --git a/src/gs-app-details-page.c b/src/gs-app-details-page.c
index b2470eded..74421eaa5 100644
--- a/src/gs-app-details-page.c
+++ b/src/gs-app-details-page.c
@@ -151,7 +151,7 @@ set_updates_description_ui (GsAppDetailsPage *page, GsApp *app)
g_object_notify_by_pspec (G_OBJECT (page), obj_props[PROP_TITLE]);
/* set update header */
- update_details = gs_app_get_update_details (app);
+ update_details = gs_app_get_update_details_markup (app);
if (update_details == NULL) {
/* TRANSLATORS: this is where the packager did not write
* a description for the update */
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index 7fb2b5525..03abfdd7a 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -86,7 +86,7 @@ gs_app_row_get_description (GsAppRow *app_row)
/* convert the markdown update description into PangoMarkup */
if (priv->show_update) {
- tmp = gs_app_get_update_details (priv->app);
+ tmp = gs_app_get_update_details_markup (priv->app);
if (tmp != NULL && tmp[0] != '\0')
return g_string_new (tmp);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]