From 791f5fe886d8b45befffac2f9d460643e6b99421 Mon Sep 17 00:00:00 2001 From: defnax Date: Tue, 13 Oct 2015 02:18:41 +0200 Subject: [PATCH] Fixed ID Details Dialog with Reputation --- .../src/gui/Identity/IdDetailsDialog.cpp | 192 +++++++---- .../src/gui/Identity/IdDetailsDialog.h | 8 +- .../src/gui/Identity/IdDetailsDialog.ui | 315 +++++++----------- 3 files changed, 245 insertions(+), 270 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdDetailsDialog.cpp b/retroshare-gui/src/gui/Identity/IdDetailsDialog.cpp index 910a9408d..57e83c1b4 100644 --- a/retroshare-gui/src/gui/Identity/IdDetailsDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDetailsDialog.cpp @@ -26,9 +26,11 @@ #include "gui/common/UIStateHelper.h" #include +#include +// Data Requests. #define IDDETAILSDIALOG_IDDETAILS 1 - +#define IDDETAILSDIALOG_REPLIST 2 /****** * #define ID_DEBUG 1 *****/ @@ -52,18 +54,9 @@ IdDetailsDialog::IdDetailsDialog(const RsGxsGroupId& id, QWidget *parent) : mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_GpgName); mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_Type); mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_LastUsed); - mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->toolButton_Reputation); - mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->line_RatingOverall); - mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->line_RatingImplicit); - mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->line_RatingOwn); - mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->line_RatingPeers); - mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->repModButton); - mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->repMod_Accept); - mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->repMod_Ban); - mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->repMod_Negative); - mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->repMod_Positive); - mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->repMod_Custom); - mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->repMod_spinBox); + mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->ownOpinion_CB); + mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->overallOpinion_TF); + mStateHelper->addWidget(IDDETAILSDIALOG_IDDETAILS, ui->neighborNodesOpinion_TF); mStateHelper->addLoadPlaceholder(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_Nickname); mStateHelper->addLoadPlaceholder(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_GpgName); @@ -72,10 +65,6 @@ IdDetailsDialog::IdDetailsDialog(const RsGxsGroupId& id, QWidget *parent) : mStateHelper->addLoadPlaceholder(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_Type); mStateHelper->addLoadPlaceholder(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_LastUsed); mStateHelper->addLoadPlaceholder(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_GpgName); - mStateHelper->addLoadPlaceholder(IDDETAILSDIALOG_IDDETAILS, ui->line_RatingOverall); - mStateHelper->addLoadPlaceholder(IDDETAILSDIALOG_IDDETAILS, ui->line_RatingImplicit); - mStateHelper->addLoadPlaceholder(IDDETAILSDIALOG_IDDETAILS, ui->line_RatingOwn); - mStateHelper->addLoadPlaceholder(IDDETAILSDIALOG_IDDETAILS, ui->line_RatingPeers); mStateHelper->addClear(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_Nickname); mStateHelper->addClear(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_KeyId); @@ -83,10 +72,8 @@ IdDetailsDialog::IdDetailsDialog(const RsGxsGroupId& id, QWidget *parent) : mStateHelper->addClear(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_Type); mStateHelper->addClear(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_LastUsed); mStateHelper->addClear(IDDETAILSDIALOG_IDDETAILS, ui->lineEdit_GpgName); - mStateHelper->addClear(IDDETAILSDIALOG_IDDETAILS, ui->line_RatingOverall); - mStateHelper->addClear(IDDETAILSDIALOG_IDDETAILS, ui->line_RatingImplicit); - mStateHelper->addClear(IDDETAILSDIALOG_IDDETAILS, ui->line_RatingOwn); - mStateHelper->addClear(IDDETAILSDIALOG_IDDETAILS, ui->line_RatingPeers); + + mStateHelper->setActive(IDDETAILSDIALOG_REPLIST, false); /* Create token queue */ mIdQueue = new TokenQueue(rsIdentity->getTokenService(), this); @@ -98,9 +85,7 @@ IdDetailsDialog::IdDetailsDialog(const RsGxsGroupId& id, QWidget *parent) : //connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(changeGroup())); connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); - - // Hiding Rep Btn until that part is finished. - ui->toolButton_Reputation->setVisible(false); + connect(ui->ownOpinion_CB, SIGNAL(currentIndexChanged(int)), this, SLOT(modifyReputation())); requestIdDetails(); } @@ -141,7 +126,7 @@ void IdDetailsDialog::insertIdDetails(uint32_t token) if (!rsIdentity->getGroupData(token, datavector)) { mStateHelper->setActive(IDDETAILSDIALOG_IDDETAILS, false); - mStateHelper->clear(IDDETAILSDIALOG_IDDETAILS); + mStateHelper->clear(IDDETAILSDIALOG_REPLIST); ui->lineEdit_KeyId->setText("ERROR GETTING KEY!"); @@ -241,82 +226,111 @@ void IdDetailsDialog::insertIdDetails(uint32_t token) } else ui->lineEdit_Type->setText(tr("Anonymous identity")) ; - -// if (isOwnId) -// { -// ui->radioButton_IdYourself->setChecked(true); -// } -// else if (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) -// { -// if (data.mPgpKnown) -// { -// if (rsPeers->isGPGAccepted(data.mPgpId)) -// { -// ui->radioButton_IdFriend->setChecked(true); -// } -// else -// { -// ui->radioButton_IdFOF->setChecked(true); -// } -// } -// else -// { -// ui->radioButton_IdOther->setChecked(true); -// } -// } -// else -// { -// ui->radioButton_IdPseudo->setChecked(true); -// } - + + if (isOwnId) { - //mStateHelper->setWidgetEnabled(ui->toolButton_Reputation, false); + mStateHelper->setWidgetEnabled(ui->ownOpinion_CB, false); } else { // No Reputation yet! - //mStateHelper->setWidgetEnabled(ui->toolButton_Reputation, /*true*/ false); + mStateHelper->setWidgetEnabled(ui->ownOpinion_CB, true); } - /* now fill in the reputation information */ - ui->line_RatingOverall->setText("Overall Rating TODO"); - ui->line_RatingOwn->setText("Own Rating TODO"); +/* now fill in the reputation information */ +#ifdef SUSPENDED if (data.mPgpKnown) { - ui->line_RatingImplicit->setText("+50 Known PGP"); + ui->line_RatingImplicit->setText(tr("+50 Known PGP")); } else if (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) { - ui->line_RatingImplicit->setText("+10 UnKnown PGP"); + ui->line_RatingImplicit->setText(tr("+10 UnKnown PGP")); } else { - ui->line_RatingImplicit->setText("+5 Anon Id"); + ui->line_RatingImplicit->setText(tr("+5 Anon Id")); } - - { - QString rating = QString::number(data.mReputation.mOverallScore); - ui->line_RatingOverall->setText(rating); - } - { QString rating = QString::number(data.mReputation.mIdScore); ui->line_RatingImplicit->setText(rating); } - { - QString rating = QString::number(data.mReputation.mOwnOpinion); - ui->line_RatingOwn->setText(rating); - } +#endif + RsReputations::ReputationInfo info ; + rsReputations->getReputationInfo(RsGxsId(data.mMeta.mGroupId),info) ; + + ui->neighborNodesOpinion_TF->setText(QString::number(info.mOverallReputationScore-1.0f)); + + ui->overallOpinion_TF->setText(QString::number(info.mOverallReputationScore-1.0f) +" ("+ + ((info.mAssessment == RsReputations::ASSESSMENT_OK)? tr("OK") : tr("Banned")) +")" ) ; + + switch(info.mOwnOpinion) { - QString rating = QString::number(data.mReputation.mPeerOpinion); - ui->line_RatingPeers->setText(rating); + case RsReputations::OPINION_NEGATIVE: ui->ownOpinion_CB->setCurrentIndex(0); break ; + case RsReputations::OPINION_NEUTRAL : ui->ownOpinion_CB->setCurrentIndex(1); break ; + case RsReputations::OPINION_POSITIVE: ui->ownOpinion_CB->setCurrentIndex(2); break ; + default: + std::cerr << "Unexpected value in own opinion: " << info.mOwnOpinion << std::endl; } } +void IdDetailsDialog::modifyReputation() +{ +#ifdef ID_DEBUG + std::cerr << "IdDialog::modifyReputation()"; + std::cerr << std::endl; +#endif + + RsGxsId id(ui->lineEdit_KeyId->text().toStdString()); + + RsReputations::Opinion op ; + + switch(ui->ownOpinion_CB->currentIndex()) + { + case 0: op = RsReputations::OPINION_NEGATIVE ; break ; + case 1: op = RsReputations::OPINION_NEUTRAL ; break ; + case 2: op = RsReputations::OPINION_POSITIVE ; break ; + default: + std::cerr << "Wrong value from opinion combobox. Bug??" << std::endl; + + } + rsReputations->setOwnOpinion(id,op) ; + +#ifdef ID_DEBUG + std::cerr << "IdDialog::modifyReputation() ID: " << id << " Mod: " << mod; + std::cerr << std::endl; +#endif + +#ifdef SUSPENDED + // Cyril: apparently the old reputation system was in used here. It's based on GXS data exchange, and probably not + // very efficient because of this. + + uint32_t token; + if (!rsIdentity->submitOpinion(token, id, false, op)) + { +#ifdef ID_DEBUG + std::cerr << "IdDialog::modifyReputation() Error submitting Opinion"; + std::cerr << std::endl; +#endif + } +#endif + +#ifdef ID_DEBUG + std::cerr << "IdDialog::modifyReputation() queuingRequest(), token: " << token; + std::cerr << std::endl; +#endif + + // trigger refresh when finished. + // basic / anstype are not needed. + requestIdDetails(); + + return; +} + void IdDetailsDialog::requestIdDetails() { mIdQueue->cancelActiveRequestTokens(IDDETAILSDIALOG_IDDETAILS); @@ -342,6 +356,32 @@ void IdDetailsDialog::requestIdDetails() mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, IDDETAILSDIALOG_IDDETAILS); } +void IdDetailsDialog::requestRepList() +{ + // Removing this for the moment. + return; + + mStateHelper->setLoading(IDDETAILSDIALOG_REPLIST, true); + + mIdQueue->cancelActiveRequestTokens(IDDETAILSDIALOG_REPLIST); + + std::list groupIds; + groupIds.push_back(mId); + + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA; + + uint32_t token; + mIdQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, IDDETAILSDIALOG_REPLIST); +} + +void IdDetailsDialog::insertRepList(uint32_t token) +{ + Q_UNUSED(token) + mStateHelper->setLoading(IDDETAILSDIALOG_REPLIST, false); + mStateHelper->setActive(IDDETAILSDIALOG_REPLIST, true); +} + void IdDetailsDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) { if (queue != mIdQueue) { @@ -358,7 +398,11 @@ void IdDetailsDialog::loadRequest(const TokenQueue *queue, const TokenRequest &r case IDDETAILSDIALOG_IDDETAILS: insertIdDetails(req.mToken); break; - + + case IDDETAILSDIALOG_REPLIST: + insertRepList(req.mToken); + break; + default: std::cerr << "IdDetailsDialog::loadRequest() ERROR"; std::cerr << std::endl; diff --git a/retroshare-gui/src/gui/Identity/IdDetailsDialog.h b/retroshare-gui/src/gui/Identity/IdDetailsDialog.h index 9ff7330bf..4992297ad 100644 --- a/retroshare-gui/src/gui/Identity/IdDetailsDialog.h +++ b/retroshare-gui/src/gui/Identity/IdDetailsDialog.h @@ -46,9 +46,15 @@ public: /* TokenResponse */ void loadRequest(const TokenQueue *queue, const TokenRequest &req); -private: +private slots: + void modifyReputation(); + +private : void requestIdDetails(); void insertIdDetails(uint32_t token); + + void requestRepList(); + void insertRepList(uint32_t token); private: RsGxsGroupId mId; diff --git a/retroshare-gui/src/gui/Identity/IdDetailsDialog.ui b/retroshare-gui/src/gui/Identity/IdDetailsDialog.ui index 042922d9c..e9e57478d 100644 --- a/retroshare-gui/src/gui/Identity/IdDetailsDialog.ui +++ b/retroshare-gui/src/gui/Identity/IdDetailsDialog.ui @@ -200,206 +200,131 @@ + + + + + + + 0 + 0 + + + + Reputation + + + + + + + + <html><head/><body><p>Average opinion of neighbor nodes about this identity. Negative is bad,</p><p>positive is good. Zero is neutral.</p></body></html> + + + true + + + + + + + Your opinion: + + + + + + + Neighbor nodes: + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Your own opinion about an identity rules the visibility of that identity for yourself,</p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">and is shared among friends. A final score is calculated according to a formula that accounts your own opinion and your friends' opinions about someone:</p> +<p style="-qt-paragraph-type:empty; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> S = own_opinion * a + friends_opinion * (1-a)</p> +<p style="-qt-paragraph-type:empty; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">The factor 'a' depends on the type of ID. </p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">- anonymous IDs: </p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">- PGP-signed IDs by unknown PGP keys: a=</p> +<p style="-qt-paragraph-type:empty; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">The overall score is used in chat lobbies, forums and channels to decide on the actions to take for each specific identity:</p> +<p style="-qt-paragraph-type:empty; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">S &lt; -0.5: Posts are not stored, nor forwarded </p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">S &lt; 0.2: Posts are hidden, but still transmitted</p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">S &lt; 0.0: </p> +<p style="-qt-paragraph-type:empty; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">The overall rating is computed in such a way that it is not possible for a single person to deterministically change someone's status at neighbor nodes.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + 0 + + + + Negative + + + + ../icons/yellow_biohazard64.png../icons/yellow_biohazard64.png + + + + + Neutral + + + + + Positive + + + + + + + + <html><head/><body><p>Overall reputation score, accounting for yours and your friends'.</p><p>Negative is bad, positive is good. Zero is neutral. If the score is too low,</p><p>the identity is flagged as bad, and will be filtered out in forums, chat lobbies,</p><p>channels, etc.</p></body></html> + + + true + + + + + + + + 75 + true + + + + Overall: + + + + + + + + + + - - - 9 - - - 0 - - - 9 - - - 9 - - - - - - 0 - 0 - - - - Reputation - - - - - - - - - 75 - true - - - - Overall - - - - - - - true - - - - - - - Implicit - - - - - - - true - - - - - - - Opinion - - - - - - - true - - - - - - - Peers - - - - - - - true - - - - - - - - - Qt::NoFocus - - - Edit Reputation - - - - :/images/edit_24.png:/images/edit_24.png - - - - 24 - 24 - - - - Qt::ToolButtonTextBesideIcon - - - true - - - - - - - - - - - 0 - 0 - - - - Tweak Opinion - - - - - - Accept (+100) - - - - - - - Positive (+10) - - - - - - - Negative (-10) - - - - - - - Ban (-100) - - - - - - - - - Custom - - - - - - - -100 - - - 100 - - - - - - - - - Modify - - - - - - - - - Qt::Vertical @@ -412,7 +337,7 @@ - + 9