summaryrefslogtreecommitdiffstats
path: root/scribus/nfttemplate.cpp
diff options
context:
space:
mode:
authorcraig <craig@11d20701-8431-0410-a711-e3c959e3b870>2012-01-01 11:40:09 +0000
committercraig <craig@11d20701-8431-0410-a711-e3c959e3b870>2012-01-01 11:40:09 +0000
commit7ed83b6c6666eb8b6b104c211ae7e52907350372 (patch)
tree4430b556abac0ad660a0aacf1887d77f85d8be02 /scribus/nfttemplate.cpp
downloadscribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.tar.gz
scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.tar.xz
scribus-7ed83b6c6666eb8b6b104c211ae7e52907350372.zip
Branch 1.3.5 tree to 1.4.x tree, goodbye 1.3.x
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17163 11d20701-8431-0410-a711-e3c959e3b870
Diffstat (limited to 'scribus/nfttemplate.cpp')
-rw-r--r--scribus/nfttemplate.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/scribus/nfttemplate.cpp b/scribus/nfttemplate.cpp
new file mode 100644
index 0000000..5f09fbe
--- /dev/null
+++ b/scribus/nfttemplate.cpp
@@ -0,0 +1,112 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+/***************************************************************************
+ * Riku Leino, tsoots@gmail.com *
+ ***************************************************************************/
+#include "nfttemplate.h"
+#include <QFileInfo>
+
+nfttemplate::nfttemplate(QFile* tmplXmlFile, const QString &tmplCategory)
+{
+ tmplXml = tmplXmlFile;
+ templateCategory = tmplCategory;
+ isWritable = tmplXml->open(QIODevice::WriteOnly | QIODevice::ReadOnly);
+ tmplXml->close();
+ isDeleted = false;
+}
+
+void nfttemplate::remove()
+{
+ if (tmplXml->exists())
+ {
+ QString newTmplXml = "";
+ QString tmp;
+ bool collect = false;
+ tmplXml->open(QIODevice::ReadOnly);
+ QTextStream stream(tmplXml);
+ stream.setCodec("UTF-8");
+ QString line = stream.readLine();
+ while (!line.isNull())
+ {
+ if ((line.indexOf(enCategory) != -1) || collect)
+ {
+ collect = true;
+ line += "\n";
+ tmp += line;
+ if (line.indexOf("name") != -1)
+ {
+ if (line.indexOf(name) == -1)
+ {
+ collect = false;
+ newTmplXml += tmp;
+ tmp = "";
+ }
+ }
+ else if (line.indexOf("file") != -1)
+ {
+ QString shortFile = file.right(file.length() - file.lastIndexOf("/") -1);
+ if (line.indexOf(shortFile) == -1)
+ {
+ collect = false;
+ newTmplXml += tmp;
+ tmp = "";
+ }
+ }
+ else if (line.indexOf("</template>") != -1)
+ {
+ collect = false;
+ tmp = "";
+ }
+ }
+ else
+ {
+ line += "\n";
+ newTmplXml += line;
+ }
+ line = stream.readLine();
+ }
+ tmplXml->close();
+ tmplXml->open(QIODevice::WriteOnly);
+ QTextStream instream(tmplXml);
+ instream.setCodec("UTF-8");
+ instream << newTmplXml;
+ tmplXml->close();
+ }
+}
+
+bool nfttemplate::canWrite()
+{
+ return isWritable;
+}
+
+bool nfttemplate::isValid()
+{
+ bool ret = true;
+
+ QFileInfo *fi = new QFileInfo(file);
+ if (!fi->exists())
+ ret = false;
+ delete fi;
+
+ fi = new QFileInfo(tnail);
+ if (!fi->exists())
+ ret = false;
+ delete fi;
+
+ fi = new QFileInfo(img);
+ if (!fi->exists())
+ ret = false;
+ delete fi;
+
+ return ret;
+}
+
+nfttemplate::~nfttemplate()
+{
+ if (isDeleted)
+ remove();
+}