2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
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.
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.
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,
23 #ifndef SITUARESERVICE_H
24 #define SITUARESERVICE_H
28 #include "../user/user.h"
29 #include "imagefetcher.h"
31 class NetworkAccessManager;
33 class QNetworkRequest;
38 * @brief SituareService class for communicating with Situare server
40 * @author Henri Lampela
41 * @class SituareService situareservice.h "situareservice/situareservice.h"
43 class SituareService : public QObject
50 * @brief Default constructor
52 * @param parent instance of parent
54 SituareService(QObject *parent = 0);
62 /*******************************************************************************
63 * MEMBER FUNCTIONS AND SLOTS
64 ******************************************************************************/
67 * @brief Retrieves location user and friends information from Situare server
70 void fetchLocations();
73 * @brief Translates coordinates to street address via Situare server
75 * @param coordinates coordinates to be translated
77 void reverseGeo(const GeoCoordinate &coordinates);
80 * @brief Updates location to the Situare server
82 * @param coordinates current cordinates
83 * @param status message
84 * @param publish publish location on Facebook wall
86 void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
91 * @brief Public slot, to clear user data
97 * @brief Public slot, which indicates when http request has been completed
99 * @param reply storage for http reply
101 void requestFinished(QNetworkReply *reply);
104 * @brief Update session data
106 * @param session New session data
108 void updateSession(const QString &session);
113 * @brief Requests ImageFetcher if user/friend has a profile image
114 * uses members: m_user and m_friendsList
116 * @param imageUrlList list of image urls
118 void addProfileImages(const QList<QUrl> &imageUrlList);
121 * @brief Append access_token and other session data to the reques url
123 * @param[in,out] requestUrl Request URL with other request parameters and ending to &
125 void appendAccessToken(QString &requestUrl);
128 * @brief Convert coordinate value in degrees (double) to string with enough precision
130 * @param degrees Coordinate value in degrees
131 * @returns Coordinate value as string
133 QString degreesToString(double degrees);
136 * @brief Parses user and friend data from JSON string
138 * @param jsonReply JSON string
140 void parseUserData(const QByteArray &jsonReply);
143 * @brief Build and send request
145 * Appends script pathname and parameters to the server base URL. Access token is appended and
146 * the request sent if the access token is available, otherwise the request is queued.
148 * @param script Requested script pathname
149 * @param parameters Hash containing parameter key/value pairs.
151 void buildRequest(const QString &script, const QHash<QString,QString> ¶meters);
154 * @brief Send request
156 * @param requestUrl Request URL containing also all parameters
158 void sendRequest(const QString &requestUrl);
162 * @brief Slot for received images
164 * @param url Image url
165 * @param image Received image
167 void imageReceived(const QUrl &url, const QPixmap &image);
169 /*******************************************************************************
171 ******************************************************************************/
176 * @brief Signals error
178 * @param context error context
179 * @param error error code
181 void error(const int context, const int error);
184 * @brief Signal for image fetching
186 * @param url Image url
188 void fetchImage(const QUrl &url);
191 * @brief Signals when user's/friend's image is downloaded
193 * @param user Instance of user/friend
195 void imageReady(User *user);
198 * @brief Signals when address data is retrieved
200 * @param address Street address
202 void reverseGeoReady(const QString &address);
205 * @brief Signals when updateLocation request finished successfully
208 void updateWasSuccessful();
211 * @brief Signals when user data is retrieved
213 * @param user instance of user
214 * @param friendList list of friends
216 void userDataChanged(User *user, QList<User *> &friendList);
218 /*******************************************************************************
220 ******************************************************************************/
224 bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
226 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
227 QList<QString> m_requestsWaitingAccessToken; ///< Requests waiting for access_token
228 QList<User *> m_friendsList; ///< List of friends(User)
230 QString m_session; ///< Session data
232 NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
234 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
235 User *m_user; ///< Pointer to User
238 #endif // SITUARESERVICE_H