[gnome-software] Move the SPDX linkifying code to GsApp
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Move the SPDX linkifying code to GsApp
- Date: Thu, 12 Mar 2015 11:45:29 +0000 (UTC)
commit 1306b028c8609c9effdf855b97a5e60be838b893
Author: Richard Hughes <richard hughsie com>
Date: Thu Mar 12 10:44:57 2015 +0000
Move the SPDX linkifying code to GsApp
We need this for future fwupd functionality.
po/POTFILES.in | 1 +
src/gs-app.c | 57 ++++++++++++++++++++++++++++++++-
src/plugins/gs-plugin-appstream.c | 63 +------------------------------------
3 files changed, 58 insertions(+), 63 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c577497..6cbfdc7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -7,6 +7,7 @@ src/gnome-software-local-file.desktop.in
src/gs-app-folder-dialog.c
src/gs-application.c
src/gs-app-addon-row.c
+src/gs-app.c
src/gs-app-row.c
src/gs-app-tile.c
src/gs-category.c
diff --git a/src/gs-app.c b/src/gs-app.c
index 30f739e..1271def 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -45,6 +45,7 @@
#include <string.h>
#include <gtk/gtk.h>
+#include <glib/gi18n.h>
#include "gs-app.h"
#include "gs-cleanup.h"
@@ -1225,9 +1226,63 @@ gs_app_get_licence (GsApp *app)
void
gs_app_set_licence (GsApp *app, const gchar *licence)
{
+ GString *urld;
+ guint i;
+ _cleanup_strv_free_ gchar **tokens = NULL;
+
g_return_if_fail (GS_IS_APP (app));
+
+ /* tokenize the license string and URLify any SPDX IDs */
+ urld = g_string_sized_new (strlen (licence) + 1);
+ tokens = as_utils_spdx_license_tokenize (licence);
+ for (i = 0; tokens[i] != NULL; i++) {
+
+ /* translated join */
+ if (g_strcmp0 (tokens[i], "&") == 0) {
+ /* TRANSLATORS: This is how we join the licences and can
+ * be considered a "Conjunctive AND Operator" according
+ * to the SPDX specification. For example:
+ * "LGPL-2.1 and MIT and BSD-2-Clause" */
+ g_string_append (urld, _(" and "));
+ continue;
+ }
+ if (g_strcmp0 (tokens[i], "|") == 0) {
+ /* TRANSLATORS: This is how we join the licences and can
+ * be considered a "Disjunctive OR Operator" according
+ * to the SPDX specification. For example:
+ * "LGPL-2.1 or MIT" */
+ g_string_append (urld, _(" or "));
+ continue;
+ }
+
+ /* legacy literal text */
+ if (g_str_has_prefix (tokens[i], "#")) {
+ g_string_append (urld, tokens[i] + 1);
+ continue;
+ }
+
+ /* SPDX value */
+ if (g_str_has_prefix (tokens[i], "@")) {
+ g_string_append_printf (urld,
+ "<a href=\"http://spdx.org/licenses/%s\">%s</a>",
+ tokens[i] + 1, tokens[i] + 1);
+ continue;
+ }
+
+ /* new SPDX value the extractor didn't know about */
+ if (as_utils_is_spdx_license_id (tokens[i])) {
+ g_string_append_printf (urld,
+ "<a href=\"http://spdx.org/licenses/%s\">%s</a>",
+ tokens[i], tokens[i]);
+ continue;
+ }
+
+ /* unknown value */
+ g_string_append (urld, tokens[i]);
+ }
+
g_free (app->priv->licence);
- app->priv->licence = g_strdup (licence);
+ app->priv->licence = g_string_free (urld, FALSE);
}
/**
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 547d13a..39c842c 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -387,67 +387,6 @@ gs_plugin_refine_add_screenshots (GsApp *app, AsApp *item)
}
/**
- * gs_plugin_appstream_set_license:
- */
-static void
-gs_plugin_appstream_set_license (GsApp *app, const gchar *license_string)
-{
- guint i;
- _cleanup_string_free_ GString *urld = NULL;
- _cleanup_strv_free_ gchar **tokens = NULL;
-
- /* tokenize the license string and URLify any SPDX IDs */
- urld = g_string_sized_new (strlen (license_string) + 1);
- tokens = as_utils_spdx_license_tokenize (license_string);
- for (i = 0; tokens[i] != NULL; i++) {
-
- /* translated join */
- if (g_strcmp0 (tokens[i], "&") == 0) {
- /* TRANSLATORS: This is how we join the licences and can
- * be considered a "Conjunctive AND Operator" according
- * to the SPDX specification. For example:
- * "LGPL-2.1 and MIT and BSD-2-Clause" */
- g_string_append (urld, _(" and "));
- continue;
- }
- if (g_strcmp0 (tokens[i], "|") == 0) {
- /* TRANSLATORS: This is how we join the licences and can
- * be considered a "Disjunctive OR Operator" according
- * to the SPDX specification. For example:
- * "LGPL-2.1 or MIT" */
- g_string_append (urld, _(" or "));
- continue;
- }
-
- /* legacy literal text */
- if (g_str_has_prefix (tokens[i], "#")) {
- g_string_append (urld, tokens[i] + 1);
- continue;
- }
-
- /* SPDX value */
- if (g_str_has_prefix (tokens[i], "@")) {
- g_string_append_printf (urld,
- "<a href=\"http://spdx.org/licenses/%s\">%s</a>",
- tokens[i] + 1, tokens[i] + 1);
- continue;
- }
-
- /* new SPDX value the extractor didn't know about */
- if (as_utils_is_spdx_license_id (tokens[i])) {
- g_string_append_printf (urld,
- "<a href=\"http://spdx.org/licenses/%s\">%s</a>",
- tokens[i], tokens[i]);
- continue;
- }
-
- /* unknown value */
- g_string_append (urld, tokens[i]);
- }
- gs_app_set_licence (app, urld->str);
-}
-
-/**
* gs_plugin_appstream_is_recent_release:
*/
static gboolean
@@ -593,7 +532,7 @@ gs_plugin_refine_item (GsPlugin *plugin,
/* set licence */
if (as_app_get_project_license (item) != NULL && gs_app_get_licence (app) == NULL)
- gs_plugin_appstream_set_license (app, as_app_get_project_license (item));
+ gs_app_set_licence (app, as_app_get_project_license (item));
/* set keywords */
if (as_app_get_keywords (item, NULL) != NULL &&
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]