From 605e1e2d93996f57b3e48f698d840f517d84a99d Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 5 Jul 2015 06:21:39 +0200 Subject: [PATCH] Printing: add functions that read/write a template Read/write templates from files. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- templatelayout.cpp | 19 +++++++++++++++++++ templatelayout.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/templatelayout.cpp b/templatelayout.cpp index fcdd22902..9a9dc9656 100644 --- a/templatelayout.cpp +++ b/templatelayout.cpp @@ -89,6 +89,25 @@ QString TemplateLayout::generate() return htmlContent; } +QString TemplateLayout::readTemplate(QString template_name) +{ + QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name); + if (qfile.open(QFile::ReadOnly | QFile::Text)) { + QTextStream in(&qfile); + return in.readAll(); + } + return ""; +} + +void TemplateLayout::writeTemplate(QString template_name, QString grantlee_template) +{ + QFile qfile(getSubsurfaceDataPath("printing_templates") + QDir::separator() + template_name); + if (qfile.open(QFile::ReadWrite | QFile::Text)) { + qfile.write(grantlee_template.toUtf8().data()); + qfile.close(); + } +} + Dive::Dive() : m_number(-1), dive(NULL) diff --git a/templatelayout.h b/templatelayout.h index 854a16259..3826c6c00 100644 --- a/templatelayout.h +++ b/templatelayout.h @@ -14,6 +14,8 @@ public: TemplateLayout(print_options *PrintOptions, template_options *templateOptions); ~TemplateLayout(); QString generate(); + static QString readTemplate(QString template_name); + static void writeTemplate(QString template_name, QString grantlee_template); private: Grantlee::Engine *m_engine;