Initial steps to keep library in a database.
[dorian] / model / ncxhandler.h
1 #ifndef NCXHANDLER_H
2 #define NCXHANDLER_H
3
4 #include "xmlhandler.h"
5 #include "book.h"
6 #include "trace.h"
7
8 /** XML content handler for NCX format. */
9 class NcxHandler: public XmlHandler
10 {
11 public:
12     NcxHandler(Book &b): book(b) {
13         book.chapters.clear();
14     }
15
16     bool endElement(const QString &namespaceUri, const QString &name,
17                     const QString &qName) {
18         (void)namespaceUri;
19         (void)qName;
20         if (name == "text") {
21             contentTitle = currentText;
22         } else if (name == "navPoint") {
23             qDebug() << "NcxHander::endElement: url" << contentUrl << "title"
24                     << contentTitle << "id" << contentId;
25             Book::ContentItem item;
26             item.href = contentUrl;
27             item.name = contentTitle;
28             book.content[contentId] = item;
29             book.chapters.append(contentId);
30         }
31         return true;
32     }
33
34     bool startElement(const QString &namespaceUri, const QString &name,
35                       const QString &qName, const QXmlAttributes &attrs) {
36         (void)namespaceUri;
37         (void)qName;
38         currentText = "";
39         if (name == "navPoint") {
40             contentId = attrs.value("id");
41         } else if (name == "content") {
42             contentUrl = attrs.value("src");
43         }
44         return true;
45     }
46
47 private:
48     Book &book;
49     QString contentId;
50     QString contentUrl;
51     QString contentTitle;
52 };
53
54 #endif // NCXHANDLER_H