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
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
28 #include "../facebookservice/facebookcredentials.h"
29 #include "../user/user.h"
30 #include "imagefetcher.h"
34 class NetworkAccessManager;
36 class QNetworkRequest;
41 * @brief SituareService class for communicating with Situare server
43 * @author Henri Lampela
44 * @class SituareService situareservice.h "situareservice/situareservice.h"
46 class SituareService : public QObject
55 friend class TestSituareService;
57 enum SuccessfulMethod {SuccessfulUpdateLocation, SuccessfulAddTags, SuccessfulRemoveTags,
58 SuccessfulSendMessage, SuccessfulRemoveMessage};
61 * @brief Default constructor
63 * @param parent instance of parent
65 SituareService(NetworkAccessManager *networkManager, ImageFetcher *imageFetcher,
74 /*******************************************************************************
75 * MEMBER FUNCTIONS AND SLOTS
76 ******************************************************************************/
78 * @brief Retrieves people with similart interest (same tags).
80 * People is searched from area defined by south-west and north-east bounds.
81 * @param southWest south-west coordinates of bounds
82 * @param northEast north-east coordinates of bounds
84 void fetchPeopleWithSimilarInterest(const GeoCoordinate &southWestCoordinates,
85 const GeoCoordinate &northEastCoordinates);
88 * @brief Retrieves location user and friends information from Situare server
91 void fetchLocations();
94 * @brief Translates coordinates to street address via Situare server
96 * @param coordinates coordinates to be translated
98 void reverseGeo(const GeoCoordinate &coordinates);
101 * @brief Updates location to the Situare server
103 * @param coordinates current cordinates
104 * @param status message
105 * @param publish publish location on Facebook wall
107 void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
111 * @brief Adds tags to the Situare server
113 * CURRENTLY TAGS ARE UPDATED TO THE LOCAL DATABASE, NOT SITUARE SERVER
114 * @param tags list of user's tags
116 void addTags(const QStringList &tags);
119 * @brief Retrieves messages sent to user.
121 void fetchMessages();
124 * @brief Retrieves popular tags.
126 * Tags are fetch from local database instead of Situare server.
128 void fetchPopularTags();
131 * @brief Public slot, to clear user data
134 void clearUserData();
137 * @brief Public slot, which indicates when facebook credentials are ready
139 * @param credentials New credentials
141 void credentialsReady(const FacebookCredentials &credentials);
144 * @brief Removes message.
146 * @param id message ID
148 void removeMessage(const QString &id);
151 * @brief Removes tags.
153 * @param tags list of tags to remove
155 void removeTags(const QStringList &tags);
158 * @brief Public slot, which indicates when http request has been completed
160 * @param reply storage for http reply
162 void requestFinished(QNetworkReply *reply);
165 * @brief Searches people by tag name.
167 * @param tag tag name
169 void searchPeopleByTag(const QString &tag);
172 * @brief Sends a message to a person.
174 * @param receiverId Facebook user ID
175 * @param message message text
176 * @param message coordinates
178 void sendMessage(const QString &receiverId, const QString &message,
179 const GeoCoordinate &coordinates = GeoCoordinate());
183 * @brief Requests ImageFetcher if user/friend has a profile image
184 * uses members: m_user and m_friendsList
186 * @param imageUrlList list of image urls
188 void addProfileImages(const QHash<QString, QUrl> &imageUrlList);
191 * @brief Forms a http cookie
193 * @param apiKeyValue application key
194 * @param expiresValue session expire date&time from Facebook
195 * @param userValue user id from Facebook
196 * @param sessionKeyValue session key from Facebook
197 * @param sessionSecretValue session secret from Facebook
198 * @param signatureValue md5 generated signature
199 * @param localeValue used locale
200 * @return QString formed cookie
202 QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
203 QString sessionKeyValue, QString sessionSecretValue,
204 const QString &signatureValue, const QString &localeValue);
207 * @brief Forms a http url
209 * @param baseUrl Server url
210 * @param phpScript Server script
211 * @param urlParameters optional parameters for url
212 * @return QUrl formed url
214 QUrl formUrl(const QString &baseUrl, const QString &phpScript,
215 QString urlParameters = QString());
218 * @brief Forms url parameters
220 * @param coordinates current coordinates
221 * @param status optional status message
222 * @param publish optional publish location on Facebook wall
225 QString formUrlParameters(const GeoCoordinate &coordinates, QString status = QString(),
226 bool publish = false);
229 * @brief Temporary method to get tags.
231 * Tags are fetch from local database instead of Situare server.
233 * @return QStringList list of tags
235 QHash<QString, QString> getTags(const QString &userId);
238 * @brief Parses interesting people data from JSON string
240 * @param jsonReply JSON string
242 void parseInterestingPeopleData(const QByteArray &jsonReply);
245 * @brief Parses messages data from JSON string
247 * @param jsonReply JSON string
249 void parseMessagesData(const QByteArray &jsonReply);
252 * @brief Parses popular tags data from JSON string
254 * @param jsonReply JSON string
256 void parsePopularTagsData(const QByteArray &jsonReply);
259 * @brief Parses user and friend data from JSON string
261 * @param jsonReply JSON string
263 void parseUserData(const QByteArray &jsonReply);
266 * @brief Sends http request
268 * @param url destination
269 * @param cookieType type of the cookie
270 * @param cookie http cookie
272 void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
276 * @brief Slot for received images
279 * @param image image pixmap
281 void imageReceived(const QString &id, const QPixmap &image);
283 /*******************************************************************************
285 ******************************************************************************/
288 * @brief Signals error
290 * @param context error context
291 * @param error error code
293 void error(const int context, const int error);
296 * @brief Signal for image fetching
299 * @param url Image url
301 void fetchImage(const QString &id, const QUrl &url);
304 * @brief Signals when user's/friend's image is downloaded
306 * @param user Instance of user/friend
308 void imageReady(User *user);
311 * @brief Signals when image is downloaded
314 * @param image image pixmap
316 void imageReady(const QString &id, const QPixmap &image);
319 * @brief Signal when fetchPeopleWithSimilarInterest request is finished
321 * @param friends list of friends
322 * @param others list of other people
324 void interestingPeopleReceived(QList<User> &friends, QList<User> &others);
327 * @brief Signal when fetchMessages request is finished
329 * @param messages list of messages sent to user
331 void messagesReceived(QList<Message> &received, QList<Message> &sent);
334 * @brief Signals when fetchPopularTags request is finished
336 * @param popularTags list of popular tags
338 void popularTagsReceived(QHash<QString, QString> &popularTags);
341 * @brief Signals when address data is retrieved
343 * @param address Street address
345 void reverseGeoReady(const QString &address);
348 * @brief Signals when updateLocation request finished successfully
351 void updateWasSuccessful(SituareService::SuccessfulMethod successfulMethod);
354 * @brief Signals when user data is retrieved
356 * @param user instance of user
357 * @param friendList list of friends
359 void userDataChanged(User *user, QList<User *> &friendList);
361 /*******************************************************************************
363 ******************************************************************************/
365 bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
367 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
368 QList<User *> m_friendsList; ///< List of friends(User)
370 Database *m_database; ///< Instance of the database
371 NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
372 FacebookCredentials m_credentials; ///< handle for FacebookCredentials
373 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
374 User *m_user; ///< Pointer to User
377 #endif // SITUARESERVICE_H