2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 #ifndef SITUARESERVICE_H
24 #define SITUARESERVICE_H
27 #include "../facebookservice/facebookcredentials.h"
28 #include "../user/user.h"
29 #include "imagefetcher.h"
30 #include "notification.h"
33 class NetworkAccessManager;
35 class QNetworkRequest;
40 * @brief SituareService class for communicating with Situare server
42 * @author Henri Lampela
43 * @class SituareService situareservice.h "situareservice/situareservice.h"
45 class SituareService : public QObject
52 * @brief Default constructor
54 * @param parent instance of parent
56 SituareService(QObject *parent = 0);
64 /*******************************************************************************
65 * MEMBER FUNCTIONS AND SLOTS
66 ******************************************************************************/
69 * @brief Retrieves people with similart interest (same tags).
71 * People is searched from area defined by south-west and north-east bounds.
72 * @param southWest south-west coordinates of bounds
73 * @param northEast north-east coordinates of bounds
75 void fetchPeopleWithSimilarInterest(const GeoCoordinate &southWestCoordinates,
76 const GeoCoordinate &northEastCoordinates);
79 * @brief Retrieves location user and friends information from Situare server
82 void fetchLocations();
85 * @brief Translates coordinates to street address via Situare server
87 * @param coordinates coordinates to be translated
89 void reverseGeo(const GeoCoordinate &coordinates);
92 * @brief Updates location to the Situare server
94 * @param coordinates current cordinates
95 * @param status message
96 * @param publish publish location on Facebook wall
98 void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
101 * @brief Updates tags to the Situare server
103 * CURRENTLY TAGS ARE UPDATED TO THE LOCAL DATABASE, NOT SITUARE SERVER
104 * @param userId user ID
105 * @param tags list of user's tags
107 void updateTags(const QString &userId, const QStringList &tags);
111 * @brief Retrieves notifications sent to user.
113 void fetchNotifications();
116 * @brief Public slot, to clear user data
119 void clearUserData();
122 * @brief Public slot, which indicates when facebook credentials are ready
124 * @param credentials New credentials
126 void credentialsReady(const FacebookCredentials &credentials);
129 * @brief Public slot, which indicates when http request has been completed
131 * @param reply storage for http reply
133 void requestFinished(QNetworkReply *reply);
137 * @brief Requests ImageFetcher if user/friend has a profile image
138 * uses members: m_user and m_friendsList
140 * @param imageUrlList list of image urls
142 void addProfileImages(const QHash<QString, QUrl> &imageUrlList);
145 * @brief Forms a http cookie
147 * @param apiKeyValue application key
148 * @param expiresValue session expire date&time from Facebook
149 * @param userValue user id from Facebook
150 * @param sessionKeyValue session key from Facebook
151 * @param sessionSecretValue session secret from Facebook
152 * @param signatureValue md5 generated signature
153 * @param localeValue used locale
154 * @return QString formed cookie
156 QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
157 QString sessionKeyValue, QString sessionSecretValue,
158 const QString &signatureValue, const QString &localeValue);
161 * @brief Forms a http url
163 * @param baseUrl Server url
164 * @param phpScript Server script
165 * @param urlParameters optional parameters for url
166 * @return QUrl formed url
168 QUrl formUrl(const QString &baseUrl, const QString &phpScript,
169 QString urlParameters = QString());
172 * @brief Forms url parameters
174 * @param coordinates current coordinates
175 * @param status optional status message
176 * @param publish optional publish location on Facebook wall
179 QString formUrlParameters(const GeoCoordinate &coordinates, QString status = QString(),
180 bool publish = false);
183 * @brief Temporary method to get tags.
185 * Tags are fetch from local database instead of Situare server.
187 * @return QStringList list of tags
189 QStringList getTags(const QString &userId);
192 * @brief Parses interesting people data from JSON string
194 * @param jsonReply JSON string
196 void parseInterestingPeopleData(const QByteArray &jsonReply);
199 * @brief Parses notifications data from JSON string
201 * @param jsonReply JSON string
203 void parseNotificationsData(const QByteArray &jsonReply);
207 * @brief Parses user and friend data from JSON string
209 * @param jsonReply JSON string
211 void parseUserData(const QByteArray &jsonReply);
214 * @brief Sends http request
216 * @param url destination
217 * @param cookieType type of the cookie
218 * @param cookie http cookie
220 void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
224 * @brief Slot for received images
227 * @param image image pixmap
229 void imageReceived(const QString &id, const QPixmap &image);
231 /*******************************************************************************
233 ******************************************************************************/
236 * @brief Signals error
238 * @param context error context
239 * @param error error code
241 void error(const int context, const int error);
244 * @brief Signal for image fetching
247 * @param url Image url
249 void fetchImage(const QString &id, const QUrl &url);
252 * @brief Signals when user's/friend's image is downloaded
254 * @param user Instance of user/friend
256 void imageReady(User *user);
259 * @brief Signals when image is downloaded
262 * @param image image pixmap
264 void imageReady(const QString &id, const QPixmap &image);
267 * @brief Signal when fetchPeopleWithSimilarInterest request is finished
269 * @param interestingPeople list of interesting people
271 void interestingPeopleReceived(QList<User> &interestingPeople);
274 * @brief Signal when fetchNotifications request is finished
276 * @param notifications list of notifications sent to user
278 void notificationsReceived(QList<Notification> ¬ifications);
281 * @brief Signals when address data is retrieved
283 * @param address Street address
285 void reverseGeoReady(const QString &address);
288 * @brief Signals when updateLocation request finished successfully
291 void updateWasSuccessful();
294 * @brief Signals when user data is retrieved
296 * @param user instance of user
297 * @param friendList list of friends
299 void userDataChanged(User *user, QList<User *> &friendList);
301 /*******************************************************************************
303 ******************************************************************************/
307 bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
309 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
310 QList<User *> m_friendsList; ///< List of friends(User)
312 Database *m_database; ///< Instance of the database
313 NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
314 FacebookCredentials m_credentials; ///< handle for FacebookCredentials
315 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
316 User *m_user; ///< Pointer to User
319 #endif // SITUARESERVICE_H