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};
71 friend class TestSituareService;
73 enum SuccessfulMethod {SuccessfulUpdateLocation, SuccessfulAddTags, SuccessfulRemoveTags,
74 SuccessfulSendMessage, SuccessfulRemoveMessage};
77 * @brief Default constructor
79 * @param parent instance of parent
81 SituareService(NetworkAccessManager *networkManager, ImageFetcher *imageFetcher,
90 /*******************************************************************************
91 * MEMBER FUNCTIONS AND SLOTS
92 ******************************************************************************/
94 * @brief Retrieves people with similart interest (same tags).
96 * People is searched from area defined by maximum distance
97 * @param maximumDistance maximum distance to people
99 void fetchPeopleWithSimilarInterest(const qreal distance);
102 * @brief Retrieves location user and friends information from Situare server
105 void fetchLocations();
108 * @brief Translates coordinates to street address via Situare server
110 * @param coordinates coordinates to be translated
112 void reverseGeo(const GeoCoordinate &coordinates);
115 * @brief Updates location to the Situare server
117 * @param coordinates current cordinates
118 * @param status message
119 * @param publish publish location on Facebook wall
121 void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
125 * @brief Adds tags to the Situare server
127 * CURRENTLY TAGS ARE UPDATED TO THE LOCAL DATABASE, NOT SITUARE SERVER
128 * @param tags list of user's tags
130 void addTags(const QStringList &tags);
133 * @brief Public slot, to clear user data
136 void clearUserData();
139 * @brief Retrieves messages sent to user.
141 void fetchMessages();
144 * @brief Retrieves popular tags.
146 * Tags are fetch from local database instead of Situare server.
148 void fetchPopularTags();
151 * @brief Removes message.
153 * @param id message ID
155 void removeMessage(const QString &id);
158 * @brief Removes tags.
160 * @param tags list of tags to remove
162 void removeTags(const QStringList &tags);
165 * @brief Public slot, which indicates when http request has been completed
167 * @param reply storage for http reply
169 void requestFinished(QNetworkReply *reply);
172 * @brief Searches people by tag name.
174 * @param tag tag name
176 void searchPeopleByTag(const QString &tag);
179 * @brief Sends a message to a person.
181 * @param receiverId Facebook user ID
182 * @param message message text
183 * @param message coordinates
185 void sendMessage(const QString &receiverId, const QString &message,
186 const GeoCoordinate &coordinates = GeoCoordinate());
189 * @brief Update session data
191 * @param session New session data
193 void updateSession(const QString &session);
197 * @brief Requests ImageFetcher if user/friend has a profile image
198 * uses members: m_user and m_friendsList
200 * @param imageUrlList list of image urls
202 void addProfileImages(const QHash<QString, QUrl> &imageUrlList);
205 * @brief Append access_token and other session data to the reques url
207 * @param[in,out] requestUrl Request URL with other request parameters and ending to &
209 void appendAccessToken(QString &requestUrl);
212 * @brief Build and send request
214 * Appends script pathname and parameters to the server base URL. Access token is appended and
215 * the request sent if the access token is available, otherwise the request is queued.
217 * @param script Requested script pathname
218 * @param parameters Hash containing parameter key/value pairs.
220 void buildRequest(const QString &script, const QHash<QString,QString> ¶meters);
223 * @brief Convert coordinate value in degrees (double) to string with enough precision
225 * @param degrees Coordinate value in degrees
226 * @returns Coordinate value as string
228 QString degreesToString(double degrees);
231 * @brief Returns reuquest script's name.
233 * @param url url to check
234 * @return RequestName
236 SituareService::RequestName getRequestName(const QUrl &url) const;
239 * @brief Temporary method to get tags.
241 * Tags are fetch from local database instead of Situare server.
243 * @return QStringList list of tags
245 QHash<QString, QString> getTags(const QString &userId);
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 and friend data from JSON string
285 * @param userData user data QVariant tree
287 void parseUserData(const QVariant &userData);
290 * @brief Send request
292 * @param requestUrl Request URL containing also all parameters
294 void sendRequest(const QString &requestUrl);
298 * @brief Slot for received images
301 * @param image image pixmap
303 void imageReceived(const QString &id, const QPixmap &image);
305 /*******************************************************************************
307 ******************************************************************************/
310 * @brief Signals error
312 * @param context error context
313 * @param error error code
315 void error(const int context, const int error);
318 * @brief Signal for image fetching
321 * @param url Image url
323 void fetchImage(const QString &id, const QUrl &url);
326 * @brief Signals when image is downloaded
329 * @param image image pixmap
331 void imageReady(const QString &id, const QPixmap &image);
334 * @brief Signal when fetchPeopleWithSimilarInterest request is finished
336 * @param friends list of friends
337 * @param others list of other people
339 void interestingPeopleReceived(QList<User> &friends, QList<User> &others);
342 * @brief Signal when fetchMessages request is finished
344 * @param messages list of messages sent to user
346 void messagesReceived(QList<Message> &received, QList<Message> &sent);
349 * @brief Signals when fetchPopularTags request is finished
351 * @param popularTags list of popular tags
353 void popularTagsReceived(QHash<QString, QString> &popularTags);
356 * @brief Signals when address data is retrieved
358 * @param address Street address
360 void reverseGeoReady(const QString &address);
363 * @brief Signals when updateLocation request finished successfully
365 void updateWasSuccessful(SituareService::SuccessfulMethod successfulMethod);
368 * @brief Signals when user data is retrieved
370 * @param user instance of user
371 * @param friendList list of friends
373 void userDataChanged(User *user, QList<User *> &friendList);
375 /*******************************************************************************
377 ******************************************************************************/
379 bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
381 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
382 QList<User *> m_friendsList; ///< List of friends(User)
384 QString m_session; ///< Session data
386 Database *m_database; ///< Instance of the database
387 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
388 NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
389 User *m_user; ///< Pointer to User
392 #endif // SITUARESERVICE_H