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>
This commit is contained in:
Thiago Macieira 2013-12-16 09:09:41 -08:00 committed by Dirk Hohndel
parent 5f12660870
commit ca8aee4701
5 changed files with 52 additions and 63 deletions

View file

@ -99,7 +99,6 @@ Section
# Files to include in installer
File subsurface.exe
File /r xslt
File /r data
File /r images
File /r plugins
@ -156,14 +155,12 @@ Section "Uninstall"
# Delete installed files
Delete "$INSTDIR\*.dll"
Delete "$INSTDIR\xslt\*.xslt"
Delete "$INSTDIR\freetype-config"
Delete "$INSTDIR\subsurface.exe"
Delete "$INSTDIR\subsurface.ico"
Delete "$INSTDIR\Uninstall.exe"
Delete "$INSTDIR\qt.conf"
RMDir /r "$INSTDIR\share"
RMDir /r "$INSTDIR\xslt"
RMDir /r "$INSTDIR\data"
RMDir /r "$INSTDIR\images"
RMDir /r "$INSTDIR\translations"

View file

@ -1970,57 +1970,6 @@ void parse_xml_exit(void)
xmlCleanupParser();
}
static xsltStylesheetPtr try_get_stylesheet(const char *path, int len, const char *name)
{
xsltStylesheetPtr ret;
int namelen = strlen(name);
char *filename = malloc(len+1+namelen+1);
if (!filename)
return NULL;
memcpy(filename, path, len);
#ifdef WIN32
filename[len] = '\\';
#else
filename[len] = '/';
#endif
memcpy(filename + len + 1, name, namelen+1);
ret = NULL;
if (!access(filename, R_OK))
ret = xsltParseStylesheetFile(filename);
free(filename);
return ret;
}
xsltStylesheetPtr get_stylesheet(const char *name)
{
const char *path, *next;
path = getenv("SUBSURFACE_XSLT_PATH");
if (!path)
path = xslt_path;
do {
int len;
xsltStylesheetPtr ret;
next = strchr(path, ':');
len = strlen(path);
if (next) {
len = next - path;
next++;
}
ret = try_get_stylesheet(path, len, name);
if (ret)
return ret;
} while ((path = next) != NULL);
return NULL;
}
static struct xslt_files {
const char *root;
const char *file;

View file

@ -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;
}

View file

@ -1,5 +1,4 @@
marbledir.files = $$MARBLEDIR
xslt.files = $$XSLT_FILES
doc.files = $$DOC_FILES
translation.files = $$replace(TRANSLATIONS, .ts, .qm)
exists($$[QT_INSTALL_TRANSLATIONS]) {
@ -27,11 +26,10 @@ mac {
datadir = Contents/Resources/share
marbledir.path = Contents/Resources/data
xslt.path = $$datadir
doc.path = $$datadir/Documentation
translation.path = Contents/Resources/translations
qttranslation.path = Contents/Resources/translations
QMAKE_BUNDLE_DATA += marbledir xslt doc translation qttranslation
QMAKE_BUNDLE_DATA += marbledir doc translation qttranslation
mac_deploy.target = mac-deploy
mac_deploy.commands += $$[QT_INSTALL_BINS]/macdeployqt $${TARGET}.app
@ -54,7 +52,6 @@ mac {
doc.path = $$WINDOWSSTAGING/Documentation
CONFIG -= copy_dir_files
deploy.path = $$WINDOWSSTAGING
deploy.files += $$xslt.files
deploy.CONFIG += no_check_exist
target.path = $$WINDOWSSTAGING
marbledir.path = $$WINDOWSSTAGING/data
@ -133,7 +130,6 @@ DATADIR = $(prefix)/share$${nl}\
DOCDIR = $(DATADIR)/subsurface/Documentation$${nl}\
DESKTOPDIR = $(DATADIR)/applications$${nl}\
MANDIR = $(DATADIR)/man/man1$${nl}\
XSLTDIR = $(DATADIR)/subsurface
QMAKE_EXTRA_TARGETS += dummy
WINDOWSSTAGING = ./packaging/windows
@ -146,7 +142,6 @@ XSLTDIR = $(DATADIR)/subsurface
manpage.path = /$(MANDIR)
manpage.files = $$MANPAGE
xslt.path = /$(XSLTDIR)
marbledir.path = /$(DATADIR)/subsurface/data
doc.path = /$(DOCDIR)
@ -155,7 +150,7 @@ XSLTDIR = $(DATADIR)/subsurface
translation.path = /$(DATADIR)/subsurface/translations
translation.CONFIG += no_check_exist
INSTALLS += target desktop manpage xslt doc marbledir translation
INSTALLS += target desktop manpage doc marbledir translation
install.target = install
}
!isEmpty(TRANSLATIONS) {

View file

@ -29,5 +29,17 @@
<file alias="left_wing">icons/planner/left_wing.png</file>
<file alias="plan_minus">icons/planner/minus.png</file>
<file alias="plan_plus">icons/planner/plus.png</file>
<file>xslt/commonTemplates.xsl</file>
<file>xslt/csv2xml.xslt</file>
<file>xslt/divelogs-export.xslt</file>
<file>xslt/divelogs.xslt</file>
<file>xslt/DivingLog.xslt</file>
<file>xslt/jdivelog2subsurface.xslt</file>
<file>xslt/MacDive.xslt</file>
<file>xslt/SuuntoDM4.xslt</file>
<file>xslt/SuuntoSDM.xslt</file>
<file>xslt/udcf.xslt</file>
<file>xslt/uddf-export.xslt</file>
<file>xslt/uddf.xslt</file>
</qresource>
</RCC>