2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
6 Sami Rämö - sami.ramo@ixonos.com
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.
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.
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,
24 #ifndef SITUARESERVICE_H
25 #define SITUARESERVICE_H
29 #include "../user/user.h"
30 #include "imagefetcher.h"
32 class NetworkAccessManager;
34 class QNetworkRequest;
39 * @brief SituareService class for communicating with Situare server
41 * @author Henri Lampela
42 * @author Sami Rämö - sami.ramo (at) ixonos.com
44 class SituareService : public QObject
50 * @brief Request name enum
52 enum RequestName { RequestUnknown,
54 RequestUpdateLocation,
59 * @brief Default constructor
61 * @param parent instance of parent
63 SituareService(QObject *parent = 0);
71 /*******************************************************************************
72 * MEMBER FUNCTIONS AND SLOTS
73 ******************************************************************************/
76 * @brief Retrieves location user and friends information from Situare server
79 void fetchLocations();
82 * @brief Translates coordinates to street address via Situare server
84 * @param coordinates coordinates to be translated
86 void reverseGeo(const GeoCoordinate &coordinates);
89 * @brief Updates location to the Situare server
91 * @param coordinates current cordinates
92 * @param status message
93 * @param publish publish location on Facebook wall
95 void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
100 * @brief Public slot, to clear user data
103 void clearUserData();
106 * @brief Public slot, which indicates when http request has been completed
108 * @param reply storage for http reply
110 void requestFinished(QNetworkReply *reply);
113 * @brief Update session data
115 * @param session New session data
117 void updateSession(const QString &session);
122 * @brief Requests ImageFetcher if user/friend has a profile image
123 * uses members: m_user and m_friendsList
125 * @param imageUrlList list of image urls
127 void addProfileImages(const QList<QUrl> &imageUrlList);
130 * @brief Append access_token and other session data to the reques url
132 * @param[in,out] requestUrl Request URL with other request parameters and ending to &
134 void appendAccessToken(QString &requestUrl);
137 * @brief Convert coordinate value in degrees (double) to string with enough precision
139 * @param degrees Coordinate value in degrees
140 * @returns Coordinate value as string
142 QString degreesToString(double degrees);
145 * @brief Returns reuquest script's name.
147 * @param url url to check
148 * @return RequestName
150 SituareService::RequestName getRequestName(const QUrl &url) const;
153 * @brief Parses reply from JSON string
155 * Calls different parse methods or emits error signal if response contains error status.
157 void parseReply(const QByteArray &jsonReply, RequestName requestName);
160 * @brief Parses reverse geo data
162 * @param reverseGeoData reverse geo data QVariant tree
164 void parseReverseGeoData(const QVariant &reverseGeoData);
167 * @brief Parses user and friend data from JSON string
169 * @param userData user data QVariant tree
171 void parseUserData(const QVariant &userData);
174 * @brief Build and send request
176 * Appends script pathname and parameters to the server base URL. Access token is appended and
177 * the request sent if the access token is available, otherwise the request is queued.
179 * @param script Requested script pathname
180 * @param parameters Hash containing parameter key/value pairs.
182 void buildRequest(const QString &script, const QHash<QString,QString> ¶meters);
185 * @brief Send request
187 * @param requestUrl Request URL containing also all parameters
189 void sendRequest(const QString &requestUrl);
193 * @brief Slot for received images
195 * @param url Image url
196 * @param image Received image
198 void imageReceived(const QUrl &url, const QPixmap &image);
200 /*******************************************************************************
202 ******************************************************************************/
207 * @brief Signals error
209 * @param context error context
210 * @param error error code
212 void error(const int context, const int error);
215 * @brief Signal for image fetching
217 * @param url Image url
219 void fetchImage(const QUrl &url);
222 * @brief Signals when user's/friend's image is downloaded
224 * @param user Instance of user/friend
226 void imageReady(User *user);
229 * @brief Signals when address data is retrieved
231 * @param address Street address
233 void reverseGeoReady(const QString &address);
236 * @brief Signals when updateLocation request finished successfully
238 void updateWasSuccessful();
241 * @brief Signals when user data is retrieved
243 * @param user instance of user
244 * @param friendList list of friends
246 void userDataChanged(User *user, QList<User *> &friendList);
248 /*******************************************************************************
250 ******************************************************************************/
253 bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
255 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
256 QList<User *> m_friendsList; ///< List of friends(User)
258 QString m_session; ///< Session data
260 NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
262 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
263 User *m_user; ///< Pointer to User
266 #endif // SITUARESERVICE_H