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:
Lubomir I. Ivanov 2015-10-19 00:25:14 +03:00 committed by Dirk Hohndel
parent dbd07af59f
commit 894e7d5d39
5 changed files with 46 additions and 9 deletions

View file

@ -152,7 +152,7 @@ void PrintOptions::on_importButton_clicked()
if (filename.isEmpty())
return;
QFileInfo fileInfo(filename);
QFile::copy(filename, getSubsurfaceDataPath("printing_templates") + QDir::separator() + fileInfo.fileName());
QFile::copy(filename, getPrintingTemplatePathUser() + QDir::separator() + fileInfo.fileName());
printOptions->p_template = fileInfo.fileName();
find_all_templates();
setup();
@ -164,7 +164,7 @@ void PrintOptions::on_exportButton_clicked()
tr("HTML files (*.html)"));
if (filename.isEmpty())
return;
QFile::copy(getSubsurfaceDataPath("printing_templates") + QDir::separator() + getSelectedTemplate(), filename);
QFile::copy(getPrintingTemplatePathUser() + QDir::separator() + getSelectedTemplate(), filename);
}
void PrintOptions::on_deleteButton_clicked()
@ -176,7 +176,7 @@ void PrintOptions::on_deleteButton_clicked()
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Cancel);
if (msgBox.exec() == QMessageBox::Ok) {
QFile f(getSubsurfaceDataPath("printing_templates") + QDir::separator() + templateName);
QFile f(getPrintingTemplatePathUser() + QDir::separator() + templateName);
f.remove();
find_all_templates();
setup();