Changing to new authentication mechanism ongoing
[situare] / src / situareservice / situareservice.h
index afaa628..d38bd4b 100644 (file)
 #define SITUARESERVICE_H
 
 #include <QObject>
-#include "../facebookservice/facebookauthentication.h"
 #include "../facebookservice/facebookcredentials.h"
 #include "../user/user.h"
 #include "imagefetcher.h"
 
-class QNetworkAccessManager;
+class NetworkAccessManager;
 class QNetworkReply;
 class QNetworkRequest;
-class QPointF;
+class GeoCoordinate;
 class QUrl;
 
 /**
@@ -51,9 +50,8 @@ public:
     * @brief Default constructor
     *
     * @param parent instance of parent
-    * @param manager instance of QNetworkAccessManager
     */
-    SituareService(QObject *parent = 0, QNetworkAccessManager *manager = 0);
+    SituareService(QObject *parent = 0);
 
     /**
     * @brief Destructor
@@ -76,33 +74,68 @@ public:
     *
     * @param coordinates coordinates to be translated
     */
-    void reverseGeo(const QPointF &coordinates);
+    void reverseGeo(const GeoCoordinate &coordinates);
 
     /**
     * @brief Updates location to the Situare server
     *
     * @param coordinates current cordinates
     * @param status message
-    * @param publish publish location on Facebook wall (true/false)
+    * @param publish publish location on Facebook wall
     */
-    void updateLocation(const QPointF &coordinates, const QString &status, const bool &publish);
+    void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
 
 public slots:
 
     /**
+    * @brief Public slot, to clear user data
+    *
+    */
+    void clearUserData();
+
+    /**
+    * @brief Public slot, which indicates when facebook credentials are ready
+    *
+    * @param credentials New credentials
+    */
+    void credentialsReady(const FacebookCredentials &credentials);
+
+    /**
     * @brief Public slot, which indicates when http request has been completed
     *
     * @param reply storage for http reply
     */
     void requestFinished(QNetworkReply *reply);
 
+    void updateAccessToken(const QString &accessToken);
+
+private:
+
     /**
-    * @brief Public slot, which indicates when facebook credentials are ready
+    * @brief Requests ImageFetcher if user/friend has a profile image
+    *        uses members: m_user and m_friendsList
     *
+    * @param imageUrlList list of image urls
     */
-    void credentialsReady();
+    void addProfileImages(const QList<QUrl> &imageUrlList);
 
-private:
+    void appendAccessToken(QString &requestUrl);
+
+    /**
+    * @brief Forms a http cookie
+    *
+    * @param apiKeyValue application key
+    * @param expiresValue session expire date&time from Facebook
+    * @param userValue user id from Facebook
+    * @param sessionKeyValue session key from Facebook
+    * @param sessionSecretValue session secret from Facebook
+    * @param signatureValue md5 generated signature
+    * @param localeValue used locale
+    * @return QString formed cookie
+    */
+    QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
+                       QString sessionKeyValue, QString sessionSecretValue,
+                       const QString &signatureValue, const QString &localeValue);
 
     /**
     * @brief Forms a http url
@@ -112,17 +145,19 @@ private:
     * @param urlParameters optional parameters for url
     * @return QUrl formed url
     */
-    QUrl formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters = 0);
+    QUrl formUrl(const QString &baseUrl, const QString &phpScript,
+                 QString urlParameters = QString());
 
     /**
     * @brief Forms url parameters
     *
     * @param coordinates current coordinates
     * @param status optional status message
-    * @param publish optional publish location on Facebook wall (true/false)
+    * @param publish optional publish location on Facebook wall
     * @return QString
     */
-    QString formUrlParameters(const QPointF &coordinates, QString status = 0, QString publish = 0);
+    QString formUrlParameters(const GeoCoordinate &coordinates, QString status = QString(),
+                              bool publish = false);
 
     /**
     * @brief Parses user and friend data from JSON string
@@ -140,6 +175,11 @@ private:
     */
     void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
 
+
+    void buildRequest(const QString &script, const QHash<QString,QString> &parameters);
+
+    void sendRequest(const QString &requestUrl);
+
 private slots:
 
     /**
@@ -148,7 +188,7 @@ private slots:
     * @param url Image url
     * @param image Received image
     */
-    void imageReceived(const QUrl &url, const QImage &image);
+    void imageReceived(const QUrl &url, const QPixmap &image);
 
 /*******************************************************************************
  * SIGNALS
@@ -159,9 +199,10 @@ signals:
     /**
     * @brief Signals error
     *
-    * @param error error message
+    * @param context error context
+    * @param error error code
     */
-    void error(const QString &error);
+    void error(const int context, const int error);
 
     /**
     * @brief Signal for image fetching
@@ -171,6 +212,13 @@ signals:
     void fetchImage(const QUrl &url);
 
     /**
+    * @brief Signals when user's/friend's image is downloaded
+    *
+    * @param user Instance of user/friend
+    */
+    void imageReady(User *user);
+
+    /**
     * @brief Signals when address data is retrieved
     *
     * @param address Street address
@@ -178,12 +226,18 @@ signals:
     void reverseGeoReady(const QString &address);
 
     /**
+    * @brief Signals when updateLocation request finished successfully
+    *
+    */
+    void updateWasSuccessful();
+
+    /**
     * @brief Signals when user data is retrieved
     *
     * @param user instance of user
     * @param friendList list of friends
     */
-    void userDataChanged(User &user, QList<User *> &friendList);
+    void userDataChanged(User *user, QList<User *> &friendList);
 
 /*******************************************************************************
  * DATA MEMBERS
@@ -191,11 +245,19 @@ signals:
 
 private:
 
-    FacebookCredentials m_credentials; ///< handle for FacebookCredentials
-    QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
-    FacebookAuthentication m_facebookAuthentication; ///< Pointer to FacebookAuthentication
-    QNetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
-    ImageFetcher *m_imageFetcher;
+    bool m_defaultImage;    ///< Indicates if some of the friends/user doesn't have a image
+
+    QList<QNetworkReply *> m_currentRequests;   ///< List of current http requests
+    QList<QString> m_requestsWaitingAccessToken;
+    QList<User *> m_friendsList;                ///< List of friends(User)
+
+    QString m_accessToken;
+
+    NetworkAccessManager *m_networkManager;    ///< Pointer to QNetworkAccessManager
+
+    FacebookCredentials m_credentials;          ///< handle for FacebookCredentials
+    ImageFetcher *m_imageFetcher;               ///< Instance of the image fetcher
+    User *m_user;                               ///< Pointer to User
 };
 
 #endif // SITUARESERVICE_H