|
@@ -9,14 +9,14 @@
|
|
// FbReadThread
|
|
// FbReadThread
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
-void FbReadThread::execute(QObject *parent, QXmlInputSource *source, QIODevice *device)
|
|
|
|
|
|
+void FbReadThread::execute(QObject *parent, QString *source, QIODevice *device)
|
|
{
|
|
{
|
|
FbReadThread *thread = new FbReadThread(parent, source, device);
|
|
FbReadThread *thread = new FbReadThread(parent, source, device);
|
|
connect(thread, SIGNAL(html(QString, FbStore*)), parent, SLOT(html(QString, FbStore*)));
|
|
connect(thread, SIGNAL(html(QString, FbStore*)), parent, SLOT(html(QString, FbStore*)));
|
|
thread->start();
|
|
thread->start();
|
|
}
|
|
}
|
|
|
|
|
|
-FbReadThread::FbReadThread(QObject *parent, QXmlInputSource *source, QIODevice *device)
|
|
|
|
|
|
+FbReadThread::FbReadThread(QObject *parent, QString *source, QIODevice *device)
|
|
: QThread(parent)
|
|
: QThread(parent)
|
|
, m_device(device)
|
|
, m_device(device)
|
|
, m_source(source)
|
|
, m_source(source)
|
|
@@ -50,32 +50,20 @@ bool FbReadThread::parse()
|
|
connect(&handler, SIGNAL(error(int,int,QString)), parent(), SIGNAL(error(int,int,QString)));
|
|
connect(&handler, SIGNAL(error(int,int,QString)), parent(), SIGNAL(error(int,int,QString)));
|
|
connect(&handler, SIGNAL(fatal(int,int,QString)), parent(), SIGNAL(fatal(int,int,QString)));
|
|
connect(&handler, SIGNAL(fatal(int,int,QString)), parent(), SIGNAL(fatal(int,int,QString)));
|
|
|
|
|
|
-#ifdef FB2_USE_LIBXML2
|
|
|
|
XML2::XmlReader reader;
|
|
XML2::XmlReader reader;
|
|
-#else
|
|
|
|
- QXmlSimpleReader reader;
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
reader.setContentHandler(&handler);
|
|
reader.setContentHandler(&handler);
|
|
reader.setLexicalHandler(&handler);
|
|
reader.setLexicalHandler(&handler);
|
|
reader.setErrorHandler(&handler);
|
|
reader.setErrorHandler(&handler);
|
|
|
|
|
|
-#ifdef FB2_USE_LIBXML2
|
|
|
|
if (m_device) {
|
|
if (m_device) {
|
|
return reader.parse(m_device);
|
|
return reader.parse(m_device);
|
|
} else {
|
|
} else {
|
|
return reader.parse(m_source);
|
|
return reader.parse(m_source);
|
|
}
|
|
}
|
|
-#else
|
|
|
|
- if (m_device) {
|
|
|
|
- m_source = new QXmlInputSource();
|
|
|
|
- m_source->setData(m_device->readAll());
|
|
|
|
- }
|
|
|
|
- return reader.parse(m_source);
|
|
|
|
-#endif
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-/*
|
|
|
|
|
|
+#if 0
|
|
FbReadThread::FbReadThread(QObject *parent, const QString &filename, const QString &xml)
|
|
FbReadThread::FbReadThread(QObject *parent, const QString &filename, const QString &xml)
|
|
: QThread(parent)
|
|
: QThread(parent)
|
|
, m_temp(0)
|
|
, m_temp(0)
|
|
@@ -98,8 +86,6 @@ void FbReadThread::run()
|
|
if (parse()) emit html(m_html);
|
|
if (parse()) emit html(m_html);
|
|
}
|
|
}
|
|
|
|
|
|
-#ifdef FB2_USE_LIBXML2
|
|
|
|
-
|
|
|
|
bool FbReadThread::parse()
|
|
bool FbReadThread::parse()
|
|
{
|
|
{
|
|
QXmlStreamWriter writer(&m_html);
|
|
QXmlStreamWriter writer(&m_html);
|
|
@@ -121,36 +107,8 @@ bool FbReadThread::parse()
|
|
return reader.parse(source);
|
|
return reader.parse(source);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-#else
|
|
|
|
-
|
|
|
|
-bool FbReadThread::parse()
|
|
|
|
-{
|
|
|
|
- QXmlStreamWriter writer(&m_html);
|
|
|
|
- FbReadHandler handler(*this, writer);
|
|
|
|
- connect(&handler, SIGNAL(binary(QString,QByteArray)), this, SLOT(data(QString,QByteArray)));
|
|
|
|
- QXmlSimpleReader reader;
|
|
|
|
- reader.setContentHandler(&handler);
|
|
|
|
- reader.setLexicalHandler(&handler);
|
|
|
|
- reader.setErrorHandler(&handler);
|
|
|
|
- QXmlInputSource source;
|
|
|
|
- if (m_xml.isEmpty()) {
|
|
|
|
- QFile file(m_filename);
|
|
|
|
- if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
|
|
|
- qCritical() << QObject::tr("Cannot read file %1: %2.").arg(m_filename).arg(file.errorString());
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- source.setData(file.readAll());
|
|
|
|
- } else {
|
|
|
|
- source.setData(m_xml);
|
|
|
|
- }
|
|
|
|
- return reader.parse(source);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-*/
|
|
|
|
-
|
|
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
// FbReadHandler::RootHandler
|
|
// FbReadHandler::RootHandler
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
@@ -168,7 +126,7 @@ FbReadHandler::RootHandler::RootHandler(FbReadHandler &owner, const QString &nam
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
-FbXmlHandler::NodeHandler * FbReadHandler::RootHandler::NewTag(const QString &name, const QXmlAttributes &atts)
|
|
|
|
|
|
+FbXmlHandler::NodeHandler * FbReadHandler::RootHandler::NewTag(const QString &name, const QXmlStreamAttributes &atts)
|
|
{
|
|
{
|
|
switch (toKeyword(name)) {
|
|
switch (toKeyword(name)) {
|
|
case Binary: return new BinaryHandler(m_owner, name, atts);
|
|
case Binary: return new BinaryHandler(m_owner, name, atts);
|
|
@@ -260,7 +218,7 @@ FB2_BEGIN_KEYHASH(FbReadHandler::TextHandler)
|
|
FB2_KEY( Code , "code" );
|
|
FB2_KEY( Code , "code" );
|
|
FB2_END_KEYHASH
|
|
FB2_END_KEYHASH
|
|
|
|
|
|
-FbReadHandler::TextHandler::TextHandler(FbReadHandler &owner, const QString &name, const QXmlAttributes &atts, const QString &tag)
|
|
|
|
|
|
+FbReadHandler::TextHandler::TextHandler(FbReadHandler &owner, const QString &name, const QXmlStreamAttributes &atts, const QString &tag)
|
|
: BaseHandler(owner, name)
|
|
: BaseHandler(owner, name)
|
|
, m_parent(NULL)
|
|
, m_parent(NULL)
|
|
, m_tag(tag)
|
|
, m_tag(tag)
|
|
@@ -269,7 +227,7 @@ FbReadHandler::TextHandler::TextHandler(FbReadHandler &owner, const QString &nam
|
|
Init(name, atts);
|
|
Init(name, atts);
|
|
}
|
|
}
|
|
|
|
|
|
-FbReadHandler::TextHandler::TextHandler(TextHandler *parent, const QString &name, const QXmlAttributes &atts, const QString &tag)
|
|
|
|
|
|
+FbReadHandler::TextHandler::TextHandler(TextHandler *parent, const QString &name, const QXmlStreamAttributes &atts, const QString &tag)
|
|
: BaseHandler(parent->m_owner, name)
|
|
: BaseHandler(parent->m_owner, name)
|
|
, m_parent(parent)
|
|
, m_parent(parent)
|
|
, m_tag(tag)
|
|
, m_tag(tag)
|
|
@@ -278,26 +236,25 @@ FbReadHandler::TextHandler::TextHandler(TextHandler *parent, const QString &name
|
|
Init(name, atts);
|
|
Init(name, atts);
|
|
}
|
|
}
|
|
|
|
|
|
-void FbReadHandler::TextHandler::Init(const QString &name, const QXmlAttributes &atts)
|
|
|
|
|
|
+void FbReadHandler::TextHandler::Init(const QString &name, const QXmlStreamAttributes &atts)
|
|
{
|
|
{
|
|
Keyword key = toKeyword(name);
|
|
Keyword key = toKeyword(name);
|
|
writer().writeStartElement(m_tag);
|
|
writer().writeStartElement(m_tag);
|
|
- int count = atts.count();
|
|
|
|
- for (int i = 0; i < count; ++i) {
|
|
|
|
- QString name = atts.qName(i);
|
|
|
|
|
|
+ for (const auto& attr : atts) {
|
|
|
|
+ QString name = attr.qualifiedName().toString();
|
|
switch (key) {
|
|
switch (key) {
|
|
- case Anchor: { if (atts.localName(i) == "href") name = "href"; break; }
|
|
|
|
- case Image: { if (atts.localName(i) == "href") name = "src"; break; }
|
|
|
|
|
|
+ case Anchor: { if (attr.name() == "href") name = "href"; break; }
|
|
|
|
+ case Image: { if (attr.name() == "href") name = "src"; break; }
|
|
default: ;
|
|
default: ;
|
|
}
|
|
}
|
|
- writer().writeAttribute(name, atts.value(i));
|
|
|
|
|
|
+ writer().writeAttribute(name, attr.value().toString());
|
|
}
|
|
}
|
|
if (m_tag == "p" && (name == "text-author" || name == "subtitle")) {
|
|
if (m_tag == "p" && (name == "text-author" || name == "subtitle")) {
|
|
writer().writeAttribute("fb:class", name);
|
|
writer().writeAttribute("fb:class", name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-FbXmlHandler::NodeHandler * FbReadHandler::TextHandler::NewTag(const QString &name, const QXmlAttributes &atts)
|
|
|
|
|
|
+FbXmlHandler::NodeHandler * FbReadHandler::TextHandler::NewTag(const QString &name, const QXmlStreamAttributes &atts)
|
|
{
|
|
{
|
|
m_empty = false;
|
|
m_empty = false;
|
|
QString tag;
|
|
QString tag;
|
|
@@ -346,7 +303,7 @@ bool FbReadHandler::TextHandler::isNotes() const
|
|
// FbReadHandler::BinaryHandler
|
|
// FbReadHandler::BinaryHandler
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
-FbReadHandler::BinaryHandler::BinaryHandler(FbReadHandler &owner, const QString &name, const QXmlAttributes &atts)
|
|
|
|
|
|
+FbReadHandler::BinaryHandler::BinaryHandler(FbReadHandler &owner, const QString &name, const QXmlStreamAttributes &atts)
|
|
: BaseHandler(owner, name)
|
|
: BaseHandler(owner, name)
|
|
, m_file(Value(atts, "id"))
|
|
, m_file(Value(atts, "id"))
|
|
{
|
|
{
|
|
@@ -360,26 +317,21 @@ void FbReadHandler::BinaryHandler::TxtTag(const QString &text)
|
|
void FbReadHandler::BinaryHandler::EndTag(const QString &name)
|
|
void FbReadHandler::BinaryHandler::EndTag(const QString &name)
|
|
{
|
|
{
|
|
Q_UNUSED(name);
|
|
Q_UNUSED(name);
|
|
- QByteArray in; in.append(m_text);
|
|
|
|
- if (!m_file.isEmpty()) m_owner.addFile(m_file, QByteArray::fromBase64(in));
|
|
|
|
|
|
+ if (!m_file.isEmpty()) m_owner.addFile(m_file, QByteArray::fromBase64(m_text.toUtf8()));
|
|
}
|
|
}
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
// FbReadHandler
|
|
// FbReadHandler
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
-bool FbReadHandler::load(QObject *page, QXmlInputSource &source, QString &html)
|
|
|
|
|
|
+bool FbReadHandler::load(QObject *page, QString &source, QString &html)
|
|
{
|
|
{
|
|
QXmlStreamWriter writer(&html);
|
|
QXmlStreamWriter writer(&html);
|
|
FbReadHandler handler(writer);
|
|
FbReadHandler handler(writer);
|
|
|
|
|
|
connect(&handler, SIGNAL(binary(QString,QByteArray)), page, SLOT(binary(QString,QByteArray)));
|
|
connect(&handler, SIGNAL(binary(QString,QByteArray)), page, SLOT(binary(QString,QByteArray)));
|
|
|
|
|
|
-#ifdef FB2_USE_LIBXML2
|
|
|
|
XML2::XmlReader reader;
|
|
XML2::XmlReader reader;
|
|
-#else
|
|
|
|
- QXmlSimpleReader reader;
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
reader.setContentHandler(&handler);
|
|
reader.setContentHandler(&handler);
|
|
reader.setLexicalHandler(&handler);
|
|
reader.setLexicalHandler(&handler);
|
|
@@ -402,7 +354,7 @@ FbReadHandler::~FbReadHandler()
|
|
m_writer.writeEndElement();
|
|
m_writer.writeEndElement();
|
|
}
|
|
}
|
|
|
|
|
|
-FbXmlHandler::NodeHandler * FbReadHandler::CreateRoot(const QString &name, const QXmlAttributes &atts)
|
|
|
|
|
|
+FbXmlHandler::NodeHandler * FbReadHandler::CreateRoot(const QString &name, const QXmlStreamAttributes &atts)
|
|
{
|
|
{
|
|
Q_UNUSED(atts);
|
|
Q_UNUSED(atts);
|
|
if (name == "fictionbook") return new RootHandler(*this, name);
|
|
if (name == "fictionbook") return new RootHandler(*this, name);
|