this, SLOT(userDataChanged(User*,QList<User*>&)));
connect(this, SIGNAL(userLocationReady(User*)), m_ui, SIGNAL(userLocationReady(User*)));
connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)), m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
+ connect(m_situareService, SIGNAL(error(QString)), this, SLOT(error(QString)));
+ connect(m_situareService, SIGNAL(updateWasSuccessful()), this, SLOT(updateWasSuccessful()));
m_facebookAuthenticator->start();
}
delete m_facebookAuthenticator;
}
+void SituareEngine::error(const QString &error)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ qDebug() << error;
+ // ToDo: signal UI?
+}
+
void SituareEngine::loginOk()
{
qDebug() << __PRETTY_FUNCTION__;
void SituareEngine::requestAddress()
{
qDebug() << __PRETTY_FUNCTION__;
- QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
+
+ QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
m_situareService->reverseGeo(coordinates);
}
void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
{
qDebug() << __PRETTY_FUNCTION__;
- QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
+
+ QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
m_situareService->updateLocation(coordinates, status, publish);
}
+void SituareEngine::updateWasSuccessful()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_situareService->fetchLocations();
+}
+
void SituareEngine::updateFriendsList()
{
qDebug() << __PRETTY_FUNCTION__;
//code here
}
-void SituareEngine::userDataChanged(User *user, QList<User *> &friendList)
+void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
{
qDebug() << __PRETTY_FUNCTION__;
+
emit userLocationReady(user);
- qDebug() << friendList.at(0)->name();
- emit friendsLocationsReady(friendList);
+ emit friendsLocationsReady(friendsList);
}
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
public slots:
+
+ /**
+ * @brief Slot to intercept error signal from ImageFetcher and SituareService
+ *
+ * @param error Error message
+ */
+ void error(const QString &error);
+
/**
* @brief Slot to intercept signal from successful login
*/
*/
void updateFriendsList();
- void userDataChanged(User *user, QList<User *> &friendList);
+ /**
+ * @brief Slot to intercept signal from successful location update
+ *
+ */
+ void updateWasSuccessful();
+
+ /**
+ * @brief Slot to intercept signal when new user data is available.
+ * Splits User and friendsList data and emits them as two different signals.
+ *
+ * @param user instance of User
+ * @param friendsList list of User instances (friends)
+ */
+ void userDataChanged(User *user, QList<User *> &friendsList);
/*******************************************************************************
* SIGNALS
******************************************************************************/
signals:
+
+ /**
+ * @brief Signals when new user data is ready
+ *
+ * @param user Instance of User
+ */
void userLocationReady(User *user);
+
+ /**
+ * @brief Signals when new friends data is ready
+ *
+ * @param friendList List of User instances (friends)
+ */
void friendsLocationsReady(QList<User *> &friendList);
/*******************************************************************************
const QString ERROR_LON = "Wrong lon value: . Longitude must be between -180 and 180!";
const QString ERROR_SESSION = "<br />\n<b>Fatal error</b>:"; // starts with
+const QString SILHOUETTE_URL = "http://static.ak.fbcdn.net/pics/q_silhouette.gif";
+
#endif // SITUARECOMMON_H
connect(this, SIGNAL(fetchImage(QUrl)), m_imageFetcher, SLOT(fetchImage(QUrl)));
connect(m_imageFetcher, SIGNAL(imageReceived(QUrl,QPixmap)), this,
SLOT(imageReceived(QUrl, QPixmap)));
+ connect(m_imageFetcher, SIGNAL(error(QString)), this, SIGNAL(error(QString)));
m_user = 0;
}
QString cookie = cookieHandler.formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
m_credentials.sessionKey(), m_credentials.sessionSecret(),
m_credentials.sig(), EN_LOCALE);
+
QString urlParameters = formUrlParameters(coordinates);
QUrl url = formUrl(SITUARE_URL, REVERSE_GEO, urlParameters);
if (reply->error()) {
qDebug() << reply->errorString();
emit error(reply->errorString());
- // ToDo: some general http error handling etc, signal UI?
}
else {
qint64 max = reply->size();
// -> we get only error for wrong lon
if(replyArray == ERROR_LAT.toAscii()) {
qDebug() << "Error: " << ERROR_LAT;
- // ToDo: signal UI?
emit error(replyArray);
}
else if(replyArray == ERROR_LON.toAscii()) {
qDebug() << "Error: " << ERROR_LON;
- // ToDo: signal UI?
emit error(replyArray);
}
else if(replyArray.contains(ERROR_SESSION.toAscii())) {
qDebug() << "Error: " << ERROR_SESSION;
- // ToDo: signal UI?
emit error(replyArray);
}
else if(replyArray.startsWith(OPENING_BRACE_MARK.toAscii())) {
}
else if(replyArray == "") {
qDebug() << "No error, update was successful";
+ emit updateWasSuccessful();
}
else {
// Street address ready
m_visited = 0;
m_nbrOfImages = 0;
+ m_defaultImage = false;
qDeleteAll(m_friendsList.begin(), m_friendsList.end());
m_friendsList.clear();
QUrl imageUrl = userMap["profile_pic"].toUrl();
+ if(imageUrl.isEmpty()) {
+ // user doesn't have profile image, so we need to get him a silhouette image
+ m_defaultImage = true;
+ }
+
m_user = new User(userMap["address"].toString(), coordinates, userMap["name"].toString(),
userMap["note"].toString(), imageUrl, userMap["timestamp"].toString(),
true, userMap["uid"].toString());
QUrl imageUrl = friendMap["profile_pic"].toUrl();
+ if(imageUrl.isEmpty()) {
+ // friend doesn't have profile image, so we need to get him a silhouette image
+ m_defaultImage = true;
+ }
+
User *user = new User(friendMap["address"].toString(), coordinates, friendMap["name"].toString(),
friendMap["note"].toString(), imageUrl, friendMap["timestamp"].toString(),
false, friendMap["uid"].toString(), distanceMap["units"].toString(),
qDebug() << __PRETTY_FUNCTION__;
qDebug() << "Image URL: " << url << " size :" << image.size();
+ // assign facebook silhouette image to all who doesn't have a profile image
+ if(url == QUrl(SILHOUETTE_URL)) {
+ if(m_user->profileImageUrl().isEmpty()) {
+ m_user->setProfileImage(image);
+ }
+ for(int i=0;i < m_friendsList.count();i++) {
+ if(m_friendsList.at(i)->profileImageUrl().isEmpty()) {
+ m_friendsList.at(i)->setProfileImage(image);
+ }
+ }
+ }
+
if(m_user->profileImageUrl() == url) {
m_user->setProfileImage(image);
}
{
qDebug() << __PRETTY_FUNCTION__;
- if(!m_user->profileImageUrl().isEmpty()) {
+ // reduce net traffic by sending only one download request for facebook silhouette image
+ if(m_defaultImage) {
+ emit fetchImage(QUrl(SILHOUETTE_URL));
+ }
+
+ if(!m_user->profileImageUrl().isEmpty() && m_user->profileImageUrl().isValid()) {
emit fetchImage(m_user->profileImageUrl());
}
for(int i=0;i<m_friendsList.count();i++) {
- if(!m_friendsList.at(i)->profileImageUrl().isEmpty()) {
+ if(!m_friendsList.at(i)->profileImageUrl().isEmpty() &&
+ m_friendsList.at(i)->profileImageUrl().isValid()) {
m_visited++; // indicates how many friends that have profile image
emit fetchImage(m_friendsList.at(i)->profileImageUrl());
}
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
+
/**
* @brief Retrieves location user and friends information from Situare server
*
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
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
};
#endif // SITUARESERVICE_H