blob: 5f09fbe547f9d8e334513f1e3f4567b7d4e97bfd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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();
}
|