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
|
/*
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.
*/
#include "scslainforeader.h"
#include <memory>
#include <QFile>
#include <QXmlStreamReader>
#include "scgzfile.h"
void ScSlaInfoReader::resetFileInfos(void)
{
m_title.resize(0);
m_author.resize(0);
m_format.resize(0);
}
bool ScSlaInfoReader::readInfos(const QString& fileName)
{
bool isScribusDocument = false;
bool readInfoSuccess = false;
bool firstStartElement = true;
std::auto_ptr<QIODevice> file;
resetFileInfos();
if (fileName.right(2).toLower() == "gz")
file.reset( new ScGzFile(fileName) );
else
file.reset( new QFile(fileName) );
if (!file.get() || !file->open(QIODevice::ReadOnly))
return false;
QByteArray bytes = file->read(512);
if (!bytes.contains("SCRIBUS") && !bytes.contains("SCRIBUSUTF8") && !bytes.contains("SCRIBUSUTF8NEW"))
{
file->close();
return false;
}
file->reset();
QXmlStreamReader reader(file.get());
while (!reader.atEnd() && !reader.hasError())
{
QXmlStreamReader::TokenType ttype = reader.readNext();
if (reader.hasError()) break;
if (ttype == QXmlStreamReader::StartElement)
{
QStringRef nodeName = reader.name();
if (firstStartElement)
{
if (nodeName == "SCRIBUS" || nodeName == "SCRIBUSUTF8" || nodeName == "SCRIBUSUTF8NEW")
{
QXmlStreamAttributes attrs = reader.attributes();
m_format = attrs.value(QLatin1String("Version")).toString();
isScribusDocument = true;
}
else
{
isScribusDocument = false;
break;
}
}
else if (nodeName == "DOCUMENT")
{
QXmlStreamAttributes attrs = reader.attributes();
m_title = attrs.value(QLatin1String("TITLE")).toString();
m_author = attrs.value(QLatin1String("AUTHOR")).toString();
readInfoSuccess = true;
break;
}
firstStartElement = false;
}
}
isScribusDocument &= !reader.hasError();
file->close();
return (isScribusDocument && readInfoSuccess);
}
|