mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
simplified code in PR/630
This commit is contained in:
parent
7e750d3161
commit
f314e7d330
@ -88,7 +88,7 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
|
||||
ui.participantsList->setColumnHidden(COLUMN_ID,true);
|
||||
|
||||
muteAct = new QAction(QIcon(), tr("Mute participant"), this);
|
||||
banAct = new QAction(QIcon(":/icons/png/thumbs-down.png"), tr("Ban this person (Sets negative opinion)"), this);
|
||||
voteNegativeAct = new QAction(QIcon(":/icons/png/thumbs-down.png"), tr("Ban this person (Sets negative opinion)"), this);
|
||||
voteNeutralAct = new QAction(QIcon(":/icons/png/thumbs-neutral.png"), tr("Give neutral opinion"), this);
|
||||
votePositiveAct = new QAction(QIcon(":/icons/png/thumbs-up.png"), tr("Give positive opinion"), this);
|
||||
distantChatAct = new QAction(QIcon(":/images/chat_24.png"), tr("Start private chat"), this);
|
||||
@ -110,11 +110,15 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
|
||||
connect(muteAct, SIGNAL(triggered()), this, SLOT(changePartipationState()));
|
||||
connect(distantChatAct, SIGNAL(triggered()), this, SLOT(distantChatParticipant()));
|
||||
connect(sendMessageAct, SIGNAL(triggered()), this, SLOT(sendMessage()));
|
||||
connect(votePositiveAct, SIGNAL(triggered()), this, SLOT(voteParticipantPositive()));
|
||||
connect(voteNeutralAct, SIGNAL(triggered()), this, SLOT(voteParticipantNeutral()));
|
||||
connect(banAct, SIGNAL(triggered()), this, SLOT(voteParticipantNegative()));
|
||||
connect(votePositiveAct, SIGNAL(triggered()), this, SLOT(voteParticipant()));
|
||||
connect(voteNeutralAct, SIGNAL(triggered()), this, SLOT(voteParticipant()));
|
||||
connect(voteNegativeAct, SIGNAL(triggered()), this, SLOT(voteParticipant()));
|
||||
connect(showinpeopleAct, SIGNAL(triggered()), this, SLOT(showInPeopleTab()));
|
||||
|
||||
votePositiveAct->setData(RsReputations::OPINION_POSITIVE);
|
||||
voteNeutralAct->setData(RsReputations::OPINION_NEUTRAL);
|
||||
voteNegativeAct->setData(RsReputations::OPINION_NEGATIVE);
|
||||
|
||||
connect(actionSortByName, SIGNAL(triggered()), this, SLOT(sortParcipants()));
|
||||
connect(actionSortByActivity, SIGNAL(triggered()), this, SLOT(sortParcipants()));
|
||||
|
||||
@ -230,7 +234,7 @@ void ChatLobbyDialog::participantsTreeWidgetCustomPopupMenu(QPoint)
|
||||
contextMnu.addAction(muteAct);
|
||||
contextMnu.addAction(votePositiveAct);
|
||||
contextMnu.addAction(voteNeutralAct);
|
||||
contextMnu.addAction(banAct);
|
||||
contextMnu.addAction(voteNegativeAct);
|
||||
contextMnu.addAction(showinpeopleAct);
|
||||
|
||||
distantChatAct->setEnabled(false);
|
||||
@ -240,95 +244,50 @@ void ChatLobbyDialog::participantsTreeWidgetCustomPopupMenu(QPoint)
|
||||
muteAct->setChecked(false);
|
||||
votePositiveAct->setEnabled(false);
|
||||
voteNeutralAct->setEnabled(false);
|
||||
banAct->setEnabled(false);
|
||||
voteNegativeAct->setEnabled(false);
|
||||
showinpeopleAct->setEnabled(selectedItems.count()==1);
|
||||
if(selectedItems.count()==1)
|
||||
{
|
||||
RsGxsId nickName;
|
||||
rsMsgs->getIdentityForChatLobby(lobbyId, nickName);
|
||||
if(RsGxsId(selectedItems.at(0)->text(COLUMN_ID).toStdString())!=nickName)
|
||||
RsGxsId gxsid(selectedItems.at(0)->text(COLUMN_ID).toStdString());
|
||||
|
||||
if(!gxsid.isNull() && !rsIdentity->isOwnId(gxsid))
|
||||
{
|
||||
distantChatAct->setEnabled(true);
|
||||
RsGxsId gxsid ;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*selectedItems.begin())->getId(gxsid);
|
||||
votePositiveAct->setEnabled(rsReputations->overallReputationLevel(gxsid) != RsReputations::REPUTATION_LOCALLY_POSITIVE);
|
||||
voteNeutralAct->setEnabled((rsReputations->overallReputationLevel(gxsid) == RsReputations::REPUTATION_LOCALLY_POSITIVE) || (rsReputations->overallReputationLevel(gxsid) == RsReputations::REPUTATION_LOCALLY_NEGATIVE) );
|
||||
banAct->setEnabled(rsReputations->overallReputationLevel(gxsid) != RsReputations::REPUTATION_LOCALLY_NEGATIVE);
|
||||
muteAct->setEnabled(true);
|
||||
if(isParticipantMuted(gxsid))
|
||||
muteAct->setChecked(true);
|
||||
voteNegativeAct->setEnabled(rsReputations->overallReputationLevel(gxsid) != RsReputations::REPUTATION_LOCALLY_NEGATIVE);
|
||||
|
||||
muteAct->setChecked(!isParticipantMuted(gxsid));
|
||||
}
|
||||
}
|
||||
contextMnu.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void ChatLobbyDialog::voteParticipantPositive()
|
||||
void ChatLobbyDialog::voteParticipant()
|
||||
{
|
||||
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
|
||||
if (selectedItems.isEmpty())
|
||||
return;
|
||||
QList<QTreeWidgetItem*>::iterator item;
|
||||
for (item = selectedItems.begin(); item != selectedItems.end(); ++item)
|
||||
{
|
||||
RsGxsId nickname;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(nickname) ;
|
||||
RsGxsId gxs_id;
|
||||
rsMsgs->getIdentityForChatLobby(lobbyId, gxs_id);
|
||||
// This test avoids to mute/ban your own identity
|
||||
if (gxs_id!=nickname)
|
||||
{
|
||||
rsReputations->setOwnOpinion(nickname, RsReputations::OPINION_POSITIVE);
|
||||
std::cerr << "Giving positive opinion to GXS id " << nickname << std::endl;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->forceUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChatLobbyDialog::voteParticipantNeutral()
|
||||
{
|
||||
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
|
||||
if (selectedItems.isEmpty())
|
||||
return;
|
||||
QList<QTreeWidgetItem*>::iterator item;
|
||||
for (item = selectedItems.begin(); item != selectedItems.end(); ++item)
|
||||
QAction *act = dynamic_cast<QAction*>(sender()) ;
|
||||
if(!act)
|
||||
{
|
||||
RsGxsId nickname;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(nickname) ;
|
||||
RsGxsId gxs_id;
|
||||
rsMsgs->getIdentityForChatLobby(lobbyId, gxs_id);
|
||||
// This test avoids to mute/ban your own identity
|
||||
if (gxs_id!=nickname)
|
||||
{
|
||||
rsReputations->setOwnOpinion(nickname, RsReputations::OPINION_NEUTRAL);
|
||||
std::cerr << "Giving neutral opinion to GXS id " << nickname << std::endl;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->forceUpdate();
|
||||
std::cerr << "No sender! Some bug in the code." << std::endl;
|
||||
return ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Called when the "ban" menu is selected. Sets a negative reputation on the selected user.
|
||||
*/
|
||||
void ChatLobbyDialog::voteParticipantNegative()
|
||||
{
|
||||
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
|
||||
if (selectedItems.isEmpty())
|
||||
return;
|
||||
QList<QTreeWidgetItem*>::iterator item;
|
||||
RsReputations::Opinion op(act->data().toUInt()) ;
|
||||
|
||||
for (item = selectedItems.begin(); item != selectedItems.end(); ++item)
|
||||
{
|
||||
RsGxsId nickname;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(nickname) ;
|
||||
RsGxsId gxs_id;
|
||||
rsMsgs->getIdentityForChatLobby(lobbyId, gxs_id);
|
||||
// This test avoids to mute/ban your own identity
|
||||
if (gxs_id!=nickname)
|
||||
{
|
||||
rsReputations->setOwnOpinion(nickname, RsReputations::OPINION_NEGATIVE);
|
||||
std::cerr << "Giving negative opinion to GXS id " << nickname << std::endl;
|
||||
|
||||
rsReputations->setOwnOpinion(nickname, op);
|
||||
std::cerr << "Giving opinion to GXS id " << nickname << " to " << op<< std::endl;
|
||||
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->forceUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChatLobbyDialog::showInPeopleTab()
|
||||
|
@ -81,9 +81,7 @@ protected slots:
|
||||
void distantChatParticipant();
|
||||
void participantsTreeWidgetDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
void sendMessage();
|
||||
void voteParticipantPositive();
|
||||
void voteParticipantNeutral();
|
||||
void voteParticipantNegative();
|
||||
void voteParticipant();
|
||||
|
||||
private:
|
||||
void updateParticipantsList();
|
||||
@ -113,7 +111,7 @@ private:
|
||||
QAction *muteAct;
|
||||
QAction *votePositiveAct;
|
||||
QAction *voteNeutralAct;
|
||||
QAction *banAct;
|
||||
QAction *voteNegativeAct;
|
||||
QAction *distantChatAct;
|
||||
QAction *actionSortByName;
|
||||
QAction *actionSortByActivity;
|
||||
|
Loading…
Reference in New Issue
Block a user