Copyright (C) 2010 Ixonos Plc. Authors:
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
#include "../user/user.h"
#include "imagefetcher.h"
+#include "message.h"
+class Database;
class NetworkAccessManager;
class QNetworkReply;
class QNetworkRequest;
* @brief SituareService class for communicating with Situare server
*
* @author Henri Lampela
+* @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:
/**
+ * Unit test class
+ */
+ friend class TestSituareService;
+
+ enum SuccessfulMethod {SuccessfulUpdateLocation, SuccessfulAddTags, SuccessfulRemoveTags,
+ SuccessfulSendMessage, SuccessfulRemoveMessage};
+
+ /**
* @brief Default constructor
*
* @param parent instance of parent
*/
- SituareService(QObject *parent = 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
void updateLocation(const GeoCoordinate &coordinates, const QString &status, const bool &publish);
public slots:
+ /**
+ * @brief Adds tags to the Situare server
+ *
+ * CURRENTLY TAGS ARE UPDATED TO THE LOCAL DATABASE, NOT SITUARE SERVER
+ * @param tags list of user's tags
+ */
+ void addTags(const QStringList &tags);
/**
* @brief Public slot, to clear user data
void clearUserData();
/**
+ * @brief Retrieves messages sent to user.
+ */
+ void fetchMessages();
+
+ /**
+ * @brief Retrieves popular tags.
+ *
+ * Tags are fetch from local database instead of Situare server.
+ */
+ void fetchPopularTags();
+
+ /**
+ * @brief Removes message.
+ *
+ * @param id message ID
+ */
+ void removeMessage(const QString &id);
+
+ /**
+ * @brief Removes tags.
+ *
+ * @param tags list of tags to remove
+ */
+ void removeTags(const QStringList &tags);
+
+ /**
* @brief Public slot, which indicates when http request has been completed
*
* @param reply storage for http reply
void requestFinished(QNetworkReply *reply);
/**
+ * @brief Searches people by tag name.
+ *
+ * @param tag tag name
+ */
+ void searchPeopleByTag(const QString &tag);
+
+ /**
+ * @brief Sends a message to a person.
+ *
+ * @param receiverId Facebook user ID
+ * @param message message text
+ * @param message coordinates
+ */
+ 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
* uses members: m_user and m_friendsList
*
* @param imageUrlList list of image urls
*/
- void addProfileImages(const QList<QUrl> &imageUrlList);
+ void addProfileImages(const QHash<QString, QUrl> &imageUrlList);
/**
* @brief Append access_token and other session data to the reques url
void appendAccessToken(QString &requestUrl);
/**
+ * @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> ¶meters);
+
+ /**
* @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 url url to check
+ * @return RequestName
+ */
+ SituareService::RequestName getRequestName(const QUrl &url) const;
/**
- * @brief Parses user and friend data from JSON string
+ * @brief Temporary method to get tags.
+ *
+ * Tags are fetch from local database instead of Situare server.
+ * @param userId
+ * @return QStringList list of tags
+ */
+ QHash<QString, QString> getTags(const QString &userId);
+
+ /**
+ * @brief Parses interesting people data from JSON string
*
* @param jsonReply JSON string
*/
- void parseUserData(const QByteArray &jsonReply);
+ void parseInterestingPeopleData(const QByteArray &jsonReply);
/**
- * @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> ¶meters);
+ * @brief Parses messages data from JSON string
+ *
+ * @param jsonReply JSON string
+ */
+ void parseMessagesData(const QByteArray &jsonReply);
+
+ /**
+ * @brief Parses popular tags data from JSON string
+ *
+ * @param jsonReply JSON string
+ */
+ void parsePopularTagsData(const QByteArray &jsonReply);
+
+ /**
+ * @brief Parses reply from JSON string
+ *
+ * Calls different parse methods or emits error signal if response contains error status.
+ */
+ void parseReply(const QByteArray &jsonReply, RequestName requestName);
+
+ /**
+ * @brief Parses reverse geo data
+ *
+ * @param reverseGeoData reverse geo data QVariant tree
+ */
+ 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
/**
* @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
*
/**
* @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 image is downloaded
+ *
+ * @param id image ID
+ * @param image image pixmap
+ */
+ void imageReady(const QString &id, const QPixmap &image);
/**
- * @brief Signals when user's/friend's image is downloaded
+ * @brief Signal when fetchPeopleWithSimilarInterest request is finished
*
- * @param user Instance of user/friend
+ * @param friends list of friends
+ * @param others list of other people
*/
- void imageReady(User *user);
+ void interestingPeopleReceived(QList<User> &friends, QList<User> &others);
+
+ /**
+ * @brief Signal when fetchMessages request is finished
+ *
+ * @param messages list of messages sent to user
+ */
+ 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
/**
* @brief Signals when updateLocation request finished successfully
- *
*/
- void updateWasSuccessful();
+ void updateWasSuccessful(SituareService::SuccessfulMethod successfulMethod);
/**
* @brief Signals when user data is retrieved
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
-
private:
bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
QString m_session; ///< Session data
+ Database *m_database; ///< Instance of the database
+ ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
-
- ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
User *m_user; ///< Pointer to User
};