+ if(imageUrl.isEmpty()) {
+ // friend doesn't have profile image, so we need to get him a silhouette image
+ m_defaultImage = true;
+ }
+
+ QString address = friendMap["address"].toString();
+ if(address.isEmpty()) {
+ QStringList location;
+ location.append(QString::number(coordinates.latitude()));
+ location.append(QString::number(coordinates.longitude()));
+ address = location.join(", ");
+ }
+
+ User buddy = User(address, coordinates, friendMap["name"].toString(),
+ friendMap["note"].toString(), imageUrl,
+ friendMap["timestamp"].toString(),
+ false, friendMap["uid"].toString(), distanceMap["units"].toString(),
+ distanceMap["value"].toDouble());
+
+ tmpFriendsList.append(buddy);
+ }
+
+ QList<QUrl> imageUrlList; // url list for images
+
+ // set unchanged profile images or add new images to imageUrlList for downloading
+ if(m_user) {
+ if(m_user->profileImageUrl() != user.profileImageUrl()) {
+ if(!user.profileImageUrl().isEmpty())
+ imageUrlList.append(user.profileImageUrl());
+ } else {
+ user.setProfileImage(m_user->profileImage());
+ }
+ } else {
+ if(!user.profileImageUrl().isEmpty())
+ imageUrlList.append(user.profileImageUrl());
+ }
+
+ // clear old user object
+ if(m_user) {
+ delete m_user;
+ m_user = 0;
+ }
+
+ // create new user object from temporary user object
+ m_user = new User(user);
+
+ // set unchanged profile images or add new images to imageUrlList for downloading
+ if(!m_friendsList.isEmpty()) {
+ foreach(User tmpBuddy, tmpFriendsList) {
+ if(!tmpBuddy.profileImageUrl().isEmpty()) {
+ bool found = false;
+ foreach(User *buddy, m_friendsList) {
+ if(tmpBuddy.profileImageUrl() == buddy->profileImageUrl()) {
+ tmpBuddy.setProfileImage(buddy->profileImage());
+ found = true;
+ break;
+ }
+ }
+ if(!found && !tmpBuddy.profileImageUrl().isEmpty())
+ imageUrlList.append(tmpBuddy.profileImageUrl());
+ }
+ }
+ } else {
+ foreach(User buddy, tmpFriendsList) {
+ if(!buddy.profileImageUrl().isEmpty())
+ imageUrlList.append(buddy.profileImageUrl());
+ }
+ }
+
+ // clear old friendlist
+ qDeleteAll(m_friendsList.begin(), m_friendsList.end());
+ m_friendsList.clear();
+
+ // populate new friendlist with temporary friendlist's data
+ foreach(User tmpFriendItem, tmpFriendsList) {
+ User *friendItem = new User(tmpFriendItem);
+ m_friendsList.append(friendItem);
+ }
+ tmpFriendsList.clear();
+
+ emit userDataChanged(m_user, m_friendsList);
+
+ // set silhouette image to imageUrlList for downloading
+ if(m_defaultImage)
+ imageUrlList.append(QUrl(SILHOUETTE_URL));
+
+ addProfileImages(imageUrlList);
+ imageUrlList.clear();
+ } else {
+ QVariant address = result.value("address");
+ if(!address.toString().isEmpty()) {
+ emit reverseGeoReady(address.toString());
+ } else {
+ QStringList coordinates;
+ coordinates.append(result.value("lat").toString());
+ coordinates.append(result.value("lon").toString());
+
+ emit error(ErrorContext::SITUARE, SituareError::ADDRESS_RETRIEVAL_FAILED);
+ emit reverseGeoReady(coordinates.join(", "));
+ }
+ }