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_Avatar, SIGNAL(triggered()), this, SLOT(getAvatar()));
connect( ui.actionSet_your_Personal_Message, SIGNAL(triggered()), this, SLOT(statusmessage())); connect( ui.actionSet_your_Personal_Message, SIGNAL(triggered()), this, SLOT(statusmessage()));
ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME);
ui.avatar->setOwnId(); ui.avatar->setOwnId();
ui.avatar->setFrameType(AvatarWidget::STATUS_FRAME);
ui.tabWidget->setTabPosition(QTabWidget::North); ui.tabWidget->setTabPosition(QTabWidget::North);
ui.tabWidget->addTab(networkView = new NetworkView(),QIcon(IMAGE_NETWORK2), tr("Network graph")); 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 */ /* Hide or show the avatar frames */
showAvatarFrame(PeerSettings->getShowAvatarFrame(chat_id)); showAvatarFrame(PeerSettings->getShowAvatarFrame(chat_id));
ui.avatarWidget->setId(chat_id);
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME); 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.ownAvatarWidget->setFrameType(AvatarWidget::STATUS_FRAME); ui.ownAvatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
ui.ownAvatarWidget->setOwnId(); ui.ownAvatarWidget->setOwnId();

View File

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

View File

@ -25,6 +25,8 @@
#include <string> #include <string>
#include <QString> #include <QString>
#include <retroshare/rstypes.h>
#include <retroshare/rsgxsifacetypes.h>
#define AVATAR_DEFAULT_IMAGE ":/images/no_avatar_background.png" #define AVATAR_DEFAULT_IMAGE ":/images/no_avatar_background.png"
@ -34,8 +36,10 @@ class AvatarDefs
{ {
public: public:
static void getOwnAvatar(QPixmap &avatar, const QString& defaultImage = AVATAR_DEFAULT_IMAGE); 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 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 #endif

View File

@ -116,45 +116,44 @@ void AvatarWidget::setFrameType(FrameType type)
break; break;
} }
//refreshAvatarImage();
refreshStatus(); refreshStatus();
updateAvatar(QString::fromStdString(mId.toStdString()));
Rshare::refreshStyleSheet(this, false); Rshare::refreshStyleSheet(this, false);
} }
void AvatarWidget::setId(const RsPeerId &id) void AvatarWidget::setId(const ChatId &id)
{ {
mId = id; mId = id;
// mPgpId = rsPeers->getGPGId(id) ; // mPgpId = rsPeers->getGPGId(id) ;
// mFlag.isGpg = false ; // mFlag.isGpg = false ;
if (mId == rsPeers->getOwnId()) {
mFlag.isOwnId = true;
setToolTip(tr("Click to change your avatar"));
}
setPixmap(QPixmap()); setPixmap(QPixmap());
if (id.isNull()) { if (id.isNotSet()) {
setEnabled(false); setEnabled(false);
} }
refreshAvatarImage();
refreshStatus(); refreshStatus();
updateAvatar(QString::fromStdString(mId.toStdString()));
} }
void AvatarWidget::setOwnId() 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; defaultAvatar = avatar_file_name;
updateAvatar(QString::fromStdString(mId.toStdString())); refreshAvatarImage();
} }
void AvatarWidget::refreshStatus() void AvatarWidget::refreshStatus()
{ {
switch (mFrameType) { switch (mFrameType)
{
case NO_FRAME: case NO_FRAME:
case NORMAL_FRAME: case NORMAL_FRAME:
{ {
@ -163,91 +162,114 @@ void AvatarWidget::refreshStatus()
} }
case STATUS_FRAME: case STATUS_FRAME:
{ {
StatusInfo statusInfo; uint32_t status ;
if (mFlag.isOwnId) { if(mId.isNotSet())
return ;
if (mFlag.isOwnId)
{
if(mId.isPeerId())
{
StatusInfo statusInfo;
rsStatus->getOwnStatus(statusInfo); rsStatus->getOwnStatus(statusInfo);
} else { status = statusInfo.status ;
// 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); 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; break;
} }
} }
} }
void AvatarWidget::updateStatus(const QString peerId, int status) void AvatarWidget::updateStatus(const QString& peerId, int status)
{ {
if (mFrameType != STATUS_FRAME) { if (mId.isPeerId() && mId.toPeerId() == RsPeerId(peerId.toStdString()))
return; updateStatus(status) ;
} }
if (mId.isNull()) { void AvatarWidget::updateStatus(int status)
mPeerState = status; {
Rshare::refreshStyleSheet(this, false); if (mFrameType != STATUS_FRAME)
} else { return;
/* set style for status */
if (mId.toStdString() == peerId.toStdString()) {
// the peers status has changed
mPeerState = status; mPeerState = status;
setEnabled(((uint32_t) status == RS_STATUS_OFFLINE) ? false : true); setEnabled(((uint32_t) status == RS_STATUS_OFFLINE) ? false : true);
Rshare::refreshStyleSheet(this, false); Rshare::refreshStyleSheet(this, false);
} }
}
}
void AvatarWidget::updateAvatar(const QString &peerId) void AvatarWidget::updateAvatar(const QString &peerId)
{ {
if (mId.isNull()) { if(mId.isPeerId() && mId.toPeerId() == RsPeerId(peerId.toStdString()))
refreshAvatarImage() ;
if(mId.isGxsId() && mId.toGxsId() == RsGxsId(peerId.toStdString()))
refreshAvatarImage() ;
}
void AvatarWidget::refreshAvatarImage()
{
if (mId.isNotSet())
{
QPixmap avatar(defaultAvatar); QPixmap avatar(defaultAvatar);
setPixmap(avatar); setPixmap(avatar);
return; return;
} }
else if (mFlag.isOwnId && mId.isPeerId())
if (mFlag.isOwnId) { {
QPixmap avatar; QPixmap avatar;
AvatarDefs::getOwnAvatar(avatar); AvatarDefs::getOwnAvatar(avatar);
setPixmap(avatar); setPixmap(avatar);
return; return;
} }
else if (mId.isPeerId())
//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; QPixmap avatar;
AvatarDefs::getAvatarFromSslId(mId.toStdString(), avatar, defaultAvatar); AvatarDefs::getAvatarFromSslId(mId.toPeerId(), avatar, defaultAvatar);
setPixmap(avatar); setPixmap(avatar);
return; 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() void AvatarWidget::updateOwnAvatar()
{ {
if (mFlag.isOwnId) { if (mFlag.isOwnId)
updateAvatar(QString::fromStdString(mId.toStdString())); refreshAvatarImage() ;
}
} }

View File

@ -25,6 +25,7 @@
#include <QLabel> #include <QLabel>
#include <stdint.h> #include <stdint.h>
#include <retroshare/rstypes.h> #include <retroshare/rstypes.h>
#include <retroshare/rsmsgs.h>
namespace Ui { namespace Ui {
class AvatarWidget; class AvatarWidget;
@ -48,25 +49,28 @@ public:
QString frameState(); QString frameState();
void setFrameType(FrameType type); void setFrameType(FrameType type);
void setId(const RsPeerId &id) ; void setId(const ChatId& id) ;
void setOwnId(); void setOwnId();
void setDefaultAvatar(const QString &avatar); void setOwnId(const RsGxsId&);
void setDefaultAvatar(const QString &avatar_file_name);
protected: protected:
void mouseReleaseEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event);
private slots: private slots:
void updateStatus(const QString peerId, int status); void updateStatus(const QString& peerId, int status);
void updateAvatar(const QString& peerId); void updateAvatar(const QString& peerId);
void updateOwnAvatar(); void updateOwnAvatar();
private: private:
void refreshAvatarImage() ;
void refreshStatus(); void refreshStatus();
void updateStatus(int status);
QString defaultAvatar; QString defaultAvatar;
Ui::AvatarWidget *ui; Ui::AvatarWidget *ui;
RsPeerId mId; ChatId mId;
struct { struct {
bool isOwnId : 1; 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)->type() == TYPE_SSL && id == (*it)->data(COLUMN_DATA, ROLE_ID).toString()) {
if ((*it)->parent() != NULL && (*it)->parent()->type() == TYPE_GPG) { if ((*it)->parent() != NULL && (*it)->parent()->type() == TYPE_GPG) {
QPixmap avatar; QPixmap avatar;
AvatarDefs::getAvatarFromSslId(id.toStdString(), avatar); AvatarDefs::getAvatarFromSslId(RsPeerId(id.toStdString()), avatar);
QIcon avatar_icon(avatar); QIcon avatar_icon(avatar);
(*it)->parent()->setIcon(COLUMN_AVATAR, avatar_icon); (*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 // only set the avatar image the first time, or when it changed
// otherwise getAvatarFromSslId sends request packages to peers. // otherwise getAvatarFromSslId sends request packages to peers.
QPixmap avatar; QPixmap avatar;
AvatarDefs::getAvatarFromSslId(bestSslId.toStdString(), avatar); AvatarDefs::getAvatarFromSslId(bestSslId, avatar);
QIcon avatar_icon(avatar); QIcon avatar_icon(avatar);
gpgItem->setIcon(COLUMN_AVATAR, avatar_icon); gpgItem->setIcon(COLUMN_AVATAR, avatar_icon);
} }

View File

@ -189,7 +189,7 @@ void ConfCertDialog::load()
if (!detail.isOnlyGPGdetail) if (!detail.isOnlyGPGdetail)
{ {
ui.avatar->setId(peerId); ui.avatar->setId(ChatId(peerId));
ui.loc->setText(QString::fromUtf8(detail.location.c_str())); ui.loc->setText(QString::fromUtf8(detail.location.c_str()));
// Dont Show a timestamp in RS calculate the day // 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&))); connect(NotifyQt::getInstance(), SIGNAL(peerHasNewAvatar(const QString&)), this, SLOT(updateAvatar(const QString&)));
avatar->setId(mPeerId); avatar->setId(ChatId(mPeerId));
updateItemStatic(); updateItemStatic();
updateItem(); updateItem();

View File

@ -81,15 +81,29 @@ void MsgItem::updateItemStatic()
return; return;
/* get peer Id */ /* get peer Id */
mPeerId = mi.rspeerid_srcId;
if(mi.msgflags & RS_MSG_SIGNED)
mPeerId = ChatId(mi.rsgxsid_srcId);
else
mPeerId = ChatId(mi.rspeerid_srcId);
avatar->setId(mPeerId); avatar->setId(mPeerId);
QString title; QString title;
QString srcName; QString srcName;
if ((mi.msgflags & RS_MSG_SYSTEM) && mi.rspeerid_srcId == rsPeers->getOwnId()) {
if ((mi.msgflags & RS_MSG_SYSTEM) && mi.rspeerid_srcId == rsPeers->getOwnId())
srcName = "RetroShare"; srcName = "RetroShare";
} else { 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()); srcName = QString::fromUtf8(rsPeers->getPeerName(mi.rspeerid_srcId).c_str());
} }

View File

@ -58,7 +58,7 @@ private:
FeedHolder *mParent; FeedHolder *mParent;
uint32_t mFeedId; uint32_t mFeedId;
RsPeerId mPeerId; ChatId mPeerId;
std::string mMsgId; std::string mMsgId;
bool mIsHome; 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())); 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(); 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())); connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateItem()));
avatar->setId(mSslId); avatar->setId(ChatId(mSslId));
expandFrame->hide(); 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.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.toasterLabel->setText(QString::fromUtf8(rsPeers->getPeerName(mPeerId).c_str()));
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME); ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
ui.avatarWidget->setId(mPeerId); ui.avatarWidget->setId(ChatId(mPeerId));
} }
void ChatToaster::chatButtonSlot() 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.toasterLabel->setText(QString::fromUtf8(rsPeers->getPeerName(peerId).c_str()));
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME); ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
ui.avatarWidget->setDefaultAvatar(":/images/user/personal64.png"); ui.avatarWidget->setDefaultAvatar(":/images/user/personal64.png");
ui.avatarWidget->setId(peerId); ui.avatarWidget->setId(ChatId(peerId));
} }
void GroupChatToaster::chatButtonSlot() void GroupChatToaster::chatButtonSlot()

View File

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