From 248359857ed254e61c4aa6e49ece183042b918c6 Mon Sep 17 00:00:00 2001 From: Shaun McCance Date: Sat, 24 Jul 2021 11:00:27 -0400 Subject: Make help list use XSLT --- Makefile.am | 1 + configure.ac | 6 +- data/xslt/info2html.xsl.in | 1 + data/xslt/links2html.xsl.in | 97 ++++++++++++++++++++ data/xslt/man2html.xsl.in | 1 + libyelp/yelp-help-list.c | 217 +++++++++++++------------------------------- 6 files changed, 170 insertions(+), 153 deletions(-) create mode 100644 data/xslt/links2html.xsl.in diff --git a/Makefile.am b/Makefile.am index 4551da42..51d9e74c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -691,6 +691,7 @@ xsldir = $(pkgdatadir)/xslt xsl_DATA = \ data/xslt/db2html.xsl \ data/xslt/info2html.xsl \ + data/xslt/links2html.xsl \ data/xslt/mal2html.xsl \ data/xslt/man2html.xsl \ data/xslt/yelp-common.xsl diff --git a/configure.ac b/configure.ac index 89244242..d9b3211b 100644 --- a/configure.ac +++ b/configure.ac @@ -35,7 +35,7 @@ PKG_CHECK_MODULES(YELP, libexslt >= 0.8.1 sqlite3 webkit2gtk-4.0 >= 2.19.2 - yelp-xsl >= 3.27.1 + yelp-xsl >= 40.0 ]) AC_SUBST([YELP_CFLAGS]) AC_SUBST([YELP_LIBS]) @@ -136,6 +136,9 @@ XSL_ICONS="`$PKG_CONFIG --variable=xsltdir yelp-xsl`/common/icons.xsl" AC_SUBST(XSL_ICONS) XSL_HTML="`$PKG_CONFIG --variable=xsltdir yelp-xsl`/common/html.xsl" AC_SUBST(XSL_HTML) +XSL_TMPL="`$PKG_CONFIG --variable=xsltdir yelp-xsl`/common/tmpl.xsl" +AC_SUBST(XSL_TMPL) + XSL_JSDIR="`$PKG_CONFIG --variable=jsdir yelp-xsl`" AC_SUBST(XSL_JSDIR) @@ -159,6 +162,7 @@ docs/libyelp/version.xml data/dtd/catalog data/xslt/db2html.xsl data/xslt/info2html.xsl +data/xslt/links2html.xsl data/xslt/mal2html.xsl data/xslt/man2html.xsl data/xslt/yelp-common.xsl diff --git a/data/xslt/info2html.xsl.in b/data/xslt/info2html.xsl.in index 34c1caa7..bb84ba60 100644 --- a/data/xslt/info2html.xsl.in +++ b/data/xslt/info2html.xsl.in @@ -10,6 +10,7 @@ + diff --git a/data/xslt/links2html.xsl.in b/data/xslt/links2html.xsl.in new file mode 100644 index 00000000..e5b8c1d2 --- /dev/null +++ b/data/xslt/links2html.xsl.in @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +.ex-yelp-panel-icon { + display: flex; +} + + + + +
+

+
+ +
+ +
diff --git a/data/xslt/man2html.xsl.in b/data/xslt/man2html.xsl.in index cae7a3c7..676ce3eb 100644 --- a/data/xslt/man2html.xsl.in +++ b/data/xslt/man2html.xsl.in @@ -10,6 +10,7 @@ + diff --git a/libyelp/yelp-help-list.c b/libyelp/yelp-help-list.c index 7c21ab1f..9860d713 100644 --- a/libyelp/yelp-help-list.c +++ b/libyelp/yelp-help-list.c @@ -33,6 +33,9 @@ #include "yelp-help-list.h" #include "yelp-settings.h" +#include "yelp-transform.h" + +#define STYLESHEET DATADIR"/yelp/xslt/links2html.xsl" typedef struct _HelpListEntry HelpListEntry; @@ -96,6 +99,9 @@ struct _YelpHelpListPrivate { GHashTable *entries; GList *all_entries; GSList *pending; + xmlDocPtr entriesdoc; + + YelpTransform *transform; xmlXPathCompExprPtr get_docbook_title; xmlXPathCompExprPtr get_mallard_title; @@ -154,6 +160,11 @@ yelp_help_list_finalize (GObject *object) g_hash_table_destroy (priv->entries); g_mutex_clear (&priv->mutex); + if (priv->entriesdoc) { + xmlFreeDoc (priv->entriesdoc); + priv->entriesdoc = NULL; + } + if (priv->get_docbook_title) xmlXPathFreeCompExpr (priv->get_docbook_title); if (priv->get_mallard_title) @@ -161,6 +172,8 @@ yelp_help_list_finalize (GObject *object) if (priv->get_mallard_desc) xmlXPathFreeCompExpr (priv->get_mallard_desc); + g_clear_object (&priv->transform); + G_OBJECT_CLASS (yelp_help_list_parent_class)->finalize (object); } @@ -389,7 +402,12 @@ help_list_think (YelpHelpList *list) else if (entry->type == YELP_URI_DOCUMENT_TYPE_DOCBOOK) help_list_process_docbook (list, entry); - tmp = g_strconcat (entryid, ".desktop", NULL); + if (g_str_equal (entryid, "gnome-terminal")) { + tmp = g_strconcat ("org.gnome.Terminal", ".desktop", NULL); + } + else { + tmp = g_strconcat (entryid, ".desktop", NULL); + } app = g_desktop_app_info_new (tmp); g_free (tmp); @@ -407,9 +425,7 @@ help_list_think (YelpHelpList *list) if (app != NULL) { GIcon *icon = g_app_info_get_icon ((GAppInfo *) app); if (icon != NULL) { - GtkIconInfo *info = gtk_icon_theme_lookup_by_gicon (theme, - icon, 22, - GTK_ICON_LOOKUP_NO_SVG); + GtkIconInfo *info = gtk_icon_theme_lookup_by_gicon (theme, icon, 48, 0); if (info != NULL) { const gchar *iconfile = gtk_icon_info_get_filename (info); if (iconfile) @@ -435,167 +451,64 @@ help_list_think (YelpHelpList *list) g_object_unref (list); } + +static void +transform_chunk_ready (YelpTransform *transform, + gchar *chunk_id, + YelpHelpList *list) +{ + gchar *content; + content = yelp_transform_take_chunk (transform, chunk_id); + yelp_document_give_contents (YELP_DOCUMENT (list), + chunk_id, + content, + "application/xhtml+xml"); + yelp_document_signal (YELP_DOCUMENT (list), + chunk_id, + YELP_DOCUMENT_SIGNAL_CONTENTS, + NULL); +} + + /* This function expects to be called inside a locked mutex */ static void help_list_handle_page (YelpHelpList *list, const gchar *page_id) { - gchar **colors, *tmp; - GList *cur; YelpHelpListPrivate *priv = yelp_help_list_get_instance_private (list); - GtkTextDirection direction = gtk_widget_get_default_direction (); - GString *string = g_string_new - ("\n"); - - tmp = g_markup_printf_escaped ("%s", - _("All Help Documents")); - g_string_append (string, tmp); - g_free (tmp); - - g_string_append (string, - "" - "
" - "
"); - tmp = g_markup_printf_escaped ("

%s

\n", - _("All Help Documents")); - g_string_append (string, tmp); - g_free (tmp); + xmlNodePtr rootnode; + GList *entrycur; + gchar **params = NULL; + + priv->entriesdoc = xmlNewDoc (BAD_CAST "1.0"); + rootnode = xmlNewDocNode (priv->entriesdoc, NULL, BAD_CAST "links", NULL); + xmlDocSetRootElement (priv->entriesdoc, rootnode); + xmlNewTextChild (rootnode, NULL, BAD_CAST "title", BAD_CAST _("All Help Documents")); priv->all_entries = g_list_sort (priv->all_entries, (GCompareFunc) help_list_entry_cmp); - for (cur = priv->all_entries; cur != NULL; cur = cur->next) { - HelpListEntry *entry = (HelpListEntry *) cur->data; - gchar *title = entry->title ? entry->title : (strchr (entry->id, ':') + 1); - const gchar *desc = entry->desc ? entry->desc : ""; + for (entrycur = priv->all_entries; entrycur != NULL; entrycur = entrycur->next) { + xmlNodePtr linknode, curnode; + HelpListEntry *entry = (HelpListEntry *) entrycur->data; + linknode = xmlNewChild (rootnode, NULL, BAD_CAST "link", NULL); + xmlSetProp (linknode, BAD_CAST "href", BAD_CAST entry->id); + xmlNewTextChild (linknode, NULL, BAD_CAST "title", BAD_CAST entry->title); + xmlNewTextChild (linknode, NULL, BAD_CAST "desc", BAD_CAST entry->desc); + curnode = xmlNewChild (linknode, NULL, BAD_CAST "thumb", NULL); + xmlSetProp (curnode, BAD_CAST "src", BAD_CAST entry->icon); + } - tmp = g_markup_printf_escaped ("" - "" - ""); + yelp_transform_start (priv->transform, priv->entriesdoc, NULL, + (const gchar * const *) params); - yelp_document_give_contents (YELP_DOCUMENT (list), page_id, - string->str, - "application/xhtml+xml"); - g_strfreev (colors); - g_string_free (string, FALSE); - yelp_document_signal (YELP_DOCUMENT (list), page_id, - YELP_DOCUMENT_SIGNAL_CONTENTS, NULL); + g_strfreev (params); } -- cgit v1.2.1