added disabling of combo elements in GxsIdChooser for creating forums posts with unautorised GXS ids. Still needs a bit of work

This commit is contained in:
csoler 2016-03-24 00:05:54 -04:00
parent 40d23509a1
commit d33a1e8555
4 changed files with 145 additions and 45 deletions

View file

@ -60,6 +60,7 @@ GxsIdChooser::GxsIdChooser(QWidget *parent)
setSizeAdjustPolicy(QComboBox::AdjustToContents);
mFirstLoad = true;
mAllowedCount = 0 ;
mDefaultId.clear() ;
@ -99,6 +100,13 @@ void GxsIdChooser::showEvent(QShowEvent *event)
QComboBox::showEvent(event);
}
void GxsIdChooser::setIdConstraintSet(const std::set<RsGxsId>& s)
{
mConstraintIdsSet = s ;
updateDisplay(true);
update(); // Qt flush
}
void GxsIdChooser::loadIds(uint32_t chooserFlags, const RsGxsId &defId)
{
mFlags = chooserFlags;
@ -119,6 +127,7 @@ static void loadPrivateIdsCallback(GxsIdDetailsType type, const RsIdentityDetail
return;
}
// this prevents the objects that depend on what's in the combo-box to activate and
// perform any change.Only user-changes should cause this.
chooser->blockSignals(true) ;
@ -167,13 +176,22 @@ static void loadPrivateIdsCallback(GxsIdDetailsType type, const RsIdentityDetail
//std::cerr << " - disabling ID - entry = " << index << std::endl;
chooser->setEntryEnabled(index,false) ;
}
std::cerr << std::endl;
if(!chooser->isInConstraintSet(details.mId))
chooser->setEntryEnabled(index,false) ;
chooser->model()->sort(0);
chooser->blockSignals(false) ;
}
bool GxsIdChooser::isInConstraintSet(const RsGxsId& id) const
{
if(mConstraintIdsSet.empty()) // special case: empty set means no constraint
return true ;
return mConstraintIdsSet.find(id) != mConstraintIdsSet.end() ;
}
void GxsIdChooser::setEntryEnabled(int indx,bool enabled)
{
bool disable = !enabled ;
@ -238,8 +256,7 @@ void GxsIdChooser::loadPrivateIds()
}
for (std::list<RsGxsId>::iterator it = ids.begin(); it != ids.end(); ++it) {
/* add to Chooser */
GxsIdDetails::process(*it, loadPrivateIdsCallback, this);
GxsIdDetails::process(*it, loadPrivateIdsCallback, this); /* add to Chooser */
}
if (mFirstLoad) {

View file

@ -59,6 +59,9 @@ public:
ChosenId_Ret getChosenId(RsGxsId &gxsId);
void setEntryEnabled(int index, bool enabled);
void setIdConstraintSet(const std::set<RsGxsId>& s) ;
bool isInConstraintSet(const RsGxsId& id) const ;
signals:
// emitted after first load of own ids
void idsLoaded();
@ -79,7 +82,9 @@ private:
uint32_t mFlags;
RsGxsId mDefaultId;
bool mFirstLoad;
uint32_t mAllowedCount ;
std::set<RsGxsId> mConstraintIdsSet ; // leave empty if all allowed
RsGxsUpdateBroadcastBase *mBase;
};

View file

@ -28,6 +28,7 @@
#include <QPushButton>
#include <retroshare/rsgxsforums.h>
#include <retroshare/rsgxscircles.h>
#include "gui/settings/rsharesettings.h"
#include "gui/RetroShareLink.h"
@ -43,6 +44,7 @@
#define CREATEGXSFORUMMSG_FORUMINFO 1
#define CREATEGXSFORUMMSG_PARENTMSG 2
#define CREATEGXSFORUMMSG_CIRCLENFO 3
//#define ENABLE_GENERATE
@ -57,6 +59,7 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
/* Setup Queue */
mForumQueue = new TokenQueue(rsGxsForums->getTokenService(), this);
mCirclesQueue = new TokenQueue(rsGxsCircles->getTokenService(), this);
/* Setup UI helper */
mStateHelper = new UIStateHelper(this);
@ -100,6 +103,7 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
mParentMsgLoaded = false;
mForumMetaLoaded = false;
mForumCircleLoaded = false;
newMsg();
@ -112,6 +116,7 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
CreateGxsForumMsg::~CreateGxsForumMsg()
{
delete(mForumQueue);
delete(mCirclesQueue);
}
void CreateGxsForumMsg::newMsg()
@ -444,6 +449,20 @@ void CreateGxsForumMsg::loadForumInfo(const uint32_t &token)
mForumMeta = fi;
mForumMetaLoaded = true;
if(!fi.mCircleId.isNull())
{
std::cerr << "Circle ID is not null: " << fi.mCircleId << ": loading circle info to add constraint to the GXS ID chooser." << std::endl;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(RsGxsGroupId(fi.mCircleId));
uint32_t _token;
mCirclesQueue->requestGroupInfo(_token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, CREATEGXSFORUMMSG_CIRCLENFO);
}
loadFormInformation();
}
else
@ -455,6 +474,45 @@ void CreateGxsForumMsg::loadForumInfo(const uint32_t &token)
mStateHelper->setLoading(CREATEGXSFORUMMSG_FORUMINFO, false);
}
}
void CreateGxsForumMsg::loadForumCircleInfo(const uint32_t& token)
{
std::cerr << "Loading forum circle info" << std::endl;
std::vector<RsGxsCircleGroup> circle_grp_v ;
rsGxsCircles->getGroupData(token, circle_grp_v);
if (circle_grp_v.empty())
{
std::cerr << "(EE) unexpected empty result from getGroupData. Cannot process circle now!" << std::endl;
return ;
}
if (circle_grp_v.size() != 1)
{
std::cerr << "(EE) very weird result from getGroupData. Should get exactly one circle" << std::endl;
return ;
}
RsGxsCircleGroup cg = circle_grp_v.front();
mForumCircleData = cg;
mForumCircleLoaded = true;
std::cerr << "Loaded content of circle " << cg.mMeta.mGroupId << std::endl;
for(std::set<RsGxsId>::const_iterator it(cg.mInvitedMembers.begin());it!=cg.mInvitedMembers.end();++it)
std::cerr << " added constraint to circle element " << *it << std::endl;
ui.idChooser->setIdConstraintSet(cg.mInvitedMembers) ;
ui.idChooser->setFlags(IDCHOOSER_NO_CREATE | ui.idChooser->flags()) ; // since there's a circle involved, no ID creation can be needed
RsGxsId tmpid ;
if(ui.idChooser->getChosenId(tmpid) == GxsIdChooser::None)
{
QMessageBox::information(NULL,tr("No compatible ID for this forum"),tr("Sorry, but this forum is restricted to a circle that contains none of your identities. As a consequence you cannot post in this forum, since your posts could not be propagated.")) ;
close() ;
}
}
void CreateGxsForumMsg::loadParentMsg(const uint32_t &token)
{
@ -501,7 +559,20 @@ void CreateGxsForumMsg::loadRequest(const TokenQueue *queue, const TokenRequest
loadParentMsg(req.mToken);
break;
default:
std::cerr << "CreateGxsForum::loadRequest() UNKNOWN UserType ";
std::cerr << "CreateGxsForumMsg::loadRequest() UNKNOWN UserType " << req.mUserType << " for token request in mForumQueue";
std::cerr << std::endl;
}
}
if(queue == mCirclesQueue)
{
switch(req.mUserType)
{
case CREATEGXSFORUMMSG_CIRCLENFO:
loadForumCircleInfo(req.mToken) ;
break ;
default:
std::cerr << "CreateGxsForumMsg::loadRequest() UNKNOWN UserType " << req.mUserType << " for token request in mCirclesQueue";
std::cerr << std::endl;
}
}

View file

@ -27,6 +27,7 @@
#include "util/TokenQueue.h"
#include <retroshare/rsgxsforums.h>
#include <retroshare/rsgxscircles.h>
class UIStateHelper;
@ -60,16 +61,22 @@ private:
void loadForumInfo(const uint32_t &token);
void loadParentMsg(const uint32_t &token);
void loadForumCircleInfo(const uint32_t &token);
RsGxsGroupId mForumId;
RsGxsCircleId mCircleId ;
RsGxsMessageId mParentId;
bool mParentMsgLoaded;
bool mForumMetaLoaded;
bool mForumCircleLoaded ;
RsGxsForumMsg mParentMsg;
RsGroupMetaData mForumMeta;
RsGxsCircleGroup mForumCircleData ;
TokenQueue *mForumQueue;
TokenQueue *mCirclesQueue;
UIStateHelper *mStateHelper;
/** Qt Designer generated object */