mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-23 06:31:20 -04:00
limiting calls to getIdDetails to the bare minimum
This commit is contained in:
parent
60750812d9
commit
e77b4271fc
3 changed files with 52 additions and 46 deletions
|
@ -1990,7 +1990,7 @@ void IdDialog::navigate(const RsGxsId& gxs_id)
|
||||||
std::cerr << "Cannot find item with ID " << gxs_id << " in ID list." << std::endl;
|
std::cerr << "Cannot find item with ID " << gxs_id << " in ID list." << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ui->idTreeWidget->selectionModel()->setCurrentIndex(proxy_indx,QItemSelectionModel::ClearAndSelect);
|
ui->idTreeWidget->selectionModel()->setCurrentIndex(proxy_indx,QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
||||||
ui->idTreeWidget->scrollTo(proxy_indx);//May change if model reloaded
|
ui->idTreeWidget->scrollTo(proxy_indx);//May change if model reloaded
|
||||||
ui->idTreeWidget->setFocus();
|
ui->idTreeWidget->setFocus();
|
||||||
}
|
}
|
||||||
|
@ -2679,7 +2679,7 @@ void IdDialog::recursRestoreExpandedItems_idTreeView(const QModelIndex& proxy_in
|
||||||
std::cerr << "Restoring selected path ";
|
std::cerr << "Restoring selected path ";
|
||||||
for(auto L:local_path) std::cerr << "\"" << L.toStdString() << "\" " ; std::cerr << std::endl;
|
for(auto L:local_path) std::cerr << "\"" << L.toStdString() << "\" " ; std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
ui->idTreeWidget->selectionModel()->select(proxy_index, QItemSelectionModel::Select);// | QItemSelectionModel::Rows);
|
ui->idTreeWidget->selectionModel()->select(proxy_index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ const QString RsIdentityListModel::FilterString("filtered");
|
||||||
const uint32_t MAX_INTERNAL_DATA_UPDATE_DELAY = 300 ; // re-update the internal data every 5 mins. Should properly cover sleep/wake-up changes.
|
const uint32_t MAX_INTERNAL_DATA_UPDATE_DELAY = 300 ; // re-update the internal data every 5 mins. Should properly cover sleep/wake-up changes.
|
||||||
const uint32_t MAX_NODE_UPDATE_DELAY = 10 ; // re-update the internal data every 5 mins. Should properly cover sleep/wake-up changes.
|
const uint32_t MAX_NODE_UPDATE_DELAY = 10 ; // re-update the internal data every 5 mins. Should properly cover sleep/wake-up changes.
|
||||||
|
|
||||||
static const uint32_t NODE_DETAILS_UPDATE_DELAY = 5; // update each node every 5 secs.
|
static const uint32_t ID_DETAILS_UPDATE_DELAY = 5; // update each node every 5 secs.
|
||||||
|
|
||||||
RsIdentityListModel::RsIdentityListModel(QObject *parent)
|
RsIdentityListModel::RsIdentityListModel(QObject *parent)
|
||||||
: QAbstractItemModel(parent)
|
: QAbstractItemModel(parent)
|
||||||
|
@ -420,41 +420,28 @@ void RsIdentityListModel::setFilter(FilterType filter_type, const QStringList& s
|
||||||
postMods();
|
postMods();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsIdentityListModel::requestIdentityDetails(const RsGxsId& id,RsIdentityDetails& det) const
|
|
||||||
{
|
|
||||||
if(!rsIdentity->getIdDetails(id,det))
|
|
||||||
{
|
|
||||||
mIdentityUpdateTimer->stop();
|
|
||||||
mIdentityUpdateTimer->setSingleShot(true);
|
|
||||||
mIdentityUpdateTimer->start(500);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
QVariant RsIdentityListModel::toolTipRole(const EntryIndex& fmpe,int /*column*/) const
|
QVariant RsIdentityListModel::toolTipRole(const EntryIndex& fmpe,int /*column*/) const
|
||||||
{
|
{
|
||||||
switch(fmpe.type)
|
switch(fmpe.type)
|
||||||
{
|
{
|
||||||
case ENTRY_TYPE_IDENTITY:
|
case ENTRY_TYPE_IDENTITY:
|
||||||
{
|
{
|
||||||
const RsGxsId& id(mIdentities[mCategories[fmpe.category_index].child_identity_indices[fmpe.identity_index]].id);
|
auto id_info = getIdentityInfo(fmpe);
|
||||||
|
|
||||||
if(rsIdentity->isOwnId(id))
|
if(!id_info)
|
||||||
return QVariant(tr("This identity is owned by you"));
|
|
||||||
|
|
||||||
RsIdentityDetails det;
|
|
||||||
if(!requestIdentityDetails(id,det))
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if(det.mPgpId.isNull())
|
if(rsIdentity->isOwnId(id_info->id))
|
||||||
|
return QVariant(tr("This identity is owned by you"));
|
||||||
|
|
||||||
|
if(id_info->owner.isNull())
|
||||||
return QVariant("Anonymous identity");
|
return QVariant("Anonymous identity");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RsPeerDetails dd;
|
RsPeerDetails dd;
|
||||||
rsPeers->getGPGDetails(det.mPgpId,dd);
|
rsPeers->getGPGDetails(id_info->owner,dd);
|
||||||
|
|
||||||
return QVariant("Identity owned by profile \""+ QString::fromUtf8(dd.name.c_str()) +"\" ("+QString::fromStdString(det.mPgpId.toStdString()));
|
return QVariant("Identity owned by profile \""+ QString::fromUtf8(dd.name.c_str()) +"\" ("+QString::fromStdString(id_info->owner.toStdString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -565,13 +552,8 @@ QVariant RsIdentityListModel::foregroundRole(const EntryIndex& e, int /*col*/) c
|
||||||
auto it = getIdentityInfo(e);
|
auto it = getIdentityInfo(e);
|
||||||
if(!it)
|
if(!it)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
RsGxsId id(it->id);
|
|
||||||
RsIdentityDetails det;
|
|
||||||
|
|
||||||
if(!requestIdentityDetails(id,det))
|
if(it->flags & RS_IDENTITY_FLAGS_IS_DEPRECATED)
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
if(det.mFlags & RS_IDENTITY_FLAGS_IS_DEPRECATED)
|
|
||||||
return QVariant(QColor(Qt::red));
|
return QVariant(QColor(Qt::red));
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -658,27 +640,22 @@ QVariant RsIdentityListModel::displayRole(const EntryIndex& e, int col) const
|
||||||
if(!idinfo)
|
if(!idinfo)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
RsIdentityDetails det;
|
|
||||||
|
|
||||||
if(!requestIdentityDetails(idinfo->id,det))
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
#ifdef DEBUG_MODEL_INDEX
|
#ifdef DEBUG_MODEL_INDEX
|
||||||
std::cerr << profile->profile_info.name.c_str() ;
|
std::cerr << profile->profile_info.name.c_str() ;
|
||||||
#endif
|
#endif
|
||||||
switch(col)
|
switch(col)
|
||||||
{
|
{
|
||||||
case COLUMN_THREAD_NAME: return QVariant(QString::fromUtf8(det.mNickname.c_str()));
|
case COLUMN_THREAD_NAME: return QVariant(QString::fromUtf8(idinfo->nickname.c_str()));
|
||||||
case COLUMN_THREAD_ID: return QVariant(QString::fromStdString(det.mId.toStdString()) );
|
case COLUMN_THREAD_ID: return QVariant(QString::fromStdString(idinfo->id.toStdString()) );
|
||||||
case COLUMN_THREAD_OWNER_NAME: if(det.mPgpId.isNull())
|
case COLUMN_THREAD_OWNER_NAME: if(idinfo->owner.isNull())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
else
|
else
|
||||||
return QVariant(QString::fromStdString(rsPeers->getGPGName(det.mPgpId)) );
|
return QVariant(QString::fromStdString(rsPeers->getGPGName(idinfo->owner)) );
|
||||||
|
|
||||||
case COLUMN_THREAD_OWNER_ID: if(det.mPgpId.isNull())
|
case COLUMN_THREAD_OWNER_ID: if(idinfo->owner.isNull())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
else
|
else
|
||||||
return QVariant(QString::fromStdString(det.mPgpId.toStdString()) );
|
return QVariant(QString::fromStdString(idinfo->owner.toStdString()) );
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -720,7 +697,23 @@ const RsIdentityListModel::HierarchicalIdentityInformation *RsIdentityListModel:
|
||||||
return NULL ;
|
return NULL ;
|
||||||
|
|
||||||
if(e.identity_index < mCategories[e.category_index].child_identity_indices.size())
|
if(e.identity_index < mCategories[e.category_index].child_identity_indices.size())
|
||||||
return &mIdentities[mCategories[e.category_index].child_identity_indices[e.identity_index]];
|
{
|
||||||
|
auto& it(mIdentities[mCategories[e.category_index].child_identity_indices[e.identity_index]]);
|
||||||
|
rstime_t now = time(nullptr);
|
||||||
|
|
||||||
|
if(now > it.last_update_TS + ID_DETAILS_UPDATE_DELAY)
|
||||||
|
{
|
||||||
|
RsIdentityDetails det;
|
||||||
|
if(rsIdentity->getIdDetails(it.id,det))
|
||||||
|
{
|
||||||
|
it.last_update_TS = now;
|
||||||
|
it.nickname = det.mNickname;
|
||||||
|
it.owner = det.mPgpId;
|
||||||
|
it.flags = det.mFlags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ⁢
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RsErr() << "Inconsistent identity index!" ;
|
RsErr() << "Inconsistent identity index!" ;
|
||||||
|
@ -747,8 +740,15 @@ QVariant RsIdentityListModel::decorationRole(const EntryIndex& entry,int col) co
|
||||||
else if(col == COLUMN_THREAD_NAME)
|
else if(col == COLUMN_THREAD_NAME)
|
||||||
{
|
{
|
||||||
QPixmap sslAvatar;
|
QPixmap sslAvatar;
|
||||||
AvatarDefs::getAvatarFromGxsId(hn->id, sslAvatar);
|
|
||||||
|
|
||||||
|
if(! AvatarDefs::getAvatarFromGxsId(hn->id, sslAvatar))
|
||||||
|
{
|
||||||
|
mIdentityUpdateTimer->stop();
|
||||||
|
mIdentityUpdateTimer->setSingleShot(true);
|
||||||
|
mIdentityUpdateTimer->start(500);
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
else
|
||||||
return QVariant(QIcon(sslAvatar));
|
return QVariant(QIcon(sslAvatar));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -863,6 +863,7 @@ void RsIdentityListModel::setIdentities(const std::list<RsGroupMetaData>& identi
|
||||||
{
|
{
|
||||||
HierarchicalIdentityInformation idinfo;
|
HierarchicalIdentityInformation idinfo;
|
||||||
idinfo.id = RsGxsId(id.mGroupId);
|
idinfo.id = RsGxsId(id.mGroupId);
|
||||||
|
idinfo.last_update_TS = 0;// forces update
|
||||||
|
|
||||||
if(rsIdentity->isOwnId(idinfo.id))
|
if(rsIdentity->isOwnId(idinfo.id))
|
||||||
mCategories[CATEGORY_OWN].child_identity_indices.push_back(mIdentities.size());
|
mCategories[CATEGORY_OWN].child_identity_indices.push_back(mIdentities.size());
|
||||||
|
|
|
@ -79,9 +79,16 @@ public:
|
||||||
QString category_name;
|
QString category_name;
|
||||||
std::vector<uint32_t> child_identity_indices; // index in the array of hierarchical profiles
|
std::vector<uint32_t> child_identity_indices; // index in the array of hierarchical profiles
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This stores all the info that is useful avoiding a call to the more expensive getIdDetails()
|
||||||
|
//
|
||||||
struct HierarchicalIdentityInformation
|
struct HierarchicalIdentityInformation
|
||||||
{
|
{
|
||||||
|
rstime_t last_update_TS;
|
||||||
RsGxsId id;
|
RsGxsId id;
|
||||||
|
RsPgpId owner;
|
||||||
|
uint32_t flags;
|
||||||
|
std::string nickname;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This structure encodes the position of a node in the hierarchy. The type tells which of the index fields are valid.
|
// This structure encodes the position of a node in the hierarchy. The type tells which of the index fields are valid.
|
||||||
|
@ -190,8 +197,6 @@ private:
|
||||||
void *getChildRef(void *ref,int row) const;
|
void *getChildRef(void *ref,int row) const;
|
||||||
int getChildrenCount(void *ref) const;
|
int getChildrenCount(void *ref) const;
|
||||||
|
|
||||||
bool requestIdentityDetails(const RsGxsId& id,RsIdentityDetails& det) const;
|
|
||||||
|
|
||||||
static bool convertIndexToInternalId(const EntryIndex& e,quintptr& ref);
|
static bool convertIndexToInternalId(const EntryIndex& e,quintptr& ref);
|
||||||
static bool convertInternalIdToIndex(quintptr ref, EntryIndex& e);
|
static bool convertInternalIdToIndex(quintptr ref, EntryIndex& e);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue