X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=model%2Fopshandler.h;h=1d961c88c90d9c9f9e19874d82316f4e6a62a5fc;hb=4f46de1a517b4d92eed3debb8f3f7012c51a5653;hp=e27f7668e77f2cfe83377fe42d1cb75a3131e64c;hpb=d73e3bc69c913c97373e1f0e3be72b73091c33bb;p=dorian diff --git a/model/opshandler.h b/model/opshandler.h index e27f766..1d961c8 100644 --- a/model/opshandler.h +++ b/model/opshandler.h @@ -1,38 +1,23 @@ #ifndef OPSHANDLER_H #define OPSHANDLER_H -#include - +#include "xmlhandler.h" #include "book.h" #include "trace.h" /** XML content handler for OPS format. */ -class OpsHandler: public QXmlContentHandler +class OpsHandler: public XmlHandler { public: - OpsHandler(Book &b): book(b), partCount(0) {} - bool endDocument() {return true;} - bool endPrefixMapping(const QString &) {return true;} - QString errorString() const {return "";} - bool ignorableWhitespace(const QString &) {return true;} - bool processingInstruction(const QString &, const QString &) { - return true; - } - void setDocumentLocator(QXmlLocator *) {} - bool skippedEntity(const QString &) {return true;} - bool startDocument() {return true;} - bool startPrefixMapping(const QString &, const QString &) {return true;} - - bool characters(const QString &ch) { - currentText += ch; - return true; + OpsHandler(Book &b): book(b), partCount(0) { + book.creators.clear(); } bool endElement(const QString &namespaceUri, const QString &name, const QString &qName) { (void)namespaceUri; (void)qName; - if (currentText != "") { + if (currentText.size()) { if (name == "title") { book.title = currentText; } else if (name == "creator") { @@ -52,32 +37,26 @@ public: bool startElement(const QString &namespaceUri, const QString &name, const QString &qName, const QXmlAttributes &attrs) { - Trace t("OpsHandler::startElement" + name); (void)namespaceUri; (void)qName; currentText = ""; if (name == "item") { Book::ContentItem item; - item.href = book.rootPath() + "/" + attrs.value("href"); + item.href = attrs.value("href"); item.name = QString("Part %1").arg(partCount + 1); + item.size = 0; QString key = attrs.value("id"); book.content[key] = item; partCount++; - t.trace(QString("name: ") + item.name); - t.trace(QString("href: ") + attrs.value("href")); - t.trace(QString("id: ") + key); - } - else if (name == "itemref") { - t.trace(QString("id: ") + attrs.value("idref")); - book.toc.append(attrs.value("idref")); + } else if (name == "itemref") { + book.parts.append(attrs.value("idref")); } return true; } private: Book &book; - QString currentText; int partCount; };