2011-09-05 17:19:07 -04:00
|
|
|
/****************************************************************
|
|
|
|
* This file is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010, RetroShare Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
2012-05-19 18:18:15 -04:00
|
|
|
#include <rshare.h>
|
2011-09-05 17:19:07 -04:00
|
|
|
#include <retroshare/rsstatus.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
|
|
|
#include <retroshare/rsmsgs.h>
|
|
|
|
|
|
|
|
#include "gui/notifyqt.h"
|
|
|
|
#include "gui/common/AvatarDefs.h"
|
|
|
|
#include "util/misc.h"
|
|
|
|
|
|
|
|
#include "AvatarWidget.h"
|
|
|
|
#include "ui_AvatarWidget.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
AvatarWidget::AvatarWidget(QWidget *parent) :
|
2012-05-19 18:18:15 -04:00
|
|
|
QLabel(parent), ui(new Ui::AvatarWidget)
|
2011-09-05 17:19:07 -04:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
mFlag.isOwnId = false;
|
2014-03-17 16:56:06 -04:00
|
|
|
// mFlag.isGpg = false;
|
2012-03-29 16:23:18 -04:00
|
|
|
defaultAvatar = ":/images/no_avatar_background.png";
|
2011-09-05 17:19:07 -04:00
|
|
|
|
|
|
|
setFrameType(NO_FRAME);
|
|
|
|
|
|
|
|
/* connect signals */
|
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(peerHasNewAvatar(const QString&)), this, SLOT(updateAvatar(const QString&)));
|
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(ownAvatarChanged()), this, SLOT(updateOwnAvatar()));
|
|
|
|
}
|
|
|
|
|
|
|
|
AvatarWidget::~AvatarWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2012-05-19 18:18:15 -04:00
|
|
|
QString AvatarWidget::frameState()
|
2011-09-05 17:19:07 -04:00
|
|
|
{
|
2012-05-19 18:18:15 -04:00
|
|
|
switch (mFrameType)
|
|
|
|
{
|
|
|
|
case NO_FRAME:
|
|
|
|
return "NOTHING";
|
|
|
|
case NORMAL_FRAME:
|
|
|
|
return "NORMAL";
|
|
|
|
case STATUS_FRAME:
|
|
|
|
switch (mPeerState)
|
|
|
|
{
|
|
|
|
case RS_STATUS_OFFLINE:
|
|
|
|
return "OFFLINE";
|
|
|
|
case RS_STATUS_INACTIVE:
|
|
|
|
return "INACTIVE";
|
|
|
|
case RS_STATUS_ONLINE:
|
|
|
|
return "ONLINE";
|
|
|
|
case RS_STATUS_AWAY:
|
|
|
|
return "AWAY";
|
|
|
|
case RS_STATUS_BUSY:
|
|
|
|
return "BUSY";
|
|
|
|
}
|
2011-09-05 17:19:07 -04:00
|
|
|
}
|
2012-05-19 18:18:15 -04:00
|
|
|
return "NOTHING";
|
2011-09-05 17:19:07 -04:00
|
|
|
}
|
|
|
|
|
2011-09-29 05:52:01 -04:00
|
|
|
void AvatarWidget::mouseReleaseEvent(QMouseEvent */*event*/)
|
2011-09-05 17:19:07 -04:00
|
|
|
{
|
|
|
|
if (mFlag.isOwnId) {
|
|
|
|
QByteArray ba;
|
|
|
|
if (misc::getOpenAvatarPicture(this, ba)) {
|
|
|
|
rsMsgs->setOwnAvatarData((unsigned char*)(ba.data()), ba.size()); // last char 0 included.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AvatarWidget::setFrameType(FrameType type)
|
|
|
|
{
|
|
|
|
mFrameType = type;
|
|
|
|
|
|
|
|
switch (mFrameType) {
|
|
|
|
case NO_FRAME:
|
|
|
|
disconnect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateStatus(const QString&, int)));
|
|
|
|
break;
|
|
|
|
case NORMAL_FRAME:
|
|
|
|
disconnect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateStatus(const QString&, int)));
|
|
|
|
break;
|
|
|
|
case STATUS_FRAME:
|
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateStatus(const QString&, int)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshStatus();
|
2014-03-17 16:56:06 -04:00
|
|
|
updateAvatar(QString::fromStdString(mId.toStdString()));
|
2012-05-19 18:18:15 -04:00
|
|
|
Rshare::refreshStyleSheet(this, false);
|
2011-09-05 17:19:07 -04:00
|
|
|
}
|
2014-03-17 16:56:06 -04:00
|
|
|
void AvatarWidget::setId(const RsPeerId &id)
|
2011-09-05 17:19:07 -04:00
|
|
|
{
|
2014-03-17 16:56:06 -04:00
|
|
|
mId = id;
|
|
|
|
// mPgpId = rsPeers->getGPGId(id) ;
|
|
|
|
// mFlag.isGpg = false ;
|
2011-09-05 17:19:07 -04:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
if (mId == rsPeers->getOwnId()) {
|
|
|
|
mFlag.isOwnId = true;
|
|
|
|
setToolTip(tr("Click to change your avatar"));
|
|
|
|
}
|
2011-09-05 17:19:07 -04:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
setPixmap(QPixmap());
|
2011-09-05 17:19:07 -04:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
if (id.isNull()) {
|
|
|
|
setEnabled(false);
|
|
|
|
}
|
2011-09-05 17:19:07 -04:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
refreshStatus();
|
|
|
|
updateAvatar(QString::fromStdString(mId.toStdString()));
|
2011-09-05 17:19:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AvatarWidget::setOwnId()
|
|
|
|
{
|
2014-03-17 16:56:06 -04:00
|
|
|
setId(rsPeers->getOwnId());
|
2011-09-05 17:19:07 -04:00
|
|
|
}
|
|
|
|
|
2012-03-29 16:23:18 -04:00
|
|
|
void AvatarWidget::setDefaultAvatar(const QString &avatar)
|
|
|
|
{
|
|
|
|
defaultAvatar = avatar;
|
2014-03-17 16:56:06 -04:00
|
|
|
updateAvatar(QString::fromStdString(mId.toStdString()));
|
2012-03-29 16:23:18 -04:00
|
|
|
}
|
|
|
|
|
2011-09-05 17:19:07 -04:00
|
|
|
void AvatarWidget::refreshStatus()
|
|
|
|
{
|
|
|
|
switch (mFrameType) {
|
|
|
|
case NO_FRAME:
|
|
|
|
case NORMAL_FRAME:
|
2012-05-19 18:18:15 -04:00
|
|
|
{
|
|
|
|
Rshare::refreshStyleSheet(this, false);
|
2011-09-05 17:19:07 -04:00
|
|
|
break;
|
2012-05-19 18:18:15 -04:00
|
|
|
}
|
2011-09-05 17:19:07 -04:00
|
|
|
case STATUS_FRAME:
|
2012-05-19 18:18:15 -04:00
|
|
|
{
|
|
|
|
StatusInfo statusInfo;
|
|
|
|
|
|
|
|
if (mFlag.isOwnId) {
|
|
|
|
rsStatus->getOwnStatus(statusInfo);
|
|
|
|
} else {
|
|
|
|
// No check of return value. Non existing status info is handled as offline.
|
|
|
|
rsStatus->getStatus(mId, statusInfo);
|
2011-09-05 17:19:07 -04:00
|
|
|
}
|
2014-03-17 16:56:06 -04:00
|
|
|
updateStatus(QString::fromStdString(statusInfo.id.toStdString()), statusInfo.status);
|
2011-09-05 17:19:07 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AvatarWidget::updateStatus(const QString peerId, int status)
|
|
|
|
{
|
|
|
|
if (mFrameType != STATUS_FRAME) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
if (mId.isNull()) {
|
2012-05-19 18:18:15 -04:00
|
|
|
mPeerState = status;
|
|
|
|
Rshare::refreshStyleSheet(this, false);
|
|
|
|
} else {
|
|
|
|
/* set style for status */
|
2014-03-17 16:56:06 -04:00
|
|
|
if (mId.toStdString() == peerId.toStdString()) {
|
2012-05-19 18:18:15 -04:00
|
|
|
// the peers status has changed
|
|
|
|
mPeerState = status;
|
|
|
|
setEnabled(((uint32_t) status == RS_STATUS_OFFLINE) ? false : true);
|
|
|
|
Rshare::refreshStyleSheet(this, false);
|
|
|
|
}
|
2011-09-05 17:19:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AvatarWidget::updateAvatar(const QString &peerId)
|
|
|
|
{
|
2014-03-17 16:56:06 -04:00
|
|
|
if (mId.isNull()) {
|
2011-09-05 17:19:07 -04:00
|
|
|
QPixmap avatar(defaultAvatar);
|
2012-05-19 18:18:15 -04:00
|
|
|
setPixmap(avatar);
|
2011-09-05 17:19:07 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mFlag.isOwnId) {
|
|
|
|
QPixmap avatar;
|
|
|
|
AvatarDefs::getOwnAvatar(avatar);
|
2012-05-19 18:18:15 -04:00
|
|
|
setPixmap(avatar);
|
2011-09-05 17:19:07 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
//if (mFlag.isGpg) {
|
|
|
|
// if (mId == peerId.toStdString()) {
|
|
|
|
// /* called from AvatarWidget with gpg id */
|
|
|
|
// QPixmap avatar;
|
|
|
|
// AvatarDefs::getAvatarFromGpgId(mId, avatar, defaultAvatar);
|
|
|
|
// setPixmap(avatar);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// /* Is this one of the ssl ids of the gpg id ? */
|
|
|
|
// std::list<std::string> sslIds;
|
|
|
|
// if (rsPeers->getAssociatedSSLIds(mId, sslIds) == false) {
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (std::find(sslIds.begin(), sslIds.end(), peerId.toStdString()) != sslIds.end()) {
|
|
|
|
// /* One of the ssl ids of the gpg id */
|
|
|
|
// QPixmap avatar;
|
|
|
|
// AvatarDefs::getAvatarFromGpgId(mId, avatar, defaultAvatar);
|
|
|
|
// setPixmap(avatar);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return;
|
|
|
|
//}
|
|
|
|
|
|
|
|
if (mId.toStdString() == peerId.toStdString()) {
|
2011-09-05 17:19:07 -04:00
|
|
|
QPixmap avatar;
|
2014-03-17 16:56:06 -04:00
|
|
|
AvatarDefs::getAvatarFromSslId(mId.toStdString(), avatar, defaultAvatar);
|
2012-05-19 18:18:15 -04:00
|
|
|
setPixmap(avatar);
|
2011-09-05 17:19:07 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AvatarWidget::updateOwnAvatar()
|
|
|
|
{
|
|
|
|
if (mFlag.isOwnId) {
|
2014-03-17 16:56:06 -04:00
|
|
|
updateAvatar(QString::fromStdString(mId.toStdString()));
|
2011-09-05 17:19:07 -04:00
|
|
|
}
|
|
|
|
}
|