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 Retrieves notifications sent to user.
87 void fetchNotifications();
90 * @brief Translates coordinates to street address via Situare server
92 * @param coordinates coordinates to be translated
94 void reverseGeo(const GeoCoordinate &coordinates);
97 * @brief Updates location to the Situare server
99 * @param coordinates current cordinates
100 * @param status message
101 * @param publish publish location on Facebook wall
103 void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
106 * @brief Updates tags to the Situare server
108 * CURRENTLY TAGS ARE UPDATED TO THE LOCAL DATABASE, NOT SITUARE SERVER
109 * @param userId user ID
110 * @param tags list of user's tags
112 void updateTags(const QString &userId, const QStringList &tags);
117 * @brief Public slot, to clear user data
120 void clearUserData();
123 * @brief Public slot, which indicates when facebook credentials are ready
125 * @param credentials New credentials
127 void credentialsReady(const FacebookCredentials &credentials);
130 * @brief Public slot, which indicates when http request has been completed
132 * @param reply storage for http reply
134 void requestFinished(QNetworkReply *reply);
138 * @brief Requests ImageFetcher if user/friend has a profile image
139 * uses members: m_user and m_friendsList
141 * @param imageUrlList list of image urls
143 void addProfileImages(const QList<QUrl> &imageUrlList);
146 * @brief Forms a http cookie
148 * @param apiKeyValue application key
149 * @param expiresValue session expire date&time from Facebook
150 * @param userValue user id from Facebook
151 * @param sessionKeyValue session key from Facebook
152 * @param sessionSecretValue session secret from Facebook
153 * @param signatureValue md5 generated signature
154 * @param localeValue used locale
155 * @return QString formed cookie
157 QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
158 QString sessionKeyValue, QString sessionSecretValue,
159 const QString &signatureValue, const QString &localeValue);
162 * @brief Forms a http url
164 * @param baseUrl Server url
165 * @param phpScript Server script
166 * @param urlParameters optional parameters for url
167 * @return QUrl formed url
169 QUrl formUrl(const QString &baseUrl, const QString &phpScript,
170 QString urlParameters = QString());
173 * @brief Forms url parameters
175 * @param coordinates current coordinates
176 * @param status optional status message
177 * @param publish optional publish location on Facebook wall
180 QString formUrlParameters(const GeoCoordinate &coordinates, QString status = QString(),
181 bool publish = false);
184 * @brief Temporary method to get tags.
186 * Tags are fetch from local database instead of Situare server.
188 * @return QStringList list of tags
190 QStringList getTags(const QString &userId);
193 * @brief Parses user and friend data from JSON string
195 * @param jsonReply JSON string
197 void parseUserData(const QByteArray &jsonReply);
200 * @brief Sends http request
202 * @param url destination
203 * @param cookieType type of the cookie
204 * @param cookie http cookie
206 void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
210 * @brief Slot for received images
212 * @param url Image url
213 * @param image Received image
215 void imageReceived(const QUrl &url, const QPixmap &image);
217 /*******************************************************************************
219 ******************************************************************************/
222 * @brief Signals error
224 * @param context error context
225 * @param error error code
227 void error(const int context, const int error);
230 * @brief Signal for image fetching
232 * @param url Image url
234 void fetchImage(const QUrl &url);
237 * @brief Signals when user's/friend's image is downloaded
239 * @param user Instance of user/friend
241 void imageReady(User *user);
244 * @brief Signal when fetchPeopleWithSimilarInterest request is finished
246 * @param interestingPeople list of interesting people
248 void interestingPeopleReceived(QList<User *> &interestingPeople);
251 * @brief Signal when fetchNotifications request is finished
253 * @param notifications list of notifications sent to user
255 void notificationsReceived(QList<Notification> ¬ifications);
258 * @brief Signals when address data is retrieved
260 * @param address Street address
262 void reverseGeoReady(const QString &address);
265 * @brief Signals when updateLocation request finished successfully
268 void updateWasSuccessful();
271 * @brief Signals when user data is retrieved
273 * @param user instance of user
274 * @param friendList list of friends
276 void userDataChanged(User *user, QList<User *> &friendList);
278 /*******************************************************************************
280 ******************************************************************************/
284 bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
286 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
287 QList<User *> m_friendsList; ///< List of friends(User)
289 Database *m_database; ///< Instance of the database
290 NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
291 FacebookCredentials m_credentials; ///< handle for FacebookCredentials
292 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
293 User *m_user; ///< Pointer to User
296 #endif // SITUARESERVICE_H