Fix author name in library and book info dialogs.
[dorian] / model / opshandler.h
1 #ifndef OPSHANDLER_H
2 #define OPSHANDLER_H
3
4 #include "xmlhandler.h"
5 #include "book.h"
6 #include "trace.h"
7
8 /** XML content handler for OPS format. */
9 class OpsHandler: public XmlHandler
10 {
11 public:
12     OpsHandler(Book &b): book(b), partCount(0) {
13         book.creators.clear();
14     }
15
16     bool endElement(const QString &namespaceUri, const QString &name,
17                     const QString &qName) {
18         (void)namespaceUri;
19         (void)qName;
20         if (currentText.size()) {
21             if (name == "title") {
22                 book.title = currentText;
23             } else if (name == "creator") {
24                 book.creators.append(currentText);
25             } else if (name == "publisher") {
26                 book.publisher = currentText;
27             } else if (name == "subject") {
28                 book.subject = currentText;
29             } else if (name == "source") {
30                 book.source = currentText;
31             } else if (name == "rights") {
32                 book.rights = currentText;
33             }
34         }
35         return true;
36     }
37
38     bool startElement(const QString &namespaceUri, const QString &name,
39                       const QString &qName, const QXmlAttributes &attrs) {
40         (void)namespaceUri;
41         (void)qName;
42         currentText = "";
43
44         if (name == "item") {
45             Book::ContentItem item;
46             item.href = attrs.value("href");
47             item.name = QString("Part %1").arg(partCount + 1);
48             item.size = 0;
49             QString key = attrs.value("id");
50             book.content[key] = item;
51             partCount++;
52         } else if (name == "itemref") {
53             book.parts.append(attrs.value("idref"));
54         }
55         return true;
56     }
57
58 private:
59     Book &book;
60     int partCount;
61 };
62
63 #endif // OPSHANDLER_H