[gnome-software/wip/mak/libas] Convert from 6-part data-ids to 5-part IDs in public API
- From: Matthias Klumpp <mak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/mak/libas] Convert from 6-part data-ids to 5-part IDs in public API
- Date: Thu, 28 Jan 2021 18:52:31 +0000 (UTC)
commit 4bef7e9afd4e8e2ef197629660804d705d25093b
Author: Matthias Klumpp <matthias tenstral net>
Date: Thu Jan 28 19:52:18 2021 +0100
Convert from 6-part data-ids to 5-part IDs in public API
lib/gs-utils.c | 34 ++++++++++++++++++++++++++++++++++
lib/gs-utils.h | 2 ++
src/gs-application.c | 14 +++++++++-----
3 files changed, 45 insertions(+), 5 deletions(-)
---
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index 4c2e2616..ab4dae0f 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -1223,6 +1223,40 @@ gs_utils_set_online_updates_timestamp (GSettings *settings)
g_settings_set (settings, "update-notification-timestamp", "x", g_date_time_to_unix (now));
}
+/**
+ * gs_utils_unique_id_compat_convert:
+ * @data_id: A string that may be a unique component ID
+ *
+ * Converts the unique ID string from its legacy 6-part form into
+ * a new-style 5-part AppStream data-id.
+ * Does nothing if the string is already valid.
+ *
+ * Returns: A newly allocated string with the new-style data-id, or %NULL if input was no valid ID.
+ *
+ * Since: 3.30
+ **/
+gchar*
+gs_utils_unique_id_compat_convert (const gchar *data_id)
+{
+ g_auto(GStrv) parts = NULL;
+ if (data_id == NULL)
+ return NULL;
+
+ /* check for the most common case first: data-id is already valid */
+ if (as_utils_data_id_valid (data_id))
+ return g_strdup (data_id);
+
+ parts = g_strsplit (data_id, "/", -1);
+ if (g_strv_length (parts) != 6)
+ return NULL;
+ return g_strdup_printf ("%s/%s/%s/%s/%s",
+ parts[0],
+ parts[1],
+ parts[2],
+ parts[4],
+ parts[5]);
+}
+
static void
gs_pixbuf_blur_private (GdkPixbuf *src, GdkPixbuf *dest, guint radius, guint8 *div_kernel_size)
{
diff --git a/lib/gs-utils.h b/lib/gs-utils.h
index c1f50143..06671563 100644
--- a/lib/gs-utils.h
+++ b/lib/gs-utils.h
@@ -93,6 +93,8 @@ gboolean gs_utils_parse_evr (const gchar *evr,
gchar **out_release);
void gs_utils_set_online_updates_timestamp (GSettings *settings);
+gchar *gs_utils_unique_id_compat_convert (const gchar *data_id);
+
void gs_utils_pixbuf_blur (GdkPixbuf *src,
guint radius,
guint iterations);
diff --git a/src/gs-application.c b/src/gs-application.c
index 5f95185c..48f0c6aa 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -594,9 +594,11 @@ details_activated (GSimpleAction *action,
gs_shell_reset_state (app->shell);
gs_shell_show_search_result (app->shell, id, search);
} else {
+ g_autofree gchar *data_id = NULL;
g_autoptr(GsPluginJob) plugin_job = NULL;
- if (as_utils_data_id_valid (id)) {
- g_autoptr(GsApp) a = gs_plugin_loader_app_create (app->plugin_loader, id);
+ data_id = gs_utils_unique_id_compat_convert (id);
+ if (data_id != NULL) {
+ g_autoptr(GsApp) a = gs_plugin_loader_app_create (app->plugin_loader, data_id);
gs_shell_reset_state (app->shell);
gs_shell_show_app (app->shell, a);
return;
@@ -667,9 +669,11 @@ install_activated (GSimpleAction *action,
const gchar *id;
GsShellInteraction interaction;
g_autoptr (GsApp) a = NULL;
+ g_autofree gchar *data_id = NULL;
g_variant_get (parameter, "(&su)", &id, &interaction);
- if (!as_utils_data_id_valid (id)) {
+ data_id = gs_utils_unique_id_compat_convert (id);
+ if (data_id == NULL) {
g_warning ("Need to use a valid unique-id: %s", id);
return;
}
@@ -677,9 +681,9 @@ install_activated (GSimpleAction *action,
if (interaction == GS_SHELL_INTERACTION_FULL)
gs_application_present_window (app, NULL);
- a = gs_plugin_loader_app_create (app->plugin_loader, id);
+ a = gs_plugin_loader_app_create (app->plugin_loader, data_id);
if (a == NULL) {
- g_warning ("Could not create app from unique-id: %s", id);
+ g_warning ("Could not create app from data-id: %s", data_id);
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]