connect(m_situareService, SIGNAL(reverseGeoReady(QString)), m_ui, SIGNAL(reverseGeoReady(QString)));
connect(m_ui, SIGNAL(statusUpdate(QString,bool)), this, SLOT(requestUpdateLocation(QString,bool)));
+ m_situareService->fetchLocations(); // request user locations
+
start();
}
m_facebookAuthenticator->start();
}
-
void SituareEngine::loginOk()
{
#include <QDebug>
#include <QNetworkRequest>
#include <QNetworkReply>
-#include <QImage>
+#include <QPixmap>
#include "imagefetcher.h"
ImageFetcher::ImageFetcher(QNetworkAccessManager *manager, QObject *parent)
if (!image.load(reply, 0))
image = QImage();
- //emit imageReceived(url, QPixmap::fromImage(image));
- emit imageReceived(url, image);
+ emit imageReceived(url, QPixmap::fromImage(image));
}
else {
emit error(reply->errorString());
* is received from the server and loaded to pixmap.
*
* @param url URL to image
- * @param image image QImage
+ * @param image image QPixmap
*/
- //void imageReceived(const QUrl &url, const QPixmap &image);
- void imageReceived(const QUrl &url, const QImage &image);
+ void imageReceived(const QUrl &url, const QPixmap &image);
/**
* @brief Signal which is emitted when there is error
#include <QDebug>
#include <QtGlobal>
#include <QStringList>
+#include <QPixmap>
#include "situareservice.h"
#include "situarecommon.h"
#include "../cookiehandler/cookiehandler.h"
m_imageFetcher = new ImageFetcher(new QNetworkAccessManager(this), this);
connect(this, SIGNAL(fetchImage(QUrl)), m_imageFetcher, SLOT(fetchImage(QUrl)));
- connect(m_imageFetcher, SIGNAL(imageReceived(QUrl,QImage)), this,
- SLOT(imageReceived(QUrl, QImage)));
+ connect(m_imageFetcher, SIGNAL(imageReceived(QUrl,QPixmap)), this,
+ SLOT(imageReceived(QUrl, QPixmap)));
m_credentials = m_facebookAuthentication.loginCredentials();
}
qDebug() << __PRETTY_FUNCTION__;
delete m_networkManager;
+ delete m_user;
}
void SituareService::fetchLocations()
{
qDebug() << __PRETTY_FUNCTION__;
+ m_visited = 0;
+ m_nbrOfImages = 0;
+ m_friendsList.clear();
+
QJson::Parser parser;
bool ok;
exit (1);
}
- QList<User *> friendsList;
+ //QList<User *> friendsList;
QVariant userVariant = result.value("user");
QMap<QString, QVariant> userMap = userVariant.toMap();
QUrl imageUrl = userMap["profile_pic"].toUrl();
- User user = User(userMap["address"].toString(), coordinates, userMap["name"].toString(),
+ m_user = new User(userMap["address"].toString(), coordinates, userMap["name"].toString(),
userMap["note"].toString(), imageUrl, userMap["timestamp"].toString(),
true, userMap["uid"].toString());
false, friendMap["uid"].toString(), distanceMap["units"].toString(),
distanceMap["value"].toDouble());
- friendsList.append(user);
+ m_friendsList.append(user);
}
- emit userDataChanged(user, friendsList);
+ addProfileImages();
}
-void SituareService::imageReceived(const QUrl &url, const QImage &image)
+void SituareService::imageReceived(const QUrl &url, const QPixmap &image)
{
qDebug() << __PRETTY_FUNCTION__;
qDebug() << "Image URL: " << url << " size :" << image.size();
- //ToDo: where now?
+
+ if(m_user->profileImageUrl() == url) {
+ m_user->setProfileImage(image);
+ }
+
+ for(int i=0;i<m_friendsList.count();i++) {
+ if(m_friendsList.at(i)->profileImageUrl() == url) {
+ m_friendsList.at(i)->setProfileImage(image);
+ m_nbrOfImages++; // indicates how many friend profile images has been downloaded
+ }
+ }
+
+ if(m_nbrOfImages == m_visited) {
+ qDebug() << "m_nbrOfImages: " << m_nbrOfImages << " m_visited: " << m_visited;
+ qDebug() << "emit userDataChanged";
+ emit userDataChanged(m_user, m_friendsList);
+ }
+}
+
+void SituareService::addProfileImages()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if(m_user->profileImageUrl() != QUrl("")) {
+ emit fetchImage(m_user->profileImageUrl());
+ }
+
+ for(int i=0;i<m_friendsList.count();i++) {
+ if(m_friendsList.at(i)->profileImageUrl() != QUrl("")) {
+ m_visited++; // indicates how many friends that have profile image
+ emit fetchImage(m_friendsList.at(i)->profileImageUrl());
+ }
+ }
}
*/
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:
/**
* @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
* @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
FacebookAuthentication m_facebookAuthentication; ///< Pointer to FacebookAuthentication
QNetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
ImageFetcher *m_imageFetcher;
+
+ 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
};
#endif // SITUARESERVICE_H
m_note = note;
}
+void User::setProfileImage(const QPixmap &image)
+{
+ m_profileImage = image;
+}
+
void User::setProfileImageUrl(const QUrl &imageUrl)
{
m_profileImageUrl = imageUrl;
return m_note;
}
+QPixmap User::profileImage() const
+{
+ return m_profileImage;
+}
+
QUrl User::profileImageUrl() const
{
return m_profileImageUrl;
#ifndef USER_H
#define USER_H
+#include <QPixmap>
#include <QPointF>
#include <QString>
#include <QUrl>
void setNote(const QString ¬e);
/**
+ * @brief Set profile image
+ *
+ * @param image Image
+ */
+ void setProfileImage(const QPixmap &image);
+
+ /**
* @brief Set download address for profile image
*
* @param imageUrl image url
QString note() const;
/**
+ * @brief Get profile image
+ *
+ * @return QPixmap image
+ */
+ QPixmap profileImage() const;
+
+ /**
* @brief Get download address for profile image
*
* @return QString url
QString m_units; ///< placeholder for distance unit type
QString m_userId; ///< placeholder for userId
double m_value; ///< placeholder for distance value
+
+ QPixmap m_profileImage; ///< placehokder for image
};