added avatar to GxsId tooltip (see in forums). Removed thread data race due to multiple threads accessing the static data member image_cache, causing avatars to not show up randomly. I do not have a clean solution yet on how to restore this cache

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7911 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-02-04 23:05:56 +00:00
parent 52901c1ddb
commit 5ae5d4f0a1
3 changed files with 63 additions and 41 deletions

View file

@ -207,13 +207,13 @@ bool GxsIdDetails::process(const RsGxsId &id, GxsIdDetailsCallbackFunction callb
} }
details.mId = id; details.mId = id;
callback(GXS_ID_DETAILS_TYPE_LOADING, details, object, data);
/* Add id to the pending list */ /* Add id to the pending list */
if (!mInstance) { if (!mInstance) {
mInstance = new GxsIdDetails; mInstance = new GxsIdDetails;
mInstance->moveToThread(qApp->thread()); mInstance->moveToThread(qApp->thread());
} }
callback(GXS_ID_DETAILS_TYPE_LOADING, details, object, data);
CallbackData pendingData; CallbackData pendingData;
pendingData.mId = id; pendingData.mId = id;
@ -338,9 +338,9 @@ static bool findTagIcon(int tag_class, int /*tag_type*/, QIcon &icon)
* Bring the source code from this adaptation: * Bring the source code from this adaptation:
* http://francisshanahan.com/identicon5/test.html * http://francisshanahan.com/identicon5/test.html
*/ */
QImage GxsIdDetails::makeDefaultIcon(const RsGxsId& id) QImage GxsIdDetails::makeDefaultIconLocal_locked(const RsGxsId& id)
{ {
static std::map<RsGxsId,QImage> image_cache ; QMutexLocker lock(&mMutex2);
std::map<RsGxsId,QImage>::const_iterator it = image_cache.find(id) ; std::map<RsGxsId,QImage>::const_iterator it = image_cache.find(id) ;
@ -351,6 +351,13 @@ QImage GxsIdDetails::makeDefaultIcon(const RsGxsId& id)
return image_cache[id] ; return image_cache[id] ;
} }
QImage GxsIdDetails::makeDefaultIcon(const RsGxsId& id)
{
// if(mInstance != NULL)
// return mInstance->makeDefaultIconLocal_locked(id) ;
// else
return drawIdentIcon(QString::fromStdString(id.toStdString()),64*3, true);
}
/** /**
* @brief GxsIdDetails::getSprite * @brief GxsIdDetails::getSprite
@ -846,26 +853,26 @@ QString GxsIdDetails::getComment(const RsIdentityDetails &details)
{ {
QString comment; QString comment;
comment = QString("%1: %2\n%3: %4").arg(QApplication::translate("GxsIdDetails", "Identity name"), comment = QString("%1:%2<br/>%3:%4").arg(QApplication::translate("GxsIdDetails", "Identity&nbsp;name"),
QString::fromUtf8(details.mNickname.c_str()), QString::fromUtf8(details.mNickname.c_str()),
QApplication::translate("GxsIdDetails", "Identity Id"), QApplication::translate("GxsIdDetails", "Identity&nbsp;Id"),
QString::fromStdString(details.mId.toStdString())); QString::fromStdString(details.mId.toStdString()));
if (details.mPgpLinked) if (details.mPgpLinked)
{ {
comment += QString("\n%1: %2 ").arg(QApplication::translate("GxsIdDetails", "Authentication"), QApplication::translate("GxsIdDetails", "signed by")); comment += QString("<br/>%1:%2 ").arg(QApplication::translate("GxsIdDetails", "Authentication"), QApplication::translate("GxsIdDetails", "Signed&nbsp;by"));
if (details.mPgpKnown) if (details.mPgpKnown)
{ {
/* look up real name */ /* look up real name */
std::string authorName = rsPeers->getGPGName(details.mPgpId); std::string authorName = rsPeers->getGPGName(details.mPgpId);
comment += QString("%1 [%2]").arg(QString::fromUtf8(authorName.c_str()), QString::fromStdString(details.mPgpId.toStdString())); comment += QString("%1&nbsp;[%2]").arg(QString::fromUtf8(authorName.c_str()), QString::fromStdString(details.mPgpId.toStdString()));
} }
else else
comment += QApplication::translate("GxsIdDetails", "unknown Key"); comment += QApplication::translate("GxsIdDetails", "unknown Key");
} }
else else
comment += QString("\n%1: %2").arg(QApplication::translate("GxsIdDetails", "Authentication"), QApplication::translate("GxsIdDetails", "anonymous")); comment += QString("<br/>%1:&nbsp;%2").arg(QApplication::translate("GxsIdDetails", "Authentication"), QApplication::translate("GxsIdDetails", "anonymous"));
return comment; return comment;
} }

View file

@ -80,6 +80,7 @@ signals:
protected: protected:
void connectObject_locked(QObject *object, bool doConnect); void connectObject_locked(QObject *object, bool doConnect);
QImage makeDefaultIconLocal_locked(const RsGxsId& id);
/* Timer */ /* Timer */
virtual void timerEvent(QTimerEvent *event); virtual void timerEvent(QTimerEvent *event);
@ -123,9 +124,11 @@ protected:
/* Pending data */ /* Pending data */
QList<CallbackData> mPendingData; QList<CallbackData> mPendingData;
int mCheckTimerId; int mCheckTimerId;
std::map<RsGxsId,QImage> image_cache ;
/* Thread safe */ /* Thread safe */
QMutex mMutex; QMutex mMutex;
QMutex mMutex2;
}; };
#endif #endif

View file

@ -23,6 +23,7 @@
#include "GxsIdTreeWidgetItem.h" #include "GxsIdTreeWidgetItem.h"
#include "GxsIdDetails.h" #include "GxsIdDetails.h"
#include "util/HandleRichText.h"
/** Constructor */ /** Constructor */
GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *parent) GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *parent)
@ -69,7 +70,6 @@ static void fillGxsIdRSTreeWidgetItemCallback(GxsIdDetailsType type, const RsIde
int column = item->idColumn(); int column = item->idColumn();
item->setText(column, GxsIdDetails::getNameForType(type, details)); item->setText(column, GxsIdDetails::getNameForType(type, details));
item->setToolTip(column, toolTip);
item->setData(column, Qt::UserRole, QString::fromStdString(details.mId.toStdString())); item->setData(column, Qt::UserRole, QString::fromStdString(details.mId.toStdString()));
QIcon combinedIcon; QIcon combinedIcon;
@ -77,6 +77,18 @@ static void fillGxsIdRSTreeWidgetItemCallback(GxsIdDetailsType type, const RsIde
GxsIdDetails::GenerateCombinedIcon(combinedIcon, icons); GxsIdDetails::GenerateCombinedIcon(combinedIcon, icons);
} }
item->setIcon(column, combinedIcon); item->setIcon(column, combinedIcon);
QImage pix ;
if(details.mAvatar.mSize == 0 || !pix.loadFromData(details.mAvatar.mData, details.mAvatar.mSize, "PNG"))
pix = GxsIdDetails::makeDefaultIcon(details.mId);
QString embeddedImage ;
if(RsHtml::makeEmbeddedImage(pix.scaled(QSize(64,64),Qt::KeepAspectRatio,Qt::SmoothTransformation),embeddedImage,128*128))
toolTip = "<table><tr><td>"+embeddedImage+"</td><td>" +toolTip+ "</td></table>" ;
item->setToolTip(column, toolTip);
} }
void GxsIdRSTreeWidgetItem::setId(const RsGxsId &id, int column) void GxsIdRSTreeWidgetItem::setId(const RsGxsId &id, int column)