X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=opshandler.h;fp=opshandler.h;h=6e1ee01b66ac17a6d9178c8800159dd9ffbecc08;hb=76446a14739779702a024d207be9fb52da36bd24;hp=0000000000000000000000000000000000000000;hpb=39dea9c13887fbcfe77bd35d90c96667807f9f6e;p=dorian diff --git a/opshandler.h b/opshandler.h new file mode 100644 index 0000000..6e1ee01 --- /dev/null +++ b/opshandler.h @@ -0,0 +1,89 @@ +#ifndef OPSHANDLER_H +#define OPSHANDLER_H + +#include + +#include "book.h" + +/** XML content handler for OPS format. */ +class OpsHandler: public QXmlContentHandler +{ +public: + OpsHandler(Book &book): mBook(book) {} + 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) + { + mCurrentText += ch; + return true; + } + + bool endElement(const QString &namespaceUri, const QString &name, + const QString &qName) + { + (void)namespaceUri; + (void)qName; + if (mCurrentText != "") { + if (name == "title") { + mBook.title = mCurrentText; + } + else if (name == "creator") { + mBook.creators.append(mCurrentText); + } + else if (name == "publisher") { + mBook.publisher = mCurrentText; + } + else if (name == "subject") { + mBook.subject = mCurrentText; + } + else if (name == "source") { + mBook.source = mCurrentText; + } + else if (name == "rights") { + mBook.rights = mCurrentText; + } + } + return true; + } + + bool startElement(const QString &namespaceUri, const QString &name, + const QString &qName, const QXmlAttributes &attrs) + { + (void)namespaceUri; + (void)name; + (void)qName; + (void)attrs; + mCurrentText = ""; + + if (name == "item") { + Book::ContentItem item; + item.href = mBook.rootPath() + "/" + attrs.value("href"); + item.type = attrs.value("media-type"); + QString key = attrs.value("id"); + mBook.content[key] = item; + qDebug() << "OpsHandler::startElement: item" << key << "type" + << item.type << "href" << item.href; + } + else if (name == "itemref") { + mBook.toc.append(attrs.value("idref")); + qDebug() << "OpsHandler::startElement: itemref" << attrs.value("idref"); + } + return true; + } + +private: + Book &mBook; + QString mCurrentText; +}; + +#endif // OPSHANDLER_H