diff --git a/retroshare-gui/src/gui/common/FriendListModel.cpp b/retroshare-gui/src/gui/common/FriendListModel.cpp index d706ac5f2..7bb836c56 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.cpp +++ b/retroshare-gui/src/gui/common/FriendListModel.cpp @@ -898,6 +898,61 @@ bool RsFriendListModel::getPeerOnlineStatus(const EntryIndex& e) const return (noded && (noded->node_info.state & RS_PEER_STATE_CONNECTED)); } +bool RsFriendListModel::getProfileStatus(const HierarchicalProfileInformation *profileInfo, uint32_t &status) const +{ + status = RS_STATUS_OFFLINE; + + if (!profileInfo) { + return false; + } + + int bestStatusIndex = 0; + + /* Find the best status */ + for (uint32_t i = 0; i < profileInfo->child_node_indices.size(); ++i) { + StatusInfo statusInfo; + rsStatus->getStatus(mLocations[profileInfo->child_node_indices[i]].node_info.id, statusInfo); + + int statusIndex = 0; + switch (statusInfo.status) { + case RS_STATUS_OFFLINE: + statusIndex = 1; + break; + + case RS_STATUS_INACTIVE: + statusIndex = 2; + break; + + case RS_STATUS_AWAY: + statusIndex = 3; + break; + + case RS_STATUS_BUSY: + statusIndex = 4; + break; + + case RS_STATUS_ONLINE: + statusIndex = 5; + break; + + default: + std::cerr << "FriendListModel: Unknown status " << statusInfo.status << std::endl; + } + + if (bestStatusIndex == 0 || statusIndex > bestStatusIndex) { + /* first status or better status */ + bestStatusIndex = statusIndex; + status = statusInfo.status; + } + } + + if (bestStatusIndex == 0) { + return false; + } + + return true; +} + QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) const { if(col > 0) @@ -946,8 +1001,11 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons } if (mDisplayStatusIcon) { - QPixmap sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(onlineRole(entry, col).toInt())); - return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon))); + uint32_t status; + if (getProfileStatus(hn, status)) { + QPixmap sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(status)); + return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon))); + } } return QVariant(QIcon(sslAvatar)); diff --git a/retroshare-gui/src/gui/common/FriendListModel.h b/retroshare-gui/src/gui/common/FriendListModel.h index ea4137085..c5a8e9705 100644 --- a/retroshare-gui/src/gui/common/FriendListModel.h +++ b/retroshare-gui/src/gui/common/FriendListModel.h @@ -223,6 +223,8 @@ private: uint32_t updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings); + bool getProfileStatus(const HierarchicalProfileInformation *profileInfo, uint32_t &status) const; + QStringList mFilterStrings; FilterType mFilterType;