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 ; static const uint32_t SortRole = Qt::UserRole+1 ;
#ifdef TO_REMOVE
// quick solution for RSID_COL_VOTES sorting // quick solution for RSID_COL_VOTES sorting
class TreeWidgetItem : public QTreeWidgetItem 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(); return data(column,Qt::DisplayRole).toString().toUpper() < other.data(column,Qt::DisplayRole).toString().toUpper();
} }
}; };
#endif
/** Constructor */ /** Constructor */
IdDialog::IdDialog(QWidget *parent) IdDialog::IdDialog(QWidget *parent)
@ -233,7 +235,7 @@ IdDialog::IdDialog(QWidget *parent)
connect(ui->inviteButton, SIGNAL(clicked()), this, SLOT(sendInvite())); connect(ui->inviteButton, SIGNAL(clicked()), this, SLOT(sendInvite()));
connect(ui->editButton, SIGNAL(clicked()), this, SLOT(editIdentity())); 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(); ui->editButton->hide();
@ -247,9 +249,10 @@ IdDialog::IdDialog(QWidget *parent)
clearPerson(); clearPerson();
#ifdef TODO
/* Add filter types */ /* Add filter types */
QMenu *idTWHMenu = new QMenu(tr("Show Items"), this); QMenu *idTWHMenu = new QMenu(tr("Show Items"), this);
ui->idTreeWidget->addContextMenuMenu(idTWHMenu); ui->idTreeWidget->addContextMenuMenu(idTWHMenu);
QActionGroup *idTWHActionGroup = new QActionGroup(this); QActionGroup *idTWHActionGroup = new QActionGroup(this);
QAction *idTWHAction = new QAction(QIcon(),tr("All"), this); QAction *idTWHAction = new QAction(QIcon(),tr("All"), this);
@ -302,6 +305,7 @@ IdDialog::IdDialog(QWidget *parent)
idTWHAction->setData(RSID_FILTER_BANNED); idTWHAction->setData(RSID_FILTER_BANNED);
connect(idTWHAction, SIGNAL(toggled(bool)), this, SLOT(filterToggled(bool))); connect(idTWHAction, SIGNAL(toggled(bool)), this, SLOT(filterToggled(bool)));
idTWHMenu->addAction(idTWHAction); idTWHMenu->addAction(idTWHAction);
#endif
QAction *CreateIDAction = new QAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/person.png"),tr("Create new Identity"), this); QAction *CreateIDAction = new QAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/person.png"),tr("Create new Identity"), this);
connect(CreateIDAction, SIGNAL(triggered()), this, SLOT(addIdentity())); connect(CreateIDAction, SIGNAL(triggered()), this, SLOT(addIdentity()));
@ -1277,22 +1281,20 @@ void IdDialog::filterToggled(const bool &value)
void IdDialog::updateSelection() void IdDialog::updateSelection()
{ {
QTreeWidgetItem *item = ui->idTreeWidget->currentItem(); auto id = RsGxsGroupId(getSelectedIdentity());
RsGxsGroupId id;
if (item) { if(id != mId)
id = RsGxsGroupId(item->text(RSID_COL_KEYID).toStdString()); {
}
if (id != mId) {
mId = id; mId = id;
updateIdentity(); updateIdentity();
//updateRepList();
} }
} }
void IdDialog::updateIdList()
{
mIdListModel->updateIdentityList();
}
#ifdef TO_REMOVE
void IdDialog::updateIdList() void IdDialog::updateIdList()
{ {
//int accept = filter; //int accept = filter;
@ -1583,6 +1585,7 @@ void IdDialog::loadIdentities(const std::map<RsGxsGroupId,RsGxsIdGroup>& ids_set
filterIds(); filterIds();
updateSelection(); updateSelection();
} }
#endif
void IdDialog::updateIdentity() void IdDialog::updateIdentity()
{ {
@ -2001,18 +2004,18 @@ void IdDialog::navigate(const RsGxsId& gxs_id)
std::cerr << "IdDialog::navigate to " << gxs_id.toStdString() << std::endl; std::cerr << "IdDialog::navigate to " << gxs_id.toStdString() << std::endl;
#endif #endif
QModelIndex indx = mIdListModel->getIndexOfIdentity(gxs_id);
// in order to do this, we just select the correct ID in the ID list // in order to do this, we just select the correct ID in the ID list
if (!gxs_id.isNull()) 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(!indx.isValid())
if(select.empty())
{ {
mIdToNavigate = RsGxsGroupId(gxs_id); mIdToNavigate = RsGxsGroupId(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->setCurrentItem(*select.begin(),true); ui->idTreeWidget->selectionModel()->select(indx,QItemSelectionModel::ClearAndSelect);
} }
mIdToNavigate = RsGxsGroupId(); mIdToNavigate = RsGxsGroupId();
@ -2106,187 +2109,171 @@ void IdDialog::filterIds()
void IdDialog::IdListCustomPopupMenu( QPoint ) void IdDialog::IdListCustomPopupMenu( QPoint )
{ {
QMenu *contextMenu = new QMenu(this); QMenu *contextMenu = new QMenu(this);
std::list<RsGxsId> own_identities;
rsIdentity->getOwnIds(own_identities);
std::list<RsGxsId> own_identities; // make some stats about what's selected. If the same value is used for all selected items, it can be switched.
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. auto lst = getSelectedIdentities();
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems(); //bool root_node_present = false ;
bool one_item_owned_by_you = false ;
uint32_t n_positive_reputations = 0 ;
uint32_t n_negative_reputations = 0 ;
uint32_t n_neutral_reputations = 0 ;
uint32_t n_is_a_contact = 0 ;
uint32_t n_is_not_a_contact = 0 ;
uint32_t n_selected_items =0 ;
bool root_node_present = false ; for(auto& keyId :lst)
bool one_item_owned_by_you = false ; {
uint32_t n_positive_reputations = 0 ; //if(it == allItem || it == contactsItem || it == ownItem)
uint32_t n_negative_reputations = 0 ; //{
uint32_t n_neutral_reputations = 0 ; // root_node_present = true ;
uint32_t n_is_a_contact = 0 ; // continue ;
uint32_t n_is_not_a_contact = 0 ; //}
uint32_t n_selected_items =0 ;
for(auto& it :selected_items) //uint32_t item_flags = mIdListModel->data(RSID_COL_KEYID,Qt::UserRole).toUInt() ;
{
if(it == allItem || it == contactsItem || it == ownItem)
{
root_node_present = true ;
continue ;
}
uint32_t item_flags = it->data(RSID_COL_KEYID,Qt::UserRole).toUInt() ; if(rsIdentity->isOwnId(keyId))
one_item_owned_by_you = true ;
if(item_flags & RSID_FILTER_OWNED_BY_YOU)
one_item_owned_by_you = true ;
#ifdef ID_DEBUG #ifdef ID_DEBUG
std::cerr << " item flags = " << item_flags << std::endl; std::cerr << " item flags = " << item_flags << std::endl;
#endif #endif
RsGxsId keyId(it->text(RSID_COL_KEYID).toStdString()); RsIdentityDetails det ;
rsIdentity->getIdDetails(keyId,det) ;
RsIdentityDetails det ; switch(det.mReputation.mOwnOpinion)
rsIdentity->getIdDetails(keyId,det) ; {
case RsOpinion::NEGATIVE: ++n_negative_reputations; break;
case RsOpinion::POSITIVE: ++n_positive_reputations; break;
case RsOpinion::NEUTRAL: ++n_neutral_reputations; break;
}
switch(det.mReputation.mOwnOpinion) ++n_selected_items;
{
case RsOpinion::NEGATIVE: ++n_negative_reputations; break;
case RsOpinion::POSITIVE: ++n_positive_reputations; break;
case RsOpinion::NEUTRAL: ++n_neutral_reputations; break;
}
++n_selected_items; if(rsIdentity->isARegularContact(keyId))
++n_is_a_contact ;
else
++n_is_not_a_contact ;
}
if(rsIdentity->isARegularContact(keyId)) if(!one_item_owned_by_you)
++n_is_a_contact ; {
else QFrame *widget = new QFrame(contextMenu);
++n_is_not_a_contact ; widget->setObjectName("gradFrame"); //Use qss
} //widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}");
if(!root_node_present) // don't show menu if some of the root nodes are present // create menu header
{ QHBoxLayout *hbox = new QHBoxLayout(widget);
hbox->setMargin(0);
hbox->setSpacing(6);
if(!one_item_owned_by_you) QLabel *iconLabel = new QLabel(widget);
{ iconLabel->setObjectName("trans_Icon");
QFrame *widget = new QFrame(contextMenu); QPixmap pix = FilesDefs::getPixmapFromQtResourcePath(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5);
widget->setObjectName("gradFrame"); //Use qss iconLabel->setPixmap(pix);
//widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}"); iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width());
hbox->addWidget(iconLabel);
// create menu header QLabel *textLabel = new QLabel("<strong>" + ui->titleBarLabel->text() + "</strong>", widget);
QHBoxLayout *hbox = new QHBoxLayout(widget); textLabel->setObjectName("trans_Text");
hbox->setMargin(0); hbox->addWidget(textLabel);
hbox->setSpacing(6);
QLabel *iconLabel = new QLabel(widget); QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
iconLabel->setObjectName("trans_Icon"); hbox->addItem(spacerItem);
QPixmap pix = FilesDefs::getPixmapFromQtResourcePath(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5);
iconLabel->setPixmap(pix);
iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width());
hbox->addWidget(iconLabel);
QLabel *textLabel = new QLabel("<strong>" + ui->titleBarLabel->text() + "</strong>", widget); widget->setLayout(hbox);
textLabel->setObjectName("trans_Text");
hbox->addWidget(textLabel);
QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); QWidgetAction *widgetAction = new QWidgetAction(this);
hbox->addItem(spacerItem); widgetAction->setDefaultWidget(widget);
contextMenu->addAction(widgetAction);
widget->setLayout(hbox); if(n_selected_items == 1) // if only one item is selected, allow to chat with this item
{
if(own_identities.size() <= 1)
{
QAction *action = contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/chats.png"), tr("Chat with this person"), this, SLOT(chatIdentity()));
QWidgetAction *widgetAction = new QWidgetAction(this); if(own_identities.empty())
widgetAction->setDefaultWidget(widget); action->setEnabled(false) ;
contextMenu->addAction(widgetAction); else
action->setData(QString::fromStdString((own_identities.front()).toStdString())) ;
}
else
{
QMenu *mnu = contextMenu->addMenu(FilesDefs::getIconFromQtResourcePath(":/icons/png/chats.png"),tr("Chat with this person as...")) ;
if(n_selected_items == 1) // if only one item is selected, allow to chat with this item for(std::list<RsGxsId>::const_iterator it=own_identities.begin();it!=own_identities.end();++it)
{ {
if(own_identities.size() <= 1) RsIdentityDetails idd ;
{ rsIdentity->getIdDetails(*it,idd) ;
QAction *action = contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/chats.png"), tr("Chat with this person"), this, SLOT(chatIdentity()));
if(own_identities.empty()) QPixmap pixmap ;
action->setEnabled(false) ;
else
action->setData(QString::fromStdString((own_identities.front()).toStdString())) ;
}
else
{
QMenu *mnu = contextMenu->addMenu(FilesDefs::getIconFromQtResourcePath(":/icons/png/chats.png"),tr("Chat with this person as...")) ;
for(std::list<RsGxsId>::const_iterator it=own_identities.begin();it!=own_identities.end();++it) if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap,GxsIdDetails::SMALL))
{ pixmap = GxsIdDetails::makeDefaultIcon(*it,GxsIdDetails::SMALL) ;
RsIdentityDetails idd ;
rsIdentity->getIdDetails(*it,idd) ;
QPixmap pixmap ; QAction *action = mnu->addAction(QIcon(pixmap), QString("%1 (%2)").arg(QString::fromUtf8(idd.mNickname.c_str()), QString::fromStdString((*it).toStdString())), this, SLOT(chatIdentity()));
action->setData(QString::fromStdString((*it).toStdString())) ;
}
}
}
// always allow to send messages
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/mail/write-mail.png"), tr("Send message"), this, SLOT(sendMsg()));
if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap,GxsIdDetails::SMALL)) contextMenu->addSeparator();
pixmap = GxsIdDetails::makeDefaultIcon(*it,GxsIdDetails::SMALL) ;
QAction *action = mnu->addAction(QIcon(pixmap), QString("%1 (%2)").arg(QString::fromUtf8(idd.mNickname.c_str()), QString::fromStdString((*it).toStdString())), this, SLOT(chatIdentity())); if(n_is_a_contact == 0)
action->setData(QString::fromStdString((*it).toStdString())) ; contextMenu->addAction(QIcon(), tr("Add to Contacts"), this, SLOT(addtoContacts()));
}
}
}
// always allow to send messages
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/mail/write-mail.png"), tr("Send message"), this, SLOT(sendMsg()));
contextMenu->addSeparator(); if(n_is_not_a_contact == 0)
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/cancel.svg"), tr("Remove from Contacts"), this, SLOT(removefromContacts()));
if(n_is_a_contact == 0) if (n_selected_items==1)
contextMenu->addAction(QIcon(), tr("Add to Contacts"), this, SLOT(addtoContacts())); contextMenu->addAction(QIcon(""),tr("Copy identity to clipboard"),this,SLOT(copyRetroshareLink())) ;
if(n_is_not_a_contact == 0) contextMenu->addSeparator();
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/cancel.svg"), tr("Remove from Contacts"), this, SLOT(removefromContacts()));
if(n_positive_reputations == 0) // only unban when all items are banned
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/thumbs-up.png"), tr("Set positive opinion"), this, SLOT(positivePerson()));
if(n_neutral_reputations == 0) // only unban when all items are banned
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/thumbs-neutral.png"), tr("Set neutral opinion"), this, SLOT(neutralPerson()));
if(n_negative_reputations == 0)
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/thumbs-down.png"), tr("Set negative opinion"), this, SLOT(negativePerson()));
if(one_item_owned_by_you && n_selected_items==1)
{
contextMenu->addSeparator();
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_EDIT),tr("Edit identity"),this,SLOT(editIdentity())) ;
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/cancel.svg"),tr("Delete identity"),this,SLOT(removeIdentity())) ;
}
} }
if (n_selected_items==1) //contextMenu = ui->idTreeWidget->createStandardContextMenu(contextMenu);
contextMenu->addAction(QIcon(""),tr("Copy identity to clipboard"),this,SLOT(copyRetroshareLink())) ;
contextMenu->addSeparator(); contextMenu->exec(QCursor::pos());
delete contextMenu;
if(n_positive_reputations == 0) // only unban when all items are banned
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/thumbs-up.png"), tr("Set positive opinion"), this, SLOT(positivePerson()));
if(n_neutral_reputations == 0) // only unban when all items are banned
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/thumbs-neutral.png"), tr("Set neutral opinion"), this, SLOT(neutralPerson()));
if(n_negative_reputations == 0)
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/thumbs-down.png"), tr("Set negative opinion"), this, SLOT(negativePerson()));
if(one_item_owned_by_you && n_selected_items==1)
{
contextMenu->addSeparator();
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_EDIT),tr("Edit identity"),this,SLOT(editIdentity())) ;
contextMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/icons/cancel.svg"),tr("Delete identity"),this,SLOT(removeIdentity())) ;
}
}
contextMenu = ui->idTreeWidget->createStandardContextMenu(contextMenu);
contextMenu->exec(QCursor::pos());
delete contextMenu;
} }
void IdDialog::copyRetroshareLink() void IdDialog::copyRetroshareLink()
{ {
QTreeWidgetItem *item = ui->idTreeWidget->currentItem(); auto gxs_id = getSelectedIdentity();
if (!item) if (gxs_id.isNull())
{ {
std::cerr << "IdDialog::editIdentity() Invalid item"; std::cerr << "IdDialog::editIdentity() Invalid item";
std::cerr << std::endl; std::cerr << std::endl;
return; return;
} }
RsGxsId gxs_id(item->text(RSID_COL_KEYID).toStdString());
if(gxs_id.isNull())
{
std::cerr << "Null GXS id. Something went wrong." << std::endl;
return ;
}
RsIdentityDetails details ; RsIdentityDetails details ;
if(! rsIdentity->getIdDetails(gxs_id,details)) if(! rsIdentity->getIdDetails(gxs_id,details))
@ -2324,35 +2311,33 @@ void IdDialog::copyRetroshareLink()
}); });
} }
void IdDialog::chatIdentity() void IdDialog::chatIdentityItem(const QModelIndex& indx)
{ {
QTreeWidgetItem* item = ui->idTreeWidget->currentItem(); auto toGxsId = mIdListModel->getIdentity(indx);
if (!item)
{
std::cerr << __PRETTY_FUNCTION__ << " Error. Invalid item!" << std::endl;
return;
}
chatIdentityItem(item); if(toGxsId.isNull())
}
void IdDialog::chatIdentityItem(QTreeWidgetItem* item)
{
if(!item)
{ {
std::cerr << __PRETTY_FUNCTION__ << " Error. Invalid item." << std::endl; std::cerr << __PRETTY_FUNCTION__ << " Error. Invalid item." << std::endl;
return; return;
} }
chatIdentity(toGxsId);
}
std::string&& toIdString(item->text(RSID_COL_KEYID).toStdString()); void IdDialog::chatIdentity()
RsGxsId toGxsId(toIdString); {
if(toGxsId.isNull()) auto id = getSelectedIdentity();
{
std::cerr << __PRETTY_FUNCTION__ << " Error. Invalid destination id: "
<< toIdString << std::endl;
return;
}
if(id.isNull())
{
std::cerr << __PRETTY_FUNCTION__ << " Error. Invalid item!" << std::endl;
return;
}
chatIdentity(id);
}
void IdDialog::chatIdentity(const RsGxsId& toGxsId)
{
RsGxsId fromGxsId; RsGxsId fromGxsId;
QAction* action = qobject_cast<QAction*>(QObject::sender()); QAction* action = qobject_cast<QAction*>(QObject::sender());
if(!action) if(!action)
@ -2371,8 +2356,7 @@ void IdDialog::chatIdentityItem(QTreeWidgetItem* item)
if(fromGxsId.isNull()) if(fromGxsId.isNull())
{ {
std::cerr << __PRETTY_FUNCTION__ << " Error. Could not determine sender" std::cerr << __PRETTY_FUNCTION__ << " Error. Could not determine sender identity to open chat toward: " << toGxsId << std::endl;
<< " identity to open chat toward: " << toIdString << std::endl;
return; return;
} }
@ -2389,12 +2373,12 @@ void IdDialog::chatIdentityItem(QTreeWidgetItem* item)
void IdDialog::sendMsg() void IdDialog::sendMsg()
{ {
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems(); auto lst = getSelectedIdentities();
if(selected_items.empty()) if(lst.empty())
return ; 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) 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; return;
@ -2402,14 +2386,9 @@ void IdDialog::sendMsg()
if (nMsgDialog == NULL) if (nMsgDialog == NULL)
return; return;
for(auto& it : selected_items) for(const auto& id : lst)
{ nMsgDialog->addRecipient(MessageComposer::TO, id);
QTreeWidgetItem *item = it ;
std::string keyId = item->text(RSID_COL_KEYID).toStdString();
nMsgDialog->addRecipient(MessageComposer::TO, RsGxsId(keyId));
}
nMsgDialog->show(); nMsgDialog->show();
nMsgDialog->activateWindow(); nMsgDialog->activateWindow();
@ -2423,13 +2402,10 @@ QString IdDialog::inviteMessage()
void IdDialog::sendInvite() void IdDialog::sendInvite()
{ {
QTreeWidgetItem *item = ui->idTreeWidget->currentItem(); auto id = getSelectedIdentity();
if (!item)
{
return;
}
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) //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() void IdDialog::negativePerson()
{ {
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems(); auto lst = getSelectedIdentities();
for(auto& it : selected_items)
{
QTreeWidgetItem *item = it ;
std::string Id = item->text(RSID_COL_KEYID).toStdString(); for(const auto& id : lst)
rsReputations->setOwnOpinion(id, RsOpinion::NEGATIVE);
rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::NEGATIVE);
}
updateIdentity(); updateIdentity();
updateIdList(); updateIdList();
@ -2460,30 +2431,20 @@ void IdDialog::negativePerson()
void IdDialog::neutralPerson() void IdDialog::neutralPerson()
{ {
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems(); auto lst = getSelectedIdentities();
for(auto& it : selected_items)
{
QTreeWidgetItem *item = it ;
std::string Id = item->text(RSID_COL_KEYID).toStdString(); for(const auto& id : lst)
rsReputations->setOwnOpinion(id, RsOpinion::NEUTRAL);
rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::NEUTRAL);
}
updateIdentity(); updateIdentity();
updateIdList(); updateIdList();
} }
void IdDialog::positivePerson() void IdDialog::positivePerson()
{ {
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems(); auto lst = getSelectedIdentities();
for(auto& it : selected_items)
{
QTreeWidgetItem *item = it ;
std::string Id = item->text(RSID_COL_KEYID).toStdString(); for(const auto& id : lst)
rsReputations->setOwnOpinion(id, RsOpinion::POSITIVE);
rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::POSITIVE);
}
updateIdentity(); updateIdentity();
updateIdList(); updateIdList();
@ -2491,28 +2452,20 @@ void IdDialog::positivePerson()
void IdDialog::addtoContacts() void IdDialog::addtoContacts()
{ {
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems(); auto lst = getSelectedIdentities();
for(auto& it : selected_items)
{
QTreeWidgetItem *item = it ;
std::string Id = item->text(RSID_COL_KEYID).toStdString();
rsIdentity->setAsRegularContact(RsGxsId(Id),true); for(const auto& id : lst)
} rsIdentity->setAsRegularContact(id,true);
updateIdList(); updateIdList();
} }
void IdDialog::removefromContacts() void IdDialog::removefromContacts()
{ {
QList<QTreeWidgetItem *> selected_items = ui->idTreeWidget->selectedItems(); auto lst = getSelectedIdentities();
for(auto& it : selected_items)
{
QTreeWidgetItem *item = it ;
std::string Id = item->text(RSID_COL_KEYID).toStdString();
rsIdentity->setAsRegularContact(RsGxsId(Id),false); for(const auto& id : lst)
} rsIdentity->setAsRegularContact(id,false);
updateIdList(); updateIdList();
} }

View file

@ -87,8 +87,9 @@ private slots:
void removeIdentity(); void removeIdentity();
void editIdentity(); void editIdentity();
void chatIdentity(); void chatIdentity();
void chatIdentityItem(QTreeWidgetItem* item); void chatIdentityItem(const QModelIndex &indx);
void sendMsg(); void chatIdentity(const RsGxsId& toGxsId);
void sendMsg();
void copyRetroshareLink(); void copyRetroshareLink();
void on_closeInfoFrameButton_Invite_clicked(); 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 QVariant RsIdentityListModel::fontRole(const EntryIndex& e, int col) const
{ {
#ifdef DEBUG_MODEL_INDEX #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; std::cerr << " font role " << e.type << ", (" << (int)e.group_index << ","<< (int)e.profile_index << ","<< (int)e.node_index << ") col="<< col<<": " << std::endl;
#endif #endif
#ifdef TODO
int status = onlineRole(e,col).toInt(); int status = onlineRole(e,col).toInt();
switch (status) switch (status)
@ -481,6 +498,8 @@ QVariant RsIdentityListModel::fontRole(const EntryIndex& e, int col) const
default: default:
return QVariant(); return QVariant();
} }
#endif
return QVariant();
} }
QVariant RsIdentityListModel::displayRole(const EntryIndex& e, int col) const QVariant RsIdentityListModel::displayRole(const EntryIndex& e, int col) const
@ -556,7 +575,7 @@ void RsIdentityListModel::checkInternalData(bool force)
rstime_t now = time(NULL); rstime_t now = time(NULL);
if( (mLastInternalDataUpdate + MAX_INTERNAL_DATA_UPDATE_DELAY < now) || force) if( (mLastInternalDataUpdate + MAX_INTERNAL_DATA_UPDATE_DELAY < now) || force)
updateInternalData(); updateIdentityList();
} }
const RsIdentityListModel::HierarchicalCategoryInformation *RsIdentityListModel::getCategoryInfo(const EntryIndex& e) const 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]() RsThread::async([this]()
{ {

View file

@ -99,7 +99,9 @@ public:
}; };
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;} 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 ; static const QString FilterString ;
@ -140,16 +142,6 @@ private:
bool isCategoryExpanded(const EntryIndex& e) const; bool isCategoryExpanded(const EntryIndex& e) const;
void checkIdentity(HierarchicalIdentityInformation& node); 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 sizeHintRole (const EntryIndex& e, int col) const;
QVariant displayRole (const EntryIndex& e, int col) const; QVariant displayRole (const EntryIndex& e, int col) const;
QVariant decorationRole(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 sortRole (const EntryIndex& e, int col) const;
QVariant fontRole (const EntryIndex& e, int col) const; QVariant fontRole (const EntryIndex& e, int col) const;
QVariant textColorRole (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; QVariant filterRole (const EntryIndex& e, int col) const;
/*! /*!
@ -176,7 +167,6 @@ signals:
void dataAboutToLoad(); void dataAboutToLoad();
private: private:
void updateInternalData();
void setIdentities(const std::list<RsGroupMetaData>& identities_meta); void setIdentities(const std::list<RsGroupMetaData>& identities_meta);
bool passesFilter(const EntryIndex &e, int column) const; bool passesFilter(const EntryIndex &e, int column) const;