Optimized avatar loading in RsFriendListModel

This commit is contained in:
thunder2 2024-07-01 16:20:11 +02:00
parent 19d613edcc
commit c8975bb2e9
2 changed files with 23 additions and 20 deletions

View File

@ -54,7 +54,9 @@ bool AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, cons
/* get avatar */ /* get avatar */
rsMsgs->getAvatarData(RsPeerId(sslId), data, size); rsMsgs->getAvatarData(RsPeerId(sslId), data, size);
if (size == 0) { if (size == 0) {
if (!defaultImage.isEmpty()) {
avatar = FilesDefs::getPixmapFromQtResourcePath(defaultImage); avatar = FilesDefs::getPixmapFromQtResourcePath(defaultImage);
}
return false; return false;
} }

View File

@ -931,23 +931,25 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons
{ {
if(!isProfileExpanded(entry)) if(!isProfileExpanded(entry))
{ {
QPixmap sslAvatar = FilesDefs::getPixmapFromQtResourcePath(AVATAR_DEFAULT_IMAGE); QPixmap sslAvatar;
QPixmap sslOverlayIcon;
sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(onlineRole(entry,col).toInt()));
const HierarchicalProfileInformation *hn = getProfileInfo(entry); const HierarchicalProfileInformation *hn = getProfileInfo(entry);
for(uint32_t i=0;i<hn->child_node_indices.size();++i) for(uint32_t i=0;i<hn->child_node_indices.size();++i) {
if(AvatarDefs::getAvatarFromSslId(RsPeerId(mLocations[hn->child_node_indices[i]].node_info.id.toStdString()), sslAvatar)) if(AvatarDefs::getAvatarFromSslId(RsPeerId(mLocations[hn->child_node_indices[i]].node_info.id.toStdString()), sslAvatar, "")) {
if (mDisplayStatusIcon) break;
return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon))); }
else }
return QVariant(QIcon(sslAvatar));
if (mDisplayStatusIcon) if (sslAvatar.isNull()) {
sslAvatar = FilesDefs::getPixmapFromQtResourcePath(AVATAR_DEFAULT_IMAGE);
}
if (mDisplayStatusIcon) {
QPixmap sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(onlineRole(entry, col).toInt()));
return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon))); return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon)));
else }
return QVariant(QIcon(sslAvatar)); return QVariant(QIcon(sslAvatar));
} }
@ -962,13 +964,12 @@ QVariant RsFriendListModel::decorationRole(const EntryIndex& entry,int col) cons
return QVariant(); return QVariant();
QPixmap sslAvatar; QPixmap sslAvatar;
QPixmap sslOverlayIcon;
sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(statusRole(entry,col).toInt()));
AvatarDefs::getAvatarFromSslId(RsPeerId(hn->node_info.id.toStdString()), sslAvatar); AvatarDefs::getAvatarFromSslId(RsPeerId(hn->node_info.id.toStdString()), sslAvatar);
if (mDisplayStatusIcon) if (mDisplayStatusIcon) {
QPixmap sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(statusRole(entry, col).toInt()));
return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon))); return QVariant(QIcon(createAvatar(sslAvatar, sslOverlayIcon)));
else }
return QVariant(QIcon(sslAvatar)); return QVariant(QIcon(sslAvatar));
} }
default: return QVariant(); default: return QVariant();