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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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-02-04 18:05:56 -05:00
|
|
|
GxsIdRSTreeWidgetItem *item = dynamic_cast<GxsIdRSTreeWidgetItem*>(object);
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString toolTip;
|
|
|
|
QList<QIcon> icons;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case GXS_ID_DETAILS_TYPE_EMPTY:
|
|
|
|
case GXS_ID_DETAILS_TYPE_FAILED:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GXS_ID_DETAILS_TYPE_LOADING:
|
|
|
|
icons.push_back(GxsIdDetails::getLoadingIcon(details.mId));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GXS_ID_DETAILS_TYPE_DONE:
|
|
|
|
GxsIdDetails::getIcons(details, icons);
|
|
|
|
break;
|
|
|
|
}
|
2015-03-07 09:27:32 -05:00
|
|
|
toolTip = GxsIdDetails::getComment(details);
|
2015-02-04 18:05:56 -05:00
|
|
|
|
|
|
|
int column = item->idColumn();
|
|
|
|
|
|
|
|
item->setText(column, GxsIdDetails::getNameForType(type, details));
|
|
|
|
item->setData(column, Qt::UserRole, QString::fromStdString(details.mId.toStdString()));
|
|
|
|
|
2015-02-22 06:52:33 -05:00
|
|
|
QPixmap combinedPixmap;
|
2015-02-04 18:05:56 -05:00
|
|
|
if (!icons.empty()) {
|
2015-02-22 06:52:33 -05:00
|
|
|
GxsIdDetails::GenerateCombinedPixmap(combinedPixmap, icons, 16);
|
2015-02-04 18:05:56 -05:00
|
|
|
}
|
2015-02-22 06:52:33 -05:00
|
|
|
item->setData(column, Qt::DecorationRole, combinedPixmap);
|
2015-02-04 18:05:56 -05:00
|
|
|
QImage pix ;
|
|
|
|
|
|
|
|
if(details.mAvatar.mSize == 0 || !pix.loadFromData(details.mAvatar.mData, details.mAvatar.mSize, "PNG"))
|
|
|
|
pix = GxsIdDetails::makeDefaultIcon(details.mId);
|
|
|
|
|
|
|
|
QString embeddedImage ;
|
|
|
|
|
|
|
|
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>" ;
|
|
|
|
|
|
|
|
item->setToolTip(column, toolTip);
|
2013-03-12 20:33:14 -04:00
|
|
|
}
|
|
|
|
|
2014-11-26 19:55:48 -05:00
|
|
|
void GxsIdRSTreeWidgetItem::setId(const RsGxsId &id, int column)
|
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-02-25 06:55:31 -05:00
|
|
|
if (mColumn == column && mId == id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
mId = id;
|
|
|
|
mColumn = column;
|
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;
|
|
|
|
}
|