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
32
qthelper.cpp
32
qthelper.cpp
|
|
@ -942,6 +942,38 @@ QString getSubsurfaceDataPath(QString folderToFind)
|
|||
return QString("");
|
||||
}
|
||||
|
||||
static const char *printing_templates = "printing_templates";
|
||||
|
||||
QString getPrintingTemplatePathUser()
|
||||
{
|
||||
static QString path = QString();
|
||||
if (path.isEmpty())
|
||||
path = QString(system_default_directory()) + QDir::separator() + QString(printing_templates);
|
||||
return path;
|
||||
}
|
||||
|
||||
QString getPrintingTemplatePathBundle()
|
||||
{
|
||||
static QString path = QString();
|
||||
if (path.isEmpty())
|
||||
path = getSubsurfaceDataPath(printing_templates);
|
||||
return path;
|
||||
}
|
||||
|
||||
void copyPath(QString src, QString dst)
|
||||
{
|
||||
QDir dir(src);
|
||||
if (!dir.exists())
|
||||
return;
|
||||
foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
||||
QString dst_path = dst + QDir::separator() + d;
|
||||
dir.mkpath(dst_path);
|
||||
copyPath(src + QDir::separator() + d, dst_path);
|
||||
}
|
||||
foreach (QString f, dir.entryList(QDir::Files))
|
||||
QFile::copy(src + QDir::separator() + f, dst + QDir::separator() + f);
|
||||
}
|
||||
|
||||
int gettimezoneoffset(timestamp_t when)
|
||||
{
|
||||
QDateTime dt1, dt2;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue