mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-06 13:48:59 -04:00
added protocol for Avatar exchange in private chat. See http://retroshare.sourceforge.net/wiki/index.php/Chat.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@959 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
ba6260d9cb
commit
cdd7377280
8 changed files with 927 additions and 603 deletions
|
@ -90,8 +90,9 @@ class MsgInfoSummary
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define RS_CHAT_PUBLIC 0x0001
|
#define RS_CHAT_PUBLIC 0x0001
|
||||||
#define RS_CHAT_PRIVATE 0x0002
|
#define RS_CHAT_PRIVATE 0x0002
|
||||||
|
#define RS_CHAT_AVATAR_AVAILABLE 0x0004
|
||||||
|
|
||||||
class ChatInfo
|
class ChatInfo
|
||||||
{
|
{
|
||||||
|
@ -131,6 +132,12 @@ virtual bool chatAvailable() = 0;
|
||||||
virtual bool ChatSend(ChatInfo &ci) = 0;
|
virtual bool ChatSend(ChatInfo &ci) = 0;
|
||||||
virtual bool getNewChat(std::list<ChatInfo> &chats) = 0;
|
virtual bool getNewChat(std::list<ChatInfo> &chats) = 0;
|
||||||
|
|
||||||
|
// get avatar data for peer pid
|
||||||
|
virtual void getAvatarData(std::string pid,unsigned char *& data,int& size) = 0 ;
|
||||||
|
// set own avatar data
|
||||||
|
virtual void setOwnAvatarData(const unsigned char *data,int size) = 0 ;
|
||||||
|
virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ;
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -146,18 +146,41 @@ void p3Msgs::initRsChatInfo(RsChatItem *c, ChatInfo &i)
|
||||||
{
|
{
|
||||||
i.rsid = c -> PeerId();
|
i.rsid = c -> PeerId();
|
||||||
i.name = mAuthMgr->getName(i.rsid);
|
i.name = mAuthMgr->getName(i.rsid);
|
||||||
|
i.chatflags = 0 ;
|
||||||
i.msg = c -> message;
|
i.msg = c -> message;
|
||||||
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
|
|
||||||
|
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
|
||||||
{
|
{
|
||||||
i.chatflags = RS_CHAT_PRIVATE;
|
i.chatflags |= RS_CHAT_PRIVATE;
|
||||||
//std::cerr << "RsServer::initRsChatInfo() Chat Private!!!";
|
//std::cerr << "RsServer::initRsChatInfo() Chat Private!!!";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i.chatflags = RS_CHAT_PUBLIC;
|
i.chatflags |= RS_CHAT_PUBLIC;
|
||||||
//std::cerr << "RsServer::initRsChatInfo() Chat Public!!!";
|
//std::cerr << "RsServer::initRsChatInfo() Chat Public!!!";
|
||||||
}
|
}
|
||||||
//std::cerr << std::endl;
|
//std::cerr << std::endl;
|
||||||
|
|
||||||
|
if(c->chatFlags & RS_CHAT_FLAG_AVATAR_AVAILABLE)
|
||||||
|
{
|
||||||
|
std::cerr << "p3msgs::initRsChatInfo(): new avatar available for peer " << i.rsid << ". Sending above." << std::endl ;
|
||||||
|
i.chatflags |= RS_CHAT_AVATAR_AVAILABLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void p3Msgs::getOwnAvatarData(unsigned char *& data,int& size)
|
||||||
|
{
|
||||||
|
mChatSrv->getOwnAvatarJpegData(data,size) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3Msgs::setOwnAvatarData(const unsigned char *data,int size)
|
||||||
|
{
|
||||||
|
mChatSrv->setOwnAvatarJpegData(data,size) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3Msgs::getAvatarData(std::string pid,unsigned char *& data,int& size)
|
||||||
|
{
|
||||||
|
mChatSrv->getAvatarJpegData(pid,data,size) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,38 +36,43 @@ class RsChatItem;
|
||||||
|
|
||||||
class p3Msgs: public RsMsgs
|
class p3Msgs: public RsMsgs
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
p3Msgs(p3AuthMgr *p3a, p3MsgService *p3m, p3ChatService *p3c)
|
p3Msgs(p3AuthMgr *p3a, p3MsgService *p3m, p3ChatService *p3c)
|
||||||
:mAuthMgr(p3a), mMsgSrv(p3m), mChatSrv(p3c) { return; }
|
:mAuthMgr(p3a), mMsgSrv(p3m), mChatSrv(p3c) { return; }
|
||||||
virtual ~p3Msgs() { return; }
|
virtual ~p3Msgs() { return; }
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
/* Message Items */
|
/* Message Items */
|
||||||
|
|
||||||
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
||||||
virtual bool getMessage(std::string mId, MessageInfo &msg);
|
virtual bool getMessage(std::string mId, MessageInfo &msg);
|
||||||
|
|
||||||
virtual bool MessageSend(MessageInfo &info);
|
virtual bool MessageSend(MessageInfo &info);
|
||||||
virtual bool MessageDelete(std::string mid);
|
virtual bool MessageDelete(std::string mid);
|
||||||
virtual bool MessageRead(std::string mid);
|
virtual bool MessageRead(std::string mid);
|
||||||
|
|
||||||
/****************************************/
|
// gets avatar from peer id in jpeg format.
|
||||||
/* Chat */
|
virtual void getAvatarData(std::string pid,unsigned char *& data,int& size);
|
||||||
virtual bool chatAvailable();
|
virtual void setOwnAvatarData(const unsigned char *data,int size);
|
||||||
virtual bool ChatSend(ChatInfo &ci);
|
virtual void getOwnAvatarData(unsigned char *& data,int& size);
|
||||||
virtual bool getNewChat(std::list<ChatInfo> &chats);
|
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
|
/* Chat */
|
||||||
|
virtual bool chatAvailable();
|
||||||
|
virtual bool ChatSend(ChatInfo &ci);
|
||||||
|
virtual bool getNewChat(std::list<ChatInfo> &chats);
|
||||||
|
|
||||||
|
/****************************************/
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void initRsChatInfo(RsChatItem *c, ChatInfo &i);
|
void initRsChatInfo(RsChatItem *c, ChatInfo &i);
|
||||||
|
|
||||||
p3AuthMgr *mAuthMgr;
|
p3AuthMgr *mAuthMgr;
|
||||||
p3MsgService *mMsgSrv;
|
p3MsgService *mMsgSrv;
|
||||||
p3ChatService *mChatSrv;
|
p3ChatService *mChatSrv;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,10 @@
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
/* chat Flags */
|
/* chat Flags */
|
||||||
const uint32_t RS_CHAT_FLAG_PRIVATE = 0x0001;
|
const uint32_t RS_CHAT_FLAG_PRIVATE = 0x0001;
|
||||||
|
const uint32_t RS_CHAT_FLAG_REQUESTS_AVATAR = 0x0002;
|
||||||
|
const uint32_t RS_CHAT_FLAG_CONTAINS_AVATAR = 0x0004;
|
||||||
|
const uint32_t RS_CHAT_FLAG_AVATAR_AVAILABLE = 0x0008;
|
||||||
|
|
||||||
class RsChatItem: public RsItem
|
class RsChatItem: public RsItem
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,6 +40,8 @@ p3ChatService::p3ChatService(p3ConnectMgr *cm)
|
||||||
:p3Service(RS_SERVICE_TYPE_CHAT), mConnMgr(cm)
|
:p3Service(RS_SERVICE_TYPE_CHAT), mConnMgr(cm)
|
||||||
{
|
{
|
||||||
addSerialType(new RsChatSerialiser());
|
addSerialType(new RsChatSerialiser());
|
||||||
|
|
||||||
|
_own_avatar = NULL ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int p3ChatService::tick()
|
int p3ChatService::tick()
|
||||||
|
@ -104,6 +106,60 @@ int p3ChatService::sendChat(std::wstring msg)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class p3ChatService::AvatarInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AvatarInfo(const unsigned char *jpeg_data,int size)
|
||||||
|
{
|
||||||
|
int n_c = size ;
|
||||||
|
int p = sizeof(wchar_t) ;
|
||||||
|
int n = n_c/p + 1 ;
|
||||||
|
|
||||||
|
_jpeg_wstring = std::wstring(n,0) ;
|
||||||
|
|
||||||
|
for(int i=0;i<n;++i)
|
||||||
|
{
|
||||||
|
wchar_t h = jpeg_data[p*i] ;
|
||||||
|
|
||||||
|
for(int j=1;j<p;++j)
|
||||||
|
{
|
||||||
|
h = h << 8 ;
|
||||||
|
h += jpeg_data[p*i+j] ;
|
||||||
|
}
|
||||||
|
_jpeg_wstring[i] = h ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AvatarInfo(const std::wstring& s) : _jpeg_wstring(s) {}
|
||||||
|
|
||||||
|
const std::wstring& toStdWString() const { return _jpeg_wstring; }
|
||||||
|
|
||||||
|
void toUnsignedChar(unsigned char *& data,int& size) const
|
||||||
|
{
|
||||||
|
int p = sizeof(wchar_t) ;
|
||||||
|
int n = _jpeg_wstring.size() ;
|
||||||
|
int n_c = p*n ;
|
||||||
|
|
||||||
|
data = new unsigned char[n_c] ;
|
||||||
|
size = n_c ;
|
||||||
|
|
||||||
|
for(int i=0;i<n;++i)
|
||||||
|
{
|
||||||
|
wchar_t h = _jpeg_wstring[i] ;
|
||||||
|
|
||||||
|
for(int j=p-1;j>=0;--j)
|
||||||
|
{
|
||||||
|
data[p*i+j] = (unsigned char)(h & 0xff) ;
|
||||||
|
h = h >> 8 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring _jpeg_wstring;
|
||||||
|
int _peer_is_new ; // true when the peer has a new avatar
|
||||||
|
int _own_is_new ; // true when I myself a new avatar to send to this peer.
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
int p3ChatService::sendPrivateChat(std::wstring msg, std::string id)
|
int p3ChatService::sendPrivateChat(std::wstring msg, std::string id)
|
||||||
{
|
{
|
||||||
// make chat item....
|
// make chat item....
|
||||||
|
@ -119,6 +175,17 @@ int p3ChatService::sendPrivateChat(std::wstring msg, std::string id)
|
||||||
ci->sendTime = time(NULL);
|
ci->sendTime = time(NULL);
|
||||||
ci->message = msg;
|
ci->message = msg;
|
||||||
|
|
||||||
|
std::map<std::string,AvatarInfo*>::iterator it = _avatars.find(id) ;
|
||||||
|
|
||||||
|
if(it != _avatars.end() && it->second->_own_is_new)
|
||||||
|
{
|
||||||
|
std::cerr << "p3ChatService::sendPrivateChat: new avatar never sent to peer " << id << ". Setting <new> flag to packet." << std::endl;
|
||||||
|
|
||||||
|
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||||
|
it->second->_own_is_new = false ;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "Sending msg to peer " << id << ", flags = " << ci->chatFlags << std::endl ;
|
||||||
#ifdef CHAT_DEBUG
|
#ifdef CHAT_DEBUG
|
||||||
std::cerr << "p3ChatService::sendPrivateChat() Item:";
|
std::cerr << "p3ChatService::sendPrivateChat() Item:";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
@ -146,11 +213,141 @@ std::list<RsChatItem *> p3ChatService::getChatQueue()
|
||||||
ci->print(std::cerr);
|
ci->print(std::cerr);
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
ci->recvTime = now;
|
std::cerr << "Got msg. Flags = " << ci->chatFlags << std::endl ;
|
||||||
ilist.push_back(ci);
|
|
||||||
|
if(ci->chatFlags & RS_CHAT_FLAG_CONTAINS_AVATAR) // no msg here. Just an avatar.
|
||||||
|
receiveAvatarJpegData(ci) ;
|
||||||
|
else if(ci->chatFlags & RS_CHAT_FLAG_REQUESTS_AVATAR) // no msg here. Just an avatar request.
|
||||||
|
sendAvatarJpegData(ci->PeerId()) ;
|
||||||
|
else // normal msg. Return it normally.
|
||||||
|
{
|
||||||
|
// Check if new avatar is available at peer's. If so, send a request to get the avatar.
|
||||||
|
if(ci->chatFlags & RS_CHAT_FLAG_AVATAR_AVAILABLE)
|
||||||
|
{
|
||||||
|
std::cerr << "New avatar is available for peer " << ci->PeerId() << ", sending request" << std::endl ;
|
||||||
|
sendAvatarRequest(ci->PeerId()) ;
|
||||||
|
ci->chatFlags &= ~RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string,AvatarInfo *>::const_iterator it = _avatars.find(ci->PeerId()) ;
|
||||||
|
|
||||||
|
std::cerr << "p3chatservice:: avatar requested from above. " << std::endl ;
|
||||||
|
// has avatar. Return it strait away.
|
||||||
|
//
|
||||||
|
if(it!=_avatars.end() && it->second->_peer_is_new)
|
||||||
|
{
|
||||||
|
std::cerr << "Adatar is new for peer. ending info above" << std::endl ;
|
||||||
|
ci->chatFlags |= RS_CHAT_FLAG_AVATAR_AVAILABLE ;
|
||||||
|
}
|
||||||
|
|
||||||
|
ci->recvTime = now;
|
||||||
|
ilist.push_back(ci);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ilist;
|
return ilist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void p3ChatService::setOwnAvatarJpegData(const unsigned char *data,int size)
|
||||||
|
{
|
||||||
|
std::cerr << "p3chatservice: Setting own avatar to new image." << std::endl ;
|
||||||
|
|
||||||
|
if(_own_avatar != NULL)
|
||||||
|
delete _own_avatar ;
|
||||||
|
|
||||||
|
_own_avatar = new AvatarInfo(data,size) ;
|
||||||
|
|
||||||
|
// set the info that our avatar is new, for all peers
|
||||||
|
for(std::map<std::string,AvatarInfo *>::iterator it(_avatars.begin());it!=_avatars.end();++it)
|
||||||
|
it->second->_own_is_new = true ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3ChatService::receiveAvatarJpegData(RsChatItem *ci)
|
||||||
|
{
|
||||||
|
std::cerr << "p3chatservice: received avatar jpeg data for peer " << ci->PeerId() << ". Storing it." << std::endl ;
|
||||||
|
|
||||||
|
bool new_peer = (_avatars.find(ci->PeerId()) == _avatars.end()) ;
|
||||||
|
|
||||||
|
_avatars[ci->PeerId()] = new AvatarInfo(ci->message) ;
|
||||||
|
_avatars[ci->PeerId()]->_peer_is_new = true ;
|
||||||
|
_avatars[ci->PeerId()]->_own_is_new = new_peer ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3ChatService::getOwnAvatarJpegData(unsigned char *& data,int& size)
|
||||||
|
{
|
||||||
|
// should be a Mutex here.
|
||||||
|
|
||||||
|
std::cerr << "p3chatservice:: own avatar requested from above. " << std::endl ;
|
||||||
|
// has avatar. Return it strait away.
|
||||||
|
//
|
||||||
|
if(_own_avatar != NULL)
|
||||||
|
_own_avatar->toUnsignedChar(data,size) ;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data=NULL ;
|
||||||
|
size=0 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void p3ChatService::getAvatarJpegData(const std::string& peer_id,unsigned char *& data,int& size)
|
||||||
|
{
|
||||||
|
// should be a Mutex here.
|
||||||
|
std::map<std::string,AvatarInfo *>::const_iterator it = _avatars.find(peer_id) ;
|
||||||
|
|
||||||
|
std::cerr << "p3chatservice:: avatar requested from above. " << std::endl ;
|
||||||
|
// has avatar. Return it strait away.
|
||||||
|
//
|
||||||
|
if(it!=_avatars.end())
|
||||||
|
{
|
||||||
|
it->second->toUnsignedChar(data,size) ;
|
||||||
|
it->second->_peer_is_new = false ;
|
||||||
|
std::cerr << "Already has avatar. Returning it" << std::endl ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
std::cerr << "No avatar for this peer. Requesting it by sending request packet." << std::endl ;
|
||||||
|
|
||||||
|
sendAvatarRequest(peer_id) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3ChatService::sendAvatarRequest(const std::string& peer_id)
|
||||||
|
{
|
||||||
|
// Doesn't have avatar. Request it.
|
||||||
|
//
|
||||||
|
RsChatItem *ci = new RsChatItem();
|
||||||
|
|
||||||
|
ci->PeerId(peer_id);
|
||||||
|
ci->chatFlags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_REQUESTS_AVATAR ;
|
||||||
|
ci->sendTime = time(NULL);
|
||||||
|
ci->message = std::wstring() ;
|
||||||
|
|
||||||
|
std::cerr << "p3ChatService::sending request for avatar, to peer " << peer_id << std::endl ;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
sendItem(ci);
|
||||||
|
}
|
||||||
|
|
||||||
|
void p3ChatService::sendAvatarJpegData(const std::string& peer_id)
|
||||||
|
{
|
||||||
|
std::cerr << "p3chatservice: sending requested for peer " << peer_id << ", data=" << (void*)_own_avatar << std::endl ;
|
||||||
|
|
||||||
|
if(_own_avatar != NULL)
|
||||||
|
{
|
||||||
|
RsChatItem *ci = new RsChatItem();
|
||||||
|
|
||||||
|
ci->PeerId(peer_id);
|
||||||
|
ci->chatFlags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_CONTAINS_AVATAR ;
|
||||||
|
ci->sendTime = time(NULL);
|
||||||
|
ci->message = _own_avatar->toStdWString() ;
|
||||||
|
|
||||||
|
// take avatar, and embed it into a std::wstring.
|
||||||
|
//
|
||||||
|
std::cerr << "p3ChatService::sending avatar image to peer" << peer_id << ", string size = " << ci->message.size() << std::endl ;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
sendItem(ci);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
std::cerr << "Doing nothing" << std::endl ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,23 +39,47 @@
|
||||||
#include "services/p3service.h"
|
#include "services/p3service.h"
|
||||||
#include "pqi/p3connmgr.h"
|
#include "pqi/p3connmgr.h"
|
||||||
|
|
||||||
|
|
||||||
class p3ChatService: public p3Service
|
class p3ChatService: public p3Service
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
p3ChatService(p3ConnectMgr *cm);
|
p3ChatService(p3ConnectMgr *cm);
|
||||||
|
|
||||||
/* overloaded */
|
/* overloaded */
|
||||||
virtual int tick();
|
virtual int tick();
|
||||||
virtual int status();
|
virtual int status();
|
||||||
|
|
||||||
int sendChat(std::wstring msg);
|
int sendChat(std::wstring msg);
|
||||||
int sendPrivateChat(std::wstring msg, std::string id);
|
int sendPrivateChat(std::wstring msg, std::string id);
|
||||||
|
|
||||||
std::list<RsChatItem *> getChatQueue();
|
/// gets the peer's avatar in jpeg format, if available. Null otherwise. Also asks the peer to send
|
||||||
|
/// its avatar, if not already available. Creates a new unsigned char array. It's the caller's
|
||||||
|
/// responsibility to delete this ones used.
|
||||||
|
///
|
||||||
|
void getAvatarJpegData(const std::string& peer_id,unsigned char *& data,int& size) ;
|
||||||
|
|
||||||
|
/// Sets the avatar data and size. Data is copied, so should be destroyed by the caller.
|
||||||
|
void setOwnAvatarJpegData(const unsigned char *data,int size) ;
|
||||||
|
void getOwnAvatarJpegData(unsigned char *& data,int& size) ;
|
||||||
|
|
||||||
|
std::list<RsChatItem *> getChatQueue();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
p3ConnectMgr *mConnMgr;
|
class AvatarInfo ;
|
||||||
|
|
||||||
|
/// Send avatar info to peer in jpeg format.
|
||||||
|
void sendAvatarJpegData(const std::string& peer_id) ;
|
||||||
|
|
||||||
|
/// Receive the avatar in a chat item, with RS_CHAT_RECEIVE_AVATAR flag.
|
||||||
|
void receiveAvatarJpegData(RsChatItem *ci) ;
|
||||||
|
|
||||||
|
/// Sends a request for an avatar to the peer of given id
|
||||||
|
void sendAvatarRequest(const std::string& peer_id) ;
|
||||||
|
|
||||||
|
p3ConnectMgr *mConnMgr;
|
||||||
|
|
||||||
|
AvatarInfo *_own_avatar ;
|
||||||
|
std::map<std::string,AvatarInfo *> _avatars ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SERVICE_CHAT_HEADER
|
#endif // SERVICE_CHAT_HEADER
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,8 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
|
||||||
colorChanged(mCurrentColor);
|
colorChanged(mCurrentColor);
|
||||||
setFont();
|
setFont();
|
||||||
|
|
||||||
|
updateAvatar() ;
|
||||||
|
updatePeerAvatar(id) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Destructor. */
|
/** Destructor. */
|
||||||
|
@ -154,7 +155,7 @@ void PopupChatDialog::getfocus()
|
||||||
{
|
{
|
||||||
|
|
||||||
QMainWindow::activateWindow();
|
QMainWindow::activateWindow();
|
||||||
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
|
setWindowState((windowState() & (~Qt::WindowMinimized)) | Qt::WindowActive);
|
||||||
QMainWindow::raise();
|
QMainWindow::raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,6 +248,12 @@ void PopupChatDialog::addChatMsg(ChatInfo *ci)
|
||||||
QTextCursor cursor = ui.textBrowser->textCursor();
|
QTextCursor cursor = ui.textBrowser->textCursor();
|
||||||
cursor.movePosition(QTextCursor::End);
|
cursor.movePosition(QTextCursor::End);
|
||||||
ui.textBrowser->setTextCursor(cursor);
|
ui.textBrowser->setTextCursor(cursor);
|
||||||
|
|
||||||
|
if(ci->chatflags & RS_CHAT_AVATAR_AVAILABLE)
|
||||||
|
{
|
||||||
|
std::cerr << "received msg saying an avatar for peer " << ci->rsid << " is available." << std::endl ;
|
||||||
|
updatePeerAvatar(ci->rsid) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopupChatDialog::checkChat()
|
void PopupChatDialog::checkChat()
|
||||||
|
@ -551,14 +558,71 @@ void PopupChatDialog::changeStyle()
|
||||||
ui.textBrowser->setTextCursor(cursor);
|
ui.textBrowser->setTextCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PopupChatDialog::updatePeerAvatar(const std::string& peer_id)
|
||||||
|
{
|
||||||
|
unsigned char *data = NULL;
|
||||||
|
int size = 0 ;
|
||||||
|
|
||||||
|
std::cerr << "Requesting avatar image for peer " << peer_id << std::endl ;
|
||||||
|
|
||||||
|
rsMsgs->getAvatarData(peer_id,data,size);
|
||||||
|
|
||||||
|
std::cerr << "Image size = " << size << std::endl ;
|
||||||
|
|
||||||
|
if(size == 0)
|
||||||
|
{
|
||||||
|
std::cerr << "Got no image" << std::endl ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the image
|
||||||
|
QPixmap pix ;
|
||||||
|
pix.loadFromData(data,size,"JPG") ;
|
||||||
|
ui.avatarlabel->setPixmap(pix); // writes image into ba in JPG format
|
||||||
|
|
||||||
|
delete[] data ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PopupChatDialog::updateAvatar()
|
||||||
|
{
|
||||||
|
unsigned char *data = NULL;
|
||||||
|
int size = 0 ;
|
||||||
|
|
||||||
|
rsMsgs->getOwnAvatarData(data,size);
|
||||||
|
|
||||||
|
std::cerr << "Image size = " << size << std::endl ;
|
||||||
|
|
||||||
|
if(size == 0)
|
||||||
|
std::cerr << "Got no image" << std::endl ;
|
||||||
|
|
||||||
|
// set the image
|
||||||
|
QPixmap pix ;
|
||||||
|
pix.loadFromData(data,size,"JPG") ;
|
||||||
|
ui.myavatarlabel->setPixmap(pix); // writes image into ba in JPG format
|
||||||
|
|
||||||
|
delete[] data ;
|
||||||
|
}
|
||||||
|
|
||||||
void PopupChatDialog::getAvatar()
|
void PopupChatDialog::getAvatar()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getOpenFileName(this, "Load File",
|
QString fileName = QFileDialog::getOpenFileName(this, "Load File", QDir::homePath(), "Pictures (*.png *.xpm *.jpg)");
|
||||||
QDir::homePath(),
|
|
||||||
"Pictures (*.png *.xpm *.jpg)");
|
|
||||||
if(!fileName.isEmpty())
|
if(!fileName.isEmpty())
|
||||||
{
|
{
|
||||||
picture = QPixmap(fileName).scaled(82,82, Qt::KeepAspectRatio);
|
picture = QPixmap(fileName).scaled(82,82, Qt::KeepAspectRatio);
|
||||||
ui.myavatarlabel->setPixmap(picture);
|
|
||||||
|
std::cerr << "Sending avatar image down the pipe" << std::endl ;
|
||||||
|
|
||||||
|
// send avatar down the pipe for other peers to get it.
|
||||||
|
QByteArray ba;
|
||||||
|
QBuffer buffer(&ba);
|
||||||
|
buffer.open(QIODevice::WriteOnly);
|
||||||
|
picture.save(&buffer, "JPG"); // writes image into ba in JPG format
|
||||||
|
|
||||||
|
std::cerr << "Image size = " << ba.size() << std::endl ;
|
||||||
|
|
||||||
|
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()),ba.size()) ; // last char 0 included.
|
||||||
|
|
||||||
|
updateAvatar() ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,8 @@ private slots:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void colorChanged(const QColor &c);
|
void colorChanged(const QColor &c);
|
||||||
|
void updatePeerAvatar(const std::string&);
|
||||||
|
void updateAvatar();
|
||||||
|
|
||||||
QAction *actionTextBold;
|
QAction *actionTextBold;
|
||||||
QAction *actionTextUnderline;
|
QAction *actionTextUnderline;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue