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 Public slot, to clear user data
127 void clearUserData();
130 * @brief Public slot, which indicates when facebook credentials are ready
132 * @param credentials New credentials
134 void credentialsReady(const FacebookCredentials &credentials);
137 * @brief Removes message.
139 * @param id message ID
141 void removeMessage(const QString &id);
144 * @brief Removes tags.
146 * @param tags list of tags to remove
148 void removeTags(const QStringList &tags);
151 * @brief Public slot, which indicates when http request has been completed
153 * @param reply storage for http reply
155 void requestFinished(QNetworkReply *reply);
158 * @brief Searches people by tag name.
160 * @param tag tag name
162 void searchPeopleByTag(const QString &tag);
165 * @brief Sends a message to a person.
167 * @param receiverId Facebook user ID
168 * @param message message text
170 void sendMessage(const QString &receiverId, const QString &message);
174 * @brief Requests ImageFetcher if user/friend has a profile image
175 * uses members: m_user and m_friendsList
177 * @param imageUrlList list of image urls
179 void addProfileImages(const QHash<QString, QUrl> &imageUrlList);
182 * @brief Forms a http cookie
184 * @param apiKeyValue application key
185 * @param expiresValue session expire date&time from Facebook
186 * @param userValue user id from Facebook
187 * @param sessionKeyValue session key from Facebook
188 * @param sessionSecretValue session secret from Facebook
189 * @param signatureValue md5 generated signature
190 * @param localeValue used locale
191 * @return QString formed cookie
193 QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
194 QString sessionKeyValue, QString sessionSecretValue,
195 const QString &signatureValue, const QString &localeValue);
198 * @brief Forms a http url
200 * @param baseUrl Server url
201 * @param phpScript Server script
202 * @param urlParameters optional parameters for url
203 * @return QUrl formed url
205 QUrl formUrl(const QString &baseUrl, const QString &phpScript,
206 QString urlParameters = QString());
209 * @brief Forms url parameters
211 * @param coordinates current coordinates
212 * @param status optional status message
213 * @param publish optional publish location on Facebook wall
216 QString formUrlParameters(const GeoCoordinate &coordinates, QString status = QString(),
217 bool publish = false);
220 * @brief Temporary method to get tags.
222 * Tags are fetch from local database instead of Situare server.
224 * @return QStringList list of tags
226 QHash<QString, QString> getTags(const QString &userId);
229 * @brief Parses interesting people data from JSON string
231 * @param jsonReply JSON string
233 void parseInterestingPeopleData(const QByteArray &jsonReply);
236 * @brief Parses messages data from JSON string
238 * @param jsonReply JSON string
240 void parseMessagesData(const QByteArray &jsonReply);
244 * @brief Parses user and friend data from JSON string
246 * @param jsonReply JSON string
248 void parseUserData(const QByteArray &jsonReply);
251 * @brief Sends http request
253 * @param url destination
254 * @param cookieType type of the cookie
255 * @param cookie http cookie
257 void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
261 * @brief Slot for received images
264 * @param image image pixmap
266 void imageReceived(const QString &id, const QPixmap &image);
268 /*******************************************************************************
270 ******************************************************************************/
273 * @brief Signals error
275 * @param context error context
276 * @param error error code
278 void error(const int context, const int error);
281 * @brief Signal for image fetching
284 * @param url Image url
286 void fetchImage(const QString &id, const QUrl &url);
289 * @brief Signals when user's/friend's image is downloaded
291 * @param user Instance of user/friend
293 void imageReady(User *user);
296 * @brief Signals when image is downloaded
299 * @param image image pixmap
301 void imageReady(const QString &id, const QPixmap &image);
304 * @brief Signal when fetchPeopleWithSimilarInterest request is finished
306 * @param interestingPeople list of interesting people
308 void interestingPeopleReceived(QList<User> &interestingPeople);
311 * @brief Signal when fetchMessages request is finished
313 * @param messages list of messages sent to user
315 void messagesReceived(QList<Message> &messages);
318 * @brief Signals when address data is retrieved
320 * @param address Street address
322 void reverseGeoReady(const QString &address);
325 * @brief Signals when updateLocation request finished successfully
328 void updateWasSuccessful(SituareService::SuccessfulMethod successfulMethod);
331 * @brief Signals when user data is retrieved
333 * @param user instance of user
334 * @param friendList list of friends
336 void userDataChanged(User *user, QList<User *> &friendList);
338 /*******************************************************************************
340 ******************************************************************************/
342 bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
344 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
345 QList<User *> m_friendsList; ///< List of friends(User)
347 Database *m_database; ///< Instance of the database
348 NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
349 FacebookCredentials m_credentials; ///< handle for FacebookCredentials
350 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
351 User *m_user; ///< Pointer to User
354 #endif // SITUARESERVICE_H