continued implementation of IdentityListModel

This commit is contained in:
csoler 2025-02-10 21:18:31 +01:00
parent 43d64bf0c5
commit 435e8ce50c
4 changed files with 209 additions and 246 deletions

View file

@ -120,6 +120,7 @@
static const uint32_t SortRole = Qt::UserRole+1 ;
#ifdef TO_REMOVE
// quick solution for RSID_COL_VOTES sorting
class TreeWidgetItem : public QTreeWidgetItem
{
@ -143,6 +144,7 @@ class TreeWidgetItem : public QTreeWidgetItem
return data(column,Qt::DisplayRole).toString().toUpper() < other.data(column,Qt::DisplayRole).toString().toUpper();
}
};
#endif
/** Constructor */
IdDialog::IdDialog(QWidget *parent)
@ -233,7 +235,7 @@ IdDialog::IdDialog(QWidget *parent)
connect(ui->inviteButton, SIGNAL(clicked()), this, SLOT(sendInvite()));
connect(ui->editButton, SIGNAL(clicked()), this, SLOT(editIdentity()));
connect( ui->idTreeWidget, &RSTreeWidget::itemDoubleClicked, this, &IdDialog::chatIdentityItem );
connect( ui->idTreeWidget, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(chatIdentityItem(QModelIndex&)) );
ui->editButton->hide();
@ -247,6 +249,7 @@ IdDialog::IdDialog(QWidget *parent)
clearPerson();
#ifdef TODO
/* Add filter types */
QMenu *idTWHMenu = new QMenu(tr("Show Items"), this);
ui->idTreeWidget->addContextMenuMenu(idTWHMenu);
@ -302,6 +305,7 @@ IdDialog::IdDialog(QWidget *parent)
idTWHAction->setData(RSID_FILTER_BANNED);
connect(idTWHAction, SIGNAL(toggled(bool)), this, SLOT(filterToggled(bool)));
idTWHMenu->addAction(idTWHAction);
#endif
QAction *CreateIDAction = new QAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/person.png"),tr("Create new Identity"), this);
connect(CreateIDAction, SIGNAL(triggered()), this, SLOT(addIdentity()));
@ -1277,22 +1281,20 @@ void IdDialog::filterToggled(const bool &value)
void IdDialog::updateSelection()
{
QTreeWidgetItem *item = ui->idTreeWidget->currentItem();
RsGxsGroupId id;
auto id = RsGxsGroupId(getSelectedIdentity());
if (item) {
id = RsGxsGroupId(item->text(RSID_COL_KEYID).toStdString());
}
if (id != mId) {
if(id != mId)
{
mId = id;
updateIdentity();
//updateRepList();
}
}
void IdDialog::updateIdList()
{
mIdListModel->updateIdentityList();
}
#ifdef TO_REMOVE
void IdDialog::updateIdList()
{
//int accept = filter;
@ -1583,6 +1585,7 @@ void IdDialog::loadIdentities(const std::map<RsGxsGroupId,RsGxsIdGroup>& ids_set
filterIds();
updateSelection();
}
#endif
void IdDialog::updateIdentity()
{
@ -2001,18 +2004,18 @@ void IdDialog::navigate(const RsGxsId& gxs_id)
std::cerr << "IdDialog::navigate to " << gxs_id.toStdString() << std::endl;
#endif
QModelIndex indx = mIdListModel->getIndexOfIdentity(gxs_id);
// in order to do this, we just select the correct ID in the ID list
if (!gxs_id.isNull())
{
QList<QTreeWidgetItem*> select = ui->idTreeWidget->findItems(QString::fromStdString(gxs_id.toStdString()),Qt::MatchExactly | Qt::MatchRecursive | Qt::MatchWrap,RSID_COL_KEYID) ;
if(select.empty())
if(!indx.isValid())
{
mIdToNavigate = RsGxsGroupId(gxs_id);
std::cerr << "Cannot find item with ID " << gxs_id << " in ID list." << std::endl;
return;
}
ui->idTreeWidget->setCurrentItem(*select.begin(),true);
ui->idTreeWidget->selectionModel()->select(indx,QItemSelectionModel::ClearAndSelect);
}
mIdToNavigate = RsGxsGroupId();
@ -2108,15 +2111,14 @@ void IdDialog::IdListCustomPopupMenu( QPoint )
{
QMenu *contextMenu = new QMenu(this);
std::list<RsGxsId> own_identities;
rsIdentity->getOwnIds(own_identities);
// make some stats about what's selected. If the same value is used for all selected items, it can be switched.
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems();
auto lst = getSelectedIdentities();
bool root_node_present = false ;
//bool root_node_present = false ;
bool one_item_owned_by_you = false ;
uint32_t n_positive_reputations = 0 ;
uint32_t n_negative_reputations = 0 ;
@ -2125,24 +2127,22 @@ void IdDialog::IdListCustomPopupMenu( QPoint )
uint32_t n_is_not_a_contact = 0 ;
uint32_t n_selected_items =0 ;
for(auto& it :selected_items)
for(auto& keyId :lst)
{
if(it == allItem || it == contactsItem || it == ownItem)
{
root_node_present = true ;
continue ;
}
//if(it == allItem || it == contactsItem || it == ownItem)
//{
// root_node_present = true ;
// continue ;
//}
uint32_t item_flags = it->data(RSID_COL_KEYID,Qt::UserRole).toUInt() ;
//uint32_t item_flags = mIdListModel->data(RSID_COL_KEYID,Qt::UserRole).toUInt() ;
if(item_flags & RSID_FILTER_OWNED_BY_YOU)
if(rsIdentity->isOwnId(keyId))
one_item_owned_by_you = true ;
#ifdef ID_DEBUG
std::cerr << " item flags = " << item_flags << std::endl;
#endif
RsGxsId keyId(it->text(RSID_COL_KEYID).toStdString());
RsIdentityDetails det ;
rsIdentity->getIdDetails(keyId,det) ;
@ -2161,9 +2161,6 @@ void IdDialog::IdListCustomPopupMenu( QPoint )
++n_is_not_a_contact ;
}
if(!root_node_present) // don't show menu if some of the root nodes are present
{
if(!one_item_owned_by_you)
{
QFrame *widget = new QFrame(contextMenu);
@ -2236,8 +2233,6 @@ void IdDialog::IdListCustomPopupMenu( QPoint )
if(n_is_not_a_contact == 0)
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/cancel.svg"), tr("Remove from Contacts"), this, SLOT(removefromContacts()));
}
if (n_selected_items==1)
contextMenu->addAction(QIcon(""),tr("Copy identity to clipboard"),this,SLOT(copyRetroshareLink())) ;
@ -2262,7 +2257,7 @@ void IdDialog::IdListCustomPopupMenu( QPoint )
}
contextMenu = ui->idTreeWidget->createStandardContextMenu(contextMenu);
//contextMenu = ui->idTreeWidget->createStandardContextMenu(contextMenu);
contextMenu->exec(QCursor::pos());
delete contextMenu;
@ -2270,20 +2265,12 @@ void IdDialog::IdListCustomPopupMenu( QPoint )
void IdDialog::copyRetroshareLink()
{
QTreeWidgetItem *item = ui->idTreeWidget->currentItem();
if (!item)
{
std::cerr << "IdDialog::editIdentity() Invalid item";
std::cerr << std::endl;
return;
}
RsGxsId gxs_id(item->text(RSID_COL_KEYID).toStdString());
auto gxs_id = getSelectedIdentity();
if (gxs_id.isNull())
{
std::cerr << "Null GXS id. Something went wrong." << std::endl;
std::cerr << "IdDialog::editIdentity() Invalid item";
std::cerr << std::endl;
return;
}
@ -2324,35 +2311,33 @@ void IdDialog::copyRetroshareLink()
});
}
void IdDialog::chatIdentityItem(const QModelIndex& indx)
{
auto toGxsId = mIdListModel->getIdentity(indx);
if(toGxsId.isNull())
{
std::cerr << __PRETTY_FUNCTION__ << " Error. Invalid item." << std::endl;
return;
}
chatIdentity(toGxsId);
}
void IdDialog::chatIdentity()
{
QTreeWidgetItem* item = ui->idTreeWidget->currentItem();
if (!item)
auto id = getSelectedIdentity();
if(id.isNull())
{
std::cerr << __PRETTY_FUNCTION__ << " Error. Invalid item!" << std::endl;
return;
}
chatIdentityItem(item);
chatIdentity(id);
}
void IdDialog::chatIdentityItem(QTreeWidgetItem* item)
void IdDialog::chatIdentity(const RsGxsId& toGxsId)
{
if(!item)
{
std::cerr << __PRETTY_FUNCTION__ << " Error. Invalid item." << std::endl;
return;
}
std::string&& toIdString(item->text(RSID_COL_KEYID).toStdString());
RsGxsId toGxsId(toIdString);
if(toGxsId.isNull())
{
std::cerr << __PRETTY_FUNCTION__ << " Error. Invalid destination id: "
<< toIdString << std::endl;
return;
}
RsGxsId fromGxsId;
QAction* action = qobject_cast<QAction*>(QObject::sender());
if(!action)
@ -2371,8 +2356,7 @@ void IdDialog::chatIdentityItem(QTreeWidgetItem* item)
if(fromGxsId.isNull())
{
std::cerr << __PRETTY_FUNCTION__ << " Error. Could not determine sender"
<< " identity to open chat toward: " << toIdString << std::endl;
std::cerr << __PRETTY_FUNCTION__ << " Error. Could not determine sender identity to open chat toward: " << toGxsId << std::endl;
return;
}
@ -2389,12 +2373,12 @@ void IdDialog::chatIdentityItem(QTreeWidgetItem* item)
void IdDialog::sendMsg()
{
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems();
auto lst = getSelectedIdentities();
if(selected_items.empty())
if(lst.empty())
return ;
if(selected_items.size() > 20)
if(lst.size() > 20)
if(QMessageBox::warning(nullptr,tr("Too many identities"),tr("<p>It is not recommended to send a message to more than 20 persons at once. Large scale diffusion of data (including friend invitations) are much more efficiently handled by forums. Click ok to proceed anyway.</p>"),QMessageBox::Ok|QMessageBox::Cancel,QMessageBox::Cancel)==QMessageBox::Cancel)
return;
@ -2402,14 +2386,9 @@ void IdDialog::sendMsg()
if (nMsgDialog == NULL)
return;
for(auto& it : selected_items)
{
QTreeWidgetItem *item = it ;
for(const auto& id : lst)
nMsgDialog->addRecipient(MessageComposer::TO, id);
std::string keyId = item->text(RSID_COL_KEYID).toStdString();
nMsgDialog->addRecipient(MessageComposer::TO, RsGxsId(keyId));
}
nMsgDialog->show();
nMsgDialog->activateWindow();
@ -2423,13 +2402,10 @@ QString IdDialog::inviteMessage()
void IdDialog::sendInvite()
{
QTreeWidgetItem *item = ui->idTreeWidget->currentItem();
if (!item)
{
return;
}
auto id = getSelectedIdentity();
RsGxsId id(ui->lineEdit_KeyId->text().toStdString());
if(id.isNull())
return;
//if ((QMessageBox::question(this, tr("Send invite?"),tr("Do you really want send a invite with your Certificate?"),QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes))== QMessageBox::Yes)
{
@ -2444,15 +2420,10 @@ void IdDialog::sendInvite()
void IdDialog::negativePerson()
{
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems();
for(auto& it : selected_items)
{
QTreeWidgetItem *item = it ;
auto lst = getSelectedIdentities();
std::string Id = item->text(RSID_COL_KEYID).toStdString();
rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::NEGATIVE);
}
for(const auto& id : lst)
rsReputations->setOwnOpinion(id, RsOpinion::NEGATIVE);
updateIdentity();
updateIdList();
@ -2460,30 +2431,20 @@ void IdDialog::negativePerson()
void IdDialog::neutralPerson()
{
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems();
for(auto& it : selected_items)
{
QTreeWidgetItem *item = it ;
auto lst = getSelectedIdentities();
std::string Id = item->text(RSID_COL_KEYID).toStdString();
rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::NEUTRAL);
}
for(const auto& id : lst)
rsReputations->setOwnOpinion(id, RsOpinion::NEUTRAL);
updateIdentity();
updateIdList();
}
void IdDialog::positivePerson()
{
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems();
for(auto& it : selected_items)
{
QTreeWidgetItem *item = it ;
auto lst = getSelectedIdentities();
std::string Id = item->text(RSID_COL_KEYID).toStdString();
rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::POSITIVE);
}
for(const auto& id : lst)
rsReputations->setOwnOpinion(id, RsOpinion::POSITIVE);
updateIdentity();
updateIdList();
@ -2491,28 +2452,20 @@ void IdDialog::positivePerson()
void IdDialog::addtoContacts()
{
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems();
for(auto& it : selected_items)
{
QTreeWidgetItem *item = it ;
std::string Id = item->text(RSID_COL_KEYID).toStdString();
auto lst = getSelectedIdentities();
rsIdentity->setAsRegularContact(RsGxsId(Id),true);
}
for(const auto& id : lst)
rsIdentity->setAsRegularContact(id,true);
updateIdList();
}
void IdDialog::removefromContacts()
{
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems();
for(auto& it : selected_items)
{
QTreeWidgetItem *item = it ;
std::string Id = item->text(RSID_COL_KEYID).toStdString();
auto lst = getSelectedIdentities();
rsIdentity->setAsRegularContact(RsGxsId(Id),false);
}
for(const auto& id : lst)
rsIdentity->setAsRegularContact(id,false);
updateIdList();
}

View file

@ -87,7 +87,8 @@ private slots:
void removeIdentity();
void editIdentity();
void chatIdentity();
void chatIdentityItem(QTreeWidgetItem* item);
void chatIdentityItem(const QModelIndex &indx);
void chatIdentity(const RsGxsId& toGxsId);
void sendMsg();
void copyRetroshareLink();
void on_closeInfoFrameButton_Invite_clicked();

View file

@ -457,12 +457,29 @@ QVariant RsIdentityListModel::sortRole(const EntryIndex& entry,int column) const
}
}
QModelIndex RsIdentityListModel::getIndexOfIdentity(const RsGxsId& id) const
{
for(uint i=0;i<mCategories.size();++i)
for(uint j=0;j<mCategories[i].child_identity_indices.size();++j)
if(mIdentities[mCategories[i].child_identity_indices[j]].id == id)
{
EntryIndex e;
e.category_index = i;
e.identity_index = j;
quintptr idx;
convertIndexToInternalId(e,idx);
return createIndex(j,0,idx);
}
return QModelIndex();
}
QVariant RsIdentityListModel::fontRole(const EntryIndex& e, int col) const
{
#ifdef DEBUG_MODEL_INDEX
std::cerr << " font role " << e.type << ", (" << (int)e.group_index << ","<< (int)e.profile_index << ","<< (int)e.node_index << ") col="<< col<<": " << std::endl;
#endif
#ifdef TODO
int status = onlineRole(e,col).toInt();
switch (status)
@ -481,6 +498,8 @@ QVariant RsIdentityListModel::fontRole(const EntryIndex& e, int col) const
default:
return QVariant();
}
#endif
return QVariant();
}
QVariant RsIdentityListModel::displayRole(const EntryIndex& e, int col) const
@ -556,7 +575,7 @@ void RsIdentityListModel::checkInternalData(bool force)
rstime_t now = time(NULL);
if( (mLastInternalDataUpdate + MAX_INTERNAL_DATA_UPDATE_DELAY < now) || force)
updateInternalData();
updateIdentityList();
}
const RsIdentityListModel::HierarchicalCategoryInformation *RsIdentityListModel::getCategoryInfo(const EntryIndex& e) const
@ -730,7 +749,7 @@ void RsIdentityListModel::setIdentities(const std::list<RsGroupMetaData>& identi
}
void RsIdentityListModel::updateInternalData()
void RsIdentityListModel::updateIdentityList()
{
RsThread::async([this]()
{

View file

@ -99,7 +99,9 @@ public:
};
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
QModelIndex getIndexOfGroup(const RsNodeGroupId& mid) const;
QModelIndex getIndexOfIdentity(const RsGxsId& id) const;
void updateIdentityList();
static const QString FilterString ;
@ -140,16 +142,6 @@ private:
bool isCategoryExpanded(const EntryIndex& e) const;
void checkIdentity(HierarchicalIdentityInformation& node);
std::map<RsPgpId,uint32_t>::const_iterator checkProfileIndex(const RsPgpId& pgp_id,
std::map<RsPgpId,uint32_t>& pgp_indices,
std::vector<HierarchicalProfileInformation>& mProfiles,
bool create);
std::map<RsPgpId,uint32_t>::const_iterator createInvalidatedProfile(const RsPgpId& pgp_id,
const RsPgpFingerprint& fpr,
std::map<RsPgpId,uint32_t>& pgp_indices,
std::vector<HierarchicalProfileInformation>& mProfiles);
QVariant sizeHintRole (const EntryIndex& e, int col) const;
QVariant displayRole (const EntryIndex& e, int col) const;
QVariant decorationRole(const EntryIndex& e, int col) const;
@ -158,7 +150,6 @@ private:
QVariant sortRole (const EntryIndex& e, int col) const;
QVariant fontRole (const EntryIndex& e, int col) const;
QVariant textColorRole (const EntryIndex& e, int col) const;
QVariant onlineRole (const EntryIndex& e, int col) const;
QVariant filterRole (const EntryIndex& e, int col) const;
/*!
@ -176,7 +167,6 @@ signals:
void dataAboutToLoad();
private:
void updateInternalData();
void setIdentities(const std::list<RsGroupMetaData>& identities_meta);
bool passesFilter(const EntryIndex &e, int column) const;