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
|
|
|
#include "retroshare/rsreputations.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
2015-03-14 15:19:34 -04:00
|
|
|
GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, uint32_t icon_mask,QTreeWidgetItem *parent)
|
|
|
|
: QObject(NULL), RSTreeWidgetItem(compareRole, parent), mColumn(0), mIconTypeMask(icon_mask)
|
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;
|
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:
|
|
|
|
icons.push_back(QIcon(":/icons/yellow_biohazard64.png")) ;
|
|
|
|
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-06-27 05:14:20 -04:00
|
|
|
GxsIdDetails::GenerateCombinedPixmap(combinedPixmap, icons, QFontMetricsF(item->font(item->idColumn())).height()*1.1);
|
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
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
if (mIdFound) {
|
|
|
|
if (mColumn == column && mId == id) {
|
|
|
|
return;
|
|
|
|
}
|
2015-02-25 06:55:31 -05:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 21:41:35 -04:00
|
|
|
if(rsReputations->isIdentityBanned(mId))
|
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
|
|
|
}
|