1 | /* |
2 | * Copyright 2011 Jon Ander PeƱalba <jonan88@gmail.com> |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #ifndef XMLHANDLER_H |
27 | #define XMLHANDLER_H |
28 | |
29 | #include <QtXml/QXmlContentHandler> |
30 | |
31 | struct Example |
32 | { |
33 | QString name, fileName; |
34 | bool plasmoid; |
35 | |
36 | bool operator == (const Example &e) const |
37 | {return name == e.name;} |
38 | }; |
39 | |
40 | struct Category |
41 | { |
42 | QString name, dirName; |
43 | QList<Example> examples; |
44 | |
45 | bool operator == (const Category &c) const |
46 | {return name == c.name;} |
47 | }; |
48 | |
49 | class XmlHandler : public QXmlContentHandler |
50 | { |
51 | public: |
52 | QList<Category> getCategories() {return m_categories;} |
53 | |
54 | virtual bool startElement(const QString &namespaceURI, |
55 | const QString &localName, |
56 | const QString &qName, |
57 | const QXmlAttributes &atts); |
58 | |
59 | // Not needed |
60 | virtual bool startDocument() {return true;} |
61 | virtual bool endDocument() {return true;} |
62 | virtual void setDocumentLocator(QXmlLocator* /*locator*/) {} |
63 | virtual bool startPrefixMapping(const QString& /*prefix*/, |
64 | const QString& /*uri*/) {return true;} |
65 | virtual bool endPrefixMapping(const QString& /*prefix*/) {return true;} |
66 | virtual bool endElement(const QString& /*namespaceURI*/, |
67 | const QString& /*localName*/, |
68 | const QString& /*qName*/) {return true;} |
69 | virtual bool characters(const QString& /*ch*/) {return true;} |
70 | virtual bool ignorableWhitespace(const QString& /*ch*/) {return true;} |
71 | virtual bool processingInstruction(const QString& /*target*/, |
72 | const QString& /*data*/) {return true;} |
73 | virtual bool skippedEntity(const QString& /*name*/) {return true;} |
74 | virtual QString errorString() const {return "true" ;} |
75 | |
76 | private: |
77 | QList<Category> m_categories; |
78 | }; |
79 | |
80 | #endif // XMLHANDLER_H |
81 | |