[gnome-software] Move the markdown parsing to the PackageKit plugin
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Move the markdown parsing to the PackageKit plugin
- Date: Thu, 7 Apr 2016 17:41:05 +0000 (UTC)
commit abbd63ed2bbd6b4a6f768cc28434349c87c88dec
Author: Richard Hughes <richard hughsie com>
Date: Thu Apr 7 11:49:23 2016 +0100
Move the markdown parsing to the PackageKit plugin
The format isn't standardized as markdown between distros.
src/gs-app-row.c | 12 +--------
src/gs-shell-updates.c | 1 -
src/gs-update-dialog.c | 29 +++++------------------
src/plugins/gs-appstream.c | 2 +-
src/plugins/gs-plugin-packagekit-refine.c | 35 ++++++++++++++++++++++++++++-
5 files changed, 44 insertions(+), 35 deletions(-)
---
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index 93f02c0..49a1fa4 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -27,7 +27,6 @@
#include "gs-app-row.h"
#include "gs-star-widget.h"
-#include "gs-markdown.h"
#include "gs-progress-button.h"
#include "gs-utils.h"
#include "gs-folders.h"
@@ -91,15 +90,8 @@ gs_app_row_get_description (GsAppRow *app_row)
(gs_app_get_state (priv->app) == AS_APP_STATE_UPDATABLE ||
gs_app_get_state (priv->app) == AS_APP_STATE_UPDATABLE_LIVE)) {
tmp = gs_app_get_update_details (priv->app);
- if (tmp != NULL && tmp[0] != '\0') {
- g_autoptr(GsMarkdown) markdown = NULL;
- markdown = gs_markdown_new (GS_MARKDOWN_OUTPUT_PANGO);
- gs_markdown_set_smart_quoting (markdown, FALSE);
- gs_markdown_set_autocode (markdown, FALSE);
- gs_markdown_set_autolinkify (markdown, FALSE);
- escaped = gs_markdown_parse (markdown, tmp);
- return g_string_new (escaped);
- }
+ if (tmp != NULL && tmp[0] != '\0')
+ return g_string_new (tmp);
}
if (gs_app_get_state (priv->app) == AS_APP_STATE_UNAVAILABLE)
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 0e908d6..70fffcb 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -29,7 +29,6 @@
#include "gs-utils.h"
#include "gs-app.h"
#include "gs-app-row.h"
-#include "gs-markdown.h"
#include "gs-update-dialog.h"
#include "gs-update-list.h"
#include "gs-update-monitor.h"
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index 937c9a0..45bae7d 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -26,7 +26,6 @@
#include "gs-update-dialog.h"
#include "gs-app-row.h"
-#include "gs-markdown.h"
#include "gs-update-list.h"
#include "gs-utils.h"
@@ -93,7 +92,6 @@ set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
AsAppKind kind;
const GdkPixbuf *pixbuf;
const gchar *update_details;
- g_autofree gchar *update_desc = NULL;
/* set window title */
kind = gs_app_get_kind (app);
@@ -114,28 +112,15 @@ set_updates_description_ui (GsUpdateDialog *dialog, GsApp *app)
gs_app_get_update_version (app));
}
- /* this is set unconditionally just in case the output of the
- * markdown->PangoMarkup parser is invalid */
- gtk_label_set_markup (GTK_LABEL (dialog->label_details),
- /* TRANSLATORS: this is where the
- * packager did not write a
- * description for the update */
- _("No update description available."));
-
- /* get the update description */
- update_details = gs_app_get_update_details (app);
- if (update_details != NULL) {
- g_autoptr(GsMarkdown) markdown = NULL;
- markdown = gs_markdown_new (GS_MARKDOWN_OUTPUT_PANGO);
- gs_markdown_set_smart_quoting (markdown, FALSE);
- gs_markdown_set_autocode (markdown, TRUE);
- update_desc = gs_markdown_parse (markdown, update_details);
- }
-
/* set update header */
gtk_widget_set_visible (dialog->box_header, kind == AS_APP_KIND_DESKTOP);
- if (update_desc != NULL)
- gtk_label_set_markup (GTK_LABEL (dialog->label_details), update_desc);
+ update_details = gs_app_get_update_details (app);
+ if (update_details == NULL) {
+ /* TRANSLATORS: this is where the packager did not write
+ * a description for the update */
+ update_details = _("No update description available.");
+ }
+ gtk_label_set_markup (GTK_LABEL (dialog->label_details), update_details);
gtk_label_set_label (GTK_LABEL (dialog->label_name), gs_app_get_name (app));
gtk_label_set_label (GTK_LABEL (dialog->label_summary), gs_app_get_summary (app));
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index 05fca84..4ddd0d2 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -549,7 +549,7 @@ gs_appstream_refine_app (GsPlugin *plugin,
if (tmp != NULL) {
g_autofree gchar *desc = NULL;
desc = as_markup_convert (tmp,
- AS_MARKUP_CONVERT_FORMAT_MARKDOWN,
+ AS_MARKUP_CONVERT_FORMAT_SIMPLE,
error);
if (desc == NULL)
return FALSE;
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index 7057dfb..4c7ea34 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -28,6 +28,7 @@
#include <gs-utils.h>
#include <glib/gi18n.h>
+#include "gs-markdown.h"
#include "packagekit-common.h"
/*
@@ -386,6 +387,33 @@ gs_plugin_packagekit_refine_from_desktop (GsPlugin *plugin,
}
/**
+ * gs_plugin_packagekit_fixup_update_description:
+ *
+ * Lets assume Fedora is sending us valid markdown, but fall back to
+ * plain text if this fails.
+ */
+static gchar *
+gs_plugin_packagekit_fixup_update_description (const gchar *text)
+{
+ gchar *tmp;
+ g_autoptr(GsMarkdown) markdown = NULL;
+
+ /* nothing to do */
+ if (text == NULL)
+ return NULL;
+
+ /* try to parse */
+ markdown = gs_markdown_new (GS_MARKDOWN_OUTPUT_TEXT);
+ gs_markdown_set_smart_quoting (markdown, FALSE);
+ gs_markdown_set_autocode (markdown, FALSE);
+ gs_markdown_set_autolinkify (markdown, FALSE);
+ tmp = gs_markdown_parse (markdown, text);
+ if (tmp != NULL)
+ return tmp;
+ return g_strdup (text);
+}
+
+/**
* gs_plugin_packagekit_refine_updatedetails:
*/
static gboolean
@@ -432,11 +460,16 @@ gs_plugin_packagekit_refine_updatedetails (GsPlugin *plugin,
app = GS_APP (l->data);
package_id = gs_app_get_source_id_default (app);
for (i = 0; i < array->len; i++) {
+ const gchar *tmp;
+ g_autofree gchar *desc = NULL;
/* right package? */
update_detail = g_ptr_array_index (array, i);
if (g_strcmp0 (package_id, pk_update_detail_get_package_id (update_detail)) != 0)
continue;
- gs_app_set_update_details (app, pk_update_detail_get_update_text (update_detail));
+ 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);
break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]