Emit error signal when login fails
[situare] / src / routing / geocodingservice.h
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Henri Lampela - henri.lampela@ixonos.com
6         Sami Rämö - sami.ramo@ixonos.com
7
8     Situare is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License
10     version 2 as published by the Free Software Foundation.
11
12     Situare is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with Situare; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20     USA.
21 */
22
23 #ifndef GEOCODINGSERVICE_H
24 #define GEOCODINGSERVICE_H
25
26 #include <QObject>
27
28 #include "location.h"
29
30 class QNetworkReply;
31 class QUrl;
32
33 class NetworkAccessManager;
34
35 /**
36 * @brief Geocoding service
37 *
38 * Searching coordinates for places based on names and addresses. Parsing the result json data into
39 * list.
40 *
41 * @author Henri Lampela - henri.lampela@ixonos.com
42 * @author Sami Rämö - sami.ramo@ixonos.com
43 */
44 class GeocodingService : public QObject
45 {
46     Q_OBJECT
47
48 public:
49     /**
50     * @brief Default constructor
51     *
52     * @param parent instance of parent
53     */
54     GeocodingService(QObject *parent = 0);
55
56 /*******************************************************************************
57  * MEMBER FUNCTIONS AND SLOTS
58  ******************************************************************************/
59 public slots:
60     /**
61     * @brief Public slot, which indicates when http request has been completed
62     *
63     * @param reply storage for http reply
64     */
65     void requestFinished(QNetworkReply *reply);
66
67     /**
68     * @brief Request location information from the server
69     *
70     * @param location location (address, city etc.)
71     */
72     void requestLocation(const QString &location);
73
74 private:
75     /**
76     * @brief Parses location data from JSON string
77     *
78     * @param jsonReply JSON string
79     */
80     void parseSearchResults(const QByteArray &jsonReply);
81
82     /**
83     * @brief Sends http request
84     *
85     * @param url destination
86     */
87     void sendRequest(const QUrl &url);
88
89 /*******************************************************************************
90  * SIGNALS
91  ******************************************************************************/
92 signals:
93     /**
94     * @brief Signals error
95     *
96     * @param context error context
97     * @param error error code
98     */
99     void error(const int context, const int error);
100
101     /**
102     * @brief Emited when location request is parsed and is ready for further processing
103     *
104     * @param result List of Location items
105     */
106     void locationDataParsed(const QList<Location> &result);
107
108 /*******************************************************************************
109  * DATA MEMBERS
110  ******************************************************************************/
111 private:
112     QList<Location> m_searchResults;            ///< List of search results
113
114     NetworkAccessManager *m_networkManager;     ///< Pointer to QNetworkAccessManager
115 };
116
117 #endif // GEOCODINGSERVICE_H