mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-28 16:17:28 -04:00
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:
parent
40d23509a1
commit
d33a1e8555
4 changed files with 145 additions and 45 deletions
|
@ -60,6 +60,7 @@ GxsIdChooser::GxsIdChooser(QWidget *parent)
|
||||||
setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||||
|
|
||||||
mFirstLoad = true;
|
mFirstLoad = true;
|
||||||
|
mAllowedCount = 0 ;
|
||||||
|
|
||||||
mDefaultId.clear() ;
|
mDefaultId.clear() ;
|
||||||
|
|
||||||
|
@ -99,6 +100,13 @@ void GxsIdChooser::showEvent(QShowEvent *event)
|
||||||
QComboBox::showEvent(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)
|
void GxsIdChooser::loadIds(uint32_t chooserFlags, const RsGxsId &defId)
|
||||||
{
|
{
|
||||||
mFlags = chooserFlags;
|
mFlags = chooserFlags;
|
||||||
|
@ -118,6 +126,7 @@ static void loadPrivateIdsCallback(GxsIdDetailsType type, const RsIdentityDetail
|
||||||
if (!chooser) {
|
if (!chooser) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// this prevents the objects that depend on what's in the combo-box to activate and
|
// 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.
|
// perform any change.Only user-changes should cause this.
|
||||||
|
@ -167,13 +176,22 @@ static void loadPrivateIdsCallback(GxsIdDetailsType type, const RsIdentityDetail
|
||||||
//std::cerr << " - disabling ID - entry = " << index << std::endl;
|
//std::cerr << " - disabling ID - entry = " << index << std::endl;
|
||||||
chooser->setEntryEnabled(index,false) ;
|
chooser->setEntryEnabled(index,false) ;
|
||||||
}
|
}
|
||||||
std::cerr << std::endl;
|
|
||||||
|
if(!chooser->isInConstraintSet(details.mId))
|
||||||
|
chooser->setEntryEnabled(index,false) ;
|
||||||
|
|
||||||
chooser->model()->sort(0);
|
chooser->model()->sort(0);
|
||||||
|
|
||||||
chooser->blockSignals(false) ;
|
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)
|
void GxsIdChooser::setEntryEnabled(int indx,bool enabled)
|
||||||
{
|
{
|
||||||
bool disable = !enabled ;
|
bool disable = !enabled ;
|
||||||
|
@ -238,8 +256,7 @@ void GxsIdChooser::loadPrivateIds()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::list<RsGxsId>::iterator it = ids.begin(); it != ids.end(); ++it) {
|
for (std::list<RsGxsId>::iterator it = ids.begin(); it != ids.end(); ++it) {
|
||||||
/* add to Chooser */
|
GxsIdDetails::process(*it, loadPrivateIdsCallback, this); /* add to Chooser */
|
||||||
GxsIdDetails::process(*it, loadPrivateIdsCallback, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mFirstLoad) {
|
if (mFirstLoad) {
|
||||||
|
|
|
@ -58,7 +58,10 @@ public:
|
||||||
bool setChosenId(const RsGxsId &gxsId);
|
bool setChosenId(const RsGxsId &gxsId);
|
||||||
ChosenId_Ret getChosenId(RsGxsId &gxsId);
|
ChosenId_Ret getChosenId(RsGxsId &gxsId);
|
||||||
|
|
||||||
void setEntryEnabled(int index, bool enabled);
|
void setEntryEnabled(int index, bool enabled);
|
||||||
|
|
||||||
|
void setIdConstraintSet(const std::set<RsGxsId>& s) ;
|
||||||
|
bool isInConstraintSet(const RsGxsId& id) const ;
|
||||||
signals:
|
signals:
|
||||||
// emitted after first load of own ids
|
// emitted after first load of own ids
|
||||||
void idsLoaded();
|
void idsLoaded();
|
||||||
|
@ -79,7 +82,9 @@ private:
|
||||||
uint32_t mFlags;
|
uint32_t mFlags;
|
||||||
RsGxsId mDefaultId;
|
RsGxsId mDefaultId;
|
||||||
bool mFirstLoad;
|
bool mFirstLoad;
|
||||||
|
uint32_t mAllowedCount ;
|
||||||
|
|
||||||
|
std::set<RsGxsId> mConstraintIdsSet ; // leave empty if all allowed
|
||||||
RsGxsUpdateBroadcastBase *mBase;
|
RsGxsUpdateBroadcastBase *mBase;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
#include <retroshare/rsgxsforums.h>
|
#include <retroshare/rsgxsforums.h>
|
||||||
|
#include <retroshare/rsgxscircles.h>
|
||||||
|
|
||||||
#include "gui/settings/rsharesettings.h"
|
#include "gui/settings/rsharesettings.h"
|
||||||
#include "gui/RetroShareLink.h"
|
#include "gui/RetroShareLink.h"
|
||||||
|
@ -43,6 +44,7 @@
|
||||||
|
|
||||||
#define CREATEGXSFORUMMSG_FORUMINFO 1
|
#define CREATEGXSFORUMMSG_FORUMINFO 1
|
||||||
#define CREATEGXSFORUMMSG_PARENTMSG 2
|
#define CREATEGXSFORUMMSG_PARENTMSG 2
|
||||||
|
#define CREATEGXSFORUMMSG_CIRCLENFO 3
|
||||||
|
|
||||||
//#define ENABLE_GENERATE
|
//#define ENABLE_GENERATE
|
||||||
|
|
||||||
|
@ -57,6 +59,7 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
|
||||||
|
|
||||||
/* Setup Queue */
|
/* Setup Queue */
|
||||||
mForumQueue = new TokenQueue(rsGxsForums->getTokenService(), this);
|
mForumQueue = new TokenQueue(rsGxsForums->getTokenService(), this);
|
||||||
|
mCirclesQueue = new TokenQueue(rsGxsCircles->getTokenService(), this);
|
||||||
|
|
||||||
/* Setup UI helper */
|
/* Setup UI helper */
|
||||||
mStateHelper = new UIStateHelper(this);
|
mStateHelper = new UIStateHelper(this);
|
||||||
|
@ -100,6 +103,7 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
|
||||||
|
|
||||||
mParentMsgLoaded = false;
|
mParentMsgLoaded = false;
|
||||||
mForumMetaLoaded = false;
|
mForumMetaLoaded = false;
|
||||||
|
mForumCircleLoaded = false;
|
||||||
|
|
||||||
newMsg();
|
newMsg();
|
||||||
|
|
||||||
|
@ -112,6 +116,7 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
|
||||||
CreateGxsForumMsg::~CreateGxsForumMsg()
|
CreateGxsForumMsg::~CreateGxsForumMsg()
|
||||||
{
|
{
|
||||||
delete(mForumQueue);
|
delete(mForumQueue);
|
||||||
|
delete(mCirclesQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateGxsForumMsg::newMsg()
|
void CreateGxsForumMsg::newMsg()
|
||||||
|
@ -297,33 +302,33 @@ void CreateGxsForumMsg::createMsg()
|
||||||
if (ui.signBox->isChecked()) {
|
if (ui.signBox->isChecked()) {
|
||||||
RsGxsId authorId;
|
RsGxsId authorId;
|
||||||
switch (ui.idChooser->getChosenId(authorId)) {
|
switch (ui.idChooser->getChosenId(authorId)) {
|
||||||
case GxsIdChooser::KnowId:
|
case GxsIdChooser::KnowId:
|
||||||
case GxsIdChooser::UnKnowId:
|
case GxsIdChooser::UnKnowId:
|
||||||
msg.mMeta.mAuthorId = authorId;
|
msg.mMeta.mAuthorId = authorId;
|
||||||
std::cerr << "CreateGxsForumMsg::createMsg() AuthorId: " << authorId;
|
std::cerr << "CreateGxsForumMsg::createMsg() AuthorId: " << authorId;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case GxsIdChooser::None:
|
case GxsIdChooser::None:
|
||||||
{
|
{
|
||||||
// This is ONLY for the case where no id exists yet
|
// This is ONLY for the case where no id exists yet
|
||||||
// If an id exists, the chooser would not return None
|
// If an id exists, the chooser would not return None
|
||||||
IdEditDialog dlg(this);
|
IdEditDialog dlg(this);
|
||||||
dlg.setupNewId(false);
|
dlg.setupNewId(false);
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
// fetch new id, we will then see if the identity creation was successful
|
// fetch new id, we will then see if the identity creation was successful
|
||||||
std::list<RsGxsId> own_ids;
|
std::list<RsGxsId> own_ids;
|
||||||
if(!rsIdentity->getOwnIds(own_ids) || own_ids.size() != 1)
|
if(!rsIdentity->getOwnIds(own_ids) || own_ids.size() != 1)
|
||||||
return;
|
return;
|
||||||
// we have only a single id, so we can use the first one
|
// we have only a single id, so we can use the first one
|
||||||
authorId = own_ids.front();
|
authorId = own_ids.front();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GxsIdChooser::NoId:
|
case GxsIdChooser::NoId:
|
||||||
default:
|
default:
|
||||||
std::cerr << "CreateGxsForumMsg::createMsg() ERROR GETTING AuthorId!";
|
std::cerr << "CreateGxsForumMsg::createMsg() ERROR GETTING AuthorId!";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
QMessageBox::warning(this, tr("RetroShare"),tr("Congrats, you found a bug!")+" "+QString(__FILE__)+":"+QString(__LINE__), QMessageBox::Ok, QMessageBox::Ok);
|
QMessageBox::warning(this, tr("RetroShare"),tr("Congrats, you found a bug!")+" "+QString(__FILE__)+":"+QString(__LINE__), QMessageBox::Ok, QMessageBox::Ok);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}//switch (ui.idChooser->getChosenId(authorId))
|
}//switch (ui.idChooser->getChosenId(authorId))
|
||||||
|
@ -431,29 +436,82 @@ void CreateGxsForumMsg::fileHashingFinished(QList<HashedFile> hashedFiles)
|
||||||
|
|
||||||
void CreateGxsForumMsg::loadForumInfo(const uint32_t &token)
|
void CreateGxsForumMsg::loadForumInfo(const uint32_t &token)
|
||||||
{
|
{
|
||||||
std::cerr << "CreateGxsForumMsg::loadForumInfo()";
|
std::cerr << "CreateGxsForumMsg::loadForumInfo()";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
std::list<RsGroupMetaData> groupInfo;
|
std::list<RsGroupMetaData> groupInfo;
|
||||||
rsGxsForums->getGroupSummary(token, groupInfo);
|
rsGxsForums->getGroupSummary(token, groupInfo);
|
||||||
|
|
||||||
if (groupInfo.size() == 1)
|
if (groupInfo.size() == 1)
|
||||||
{
|
{
|
||||||
RsGroupMetaData fi = groupInfo.front();
|
RsGroupMetaData fi = groupInfo.front();
|
||||||
|
|
||||||
mForumMeta = fi;
|
mForumMeta = fi;
|
||||||
mForumMetaLoaded = true;
|
mForumMetaLoaded = true;
|
||||||
|
|
||||||
loadFormInformation();
|
if(!fi.mCircleId.isNull())
|
||||||
}
|
{
|
||||||
else
|
std::cerr << "Circle ID is not null: " << fi.mCircleId << ": loading circle info to add constraint to the GXS ID chooser." << std::endl;
|
||||||
{
|
|
||||||
std::cerr << "CreateGxsForumMsg::loadForumInfo() ERROR INVALID Number of Forums";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
mStateHelper->setActive(CREATEGXSFORUMMSG_FORUMINFO, false);
|
RsTokReqOptions opts;
|
||||||
mStateHelper->setLoading(CREATEGXSFORUMMSG_FORUMINFO, false);
|
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
|
||||||
|
{
|
||||||
|
std::cerr << "CreateGxsForumMsg::loadForumInfo() ERROR INVALID Number of Forums";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
mStateHelper->setActive(CREATEGXSFORUMMSG_FORUMINFO, false);
|
||||||
|
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)
|
void CreateGxsForumMsg::loadParentMsg(const uint32_t &token)
|
||||||
|
@ -501,10 +559,23 @@ void CreateGxsForumMsg::loadRequest(const TokenQueue *queue, const TokenRequest
|
||||||
loadParentMsg(req.mToken);
|
loadParentMsg(req.mToken);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
std::cerr << "CreateGxsForum::loadRequest() UNKNOWN UserType ";
|
std::cerr << "CreateGxsForumMsg::loadRequest() UNKNOWN UserType " << req.mUserType << " for token request in mForumQueue";
|
||||||
std::cerr << std::endl;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateGxsForumMsg::insertPastedText(QString msg)
|
void CreateGxsForumMsg::insertPastedText(QString msg)
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "util/TokenQueue.h"
|
#include "util/TokenQueue.h"
|
||||||
|
|
||||||
#include <retroshare/rsgxsforums.h>
|
#include <retroshare/rsgxsforums.h>
|
||||||
|
#include <retroshare/rsgxscircles.h>
|
||||||
|
|
||||||
class UIStateHelper;
|
class UIStateHelper;
|
||||||
|
|
||||||
|
@ -54,22 +55,28 @@ private slots:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent (QCloseEvent * event);
|
void closeEvent (QCloseEvent * event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadFormInformation();
|
void loadFormInformation();
|
||||||
|
|
||||||
void loadForumInfo(const uint32_t &token);
|
void loadForumInfo(const uint32_t &token);
|
||||||
void loadParentMsg(const uint32_t &token);
|
void loadParentMsg(const uint32_t &token);
|
||||||
|
void loadForumCircleInfo(const uint32_t &token);
|
||||||
|
|
||||||
RsGxsGroupId mForumId;
|
RsGxsGroupId mForumId;
|
||||||
|
RsGxsCircleId mCircleId ;
|
||||||
RsGxsMessageId mParentId;
|
RsGxsMessageId mParentId;
|
||||||
|
|
||||||
bool mParentMsgLoaded;
|
bool mParentMsgLoaded;
|
||||||
bool mForumMetaLoaded;
|
bool mForumMetaLoaded;
|
||||||
|
bool mForumCircleLoaded ;
|
||||||
RsGxsForumMsg mParentMsg;
|
RsGxsForumMsg mParentMsg;
|
||||||
RsGroupMetaData mForumMeta;
|
RsGroupMetaData mForumMeta;
|
||||||
|
RsGxsCircleGroup mForumCircleData ;
|
||||||
|
|
||||||
TokenQueue *mForumQueue;
|
TokenQueue *mForumQueue;
|
||||||
|
TokenQueue *mCirclesQueue;
|
||||||
|
|
||||||
UIStateHelper *mStateHelper;
|
UIStateHelper *mStateHelper;
|
||||||
|
|
||||||
/** Qt Designer generated object */
|
/** Qt Designer generated object */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue