half way through enabling GXS avatars into distant chat. Converted AvatarWidget to use a generic ChatId instead of RsPeerId. Still need to add own Id to PopupDistantChatDialog and properly compute own name.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7924 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-02-07 22:43:53 +00:00
parent 3b5644c474
commit ccee594a28
16 changed files with 207 additions and 142 deletions

View File

@ -87,8 +87,8 @@ FriendsDialog::FriendsDialog(QWidget *parent)
connect( ui.actionSet_your_Avatar, SIGNAL(triggered()), this, SLOT(getAvatar()));
connect( ui.actionSet_your_Personal_Message, SIGNAL(triggered()), this, SLOT(statusmessage()));
ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME);
ui.avatar->setOwnId();
ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME);
ui.tabWidget->setTabPosition(QTabWidget::North);
ui.tabWidget->addTab(networkView = new NetworkView(),QIcon(IMAGE_NETWORK2), tr("Network graph"));

View File

@ -58,9 +58,8 @@ void PopupChatDialog::init(const ChatId &chat_id, const QString &title)
/* Hide or show the avatar frames */
showAvatarFrame(PeerSettings->getShowAvatarFrame(chat_id));
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
ui.avatarWidget->setId(chat_id.toPeerId()); // not 100% correct, since this code is also used for distant chat
// but distance peers don't have a status anyway
ui.avatarWidget->setId(chat_id);
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
ui.ownAvatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
ui.ownAvatarWidget->setOwnId();

View File

@ -23,6 +23,8 @@
#include <retroshare/rsmsgs.h>
#include <retroshare/rspeers.h>
#include <retroshare/rsidentity.h>
#include <gui/gxs/GxsIdDetails.h>
#include "AvatarDefs.h"
@ -44,37 +46,57 @@ void AvatarDefs::getOwnAvatar(QPixmap &avatar, const QString& defaultImage)
delete[] data;
}
void AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, const QString& defaultImage)
{
unsigned char *data = NULL;
int size = 0;
void AvatarDefs::getAvatarFromSslId(const std::string& sslId, QPixmap &avatar, const QString& defaultImage)
/* get avatar */
rsMsgs->getAvatarData(RsPeerId(sslId), data, size);
if (size == 0) {
avatar = QPixmap(defaultImage);
return;
}
/* load image */
avatar.loadFromData(data, size, "PNG") ;
delete[] data;
}
void AvatarDefs::getAvatarFromGxsId(const RsGxsId& gxsId, QPixmap &avatar, const QString& defaultImage)
{
unsigned char *data = NULL;
int size = 0;
int size = 0;
/* get avatar */
rsMsgs->getAvatarData(RsPeerId(sslId), data, size);
if (size == 0) {
avatar = QPixmap(defaultImage);
return;
}
/* get avatar */
RsIdentityDetails details ;
/* load image */
avatar.loadFromData(data, size, "PNG") ;
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));
delete[] data;
}
void AvatarDefs::getAvatarFromGpgId(const std::string& gpgId, QPixmap &avatar, const QString& defaultImage)
void AvatarDefs::getAvatarFromGpgId(const RsPgpId& gpgId, QPixmap &avatar, const QString& defaultImage)
{
unsigned char *data = NULL;
int size = 0;
if (RsPgpId(gpgId) == rsPeers->getGPGOwnId()) {
if (gpgId == rsPeers->getGPGOwnId()) {
/* Its me */
rsMsgs->getOwnAvatarData(data,size);
} else {
/* get the first available avatar of one of the ssl ids */
std::list<RsPeerId> sslIds;
if (rsPeers->getAssociatedSSLIds(RsPgpId(gpgId), sslIds)) {
if (rsPeers->getAssociatedSSLIds(gpgId, sslIds)) {
std::list<RsPeerId>::iterator sslId;
for (sslId = sslIds.begin(); sslId != sslIds.end(); ++sslId) {
rsMsgs->getAvatarData(*sslId, data, size);

View File

@ -25,6 +25,8 @@
#include <string>
#include <QString>
#include <retroshare/rstypes.h>
#include <retroshare/rsgxsifacetypes.h>
#define AVATAR_DEFAULT_IMAGE ":/images/no_avatar_background.png"
@ -33,9 +35,11 @@ class QPixmap;
class AvatarDefs
{
public:
static void getOwnAvatar(QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
static void getAvatarFromSslId(const std::string& sslId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
static void getAvatarFromGpgId(const std::string& gpgId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
static void getOwnAvatar(QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
static void getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
static void getAvatarFromGpgId(const RsPgpId & gpgId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
static void getAvatarFromGxsId(const RsGxsId & gxsId, QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE);
};
#endif

View File

@ -116,138 +116,160 @@ void AvatarWidget::setFrameType(FrameType type)
break;
}
refreshStatus();
updateAvatar(QString::fromStdString(mId.toStdString()));
Rshare::refreshStyleSheet(this, false);
//refreshAvatarImage();
refreshStatus();
Rshare::refreshStyleSheet(this, false);
}
void AvatarWidget::setId(const RsPeerId &id)
void AvatarWidget::setId(const ChatId &id)
{
mId = id;
// mPgpId = rsPeers->getGPGId(id) ;
// mFlag.isGpg = false ;
if (mId == rsPeers->getOwnId()) {
mFlag.isOwnId = true;
setToolTip(tr("Click to change your avatar"));
}
setPixmap(QPixmap());
if (id.isNull()) {
if (id.isNotSet()) {
setEnabled(false);
}
refreshAvatarImage();
refreshStatus();
updateAvatar(QString::fromStdString(mId.toStdString()));
}
void AvatarWidget::setOwnId()
{
setId(rsPeers->getOwnId());
mFlag.isOwnId = true;
setToolTip(tr("Click to change your avatar"));
setId(ChatId(rsPeers->getOwnId()));
}
void AvatarWidget::setDefaultAvatar(const QString &avatar)
void AvatarWidget::setDefaultAvatar(const QString &avatar_file_name)
{
defaultAvatar = avatar;
updateAvatar(QString::fromStdString(mId.toStdString()));
defaultAvatar = avatar_file_name;
refreshAvatarImage();
}
void AvatarWidget::refreshStatus()
{
switch (mFrameType) {
case NO_FRAME:
case NORMAL_FRAME:
{
Rshare::refreshStyleSheet(this, false);
break;
}
case STATUS_FRAME:
{
StatusInfo statusInfo;
switch (mFrameType)
{
case NO_FRAME:
case NORMAL_FRAME:
{
Rshare::refreshStyleSheet(this, false);
break;
}
case STATUS_FRAME:
{
uint32_t status ;
if (mFlag.isOwnId) {
rsStatus->getOwnStatus(statusInfo);
} else {
// No check of return value. Non existing status info is handled as offline.
rsStatus->getStatus(mId, statusInfo);
}
updateStatus(QString::fromStdString(statusInfo.id.toStdString()), statusInfo.status);
break;
}
}
if(mId.isNotSet())
return ;
if (mFlag.isOwnId)
{
if(mId.isPeerId())
{
StatusInfo statusInfo;
rsStatus->getOwnStatus(statusInfo);
status = statusInfo.status ;
}
else if(mId.isGxsId())
status = RS_STATUS_ONLINE ;
else
{
std::cerr << "Unhandled chat id type in AvatarWidget::refreshStatus()" << std::endl;
return ;
}
}
else
{
// No check of return value. Non existing status info is handled as offline.
if(mId.isPeerId())
{
StatusInfo statusInfo;
rsStatus->getStatus(mId.toPeerId(), statusInfo);
status = statusInfo.status ;
}
else if(mId.isGxsId())
{
if(!rsMsgs->getDistantChatStatus(mId.toGxsId(),status))
status = RS_STATUS_OFFLINE ;
}
else
{
std::cerr << "Unhandled chat id type in AvatarWidget::refreshStatus()" << std::endl;
return ;
}
}
updateStatus(status);
break;
}
}
}
void AvatarWidget::updateStatus(const QString peerId, int status)
void AvatarWidget::updateStatus(const QString& peerId, int status)
{
if (mFrameType != STATUS_FRAME) {
return;
}
if (mId.isPeerId() && mId.toPeerId() == RsPeerId(peerId.toStdString()))
updateStatus(status) ;
}
if (mId.isNull()) {
mPeerState = status;
Rshare::refreshStyleSheet(this, false);
} else {
/* set style for status */
if (mId.toStdString() == peerId.toStdString()) {
// the peers status has changed
mPeerState = status;
setEnabled(((uint32_t) status == RS_STATUS_OFFLINE) ? false : true);
Rshare::refreshStyleSheet(this, false);
}
}
void AvatarWidget::updateStatus(int status)
{
if (mFrameType != STATUS_FRAME)
return;
mPeerState = status;
setEnabled(((uint32_t) status == RS_STATUS_OFFLINE) ? false : true);
Rshare::refreshStyleSheet(this, false);
}
void AvatarWidget::updateAvatar(const QString &peerId)
{
if (mId.isNull()) {
QPixmap avatar(defaultAvatar);
setPixmap(avatar);
return;
}
if(mId.isPeerId() && mId.toPeerId() == RsPeerId(peerId.toStdString()))
refreshAvatarImage() ;
if (mFlag.isOwnId) {
QPixmap avatar;
AvatarDefs::getOwnAvatar(avatar);
setPixmap(avatar);
return;
}
//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()) {
QPixmap avatar;
AvatarDefs::getAvatarFromSslId(mId.toStdString(), avatar, defaultAvatar);
setPixmap(avatar);
return;
}
if(mId.isGxsId() && mId.toGxsId() == RsGxsId(peerId.toStdString()))
refreshAvatarImage() ;
}
void AvatarWidget::refreshAvatarImage()
{
if (mId.isNotSet())
{
QPixmap avatar(defaultAvatar);
setPixmap(avatar);
return;
}
else if (mFlag.isOwnId && mId.isPeerId())
{
QPixmap avatar;
AvatarDefs::getOwnAvatar(avatar);
setPixmap(avatar);
return;
}
else if (mId.isPeerId())
{
QPixmap avatar;
AvatarDefs::getAvatarFromSslId(mId.toPeerId(), avatar, defaultAvatar);
setPixmap(avatar);
return;
}
else if (mId.isGxsId())
{
QPixmap avatar;
AvatarDefs::getAvatarFromGxsId(mId.toGxsId(), avatar, defaultAvatar);
setPixmap(avatar);
return;
}
else
std::cerr << "WARNING: unhandled situation in AvatarWidget::refreshAvatarImage()" << std::endl;
}
void AvatarWidget::updateOwnAvatar()
{
if (mFlag.isOwnId) {
updateAvatar(QString::fromStdString(mId.toStdString()));
}
if (mFlag.isOwnId)
refreshAvatarImage() ;
}

View File

@ -25,6 +25,7 @@
#include <QLabel>
#include <stdint.h>
#include <retroshare/rstypes.h>
#include <retroshare/rsmsgs.h>
namespace Ui {
class AvatarWidget;
@ -48,25 +49,28 @@ public:
QString frameState();
void setFrameType(FrameType type);
void setId(const RsPeerId &id) ;
void setId(const ChatId& id) ;
void setOwnId();
void setDefaultAvatar(const QString &avatar);
void setOwnId(const RsGxsId&);
void setDefaultAvatar(const QString &avatar_file_name);
protected:
void mouseReleaseEvent(QMouseEvent *event);
private slots:
void updateStatus(const QString peerId, int status);
void updateStatus(const QString& peerId, int status);
void updateAvatar(const QString& peerId);
void updateOwnAvatar();
void updateOwnAvatar();
private:
void refreshStatus();
void refreshAvatarImage() ;
void refreshStatus();
void updateStatus(int status);
QString defaultAvatar;
Ui::AvatarWidget *ui;
RsPeerId mId;
ChatId mId;
struct {
bool isOwnId : 1;

View File

@ -562,7 +562,7 @@ void FriendList::updateAvatar(const QString& id)
if ((*it)->type() == TYPE_SSL && id == (*it)->data(COLUMN_DATA, ROLE_ID).toString()) {
if ((*it)->parent() != NULL && (*it)->parent()->type() == TYPE_GPG) {
QPixmap avatar;
AvatarDefs::getAvatarFromSslId(id.toStdString(), avatar);
AvatarDefs::getAvatarFromSslId(RsPeerId(id.toStdString()), avatar);
QIcon avatar_icon(avatar);
(*it)->parent()->setIcon(COLUMN_AVATAR, avatar_icon);
}
@ -1145,7 +1145,7 @@ void FriendList::insertPeers()
// only set the avatar image the first time, or when it changed
// otherwise getAvatarFromSslId sends request packages to peers.
QPixmap avatar;
AvatarDefs::getAvatarFromSslId(bestSslId.toStdString(), avatar);
AvatarDefs::getAvatarFromSslId(bestSslId, avatar);
QIcon avatar_icon(avatar);
gpgItem->setIcon(COLUMN_AVATAR, avatar_icon);
}

View File

@ -189,7 +189,7 @@ void ConfCertDialog::load()
if (!detail.isOnlyGPGdetail)
{
ui.avatar->setId(peerId);
ui.avatar->setId(ChatId(peerId));
ui.loc->setText(QString::fromUtf8(detail.location.c_str()));
// Dont Show a timestamp in RS calculate the day

View File

@ -64,7 +64,7 @@ ChatMsgItem::ChatMsgItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &pe
connect(NotifyQt::getInstance(), SIGNAL(peerHasNewAvatar(const QString&)), this, SLOT(updateAvatar(const QString&)));
avatar->setId(mPeerId);
avatar->setId(ChatId(mPeerId));
updateItemStatic();
updateItem();

View File

@ -80,18 +80,32 @@ void MsgItem::updateItemStatic()
if (!rsMsgs->getMessage(mMsgId, mi))
return;
/* get peer Id */
mPeerId = mi.rspeerid_srcId;
/* get peer Id */
if(mi.msgflags & RS_MSG_SIGNED)
mPeerId = ChatId(mi.rsgxsid_srcId);
else
mPeerId = ChatId(mi.rspeerid_srcId);
avatar->setId(mPeerId);
QString title;
QString srcName;
if ((mi.msgflags & RS_MSG_SYSTEM) && mi.rspeerid_srcId == rsPeers->getOwnId()) {
QString srcName;
if ((mi.msgflags & RS_MSG_SYSTEM) && mi.rspeerid_srcId == rsPeers->getOwnId())
srcName = "RetroShare";
} else {
srcName = QString::fromUtf8(rsPeers->getPeerName(mi.rspeerid_srcId).c_str());
}
else
{
if(mi.msgflags & RS_MSG_SIGNED)
{
RsIdentityDetails details ;
rsIdentity->getIdDetails(mi.rsgxsid_srcId, details) ;
srcName = QString::fromUtf8(details.mNickname.c_str());
}
else
srcName = QString::fromUtf8(rsPeers->getPeerName(mi.rspeerid_srcId).c_str());
}
timestampLabel->setText(DateTime::formatLongDateTime(mi.ts));
@ -102,7 +116,7 @@ void MsgItem::updateItemStatic()
else
{
/* subject */
uint32_t box = mi.msgflags & RS_MSG_BOXMASK;
uint32_t box = mi.msgflags & RS_MSG_BOXMASK;
switch(box)
{
case RS_MSG_SENTBOX:

View File

@ -58,7 +58,7 @@ private:
FeedHolder *mParent;
uint32_t mFeedId;
RsPeerId mPeerId;
ChatId mPeerId;
std::string mMsgId;
bool mIsHome;

View File

@ -59,7 +59,7 @@ PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId,
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateItem()));
avatar->setId(RsPeerId(mPeerId));// TODO: remove unnecesary converstation
avatar->setId(ChatId(mPeerId));// TODO: remove unnecesary converstation
expandFrame->hide();

View File

@ -73,7 +73,7 @@ SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &g
connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateItem()));
avatar->setId(mSslId);
avatar->setId(ChatId(mSslId));
expandFrame->hide();

View File

@ -37,7 +37,7 @@ ChatToaster::ChatToaster(const RsPeerId &peer_id, const QString &message) : QWid
ui.textLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE));
ui.toasterLabel->setText(QString::fromUtf8(rsPeers->getPeerName(mPeerId).c_str()));
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
ui.avatarWidget->setId(mPeerId);
ui.avatarWidget->setId(ChatId(mPeerId));
}
void ChatToaster::chatButtonSlot()

View File

@ -38,7 +38,7 @@ GroupChatToaster::GroupChatToaster(const RsPeerId &peerId, const QString &messag
ui.toasterLabel->setText(QString::fromUtf8(rsPeers->getPeerName(peerId).c_str()));
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
ui.avatarWidget->setDefaultAvatar(":/images/user/personal64.png");
ui.avatarWidget->setId(peerId);
ui.avatarWidget->setId(ChatId(peerId));
}
void GroupChatToaster::chatButtonSlot()

View File

@ -35,8 +35,8 @@ OnlineToaster::OnlineToaster(const RsPeerId &peerId) : QWidget(NULL)
/* set informations */
ui.textLabel->setText(QString::fromUtf8(rsPeers->getPeerName(peerId).c_str()));
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
ui.avatarWidget->setId(peerId);
ui.avatarWidget->setId(ChatId(peerId));
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
}
void OnlineToaster::chatButtonSlot()