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
51 * @brief Default constructor
53 * @param parent instance of parent
55 SituareService(QObject *parent = 0);
63 /*******************************************************************************
64 * MEMBER FUNCTIONS AND SLOTS
65 ******************************************************************************/
68 * @brief Retrieves location user and friends information from Situare server
71 void fetchLocations();
74 * @brief Translates coordinates to street address via Situare server
76 * @param coordinates coordinates to be translated
78 void reverseGeo(const GeoCoordinate &coordinates);
81 * @brief Updates location to the Situare server
83 * @param coordinates current cordinates
84 * @param status message
85 * @param publish publish location on Facebook wall
87 void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
92 * @brief Public slot, to clear user data
98 * @brief Public slot, which indicates when http request has been completed
100 * @param reply storage for http reply
102 void requestFinished(QNetworkReply *reply);
105 * @brief Update session data
107 * @param session New session data
109 void updateSession(const QString &session);
114 * @brief Requests ImageFetcher if user/friend has a profile image
115 * uses members: m_user and m_friendsList
117 * @param imageUrlList list of image urls
119 void addProfileImages(const QList<QUrl> &imageUrlList);
122 * @brief Append access_token and other session data to the reques url
124 * @param[in,out] requestUrl Request URL with other request parameters and ending to &
126 void appendAccessToken(QString &requestUrl);
129 * @brief Convert coordinate value in degrees (double) to string with enough precision
131 * @param degrees Coordinate value in degrees
132 * @returns Coordinate value as string
134 QString degreesToString(double degrees);
137 * @brief Parses user and friend data from JSON string
139 * @param jsonReply JSON string
141 void parseUserData(const QByteArray &jsonReply);
144 * @brief Build and send request
146 * Appends script pathname and parameters to the server base URL. Access token is appended and
147 * the request sent if the access token is available, otherwise the request is queued.
149 * @param script Requested script pathname
150 * @param parameters Hash containing parameter key/value pairs.
152 void buildRequest(const QString &script, const QHash<QString,QString> ¶meters);
155 * @brief Send request
157 * @param requestUrl Request URL containing also all parameters
159 void sendRequest(const QString &requestUrl);
163 * @brief Slot for received images
165 * @param url Image url
166 * @param image Received image
168 void imageReceived(const QUrl &url, const QPixmap &image);
170 /*******************************************************************************
172 ******************************************************************************/
177 * @brief Signals error
179 * @param context error context
180 * @param error error code
182 void error(const int context, const int error);
185 * @brief Signal for image fetching
187 * @param url Image url
189 void fetchImage(const QUrl &url);
192 * @brief Signals when user's/friend's image is downloaded
194 * @param user Instance of user/friend
196 void imageReady(User *user);
199 * @brief Signals when address data is retrieved
201 * @param address Street address
203 void reverseGeoReady(const QString &address);
206 * @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 ******************************************************************************/
223 bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
225 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
226 QList<User *> m_friendsList; ///< List of friends(User)
228 QString m_session; ///< Session data
230 NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
232 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
233 User *m_user; ///< Pointer to User
236 #endif // SITUARESERVICE_H