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"
31 class QNetworkAccessManager;
33 class QNetworkRequest;
38 * @brief SituareService class for communicating with Situare server
40 * @author Henri Lampela
41 * @class SituareService situareservice.h "situareservice/situareservice.h"
43 class SituareService : public QObject
50 * @brief Default constructor
52 * @param parent instance of parent
54 SituareService(QObject *parent = 0);
62 /*******************************************************************************
63 * MEMBER FUNCTIONS AND SLOTS
64 ******************************************************************************/
67 * @brief Retrieves location user and friends information from Situare server
70 void fetchLocations();
73 * @brief Translates coordinates to street address via Situare server
75 * @param coordinates coordinates to be translated
77 void reverseGeo(const QPointF &coordinates);
80 * @brief Updates location to the Situare server
82 * @param coordinates current cordinates
83 * @param status message
84 * @param publish publish location on Facebook wall (true/false)
86 void updateLocation(const QPointF &coordinates, const QString &status, const bool &publish);
91 * @brief Public slot, which indicates when http request has been completed
93 * @param reply storage for http reply
95 void requestFinished(QNetworkReply *reply);
98 * @brief Public slot, which indicates when facebook credentials are ready
100 * @param credentials New credentials
102 void credentialsReady(const FacebookCredentials &credentials);
107 * @brief Forms a http cookie
109 * @param apiKeyValue application key
110 * @param expiresValue session expire date&time from Facebook
111 * @param userValue user id from Facebook
112 * @param sessionKeyValue session key from Facebook
113 * @param sessionSecretValue session secret from Facebook
114 * @param signatureValue md5 generated signature
115 * @param localeValue used locale
116 * @return QString formed cookie
118 QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
119 QString sessionKeyValue, QString sessionSecretValue,
120 const QString &signatureValue, const QString &localeValue);
123 * @brief Forms a http url
125 * @param baseUrl Server url
126 * @param phpScript Server script
127 * @param urlParameters optional parameters for url
128 * @return QUrl formed url
130 QUrl formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters = 0);
133 * @brief Forms url parameters
135 * @param coordinates current coordinates
136 * @param status optional status message
137 * @param publish optional publish location on Facebook wall (true/false)
140 QString formUrlParameters(const QPointF &coordinates, QString status = 0, QString publish = 0);
143 * @brief Parses user and friend data from JSON string
145 * @param jsonReply JSON string
147 void parseUserData(const QByteArray &jsonReply);
150 * @brief Sends http request
152 * @param url destination
153 * @param cookieType type of the cookie
154 * @param cookie http cookie
156 void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
159 * @brief Requests ImageFetcher if user/friend has a profile image
160 * uses members: m_user and m_friendsList
163 void addProfileImages();
168 * @brief Slot for received images
170 * @param url Image url
171 * @param image Received image
173 void imageReceived(const QUrl &url, const QPixmap &image);
175 /*******************************************************************************
177 ******************************************************************************/
182 * @brief Signals error
184 * @param error error message
186 void error(const QString &error);
189 * @brief Signal for image fetching
191 * @param url Image url
193 void fetchImage(const QUrl &url);
196 * @brief Signals when address data is retrieved
198 * @param address Street address
200 void reverseGeoReady(const QString &address);
203 * @brief Signals when updateLocation request finished successfully
206 void updateWasSuccessful();
209 * @brief Signals when user data is retrieved
211 * @param user instance of user
212 * @param friendList list of friends
214 void userDataChanged(User *user, QList<User *> &friendList);
216 /*******************************************************************************
218 ******************************************************************************/
222 FacebookCredentials m_credentials; ///< handle for FacebookCredentials
223 QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
224 QNetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
225 ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
227 User *m_user; ///< Pointer to User
228 QList<User *> m_friendsList; ///< List of friends(User)
229 int m_visited; ///< Indicates number of friends with profile images
230 int m_nbrOfImages; ///< Indicates number of friends whose profile images have been downloaded
231 bool m_defaultImage; ///< Indicates if some of the friends or the user does not have a profile image
234 #endif // SITUARESERVICE_H