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"
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 messages sent to user.
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);
139 * @brief Requests ImageFetcher if user/friend has a profile image
140 * uses members: m_user and m_friendsList
142 * @param imageUrlList list of image urls
144 void addProfileImages(const QList<QUrl> &imageUrlList);
147 * @brief Forms a http cookie
149 * @param apiKeyValue application key
150 * @param expiresValue session expire date&time from Facebook
151 * @param userValue user id from Facebook
152 * @param sessionKeyValue session key from Facebook
153 * @param sessionSecretValue session secret from Facebook
154 * @param signatureValue md5 generated signature
155 * @param localeValue used locale
156 * @return QString formed cookie
158 QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
159 QString sessionKeyValue, QString sessionSecretValue,
160 const QString &signatureValue, const QString &localeValue);
163 * @brief Forms a http url
165 * @param baseUrl Server url
166 * @param phpScript Server script
167 * @param urlParameters optional parameters for url
168 * @return QUrl formed url
170 QUrl formUrl(const QString &baseUrl, const QString &phpScript,
171 QString urlParameters = QString());
174 * @brief Forms url parameters
176 * @param coordinates current coordinates
177 * @param status optional status message
178 * @param publish optional publish location on Facebook wall
181 QString formUrlParameters(const GeoCoordinate &coordinates, QString status = QString(),
182 bool publish = false);
185 * @brief Temporary method to get tags.
187 * Tags are fetch from local database instead of Situare server.
189 * @return QStringList list of tags
191 QStringList getTags(const QString &userId);
194 * @brief Parses user and friend data from JSON string
196 * @param jsonReply JSON string
198 void parseUserData(const QByteArray &jsonReply);
201 * @brief Sends http request
203 * @param url destination
204 * @param cookieType type of the cookie
205 * @param cookie http cookie
207 void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
211 * @brief Slot for received images
213 * @param url Image url
214 * @param image Received image
216 void imageReceived(const QUrl &url, const QPixmap &image);
218 /*******************************************************************************
220 ******************************************************************************/
223 * @brief Signals error
225 * @param context error context
226 * @param error error code
228 void error(const int context, const int error);
231 * @brief Signal for image fetching
233 * @param url Image url
235 void fetchImage(const QUrl &url);
238 * @brief Signals when user's/friend's image is downloaded
240 * @param user Instance of user/friend
242 void imageReady(User *user);
245 * @brief Signal when fetchPeopleWithSimilarInterest request is finished
247 * @param interestingPeople list of interesting people
249 void interestingPeopleReceived(QList<User *> &interestingPeople);
252 * @brief Signal when fetchMessages request is finished
254 * @param messages list of messages sent to user
256 void messagesReceived(QList<Message> &messages);
259 * @brief Signals when address data is retrieved
261 * @param address Street address
263 void reverseGeoReady(const QString &address);
266 * @brief Signals when updateLocation request finished successfully
269 void updateWasSuccessful();
272 * @brief Signals when user data is retrieved
274 * @param user instance of user
275 * @param friendList list of friends
277 void userDataChanged(User *user, QList<User *> &friendList);
279 /*******************************************************************************
281 ******************************************************************************/
285 bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
287 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
288 QList<User *> m_friendsList; ///< List of friends(User)
290 Database *m_database; ///< Instance of the database
291 NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
292 FacebookCredentials m_credentials; ///< handle for FacebookCredentials
293 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
294 User *m_user; ///< Pointer to User
297 #endif // SITUARESERVICE_H