2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
6 Jussi Laitinen - jussi.laitinen@ixonos.com
7 Sami Rämö - sami.ramo@ixonos.com
9 Situare is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 version 2 as published by the Free Software Foundation.
13 Situare is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Situare; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 #ifndef SITUARESERVICE_H
26 #define SITUARESERVICE_H
30 #include "../user/user.h"
31 #include "imagefetcher.h"
35 class NetworkAccessManager;
37 class QNetworkRequest;
42 * @brief SituareService class for communicating with Situare server
44 * @author Henri Lampela
45 * @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
46 * @author Sami Rämö - sami.ramo (at) ixonos.com
48 class SituareService : public QObject
57 friend class TestSituareService;
59 enum SuccessfulMethod {SuccessfulUpdateLocation, SuccessfulAddTags, SuccessfulRemoveTags,
60 SuccessfulSendMessage, SuccessfulRemoveMessage};
63 * @brief Default constructor
65 * @param parent instance of parent
67 SituareService(NetworkAccessManager *networkManager, ImageFetcher *imageFetcher,
76 /*******************************************************************************
77 * MEMBER FUNCTIONS AND SLOTS
78 ******************************************************************************/
80 * @brief Retrieves people with similart interest (same tags).
82 * People is searched from area defined by south-west and north-east bounds.
83 * @param southWest south-west coordinates of bounds
84 * @param northEast north-east coordinates of bounds
86 void fetchPeopleWithSimilarInterest(const GeoCoordinate &southWestCoordinates,
87 const GeoCoordinate &northEastCoordinates);
90 * @brief Retrieves location user and friends information from Situare server
93 void fetchLocations();
96 * @brief Translates coordinates to street address via Situare server
98 * @param coordinates coordinates to be translated
100 void reverseGeo(const GeoCoordinate &coordinates);
103 * @brief Updates location to the Situare server
105 * @param coordinates current cordinates
106 * @param status message
107 * @param publish publish location on Facebook wall
109 void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
113 * @brief Adds tags to the Situare server
115 * CURRENTLY TAGS ARE UPDATED TO THE LOCAL DATABASE, NOT SITUARE SERVER
116 * @param tags list of user's tags
118 void addTags(const QStringList &tags);
121 * @brief Public slot, to clear user data
124 void clearUserData();
127 * @brief Retrieves messages sent to user.
129 void fetchMessages();
132 * @brief Retrieves popular tags.
134 * Tags are fetch from local database instead of Situare server.
136 void fetchPopularTags();
139 * @brief Removes message.
141 * @param id message ID
143 void removeMessage(const QString &id);
146 * @brief Removes tags.
148 * @param tags list of tags to remove
150 void removeTags(const QStringList &tags);
153 * @brief Public slot, which indicates when http request has been completed
155 * @param reply storage for http reply
157 void requestFinished(QNetworkReply *reply);
160 * @brief Searches people by tag name.
162 * @param tag tag name
164 void searchPeopleByTag(const QString &tag);
167 * @brief Sends a message to a person.
169 * @param receiverId Facebook user ID
170 * @param message message text
171 * @param message coordinates
173 void sendMessage(const QString &receiverId, const QString &message,
174 const GeoCoordinate &coordinates = GeoCoordinate());
177 * @brief Update session data
179 * @param session New session data
181 void updateSession(const QString &session);
185 * @brief Requests ImageFetcher if user/friend has a profile image
186 * uses members: m_user and m_friendsList
188 * @param imageUrlList list of image urls
190 void addProfileImages(const QHash<QString, QUrl> &imageUrlList);
193 * @brief Append access_token and other session data to the reques url
195 * @param[in,out] requestUrl Request URL with other request parameters and ending to &
197 void appendAccessToken(QString &requestUrl);
200 * @brief Build and send request
202 * Appends script pathname and parameters to the server base URL. Access token is appended and
203 * the request sent if the access token is available, otherwise the request is queued.
205 * @param script Requested script pathname
206 * @param parameters Hash containing parameter key/value pairs.
208 void buildRequest(const QString &script, const QHash<QString,QString> ¶meters);
211 * @brief Convert coordinate value in degrees (double) to string with enough precision
213 * @param degrees Coordinate value in degrees
214 * @returns Coordinate value as string
216 QString degreesToString(double degrees);
219 * @brief Temporary method to get tags.
221 * Tags are fetch from local database instead of Situare server.
223 * @return QStringList list of tags
225 QHash<QString, QString> getTags(const QString &userId);
228 * @brief Parses interesting people data from JSON string
230 * @param jsonReply JSON string
232 void parseInterestingPeopleData(const QByteArray &jsonReply);
235 * @brief Parses messages data from JSON string
237 * @param jsonReply JSON string
239 void parseMessagesData(const QByteArray &jsonReply);
242 * @brief Parses popular tags data from JSON string
244 * @param jsonReply JSON string
246 void parsePopularTagsData(const QByteArray &jsonReply);
249 * @brief Parses user and friend data from JSON string
251 * @param jsonReply JSON string
253 void parseUserData(const QByteArray &jsonReply);
256 * @brief Send request
258 * @param requestUrl Request URL containing also all parameters
260 void sendRequest(const QString &requestUrl);
264 * @brief Slot for received images
267 * @param image image pixmap
269 void imageReceived(const QString &id, const QPixmap &image);
271 /*******************************************************************************
273 ******************************************************************************/
276 * @brief Signals error
278 * @param context error context
279 * @param error error code
281 void error(const int context, const int error);
284 * @brief Signal for image fetching
287 * @param url Image url
289 void fetchImage(const QString &id, const QUrl &url);
292 * @brief Signals when image is downloaded
295 * @param image image pixmap
297 void imageReady(const QString &id, const QPixmap &image);
300 * @brief Signal when fetchPeopleWithSimilarInterest request is finished
302 * @param friends list of friends
303 * @param others list of other people
305 void interestingPeopleReceived(QList<User> &friends, QList<User> &others);
308 * @brief Signal when fetchMessages request is finished
310 * @param messages list of messages sent to user
312 void messagesReceived(QList<Message> &received, QList<Message> &sent);
315 * @brief Signals when fetchPopularTags request is finished
317 * @param popularTags list of popular tags
319 void popularTagsReceived(QHash<QString, QString> &popularTags);
322 * @brief Signals when address data is retrieved
324 * @param address Street address
326 void reverseGeoReady(const QString &address);
329 * @brief Signals when updateLocation request finished successfully
331 void updateWasSuccessful(SituareService::SuccessfulMethod successfulMethod);
334 * @brief Signals when user data is retrieved
336 * @param user instance of user
337 * @param friendList list of friends
339 void userDataChanged(User *user, QList<User *> &friendList);
341 /*******************************************************************************
343 ******************************************************************************/
345 bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
347 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
348 QList<User *> m_friendsList; ///< List of friends(User)
350 QString m_session; ///< Session data
352 Database *m_database; ///< Instance of the database
353 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
354 NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
355 User *m_user; ///< Pointer to User
358 #endif // SITUARESERVICE_H