From 94cbe6514270bae3aa8366e0dba3d3537ba1617b Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 4 Jun 2019 11:49:26 +0200 Subject: [PATCH] added various sizes in icons cache so that we do not always allocate the largest sizes --- retroshare-gui/src/gui/ChatLobbyWidget.cpp | 4 +- .../src/gui/Circles/CreateCircleDialog.cpp | 12 +-- .../src/gui/Identity/IdDetailsDialog.cpp | 6 +- retroshare-gui/src/gui/Identity/IdDialog.cpp | 16 ++-- .../src/gui/Identity/IdEditDialog.cpp | 2 +- .../src/gui/People/PeopleDialog.cpp | 4 +- .../src/gui/Posted/PostedDialog.cpp | 2 +- .../src/gui/Posted/PostedGroupDialog.cpp | 2 +- retroshare-gui/src/gui/Posted/PostedItem.cpp | 2 +- retroshare-gui/src/gui/common/AvatarDefs.cpp | 8 +- .../src/gui/common/AvatarDialog.cpp | 6 +- retroshare-gui/src/gui/common/AvatarDialog.h | 4 +- .../src/gui/feeds/GxsChannelGroupItem.cpp | 2 +- .../src/gui/feeds/GxsChannelPostItem.cpp | 2 +- .../src/gui/feeds/PostedGroupItem.cpp | 2 +- retroshare-gui/src/gui/gxs/GxsIdDetails.cpp | 80 ++++++++++++++----- retroshare-gui/src/gui/gxs/GxsIdDetails.h | 13 ++- .../src/gui/gxs/GxsIdTreeWidgetItem.cpp | 4 +- 18 files changed, 107 insertions(+), 64 deletions(-) diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.cpp b/retroshare-gui/src/gui/ChatLobbyWidget.cpp index 82dc7cd6d..d310bc05d 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.cpp +++ b/retroshare-gui/src/gui/ChatLobbyWidget.cpp @@ -322,8 +322,8 @@ void ChatLobbyWidget::lobbyTreeWidgetCustomPopupMenu(QPoint) QPixmap pixmap ; - if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap)) - pixmap = GxsIdDetails::makeDefaultIcon(*it) ; + if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap, GxsIdDetails::SMALL)) + pixmap = GxsIdDetails::makeDefaultIcon(*it,GxsIdDetails::SMALL) ; QAction *action = mnu->addAction(QIcon(pixmap), QString("%1 (%2)").arg(QString::fromUtf8(idd.mNickname.c_str()), QString::fromStdString((*it).toStdString())), this, SLOT(subscribeChatLobbyAs())); action->setData(QString::fromStdString((*it).toStdString())) ; diff --git a/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp b/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp index bf40c6de5..8808f17a3 100644 --- a/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp +++ b/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp @@ -270,8 +270,8 @@ void CreateCircleDialog::addMember(const RsGxsIdGroup &idGroup) QPixmap pixmap ; - if(idGroup.mImage.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idGroup.mImage.mData, idGroup.mImage.mSize, pixmap)) - pixmap = GxsIdDetails::makeDefaultIcon(RsGxsId(idGroup.mMeta.mGroupId)); + if(idGroup.mImage.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idGroup.mImage.mData, idGroup.mImage.mSize, pixmap, GxsIdDetails::SMALL)) + pixmap = GxsIdDetails::makeDefaultIcon(RsGxsId(idGroup.mMeta.mGroupId),GxsIdDetails::SMALL); if (idGroup.mPgpKnown){ RsPeerDetails details; @@ -331,8 +331,8 @@ void CreateCircleDialog::addCircle(const RsGxsCircleDetails &cirDetails) QPixmap pixmap ; - if(gxs_details.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(gxs_details.mAvatar.mData, gxs_details.mAvatar.mSize, pixmap)) - pixmap = GxsIdDetails::makeDefaultIcon(gxs_details.mId); + if(gxs_details.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(gxs_details.mAvatar.mData, gxs_details.mAvatar.mSize, pixmap, GxsIdDetails::SMALL)) + pixmap = GxsIdDetails::makeDefaultIcon(gxs_details.mId,GxsIdDetails::SMALL); addMember(keyId, idtype, nickname, QIcon(pixmap)); @@ -814,8 +814,8 @@ void CreateCircleDialog::loadIdentities(uint32_t token) QPixmap pixmap ; - if(idGroup.mImage.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idGroup.mImage.mData, idGroup.mImage.mSize, pixmap)) - pixmap = GxsIdDetails::makeDefaultIcon(RsGxsId(idGroup.mMeta.mGroupId)) ; + if(idGroup.mImage.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idGroup.mImage.mData, idGroup.mImage.mSize, pixmap, GxsIdDetails::SMALL)) + pixmap = GxsIdDetails::makeDefaultIcon(RsGxsId(idGroup.mMeta.mGroupId),GxsIdDetails::SMALL) ; if (idGroup.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID_kept_for_compatibility) { diff --git a/retroshare-gui/src/gui/Identity/IdDetailsDialog.cpp b/retroshare-gui/src/gui/Identity/IdDetailsDialog.cpp index 2f1a003c0..e5aae3b49 100644 --- a/retroshare-gui/src/gui/Identity/IdDetailsDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDetailsDialog.cpp @@ -183,11 +183,11 @@ void IdDetailsDialog::insertIdDetails(uint32_t token) QPixmap pixmap; - if(data.mImage.mSize > 0 && GxsIdDetails::loadPixmapFromData(data.mImage.mData, data.mImage.mSize, pixmap)) - ui->avatarLabel->setPixmap(pixmap) ; + if(data.mImage.mSize > 0 && GxsIdDetails::loadPixmapFromData(data.mImage.mData, data.mImage.mSize, pixmap, GxsIdDetails::LARGE)) + ui->avatarLabel->setPixmap(pixmap); else { - pixmap = GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId)) ; + pixmap = GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId),GxsIdDetails::LARGE) ; ui->avatarLabel->setPixmap(pixmap) ; // we need to use the default pixmap here, generated from the ID } diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index d0417a271..8bd1f0352 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -752,8 +752,8 @@ void IdDialog::loadCircleGroupMeta(const uint32_t &token) QPixmap pixmap ; - if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap)) - pixmap = GxsIdDetails::makeDefaultIcon(it->first) ; + if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap,GxsIdDetails::SMALL)) + pixmap = GxsIdDetails::makeDefaultIcon(it->first,GxsIdDetails::SMALL) ; if(has_id) subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(idd.mNickname.c_str())) ; @@ -1551,8 +1551,8 @@ bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item, QPixmap pixmap ; - if(data.mImage.mSize == 0 || !GxsIdDetails::loadPixmapFromData(data.mImage.mData, data.mImage.mSize, pixmap)) - pixmap = GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId)) ; + if(data.mImage.mSize == 0 || !GxsIdDetails::loadPixmapFromData(data.mImage.mData, data.mImage.mSize, pixmap,GxsIdDetails::SMALL)) + pixmap = GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId),GxsIdDetails::SMALL) ; item->setIcon(RSID_COL_NICKNAME, QIcon(pixmap)); @@ -1797,8 +1797,8 @@ void IdDialog::insertIdDetails(uint32_t token) QPixmap pixmap ; - if(data.mImage.mSize == 0 || !GxsIdDetails::loadPixmapFromData(data.mImage.mData, data.mImage.mSize, pixmap)) - pixmap = GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId)) ; + if(data.mImage.mSize == 0 || !GxsIdDetails::loadPixmapFromData(data.mImage.mData, data.mImage.mSize, pixmap,GxsIdDetails::LARGE)) + pixmap = GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId),GxsIdDetails::LARGE) ; #ifdef ID_DEBUG std::cerr << "Setting header frame image : " << pixmap.width() << " x " << pixmap.height() << std::endl; @@ -2470,8 +2470,8 @@ void IdDialog::IdListCustomPopupMenu( QPoint ) QPixmap pixmap ; - if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap)) - pixmap = GxsIdDetails::makeDefaultIcon(*it) ; + if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap,GxsIdDetails::SMALL)) + pixmap = GxsIdDetails::makeDefaultIcon(*it,GxsIdDetails::SMALL) ; QAction *action = mnu->addAction(QIcon(pixmap), QString("%1 (%2)").arg(QString::fromUtf8(idd.mNickname.c_str()), QString::fromStdString((*it).toStdString())), this, SLOT(chatIdentity())); action->setData(QString::fromStdString((*it).toStdString())) ; diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp index ac7b6c980..bde6b8f0d 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp @@ -258,7 +258,7 @@ void IdEditDialog::loadExistingId(uint32_t token) QPixmap avatar; if (mEditGroup.mImage.mSize > 0) - GxsIdDetails::loadPixmapFromData(mEditGroup.mImage.mData, mEditGroup.mImage.mSize, avatar); + GxsIdDetails::loadPixmapFromData(mEditGroup.mImage.mData, mEditGroup.mImage.mSize, avatar,GxsIdDetails::LARGE); setAvatar(avatar); diff --git a/retroshare-gui/src/gui/People/PeopleDialog.cpp b/retroshare-gui/src/gui/People/PeopleDialog.cpp index 1aefdcf5b..626df8206 100644 --- a/retroshare-gui/src/gui/People/PeopleDialog.cpp +++ b/retroshare-gui/src/gui/People/PeopleDialog.cpp @@ -467,8 +467,8 @@ void PeopleDialog::iw_AddButtonClickedExt() QPixmap pixmap ; - if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap)) - pixmap = GxsIdDetails::makeDefaultIcon(*it) ; + if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap,GxsIdDetails::SMALL)) + pixmap = GxsIdDetails::makeDefaultIcon(*it,GxsIdDetails::SMALL) ; QAction *action = mnu->addAction(QIcon(pixmap), QString("%1 (%2)").arg(QString::fromUtf8(idd.mNickname.c_str()), QString::fromStdString((*it).toStdString())), this, SLOT(chatIdentity())); action->setData(QString::fromStdString((*it).toStdString()) + ";" + QString::fromStdString(dest->groupInfo().mMeta.mGroupId.toStdString())) ; diff --git a/retroshare-gui/src/gui/Posted/PostedDialog.cpp b/retroshare-gui/src/gui/Posted/PostedDialog.cpp index 1ae281f94..c312bd8e8 100644 --- a/retroshare-gui/src/gui/Posted/PostedDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedDialog.cpp @@ -165,7 +165,7 @@ void PostedDialog::loadGroupSummaryToken(const uint32_t &token, std::listmIcon[group.mMeta.mGroupId] = image; } diff --git a/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp b/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp index 1410ec6f9..678c41a98 100644 --- a/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp @@ -164,7 +164,7 @@ bool PostedGroupDialog::service_loadGroup(uint32_t token, Mode /*mode*/, RsGroup if (group.mGroupImage.mData) { QPixmap pixmap; - if (GxsIdDetails::loadPixmapFromData(group.mGroupImage.mData, group.mGroupImage.mSize, pixmap)) + if (GxsIdDetails::loadPixmapFromData(group.mGroupImage.mData, group.mGroupImage.mSize, pixmap,GxsIdDetails::ORIGINAL)) setLogo(pixmap); } else { diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp index a967d2771..5e42a1ef6 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.cpp +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -256,7 +256,7 @@ void PostedItem::fill() if(mPost.mImage.mData != NULL) { QPixmap pixmap; - GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap); + GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL); // Wiping data - as its been passed to thumbnail. QPixmap sqpixmap = pixmap.scaled(desired_width,desired_height, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); diff --git a/retroshare-gui/src/gui/common/AvatarDefs.cpp b/retroshare-gui/src/gui/common/AvatarDefs.cpp index a507689bf..a3b6c3b54 100644 --- a/retroshare-gui/src/gui/common/AvatarDefs.cpp +++ b/retroshare-gui/src/gui/common/AvatarDefs.cpp @@ -41,7 +41,7 @@ void AvatarDefs::getOwnAvatar(QPixmap &avatar, const QString& defaultImage) } /* load image */ - GxsIdDetails::loadPixmapFromData(data, size, avatar) ; + GxsIdDetails::loadPixmapFromData(data, size, avatar,GxsIdDetails::ORIGINAL) ; free(data); } @@ -58,7 +58,7 @@ void AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, cons } /* load image */ - GxsIdDetails::loadPixmapFromData(data, size, avatar) ; + GxsIdDetails::loadPixmapFromData(data, size, avatar, GxsIdDetails::LARGE) ; free(data); } @@ -77,8 +77,8 @@ void AvatarDefs::getAvatarFromGxsId(const RsGxsId& gxsId, QPixmap &avatar, const /* load image */ - if(details.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(details.mAvatar.mData, details.mAvatar.mSize, avatar)) - avatar = GxsIdDetails::makeDefaultIcon(gxsId); + if(details.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(details.mAvatar.mData, details.mAvatar.mSize, avatar,GxsIdDetails::LARGE)) + avatar = GxsIdDetails::makeDefaultIcon(gxsId,GxsIdDetails::LARGE); } void AvatarDefs::getAvatarFromGpgId(const RsPgpId& gpgId, QPixmap &avatar, const QString& defaultImage) diff --git a/retroshare-gui/src/gui/common/AvatarDialog.cpp b/retroshare-gui/src/gui/common/AvatarDialog.cpp index 0ff7a9232..c6a9f9c0b 100644 --- a/retroshare-gui/src/gui/common/AvatarDialog.cpp +++ b/retroshare-gui/src/gui/common/AvatarDialog.cpp @@ -45,8 +45,8 @@ AvatarDialog::AvatarDialog(QWidget *parent) : updateInterface(); } -const int AvatarDialog::RS_AVATAR_IMAGE_W = 128; -const int AvatarDialog::RS_AVATAR_IMAGE_H = 128; +const int AvatarDialog::RS_AVATAR_DEFAULT_IMAGE_W = 64; +const int AvatarDialog::RS_AVATAR_DEFAULT_IMAGE_H = 64; AvatarDialog::~AvatarDialog() { @@ -55,7 +55,7 @@ AvatarDialog::~AvatarDialog() void AvatarDialog::changeAvatar() { - QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load Avatar"), RS_AVATAR_IMAGE_W,RS_AVATAR_IMAGE_H); + QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load Avatar"), RS_AVATAR_DEFAULT_IMAGE_W,RS_AVATAR_DEFAULT_IMAGE_H); if (img.isNull()) return; diff --git a/retroshare-gui/src/gui/common/AvatarDialog.h b/retroshare-gui/src/gui/common/AvatarDialog.h index daf6e655f..407e95604 100644 --- a/retroshare-gui/src/gui/common/AvatarDialog.h +++ b/retroshare-gui/src/gui/common/AvatarDialog.h @@ -35,8 +35,8 @@ class AvatarDialog : public QDialog Q_OBJECT public: - static const int RS_AVATAR_IMAGE_W ; - static const int RS_AVATAR_IMAGE_H ; + static const int RS_AVATAR_DEFAULT_IMAGE_W ; + static const int RS_AVATAR_DEFAULT_IMAGE_H ; AvatarDialog(QWidget *parent = 0); ~AvatarDialog(); diff --git a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp index 32e396f0d..edc83c586 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp @@ -135,7 +135,7 @@ void GxsChannelGroupItem::fill() if (mGroup.mImage.mData != NULL) { QPixmap chanImage; - GxsIdDetails::loadPixmapFromData(mGroup.mImage.mData, mGroup.mImage.mSize, chanImage); + GxsIdDetails::loadPixmapFromData(mGroup.mImage.mData, mGroup.mImage.mSize, chanImage,GxsIdDetails::ORIGINAL); ui->logoLabel->setPixmap(QPixmap(chanImage)); } diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index 775090695..9b70ca191 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -393,7 +393,7 @@ void GxsChannelPostItem::fill() if(mPost.mThumbnail.mData != NULL) { QPixmap thumbnail; - GxsIdDetails::loadPixmapFromData(mPost.mThumbnail.mData, mPost.mThumbnail.mSize, thumbnail); + GxsIdDetails::loadPixmapFromData(mPost.mThumbnail.mData, mPost.mThumbnail.mSize, thumbnail,GxsIdDetails::ORIGINAL); // Wiping data - as its been passed to thumbnail. ui->logoLabel->setPixmap(thumbnail); } diff --git a/retroshare-gui/src/gui/feeds/PostedGroupItem.cpp b/retroshare-gui/src/gui/feeds/PostedGroupItem.cpp index a79467f4c..f0453e4df 100644 --- a/retroshare-gui/src/gui/feeds/PostedGroupItem.cpp +++ b/retroshare-gui/src/gui/feeds/PostedGroupItem.cpp @@ -138,7 +138,7 @@ void PostedGroupItem::fill() if (mGroup.mGroupImage.mData != NULL) { QPixmap postedImage; - GxsIdDetails::loadPixmapFromData(mGroup.mGroupImage.mData, mGroup.mGroupImage.mSize, postedImage); + GxsIdDetails::loadPixmapFromData(mGroup.mGroupImage.mData, mGroup.mGroupImage.mSize, postedImage,GxsIdDetails::ORIGINAL); ui->logoLabel->setPixmap(QPixmap(postedImage)); } else { ui->logoLabel->setPixmap(QPixmap(":/images/posted_64.png")); diff --git a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp index 61f3fb0f0..59d910b0a 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp @@ -68,10 +68,10 @@ uint32_t GxsIdDetails::mImagesAllocated = 0; time_t GxsIdDetails::mLastIconCacheCleaning = time(NULL); -std::map > GxsIdDetails::mDefaultIconCache ; +std::map[4] > GxsIdDetails::mDefaultIconCache ; -#define ICON_CACHE_STORAGE_TIME 600 -#define DELAY_BETWEEN_ICON_CACHE_CLEANING 300 +#define ICON_CACHE_STORAGE_TIME 60 +#define DELAY_BETWEEN_ICON_CACHE_CLEANING 30 void ReputationItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { @@ -459,7 +459,7 @@ static bool findTagIcon(int tag_class, int /*tag_type*/, QIcon &icon) * Bring the source code from this adaptation: * http://francisshanahan.com/identicon5/test.html */ -const QPixmap GxsIdDetails::makeDefaultIcon(const RsGxsId& id) +const QPixmap GxsIdDetails::makeDefaultIcon(const RsGxsId& id, AvatarSize size) { checkCleanImagesCache(); @@ -471,17 +471,28 @@ const QPixmap GxsIdDetails::makeDefaultIcon(const RsGxsId& id) // now look for the icon - auto it = mDefaultIconCache.find(id); + auto& it = mDefaultIconCache[id]; - if(it != mDefaultIconCache.end()) + if(it[(int)size].second.width() > 0) { - it->second.first = now; - return it->second.second; + it[(int)size].first = now; + return it[(int)size].second; } - QPixmap image = drawIdentIcon(QString::fromStdString(id.toStdString()),64*3, true); + int S =0; - mDefaultIconCache[id] = std::make_pair(now,image); + switch(size) + { + case SMALL: S = 16*3 ; break; + default: + case MEDIUM: S = 32*3 ; break; + case ORIGINAL: + case LARGE: S = 64*3 ; break; + } + + QPixmap image = drawIdentIcon(QString::fromStdString(id.toStdString()),S,true); + + it[(int)size] = std::make_pair(now,image); return image; } @@ -498,13 +509,26 @@ void GxsIdDetails::checkCleanImagesCache() int nb_deleted = 0; for(auto it(mDefaultIconCache.begin());it!=mDefaultIconCache.end();) - if(it->second.first + ICON_CACHE_STORAGE_TIME < now && it->second.second.isDetached()) - { + { + bool all_empty = true ; + + for(int i=0;i<4;++i) + if(it->second[i].first + ICON_CACHE_STORAGE_TIME < now && it->second[i].second.isDetached()) + { + it->second[i].second = QPixmap(); + + std::cerr << "Deleting pixmap " << it->first << " size " << i << std::endl; + it = mDefaultIconCache.erase(it); + ++nb_deleted; + } + else + all_empty = false; + + if(all_empty) it = mDefaultIconCache.erase(it); - ++nb_deleted; - } else ++it; + } mLastIconCacheCleaning = now; std::cerr << "(II) Removed " << nb_deleted << " unused icons. Cache contains " << mDefaultIconCache.size() << " icons"<< std::endl; @@ -512,7 +536,7 @@ void GxsIdDetails::checkCleanImagesCache() } -bool GxsIdDetails::loadPixmapFromData(const unsigned char *data,size_t data_len,QPixmap& pixmap) +bool GxsIdDetails::loadPixmapFromData(const unsigned char *data,size_t data_len,QPixmap& pixmap, AvatarSize size) { // The trick below converts the data into an Id that can be read in the image cache. Because this method is mainly dedicated to loading // avatars, we could also use the GxsId as id, but the avatar may change in time, so we actually need to make the id from the data itself. @@ -531,12 +555,12 @@ bool GxsIdDetails::loadPixmapFromData(const unsigned char *data,size_t data_len, // now look for the icon time_t now = time(NULL); - auto it = mDefaultIconCache.find(id); + auto& it = mDefaultIconCache[id]; - if(it != mDefaultIconCache.end()) + if(it[(int)size].second.width() > 0) { - it->second.first = now; - pixmap = it->second.second; + it[(int)size].first = now; + pixmap = it[(int)size].second; return true; } @@ -546,11 +570,23 @@ bool GxsIdDetails::loadPixmapFromData(const unsigned char *data,size_t data_len, // This resize is here just to prevent someone to explicitely add a huge blank image to screw up the UI - if(pixmap.width() != AvatarDialog::RS_AVATAR_IMAGE_W || pixmap.height() != AvatarDialog::RS_AVATAR_IMAGE_H) - pixmap = pixmap.scaled(AvatarDialog::RS_AVATAR_IMAGE_W,AvatarDialog::RS_AVATAR_IMAGE_H,Qt::IgnoreAspectRatio,Qt::SmoothTransformation); + int wanted_S=0; - mDefaultIconCache[id] = std::make_pair(now,pixmap); + switch(size) + { + case ORIGINAL: wanted_S = 0 ;break; + case SMALL: wanted_S = 32 ;break; + default: + case MEDIUM: wanted_S = 64 ;break; + case LARGE: wanted_S = 128 ;break; + } + if(wanted_S > 0) + pixmap = pixmap.scaled(wanted_S,wanted_S,Qt::IgnoreAspectRatio,Qt::SmoothTransformation); + + mDefaultIconCache[id][(int)size] = std::make_pair(now,pixmap); + + std::cerr << "Allocated new icon " << id << " size " << (int)size << std::endl; return true; } /** diff --git a/retroshare-gui/src/gui/gxs/GxsIdDetails.h b/retroshare-gui/src/gui/gxs/GxsIdDetails.h index f07f0132d..2cb8145e4 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdDetails.h +++ b/retroshare-gui/src/gui/gxs/GxsIdDetails.h @@ -74,6 +74,13 @@ public: GxsIdDetails(); virtual ~GxsIdDetails(); + enum AvatarSize { + SMALL = 0x00, + MEDIUM = 0x01, + LARGE = 0x02, + ORIGINAL= 0x03 + }; + static void initialize(); static void cleanup(); @@ -104,8 +111,8 @@ public: // These two methods use a cache so as to minimize the memory impact of avatars. - static const QPixmap makeDefaultIcon(const RsGxsId& id); - static bool loadPixmapFromData(const unsigned char *data,size_t data_len,QPixmap& pix); + static const QPixmap makeDefaultIcon(const RsGxsId& id, AvatarSize size = MEDIUM); + static bool loadPixmapFromData(const unsigned char *data, size_t data_len, QPixmap& pix, AvatarSize size = MEDIUM); static void checkCleanImagesCache(); /* Processing */ @@ -162,7 +169,7 @@ protected: QMap::iterator mPendingDataIterator; static uint32_t mImagesAllocated; - static std::map > mDefaultIconCache; + static std::map[4] > mDefaultIconCache; static time_t mLastIconCacheCleaning; int mCheckTimerId; diff --git a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp index a5ee46865..f6709922a 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp @@ -160,8 +160,8 @@ QVariant GxsIdRSTreeWidgetItem::data(int column, int role) const return RSTreeWidgetItem::data(column, role); else if( rsReputations->overallReputationLevel(mId) == RsReputationLevel::LOCALLY_NEGATIVE ) pix = QPixmap(BANNED_IMAGE); - else if ( mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(mAvatar.mData, mAvatar.mSize, pix) ) - pix = GxsIdDetails::makeDefaultIcon(mId); + else if ( mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(mAvatar.mData, mAvatar.mSize, pix,GxsIdDetails::LARGE) ) + pix = GxsIdDetails::makeDefaultIcon(mId,GxsIdDetails::LARGE); int S = QFontMetricsF(font(column)).height();