fixed display of contactlist when changing status, and improved computaitonal efficiency

This commit is contained in:
csoler 2015-12-23 12:08:20 -05:00
parent 5d9272055f
commit 52da8cd0e6
3 changed files with 71 additions and 72 deletions

View file

@ -121,6 +121,7 @@ class RsGxsIdGroup
// Not Serialised - for GUI's benefit. // Not Serialised - for GUI's benefit.
bool mPgpKnown; bool mPgpKnown;
bool mIsAContact; // change that into flags one day
RsPgpId mPgpId; RsPgpId mPgpId;
GxsReputation mReputation; GxsReputation mReputation;
}; };

View file

@ -1099,6 +1099,8 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup>
std::cerr << std::endl; std::cerr << std::endl;
} }
group.mIsAContact = (mContacts.find(RsGxsId(group.mMeta.mGroupId)) != mContacts.end());
groups.push_back(group); groups.push_back(group);
delete(item); delete(item);
} }

View file

@ -442,6 +442,7 @@ void IdDialog::insertIdList(uint32_t token)
RsGxsIdGroup data; RsGxsIdGroup data;
std::vector<RsGxsIdGroup> datavector; std::vector<RsGxsIdGroup> datavector;
std::vector<RsGxsIdGroup>::iterator vit; std::vector<RsGxsIdGroup>::iterator vit;
if (!rsIdentity->getGroupData(token, datavector)) if (!rsIdentity->getGroupData(token, datavector))
{ {
#ifdef ID_DEBUG #ifdef ID_DEBUG
@ -455,71 +456,68 @@ void IdDialog::insertIdList(uint32_t token)
return; return;
} }
// turn that vector into a std::set, to avoid a linear search
std::map<RsGxsGroupId,RsGxsIdGroup> ids_set ;
for(uint32_t i=0;i<datavector.size();++i)
ids_set[datavector[i].mMeta.mGroupId] = datavector[i] ;
mStateHelper->setActive(IDDIALOG_IDLIST, true); mStateHelper->setActive(IDDIALOG_IDLIST, true);
RsPgpId ownPgpId = rsPeers->getGPGOwnId(); RsPgpId ownPgpId = rsPeers->getGPGOwnId();
/* Update existing and remove not existing items */ // Update existing and remove not existing items
// Also remove items that do not have the correct parent
QTreeWidgetItemIterator itemIterator(ui->idTreeWidget); QTreeWidgetItemIterator itemIterator(ui->idTreeWidget);
QTreeWidgetItem *item = NULL; QTreeWidgetItem *item = NULL;
while ((item = *itemIterator) != NULL) {
++itemIterator;
for (vit = datavector.begin(); vit != datavector.end(); ++vit) while ((item = *itemIterator) != NULL)
{ {
if (vit->mMeta.mGroupId == RsGxsGroupId(item->text(RSID_COL_KEYID).toStdString())) ++itemIterator;
{ std::map<RsGxsGroupId,RsGxsIdGroup>::iterator it = ids_set.find(RsGxsGroupId(item->text(RSID_COL_KEYID).toStdString())) ;
break;
} if(it == ids_set.end())
}
if (vit == datavector.end())
{ {
if(item != allItem && item != contactsItem) if(item != allItem && item != contactsItem)
{
delete(item); delete(item);
continue ;
} }
} else {
if (!fillIdListItem(*vit, item, ownPgpId, accept)) QTreeWidgetItem *parent_item = item->parent() ;
if( (parent_item == allItem && it->second.mIsAContact) || (parent_item == contactsItem && !it->second.mIsAContact))
{ {
delete item ; // do not remove from the list, so that it is added again in the correct place.
continue ;
}
if (!fillIdListItem(it->second, item, ownPgpId, accept))
delete(item); delete(item);
}
datavector.erase(vit); ids_set.erase(it); // erase, so it is not considered to be a new item
}
} }
/* Insert new items */ /* Insert new items */
for (vit = datavector.begin(); vit != datavector.end(); ++vit) for (std::map<RsGxsGroupId,RsGxsIdGroup>::const_iterator vit = ids_set.begin(); vit != ids_set.end(); ++vit)
{ {
data = (*vit); data = vit->second ;
item = NULL; item = NULL;
ui->idTreeWidget->insertTopLevelItem(0, contactsItem ); ui->idTreeWidget->insertTopLevelItem(0, contactsItem );
ui->idTreeWidget->insertTopLevelItem(0, allItem); ui->idTreeWidget->insertTopLevelItem(0, allItem);
if (fillIdListItem(*vit, item, ownPgpId, accept)) if (fillIdListItem(vit->second, item, ownPgpId, accept))
{ if(vit->second.mIsAContact)
RsIdentityDetails details;
std::string keyId = item->text(RSID_COL_KEYID).toStdString();
rsIdentity->getIdDetails(RsGxsId(keyId), details);
if(details.mFlags & RS_IDENTITY_FLAGS_IS_A_CONTACT)
{
contactsItem->addChild(item); contactsItem->addChild(item);
}
else else
{
allItem->addChild(item); allItem->addChild(item);
} }
}
}
//int itemCount = item->childCount();
/* count items */
//ui->label_count->setText( "(" + QString::number(itemCount) + ")" );
filterIds(); filterIds();
updateSelection(); updateSelection();
} }
@ -1110,7 +1108,6 @@ void IdDialog::addtoContacts()
rsIdentity->setAsRegularContact(RsGxsId(Id),true); rsIdentity->setAsRegularContact(RsGxsId(Id),true);
requestIdDetails();
requestIdList(); requestIdList();
} }
@ -1126,7 +1123,6 @@ void IdDialog::removefromContacts()
rsIdentity->setAsRegularContact(RsGxsId(Id),false); rsIdentity->setAsRegularContact(RsGxsId(Id),false);
requestIdDetails();
requestIdList(); requestIdList();
} }