First phase of facebookservice and situareservice integration.
[situare] / src / situareservice / situareservice.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
7    Situare is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License
9    version 2 as published by the Free Software Foundation.
10
11    Situare is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with Situare; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19    USA.
20 */
21
22
23 #ifndef SITUARESERVICE_H
24 #define SITUARESERVICE_H
25
26 #include <QObject>
27 #include <QPointF>
28 #include <QNetworkAccessManager>
29 #include <QNetworkRequest>
30 #include <QNetworkReply>
31 #include <QUrl>
32
33 #include "../facebookservice/facebookauthentication.h"  // not final
34 #include "../facebookservice/facebookcredentials.h"  // not final
35
36 /**
37 * @brief SituareService class for communicating with Situare server
38 *
39 * @class SituareService situareservice.h "situareservice/situareservice.h"
40 */
41 class SituareService : public QObject
42 {
43     Q_OBJECT
44
45 public:
46
47     /**
48     * @brief Default constructor
49     *
50     * @fn SituareService
51     * @param parent instance of parent
52     * @param manager instance of QNetworkAccessManager
53     */
54     SituareService(QObject *parent = 0, QNetworkAccessManager *manager = 0);
55     ~SituareService();
56
57     /**
58     * @brief Updates location to the Situare server
59     *
60     * @fn updateLocation
61     * @param coordinates current cordinates
62     * @param status message
63     * @param publish publish location on Facebook wall (true/false)
64     */
65     void updateLocation(QPointF coordinates, QString status, bool publish);
66
67     /**
68     * @brief Translates coordinates to street address via Situare server
69     *
70     * @fn reverseGeo
71     * @param coordinates coordinates to be translated
72     */
73     void reverseGeo(QPointF coordinates);
74
75     /**
76     * @brief Forms a http url
77     *
78     * @fn formUrl
79     * @param baseUrl Server url
80     * @param phpScript Server script
81     * @param urlParameters optional parameters for url
82     * @return QUrl formed url
83     */
84     QUrl formUrl(const QString baseUrl, const QString phpScript, QString urlParameters = 0);
85
86     /**
87     * @brief Forms url parameters
88     *
89     * @fn formUrlParameters
90     * @param coordinates current coordinates
91     * @param status optional status message
92     * @param publish optional publish location on Facebook wall (true/false)
93     * @return QString
94     */
95     QString formUrlParameters(QPointF coordinates, QString status = 0, QString publish = 0);
96
97     /**
98     * @brief Sends http request
99     *
100     * @fn sendRequest
101     * @param url destination
102     * @param cookieType type of the cookie
103     * @param cookie http cookie
104     */
105     void sendRequest(QUrl url, const QString cookieType, QString cookie);
106
107 signals:
108
109     /**
110     * @brief Signals error
111     *
112     * @fn error
113     * @param error error message
114     */
115     void error(const QString &error);
116
117 public slots:
118
119     /**
120     * @brief Public slot, which indicates when http request has been completed
121     *
122     * @fn requestFinished
123     * @param reply storage for http reply
124     */
125     void requestFinished(QNetworkReply *reply);
126
127
128     void credentialsReady(); // not final
129
130 private:
131     QNetworkAccessManager *networkManager;
132     QList<QNetworkReply *> currentRequests;
133     FacebookAuthentication facebookAuthentication; // not final
134     FacebookCredentials credentials; // not final
135 };
136
137 #endif // SITUARESERVICE_H