mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-17 13:24:15 -05:00
- fixed a few bugs in PopupDistantChatDialog (Possible deadlock, wrong window for private chat)
- added method to properly close distant chat conversation (Still needs some work) - improved chat link creation window + clipboard copy git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6426 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
3f752b9eae
commit
42db43e590
@ -329,6 +329,7 @@ virtual bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_va
|
||||
virtual bool getDistantChatInviteList(std::vector<DistantChatInviteInfo>& invites) = 0;
|
||||
virtual bool initiateDistantChatConnexion(const std::string& encrypted_string,std::string& hash,uint32_t& error_code) = 0;
|
||||
virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) = 0;
|
||||
virtual bool closeDistantChatConnexion(const std::string& hash) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -360,4 +360,8 @@ bool p3Msgs::getDistantChatStatus(const std::string& hash,uint32_t& status,std::
|
||||
{
|
||||
return mChatSrv->getDistantChatStatus(hash,status,pgp_id) ;
|
||||
}
|
||||
bool p3Msgs::closeDistantChatConnexion(const std::string& hash)
|
||||
{
|
||||
return mChatSrv->closeDistantChatConnexion(hash) ;
|
||||
}
|
||||
|
||||
|
@ -191,6 +191,7 @@ class p3Msgs: public RsMsgs
|
||||
virtual bool getDistantChatInviteList(std::vector<DistantChatInviteInfo>& invites);
|
||||
virtual bool initiateDistantChatConnexion(const std::string& encrypted_string,std::string& hash,uint32_t& error_code) ;
|
||||
virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) ;
|
||||
virtual bool closeDistantChatConnexion(const std::string& hash) ;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -2891,6 +2891,7 @@ void p3ChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtua
|
||||
it->second.last_contact = now ;
|
||||
it->second.status = RS_DISTANT_CHAT_STATUS_TUNNEL_OK ;
|
||||
it->second.virtual_peer_id = virtual_peer_id ;
|
||||
it->second.direction = dir ;
|
||||
|
||||
#ifdef DEBUG_DISTANT_CHAT
|
||||
std::cerr << "(II) Adding virtual peer " << virtual_peer_id << " for chat hash " << hash << std::endl;
|
||||
@ -2918,6 +2919,7 @@ void p3ChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtua
|
||||
info.status = RS_DISTANT_CHAT_STATUS_TUNNEL_OK ;
|
||||
info.virtual_peer_id = virtual_peer_id ;
|
||||
info.pgp_id = it->second.destination_pgp_id ;
|
||||
info.direction = dir ;
|
||||
memcpy(info.aes_key,it->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ;
|
||||
|
||||
_distant_chat_peers[hash] = info ;
|
||||
@ -2926,8 +2928,6 @@ void p3ChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtua
|
||||
|
||||
rsicontrol->getNotify().notifyChatStatus(hash,"tunnel is up again!",true) ;
|
||||
rsicontrol->getNotify().notifyPeerStatusChanged(hash,RS_STATUS_ONLINE) ;
|
||||
|
||||
getPqiNotify()->AddPopupMessage(RS_POPUP_CHAT, hash, "Distant peer", "Conversation starts...");
|
||||
}
|
||||
|
||||
void p3ChatService::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id)
|
||||
@ -3079,7 +3079,7 @@ void p3ChatService::sendTurtleData(RsChatItem *item)
|
||||
|
||||
if(it == _distant_chat_peers.end())
|
||||
{
|
||||
std::cerr << "(EE) item is not coming out of a registered tunnel. Weird. peer id = " << virtual_peer_id << std::endl;
|
||||
std::cerr << "(EE) item is not going into a registered tunnel. Weird. peer id = " << virtual_peer_id << std::endl;
|
||||
delete[] buff ;
|
||||
return ;
|
||||
}
|
||||
@ -3285,6 +3285,7 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st
|
||||
info.last_contact = time(NULL) ;
|
||||
info.status = RS_DISTANT_CHAT_STATUS_TUNNEL_DN ;
|
||||
info.pgp_id = pgp_id.toStdString() ;
|
||||
info.direction = RsTurtleGenericTunnelItem::DIRECTION_SERVER ;
|
||||
memcpy(info.aes_key,data+DISTANT_CHAT_HASH_SIZE,DISTANT_CHAT_AES_KEY_SIZE) ;
|
||||
|
||||
_distant_chat_peers[hash] = info ;
|
||||
@ -3302,6 +3303,8 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st
|
||||
// And notify about chatting.
|
||||
|
||||
error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ;
|
||||
|
||||
getPqiNotify()->AddPopupMessage(RS_POPUP_CHAT, hash, "Distant peer", "Conversation starts...");
|
||||
return true ;
|
||||
}
|
||||
|
||||
@ -3359,7 +3362,10 @@ bool p3ChatService::getDistantChatStatus(const std::string& hash,uint32_t& statu
|
||||
std::map<TurtleFileHash,DistantChatPeerInfo>::const_iterator it = _distant_chat_peers.find(hash) ;
|
||||
|
||||
if(it == _distant_chat_peers.end())
|
||||
{
|
||||
status = RS_DISTANT_CHAT_STATUS_UNKNOWN ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
status = it->second.status ;
|
||||
pgp_id = it->second.pgp_id ;
|
||||
@ -3367,6 +3373,40 @@ bool p3ChatService::getDistantChatStatus(const std::string& hash,uint32_t& statu
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool p3ChatService::closeDistantChatConnexion(const std::string& hash)
|
||||
{
|
||||
// two cases:
|
||||
// - client needs to stop asking for tunnels => remove the hash from the list of tunnelled files
|
||||
// - server needs to only close the window and let the tunnel die. But the window should only open if a message arrives.
|
||||
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string,DistantChatPeerInfo>::iterator it = _distant_chat_peers.find(hash) ;
|
||||
|
||||
if(it == _distant_chat_peers.end()) // server side. Nothing to do.
|
||||
{
|
||||
std::cerr << "Cannot close chat associated to hash " << hash << ": not found." << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// We can't do just that. We should:
|
||||
// - mark the peer as closing, but not closed. If the tunnel gets deleted because of no traffic, then stop monitor
|
||||
// it. That can be done in removeVirtualPeer
|
||||
//
|
||||
if(it->second.direction == RsTurtleGenericTunnelItem::DIRECTION_SERVER)
|
||||
{
|
||||
// Client side: Stop tunnels
|
||||
//
|
||||
std::cerr << "This is client side. Stopping tunnel manageement for hash " << hash << std::endl;
|
||||
mTurtle->stopMonitoringTunnels(hash) ;
|
||||
|
||||
// and remove hash from list of current peers.
|
||||
_distant_chat_peers.erase(it) ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -313,6 +313,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
|
||||
bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,TurtleFileHash& hash) ;
|
||||
bool getDistantChatInviteList(std::vector<DistantChatInviteInfo>& invites) ;
|
||||
bool initiateDistantChatConnexion(const std::string& encrypted_string,std::string& hash,uint32_t& error_code) ;
|
||||
bool closeDistantChatConnexion(const std::string& hash) ;
|
||||
|
||||
virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) ;
|
||||
|
||||
@ -332,6 +333,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
|
||||
uint32_t status ; // info: do we have a tunnel ?
|
||||
std::string virtual_peer_id; // given by the turtle router. Identifies the tunnel.
|
||||
std::string pgp_id ; // pgp id of the peer we're talking to.
|
||||
RsTurtleGenericTunnelItem::Direction direction ; // specifiec wether we are client(managing the tunnel) or server.
|
||||
};
|
||||
|
||||
// This map contains the ongoing invites. This is the list where to look to
|
||||
|
@ -42,6 +42,7 @@ CreateMsgLinkDialog::CreateMsgLinkDialog()
|
||||
QObject::connect(_create_link_PB,SIGNAL(clicked()),this,SLOT(createLink())) ;
|
||||
QObject::connect(_create_new_PB,SIGNAL(toggled(bool)),this,SLOT(toggleCreateLink(bool))) ;
|
||||
QObject::connect(_existing_links_LW,SIGNAL(currentRowChanged(int)),this,SLOT(updateCurrentRow(int))) ;
|
||||
QObject::connect(_copy_to_clipboard_PB,SIGNAL(clicked()),this,SLOT(copyLinkToClipboard())) ;
|
||||
|
||||
_gpg_selection->setModus(FriendSelectionWidget::MODUS_SINGLE) ;
|
||||
_gpg_selection->setShowType(FriendSelectionWidget::SHOW_NON_FRIEND_GPG | FriendSelectionWidget::SHOW_GPG) ;
|
||||
@ -53,6 +54,24 @@ CreateMsgLinkDialog::CreateMsgLinkDialog()
|
||||
updateCurrentRow(-1) ;
|
||||
}
|
||||
|
||||
void CreateMsgLinkDialog::copyLinkToClipboard()
|
||||
{
|
||||
QList<QListWidgetItem*> selected = _existing_links_LW->selectedItems() ;
|
||||
|
||||
QList<RetroShareLink> links ;
|
||||
|
||||
for(QList<QListWidgetItem*>::const_iterator it(selected.begin());it!=selected.end();++it)
|
||||
{
|
||||
QUrl text = (*it)->data(Qt::UserRole).toUrl() ;
|
||||
RetroShareLink link(text) ;
|
||||
|
||||
links.push_back(link) ;
|
||||
}
|
||||
|
||||
if(!links.empty())
|
||||
RSLinkClipboard::copyLinks(links) ;
|
||||
}
|
||||
|
||||
void CreateMsgLinkDialog::updateCurrentRow(int r)
|
||||
{
|
||||
if(r < 0)
|
||||
|
@ -39,6 +39,7 @@ class CreateMsgLinkDialog : public QDialog, public Ui::CreateMsgLinkDialog
|
||||
void update() ;
|
||||
void toggleCreateLink(bool) ;
|
||||
void updateCurrentRow(int) ;
|
||||
void copyLinkToClipboard() ;
|
||||
|
||||
private:
|
||||
time_t computeValidityDuration() const ;
|
||||
|
@ -73,7 +73,7 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<widget class="QPushButton" name="_copy_to_clipboard_PB">
|
||||
<property name="text">
|
||||
<string>Copy to clipboard</string>
|
||||
</property>
|
||||
|
@ -20,6 +20,8 @@
|
||||
****************************************************************/
|
||||
|
||||
#include <QTimer>
|
||||
#include <QCloseEvent>
|
||||
#include "RsAutoUpdatePage.h"
|
||||
#include "PopupDistantChatDialog.h"
|
||||
|
||||
#define IMAGE_RED_LED ":/images/redled.png"
|
||||
@ -27,24 +29,25 @@
|
||||
#define IMAGE_GRN_LED ":/images/greenled.png"
|
||||
#define IMAGE_GRY_LED ":/images/grayled.png"
|
||||
|
||||
PopupDistantChatDialog::~PopupDistantChatDialog()
|
||||
{
|
||||
delete _tunnel_check_timer ;
|
||||
PopupDistantChatDialog::~PopupDistantChatDialog()
|
||||
{
|
||||
_update_timer->stop() ;
|
||||
delete _update_timer ;
|
||||
}
|
||||
|
||||
PopupDistantChatDialog::PopupDistantChatDialog(QWidget *parent, Qt::WFlags flags)
|
||||
: PopupChatDialog(parent,flags)
|
||||
{
|
||||
_tunnel_check_timer = new QTimer;
|
||||
_tunnel_check_timer->setInterval(1000) ;
|
||||
|
||||
QObject::connect(_tunnel_check_timer,SIGNAL(timeout()),this,SLOT(checkTunnel())) ;
|
||||
|
||||
_tunnel_check_timer->start() ;
|
||||
_status_label = new QLabel ;
|
||||
_update_timer = new QTimer ;
|
||||
|
||||
_update_timer->setInterval(1000) ;
|
||||
QObject::connect(_update_timer,SIGNAL(timeout()),this,SLOT(updateDisplay())) ;
|
||||
|
||||
_update_timer->start() ;
|
||||
|
||||
addChatBarWidget(_status_label) ;
|
||||
checkTunnel() ;
|
||||
updateDisplay() ;
|
||||
}
|
||||
|
||||
void PopupDistantChatDialog::init(const std::string& hash,const QString & title)
|
||||
@ -53,8 +56,11 @@ void PopupDistantChatDialog::init(const std::string& hash,const QString & title)
|
||||
PopupChatDialog::init(hash,title) ;
|
||||
}
|
||||
|
||||
void PopupDistantChatDialog::checkTunnel()
|
||||
void PopupDistantChatDialog::updateDisplay()
|
||||
{
|
||||
if(RsAutoUpdatePage::eventsLocked()) // we need to do that by end, because it's not possible to derive from both PopupChatDialog and RsAutoUpdatePage
|
||||
return ; // which both derive from QObject. Signals-slot connexions won't work anymore.
|
||||
|
||||
if(!isVisible())
|
||||
return ;
|
||||
|
||||
@ -70,23 +76,33 @@ void PopupDistantChatDialog::checkTunnel()
|
||||
{
|
||||
case RS_DISTANT_CHAT_STATUS_UNKNOWN: std::cerr << "Unknown hash. Error!" << std::endl;
|
||||
_status_label->setPixmap(QPixmap(IMAGE_GRY_LED)) ;
|
||||
_status_label->setToolTip(tr("Hash error")) ;
|
||||
_status_label->setToolTip(QObject::tr("Hash error")) ;
|
||||
break ;
|
||||
case RS_DISTANT_CHAT_STATUS_TUNNEL_DN: std::cerr << "Tunnel asked. Waiting for reponse. " << std::endl;
|
||||
_status_label->setPixmap(QPixmap(IMAGE_RED_LED)) ;
|
||||
_status_label->setToolTip(tr("Tunnel is broken")) ;
|
||||
_status_label->setToolTip(QObject::tr("Tunnel is broken")) ;
|
||||
break ;
|
||||
case RS_DISTANT_CHAT_STATUS_TUNNEL_OK: std::cerr << "Tunnel is ok. " << std::endl;
|
||||
_status_label->setPixmap(QPixmap(IMAGE_YEL_LED)) ;
|
||||
_status_label->setToolTip(tr("Tunnel established")) ;
|
||||
_status_label->setToolTip(QObject::tr("Tunnel established")) ;
|
||||
break ;
|
||||
case RS_DISTANT_CHAT_STATUS_CAN_TALK: std::cerr << "Tunnel is ok and works. You can talk!" << std::endl;
|
||||
_status_label->setPixmap(QPixmap(IMAGE_GRN_LED)) ;
|
||||
_status_label->setToolTip(tr("Tunnel is working")) ;
|
||||
_status_label->setToolTip(QObject::tr("Tunnel is working")) ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
void PopupDistantChatDialog::closeEvent(QCloseEvent *e)
|
||||
{
|
||||
std::cerr << "Closing window => closing distant chat for hash " << _hash << std::endl;
|
||||
rsMsgs->closeDistantChatConnexion(_hash) ;
|
||||
|
||||
e->accept() ;
|
||||
|
||||
PopupChatDialog::closeEvent(e) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -95,4 +111,3 @@ void PopupDistantChatDialog::checkTunnel()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "PopupChatDialog.h"
|
||||
|
||||
class QTimer ;
|
||||
class QCloseEvent ;
|
||||
|
||||
class PopupDistantChatDialog: public PopupChatDialog
|
||||
{
|
||||
@ -32,10 +33,7 @@ class PopupDistantChatDialog: public PopupChatDialog
|
||||
|
||||
friend class ChatDialog;
|
||||
|
||||
public slots:
|
||||
void checkTunnel() ;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
/** Default constructor */
|
||||
PopupDistantChatDialog(QWidget *parent = 0, Qt::WFlags flags = 0);
|
||||
/** Default destructor */
|
||||
@ -43,8 +41,13 @@ protected:
|
||||
|
||||
virtual void init(const std::string& _hash, const QString &title);
|
||||
virtual void updateStatus(int /*status*/) {}
|
||||
virtual void closeEvent(QCloseEvent *e) ;
|
||||
|
||||
QTimer *_tunnel_check_timer ;
|
||||
protected slots:
|
||||
void updateDisplay() ; // overloads RsAutoUpdatePage
|
||||
|
||||
private:
|
||||
QTimer *_update_timer ;
|
||||
std::string _hash ;
|
||||
std::string _virtual_peer_id ;
|
||||
QLabel *_status_label ;
|
||||
|
Loading…
x
Reference in New Issue
Block a user