Unity Scopes Qt library
JsonReader.h
1 /*
2  * Copyright (C) 2014 Canonical, Ltd.
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of version 3 of the GNU Lesser General Public License as published
6  * by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
17  */
18 #pragma once
19 
20 #ifndef _ENABLE_QT_EXPERIMENTAL_
21 #error You should define _ENABLE_QT_EXPERIMENTAL_ in order to use this experimental header file.
22 #endif
23 
24 #include <QtCore/QJsonDocument>
25 #include <QtCore/QUrl>
26 
27 #include <memory>
28 #include <vector>
29 
30 namespace unity
31 {
32 
33 namespace scopes
34 {
35 
36 namespace qt
37 {
38 
39 class JsonAsyncReader;
40 
46 class JsonReader final
47 {
48 public:
50  JsonReader();
51  ~JsonReader() = default;
52 
53  typedef std::shared_ptr<QJsonDocument> QJsonDocumentSptr;
54 
55  typedef QVector<QPair<QString, QString>> QJsonParameters;
57 
64  QJsonDocumentSptr read(QUrl const& uri) const;
65 
73  QJsonDocumentSptr read(QString const& host, QJsonParameters const& parameters) const;
74 
75 private:
76  JsonReader(JsonReader const&) = delete;
77  JsonReader& operator=(JsonReader const&) = delete;
78 
79  std::shared_ptr<JsonAsyncReader> p_;
80 };
81 
82 } // namespace qt
83 
84 } // namespace scopes
85 
86 } // namespace unity
Class that downloads http JSON files synchronously.
Definition: JsonReader.h:46
Definition: HttpAsyncReader.h:39
QJsonDocumentSptr read(QUrl const &uri) const
Downloads a remote JSON document and returns a parser containing the data.