[gnome-software] Support full markup in AppStream descriptions
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Support full markup in AppStream descriptions
- Date: Mon, 21 Oct 2013 11:58:40 +0000 (UTC)
commit 61bbab48f2557e8f8472c60f07296fa49084e627
Author: Richard Hughes <richard hughsie com>
Date: Mon Oct 21 12:51:04 2013 +0100
Support full markup in AppStream descriptions
src/plugins/Makefile.am | 2 +
src/plugins/appstream-app.c | 15 ++------
src/plugins/appstream-app.h | 3 +-
src/plugins/appstream-cache.c | 67 +++++++++++++++++++++++++++++++++------
src/plugins/appstream-markup.c | 1 -
5 files changed, 63 insertions(+), 25 deletions(-)
---
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index bda7b8c..febcf2f 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -76,6 +76,8 @@ libgs_plugin_appstream_la_SOURCES = \
appstream-screenshot.h \
appstream-common.c \
appstream-common.h \
+ appstream-markup.c \
+ appstream-markup.h \
appstream-cache.c \
appstream-cache.h
libgs_plugin_appstream_la_LIBADD = $(GS_PLUGIN_LIBS)
diff --git a/src/plugins/appstream-app.c b/src/plugins/appstream-app.c
index bc7fab9..fb22fed 100644
--- a/src/plugins/appstream-app.c
+++ b/src/plugins/appstream-app.c
@@ -37,7 +37,6 @@ struct AppstreamApp
gchar *summary;
guint summary_value;
gchar *description;
- guint description_value;
GHashTable *urls;
gchar *licence;
gchar *project_group;
@@ -115,7 +114,6 @@ appstream_app_new (void)
app->urls = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
app->name_value = G_MAXUINT;
app->summary_value = G_MAXUINT;
- app->description_value = G_MAXUINT;
app->icon_kind = APPSTREAM_APP_ICON_KIND_UNKNOWN;
app->id_kind = APPSTREAM_APP_ID_KIND_UNKNOWN;
app->priority = 0;
@@ -400,18 +398,13 @@ appstream_app_set_project_group (AppstreamApp *app,
*/
void
appstream_app_set_description (AppstreamApp *app,
- const gchar *lang,
const gchar *description,
- gsize length)
+ gssize length)
{
- guint new_value;
-
- new_value = appstream_get_locale_value (lang);
- if (new_value < app->description_value) {
- g_free (app->description);
+ if (length < 0)
+ app->description = g_strdup (description);
+ else
app->description = g_strndup (description, length);
- app->description_value = new_value;
- }
}
/**
diff --git a/src/plugins/appstream-app.h b/src/plugins/appstream-app.h
index ac2329e..ebc1336 100644
--- a/src/plugins/appstream-app.h
+++ b/src/plugins/appstream-app.h
@@ -96,9 +96,8 @@ void appstream_app_set_project_group (AppstreamApp *app,
const gchar *project_group,
gsize length);
void appstream_app_set_description (AppstreamApp *app,
- const gchar *lang,
const gchar *description,
- gsize length);
+ gssize length);
void appstream_app_set_icon (AppstreamApp *app,
const gchar *icon,
gsize length);
diff --git a/src/plugins/appstream-cache.c b/src/plugins/appstream-cache.c
index 2a95a68..6e4924e 100644
--- a/src/plugins/appstream-cache.c
+++ b/src/plugins/appstream-cache.c
@@ -26,6 +26,7 @@
#include "appstream-cache.h"
#include "appstream-common.h"
#include "appstream-image.h"
+#include "appstream-markup.h"
#include "appstream-screenshot.h"
static void appstream_cache_finalize (GObject *object);
@@ -120,6 +121,7 @@ typedef struct {
AppstreamImage *image;
AppstreamScreenshot *screenshot;
gint priority;
+ AppstreamMarkup *markup;
} AppstreamCacheHelper;
/**
@@ -160,6 +162,28 @@ appstream_cache_start_element_cb (GMarkupParseContext *context,
guint i;
guint width = 0;
+ /* description markup */
+ if (helper->tag == APPSTREAM_TAG_DESCRIPTION) {
+ for (i = 0; attribute_names[i] != NULL; i++) {
+ if (g_strcmp0 (attribute_names[i], "xml:lang") == 0) {
+ appstream_markup_set_lang (helper->markup,
+ attribute_values[i]);
+ break;
+ }
+ }
+ if (g_strcmp0 (element_name, "p") == 0) {
+ appstream_markup_set_mode (helper->markup,
+ APPSTREAM_MARKUP_MODE_P_START);
+ } else if (g_strcmp0 (element_name, "ul") == 0) {
+ appstream_markup_set_mode (helper->markup,
+ APPSTREAM_MARKUP_MODE_UL_START);
+ } else if (g_strcmp0 (element_name, "li") == 0) {
+ appstream_markup_set_mode (helper->markup,
+ APPSTREAM_MARKUP_MODE_LI_START);
+ }
+ return;
+ }
+
/* process tag start */
section_new = appstream_tag_from_string (element_name);
switch (section_new) {
@@ -347,7 +371,6 @@ appstream_cache_start_element_cb (GMarkupParseContext *context,
case APPSTREAM_TAG_NAME:
case APPSTREAM_TAG_SUMMARY:
- case APPSTREAM_TAG_DESCRIPTION:
if (helper->item_temp == NULL ||
helper->tag != APPSTREAM_TAG_APPLICATION) {
g_set_error (error,
@@ -366,6 +389,11 @@ appstream_cache_start_element_cb (GMarkupParseContext *context,
if (!helper->lang_temp)
helper->lang_temp = g_strdup ("C");
break;
+ case APPSTREAM_TAG_DESCRIPTION:
+ appstream_markup_set_enabled (helper->markup, TRUE);
+ appstream_markup_set_mode (helper->markup,
+ APPSTREAM_MARKUP_MODE_START);
+ break;
default:
/* ignore unknown entries */
break;
@@ -439,6 +467,28 @@ appstream_cache_end_element_cb (GMarkupParseContext *context,
{
AppstreamCacheHelper *helper = (AppstreamCacheHelper *) user_data;
AppstreamTag section_new;
+ const gchar *tmp;
+
+ if (helper->tag == APPSTREAM_TAG_DESCRIPTION) {
+ if (g_strcmp0 (element_name, "p") == 0) {
+ appstream_markup_set_mode (helper->markup,
+ APPSTREAM_MARKUP_MODE_P_END);
+ } else if (g_strcmp0 (element_name, "ul") == 0) {
+ appstream_markup_set_mode (helper->markup,
+ APPSTREAM_MARKUP_MODE_UL_END);
+ } else if (g_strcmp0 (element_name, "li") == 0) {
+ appstream_markup_set_mode (helper->markup,
+ APPSTREAM_MARKUP_MODE_LI_END);
+ } else if (g_strcmp0 (element_name, "description") == 0) {
+ appstream_markup_set_mode (helper->markup,
+ APPSTREAM_MARKUP_MODE_END);
+ tmp = appstream_markup_get_text (helper->markup);
+ if (tmp != NULL)
+ appstream_app_set_description (helper->item_temp, tmp, -1);
+ helper->tag = APPSTREAM_TAG_APPLICATION;
+ }
+ return;
+ }
section_new = appstream_tag_from_string (element_name);
switch (section_new) {
@@ -483,7 +533,6 @@ appstream_cache_end_element_cb (GMarkupParseContext *context,
case APPSTREAM_TAG_NAME:
case APPSTREAM_TAG_SUMMARY:
case APPSTREAM_TAG_PROJECT_GROUP:
- case APPSTREAM_TAG_DESCRIPTION:
helper->tag = APPSTREAM_TAG_APPLICATION;
g_free (helper->lang_temp);
helper->lang_temp = NULL;
@@ -646,14 +695,7 @@ appstream_cache_text_cb (GMarkupParseContext *context,
appstream_app_set_licence (helper->item_temp, text, text_len);
break;
case APPSTREAM_TAG_DESCRIPTION:
- if (helper->item_temp == NULL) {
- g_set_error_literal (error,
- APPSTREAM_CACHE_ERROR,
- APPSTREAM_CACHE_ERROR_FAILED,
- "item_temp description invalid");
- return;
- }
- appstream_app_set_description (helper->item_temp, helper->lang_temp, text, text_len);
+ appstream_markup_add_content (helper->markup, text, text_len);
break;
case APPSTREAM_TAG_ICON:
if (helper->item_temp == NULL ||
@@ -752,6 +794,7 @@ appstream_cache_parse_file (AppstreamCache *cache,
helper = g_new0 (AppstreamCacheHelper, 1);
helper->cache = cache;
+ helper->markup = appstream_markup_new ();
helper->path_icons = icon_path_tmp;
ctx = g_markup_parse_context_new (&parser,
G_MARKUP_PREFIX_ERROR_POSITION,
@@ -766,8 +809,10 @@ appstream_cache_parse_file (AppstreamCache *cache,
if (len < 0)
ret = FALSE;
out:
- if (helper != NULL && helper->item_temp != NULL)
+ if (helper != NULL && helper->item_temp != NULL) {
+ appstream_markup_free (helper->markup);
appstream_app_free (helper->item_temp);
+ }
if (info != NULL)
g_object_unref (info);
g_free (helper);
diff --git a/src/plugins/appstream-markup.c b/src/plugins/appstream-markup.c
index f3624f3..4fe59c0 100644
--- a/src/plugins/appstream-markup.c
+++ b/src/plugins/appstream-markup.c
@@ -73,7 +73,6 @@ appstream_markup_process_locale (AppstreamMarkup *markup)
/* is this better than the previous locale */
if (locale_value < markup->locale_value) {
- g_debug ("Dumping existing string for locale %s!", markup->lang);
g_string_set_size (markup->string, 0);
markup->locale_value = locale_value;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]