Copyright (C) 2010 Ixonos Plc. Authors:
Henri Lampela - henri.lampela@ixonos.com
+ Jussi Laitinen - jussi.laitinen@ixonos.com
Situare is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
#include "../facebookservice/facebookcredentials.h"
#include "../user/user.h"
#include "imagefetcher.h"
+#include "message.h"
-class QNetworkAccessManager;
+class Database;
+class NetworkAccessManager;
class QNetworkReply;
class QNetworkRequest;
-class QPointF;
+class GeoCoordinate;
class QUrl;
/**
public:
/**
+ * Unit test class
+ */
+ friend class TestSituareService;
+
+ /**
* @brief Default constructor
*
* @param parent instance of parent
- * @param manager instance of QNetworkAccessManager
*/
- SituareService(QObject *parent = 0, QNetworkAccessManager *manager = 0);
+ SituareService(NetworkAccessManager *networkManager, ImageFetcher *imageFetcher,
+ QObject *parent = 0);
/**
* @brief Destructor
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
+ /**
+ * @brief Retrieves people with similart interest (same tags).
+ *
+ * People is searched from area defined by south-west and north-east bounds.
+ * @param southWest south-west coordinates of bounds
+ * @param northEast north-east coordinates of bounds
+ */
+ void fetchPeopleWithSimilarInterest(const GeoCoordinate &southWestCoordinates,
+ const GeoCoordinate &northEastCoordinates);
/**
* @brief Retrieves location user and friends information from Situare server
*
* @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 GeoCoordinate &coordinates, const QString &status, const bool &publish);
+
+ /**
+ * @brief Updates tags to the Situare server
+ *
+ * CURRENTLY TAGS ARE UPDATED TO THE LOCAL DATABASE, NOT SITUARE SERVER
+ * @param userId user ID
+ * @param tags list of user's tags
*/
- void updateLocation(const QPointF &coordinates, const QString &status, const bool &publish);
+ void updateTags(const QString &userId, const QStringList &tags);
public slots:
+ /**
+ * @brief Retrieves messages sent to user.
+ */
+ void fetchMessages();
/**
- * @brief Public slot, which indicates when http request has been completed
+ * @brief Public slot, to clear user data
*
- * @param reply storage for http reply
*/
- void requestFinished(QNetworkReply *reply);
+ void clearUserData();
/**
* @brief Public slot, which indicates when facebook credentials are ready
*/
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);
+
+ /**
+ * @brief Sends a message to a person.
+ *
+ * @param receiverId Facebook user ID
+ * @param message message text
+ */
+ void sendMessage(const QString &receiverId, const QString &message);
+
private:
+ /**
+ * @brief Requests ImageFetcher if user/friend has a profile image
+ * uses members: m_user and m_friendsList
+ *
+ * @param imageUrlList list of image urls
+ */
+ 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 Forms a http url
* @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 Temporary method to get tags.
+ *
+ * Tags are fetch from local database instead of Situare server.
+ * @param userId
+ * @return QStringList list of tags
+ */
+ QStringList getTags(const QString &userId);
+
+ /**
+ * @brief Parses interesting people data from JSON string
+ *
+ * @param jsonReply JSON string
+ */
+ void parseInterestingPeopleData(const QByteArray &jsonReply);
+
+ /**
+ * @brief Parses messages data from JSON string
+ *
+ * @param jsonReply JSON string
+ */
+ void parseMessagesData(const QByteArray &jsonReply);
+
/**
* @brief Parses user and friend data from JSON string
*/
void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
- /**
- * @brief Requests ImageFetcher if user/friend has a profile image
- * uses members: m_user and m_friendsList
- *
- */
- void addProfileImages();
-
private slots:
-
/**
* @brief Slot for received images
*
- * @param url Image url
- * @param image Received image
+ * @param id image ID
+ * @param image image pixmap
*/
- void imageReceived(const QUrl &url, const QPixmap &image);
+ void imageReceived(const QString &id, const QPixmap &image);
/*******************************************************************************
* SIGNALS
******************************************************************************/
-
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
*
+ * @param id Image id
* @param url Image url
*/
- void fetchImage(const QUrl &url);
+ 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
+ * @param image image pixmap
+ */
+ void imageReady(const QString &id, const QPixmap &image);
+
+ /**
+ * @brief Signal when fetchPeopleWithSimilarInterest request is finished
+ *
+ * @param interestingPeople list of interesting people
+ */
+ void interestingPeopleReceived(QList<User> &interestingPeople);
+
+ /**
+ * @brief Signal when fetchMessages request is finished
+ *
+ * @param messages list of messages sent to user
+ */
+ void messagesReceived(QList<Message> &messages);
/**
* @brief Signals when address data is retrieved
*/
void reverseGeoReady(const QString &address);
+ /**
+ * @brief Signals when updateLocation request finished successfully
+ *
+ */
void updateWasSuccessful();
/**
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
-
private:
+ bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
- FacebookCredentials m_credentials; ///< handle for FacebookCredentials
- QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
- QNetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
- ImageFetcher *m_imageFetcher;
+ QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
+ QList<User *> m_friendsList; ///< List of friends(User)
- User *m_user; ///< Pointer to User
- QList<User *> m_friendsList; ///< List of friends(User)
- int m_visited; ///< Indicates number of friends with profile images
- int m_nbrOfImages; ///< Indicates number of friends whose profile images have been downloaded
- bool m_defaultImage; ///< Indicates if some of the friends or the user does not have a profile image
+ 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
+ User *m_user; ///< Pointer to User
};
#endif // SITUARESERVICE_H