From 8ab9adacef8ad40a84410fdd3b79593b6bffbe47 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 22 Jun 2022 15:13:07 +0200 Subject: [PATCH] removed token queue from circles --- .../src/gui/Circles/CirclesDialog.cpp | 109 ++++++++++-------- .../src/gui/Circles/CirclesDialog.h | 8 +- 2 files changed, 66 insertions(+), 51 deletions(-) diff --git a/retroshare-gui/src/gui/Circles/CirclesDialog.cpp b/retroshare-gui/src/gui/Circles/CirclesDialog.cpp index 41fd4e9f2..5c792c1d1 100644 --- a/retroshare-gui/src/gui/Circles/CirclesDialog.cpp +++ b/retroshare-gui/src/gui/Circles/CirclesDialog.cpp @@ -25,6 +25,7 @@ #include "gui/Circles/CirclesDialog.h" #include "gui/Circles/CreateCircleDialog.h" #include "gui/common/UIStateHelper.h" +#include "util/qtthreadsutils.h" #include #include @@ -72,9 +73,6 @@ CirclesDialog::CirclesDialog(QWidget *parent) connect(ui.treeWidget_membership, SIGNAL(itemSelectionChanged()), this, SLOT(circle_selected())); - /* Setup TokenQueue */ - mCircleQueue = new TokenQueue(rsGxsCircles->getTokenService(), this); - /* Set header resize modes and initial section sizes */ QHeaderView * membership_header = ui.treeWidget_membership->header () ; membership_header->resizeSection ( CIRCLEGROUP_CIRCLE_COL_GROUPNAME, 200 ); @@ -82,7 +80,6 @@ CirclesDialog::CirclesDialog(QWidget *parent) CirclesDialog::~CirclesDialog() { - delete mCircleQueue; } void CirclesDialog::todo() @@ -564,37 +561,59 @@ void CirclesDialog::requestGroupMeta() { mStateHelper->setLoading(CIRCLESDIALOG_GROUPMETA, true); - std::cerr << "CirclesDialog::requestGroupMeta()"; - std::cerr << std::endl; + RsThread::async([this]() + { + std::list circles; - mCircleQueue->cancelActiveRequestTokens(CIRCLESDIALOG_GROUPMETA); + if(!rsGxsCircles->getCirclesSummaries(circles)) + { + std::cerr << __PRETTY_FUNCTION__ << " failed to get circles summaries " << std::endl; + return; + } - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_META; + RsQThreadUtils::postToObject( [this,circles]() + { + /* 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, note that + * Qt::QueuedConnection is important! + */ - uint32_t token; - mCircleQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, CIRCLESDIALOG_GROUPMETA); + loadGroupMeta(circles); + + }, this ); + }); +// std::cerr << "CirclesDialog::requestGroupMeta()"; +// std::cerr << std::endl; +// +// mCircleQueue->cancelActiveRequestTokens(CIRCLESDIALOG_GROUPMETA); +// +// RsTokReqOptions opts; +// opts.mReqType = GXS_REQUEST_TYPE_GROUP_META; +// +// uint32_t token; +// mCircleQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, CIRCLESDIALOG_GROUPMETA); } -void CirclesDialog::loadGroupMeta(const uint32_t &token) +void CirclesDialog::loadGroupMeta(const std::list& groupInfo) { mStateHelper->setLoading(CIRCLESDIALOG_GROUPMETA, false); - std::cerr << "CirclesDialog::loadGroupMeta()"; - std::cerr << std::endl; +// std::cerr << "CirclesDialog::loadGroupMeta()"; +// std::cerr << std::endl; ui.treeWidget_membership->clear(); - std::list groupInfo; - std::list::iterator vit; +// std::list groupInfo; +// std::list::iterator vit; - if (!rsGxsCircles->getGroupSummary(token,groupInfo)) - { - std::cerr << "CirclesDialog::loadGroupMeta() Error getting GroupMeta"; - std::cerr << std::endl; - mStateHelper->setActive(CIRCLESDIALOG_GROUPMETA, false); - return; - } +// if (!rsGxsCircles->getGroupSummary(token,groupInfo)) +// { +// std::cerr << "CirclesDialog::loadGroupMeta() Error getting GroupMeta"; +// std::cerr << std::endl; +// mStateHelper->setActive(CIRCLESDIALOG_GROUPMETA, false); +// return; +// } mStateHelper->setActive(CIRCLESDIALOG_GROUPMETA, true); @@ -615,7 +634,7 @@ void CirclesDialog::loadGroupMeta(const uint32_t &token) externalOtherCirclesItem->setText(0, tr("External Circles (Other)")); ui.treeWidget_membership->addTopLevelItem(externalOtherCirclesItem); - for(vit = groupInfo.begin(); vit != groupInfo.end(); ++vit) + for(auto vit = groupInfo.begin(); vit != groupInfo.end(); ++vit) { /* Add Widget, and request Pages */ std::cerr << "CirclesDialog::loadGroupMeta() GroupId: " << vit->mGroupId; @@ -648,24 +667,24 @@ void CirclesDialog::loadGroupMeta(const uint32_t &token) } } -void CirclesDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) -{ - std::cerr << "CirclesDialog::loadRequest() UserType: " << req.mUserType; - std::cerr << std::endl; - - if (queue == mCircleQueue) - { - /* now switch on req */ - switch(req.mUserType) - { - case CIRCLESDIALOG_GROUPMETA: - loadGroupMeta(req.mToken); - break; - - default: - std::cerr << "CirclesDialog::loadRequest() ERROR: INVALID TYPE"; - std::cerr << std::endl; - break; - } - } -} +// void CirclesDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) +// { +// std::cerr << "CirclesDialog::loadRequest() UserType: " << req.mUserType; +// std::cerr << std::endl; +// +// if (queue == mCircleQueue) +// { +// /* now switch on req */ +// switch(req.mUserType) +// { +// case CIRCLESDIALOG_GROUPMETA: +// loadGroupMeta(req.mToken); +// break; +// +// default: +// std::cerr << "CirclesDialog::loadRequest() ERROR: INVALID TYPE"; +// std::cerr << std::endl; +// break; +// } +// } +// } diff --git a/retroshare-gui/src/gui/Circles/CirclesDialog.h b/retroshare-gui/src/gui/Circles/CirclesDialog.h index ac87f9f61..56011dc61 100644 --- a/retroshare-gui/src/gui/Circles/CirclesDialog.h +++ b/retroshare-gui/src/gui/Circles/CirclesDialog.h @@ -24,14 +24,13 @@ #define MRK_CIRCLE_DIALOG_H #include "gui/gxs/RsGxsUpdateBroadcastPage.h" -#include "util/TokenQueue.h" #include "ui_CirclesDialog.h" #define IMAGE_CIRCLES ":/icons/png/circles.png" class UIStateHelper; -class CirclesDialog : public MainPage, public TokenResponse +class CirclesDialog : public MainPage { Q_OBJECT @@ -43,8 +42,6 @@ public: virtual QString pageName() const { return tr("Circles") ; } //MainPage virtual QString helpText() const { return ""; } //MainPage - void loadRequest(const TokenQueue *queue, const TokenRequest &req); - protected: virtual void updateDisplay(bool complete); @@ -62,9 +59,8 @@ private: void reloadAll(); void requestGroupMeta(); - void loadGroupMeta(const uint32_t &token); + void loadGroupMeta(const std::list& groupInfo); - TokenQueue *mCircleQueue; UIStateHelper *mStateHelper; /* UI - from Designer */