Unity Scopes API
JsonReader.h
1 /*
2  * Copyright (C) 2014 Canonical Ltd
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more 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 
19 #pragma once
20 
21 #ifndef _ENABLE_QT_EXPERIMENTAL_
22 #error You should define _ENABLE_QT_EXPERIMENTAL_ in order to use this experimental header file.
23 #endif
24 
25 #include <QtCore/QJsonDocument>
26 #include <QtCore/QUrl>
27 
28 #include <memory>
29 #include <vector>
30 
31 namespace unity
32 {
33 
34 namespace scopes
35 {
36 
37 namespace qt
38 {
39 
40 class JsonAsyncReader;
41 
47 class JsonReader final
48 {
49 public:
51  JsonReader();
52  ~JsonReader() = default;
53 
54  typedef std::shared_ptr<QJsonDocument> QJsonDocumentSptr;
55 
56  typedef QVector<QPair<QString, QString>> QJsonParameters;
58 
65  QJsonDocumentSptr read(QUrl const& uri) const;
66 
74  QJsonDocumentSptr read(QString const& host, QJsonParameters const& parameters) const;
75 
76 private:
77  JsonReader(JsonReader const&) = delete;
78  JsonReader& operator=(JsonReader const&) = delete;
79 
80  std::shared_ptr<JsonAsyncReader> p_;
81 };
82 
83 } // namespace qt
84 
85 } // namespace scopes
86 
87 } // namespace unity
Class that downloads http JSON files synchronously.
Definition: JsonReader.h:47
Top-level namespace for all things Unity-related.
Definition: Version.h:49
QJsonDocumentSptr read(QUrl const &uri) const
Downloads a remote JSON document and returns a parser containing the data.