4 #include "xmlhandler.h"
8 /** XML content handler for NCX format. */
9 class NcxHandler: public XmlHandler
14 TreeItem(const QString &i, TreeItem *p = 0): id(i), parent(p) {
16 parent->children.append(this);
17 depth = parent->depth + 1;
25 void addToBook(Book &book) {
26 Book::ContentItem contentItem;
27 contentItem.href = href;
28 contentItem.name = QString(" ").repeated(depth) + name;
30 book.content[id] = contentItem;
31 book.chapters.append(id);
32 qDebug() << "TreeItem::addToBook" << id << contentItem.href
34 foreach (TreeItem *child, children) {
35 child->addToBook(book);
38 QList<TreeItem *> children;
46 NcxHandler(Book &b): book(b), rootItem(0), currentItem(0) {
47 book.chapters.clear();
54 bool endElement(const QString &namespaceUri, const QString &name,
55 const QString &qName) {
61 currentItem->name = currentText;
64 } else if (name == "navPoint") {
66 currentItem = currentItem->parent;
67 if (currentItem == 0) {
68 // Root navigation point reached, dump TOC tree
69 rootItem->addToBook(book);
78 bool startElement(const QString &namespaceUri, const QString &name,
79 const QString &qName, const QXmlAttributes &attrs) {
83 if (name == "navPoint") {
84 TreeItem *item = new TreeItem(attrs.value("id"), currentItem);
89 } else if (name == "content") {
91 currentItem->href = attrs.value("src");
101 QString contentTitle;
103 TreeItem *currentItem;
106 #endif // NCXHANDLER_H