Some cleanup for FacebookServices and SituareServices
[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 * @author Henri Lampela
40 * @class SituareService situareservice.h "situareservice/situareservice.h"
41 */
42 class SituareService : public QObject
43 {
44     Q_OBJECT
45
46 public:
47
48     /**
49     * @brief Default constructor
50     *
51     * @param parent instance of parent
52     * @param manager instance of QNetworkAccessManager
53     */
54     SituareService(QObject *parent = 0, QNetworkAccessManager *manager = 0);
55
56     /**
57     * @brief Destructor
58     *
59     */
60     ~SituareService();
61
62     /**
63     * @brief Updates location to the Situare server
64     *
65     * @param coordinates current cordinates
66     * @param status message
67     * @param publish publish location on Facebook wall (true/false)
68     */
69     void updateLocation(QPointF coordinates, QString status, bool publish);
70
71     /**
72     * @brief Translates coordinates to street address via Situare server
73     *
74     * @param coordinates coordinates to be translated
75     */
76     void reverseGeo(QPointF coordinates);
77
78 private:
79
80     /**
81     * @brief Forms a http url
82     *
83     * @param baseUrl Server url
84     * @param phpScript Server script
85     * @param urlParameters optional parameters for url
86     * @return QUrl formed url
87     */
88     QUrl formUrl(const QString baseUrl, const QString phpScript, QString urlParameters = 0);
89
90     /**
91     * @brief Forms url parameters
92     *
93     * @param coordinates current coordinates
94     * @param status optional status message
95     * @param publish optional publish location on Facebook wall (true/false)
96     * @return QString
97     */
98     QString formUrlParameters(QPointF coordinates, QString status = 0, QString publish = 0);
99
100     /**
101     * @brief Sends http request
102     *
103     * @param url destination
104     * @param cookieType type of the cookie
105     * @param cookie http cookie
106     */
107     void sendRequest(QUrl url, const QString cookieType, QString cookie);
108
109 signals:
110
111     /**
112     * @brief Signals error
113     *
114     * @param error error message
115     */
116     void error(const QString &error);
117
118 public slots:
119
120     /**
121     * @brief Public slot, which indicates when http request has been completed
122     *
123     * @param reply storage for http reply
124     */
125     void requestFinished(QNetworkReply *reply);
126
127
128     /**
129     * @brief Public slot, which indicates when facebook credentials are ready
130     *
131     */
132     void credentialsReady();
133
134 private:
135
136     FacebookCredentials credentials; ///< FacebookCredentials
137     QList<QNetworkReply *> currentRequests; ///< List of current http requests
138     FacebookAuthentication facebookAuthentication; ///< Pointer to FacebookAuthentication
139     QNetworkAccessManager *networkManager; ///< Pointer to QNetworkAccessManager
140 };
141
142 #endif // SITUARESERVICE_H