Added missing enum.
[situare] / src / situareservice / situareservice.h
index b676067..e7fb4a7 100644 (file)
@@ -4,6 +4,7 @@
 
       Henri Lampela - henri.lampela@ixonos.com
       Jussi Laitinen - jussi.laitinen@ixonos.com
+      Sami Rämö - sami.ramo@ixonos.com
 
    Situare is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -25,7 +26,7 @@
 #define SITUARESERVICE_H
 
 #include <QObject>
-#include "../facebookservice/facebookcredentials.h"
+
 #include "../user/user.h"
 #include "imagefetcher.h"
 #include "message.h"
@@ -41,12 +42,22 @@ class QUrl;
 * @brief SituareService class for communicating with Situare server
 *
 * @author Henri Lampela
-* @class SituareService situareservice.h "situareservice/situareservice.h"
+* @author Jussi Laitinen - jussi.laitinen (at) ixonos.com
+* @author Sami Rämö - sami.ramo (at) ixonos.com
 */
 class SituareService : public QObject
 {
     Q_OBJECT
 
+private:
+    /**
+    * @brief Request name enum
+    */
+    enum RequestName { RequestUnknown,
+                       RequestGetLocations,
+                       RequestUpdateLocation,
+                       RequestReverseGeo};
+
 public:
 
     /**
@@ -116,6 +127,12 @@ public slots:
     void addTags(const QStringList &tags);
 
     /**
+    * @brief Public slot, to clear user data
+    *
+    */
+    void clearUserData();
+
+    /**
     * @brief Retrieves messages sent to user.
     */
     void fetchMessages();
@@ -128,19 +145,6 @@ public slots:
     void fetchPopularTags();
 
     /**
-    * @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 Removes message.
     *
     * @param id message ID
@@ -178,6 +182,13 @@ public slots:
     void sendMessage(const QString &receiverId, const QString &message,
                      const GeoCoordinate &coordinates = GeoCoordinate());
 
+    /**
+      * @brief Update session data
+      *
+      * @param session New session data
+      */
+    void updateSession(const QString &session);
+
 private:
     /**
     * @brief Requests ImageFetcher if user/friend has a profile image
@@ -188,42 +199,38 @@ private:
     void addProfileImages(const QHash<QString, QUrl> &imageUrlList);
 
     /**
-    * @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 Append access_token and other session data to the reques url
+      *
+      * @param[in,out] requestUrl Request URL with other request parameters and ending to &
+      */
+    void appendAccessToken(QString &requestUrl);
 
     /**
-    * @brief Forms a http url
-    *
-    * @param baseUrl Server url
-    * @param phpScript Server script
-    * @param urlParameters optional parameters for url
-    * @return QUrl formed url
-    */
-    QUrl formUrl(const QString &baseUrl, const QString &phpScript,
-                 QString urlParameters = QString());
+      * @brief Build and send request
+      *
+      * Appends script pathname and parameters to the server base URL. Access token is appended and
+      * the request sent if the access token is available, otherwise the request is queued.
+      *
+      * @param script Requested script pathname
+      * @param parameters Hash containing parameter key/value pairs.
+      */
+    void buildRequest(const QString &script, const QHash<QString,QString> &parameters);
 
     /**
-    * @brief Forms url parameters
+      * @brief Convert coordinate value in degrees (double) to string with enough precision
+      *
+      * @param degrees Coordinate value in degrees
+      * @returns Coordinate value as string
+      */
+    QString degreesToString(double degrees);
+    
+    /**
+    * @brief Returns reuquest script's name.
     *
-    * @param coordinates current coordinates
-    * @param status optional status message
-    * @param publish optional publish location on Facebook wall
-    * @return QString
+    * @param url url to check
+    * @return RequestName
     */
-    QString formUrlParameters(const GeoCoordinate &coordinates, QString status = QString(),
-                              bool publish = false);
+    SituareService::RequestName getRequestName(const QUrl &url) const;
 
     /**
     * @brief Temporary method to get tags.
@@ -256,20 +263,32 @@ private:
     void parsePopularTagsData(const QByteArray &jsonReply);
 
     /**
-    * @brief Parses user and friend data from JSON string
+    * @brief Parses reply from JSON string
     *
-    * @param jsonReply JSON string
+    * Calls different parse methods or emits error signal if response contains error status.
     */
-    void parseUserData(const QByteArray &jsonReply);
+    void parseReply(const QByteArray &jsonReply, RequestName requestName);
 
     /**
-    * @brief Sends http request
+    * @brief Parses reverse geo data
     *
-    * @param url destination
-    * @param cookieType type of the cookie
-    * @param cookie http cookie
+    * @param reverseGeoData reverse geo data QVariant tree
     */
-    void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
+    void parseReverseGeoData(const QVariant &reverseGeoData);
+
+    /**
+    * @brief Parses user and friend data from JSON string
+    *
+    * @param userData user data QVariant tree
+    */
+    void parseUserData(const QVariant &userData);
+
+    /**
+      * @brief Send request
+      *
+      * @param requestUrl Request URL containing also all parameters
+      */
+    void sendRequest(const QString &requestUrl);
 
 private slots:
     /**
@@ -301,13 +320,6 @@ signals:
     void fetchImage(const QString &id, 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 image is downloaded
     *
     * @param id image ID
@@ -331,6 +343,13 @@ signals:
     void messagesReceived(QList<Message> &received, QList<Message> &sent);
 
     /**
+    * @brief Signals when fetchPopularTags request is finished
+    *
+    * @param popularTags list of popular tags
+    */
+    void popularTagsReceived(QHash<QString, QString> &popularTags);
+
+    /**
     * @brief Signals when address data is retrieved
     *
     * @param address Street address
@@ -339,7 +358,6 @@ signals:
 
     /**
     * @brief Signals when updateLocation request finished successfully
-    *
     */
     void updateWasSuccessful(SituareService::SuccessfulMethod successfulMethod);
 
@@ -357,13 +375,14 @@ signals:
 private:
     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<User *> m_friendsList;                ///< List of friends(User)
+    QList<QNetworkReply *> m_currentRequests;       ///< List of current http requests
+    QList<User *> m_friendsList;                    ///< List of friends(User)
+
+    QString m_session;                          ///< Session data
 
     Database *m_database;                       ///< Instance of the database
-    NetworkAccessManager *m_networkManager;    ///< Pointer to QNetworkAccessManager
-    FacebookCredentials m_credentials;          ///< handle for FacebookCredentials
-    ImageFetcher *m_imageFetcher;               ///< Instance of the image fetcher
+    ImageFetcher *m_imageFetcher;               ///< Instance of the image fetcher    
+    NetworkAccessManager *m_networkManager;     ///< Pointer to QNetworkAccessManager
     User *m_user;                               ///< Pointer to User
 };