Merge pull request #1819 from csoler/v0.6-FT4

attempt to fix crashes in IdDialog::loadCircles()
This commit is contained in:
csoler 2020-03-07 16:17:58 +01:00 committed by GitHub
commit 8a2508109a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 84 additions and 96 deletions

View File

@ -3002,9 +3002,11 @@ void p3IdService::requestIdsFromNet()
}
else
{
#ifdef DEBUG_IDS
RsInfo() << __PRETTY_FUNCTION__ << " no online peers among supplied"
<< " list in request for RsGxsId: " << gxsId
<< ". Keeping it until peers show up."<< std::endl;
#endif
++cit;
}
}

View File

@ -185,7 +185,7 @@ bool RetroDb::execSQL(const std::string &query){
uint32_t delta = 3;
rstime_t stamp = time(NULL), now = 0;
rstime_t stamp = time(NULL);
bool timeOut = false, ok = false;
while(!timeOut){
@ -202,10 +202,8 @@ bool RetroDb::execSQL(const std::string &query){
break;
}
now = time(NULL);
delta = stamp - now;
if(delta > TIME_LIMIT){
if(time(NULL) > stamp + TIME_LIMIT)
{
ok = false;
timeOut = true;
}

View File

@ -515,6 +515,68 @@ void IdDialog::updateCircles()
});
}
static QTreeWidgetItem *setChildItem(QTreeWidgetItem *item, const RsGroupMetaData& circle_group)
{
QString test_str = QString::fromStdString(circle_group.mGroupId.toStdString());
// 1 - check if the item already exists and remove possible duplicates
std::vector<uint32_t> found_indices;
for(uint32_t k=0; k < (uint32_t)item->childCount(); ++k)
if( item->child(k)->data(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole).toString() == test_str)
found_indices.push_back(k);
while(found_indices.size() > 1) // delete duplicates, starting from the end in order that deletion preserves indices
{
delete item->takeChild(found_indices.back());
found_indices.pop_back();
}
if(!found_indices.empty())
{
QTreeWidgetItem *subitem = item->child(found_indices[0]);
if(subitem->text(CIRCLEGROUP_CIRCLE_COL_GROUPNAME) != QString::fromUtf8(circle_group.mGroupName.c_str()))
{
#ifdef ID_DEBUG
std::cerr << " Existing circle has a new name. Updating it in the tree." << std::endl;
#endif
subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(circle_group.mGroupName.c_str()));
}
return subitem;
}
// 2 - if not, create
QTreeWidgetItem *subitem = new QTreeWidgetItem();
subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(circle_group.mGroupName.c_str()));
subitem->setData(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole, QString::fromStdString(circle_group.mGroupId.toStdString()));
subitem->setData(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole, QVariant(circle_group.mSubscribeFlags));
item->addChild(subitem);
return subitem;
}
static void removeChildItem(QTreeWidgetItem *item, const RsGroupMetaData& circle_group)
{
QString test_str = QString::fromStdString(circle_group.mGroupId.toStdString());
// 1 - check if the item already exists and remove possible duplicates
std::list<uint32_t> found_indices;
for(uint32_t k=0; k < (uint32_t)item->childCount(); ++k)
if( item->child(k)->data(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole).toString() == test_str)
found_indices.push_front(k);
for(auto k:found_indices)
delete item->takeChild(k); // delete items in the reverse order (because of the push_front()), so that indices are preserved
}
void IdDialog::loadCircles(const std::list<RsGroupMetaData>& groupInfo)
{
#ifdef ID_DEBUG
@ -561,102 +623,27 @@ void IdDialog::loadCircles(const std::list<RsGroupMetaData>& groupInfo)
bool am_I_in_circle = details.mAmIAllowed ;
bool am_I_admin (vit->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN) ;
bool am_I_subscribed (vit->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED) ;
QTreeWidgetItem *item = NULL ;
#ifdef ID_DEBUG
std::cerr << "Loaded info for circle " << vit->mGroupId << ". am_I_in_circle=" << am_I_in_circle << std::endl;
#endif
// find already existing items for this circle
// implement the search manually, because there's no find based on user role.
//QList<QTreeWidgetItem*> clist = ui->treeWidget_membership->findItems( QString::fromStdString(vit->mGroupId.toStdString()), Qt::MatchExactly|Qt::MatchRecursive, CIRCLEGROUP_CIRCLE_COL_GROUPID);
QList<QTreeWidgetItem*> clist ;
QString test_str = QString::fromStdString(vit->mGroupId.toStdString()) ;
for(QTreeWidgetItemIterator itt(ui->treeWidget_membership);*itt;++itt)
if( (*itt)->data(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole).toString() == test_str)
clist.push_back(*itt) ;
if(!clist.empty())
{
// delete all duplicate items. This should not happen, but just in case it does.
while(clist.size() > 1)
{
#ifdef ID_DEBUG
std::cerr << " more than 1 item correspond to this ID. Removing!" << std::endl;
#endif
delete clist.front() ;
clist.pop_front();
}
item = clist.front() ;
#ifdef CIRCLE_MEMBERSHIP_CATEGORIES
if(am_I_in_circle && item->parent() != mExternalBelongingCircleItem)
{
#ifdef ID_DEBUG
std::cerr << " Existing circle is not in subscribed items although it is subscribed. Removing." << std::endl;
#endif
delete item ;
item = NULL ;
}
else if(!am_I_in_circle && item->parent() != mExternalOtherCircleItem)
{
#ifdef ID_DEBUG
std::cerr << " Existing circle is not in subscribed items although it is subscribed. Removing." << std::endl;
#endif
delete item ;
item = NULL ;
}
else
#endif
should_re_add = false ; // item already exists
}
/* Add Widget, and request Pages */
if(should_re_add)
{
item = new QTreeWidgetItem();
item->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(vit->mGroupName.c_str()));
item->setData(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole, QString::fromStdString(vit->mGroupId.toStdString()));
item->setData(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole, QVariant(vit->mSubscribeFlags));
#ifdef CIRCLE_MEMBERSHIP_CATEGORIES
if(am_I_in_circle)
{
#ifdef ID_DEBUG
std::cerr << " adding item for circle " << vit->mGroupId << " to own circles"<< std::endl;
#endif
mExternalBelongingCircleItem->addChild(item);
}
else
{
#ifdef ID_DEBUG
std::cerr << " adding item for circle " << vit->mGroupId << " to others"<< std::endl;
#endif
mExternalOtherCircleItem->addChild(item);
}
#else
ui->treeWidget_membership->addTopLevelItem(item) ;
#endif
}
else if(item->text(CIRCLEGROUP_CIRCLE_COL_GROUPNAME) != QString::fromUtf8(vit->mGroupName.c_str()))
{
#ifdef ID_DEBUG
std::cerr << " Existing circle has a new name. Updating it in the tree." << std::endl;
#endif
item->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(vit->mGroupName.c_str()));
}
// just in case.
// Find already existing items for this circle, or create one.
QTreeWidgetItem *item = NULL ;
if(am_I_in_circle)
{
item = setChildItem(mExternalBelongingCircleItem,*vit);
removeChildItem(mExternalOtherCircleItem,*vit);
}
else
{
item = setChildItem(mExternalOtherCircleItem,*vit);
removeChildItem(mExternalBelongingCircleItem,*vit);
}
item->setData(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole, QVariant(vit->mSubscribeFlags));
QString tooltip ;
tooltip += tr("Circle ID: ")+QString::fromStdString(vit->mGroupId.toStdString()) ;
tooltip += "\n"+tr("Visibility: ");
if(details.mRestrictedCircleId == details.mCircleId)
@ -1532,11 +1519,12 @@ void IdDialog::loadIdentities(const std::map<RsGxsGroupId,RsGxsIdGroup>& ids_set
contactsItem->addChild(item);
else
allItem->addChild(item);
}
GxsIdLabel *label = new GxsIdLabel();
label->setId(RsGxsId(data.mMeta.mGroupId)) ;
ui->treeWidget_membership->setItemWidget(item,0,label) ;
GxsIdLabel *label = new GxsIdLabel();
label->setId(RsGxsId(data.mMeta.mGroupId)) ;
ui->treeWidget_membership->setItemWidget(item,0,label) ;
}
}
/* count items */