simplified code in PR/630

This commit is contained in:
csoler 2017-01-15 20:56:44 +01:00
parent 7e750d3161
commit f314e7d330
2 changed files with 30 additions and 73 deletions

View File

@ -88,7 +88,7 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
ui.participantsList->setColumnHidden(COLUMN_ID,true); ui.participantsList->setColumnHidden(COLUMN_ID,true);
muteAct = new QAction(QIcon(), tr("Mute participant"), this); 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); 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); 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); 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(muteAct, SIGNAL(triggered()), this, SLOT(changePartipationState()));
connect(distantChatAct, SIGNAL(triggered()), this, SLOT(distantChatParticipant())); connect(distantChatAct, SIGNAL(triggered()), this, SLOT(distantChatParticipant()));
connect(sendMessageAct, SIGNAL(triggered()), this, SLOT(sendMessage())); connect(sendMessageAct, SIGNAL(triggered()), this, SLOT(sendMessage()));
connect(votePositiveAct, SIGNAL(triggered()), this, SLOT(voteParticipantPositive())); connect(votePositiveAct, SIGNAL(triggered()), this, SLOT(voteParticipant()));
connect(voteNeutralAct, SIGNAL(triggered()), this, SLOT(voteParticipantNeutral())); connect(voteNeutralAct, SIGNAL(triggered()), this, SLOT(voteParticipant()));
connect(banAct, SIGNAL(triggered()), this, SLOT(voteParticipantNegative())); connect(voteNegativeAct, SIGNAL(triggered()), this, SLOT(voteParticipant()));
connect(showinpeopleAct, SIGNAL(triggered()), this, SLOT(showInPeopleTab())); 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(actionSortByName, SIGNAL(triggered()), this, SLOT(sortParcipants()));
connect(actionSortByActivity, 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(muteAct);
contextMnu.addAction(votePositiveAct); contextMnu.addAction(votePositiveAct);
contextMnu.addAction(voteNeutralAct); contextMnu.addAction(voteNeutralAct);
contextMnu.addAction(banAct); contextMnu.addAction(voteNegativeAct);
contextMnu.addAction(showinpeopleAct); contextMnu.addAction(showinpeopleAct);
distantChatAct->setEnabled(false); distantChatAct->setEnabled(false);
@ -240,94 +244,49 @@ void ChatLobbyDialog::participantsTreeWidgetCustomPopupMenu(QPoint)
muteAct->setChecked(false); muteAct->setChecked(false);
votePositiveAct->setEnabled(false); votePositiveAct->setEnabled(false);
voteNeutralAct->setEnabled(false); voteNeutralAct->setEnabled(false);
banAct->setEnabled(false); voteNegativeAct->setEnabled(false);
showinpeopleAct->setEnabled(selectedItems.count()==1); showinpeopleAct->setEnabled(selectedItems.count()==1);
if(selectedItems.count()==1) if(selectedItems.count()==1)
{ {
RsGxsId nickName; RsGxsId gxsid(selectedItems.at(0)->text(COLUMN_ID).toStdString());
rsMsgs->getIdentityForChatLobby(lobbyId, nickName);
if(RsGxsId(selectedItems.at(0)->text(COLUMN_ID).toStdString())!=nickName) if(!gxsid.isNull() && !rsIdentity->isOwnId(gxsid))
{ {
distantChatAct->setEnabled(true); distantChatAct->setEnabled(true);
RsGxsId gxsid ;
dynamic_cast<GxsIdRSTreeWidgetItem*>(*selectedItems.begin())->getId(gxsid);
votePositiveAct->setEnabled(rsReputations->overallReputationLevel(gxsid) != RsReputations::REPUTATION_LOCALLY_POSITIVE); 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) ); 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); voteNegativeAct->setEnabled(rsReputations->overallReputationLevel(gxsid) != RsReputations::REPUTATION_LOCALLY_NEGATIVE);
muteAct->setEnabled(true);
if(isParticipantMuted(gxsid)) muteAct->setChecked(!isParticipantMuted(gxsid));
muteAct->setChecked(true);
} }
} }
contextMnu.exec(QCursor::pos()); contextMnu.exec(QCursor::pos());
} }
void ChatLobbyDialog::voteParticipantPositive() void ChatLobbyDialog::voteParticipant()
{ {
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems(); QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems();
if (selectedItems.isEmpty()) if (selectedItems.isEmpty())
return; return;
QList<QTreeWidgetItem*>::iterator item; 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() QAction *act = dynamic_cast<QAction*>(sender()) ;
{ if(!act)
QList<QTreeWidgetItem*> selectedItems = ui.participantsList->selectedItems(); {
if (selectedItems.isEmpty()) std::cerr << "No sender! Some bug in the code." << std::endl;
return; 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_NEUTRAL);
std::cerr << "Giving neutral opinion to GXS id " << nickname << std::endl;
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->forceUpdate();
}
} }
}
/** RsReputations::Opinion op(act->data().toUInt()) ;
* @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;
for (item = selectedItems.begin(); item != selectedItems.end(); ++item) for (item = selectedItems.begin(); item != selectedItems.end(); ++item)
{ {
RsGxsId nickname; RsGxsId nickname;
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(nickname) ; dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->getId(nickname) ;
RsGxsId gxs_id;
rsMsgs->getIdentityForChatLobby(lobbyId, gxs_id); rsReputations->setOwnOpinion(nickname, op);
// This test avoids to mute/ban your own identity std::cerr << "Giving opinion to GXS id " << nickname << " to " << op<< std::endl;
if (gxs_id!=nickname) dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->forceUpdate();
{
rsReputations->setOwnOpinion(nickname, RsReputations::OPINION_NEGATIVE);
std::cerr << "Giving negative opinion to GXS id " << nickname << std::endl;
dynamic_cast<GxsIdRSTreeWidgetItem*>(*item)->forceUpdate();
}
} }
} }

View File

@ -81,9 +81,7 @@ protected slots:
void distantChatParticipant(); void distantChatParticipant();
void participantsTreeWidgetDoubleClicked(QTreeWidgetItem *item, int column); void participantsTreeWidgetDoubleClicked(QTreeWidgetItem *item, int column);
void sendMessage(); void sendMessage();
void voteParticipantPositive(); void voteParticipant();
void voteParticipantNeutral();
void voteParticipantNegative();
private: private:
void updateParticipantsList(); void updateParticipantsList();
@ -113,7 +111,7 @@ private:
QAction *muteAct; QAction *muteAct;
QAction *votePositiveAct; QAction *votePositiveAct;
QAction *voteNeutralAct; QAction *voteNeutralAct;
QAction *banAct; QAction *voteNegativeAct;
QAction *distantChatAct; QAction *distantChatAct;
QAction *actionSortByName; QAction *actionSortByName;
QAction *actionSortByActivity; QAction *actionSortByActivity;