Merge pull request #531 from PhenomRetroShare/Fix_AvatarOnEditCircle

Fix Missing ID-Avatars in Create Circle Menu
This commit is contained in:
Cyril Soler 2016-10-09 18:23:25 +02:00 committed by GitHub
commit 32816eda71
4 changed files with 90 additions and 66 deletions

View File

@ -25,16 +25,16 @@
#include <QMenu> #include <QMenu>
#include <algorithm> #include <algorithm>
#include "gui/Circles/CreateCircleDialog.h"
#include "gui/gxs/GxsIdDetails.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include <retroshare/rsidentity.h> #include <retroshare/rsidentity.h>
#include "gui/common/AvatarDefs.h"
#include "gui/Circles/CreateCircleDialog.h"
#include "gui/gxs/GxsIdDetails.h"
#include "gui/Identity/IdDialog.h" #include "gui/Identity/IdDialog.h"
#include "gui/Identity/IdEditDialog.h" #include "gui/Identity/IdEditDialog.h"
#include <algorithm>
//#define DEBUG_CREATE_CIRCLE_DIALOG 1 //#define DEBUG_CREATE_CIRCLE_DIALOG 1
#define CREATECIRCLEDIALOG_CIRCLEINFO 2 #define CREATECIRCLEDIALOG_CIRCLEINFO 2
@ -258,8 +258,9 @@ void CreateCircleDialog::addMember()
QString keyId = item->text(RSCIRCLEID_COL_KEYID); QString keyId = item->text(RSCIRCLEID_COL_KEYID);
QString idtype = item->text(RSCIRCLEID_COL_IDTYPE); QString idtype = item->text(RSCIRCLEID_COL_IDTYPE);
QString nickname = item->text(RSCIRCLEID_COL_NICKNAME); QString nickname = item->text(RSCIRCLEID_COL_NICKNAME);
QIcon icon = item->icon(RSCIRCLEID_COL_NICKNAME);
addMember(keyId, idtype, nickname); addMember(keyId, idtype, nickname, icon);
} }
void CreateCircleDialog::addMember(const RsGxsIdGroup &idGroup) void CreateCircleDialog::addMember(const RsGxsIdGroup &idGroup)
@ -267,15 +268,27 @@ void CreateCircleDialog::addMember(const RsGxsIdGroup &idGroup)
QString keyId = QString::fromStdString(idGroup.mMeta.mGroupId.toStdString()); QString keyId = QString::fromStdString(idGroup.mMeta.mGroupId.toStdString());
QString nickname = QString::fromUtf8(idGroup.mMeta.mGroupName.c_str()); QString nickname = QString::fromUtf8(idGroup.mMeta.mGroupName.c_str());
QString idtype = tr("Anon Id"); QString idtype = tr("Anon Id");
QPixmap pixmap ;
if(idGroup.mImage.mSize == 0 || !pixmap.loadFromData(idGroup.mImage.mData, idGroup.mImage.mSize, "PNG"))
pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(RsGxsId(idGroup.mMeta.mGroupId)));
if (idGroup.mPgpKnown){ if (idGroup.mPgpKnown){
RsPeerDetails details; RsPeerDetails details;
rsPeers->getGPGDetails(idGroup.mPgpId, details); rsPeers->getGPGDetails(idGroup.mPgpId, details);
idtype = QString::fromUtf8(details.name.c_str()); idtype = QString::fromUtf8(details.name.c_str());
}//if (idGroup.mPgpKnown) }//if (idGroup.mPgpKnown)
addMember(keyId, idtype, nickname); addMember(keyId, idtype, nickname, QIcon(pixmap));
} }
void CreateCircleDialog::addMember(const QString& keyId, const QString& idtype, const QString& nickname ) void CreateCircleDialog::addMember(const QString& keyId, const QString& idtype, const QString& nickname )
{
QIcon icon;
addMember(keyId, idtype, nickname, icon);
}
void CreateCircleDialog::addMember(const QString& keyId, const QString& idtype, const QString& nickname, const QIcon& icon)
{ {
QTreeWidget *tree = ui.treeWidget_membership; QTreeWidget *tree = ui.treeWidget_membership;
@ -293,9 +306,9 @@ void CreateCircleDialog::addMember(const QString& keyId, const QString& idtype,
QTreeWidgetItem *member = new QTreeWidgetItem(); QTreeWidgetItem *member = new QTreeWidgetItem();
member->setText(RSCIRCLEID_COL_NICKNAME, nickname); member->setText(RSCIRCLEID_COL_NICKNAME, nickname);
member->setIcon(RSCIRCLEID_COL_NICKNAME, icon);
member->setText(RSCIRCLEID_COL_KEYID, keyId); member->setText(RSCIRCLEID_COL_KEYID, keyId);
member->setText(RSCIRCLEID_COL_IDTYPE, idtype); member->setText(RSCIRCLEID_COL_IDTYPE, idtype);
//member->setIcon(RSCIRCLEID_COL_NICKNAME, pixmap);
tree->addTopLevelItem(member); tree->addTopLevelItem(member);
@ -317,7 +330,12 @@ void CreateCircleDialog::addCircle(const RsGxsCircleDetails &cirDetails)
QString nickname = QString::fromUtf8(gxs_details.mNickname.c_str()); QString nickname = QString::fromUtf8(gxs_details.mNickname.c_str());
QString idtype = tr("Anon Id"); QString idtype = tr("Anon Id");
addMember(keyId, idtype, nickname); QPixmap pixmap ;
if(gxs_details.mAvatar.mSize == 0 || !pixmap.loadFromData(gxs_details.mAvatar.mData, gxs_details.mAvatar.mSize, "PNG"))
pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(gxs_details.mId));
addMember(keyId, idtype, nickname, QIcon(pixmap));
}//if(!gxs_id.isNull() && rsIdentity->getIdDetails(gxs_id,gxs_details)) }//if(!gxs_id.isNull() && rsIdentity->getIdDetails(gxs_id,gxs_details))
}//for (itUnknownPeers it = cirDetails.mUnknownPeers.begin() }//for (itUnknownPeers it = cirDetails.mUnknownPeers.begin()
@ -333,7 +351,10 @@ void CreateCircleDialog::addCircle(const RsGxsCircleDetails &cirDetails)
QString nickname = QString::fromUtf8(details.name.c_str()); QString nickname = QString::fromUtf8(details.name.c_str());
QString idtype = tr("PGP Identity"); QString idtype = tr("PGP Identity");
addMember(keyId, idtype, nickname); QPixmap avatar;
AvatarDefs::getAvatarFromGpgId(gpg_id, avatar);
addMember(keyId, idtype, nickname, QIcon(avatar));
}//if(!gpg_id.isNull() && rsPeers->getGPGDetails(gpg_id,details)) }//if(!gpg_id.isNull() && rsPeers->getGPGDetails(gpg_id,details))
}//for (itAllowedPeers it = cirDetails.mAllowedPeers.begin() }//for (itAllowedPeers it = cirDetails.mAllowedPeers.begin()
@ -756,7 +777,7 @@ void CreateCircleDialog::loadIdentities(uint32_t token)
bool acceptAllPGP = ui.radioButton_ListAllPGP->isChecked(); bool acceptAllPGP = ui.radioButton_ListAllPGP->isChecked();
//bool acceptKnownPGP = ui.radioButton_ListKnownPGP->isChecked(); //bool acceptKnownPGP = ui.radioButton_ListKnownPGP->isChecked();
RsGxsIdGroup data; RsGxsIdGroup idGroup;
std::vector<RsGxsIdGroup> datavector; std::vector<RsGxsIdGroup> datavector;
std::vector<RsGxsIdGroup>::iterator vit; std::vector<RsGxsIdGroup>::iterator vit;
if (!rsIdentity->getGroupData(token, datavector)) { if (!rsIdentity->getGroupData(token, datavector)) {
@ -767,16 +788,16 @@ void CreateCircleDialog::loadIdentities(uint32_t token)
for(vit = datavector.begin(); vit != datavector.end(); ++vit) for(vit = datavector.begin(); vit != datavector.end(); ++vit)
{ {
data = (*vit); idGroup = (*vit);
/* do filtering */ /* do filtering */
bool ok = false; bool ok = false;
if (acceptAnonymous) if (acceptAnonymous)
ok = true; ok = true;
else if (acceptAllPGP) else if (acceptAllPGP)
ok = data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID ; ok = idGroup.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID ;
else if (data.mPgpKnown) else if (idGroup.mPgpKnown)
ok = data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID ; ok = idGroup.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID ;
if (!ok) { if (!ok) {
#ifdef DEBUG_CREATE_CIRCLE_DIALOG #ifdef DEBUG_CREATE_CIRCLE_DIALOG
@ -786,20 +807,20 @@ void CreateCircleDialog::loadIdentities(uint32_t token)
continue; continue;
} }
QString keyId = QString::fromStdString(data.mMeta.mGroupId.toStdString()); QString keyId = QString::fromStdString(idGroup.mMeta.mGroupId.toStdString());
QString nickname = QString::fromUtf8(data.mMeta.mGroupName.c_str()); QString nickname = QString::fromUtf8(idGroup.mMeta.mGroupName.c_str());
QString idtype = tr("Anon Id"); QString idtype = tr("Anon Id");
QPixmap pixmap ; QPixmap pixmap ;
if(data.mImage.mSize == 0 || !pixmap.loadFromData(data.mImage.mData, data.mImage.mSize, "PNG")) if(idGroup.mImage.mSize == 0 || !pixmap.loadFromData(idGroup.mImage.mData, idGroup.mImage.mSize, "PNG"))
pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId))) ; pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(RsGxsId(idGroup.mMeta.mGroupId))) ;
if (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) if (idGroup.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID)
{ {
if (data.mPgpKnown) { if (idGroup.mPgpKnown) {
RsPeerDetails details; RsPeerDetails details;
rsPeers->getGPGDetails(data.mPgpId, details); rsPeers->getGPGDetails(idGroup.mPgpId, details);
idtype = QString::fromUtf8(details.name.c_str()); idtype = QString::fromUtf8(details.name.c_str());
} }
else else
@ -822,8 +843,9 @@ void CreateCircleDialog::loadIdentities(uint32_t token)
// We use an explicit cast // We use an explicit cast
// //
if ( mCircleGroup.mInvitedMembers.find(RsGxsId(data.mMeta.mGroupId)) != mCircleGroup.mInvitedMembers.end()) /* found it */ if ( mCircleGroup.mInvitedMembers.find(RsGxsId(idGroup.mMeta.mGroupId)) != mCircleGroup.mInvitedMembers.end()) /* found it */
addMember(keyId, idtype, nickname); addMember(keyId, idtype, nickname, QIcon(pixmap));
} }
} }
} }

View File

@ -41,6 +41,7 @@ public:
void editNewId(bool isExternal); void editNewId(bool isExternal);
void editExistingId(const RsGxsGroupId &circleId, const bool &clearList = true, bool readonly=true); void editExistingId(const RsGxsGroupId &circleId, const bool &clearList = true, bool readonly=true);
void addMember(const QString &keyId, const QString &idtype, const QString &nickname, const QIcon &icon);
void addMember(const QString &keyId, const QString &idtype, const QString &nickname); void addMember(const QString &keyId, const QString &idtype, const QString &nickname);
void addMember(const RsGxsIdGroup &idGroup); void addMember(const RsGxsIdGroup &idGroup);
void addCircle(const RsGxsCircleDetails &cirDetails); void addCircle(const RsGxsCircleDetails &cirDetails);

View File

@ -42,6 +42,7 @@ public:
const QString idtype() const { return _idtype; } const QString idtype() const { return _idtype; }
const QString nickname() const { return _nickname; } const QString nickname() const { return _nickname; }
const QString gxsId() const { return _gxsId; } const QString gxsId() const { return _gxsId; }
const QImage avatar() const { return _avatar; }
signals: signals:
void addButtonClicked(); void addButtonClicked();

View File

@ -557,7 +557,7 @@ void PeopleDialog::addToCircleInt()
std::map<RsPgpId,IdentityWidget *>::iterator itIdFound; std::map<RsPgpId,IdentityWidget *>::iterator itIdFound;
if((itIdFound=_pgp_identity_widgets.find(pgp_id)) != _pgp_identity_widgets.end()) { if((itIdFound=_pgp_identity_widgets.find(pgp_id)) != _pgp_identity_widgets.end()) {
IdentityWidget *idWidget = itIdFound->second; IdentityWidget *idWidget = itIdFound->second;
dlg.addMember(idWidget->keyId(), idWidget->idtype(), idWidget->nickname()); dlg.addMember(idWidget->keyId(), idWidget->idtype(), idWidget->nickname(), QIcon(QPixmap::fromImage(idWidget->avatar())) );
}//if((itFound=_pgp_identity_widgets.find(pgp_id)) != _pgp_identity_widgets.end()) }//if((itFound=_pgp_identity_widgets.find(pgp_id)) != _pgp_identity_widgets.end())
dlg.editExistingId(circle->groupInfo().mGroupId, false,false); dlg.editExistingId(circle->groupInfo().mGroupId, false,false);
@ -769,7 +769,7 @@ void PeopleDialog::fl_flowLayoutItemDroppedInt(QList<FlowLayoutItem *>flListItem
IdentityWidget* idDest = qobject_cast<IdentityWidget*>(dest); IdentityWidget* idDest = qobject_cast<IdentityWidget*>(dest);
if (idDest) { if (idDest) {
if (idDest->havePGPDetail()){ if (idDest->havePGPDetail()){
dlg.addMember(idDest->keyId(), idDest->idtype(), idDest->nickname()); dlg.addMember(idDest->keyId(), idDest->idtype(), idDest->nickname(), QIcon(QPixmap::fromImage(idDest->avatar())) );
}//if (idDest->havePGPDetail()) }//if (idDest->havePGPDetail())
}//if (idDest) }//if (idDest)
@ -790,7 +790,7 @@ void PeopleDialog::fl_flowLayoutItemDroppedInt(QList<FlowLayoutItem *>flListItem
} else {//if (cirDropped) } else {//if (cirDropped)
IdentityWidget* idDropped = qobject_cast<IdentityWidget*>(flCurs); IdentityWidget* idDropped = qobject_cast<IdentityWidget*>(flCurs);
if (idDropped){ if (idDropped){
dlg.addMember(idDropped->keyId(), idDropped->idtype(), idDropped->nickname()); dlg.addMember(idDropped->keyId(), idDropped->idtype(), idDropped->nickname(), QIcon(QPixmap::fromImage(idDropped->avatar())) );
}//if (idDropped) }//if (idDropped)
}//else (cirDropped) }//else (cirDropped)
@ -980,7 +980,7 @@ void PeopleDialog::pf_dropEventOccursInt(QDropEvent *event)
IdentityWidget* idDropped = qobject_cast<IdentityWidget*>(flCurs); IdentityWidget* idDropped = qobject_cast<IdentityWidget*>(flCurs);
if (idDropped){ if (idDropped){
if (idDropped->havePGPDetail()){ if (idDropped->havePGPDetail()){
dlg.addMember(idDropped->keyId(), idDropped->idtype(), idDropped->nickname()); dlg.addMember(idDropped->keyId(), idDropped->idtype(), idDropped->nickname(), QIcon(QPixmap::fromImage(idDropped->avatar())) );
atLeastOne = true; atLeastOne = true;
}//if (idDropped->havePGPDetail()) }//if (idDropped->havePGPDetail())
}//if (idDropped) }//if (idDropped)
@ -1015,7 +1015,7 @@ void PeopleDialog::pf_dropEventOccursInt(QDropEvent *event)
IdentityWidget* idDropped = qobject_cast<IdentityWidget*>(flCurs); IdentityWidget* idDropped = qobject_cast<IdentityWidget*>(flCurs);
if (idDropped){ if (idDropped){
if (idDropped->havePGPDetail()){ if (idDropped->havePGPDetail()){
dlg.addMember(idDropped->keyId(), idDropped->idtype(), idDropped->nickname()); dlg.addMember(idDropped->keyId(), idDropped->idtype(), idDropped->nickname(), QIcon(QPixmap::fromImage(idDropped->avatar())) );
atLeastOne = true; atLeastOne = true;
}//if (idDropped->havePGPDetail()) }//if (idDropped->havePGPDetail())