mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
dbd07af59f
commit
894e7d5d39
5 changed files with 46 additions and 9 deletions
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue