Emit error signal when login fails
[situare] / src / routing / routingservice.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 ROUTINGSERVICE_H
24 #define ROUTINGSERVICE_H
25
26 #include <QObject>
27
28 class QNetworkReply;
29 class QUrl;
30
31 class GeoCoordinate;
32 class NetworkAccessManager;
33 class Route;
34
35 /**
36 * @brief RoutingService class for communicating with CloudMade server
37 *        and parsing routing data
38 *
39 * @author Henri Lampela - henri.lampela@ixonos.com
40 * @author Sami Rämö - sami.ramo@ixonos.com
41 */
42 class RoutingService : public QObject
43 {
44     Q_OBJECT
45
46 public:
47     /**
48     * @brief Default constructor
49     *
50     * @param parent instance of parent
51     */
52     RoutingService(QObject *parent = 0);
53
54 /*******************************************************************************
55  * MEMBER FUNCTIONS AND SLOTS
56  ******************************************************************************/
57 public slots:
58     /**
59     * @brief Public slot, which indicates when http request has been completed
60     *
61     * @param reply storage for http reply
62     */
63     void requestFinished(QNetworkReply *reply);
64
65     /**
66     * @brief Request routing information from the server
67     *
68     * @param from Start point of the route
69     * @param to End point of the route
70     */
71     void requestRoute(const GeoCoordinate &from, const GeoCoordinate &to);
72
73 private:
74     /**
75     * @brief Parses routing data from JSON string
76     *
77     * @param jsonReply JSON string
78     */
79     void parseRouteData(const QByteArray &jsonReply);
80
81     /**
82     * @brief Request authorization token
83     *
84     */
85     void requestAuthorizationToken();
86
87     /**
88     * @brief Sends http request
89     *
90     * @param url destination
91     */
92     void sendRequest(const QUrl &url);
93
94 /*******************************************************************************
95  * SIGNALS
96  ******************************************************************************/
97 signals:
98     /**
99     * @brief Signals error
100     *
101     * @param context error context
102     * @param error error code
103     */
104     void error(const int context, const int error);
105
106     /**
107     * @brief Emited when route is parsed and is ready for further processing
108     *
109     * @param route Route item containing parsed route details
110     */
111     void routeParsed(Route &route);
112
113 /*******************************************************************************
114  * DATA MEMBERS
115  ******************************************************************************/
116 private:
117     QString m_pendingRequest;                   ///< Placeholder for pending route request
118     QString m_token;                            ///< Placeholder for authentication token
119
120     NetworkAccessManager *m_networkManager;     ///< Pointer to QNetworkAccessManager
121 };
122
123 #endif // ROUTINGSERVICE_H