summaryrefslogtreecommitdiffstats
path: root/templatelayout.cpp
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2015-10-19 00:25:14 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-18 17:37:49 -0700
commit894e7d5d39b8e926d06a10e7eb70300cb93bd374 (patch)
tree3808dae1c5a8dc16eb963e63ff5ec99eef032d39 /templatelayout.cpp
parentdbd07af59fd14d20e529c3561fb6cfc3a8fb1814 (diff)
downloadsubsurface-894e7d5d39b8e926d06a10e7eb70300cb93bd374.tar.gz
Print: copy the bundled templates to a safe location
This patch adds couple of helpers to retrieve the template path in the application bundle (getPrintingTemplatePathBundle()) and the template path in the user directory (getPrintingTemplatePathUser()). Once the print dialog is initiated for the first time the contents of the bundled template path are copied to the user template path using copyPath(). No overwriting of files will occur. The PrintOptions and TemplateLayout classes then only use the user path for retrieving templates. Fixes an issue where the bundled templates can be locked as read-only on OSX and Linux. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'templatelayout.cpp')
-rw-r--r--templatelayout.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/templatelayout.cpp b/templatelayout.cpp
index 161200d62..a376459a6 100644
--- a/templatelayout.cpp
+++ b/templatelayout.cpp
@@ -25,7 +25,7 @@ void find_all_templates()
{
grantlee_templates.clear();
grantlee_statistics_templates.clear();
- QDir dir(getSubsurfaceDataPath("printing_templates"));
+ QDir dir(getPrintingTemplatePathUser());
QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
foreach (QFileInfo finfo, list) {
QString filename = finfo.fileName();
@@ -34,7 +34,7 @@ void find_all_templates()
}
}
// find statistics templates
- dir.setPath(getSubsurfaceDataPath("printing_templates") + QDir::separator() + "statistics");
+ dir.setPath(getPrintingTemplatePathUser() + QDir::separator() + "statistics");
list = dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
foreach (QFileInfo finfo, list) {
QString filename = finfo.fileName();
@@ -66,7 +66,7 @@ QString TemplateLayout::generate()
QSharedPointer<Grantlee::FileSystemTemplateLoader> m_templateLoader =
QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader());
- m_templateLoader->setTemplateDirs(QStringList() << getSubsurfaceDataPath("printing_templates"));
+ m_templateLoader->setTemplateDirs(QStringList() << getPrintingTemplatePathUser());
m_engine->addTemplateLoader(m_templateLoader);
Grantlee::registerMetaType<Dive>();
@@ -113,7 +113,7 @@ QString TemplateLayout::generateStatistics()
QSharedPointer<Grantlee::FileSystemTemplateLoader> m_templateLoader =
QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader());
- m_templateLoader->setTemplateDirs(QStringList() << getSubsurfaceDataPath("printing_templates/statistics"));
+ m_templateLoader->setTemplateDirs(QStringList() << getPrintingTemplatePathUser() + QDir::separator() + QString("statistics"));
m_engine->addTemplateLoader(m_templateLoader);
Grantlee::registerMetaType<YearInfo>();
@@ -153,7 +153,7 @@ QString TemplateLayout::generateStatistics()
QString TemplateLayout::readTemplate(QString template_name)
{
- QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name);
+ QFile qfile(getPrintingTemplatePathUser() + QDir::separator() + template_name);
if (qfile.open(QFile::ReadOnly | QFile::Text)) {
QTextStream in(&qfile);
return in.readAll();
@@ -163,7 +163,7 @@ QString TemplateLayout::readTemplate(QString template_name)
void TemplateLayout::writeTemplate(QString template_name, QString grantlee_template)
{
- QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name);
+ QFile qfile(getPrintingTemplatePathUser() + QDir::separator() + template_name);
if (qfile.open(QFile::ReadWrite | QFile::Text)) {
qfile.write(grantlee_template.toUtf8().data());
qfile.resize(qfile.pos());