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 foreach (TreeItem *child, children) {
33 child->addToBook(book);
36 QList<TreeItem *> children;
44 NcxHandler(Book &b): book(b), rootItem(0), currentItem(0) {
45 book.chapters.clear();
52 bool endElement(const QString &namespaceUri, const QString &name,
53 const QString &qName) {
59 currentItem->name = currentText;
62 } else if (name == "navPoint") {
64 currentItem = currentItem->parent;
65 if (currentItem == 0) {
66 // Root navigation point reached, dump TOC tree
67 rootItem->addToBook(book);
76 bool startElement(const QString &namespaceUri, const QString &name,
77 const QString &qName, const QXmlAttributes &attrs) {
81 if (name == "navPoint") {
82 TreeItem *item = new TreeItem(attrs.value("id"), currentItem);
87 } else if (name == "content") {
89 currentItem->href = attrs.value("src");
101 TreeItem *currentItem;
104 #endif // NCXHANDLER_H