2013-03-15 17:02:43 -04:00
|
|
|
/*
|
|
|
|
* Retroshare Gxs Support
|
2012-11-19 17:14:45 -05:00
|
|
|
*
|
2013-03-15 17:02:43 -04:00
|
|
|
* Copyright 2012-2013 by Robert Fernie.
|
2012-11-19 17:14:45 -05:00
|
|
|
*
|
2013-03-15 17:02:43 -04:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2.1 as published by the Free Software Foundation.
|
2012-11-19 17:14:45 -05:00
|
|
|
*
|
2013-03-15 17:02:43 -04:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
2012-11-19 17:14:45 -05:00
|
|
|
*
|
2013-03-15 17:02:43 -04:00
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
#include "rshare.h"
|
2012-11-19 17:14:45 -05:00
|
|
|
#include "GxsIdTreeWidgetItem.h"
|
2014-02-02 06:25:11 -05:00
|
|
|
#include "GxsIdDetails.h"
|
2015-02-04 18:05:56 -05:00
|
|
|
#include "util/HandleRichText.h"
|
2015-10-10 21:25:06 -04:00
|
|
|
|
|
|
|
#define BANNED_IMAGE ":/icons/yellow_biohazard64.png"
|
2014-02-02 06:25:11 -05:00
|
|
|
|
2012-11-19 17:14:45 -05:00
|
|
|
/** Constructor */
|
2015-03-14 15:19:34 -04:00
|
|
|
GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, uint32_t icon_mask,QTreeWidget *parent)
|
|
|
|
: QObject(NULL), RSTreeWidgetItem(compareRole, parent), mColumn(0), mIconTypeMask(icon_mask)
|
2012-11-19 17:14:45 -05:00
|
|
|
{
|
2012-11-21 13:55:52 -05:00
|
|
|
init();
|
|
|
|
}
|
2012-11-19 17:14:45 -05:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
void GxsIdRSTreeWidgetItem::init()
|
2012-11-19 17:14:45 -05:00
|
|
|
{
|
2015-03-09 16:41:14 -04:00
|
|
|
mIdFound = false;
|
|
|
|
mRetryWhenFailed = false;
|
2016-03-09 21:49:24 -05:00
|
|
|
mBannedState = false ;
|
2012-11-19 17:14:45 -05:00
|
|
|
}
|
|
|
|
|
2014-11-26 19:55:48 -05:00
|
|
|
static void fillGxsIdRSTreeWidgetItemCallback(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &/*data*/)
|
2012-11-19 17:14:45 -05:00
|
|
|
{
|
2015-03-09 16:41:14 -04:00
|
|
|
GxsIdRSTreeWidgetItem *item = dynamic_cast<GxsIdRSTreeWidgetItem*>(object);
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
2015-02-04 18:05:56 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
QList<QIcon> icons;
|
2015-02-04 18:05:56 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
switch (type) {
|
|
|
|
case GXS_ID_DETAILS_TYPE_EMPTY:
|
|
|
|
item->processResult(true);
|
|
|
|
break;
|
2015-02-04 18:05:56 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
case GXS_ID_DETAILS_TYPE_FAILED:
|
|
|
|
item->processResult(false);
|
|
|
|
break;
|
2015-02-04 18:05:56 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
case GXS_ID_DETAILS_TYPE_LOADING:
|
|
|
|
icons.push_back(GxsIdDetails::getLoadingIcon(details.mId));
|
|
|
|
break;
|
2015-02-04 18:05:56 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
case GXS_ID_DETAILS_TYPE_DONE:
|
2015-03-14 15:19:34 -04:00
|
|
|
GxsIdDetails::getIcons(details, icons, item->iconTypeMask());
|
2015-03-09 16:41:14 -04:00
|
|
|
item->processResult(true);
|
|
|
|
break;
|
2015-10-10 21:25:06 -04:00
|
|
|
|
|
|
|
case GXS_ID_DETAILS_TYPE_BANNED:
|
2015-10-11 22:08:19 -04:00
|
|
|
icons.push_back(QIcon("BANNED_IMAGE")) ;
|
2015-10-10 21:25:06 -04:00
|
|
|
break ;
|
2015-03-09 16:41:14 -04:00
|
|
|
}
|
2015-02-04 18:05:56 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
int column = item->idColumn();
|
2015-06-24 15:27:52 -04:00
|
|
|
item->setToolTip(column, GxsIdDetails::getComment(details));
|
2015-02-04 18:05:56 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
item->setText(column, GxsIdDetails::getNameForType(type, details));
|
|
|
|
item->setData(column, Qt::UserRole, QString::fromStdString(details.mId.toStdString()));
|
|
|
|
|
|
|
|
QPixmap combinedPixmap;
|
|
|
|
if (!icons.empty()) {
|
2015-10-12 10:58:24 -04:00
|
|
|
GxsIdDetails::GenerateCombinedPixmap(combinedPixmap, icons, QFontMetricsF(item->font(item->idColumn())).height()*1.4);
|
2015-03-09 16:41:14 -04:00
|
|
|
}
|
|
|
|
item->setData(column, Qt::DecorationRole, combinedPixmap);
|
2015-06-24 15:27:52 -04:00
|
|
|
item->setAvatar(details.mAvatar);
|
2013-03-12 20:33:14 -04:00
|
|
|
}
|
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
void GxsIdRSTreeWidgetItem::setId(const RsGxsId &id, int column, bool retryWhenFailed)
|
2013-03-12 20:33:14 -04:00
|
|
|
{
|
2014-11-26 19:55:48 -05:00
|
|
|
//std::cerr << " GxsIdRSTreeWidgetItem::setId(" << id << "," << column << ")";
|
|
|
|
//std::cerr << std::endl;
|
2013-03-12 20:33:14 -04:00
|
|
|
|
2017-01-14 05:02:02 -05:00
|
|
|
if (mIdFound && mColumn == column && mId == id && (mBannedState == rsReputations->isIdentityBanned(mId)))
|
2015-03-09 16:41:14 -04:00
|
|
|
return;
|
2015-02-25 06:55:31 -05:00
|
|
|
|
2017-01-14 05:02:02 -05:00
|
|
|
mBannedState = rsReputations->isIdentityBanned(mId);
|
2015-03-09 16:41:14 -04:00
|
|
|
mIdFound = false;
|
|
|
|
mRetryWhenFailed = retryWhenFailed;
|
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
mId = id;
|
|
|
|
mColumn = column;
|
2014-11-26 19:55:48 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
startProcess();
|
|
|
|
}
|
|
|
|
|
2016-03-09 21:49:24 -05:00
|
|
|
void GxsIdRSTreeWidgetItem::updateBannedState()
|
|
|
|
{
|
2017-01-13 12:31:50 -05:00
|
|
|
if(mBannedState != rsReputations->isIdentityBanned(mId))
|
2016-03-09 21:49:24 -05:00
|
|
|
forceUpdate() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsIdRSTreeWidgetItem::forceUpdate()
|
|
|
|
{
|
|
|
|
mIdFound = false;
|
2017-01-13 12:31:50 -05:00
|
|
|
mBannedState = (rsReputations->isIdentityBanned(mId));
|
2016-03-09 21:49:24 -05:00
|
|
|
|
|
|
|
startProcess();
|
|
|
|
}
|
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
void GxsIdRSTreeWidgetItem::startProcess()
|
|
|
|
{
|
|
|
|
if (mRetryWhenFailed) {
|
|
|
|
disconnect(rApp, SIGNAL(minuteTick()), this, SLOT(startProcess()));
|
|
|
|
}
|
|
|
|
|
2014-11-26 19:55:48 -05:00
|
|
|
GxsIdDetails::process(mId, fillGxsIdRSTreeWidgetItemCallback, this);
|
2013-03-12 20:33:14 -04:00
|
|
|
}
|
2012-11-19 17:14:45 -05:00
|
|
|
|
2014-11-26 19:55:48 -05:00
|
|
|
bool GxsIdRSTreeWidgetItem::getId(RsGxsId &id)
|
2013-03-12 20:33:14 -04:00
|
|
|
{
|
|
|
|
id = mId;
|
2012-11-19 17:14:45 -05:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-09 16:41:14 -04:00
|
|
|
|
|
|
|
void GxsIdRSTreeWidgetItem::processResult(bool success)
|
|
|
|
{
|
|
|
|
mIdFound = success;
|
|
|
|
|
|
|
|
if (!mIdFound && mRetryWhenFailed) {
|
|
|
|
/* Try again */
|
|
|
|
connect(rApp, SIGNAL(minuteTick()), this, SLOT(startProcess()));
|
|
|
|
}
|
|
|
|
}
|
2015-06-24 15:27:52 -04:00
|
|
|
|
|
|
|
void GxsIdRSTreeWidgetItem::setAvatar(const RsGxsImage &avatar)
|
|
|
|
{
|
|
|
|
mAvatar = avatar;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant GxsIdRSTreeWidgetItem::data(int column, int role) const
|
|
|
|
{
|
2015-10-10 21:25:06 -04:00
|
|
|
if (column == idColumn())
|
|
|
|
{
|
|
|
|
if (role == Qt::ToolTipRole)
|
|
|
|
{
|
|
|
|
QString t = RSTreeWidgetItem::data(column, role).toString();
|
|
|
|
QImage pix;
|
|
|
|
|
2015-10-11 22:08:19 -04:00
|
|
|
if(mId.isNull())
|
|
|
|
return RSTreeWidgetItem::data(column, role);
|
2017-01-10 15:44:37 -05:00
|
|
|
else if(rsReputations->overallReputationLevel(mId) == RsReputations::REPUTATION_LOCALLY_NEGATIVE)
|
2015-10-10 21:25:06 -04:00
|
|
|
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();
|
|
|
|
|
|
|
|
QString embeddedImage;
|
|
|
|
if (RsHtml::makeEmbeddedImage(pix.scaled(QSize(4*S,4*S), Qt::KeepAspectRatio, Qt::SmoothTransformation), embeddedImage, 8*S * 8*S)) {
|
|
|
|
t = "<table><tr><td>" + embeddedImage + "</td><td>" + t + "</td></table>";
|
|
|
|
}
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RSTreeWidgetItem::data(column, role);
|
2015-06-24 15:27:52 -04:00
|
|
|
}
|