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"
|
2014-02-02 06:25:11 -05:00
|
|
|
|
2012-11-19 17:14:45 -05:00
|
|
|
/** Constructor */
|
2013-03-12 20:33:14 -04:00
|
|
|
GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidget *parent)
|
2014-11-26 19:55:48 -05:00
|
|
|
: QObject(NULL), RSTreeWidgetItem(compareRole, parent), mColumn(0)
|
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
|
|
|
GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, QTreeWidgetItem *parent)
|
2014-11-26 19:55:48 -05:00
|
|
|
: QObject(NULL), RSTreeWidgetItem(compareRole, parent), mColumn(0)
|
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
|
|
|
QString toolTip;
|
|
|
|
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:
|
|
|
|
GxsIdDetails::getIcons(details, icons);
|
|
|
|
item->processResult(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
toolTip = GxsIdDetails::getComment(details);
|
2015-02-04 18:05:56 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
int column = item->idColumn();
|
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()) {
|
|
|
|
GxsIdDetails::GenerateCombinedPixmap(combinedPixmap, icons, 16);
|
|
|
|
}
|
|
|
|
item->setData(column, Qt::DecorationRole, combinedPixmap);
|
|
|
|
QImage pix ;
|
2015-02-04 18:05:56 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
if(details.mAvatar.mSize == 0 || !pix.loadFromData(details.mAvatar.mData, details.mAvatar.mSize, "PNG"))
|
|
|
|
pix = GxsIdDetails::makeDefaultIcon(details.mId);
|
2015-02-04 18:05:56 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
QString embeddedImage ;
|
2015-02-04 18:05:56 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
if(RsHtml::makeEmbeddedImage(pix.scaled(QSize(64,64),Qt::KeepAspectRatio,Qt::SmoothTransformation),embeddedImage,128*128))
|
|
|
|
toolTip = "<table><tr><td>"+embeddedImage+"</td><td>" +toolTip+ "</td></table>" ;
|
2015-02-04 18:05:56 -05:00
|
|
|
|
2015-03-09 16:41:14 -04:00
|
|
|
item->setToolTip(column, toolTip);
|
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()));
|
|
|
|
}
|
|
|
|
}
|