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

@ -120,8 +120,9 @@ class RsGxsIdGroup
time_t mLastUsageTS ;
// Not Serialised - for GUI's benefit.
bool mPgpKnown;
RsPgpId mPgpId;
bool mPgpKnown;
bool mIsAContact; // change that into flags one day
RsPgpId mPgpId;
GxsReputation mReputation;
};

View File

@ -1060,33 +1060,33 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup>
if (item)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::getGroupData() Item is:";
std::cerr << std::endl;
item->print(std::cerr);
std::cerr << std::endl;
std::cerr << "p3IdService::getGroupData() Item is:";
std::cerr << std::endl;
item->print(std::cerr);
std::cerr << std::endl;
#endif // DEBUG_IDS
RsGxsIdGroup group ;
item->toGxsIdGroup(group,false) ;
RsGxsIdGroup group ;
item->toGxsIdGroup(group,false) ;
{
RS_STACK_MUTEX(mIdMtx) ;
group.mLastUsageTS = locked_getLastUsageTS(RsGxsId(group.mMeta.mGroupId)) ;
}
{
RS_STACK_MUTEX(mIdMtx) ;
group.mLastUsageTS = locked_getLastUsageTS(RsGxsId(group.mMeta.mGroupId)) ;
}
// Decode information from serviceString.
SSGxsIdGroup ssdata;
if (ssdata.load(group.mMeta.mServiceString))
{
group.mPgpKnown = ssdata.pgp.idKnown;
group.mPgpId = ssdata.pgp.pgpId;
group.mReputation = ssdata.score.rep;
// Decode information from serviceString.
SSGxsIdGroup ssdata;
if (ssdata.load(group.mMeta.mServiceString))
{
group.mPgpKnown = ssdata.pgp.idKnown;
group.mPgpId = ssdata.pgp.pgpId;
group.mReputation = ssdata.score.rep;
#ifdef DEBUG_IDS
std::cerr << "p3IdService::getGroupData() Success decoding ServiceString";
std::cerr << std::endl;
std::cerr << "\t mGpgKnown: " << group.mPgpKnown;
std::cerr << std::endl;
std::cerr << "\t mGpgId: " << group.mPgpId;
std::cerr << std::endl;
std::cerr << "p3IdService::getGroupData() Success decoding ServiceString";
std::cerr << std::endl;
std::cerr << "\t mGpgKnown: " << group.mPgpKnown;
std::cerr << std::endl;
std::cerr << "\t mGpgId: " << group.mPgpId;
std::cerr << std::endl;
#endif // DEBUG_IDS
}
else
@ -1094,13 +1094,15 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup>
group.mPgpKnown = false;
group.mPgpId.clear();
std::cerr << "p3IdService::getGroupData() Failed to decode ServiceString \""
<< group.mMeta.mServiceString << "\"" ;
std::cerr << "p3IdService::getGroupData() Failed to decode ServiceString \""
<< group.mMeta.mServiceString << "\"" ;
std::cerr << std::endl;
}
group.mIsAContact = (mContacts.find(RsGxsId(group.mMeta.mGroupId)) != mContacts.end());
groups.push_back(group);
delete(item);
delete(item);
}
else
{

View File

@ -442,6 +442,7 @@ void IdDialog::insertIdList(uint32_t token)
RsGxsIdGroup data;
std::vector<RsGxsIdGroup> datavector;
std::vector<RsGxsIdGroup>::iterator vit;
if (!rsIdentity->getGroupData(token, datavector))
{
#ifdef ID_DEBUG
@ -454,72 +455,69 @@ void IdDialog::insertIdList(uint32_t token)
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);
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);
QTreeWidgetItem *item = NULL;
while ((item = *itemIterator) != NULL) {
while ((item = *itemIterator) != NULL)
{
++itemIterator;
std::map<RsGxsGroupId,RsGxsIdGroup>::iterator it = ids_set.find(RsGxsGroupId(item->text(RSID_COL_KEYID).toStdString())) ;
for (vit = datavector.begin(); vit != datavector.end(); ++vit)
if(it == ids_set.end())
{
if (vit->mMeta.mGroupId == RsGxsGroupId(item->text(RSID_COL_KEYID).toStdString()))
{
break;
}
}
if (vit == datavector.end())
{
if(item != allItem && item != contactsItem)
{
delete(item);
}
} else {
if (!fillIdListItem(*vit, item, ownPgpId, accept))
{
if(item != allItem && item != contactsItem)
delete(item);
}
datavector.erase(vit);
}
continue ;
}
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);
ids_set.erase(it); // erase, so it is not considered to be a new item
}
/* 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;
ui->idTreeWidget->insertTopLevelItem(0, contactsItem );
ui->idTreeWidget->insertTopLevelItem(0, allItem);
if (fillIdListItem(*vit, item, ownPgpId, accept))
{
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);
}
else
{
allItem->addChild(item);
}
if (fillIdListItem(vit->second, item, ownPgpId, accept))
if(vit->second.mIsAContact)
contactsItem->addChild(item);
else
allItem->addChild(item);
}
}
//int itemCount = item->childCount();
/* count items */
//ui->label_count->setText( "(" + QString::number(itemCount) + ")" );
filterIds();
updateSelection();
}
@ -1110,7 +1108,6 @@ void IdDialog::addtoContacts()
rsIdentity->setAsRegularContact(RsGxsId(Id),true);
requestIdDetails();
requestIdList();
}
@ -1126,7 +1123,6 @@ void IdDialog::removefromContacts()
rsIdentity->setAsRegularContact(RsGxsId(Id),false);
requestIdDetails();
requestIdList();
}