diff options
author | Thiago Macieira <thiago@macieira.org> | 2013-12-16 09:09:41 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-12-16 16:20:52 -0800 |
commit | ca8aee4701f95a758f93033eb88ca851d61b2008 (patch) | |
tree | a5d0989a975791a6eea8f0bf610430490a47d7b6 /qt-gui.cpp | |
parent | 5f12660870be4b1692eae28339785bc4b2d08550 (diff) | |
download | subsurface-ca8aee4701f95a758f93033eb88ca851d61b2008.tar.gz |
Move the XSLT files into a Qt resource
This means we no longer need to keep them on disk and worry about
installing / uninstalling them. They will always be kept in-memory
(compressed).
Signed-off-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-gui.cpp')
-rw-r--r-- | qt-gui.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/qt-gui.cpp b/qt-gui.cpp index 78ce3c9a3..67061ef81 100644 --- a/qt-gui.cpp +++ b/qt-gui.cpp @@ -9,6 +9,8 @@ #include <sys/time.h> #include <ctype.h> +#include <libxslt/documents.h> + #include "dive.h" #include "divelist.h" #include "display.h" @@ -35,6 +37,7 @@ #include <QNetworkProxy> #include <QDateTime> #include <QRegExp> +#include <QResource> #include <QLibraryInfo> #include <gettextfromc.h> @@ -507,3 +510,36 @@ QString get_trip_date_string(timestamp_t when, int nr) .arg(monthname(tm.tm_mon)) .arg(tm.tm_year + 1900); } + +static xmlDocPtr get_stylesheet_doc(const xmlChar *uri, xmlDictPtr, int, void *, xsltLoadType) +{ + QFile f(QLatin1String(":/xslt/") + (const char *)uri); + if (!f.open(QIODevice::ReadOnly)) + return NULL; + + /* Load and parse the data */ + QByteArray source = f.readAll(); + + xmlDocPtr doc = xmlParseMemory(source, source.size()); + return doc; +} + +xsltStylesheetPtr get_stylesheet(const char *name) +{ + // this needs to be done only once, but doesn't hurt to run every time + xsltSetLoaderFunc(get_stylesheet_doc); + + // get main document: + xmlDocPtr doc = get_stylesheet_doc((const xmlChar *)name, NULL, 0, NULL, XSLT_LOAD_START); + if (!doc) + return NULL; + +// xsltSetGenericErrorFunc(stderr, NULL); + xsltStylesheetPtr xslt = xsltParseStylesheetDoc(doc); + if (!xslt) { + xmlFreeDoc(doc); + return NULL; + } + + return xslt; +} |