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,
73 friend class TestSituareService;
75 enum SuccessfulMethod {SuccessfulUpdateLocation, SuccessfulAddTags, SuccessfulRemoveTags,
76 SuccessfulSendMessage, SuccessfulRemoveMessage};
79 * @brief Default constructor
81 * @param parent instance of parent
83 SituareService(NetworkAccessManager *networkManager, ImageFetcher *imageFetcher,
92 /*******************************************************************************
93 * MEMBER FUNCTIONS AND SLOTS
94 ******************************************************************************/
96 * @brief Retriesves user tags.
98 * @return QStringList list of tags
103 * @brief Retrieves people with similart interest (same tags).
105 * People is searched from area defined by maximum distance
106 * @param maximumDistance maximum distance to people
108 void fetchPeopleWithSimilarInterest(const qreal distance);
111 * @brief Retrieves location user and friends information from Situare server
114 void fetchLocations();
117 * @brief Translates coordinates to street address via Situare server
119 * @param coordinates coordinates to be translated
121 void reverseGeo(const GeoCoordinate &coordinates);
124 * @brief Updates location to the Situare server
126 * @param coordinates current cordinates
127 * @param status message
128 * @param publish publish location on Facebook wall
130 void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
134 * @brief Adds tags to the Situare server
136 * CURRENTLY TAGS ARE UPDATED TO THE LOCAL DATABASE, NOT SITUARE SERVER
137 * @param tags list of user's tags
139 void addTags(const QStringList &tags);
142 * @brief Public slot, to clear user data
145 void clearUserData();
148 * @brief Retrieves messages sent to user.
150 void fetchMessages();
153 * @brief Retrieves popular tags.
155 * Tags are fetch from local database instead of Situare server.
157 void fetchPopularTags();
160 * @brief Removes message.
162 * @param id message ID
164 void removeMessage(const QString &id);
167 * @brief Removes tags.
169 * @param tags list of tags to remove
171 void removeTags(const QStringList &tags);
174 * @brief Public slot, which indicates when http request has been completed
176 * @param reply storage for http reply
178 void requestFinished(QNetworkReply *reply);
181 * @brief Searches people by tag name.
183 * @param tag tag name
185 void searchPeopleByTag(const QString &tag);
188 * @brief Sends a message to a person.
190 * @param receiverId Facebook user ID
191 * @param message message text
192 * @param message coordinates
194 void sendMessage(const QString &receiverId, const QString &message,
195 const GeoCoordinate &coordinates = GeoCoordinate());
198 * @brief Update session data
200 * @param session New session data
202 void updateSession(const QString &session);
206 * @brief Requests ImageFetcher if user/friend has a profile image
207 * uses members: m_user and m_friendsList
209 * @param imageUrlList list of image urls
211 void addProfileImages(const QHash<QString, QUrl> &imageUrlList);
214 * @brief Append access_token and other session data to the reques url
216 * @param[in,out] requestUrl Request URL with other request parameters and ending to &
218 void appendAccessToken(QString &requestUrl);
221 * @brief Build and send request
223 * Appends script pathname and parameters to the server base URL. Access token is appended and
224 * the request sent if the access token is available, otherwise the request is queued.
226 * @param script Requested script pathname
227 * @param parameters Hash containing parameter key/value pairs.
229 void buildRequest(const QString &script, const QHash<QString,QString> ¶meters);
232 * @brief Convert coordinate value in degrees (double) to string with enough precision
234 * @param degrees Coordinate value in degrees
235 * @returns Coordinate value as string
237 QString degreesToString(double degrees);
240 * @brief Returns reuquest script's name.
242 * @param url url to check
243 * @return RequestName
245 SituareService::RequestName getRequestName(const QUrl &url) const;
248 * @brief Parses interesting people data from JSON string
250 * @param interestingPeopleData interesting people data QVariant tree
252 void parseInterestingPeopleData(const QVariant &interestingPeopleData);
255 * @brief Parses messages data from JSON string
257 * @param messagesData messages data QVariant tree
259 void parseMessagesData(const QVariant &messagesData);
262 * @brief Parses popular tags data from JSON string
264 * @param popularTagsData popular tags data QVariant tree
266 void parsePopularTagsData(const QVariant &popularTagsData);
269 * @brief Parses reply from JSON string
271 * Calls different parse methods or emits error signal if response contains error status.
273 void parseReply(const QByteArray &jsonReply, RequestName requestName);
276 * @brief Parses reverse geo data
278 * @param reverseGeoData reverse geo data QVariant tree
280 void parseReverseGeoData(const QVariant &reverseGeoData);
283 * @brief Parses user tags data from JSON string
285 * @param userTagsData user tags data QVariant tree
287 void parseUserTagsData(const QVariant &userTagsData);
290 * @brief Parses user and friend data from JSON string
292 * @param userData user data QVariant tree
294 void parseUserData(const QVariant &userData);
297 * @brief Send request
299 * @param requestUrl Request URL containing also all parameters
301 void sendRequest(const QString &requestUrl);
305 * @brief Slot for received images
308 * @param image image pixmap
310 void imageReceived(const QString &id, const QPixmap &image);
312 /*******************************************************************************
314 ******************************************************************************/
317 * @brief Signals error
319 * @param context error context
320 * @param error error code
322 void error(const int context, const int error);
325 * @brief Signal for image fetching
328 * @param url Image url
330 void fetchImage(const QString &id, const QUrl &url);
333 * @brief Signals when image is downloaded
336 * @param image image pixmap
338 void imageReady(const QString &id, const QPixmap &image);
341 * @brief Signal when fetchPeopleWithSimilarInterest request is finished
343 * @param friends list of friends
344 * @param others list of other people
346 void interestingPeopleReceived(QList<User> &friends, QList<User> &others);
349 * @brief Signal when fetchMessages request is finished
351 * @param messages list of messages sent to user
353 void messagesReceived(QList<Message> &received, QList<Message> &sent);
356 * @brief Signals when fetchPopularTags request is finished
358 * @param popularTags list of popular tags
360 void popularTagsReceived(QHash<QString, QString> &popularTags);
363 * @brief Signals when address data is retrieved
365 * @param address Street address
367 void reverseGeoReady(const QString &address);
370 * @brief Signals when updateLocation request finished successfully
372 void updateWasSuccessful(SituareService::SuccessfulMethod successfulMethod);
375 * @brief Signals when user data is retrieved
377 * @param user instance of user
378 * @param friendList list of friends
380 void userDataChanged(User *user, QList<User *> &friendList);
383 * @brief Signals when getTags request is finished
385 * @param userTags list of user tags
387 void userTagsReceived(QHash<QString, QString> &userTags);
389 /*******************************************************************************
391 ******************************************************************************/
393 bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
395 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
396 QList<User *> m_friendsList; ///< List of friends(User)
398 QString m_session; ///< Session data
400 Database *m_database; ///< Instance of the database
401 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
402 NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
403 User *m_user; ///< Pointer to User
406 #endif // SITUARESERVICE_H