From f7508184025d3510d7ffcf316d1bf55252ae08ae Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 10 Oct 2015 21:25:06 -0400 Subject: [PATCH] added proper icons and names for banned users --- retroshare-gui/src/gui/gxs/GxsIdChooser.cpp | 6 +++ retroshare-gui/src/gui/gxs/GxsIdDetails.cpp | 31 +++++++++++-- retroshare-gui/src/gui/gxs/GxsIdDetails.h | 3 +- .../src/gui/gxs/GxsIdTreeWidgetItem.cpp | 45 +++++++++++-------- .../gui/gxsforums/GxsForumThreadWidget.cpp | 10 ++--- 5 files changed, 67 insertions(+), 28 deletions(-) diff --git a/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp b/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp index 7fb83f131..71554f31a 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp @@ -42,6 +42,8 @@ #define TYPE_UNKNOWN_ID 3 #define TYPE_CREATE_ID 4 +#define BANNED_ICON ":/icons/yellow_biohazard64.png" + #define IDCHOOSER_REFRESH 1 //#define IDCHOOSER_DEBUG @@ -148,6 +150,10 @@ static void loadPrivateIdsCallback(GxsIdDetailsType type, const RsIdentityDetail case GXS_ID_DETAILS_TYPE_DONE: GxsIdDetails::getIcons(details, icons); break; + + case GXS_ID_DETAILS_TYPE_BANNED: + icons.push_back(QIcon(BANNED_ICON)) ; + break; } chooser->setItemData(index, QString("%1_%2").arg((type == GXS_ID_DETAILS_TYPE_DONE) ? TYPE_FOUND_ID : TYPE_UNKNOWN_ID).arg(text), ROLE_SORT); diff --git a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp index aab87ddf7..dc8667a84 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp @@ -29,6 +29,7 @@ #include #include "GxsIdDetails.h" #include "retroshare-gui/RsAutoUpdatePage.h" +#include "retroshare/rsreputations.h" #include @@ -40,6 +41,7 @@ #define IMAGE_PGPKNOWN ":/images/contact.png" #define IMAGE_PGPUNKNOWN ":/images/tags/pgp-unknown.png" #define IMAGE_ANON ":/images/tags/anon.png" +#define IMAGE_BANNED ":/icons/yellow_biohazard64.png" #define IMAGE_DEV_AMBASSADOR ":/images/tags/dev-ambassador.png" #define IMAGE_DEV_CONTRIBUTOR ":/images/tags/vote_down.png" @@ -821,6 +823,9 @@ QString GxsIdDetails::getNameForType(GxsIdDetailsType type, const RsIdentityDeta case GXS_ID_DETAILS_TYPE_DONE: return getName(details); + case GXS_ID_DETAILS_TYPE_BANNED: + return tr("[Banned]") ; + case GXS_ID_DETAILS_TYPE_FAILED: return getFailedText(details.mId); } @@ -873,7 +878,10 @@ bool GxsIdDetails::MakeIdDesc(const RsGxsId &id, bool doIcons, QString &str, QLi QString GxsIdDetails::getName(const RsIdentityDetails &details) { - QString name = QString::fromUtf8(details.mNickname.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE); + if(!rsReputations->isIdentityOk(details.mId)) + return tr("[Banned]") ; + + QString name = QString::fromUtf8(details.mNickname.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE); std::list::const_iterator it; for (it = details.mRecognTags.begin(); it != details.mRecognTags.end(); ++it) @@ -887,9 +895,18 @@ QString GxsIdDetails::getName(const RsIdentityDetails &details) QString GxsIdDetails::getComment(const RsIdentityDetails &details) { QString comment; +QString nickname ; -QString nickname = details.mNickname.empty()?tr("[Unknown]"):QString::fromUtf8(details.mNickname.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE) ; + bool banned = !rsReputations->isIdentityOk(details.mId) ; + + if(details.mNickname.empty()) + nickname = tr("[Unknown]") ; + else if(banned) + nickname = tr("[Banned]") ; + else + nickname = QString::fromUtf8(details.mNickname.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE) ; + comment = QString("%1:%2
%3:%4").arg(QApplication::translate("GxsIdDetails", "Identity name"), nickname, QApplication::translate("GxsIdDetails", "Identity Id"), @@ -903,7 +920,8 @@ QString nickname = details.mNickname.empty()?tr("[Unknown]"):QString::fromUtf8(d { /* look up real name */ std::string authorName = rsPeers->getGPGName(details.mPgpId); - comment += QString("%1 [%2]").arg(QString::fromUtf8(authorName.c_str()), QString::fromStdString(details.mPgpId.toStdString())); + + comment += QString("%1 [%2]").arg(QString::fromUtf8(authorName.c_str()), QString::fromStdString(details.mPgpId.toStdString())); } else comment += QApplication::translate("GxsIdDetails", "unknown Key"); @@ -918,6 +936,13 @@ void GxsIdDetails::getIcons(const RsIdentityDetails &details, QList &icon { QPixmap pix ; + if(!rsReputations->isIdentityOk(details.mId)) + { + icons.clear() ; + icons.push_back(QIcon(IMAGE_BANNED)) ; + return ; + } + if(icon_types & ICON_TYPE_AVATAR) { if(details.mAvatar.mSize == 0 || !pix.loadFromData(details.mAvatar.mData, details.mAvatar.mSize, "PNG")) diff --git a/retroshare-gui/src/gui/gxs/GxsIdDetails.h b/retroshare-gui/src/gui/gxs/GxsIdDetails.h index 53ce44729..3c9259ff3 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdDetails.h +++ b/retroshare-gui/src/gui/gxs/GxsIdDetails.h @@ -39,7 +39,8 @@ enum GxsIdDetailsType GXS_ID_DETAILS_TYPE_EMPTY, GXS_ID_DETAILS_TYPE_LOADING, GXS_ID_DETAILS_TYPE_DONE, - GXS_ID_DETAILS_TYPE_FAILED + GXS_ID_DETAILS_TYPE_FAILED, + GXS_ID_DETAILS_TYPE_BANNED }; typedef void (*GxsIdDetailsCallbackFunction)(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &data); diff --git a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp index 56c225d6b..2726a1376 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp @@ -25,6 +25,9 @@ #include "GxsIdTreeWidgetItem.h" #include "GxsIdDetails.h" #include "util/HandleRichText.h" +#include "retroshare/rsreputations.h" + +#define BANNED_IMAGE ":/icons/yellow_biohazard64.png" /** Constructor */ GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, uint32_t icon_mask,QTreeWidget *parent) @@ -71,6 +74,10 @@ static void fillGxsIdRSTreeWidgetItemCallback(GxsIdDetailsType type, const RsIde GxsIdDetails::getIcons(details, icons, item->iconTypeMask()); item->processResult(true); break; + + case GXS_ID_DETAILS_TYPE_BANNED: + icons.push_back(QIcon(":/icons/yellow_biohazard64.png")) ; + break ; } int column = item->idColumn(); @@ -139,28 +146,28 @@ void GxsIdRSTreeWidgetItem::setAvatar(const RsGxsImage &avatar) QVariant GxsIdRSTreeWidgetItem::data(int column, int role) const { - if (column == idColumn()) { - switch (role) { - case Qt::ToolTipRole: - { - QString t = RSTreeWidgetItem::data(column, role).toString(); + if (column == idColumn()) + { + if (role == Qt::ToolTipRole) + { + QString t = RSTreeWidgetItem::data(column, role).toString(); + QImage pix; - QImage pix; - if (mAvatar.mSize == 0 || !pix.loadFromData(mAvatar.mData, mAvatar.mSize, "PNG")) { - pix = GxsIdDetails::makeDefaultIcon(mId); - } + if(!rsReputations->isIdentityOk(mId)) + pix = QImage(BANNED_IMAGE) ; + else if (mAvatar.mSize == 0 || !pix.loadFromData(mAvatar.mData, mAvatar.mSize, "PNG")) + pix = GxsIdDetails::makeDefaultIcon(mId); - int S = QFontMetricsF(font(column)).height(); + int S = QFontMetricsF(font(column)).height(); - QString embeddedImage; - if (RsHtml::makeEmbeddedImage(pix.scaled(QSize(4*S,4*S), Qt::KeepAspectRatio, Qt::SmoothTransformation), embeddedImage, 8*S * 8*S)) { - t = "
" + embeddedImage + "" + t + "
"; - } + QString embeddedImage; + if (RsHtml::makeEmbeddedImage(pix.scaled(QSize(4*S,4*S), Qt::KeepAspectRatio, Qt::SmoothTransformation), embeddedImage, 8*S * 8*S)) { + t = "
" + embeddedImage + "" + t + "
"; + } - return t; - } - } - } + return t; + } + } - return RSTreeWidgetItem::data(column, role); + return RSTreeWidgetItem::data(column, role); } diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 8a3c1befe..f1a7d6204 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -83,7 +83,6 @@ #define ROLE_THREAD_READCHILDREN Qt::UserRole + 4 #define ROLE_THREAD_UNREADCHILDREN Qt::UserRole + 5 #define ROLE_THREAD_SORT Qt::UserRole + 6 -#define ROLE_THREAD_REDACTED Qt::UserRole + 7 #define ROLE_THREAD_COUNT 4 @@ -980,7 +979,6 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum #endif item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_STATUS, msg.mMeta.mMsgStatus); item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_MISSING, false); - item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_REDACTED, redacted); return item; } @@ -1357,9 +1355,9 @@ void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg) if(redacted) { QString extraTxt = tr("

The author of this message (with ID %1) is banned.").arg(QString::fromStdString(msg.mMeta.mAuthorId.toStdString())) ; - extraTxt += "

  • Messages from this author are not forwarded.
  • " ; - extraTxt += "
    • Messages from this author are replaced by this text.
    • " ; - ui->postText->setHtml(extraTxt); + extraTxt += "
      • Messages from this author are not forwarded.
      • " ; + extraTxt += "
      • Messages from this author are replaced by this text.
      " ; + ui->postText->setHtml(extraTxt); } else { @@ -1721,6 +1719,8 @@ void GxsForumThreadWidget::flagpersonasbad() QTreeWidgetItem *item = ui->threadTreeWidget->currentItem(); std::cerr << "Author string: \"" << item->data(COLUMN_THREAD_DATA, ROLE_THREAD_AUTHOR).toString().toStdString()<< std::endl; + std::cerr << "Messagestring: \"" << item->data(COLUMN_THREAD_DATA, ROLE_THREAD_MSGID).toString().toStdString()<< std::endl; + std::cerr << "Messagestring: \"" << item->data(COLUMN_THREAD_DATA, ROLE_THREAD_STATUS).toString().toStdString()<< std::endl; RsGxsId gxsId(item->data(COLUMN_THREAD_DATA, ROLE_THREAD_AUTHOR).toString().toStdString()); // Get Message ... then complete replyMessageData().