diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-11-23 01:59:26 +0200 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-11-24 21:50:12 +0200 |
commit | 9209382c1868045baf49da42c5700da43556a49f (patch) | |
tree | 74315c1c768e1c658ed48b20de4579cd14179916 /desktop-widgets | |
parent | 6895c0eca5550b449ee616b7d3b3c5beb8b54ab3 (diff) | |
download | subsurface-9209382c1868045baf49da42c5700da43556a49f.tar.gz |
printing: add set_bundled_templates_as_read_only()
Add the function set_bundled_templates_as_read_only()
in templatelayout.cpp/h. The function is used to
mark the bundled template files as read-only in
the user folder. It is called in mainwindow.cpp,
after the files are copied from the bundle.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 1 | ||||
-rw-r--r-- | desktop-widgets/templatelayout.cpp | 24 | ||||
-rw-r--r-- | desktop-widgets/templatelayout.h | 1 |
3 files changed, 26 insertions, 0 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index f685a2b74..05314af1d 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -258,6 +258,7 @@ MainWindow::MainWindow() : QMainWindow(), #ifndef NO_PRINTING // copy the bundled print templates to the user path; no overwriting occurs! copyPath(getPrintingTemplatePathBundle(), getPrintingTemplatePathUser()); + set_bundled_templates_as_read_only(); find_all_templates(); #endif diff --git a/desktop-widgets/templatelayout.cpp b/desktop-widgets/templatelayout.cpp index 9f933e91c..b53f55741 100644 --- a/desktop-widgets/templatelayout.cpp +++ b/desktop-widgets/templatelayout.cpp @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#include <QFileDevice> #include <string> #include "templatelayout.h" @@ -39,6 +40,29 @@ void find_all_templates() } } +/* find templates which are part of the bundle in the user path + * and set them as read only. + */ +void set_bundled_templates_as_read_only() +{ + QDir dir; + const QString stats("statistics"); + QStringList list, listStats; + QString pathBundle = getPrintingTemplatePathBundle(); + QString pathUser = getPrintingTemplatePathUser(); + + dir.setPath(pathBundle); + list = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); + dir.setPath(pathBundle + QDir::separator() + stats); + listStats = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); + for (int i = 0; i < listStats.length(); i++) + listStats[i] = stats + QDir::separator() + listStats.at(i); + list += listStats; + + foreach (const QString& f, list) + QFile::setPermissions(pathUser + QDir::separator() + f, QFileDevice::ReadOwner | QFileDevice::ReadUser); +} + TemplateLayout::TemplateLayout(print_options *PrintOptions, template_options *templateOptions) : m_engine(NULL) { diff --git a/desktop-widgets/templatelayout.h b/desktop-widgets/templatelayout.h index 9c24d096d..8ec4eadc7 100644 --- a/desktop-widgets/templatelayout.h +++ b/desktop-widgets/templatelayout.h @@ -12,6 +12,7 @@ int getTotalWork(print_options *printOptions); void find_all_templates(); +void set_bundled_templates_as_read_only(); extern QList<QString> grantlee_templates, grantlee_statistics_templates; |