Merge pull request #2327 from csoler/v0.6-BugFixing_10

experimental fix against early closing crash on CreateCircleDialog
This commit is contained in:
csoler 2021-02-19 18:05:04 +01:00 committed by GitHub
commit d2407c4e9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 5 deletions

View File

@ -21,6 +21,7 @@
*******************************************************************************/ *******************************************************************************/
#include <QMessageBox> #include <QMessageBox>
#include <QCloseEvent>
#include <QMenu> #include <QMenu>
#include <algorithm> #include <algorithm>
@ -51,7 +52,11 @@
CreateCircleDialog::CreateCircleDialog() CreateCircleDialog::CreateCircleDialog()
: QDialog(NULL, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint) : QDialog(NULL, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint)
{ {
/* Invoke the Qt Designer generated object setup routine */ mIdentitiesLoading = false;
mCircleLoading = false;
mCloseRequested = false;
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this); ui.setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, false); setAttribute(Qt::WA_DeleteOnClose, false);
@ -112,12 +117,46 @@ CreateCircleDialog::CreateCircleDialog()
QObject::connect(ui.radioButton_Public, SIGNAL(toggled(bool)), this, SLOT(updateCircleType(bool))) ; QObject::connect(ui.radioButton_Public, SIGNAL(toggled(bool)), this, SLOT(updateCircleType(bool))) ;
QObject::connect(ui.radioButton_Self, SIGNAL(toggled(bool)), this, SLOT(updateCircleType(bool))) ; QObject::connect(ui.radioButton_Self, SIGNAL(toggled(bool)), this, SLOT(updateCircleType(bool))) ;
QObject::connect(ui.radioButton_Restricted, SIGNAL(toggled(bool)), this, SLOT(updateCircleType(bool))) ; QObject::connect(ui.radioButton_Restricted, SIGNAL(toggled(bool)), this, SLOT(updateCircleType(bool))) ;
} }
CreateCircleDialog::~CreateCircleDialog() CreateCircleDialog::~CreateCircleDialog()
{ {
} }
bool CreateCircleDialog::tryClose()
{
if(mIdentitiesLoading || mCircleLoading)
{
std::cerr << "Close() called. Identities or circle currently loading => not actually closing." << std::endl;
mCloseRequested = true;
return false;
}
else
{
std::cerr << "Close() called. Identities not currently loading => closing." << std::endl;
return true;
}
}
void CreateCircleDialog::accept()
{
if(tryClose())
QDialog::accept();
}
void CreateCircleDialog::reject()
{
if(tryClose())
QDialog::reject();
}
void CreateCircleDialog::keyPressEvent(QKeyEvent *e)
{
if(e->key() != Qt::Key_Escape || tryClose())
QDialog::keyPressEvent(e);
}
void CreateCircleDialog::editExistingId(const RsGxsGroupId &circleId, const bool &clearList /*= true*/,bool readonly) void CreateCircleDialog::editExistingId(const RsGxsGroupId &circleId, const bool &clearList /*= true*/,bool readonly)
{ {
/* load this circle */ /* load this circle */
@ -666,6 +705,9 @@ void CreateCircleDialog::loadCircle(const RsGxsGroupId& groupId)
QTreeWidget *tree = ui.treeWidget_membership; QTreeWidget *tree = ui.treeWidget_membership;
if (mClearList) tree->clear(); if (mClearList) tree->clear();
std::cerr << "Loading circle..."<< std::endl;
mCircleLoading = true;
RsThread::async([groupId,this]() RsThread::async([groupId,this]()
{ {
std::vector<RsGxsCircleGroup> circlesInfo ; std::vector<RsGxsCircleGroup> circlesInfo ;
@ -691,7 +733,17 @@ void CreateCircleDialog::loadCircle(const RsGxsGroupId& groupId)
#endif #endif
updateCircleGUI(); updateCircleGUI();
}, this ); mCircleLoading = false;
std::cerr << "finished loading circle..."<< std::endl;
if(mCloseRequested && !mIdentitiesLoading)
{
std::cerr << "Close() previously called, so closing now." << std::endl;
close();
}
}, this );
}); });
} }
@ -700,6 +752,8 @@ void CreateCircleDialog::loadIdentities()
{ {
std::cerr << "Loading identities..." << std::endl; std::cerr << "Loading identities..." << std::endl;
mIdentitiesLoading = true;
RsThread::async([this]() RsThread::async([this]()
{ {
std::list<RsGroupMetaData> ids_meta; std::list<RsGroupMetaData> ids_meta;
@ -735,7 +789,17 @@ void CreateCircleDialog::loadIdentities()
fillIdentitiesList(*id_groups); fillIdentitiesList(*id_groups);
delete id_groups; delete id_groups;
}, this );
std::cerr << "Identities finished loading." << std::endl;
mIdentitiesLoading = false;
if(mCloseRequested && !mCircleLoading)
{
std::cerr << "Close() previously called, so closing now." << std::endl;
close();
}
}, this );
}); });
} }
@ -756,6 +820,8 @@ void CreateCircleDialog::fillIdentitiesList(const std::vector<RsGxsIdGroup>& id_
for(const auto& idGroup:id_groups) for(const auto& idGroup:id_groups)
{ {
//usleep(20*1000);
bool isSigned = !idGroup.mPgpId.isNull(); bool isSigned = !idGroup.mPgpId.isNull();
bool isSignedByFriendNode = isSigned && rsPeers->isPgpFriend(idGroup.mPgpId); bool isSignedByFriendNode = isSigned && rsPeers->isPgpFriend(idGroup.mPgpId);

View File

@ -44,7 +44,8 @@ public:
void addCircle(const RsGxsCircleDetails &cirDetails); void addCircle(const RsGxsCircleDetails &cirDetails);
private slots: private slots:
void addMember();
void addMember();
void removeMember(); void removeMember();
void updateCircleType(bool b); void updateCircleType(bool b);
@ -60,6 +61,12 @@ private slots:
void IdListCustomPopupMenu( QPoint point ); void IdListCustomPopupMenu( QPoint point );
void MembershipListCustomPopupMenu( QPoint point); void MembershipListCustomPopupMenu( QPoint point);
protected:
virtual void keyPressEvent(QKeyEvent *e) override;
virtual void accept() override;
virtual void reject() override;
bool tryClose();
private: private:
void updateCircleGUI(); void updateCircleGUI();
@ -69,7 +76,10 @@ private:
bool mIsExistingCircle; bool mIsExistingCircle;
bool mIsExternalCircle; bool mIsExternalCircle;
bool mReadOnly; bool mReadOnly;
bool mIdentitiesLoading;
bool mCircleLoading;
bool mCloseRequested;
void loadCircle(const RsGxsGroupId& groupId); void loadCircle(const RsGxsGroupId& groupId);
void loadIdentities(); void loadIdentities();