adapt opensearch reader and writer for xml suggestions
[rekonq:nikhilms-mainline.git] / src / opensearch / suggestionparser.h
1 /* ============================================================
2  * 
3  * This file is a part of the rekonq project
4  *
5  * Copyright (C) 2010 by Lionel Chauvin <megabigbug@yahoo.fr>
6  * Copyright (C) 2010 by Andrea Diamantini <adjam7 at gmail dot com>
7  *
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License or (at your option) version 3 or any later version
13  * accepted by the membership of KDE e.V. (or its successor approved
14  * by the membership of KDE e.V.), which shall act as a proxy
15  * defined in Section 14 of version 3 of the license.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  *
25  * ============================================================ */
26
27 #ifndef SUGGESTIONPARSER_H
28 #define SUGGESTIONPARSER_H
29
30 // Self Includes
31
32 // Local Includes
33
34
35 // Qt Includes
36 #include <QList>
37 #include <QtScript/QScriptEngine>
38 #include <QtCore/QXmlStreamReader>
39
40
41 class Response
42 {
43 public:
44     QString title;
45     QString description;
46     QString url;
47     QString image;
48     int image_width;
49     int image_height;
50
51     Response(const Response &item) : title(item.title),
52                                      description(item.description),
53                                      url(item.url),
54                                      image(item.image),
55                                      image_width(item.image_width),
56                                      image_height(item.image_height)
57
58     {};
59
60     Response() : title(QString()),
61                  description(QString()),
62                  url(QString()),
63                  image(QString()),
64                  image_width(0),
65                  image_height(0)
66
67     {};
68
69     Response(const QString &_title = QString(),
70              const QString &_description = QString(),
71              const QString &_url  = QString(),
72              const QString &_image = QString(),
73              const int &_image_width = 0,
74              const int &_image_height = 0) : title(_title),
75                                              description(_description),
76                                              url(_url),
77                                              image(_image),
78                                              image_width(_image_width),
79                                              image_height(_image_height)
80     {};
81 };
82
83 typedef QList <Response> ResponseList;
84
85
86 class SuggestionParser
87 {
88 public:
89     virtual ~SuggestionParser();
90     virtual ResponseList parse(const QByteArray &resp);
91     virtual QString type(){ return ""; }
92 };
93
94
95 class XMLParser : public SuggestionParser
96 {   
97 protected:
98     QXmlStreamReader m_reader;
99
100 public:
101     ResponseList parse(const QByteArray &resp);
102     QString type(){ return "application/x-suggestions+xml"; }
103 };
104
105 class JSONParser : public SuggestionParser
106 {
107 private:
108     QScriptEngine m_reader;
109     
110 public:
111     ResponseList parse(const QByteArray &resp);
112     QString type(){ return "application/x-suggestions+json"; }
113 };
114
115 #endif //SUGGESTIONPARSER_H