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
54 * @brief Request name enum
56 enum RequestName { RequestUnknown,
58 RequestUpdateLocation,
63 RequestGetPeopleWithSimilarInterest,
64 RequestGetPopularTags,
68 RequestGetPeopleWithTag };
75 friend class TestSituareService;
77 enum SuccessfulMethod {SuccessfulUpdateLocation, SuccessfulAddTags, SuccessfulRemoveTags,
78 SuccessfulSendMessage, SuccessfulRemoveMessage};
81 * @brief Default constructor
83 * @param parent instance of parent
85 SituareService(NetworkAccessManager *networkManager, ImageFetcher *imageFetcher,
94 /*******************************************************************************
95 * MEMBER FUNCTIONS AND SLOTS
96 ******************************************************************************/
98 * @brief Retriesves user tags.
100 * @return QStringList list of tags
105 * @brief Retrieves people with similart interest (same tags).
107 * People is searched from area defined by maximum distance
108 * @param maximumDistance maximum distance to people
110 void fetchPeopleWithSimilarInterest(const qreal distance);
113 * @brief Retrieves location user and friends information from Situare server
116 void fetchLocations();
119 * @brief Translates coordinates to street address via Situare server
121 * @param coordinates coordinates to be translated
123 void reverseGeo(const GeoCoordinate &coordinates);
126 * @brief Updates location to the Situare server
128 * @param coordinates current cordinates
129 * @param status message
130 * @param publish publish location on Facebook wall
132 void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
136 * @brief Adds tags to the Situare server
138 * CURRENTLY TAGS ARE UPDATED TO THE LOCAL DATABASE, NOT SITUARE SERVER
139 * @param tags list of user's tags
141 void addTags(const QStringList &tags);
144 * @brief Public slot, to clear user data
147 void clearUserData();
150 * @brief Retrieves messages sent to user.
152 void fetchMessages();
155 * @brief Retrieves popular tags.
157 * Tags are fetch from local database instead of Situare server.
159 void fetchPopularTags();
162 * @brief Removes message.
164 * @param id message ID
166 void removeMessage(const QString &id);
169 * @brief Removes tags.
171 * @param tags list of tags to remove
173 void removeTags(const QStringList &tags);
176 * @brief Public slot, which indicates when http request has been completed
178 * @param reply storage for http reply
180 void requestFinished(QNetworkReply *reply);
183 * @brief Searches people by tag name.
185 * @param tag tag name
187 void searchPeopleByTag(const QString &tag);
190 * @brief Sends a message to a person.
192 * @param receiverId Facebook user ID
193 * @param message message text
194 * @param message coordinates
196 void sendMessage(const QString &receiverId, const QString &message,
197 const GeoCoordinate &coordinates = GeoCoordinate());
200 * @brief Update session data
202 * @param session New session data
204 void updateSession(const QString &session);
208 * @brief Requests ImageFetcher if user/friend has a profile image
209 * uses members: m_user and m_friendsList
211 * @param imageUrlList list of image urls
213 void addProfileImages(const QHash<QString, QUrl> &imageUrlList);
216 * @brief Append access_token and other session data to the reques url
218 * @param[in,out] requestUrl Request URL with other request parameters and ending to &
220 void appendAccessToken(QString &requestUrl);
223 * @brief Build and send request
225 * Appends script pathname and parameters to the server base URL. Access token is appended and
226 * the request sent if the access token is available, otherwise the request is queued.
228 * @param script Requested script pathname
229 * @param parameters Hash containing parameter key/value pairs.
231 void buildRequest(const QString &script, const QHash<QString,QString> ¶meters);
234 * @brief Convert coordinate value in degrees (double) to string with enough precision
236 * @param degrees Coordinate value in degrees
237 * @returns Coordinate value as string
239 QString degreesToString(double degrees);
242 * @brief Returns reuquest script's name.
244 * @param url url to check
245 * @return RequestName
247 SituareService::RequestName getRequestName(const QUrl &url) const;
250 * @brief Parses interesting people data from JSON string
252 * @param interestingPeopleData interesting people data QVariant tree
254 void parseInterestingPeopleData(const QVariant &interestingPeopleData);
257 * @brief Parses messages data from JSON string
259 * @param messagesData messages data QVariant tree
261 void parseMessagesData(const QVariant &messagesData);
264 * @brief Parses popular tags data from JSON string
266 * @param popularTagsData popular tags data QVariant tree
268 void parsePopularTagsData(const QVariant &popularTagsData);
271 * @brief Parses reply from JSON string
273 * Calls different parse methods or emits error signal if response contains error status.
275 void parseReply(const QByteArray &jsonReply, RequestName requestName);
278 * @brief Parses reverse geo data
280 * @param reverseGeoData reverse geo data QVariant tree
282 void parseReverseGeoData(const QVariant &reverseGeoData);
285 * @brief Parses user tags data from JSON string
287 * @param userTagsData user tags data QVariant tree
289 void parseUserTagsData(const QVariant &userTagsData);
292 * @brief Parses user and friend data from JSON string
294 * @param userData user data QVariant tree
296 void parseUserData(const QVariant &userData);
299 * @brief Send request
301 * @param requestUrl Request URL containing also all parameters
303 void sendRequest(const QString &requestUrl);
307 * @brief Slot for received images
310 * @param image image pixmap
312 void imageReceived(const QString &id, const QPixmap &image);
314 /*******************************************************************************
316 ******************************************************************************/
319 * @brief Signals error
321 * @param context error context
322 * @param error error code
324 void error(const int context, const int error);
327 * @brief Signal for image fetching
330 * @param url Image url
332 void fetchImage(const QString &id, const QUrl &url);
335 * @brief Signals when image is downloaded
338 * @param image image pixmap
340 void imageReady(const QString &id, const QPixmap &image);
343 * @brief Signal when fetchPeopleWithSimilarInterest request is finished
345 * @param friends list of friends
346 * @param others list of other people
348 void interestingPeopleReceived(QList<User> &friends, QList<User> &others);
351 * @brief Signal when fetchMessages request is finished
353 * @param messages list of messages sent to user
355 void messagesReceived(QList<Message> &received, QList<Message> &sent);
358 * @brief Signals when fetchPopularTags request is finished
360 * @param popularTags list of popular tags
362 void popularTagsReceived(QHash<QString, QString> &popularTags);
365 * @brief Signals when address data is retrieved
367 * @param address Street address
369 void reverseGeoReady(const QString &address);
372 * @brief Signals when updateLocation request finished successfully
374 void updateWasSuccessful(SituareService::SuccessfulMethod successfulMethod);
377 * @brief Signals when user data is retrieved
379 * @param user instance of user
380 * @param friendList list of friends
382 void userDataChanged(User *user, QList<User *> &friendList);
385 * @brief Signals when getTags request is finished
387 * @param userTags list of user tags
389 void userTagsReceived(QHash<QString, QString> &userTags);
391 /*******************************************************************************
393 ******************************************************************************/
395 bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
397 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
398 QList<User *> m_friendsList; ///< List of friends(User)
400 QString m_session; ///< Session data
402 Database *m_database; ///< Instance of the database
403 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
404 NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
405 User *m_user; ///< Pointer to User
408 #endif // SITUARESERVICE_H