[gnome-software] Move the license markup conversion to the details panel
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Move the license markup conversion to the details panel
- Date: Tue, 10 May 2016 16:07:14 +0000 (UTC)
commit a4c0e7f4f6092906d740caa0f64f91854bedd38a
Author: Richard Hughes <richard hughsie com>
Date: Tue May 10 15:00:37 2016 +0100
Move the license markup conversion to the details panel
One less translatable file.
po/POTFILES.in | 1 -
src/gs-app.c | 92 ++----------------------------------------
src/gs-self-test.c | 8 +--
src/gs-shell-details.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 111 insertions(+), 94 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8bd9c8b..5b7e6b9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -7,7 +7,6 @@ data/org.gnome.software.gschema.xml
src/gnome-software-local-file.desktop.in
[type: gettext/glade]src/gnome-software.ui
src/gs-app-addon-row.c
-src/gs-app.c
src/gs-app-folder-dialog.c
src/gs-application.c
src/gs-app-row.c
diff --git a/src/gs-app.c b/src/gs-app.c
index 8f3b83b..cce2154 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -1566,7 +1566,6 @@ gs_app_get_license_token_is_nonfree (const gchar *token)
void
gs_app_set_license (GsApp *app, GsAppQuality quality, const gchar *license)
{
- GString *urld;
guint i;
g_auto(GStrv) tokens = NULL;
@@ -1579,104 +1578,23 @@ gs_app_set_license (GsApp *app, GsAppQuality quality, const gchar *license)
return;
app->license_quality = quality;
- /* assume free software until we find an unmatched SPDX token */
+ /* assume free software until we find a nonfree SPDX token */
app->license_is_free = TRUE;
-
- /* tokenize the license string and URLify any SPDX IDs */
- urld = g_string_sized_new (strlen (license) + 1);
tokens = as_utils_spdx_license_tokenize (license);
for (i = 0; tokens[i] != NULL; i++) {
-
- /* translated join */
- if (g_strcmp0 (tokens[i], "&") == 0) {
- /* TRANSLATORS: This is how we join the licenses 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 licenses 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 "));
+ if (g_strcmp0 (tokens[i], "&") == 0 ||
+ g_strcmp0 (tokens[i], "|") == 0)
continue;
- }
-
- /* do the best we can */
if (gs_app_get_license_token_is_nonfree (tokens[i])) {
g_debug ("nonfree license from %s: '%s'",
gs_app_get_id (app), tokens[i]);
app->license_is_free = FALSE;
+ break;
}
-
- /* legacy literal text */
- if (g_str_has_prefix (tokens[i], "#")) {
- g_string_append (urld, tokens[i] + 1);
- continue;
- }
-
- /* proprietary software */
- if (g_strcmp0 (tokens[i], "@LicenseRef-proprietary") == 0) {
- const gchar *url = "https://en.wikipedia.org/wiki/Proprietary_software";
- g_string_append_printf (urld,
- "<a href=\"%s\">%s</a>",
- /* TRANSLATORS: non-free app */
- url, _("Proprietary"));
- continue;
- }
-
- /* public domain */
- if (g_strcmp0 (tokens[i], "@LicenseRef-public-domain") == 0) {
- const gchar *url = "https://en.wikipedia.org/wiki/Public_domain";
- g_string_append_printf (urld,
- "<a href=\"%s\">%s</a>",
- /* TRANSLATORS: see the wikipedia page */
- url, _("Public domain"));
- continue;
- }
-
- /* free software, license unspecified */
- if (g_str_has_prefix (tokens[i], "@LicenseRef-free")) {
- const gchar *url = "https://www.gnu.org/philosophy/free-sw";
- gchar *tmp;
-
- /* we support putting a custom URL in the
- * token string, e.g. @LicenseRef-free=http://ubuntu.com */
- tmp = g_strstr_len (tokens[i], -1, "=");
- if (tmp != NULL)
- url = tmp + 1;
- g_string_append_printf (urld,
- "<a href=\"%s\">%s</a>",
- /* TRANSLATORS: see GNU page */
- url, _("Free Software"));
- 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->license);
- app->license = g_string_free (urld, FALSE);
+ app->license = g_strdup (license);
}
/**
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index c40450a..5600b1d 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -238,8 +238,7 @@ gs_plugin_loader_refine_func (GsPluginLoader *plugin_loader)
g_assert_no_error (error);
g_assert (ret);
- g_assert_cmpstr (gs_app_get_license (app), ==,
- "<a href=\"http://spdx.org/licenses/GPL-2.0+\">GPL-2.0+</a>");
+ g_assert_cmpstr (gs_app_get_license (app), ==, "GPL-2.0+");
g_assert_cmpstr (gs_app_get_description (app), !=, NULL);
g_assert_cmpstr (gs_app_get_url (app, AS_URL_KIND_HOMEPAGE), ==, "http://www.test.org/");
}
@@ -378,8 +377,7 @@ gs_plugin_loader_installed_func (GsPluginLoader *plugin_loader)
/* check various bitfields */
g_assert (gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE));
- g_assert_cmpstr (gs_app_get_license (app), ==,
- "<a href=\"http://spdx.org/licenses/GPL-2.0+\">GPL-2.0+</a>");
+ g_assert_cmpstr (gs_app_get_license (app), ==, "GPL-2.0+");
g_assert (gs_app_get_license_is_free (app));
/* check kudos */
@@ -405,7 +403,7 @@ gs_plugin_loader_installed_func (GsPluginLoader *plugin_loader)
g_assert_cmpstr (gs_app_get_name (addon), ==, "Spell Check");
g_assert_cmpstr (gs_app_get_source_default (addon), ==, "zeus-spell");
g_assert_cmpstr (gs_app_get_license (addon), ==,
- "<a href=\"https://www.debian.org/\">Free Software</a>");
+ "LicenseRef-free=https://www.debian.org/");
g_assert (gs_app_get_pixbuf (addon) == NULL);
}
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 4c9cc82..f46ddf9 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -668,6 +668,105 @@ gs_shell_details_history_cb (GtkLabel *label,
}
/**
+ * gs_shell_details_get_license_markup:
+ **/
+static gchar *
+gs_shell_details_get_license_markup (const gchar *license)
+{
+ GString *urld;
+ guint i;
+ g_auto(GStrv) tokens = NULL;
+
+ /* URLify any SPDX IDs */
+ urld = g_string_new ("");
+ tokens = as_utils_spdx_license_tokenize (license);
+ for (i = 0; tokens[i] != NULL; i++) {
+
+ /* translated join */
+ if (g_strcmp0 (tokens[i], "&") == 0) {
+ /* TRANSLATORS: This is how we join the licenses 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 licenses 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;
+ }
+
+ /* proprietary software */
+ if (g_strcmp0 (tokens[i], "@LicenseRef-proprietary") == 0) {
+ const gchar *url = "https://en.wikipedia.org/wiki/Proprietary_software";
+ g_string_append_printf (urld,
+ "<a href=\"%s\">%s</a>",
+ /* TRANSLATORS: non-free app */
+ url, _("Proprietary"));
+ continue;
+ }
+
+ /* public domain */
+ if (g_strcmp0 (tokens[i], "@LicenseRef-public-domain") == 0) {
+ const gchar *url = "https://en.wikipedia.org/wiki/Public_domain";
+ g_string_append_printf (urld,
+ "<a href=\"%s\">%s</a>",
+ /* TRANSLATORS: see the wikipedia page */
+ url, _("Public domain"));
+ continue;
+ }
+
+ /* free software, license unspecified */
+ if (g_str_has_prefix (tokens[i], "@LicenseRef-free")) {
+ const gchar *url = "https://www.gnu.org/philosophy/free-sw";
+ gchar *tmp;
+
+ /* we support putting a custom URL in the
+ * token string, e.g. @LicenseRef-free=http://ubuntu.com */
+ tmp = g_strstr_len (tokens[i], -1, "=");
+ if (tmp != NULL)
+ url = tmp + 1;
+ g_string_append_printf (urld,
+ "<a href=\"%s\">%s</a>",
+ /* TRANSLATORS: see GNU page */
+ url, _("Free Software"));
+ 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]);
+ }
+
+ return g_string_free (urld, FALSE);
+}
+
+/**
* gs_shell_details_refresh_all:
**/
static void
@@ -742,7 +841,10 @@ gs_shell_details_refresh_all (GsShellDetails *self)
gtk_label_set_label (GTK_LABEL (self->label_details_license_value), C_("license", "Unknown"));
gtk_widget_set_tooltip_text (self->label_details_license_value, NULL);
} else {
- gtk_label_set_markup (GTK_LABEL (self->label_details_license_value), tmp);
+ g_autofree gchar *license_markup = NULL;
+ license_markup = gs_shell_details_get_license_markup (tmp);
+ gtk_label_set_markup (GTK_LABEL (self->label_details_license_value),
+ license_markup);
gtk_widget_set_tooltip_text (self->label_details_license_value, NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]