From 8be92f24b6da70161303ff87f78d35d5cbc71b3f Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 29 Feb 2020 23:48:37 +0100 Subject: [PATCH] removed TokenQueue from CircleCreationDialog --- .../src/gui/Circles/CreateCircleDialog.cpp | 211 ++++++------------ .../src/gui/Circles/CreateCircleDialog.h | 18 +- 2 files changed, 71 insertions(+), 158 deletions(-) diff --git a/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp b/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp index 8808f17a3..0785b683f 100644 --- a/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp +++ b/retroshare-gui/src/gui/Circles/CreateCircleDialog.cpp @@ -29,6 +29,7 @@ #include #include "gui/common/AvatarDefs.h" +#include "util/qtthreadsutils.h" #include "gui/Circles/CreateCircleDialog.h" #include "gui/gxs/GxsIdDetails.h" #include "gui/Identity/IdDialog.h" @@ -51,9 +52,6 @@ CreateCircleDialog::CreateCircleDialog() ui.setupUi(this); /* Setup Queue */ - mCircleQueue = new TokenQueue(rsGxsCircles->getTokenService(), this); - mIdQueue = new TokenQueue(rsIdentity->getTokenService(), this); - ui.headerFrame->setHeaderImage(QPixmap(":/icons/png/circles.png")); // connect up the buttons. @@ -107,8 +105,6 @@ CreateCircleDialog::CreateCircleDialog() CreateCircleDialog::~CreateCircleDialog() { - delete(mCircleQueue); - delete(mIdQueue); } void CreateCircleDialog::editExistingId(const RsGxsGroupId &circleId, const bool &clearList /*= true*/,bool readonly) @@ -147,14 +143,15 @@ void CreateCircleDialog::editExistingId(const RsGxsGroupId &circleId, const bool ui.removeButton->setEnabled(!readonly) ; if(readonly) - { - ui.buttonBox->setStandardButtons(QDialogButtonBox::Cancel); - ui.buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Close")); - ui.peersSelection_GB->hide() ; - ui.addButton->hide() ; - ui.removeButton->hide() ; - } - requestCircle(circleId); + { + ui.buttonBox->setStandardButtons(QDialogButtonBox::Cancel); + ui.buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Close")); + ui.peersSelection_GB->hide() ; + ui.addButton->hide() ; + ui.removeButton->hide() ; + } + + loadCircle(circleId); } @@ -233,7 +230,7 @@ void CreateCircleDialog::setupForExternalCircle() ui.idChooser->show(); //ui.toolButton_NewId->show(); - requestGxsIdentities(); + loadIdentities(); } void CreateCircleDialog::selectedId(QTreeWidgetItem *current, QTreeWidgetItem *previous) @@ -663,107 +660,79 @@ void CreateCircleDialog::updateCircleGUI() } } -void CreateCircleDialog::requestCircle(const RsGxsGroupId &groupId) +void CreateCircleDialog::loadCircle(const RsGxsGroupId& groupId) { - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - - std::list groupIds; - groupIds.push_back(groupId); - -#ifdef DEBUG_CREATE_CIRCLE_DIALOG - std::cerr << "CreateCircleDialog::requestCircle() Requesting Group Summary(" << groupId << ")"; - std::cerr << std::endl; -#endif - - uint32_t token; - mCircleQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, CREATECIRCLEDIALOG_CIRCLEINFO); -} - -void CreateCircleDialog::loadCircle(uint32_t token) -{ -#ifdef DEBUG_CREATE_CIRCLE_DIALOG - std::cerr << "CreateCircleDialog::loadCircle(" << token << ")"; - std::cerr << std::endl; -#endif - QTreeWidget *tree = ui.treeWidget_membership; - if (mClearList) tree->clear(); - std::vector groups; - if (!rsGxsCircles->getGroupData(token, groups)) { - std::cerr << "CreateCircleDialog::loadCircle() Error getting GroupData"; - std::cerr << std::endl; - return; - } + RsThread::async([groupId,this]() + { + std::vector circlesInfo ; - if (groups.size() != 1) { - std::cerr << "CreateCircleDialog::loadCircle() Error Group.size() != 1"; - std::cerr << std::endl; - return; - } - - mCircleGroup = groups[0]; - -#ifdef DEBUG_CREATE_CIRCLE_DIALOG - std::cerr << "CreateCircleDialog::loadCircle() LoadedGroup.meta: " << mCircleGroup.mMeta << std::endl; + if(! rsGxsCircles->getCirclesInfo(std::list({ groupId }), circlesInfo) || circlesInfo.size() != 1) + { + std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve circle info for circle " << groupId << std::endl; + return; + } + + RsGxsCircleGroup grp(circlesInfo[0]); + + RsQThreadUtils::postToObject( [grp,this]() + { + /* Here it goes any code you want to be executed on the Qt Gui + * thread, for example to update the data model with new information + * after a blocking call to RetroShare API complete */ + + mCircleGroup = grp; + +#ifdef DEBUG_CREATE_CIRCLE_DIALOG + std::cerr << "CreateCircleDialog::loadCircle() LoadedGroup.meta: " << mCircleGroup.mMeta << std::endl; #endif - updateCircleGUI(); + updateCircleGUI(); + + }, this ); + }); + } -/*void CreateCircleDialog::getPgpIdentities() +void CreateCircleDialog::loadIdentities() { - std::cerr << "CreateCircleDialog::getPgpIdentities()"; - std::cerr << std::endl; + RsThread::async([this]() + { + std::list ids_meta; - QTreeWidget *tree = ui.treeWidget_IdList; + if(!rsIdentity->getIdentitiesSummaries(ids_meta)) + { + std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve identities ids for all identities" << std::endl; + return; + } + std::set ids; - tree->clear(); - std::list ids; - std::list::iterator it; + for(auto& meta:ids_meta) + ids.insert(RsGxsId(meta.mGroupId)) ; - rsPeers->getGPGAcceptedList(ids); - for(it = ids.begin(); it != ids.end(); ++it) { - RsPeerDetails details; + std::vector id_groups; - rsPeers->getGPGDetails(*it, details); + if(!rsIdentity->getIdentitiesInfo(ids,id_groups)) + { + std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve identities group info for all identities" << std::endl; + return; + } - QString keyId = QString::fromStdString(details.gpg_id.toStdString()); - QString nickname = QString::fromUtf8(details.name.c_str()); - QString idtype = tr("PGP Identity"); + RsQThreadUtils::postToObject( [id_groups,this]() + { + /* Here it goes any code you want to be executed on the Qt Gui + * thread, for example to update the data model with new information + * after a blocking call to RetroShare API complete */ - QTreeWidgetItem *item = new QTreeWidgetItem(); - item->setText(RSCIRCLEID_COL_NICKNAME, nickname); - item->setText(RSCIRCLEID_COL_KEYID, keyId); - item->setText(RSCIRCLEID_COL_IDTYPE, idtype); - tree->addTopLevelItem(item); + fillIdentitiesList(id_groups) ; - // Local Circle. - if (mIsExistingCircle) - if ( mCircleGroup.mLocalFriends.find(details.gpg_id) != mCircleGroup.mLocalFriends.end()) // check if its in the circle. - addMember(keyId, idtype, nickname); - } - - filterIds(); -}*/ + }, this ); + }); - -void CreateCircleDialog::requestGxsIdentities() -{ - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - -#ifdef DEBUG_CREATE_CIRCLE_DIALOG - std::cerr << "CreateCircleDialog::requestIdentities()"; - std::cerr << std::endl; -#endif - - uint32_t token; - mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, CREATECIRCLEDIALOG_IDINFO); } -void CreateCircleDialog::loadIdentities(uint32_t token) +void CreateCircleDialog::fillIdentitiesList(const std::vector& id_groups) { #ifdef DEBUG_CREATE_CIRCLE_DIALOG std::cerr << "CreateCircleDialog::loadIdentities(" << token << ")"; @@ -771,26 +740,14 @@ void CreateCircleDialog::loadIdentities(uint32_t token) #endif QTreeWidget *tree = ui.treeWidget_IdList; - tree->clear(); bool acceptAnonymous = ui.radioButton_ListAll->isChecked(); bool acceptAllPGP = ui.radioButton_ListAllPGP->isChecked(); //bool acceptKnownPGP = ui.radioButton_ListKnownPGP->isChecked(); - RsGxsIdGroup idGroup; - std::vector datavector; - std::vector::iterator vit; - if (!rsIdentity->getGroupData(token, datavector)) { - std::cerr << "CreateCircleDialog::insertIdentities() Error getting GroupData"; - std::cerr << std::endl; - return; - } - - for(vit = datavector.begin(); vit != datavector.end(); ++vit) + for(const auto& idGroup:id_groups) { - idGroup = (*vit); - /* do filtering */ bool ok = false; if (acceptAnonymous) @@ -851,43 +808,9 @@ void CreateCircleDialog::loadIdentities(uint32_t token) } } -void CreateCircleDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) -{ -#ifdef DEBUG_CREATE_CIRCLE_DIALOG - std::cerr << "CreateCircleDialog::loadRequest() UserType: " << req.mUserType; - std::cerr << std::endl; -#endif - - if (queue == mCircleQueue) { - /* now switch on req */ - switch(req.mUserType) { - case CREATECIRCLEDIALOG_CIRCLEINFO: - loadCircle(req.mToken); - break; - - default: - std::cerr << "CreateCircleDialog::loadRequest() UNKNOWN UserType "; - std::cerr << std::endl; - } - } - - if (queue == mIdQueue) { - /* now switch on req */ - switch(req.mUserType) { - case CREATECIRCLEDIALOG_IDINFO: - loadIdentities(req.mToken); - break; - - default: - std::cerr << "CreateCircleDialog::loadRequest() UNKNOWN UserType "; - std::cerr << std::endl; - } - } -} - void CreateCircleDialog::idTypeChanged() { - requestGxsIdentities(); + loadIdentities(); } void CreateCircleDialog::filterChanged(const QString &text) { diff --git a/retroshare-gui/src/gui/Circles/CreateCircleDialog.h b/retroshare-gui/src/gui/Circles/CreateCircleDialog.h index dd5e52494..8ced0ecdc 100644 --- a/retroshare-gui/src/gui/Circles/CreateCircleDialog.h +++ b/retroshare-gui/src/gui/Circles/CreateCircleDialog.h @@ -25,12 +25,10 @@ #include "ui_CreateCircleDialog.h" -#include "util/TokenQueue.h" - #include #include -class CreateCircleDialog : public QDialog, public TokenResponse +class CreateCircleDialog : public QDialog { Q_OBJECT @@ -45,8 +43,6 @@ public: void addMember(const RsGxsIdGroup &idGroup); void addCircle(const RsGxsCircleDetails &cirDetails); - virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req); - private slots: void addMember(); void removeMember(); @@ -75,17 +71,11 @@ private: bool mIsExternalCircle; bool mReadOnly; - void loadCircle(uint32_t token); - void loadIdentities(uint32_t token); - - void requestCircle(const RsGxsGroupId &groupId); - void requestGxsIdentities(); - //void getPgpIdentities(); + void loadCircle(const RsGxsGroupId& groupId); + void loadIdentities(); void filterIds(); - - TokenQueue *mCircleQueue; - TokenQueue *mIdQueue; + void fillIdentitiesList(const std::vector& id_groups); RsGxsCircleGroup mCircleGroup; // for editting existing Circles. bool mClearList;