2018-11-08 17:34:42 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/common/AvatarDefs.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2012, Robert Fernie <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2011-09-02 06:22:44 -04:00
|
|
|
|
|
|
|
#include <QPixmap>
|
|
|
|
|
|
|
|
#include <retroshare/rsmsgs.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
2015-02-07 17:43:53 -05:00
|
|
|
#include <retroshare/rsidentity.h>
|
|
|
|
#include <gui/gxs/GxsIdDetails.h>
|
2011-09-02 06:22:44 -04:00
|
|
|
|
|
|
|
#include "AvatarDefs.h"
|
|
|
|
|
|
|
|
void AvatarDefs::getOwnAvatar(QPixmap &avatar, const QString& defaultImage)
|
|
|
|
{
|
|
|
|
unsigned char *data = NULL;
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
/* get avatar */
|
|
|
|
rsMsgs->getOwnAvatarData(data, size);
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
avatar = QPixmap(defaultImage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load image */
|
|
|
|
avatar.loadFromData(data, size, "PNG") ;
|
|
|
|
|
2017-06-24 05:38:48 -04:00
|
|
|
free(data);
|
2011-09-02 06:22:44 -04:00
|
|
|
}
|
2015-02-07 17:43:53 -05:00
|
|
|
void AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, const QString& defaultImage)
|
|
|
|
{
|
|
|
|
unsigned char *data = NULL;
|
|
|
|
int size = 0;
|
|
|
|
|
|
|
|
/* get avatar */
|
|
|
|
rsMsgs->getAvatarData(RsPeerId(sslId), data, size);
|
|
|
|
if (size == 0) {
|
|
|
|
avatar = QPixmap(defaultImage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load image */
|
|
|
|
avatar.loadFromData(data, size, "PNG") ;
|
2011-09-02 06:22:44 -04:00
|
|
|
|
2017-06-24 05:38:48 -04:00
|
|
|
free(data);
|
2015-02-07 17:43:53 -05:00
|
|
|
}
|
|
|
|
void AvatarDefs::getAvatarFromGxsId(const RsGxsId& gxsId, QPixmap &avatar, const QString& defaultImage)
|
2011-09-02 06:22:44 -04:00
|
|
|
{
|
2016-06-05 10:43:57 -04:00
|
|
|
//int size = 0;
|
2011-09-02 06:22:44 -04:00
|
|
|
|
2015-02-07 17:43:53 -05:00
|
|
|
/* get avatar */
|
|
|
|
RsIdentityDetails details ;
|
2011-09-02 06:22:44 -04:00
|
|
|
|
2015-02-07 17:43:53 -05:00
|
|
|
if(!rsIdentity->getIdDetails(gxsId, details))
|
|
|
|
{
|
|
|
|
avatar = QPixmap(defaultImage);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load image */
|
|
|
|
|
|
|
|
if(details.mAvatar.mSize == 0 || !avatar.loadFromData(details.mAvatar.mData, details.mAvatar.mSize, "PNG"))
|
|
|
|
avatar = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(gxsId));
|
2011-09-02 06:22:44 -04:00
|
|
|
}
|
|
|
|
|
2015-02-07 17:43:53 -05:00
|
|
|
void AvatarDefs::getAvatarFromGpgId(const RsPgpId& gpgId, QPixmap &avatar, const QString& defaultImage)
|
2011-09-02 06:22:44 -04:00
|
|
|
{
|
|
|
|
unsigned char *data = NULL;
|
|
|
|
int size = 0;
|
|
|
|
|
2015-02-07 17:43:53 -05:00
|
|
|
if (gpgId == rsPeers->getGPGOwnId()) {
|
2011-09-02 06:22:44 -04:00
|
|
|
/* Its me */
|
|
|
|
rsMsgs->getOwnAvatarData(data,size);
|
|
|
|
} else {
|
|
|
|
/* get the first available avatar of one of the ssl ids */
|
2014-03-17 16:56:06 -04:00
|
|
|
std::list<RsPeerId> sslIds;
|
2015-02-07 17:43:53 -05:00
|
|
|
if (rsPeers->getAssociatedSSLIds(gpgId, sslIds)) {
|
2014-03-17 16:56:06 -04:00
|
|
|
std::list<RsPeerId>::iterator sslId;
|
2014-10-21 18:33:02 -04:00
|
|
|
for (sslId = sslIds.begin(); sslId != sslIds.end(); ++sslId) {
|
2011-09-02 06:22:44 -04:00
|
|
|
rsMsgs->getAvatarData(*sslId, data, size);
|
|
|
|
if (size) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
avatar = QPixmap(defaultImage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load image */
|
|
|
|
avatar.loadFromData(data, size, "PNG") ;
|
|
|
|
|
2017-06-24 05:38:48 -04:00
|
|
|
free(data);
|
2011-09-02 06:22:44 -04:00
|
|
|
}
|