From 481ee246b50217347b34e53d0c8310ab04e20ea1 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 25 Jan 2015 22:09:12 +0000 Subject: [PATCH] added avatars to identities. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7875 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsidentity.h | 17 +- libretroshare/src/serialiser/rsgxsiditems.cc | 102 ++++-- libretroshare/src/serialiser/rsgxsiditems.h | 29 +- libretroshare/src/services/p3idservice.cc | 110 +++--- retroshare-gui/src/gui/Identity/IdDialog.cpp | 21 +- .../src/gui/Identity/IdEditDialog.cpp | 42 ++- .../src/gui/Identity/IdEditDialog.h | 3 +- .../src/gui/Identity/IdEditDialog.ui | 324 +++++++++++------- retroshare-gui/src/gui/gxs/GxsIdDetails.cpp | 8 +- retroshare-gui/src/util/misc.cpp | 2 +- 10 files changed, 418 insertions(+), 240 deletions(-) diff --git a/libretroshare/src/retroshare/rsidentity.h b/libretroshare/src/retroshare/rsidentity.h index 6f9721d18..9e290372d 100644 --- a/libretroshare/src/retroshare/rsidentity.h +++ b/libretroshare/src/retroshare/rsidentity.h @@ -33,6 +33,8 @@ #include "retroshare/rstokenservice.h" #include "retroshare/rsgxsifacehelper.h" #include "retroshare/rsids.h" +#include "serialiser/rstlvimage.h" +#include "retroshare/rsgxscommon.h" /* The Main Interface Class - for information about your Peers */ class RsIdentity; @@ -105,10 +107,13 @@ class RsGxsIdGroup // Recognition Strings. MAX# defined above. std::list mRecognTags; - // Not Serialised - for GUI's benefit. + // Avatar + RsGxsImage mImage ; + + // Not Serialised - for GUI's benefit. bool mPgpKnown; RsPgpId mPgpId; - GxsReputation mReputation; + GxsReputation mReputation; }; @@ -168,7 +173,10 @@ class RsIdentityDetails std::list mRecognTags; // reputation details. - GxsReputation mReputation; + GxsReputation mReputation; + + // avatar + RsGxsImage mAvatar ; }; @@ -185,7 +193,8 @@ class RsIdentityParameters public: RsIdentityParameters(): isPgpLinked(false) { return; } bool isPgpLinked; - std::string nickname; + std::string nickname; + RsGxsImage mImage ; }; diff --git a/libretroshare/src/serialiser/rsgxsiditems.cc b/libretroshare/src/serialiser/rsgxsiditems.cc index c3b1fda27..ae7c548b9 100644 --- a/libretroshare/src/serialiser/rsgxsiditems.cc +++ b/libretroshare/src/serialiser/rsgxsiditems.cc @@ -131,17 +131,13 @@ RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size) void RsGxsIdGroupItem::clear() { - group.mPgpIdHash.clear(); - group.mPgpIdSign.clear(); - - group.mRecognTags.clear(); - - group.mPgpKnown = false; - group.mPgpId.clear(); + mPgpIdHash.clear(); + mPgpIdSign.clear(); + mRecognTags.clear(); + mImage.TlvClear(); } - std::ostream& RsGxsIdGroupItem::print(std::ostream& out, uint16_t indent) { printRsItemBase(out, "RsGxsIdGroupItem", indent); @@ -150,20 +146,20 @@ std::ostream& RsGxsIdGroupItem::print(std::ostream& out, uint16_t indent) printIndent(out, int_Indent); out << "MetaData: " << meta << std::endl; printIndent(out, int_Indent); - out << "PgpIdHash: " << group.mPgpIdHash << std::endl; + out << "PgpIdHash: " << mPgpIdHash << std::endl; printIndent(out, int_Indent); std::string signhex; // convert from binary to hex. - for(unsigned int i = 0; i < group.mPgpIdSign.length(); i++) + for(unsigned int i = 0; i < mPgpIdSign.length(); i++) { - rs_sprintf_append(signhex, "%02x", (uint32_t) ((uint8_t) group.mPgpIdSign[i])); + rs_sprintf_append(signhex, "%02x", (uint32_t) ((uint8_t) mPgpIdSign[i])); } out << "PgpIdSign: " << signhex << std::endl; printIndent(out, int_Indent); out << "RecognTags:" << std::endl; - RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, group.mRecognTags); + RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags); set.print(out, int_Indent + 2); printRsItemEnd(out ,"RsGxsIdGroupItem", indent); @@ -173,17 +169,17 @@ std::ostream& RsGxsIdGroupItem::print(std::ostream& out, uint16_t indent) uint32_t RsGxsIdSerialiser::sizeGxsIdGroupItem(RsGxsIdGroupItem *item) { + uint32_t s = 8; // header - const RsGxsIdGroup& group = item->group; - uint32_t s = 8; // header + s += Sha1CheckSum::SIZE_IN_BYTES; + s += GetTlvStringSize(item->mPgpIdSign); - s += Sha1CheckSum::SIZE_IN_BYTES; - s += GetTlvStringSize(group.mPgpIdSign); + RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->mRecognTags); + s += set.TlvSize(); - RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->group.mRecognTags); - s += set.TlvSize(); + s += item->mImage.TlvSize() ; - return s; + return s; } bool RsGxsIdSerialiser::serialiseGxsIdGroupItem(RsGxsIdGroupItem *item, void *data, uint32_t *size) @@ -211,12 +207,14 @@ bool RsGxsIdSerialiser::serialiseGxsIdGroupItem(RsGxsIdGroupItem *item, void *da offset += 8; /* GxsIdGroupItem */ - ok &= item->group.mPgpIdHash.serialise(data, tlvsize, offset); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_SIGN, item->group.mPgpIdSign); + ok &= item->mPgpIdHash.serialise(data, tlvsize, offset); + ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_SIGN, item->mPgpIdSign); - RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->group.mRecognTags); + RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->mRecognTags); ok &= set.SetTlv(data, tlvsize, &offset); - + + ok &= item->mImage.SetTlv(data,tlvsize,&offset) ; + if(offset != tlvsize) { #ifdef GXSID_DEBUG @@ -234,7 +232,48 @@ bool RsGxsIdSerialiser::serialiseGxsIdGroupItem(RsGxsIdGroupItem *item, void *da return ok; } - + + +bool RsGxsIdGroupItem::fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage) +{ + clear(); + meta = group.mMeta; + mPgpIdHash = group.mPgpIdHash; + mPgpIdSign = group.mPgpIdSign; + mRecognTags = group.mRecognTags; + + if (moveImage) + { + mImage.binData.bin_data = group.mImage.mData; + mImage.binData.bin_len = group.mImage.mSize; + group.mImage.shallowClear(); + } + else + { + mImage.binData.setBinData(group.mImage.mData, group.mImage.mSize); + } + return true ; +} +bool RsGxsIdGroupItem::toGxsIdGroup(RsGxsIdGroup &group, bool moveImage) +{ + group.mMeta = meta; + group.mPgpIdHash = mPgpIdHash; + group.mPgpIdSign = mPgpIdSign; + group.mRecognTags = mRecognTags; + + if (moveImage) + { + group.mImage.take((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len); + // mImage doesn't have a ShallowClear at the moment! + mImage.binData.TlvShallowClear(); + } + else + { + group.mImage.copy((uint8_t *) mImage.binData.bin_data, mImage.binData.bin_len); + } + return true ; +} + RsGxsIdGroupItem* RsGxsIdSerialiser::deserialiseGxsIdGroupItem(void *data, uint32_t *size) { /* get the type and size */ @@ -271,14 +310,17 @@ RsGxsIdGroupItem* RsGxsIdSerialiser::deserialiseGxsIdGroupItem(void *data, uint3 /* skip the header */ offset += 8; - ok &= item->group.mPgpIdHash.deserialise(data, rssize, offset); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_SIGN, item->group.mPgpIdSign); + ok &= item->mPgpIdHash.deserialise(data, rssize, offset); + ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_SIGN, item->mPgpIdSign); - RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->group.mRecognTags); + RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->mRecognTags); ok &= set.GetTlv(data, rssize, &offset); - - - if (offset != rssize) + + // image is optional,so that we can continue reading old items. + if(offset < rssize) + ok &= item->mImage.GetTlv(data,rssize,&offset) ; + + if (offset != rssize) { #ifdef GXSID_DEBUG std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL size mismatch" << std::endl; diff --git a/libretroshare/src/serialiser/rsgxsiditems.h b/libretroshare/src/serialiser/rsgxsiditems.h index 859e1f8ac..8cd4e814c 100644 --- a/libretroshare/src/serialiser/rsgxsiditems.h +++ b/libretroshare/src/serialiser/rsgxsiditems.h @@ -34,7 +34,9 @@ #include "rsgxsitems.h" #include "retroshare/rsidentity.h" -const uint8_t RS_PKT_SUBTYPE_GXSID_GROUP_ITEM = 0x02; +//const uint8_t RS_PKT_SUBTYPE_GXSID_GROUP_ITEM_deprecated = 0x02; + +const uint8_t RS_PKT_SUBTYPE_GXSID_GROUP_ITEM = 0x02; const uint8_t RS_PKT_SUBTYPE_GXSID_OPINION_ITEM = 0x03; const uint8_t RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM = 0x04; @@ -43,15 +45,26 @@ class RsGxsIdGroupItem : public RsGxsGrpItem public: - RsGxsIdGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSID, - RS_PKT_SUBTYPE_GXSID_GROUP_ITEM) { return;} - virtual ~RsGxsIdGroupItem() { return;} + RsGxsIdGroupItem(): RsGxsGrpItem(RS_SERVICE_GXS_TYPE_GXSID, + RS_PKT_SUBTYPE_GXSID_GROUP_ITEM) { return;} + virtual ~RsGxsIdGroupItem() { return;} - void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); + void clear(); + std::ostream &print(std::ostream &out, uint16_t indent = 0); + bool fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage); + bool toGxsIdGroup(RsGxsIdGroup &group, bool moveImage); - RsGxsIdGroup group; + Sha1CheckSum mPgpIdHash; + // Need a signature as proof - otherwise anyone could add others Hashes. + // This is a string, as the length is variable. + std::string mPgpIdSign; + + // Recognition Strings. MAX# defined above. + std::list mRecognTags; + + // Avatar + RsTlvImage mImage ; }; #if 0 @@ -59,7 +72,7 @@ class RsGxsIdOpinionItem : public RsGxsMsgItem { public: - RsGxsIdOpinionItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSID, + RsGxsIdOpinionItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_GXSID, RS_PKT_SUBTYPE_GXSID_OPINION_ITEM) {return; } virtual ~RsGxsIdOpinionItem() { return;} void clear(); diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index 977af061e..cfe3ea72b 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -324,7 +324,9 @@ bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters ¶ms) RsGxsIdGroup id; - id.mMeta.mGroupName = params.nickname; + id.mMeta.mGroupName = params.nickname; + id.mImage = params.mImage; + if (params.isPgpLinked) { id.mMeta.mGroupFlags = RSGXSID_GROUPFLAG_REALID; @@ -740,8 +742,8 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector item->print(std::cerr); std::cerr << std::endl; #endif // DEBUG_IDS - RsGxsIdGroup group = item->group; - group.mMeta = item->meta; + RsGxsIdGroup group ; + item->toGxsIdGroup(group,false) ; // Decode information from serviceString. SSGxsIdGroup ssdata; @@ -769,7 +771,7 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector } groups.push_back(group); - delete(item); + delete(item); } else { @@ -789,19 +791,21 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector bool p3IdService::createGroup(uint32_t& token, RsGxsIdGroup &group) { - RsGxsIdGroupItem* item = new RsGxsIdGroupItem(); - item->group = group; - item->meta = group.mMeta; - RsGenExchange::publishGroup(token, item); - return true; + RsGxsIdGroupItem* item = new RsGxsIdGroupItem(); + + item->meta = group.mMeta; + item->mImage.binData.setBinData(group.mImage.mData, group.mImage.mSize); + + RsGenExchange::publishGroup(token, item); + return true; } bool p3IdService::updateGroup(uint32_t& token, RsGxsIdGroup &group) { RsGxsId id = RsGxsId(group.mMeta.mGroupId.toStdString()); - RsGxsIdGroupItem* item = new RsGxsIdGroupItem(); - item->group = group; - item->meta = group.mMeta; + RsGxsIdGroupItem* item = new RsGxsIdGroupItem(); + + item->fromGxsIdGroup(group,false) ; #ifdef DEBUG_IDS std::cerr << "p3IdService::updateGroup() Updating RsGxsId: " << id; @@ -850,9 +854,9 @@ bool p3IdService::updateGroup(uint32_t& token, RsGxsIdGroup &group) bool p3IdService::deleteGroup(uint32_t& token, RsGxsIdGroup &group) { RsGxsId id = RsGxsId(group.mMeta.mGroupId.toStdString()); - RsGxsIdGroupItem* item = new RsGxsIdGroupItem(); - item->group = group; - item->meta = group.mMeta; + RsGxsIdGroupItem* item = new RsGxsIdGroupItem(); + + item->fromGxsIdGroup(group,false) ; #ifdef DEBUG_IDS std::cerr << "p3IdService::deleteGroup() Deleting RsGxsId: " << id; @@ -1285,7 +1289,9 @@ RsGxsIdCache::RsGxsIdCache(const RsGxsIdGroupItem *item, const RsTlvSecurityKey mPublishTs = item->meta.mPublishTs; // Save RecognTags. - mRecognTags = tagList; + mRecognTags = tagList; + + details.mAvatar.copy((uint8_t *) item->mImage.binData.bin_data, item->mImage.binData.bin_len); // Fill in Details. details.mNickname = item->meta.mGroupName; @@ -1396,7 +1402,7 @@ bool p3IdService::recogn_extract_taginfo(const RsGxsIdGroupItem *item, std::list std::list::const_iterator rit; int count = 0; - for(rit = item->group.mRecognTags.begin(); rit != item->group.mRecognTags.end(); ++rit) + for(rit = item->mRecognTags.begin(); rit != item->mRecognTags.end(); ++rit) { if (++count > RSRECOGN_MAX_TAGINFO) { @@ -2179,7 +2185,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte if(pk.keyFlags == (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL)) { - item->group.mMeta.mGroupId = RsGxsGroupId(pk.keyId); + item->meta.mGroupId = RsGxsGroupId(pk.keyId); break; } } @@ -2195,36 +2201,36 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte /********************* TEMP HACK UNTIL GXS FILLS IN GROUP_ID *****************/ // SANITY CHECK. - if (item->group.mMeta.mAuthorId != item->meta.mAuthorId) - { - std::cerr << "p3IdService::service_CreateGroup() AuthorId mismatch("; - std::cerr << item->group.mMeta.mAuthorId; - std::cerr << " vs "; - std::cerr << item->meta.mAuthorId; - std::cerr << std::endl; - } - - if (item->group.mMeta.mGroupId != item->meta.mGroupId) - { - std::cerr << "p3IdService::service_CreateGroup() GroupId mismatch("; - std::cerr << item->group.mMeta.mGroupId; - std::cerr << " vs "; - std::cerr << item->meta.mGroupId; - std::cerr << std::endl; - } - - - if (item->group.mMeta.mGroupFlags != item->meta.mGroupFlags) - { - std::cerr << "p3IdService::service_CreateGroup() GroupFlags mismatch("; - std::cerr << item->group.mMeta.mGroupFlags; - std::cerr << " vs "; - std::cerr << item->meta.mGroupFlags; - std::cerr << std::endl; - } +// if (item->mMeta.mAuthorId != item->meta.mAuthorId) +// { +// std::cerr << "p3IdService::service_CreateGroup() AuthorId mismatch("; +// std::cerr << item->mMeta.mAuthorId; +// std::cerr << " vs "; +// std::cerr << item->meta.mAuthorId; +// std::cerr << std::endl; +// } +// +// if (item->group.mMeta.mGroupId != item->meta.mGroupId) +// { +// std::cerr << "p3IdService::service_CreateGroup() GroupId mismatch("; +// std::cerr << item->mMeta.mGroupId; +// std::cerr << " vs "; +// std::cerr << item->meta.mGroupId; +// std::cerr << std::endl; +// } +// +// +// if (item->group.mMeta.mGroupFlags != item->meta.mGroupFlags) +// { +// std::cerr << "p3IdService::service_CreateGroup() GroupFlags mismatch("; +// std::cerr << item->mMeta.mGroupFlags; +// std::cerr << " vs "; +// std::cerr << item->meta.mGroupFlags; +// std::cerr << std::endl; +// } #ifdef DEBUG_IDS - std::cerr << "p3IdService::service_CreateGroup() for : " << item->group.mMeta.mGroupId; + std::cerr << "p3IdService::service_CreateGroup() for : " << item->mMeta.mGroupId; std::cerr << std::endl; std::cerr << "p3IdService::service_CreateGroup() Alt GroupId : " << item->meta.mGroupId; std::cerr << std::endl; @@ -2232,7 +2238,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte ServiceCreate_Return createStatus; - if (item->group.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) + if (item->meta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) { /* create the hash */ Sha1CheckSum hash; @@ -2265,9 +2271,9 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte std::cerr << std::endl; #endif - RsGxsId gxsId(item->group.mMeta.mGroupId.toStdString()); + RsGxsId gxsId(item->meta.mGroupId.toStdString()); calcPGPHash(gxsId, ownFinger, hash); - item->group.mPgpIdHash = hash; + item->mPgpIdHash = hash; #ifdef DEBUG_IDS @@ -2306,13 +2312,13 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte std::string strout; #endif /* push binary into string -> really bad! */ - item->group.mPgpIdSign = ""; + item->mPgpIdSign = ""; for(unsigned int i = 0; i < sign_size; i++) { #ifdef DEBUG_IDS rs_sprintf_append(strout, "%02x", (uint32_t) signarray[i]); #endif - item->group.mPgpIdSign += signarray[i]; + item->mPgpIdSign += signarray[i]; } createStatus = SERVICE_CREATE_SUCCESS; @@ -2330,7 +2336,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte // Enforce no AuthorId. item->meta.mAuthorId.clear() ; - item->group.mMeta.mAuthorId.clear() ; + //item->mMeta.mAuthorId.clear() ; // copy meta data to be sure its all the same. //item->group.mMeta = item->meta; diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 990e87fa8..69de254f8 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -377,11 +377,15 @@ bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item, item->setToolTip(RSID_COL_IDTYPE, tooltip) ; } - QPixmap pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId))) ; #ifdef ID_DEBUG std::cerr << "Setting item image : " << pixmap.width() << " x " << pixmap.height() << std::endl; #endif - item->setIcon(RSID_COL_NICKNAME, QIcon(pixmap)); + QPixmap pixmap ; + + if(data.mImage.mSize == 0 || !pixmap.loadFromData(data.mImage.mData, data.mImage.mSize, "PNG")) + pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId))) ; + + item->setIcon(RSID_COL_NICKNAME, QIcon(pixmap)); if (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) { @@ -545,11 +549,15 @@ void IdDialog::insertIdDetails(uint32_t token) ui->headerFrame->setHeaderText(QString::fromUtf8(data.mMeta.mGroupName.c_str())); - QPixmap pix = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId))) ; + QPixmap pixmap ; + + if(data.mImage.mSize == 0 || !pixmap.loadFromData(data.mImage.mData, data.mImage.mSize, "PNG")) + pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId))) ; + #ifdef ID_DEBUG std::cerr << "Setting header frame image : " << pix.width() << " x " << pix.height() << std::endl; #endif - ui->headerFrame->setHeaderImage(pix); + ui->headerFrame->setHeaderImage(pixmap); if (data.mPgpKnown) { @@ -953,7 +961,10 @@ void IdDialog::IdListCustomPopupMenu( QPoint ) RsIdentityDetails idd ; rsIdentity->getIdDetails(*it,idd) ; - QPixmap pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(*it)) ; + QPixmap pixmap ; + + if(idd.mAvatar.mSize == 0 || !pixmap.loadFromData(idd.mAvatar.mData, idd.mAvatar.mSize, "PNG")) + pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(*it)) ; 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 3d3f11e94..515ea64fd 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp @@ -21,9 +21,12 @@ * */ +#include + #include "gui/Identity/IdEditDialog.h" #include "gui/common/UIStateHelper.h" #include "util/TokenQueue.h" +#include "util/misc.h" #include #include @@ -78,11 +81,22 @@ IdEditDialog::IdEditDialog(QWidget *parent) connect(ui.toolButton_Tag3, SIGNAL(clicked(bool)), this, SLOT(rmTag3())); connect(ui.toolButton_Tag4, SIGNAL(clicked(bool)), this, SLOT(rmTag4())); connect(ui.toolButton_Tag5, SIGNAL(clicked(bool)), this, SLOT(rmTag5())); + connect(ui.avatarLabel, SIGNAL(clicked(bool)), this, SLOT(changeAvatar())); mIdQueue = new TokenQueue(rsIdentity->getTokenService(), this); ui.pushButton_Tag->setEnabled(false); } +void IdEditDialog::changeAvatar() +{ + QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load Avatar"), 128, 128); + + if (img.isNull()) + return; + + ui.avatarLabel->setPixmap(img) ; +} + IdEditDialog::~IdEditDialog() { delete(mIdQueue); @@ -177,8 +191,15 @@ void IdEditDialog::loadExistingId(uint32_t token) ui.lineEdit_KeyId->setText(tr("Error getting key!")); return; } + mEditGroup = datavector[0]; + QPixmap pixmap; - if (datavector.size() != 1) + if(mEditGroup.mImage.mSize > 0 && pixmap.loadFromData(mEditGroup.mImage.mData, mEditGroup.mImage.mSize, "PNG")) + ui.avatarLabel->setPixmap(pixmap); +// else +// ui.avatarLabel->setPixmap(pixmap); // we need to use the default pixmap here, generated from the ID + + if (datavector.size() != 1) { std::cerr << "IdDialog::insertIdDetails() Invalid datavector size"; std::cerr << std::endl; @@ -192,8 +213,6 @@ void IdEditDialog::loadExistingId(uint32_t token) return; } - mEditGroup = datavector[0]; - bool realid = (mEditGroup.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID); if (realid) @@ -446,7 +465,22 @@ void IdEditDialog::createId() RsIdentityParameters params; params.nickname = groupname; - params.isPgpLinked = (ui.radioButton_GpgId->isChecked()); + params.isPgpLinked = (ui.radioButton_GpgId->isChecked()); + + const QPixmap *pixmap = ui.avatarLabel->pixmap(); + + if (!pixmap->isNull()) + { + QByteArray ba; + QBuffer buffer(&ba); + + buffer.open(QIODevice::WriteOnly); + pixmap->save(&buffer, "PNG"); // writes image into ba in PNG format + + params.mImage.copy((uint8_t *) ba.data(), ba.size()); + } + else + params.mImage.clear(); uint32_t dummyToken = 0; rsIdentity->createIdentity(dummyToken, params); diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.h b/retroshare-gui/src/gui/Identity/IdEditDialog.h index a8ccb0808..ae03fcac7 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.h +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.h @@ -54,7 +54,8 @@ private slots: void idTypeToggled(bool checked); void submit(); - void addRecognTag(); + void changeAvatar() ; + void addRecognTag(); void checkNewTag(); void rmTag1(); void rmTag2(); diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.ui b/retroshare-gui/src/gui/Identity/IdEditDialog.ui index a8fb00bc0..dd51d02ad 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.ui +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.ui @@ -6,15 +6,21 @@ 0 0 - 468 - 480 + 515 + 591 + + + 64 + 64 + + :/images/identity/identities_32.png:/images/identity/identities_32.png - + 0 @@ -22,14 +28,7 @@ 0 - - - QFrame::NoFrame - - - QFrame::Plain - - + @@ -45,97 +44,188 @@ QFrame::Raised - - - - - Type - - + + + + + + + Type + + + + + + + PGP Associated ID + + + + :/images/tags/pgp-known.png:/images/tags/pgp-known.png + + + + 22 + 22 + + + + + + + + Pseudonym + + + + :/images/tags/anon.png:/images/tags/anon.png + + + + 22 + 22 + + + + + + + + Qt::Horizontal + + + + 131 + 20 + + + + + - - - - PGP Associated ID - - - - :/images/tags/pgp-known.png:/images/tags/pgp-known.png - - - - 22 - 22 - - - + + + + + + + + Nickname + + + + + + + + + + Key ID + + + + + + + true + + + + + + + PGP Hash + + + + + + + true + + + + + + + PGP Id + + + + + + + true + + + + + + + PGP Name + + + + + + + true + + + + + + + + + + + + 0 + 0 + + + + + 128 + 128 + + + + + 128 + 128 + + + + TextLabel + + + Qt::AlignCenter + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + - - - - Pseudonym - - - - :/images/tags/anon.png:/images/tags/anon.png - - - - 22 - 22 - - - - - - - - Qt::Horizontal - - - - 131 - 20 - - - - - - - - Nickname - - - - - - - Key ID - - - - - - - PGP Hash - - - - - - - PGP Id - - - - - - - PGP Name - - - - + Qt::Vertical @@ -148,37 +238,6 @@ - - - - - - - true - - - - - - - true - - - - - - - true - - - - - - - true - - - @@ -337,9 +396,8 @@ HeaderFrame - QFrame + QWidget
gui/common/HeaderFrame.h
- 1
diff --git a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp index 57a3310fb..1c9135dab 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp @@ -469,8 +469,12 @@ QString GxsIdDetails::getComment(const RsIdentityDetails &details) void GxsIdDetails::getIcons(const RsIdentityDetails &details, QList &icons) { - QPixmap pix ; - pix.convertFromImage(makeDefaultIcon(details.mId)); + QPixmap pix ; + + if(details.mAvatar.mSize == 0 || !pix.loadFromData(details.mAvatar.mData, details.mAvatar.mSize, "PNG")) + pix.convertFromImage(makeDefaultIcon(details.mId)); + + QIcon idIcon(pix); //CreateIdIcon(id, idIcon); icons.push_back(idIcon); diff --git a/retroshare-gui/src/util/misc.cpp b/retroshare-gui/src/util/misc.cpp index 977285d29..23caad704 100644 --- a/retroshare-gui/src/util/misc.cpp +++ b/retroshare-gui/src/util/misc.cpp @@ -293,7 +293,7 @@ QPixmap misc::getOpenThumbnailedPicture(QWidget *parent, const QString &caption, if (!getOpenFileName(parent, RshareSettings::LASTDIR_IMAGES, caption, tr("Pictures (*.png *.xpm *.jpg *.tiff *.gif)"), fileName)) return QPixmap(); - return QPixmap(fileName).scaledToHeight(height).copy( 0, 0, width, height); + return QPixmap(fileName).scaledToHeight(height, Qt::SmoothTransformation).copy( 0, 0, width, height); //return QPixmap(fileName).scaledToHeight(width, height, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); }