From cb9f174efa55ac6532b808a2ddaf3a8150fe7f2b Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 23 Apr 2013 22:43:19 +0000 Subject: [PATCH] added tunnel state light to distant chat popup dialog. Added proper peer name. Changed method for adding widgets in the chat bar git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-GenericTunneling@6337 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsmsgs.h | 2 +- libretroshare/src/rsserver/p3msgs.cc | 4 ++-- libretroshare/src/rsserver/p3msgs.h | 2 +- libretroshare/src/services/p3chatservice.cc | 20 +++++++++++------- libretroshare/src/services/p3chatservice.h | 4 +++- plugins/VOIP/gui/AudioPopupChatDialog.cpp | 4 ++-- retroshare-gui/src/gui/chat/ChatDialog.cpp | 8 ++++--- .../src/gui/chat/ChatLobbyDialog.cpp | 4 ++-- retroshare-gui/src/gui/chat/ChatWidget.cpp | 4 ++-- retroshare-gui/src/gui/chat/ChatWidget.h | 2 +- .../src/gui/chat/PopupChatDialog.cpp | 4 ++-- retroshare-gui/src/gui/chat/PopupChatDialog.h | 2 +- .../src/gui/chat/PopupDistantChatDialog.cpp | 21 ++++++++++++++++++- .../src/gui/chat/PopupDistantChatDialog.h | 1 + 14 files changed, 56 insertions(+), 26 deletions(-) diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index f875af0b4..15c7314f5 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -312,7 +312,7 @@ virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::str virtual bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_string) = 0 ; virtual bool getDistantChatInviteList(std::vector& invites) = 0; virtual bool initiateDistantChatConnexion(const std::string& encrypted_string,std::string& hash,uint32_t& error_code) = 0; -virtual uint32_t getDistantChatStatus(const std::string& hash) = 0; +virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) = 0; }; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index b69b9f280..e36998dac 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -342,8 +342,8 @@ bool p3Msgs::initiateDistantChatConnexion(const std::string& encrypted_str,std:: { return mChatSrv->initiateDistantChatConnexion(encrypted_str,hash,error_code) ; } -uint32_t p3Msgs::getDistantChatStatus(const std::string& hash) +bool p3Msgs::getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) { - return mChatSrv->getDistantChatStatus(hash) ; + return mChatSrv->getDistantChatStatus(hash,status,pgp_id) ; } diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 8fbe7f3bb..217b5fa98 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -186,7 +186,7 @@ class p3Msgs: public RsMsgs virtual bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,std::string& encrypted_string) ; virtual bool getDistantChatInviteList(std::vector& invites); virtual bool initiateDistantChatConnexion(const std::string& encrypted_string,std::string& hash,uint32_t& error_code) ; - virtual uint32_t getDistantChatStatus(const std::string& hash) ; + virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) ; private: diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index b4c0ce094..da40f1bd3 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -420,12 +420,13 @@ bool p3ChatService::isOnline(const std::string& id) { // check if the id is a tunnel id or a peer id. - uint32_t res = getDistantChatStatus(id) ; + uint32_t status ; + std::string pgp_id ; - if(!res) + if(!getDistantChatStatus(id,status,pgp_id)) return mLinkMgr->isOnline(id) ; - return res == RS_DISTANT_CHAT_STATUS_TUNNEL_OK ; + return true ; } bool p3ChatService::sendPrivateChat(const std::string &id, const std::wstring &msg) @@ -2897,6 +2898,7 @@ void p3ChatService::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtua info.last_contact = now ; info.status = RS_DISTANT_CHAT_STATUS_TUNNEL_OK ; info.virtual_peer_id = virtual_peer_id ; + info.pgp_id = it->second.destination_pgp_id ; memcpy(info.aes_key,it->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ; _distant_chat_peers[hash] = info ; @@ -3226,6 +3228,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() ; memcpy(info.aes_key,data+DISTANT_CHAT_HASH_SIZE,DISTANT_CHAT_AES_KEY_SIZE) ; _distant_chat_peers[hash] = info ; @@ -3286,16 +3289,19 @@ bool p3ChatService::getDistantChatInviteList(std::vector& return true ; } -uint32_t p3ChatService::getDistantChatStatus(const std::string& hash) +bool p3ChatService::getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) { RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ std::map::const_iterator it = _distant_chat_peers.find(hash) ; if(it == _distant_chat_peers.end()) - return RS_DISTANT_CHAT_STATUS_UNKNOWN ; - else - return it->second.status ; + return false ; + + status = it->second.status ; + pgp_id = it->second.pgp_id ; + + return true ; } diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index 666863334..ed4481828 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -313,7 +313,8 @@ 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& invites) ; bool initiateDistantChatConnexion(const std::string& encrypted_string,std::string& hash,uint32_t& error_code) ; - virtual uint32_t getDistantChatStatus(const std::string& hash) ; + + virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) ; private: struct DistantChatInvite @@ -330,6 +331,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi unsigned char aes_key[16] ; // key to encrypt packets 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. }; // This map contains the ongoing invites. This is the list where to look to diff --git a/plugins/VOIP/gui/AudioPopupChatDialog.cpp b/plugins/VOIP/gui/AudioPopupChatDialog.cpp index 71135ccf6..75afbf264 100644 --- a/plugins/VOIP/gui/AudioPopupChatDialog.cpp +++ b/plugins/VOIP/gui/AudioPopupChatDialog.cpp @@ -49,8 +49,8 @@ AudioPopupChatDialog::AudioPopupChatDialog(QWidget *parent) connect(audioListenToggleButton, SIGNAL(clicked()), this , SLOT(toggleAudioListen())); connect(audioMuteCaptureToggleButton, SIGNAL(clicked()), this , SLOT(toggleAudioMuteCapture())); - addButton(audioListenToggleButton) ; - addButton(audioMuteCaptureToggleButton) ; + addChatBarWidget(audioListenToggleButton) ; + addChatBarWidget(audioMuteCaptureToggleButton) ; //ui.chatWidget->resetStatusBar(); diff --git a/retroshare-gui/src/gui/chat/ChatDialog.cpp b/retroshare-gui/src/gui/chat/ChatDialog.cpp index 22721e84c..d4f55869a 100644 --- a/retroshare-gui/src/gui/chat/ChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatDialog.cpp @@ -100,10 +100,10 @@ void ChatDialog::init(const std::string &peerId, const QString &title) } uint32_t distant_peer_status ; + std::string distant_chat_pgp_id ; - if(distant_peer_status = rsMsgs->getDistantChatStatus(peerId)) { + if(rsMsgs->getDistantChatStatus(peerId,distant_peer_status,distant_chat_pgp_id)) chatflags = RS_CHAT_OPEN | RS_CHAT_FOCUS; // use own flags - } if (chatflags & RS_CHAT_OPEN) { if (lobby_id) { @@ -120,7 +120,9 @@ void ChatDialog::init(const std::string &peerId, const QString &title) } else if(distant_peer_status > 0) { cd = new PopupDistantChatDialog(); chatDialogs[peerId] = cd; - cd->init(peerId, tr("Distant peer (PGP id=%1)")) ; + std::string peer_name = rsPeers->getGPGName(distant_chat_pgp_id) ; + cd->init(peerId, tr("Talking to ")+QString::fromStdString(peer_name)+" (PGP id="+QString::fromStdString(distant_chat_pgp_id)+")") ; + } else { RsPeerDetails sslDetails; if (rsPeers->getPeerDetails(peerId, sslDetails)) { diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp index 604002e02..5c831b4e2 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp @@ -78,7 +78,7 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::WF connect(inviteFriendsButton, SIGNAL(clicked()), this , SLOT(inviteFriends())); - getChatWidget()->addChatButton(inviteFriendsButton) ; + getChatWidget()->addChatBarWidget(inviteFriendsButton) ; unsubscribeButton = new QPushButton ; unsubscribeButton->setMinimumSize(QSize(28,28)) ; @@ -95,7 +95,7 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::WF connect(unsubscribeButton, SIGNAL(clicked()), this , SLOT(leaveLobby())); - getChatWidget()->addChatButton(unsubscribeButton) ; + getChatWidget()->addChatBarWidget(unsubscribeButton) ; } void ChatLobbyDialog::leaveLobby() diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index bfe00445e..5ec998adf 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -140,9 +140,9 @@ void ChatWidget::setDefaultExtraFileFlags(TransferRequestFlags fl) ui->hashBox->setDefaultTransferRequestFlags(fl) ; } -void ChatWidget::addChatButton(QPushButton *button) +void ChatWidget::addChatBarWidget(QWidget *w) { - ui->toolBarFrame->layout()->addWidget(button) ; + ui->toolBarFrame->layout()->addWidget(w) ; } void ChatWidget::init(const std::string &peerId, const QString &title) diff --git a/retroshare-gui/src/gui/chat/ChatWidget.h b/retroshare-gui/src/gui/chat/ChatWidget.h index 831158121..a7aff6b15 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.h +++ b/retroshare-gui/src/gui/chat/ChatWidget.h @@ -73,7 +73,7 @@ public: bool setStyle(); const RSStyle *getStyle() { return &style; } - void addChatButton(QPushButton *button) ; + void addChatBarWidget(QWidget *w) ; bool isActive(); void setDefaultExtraFileFlags(TransferRequestFlags f) ; diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index 9c4afeb50..1692ad048 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -141,9 +141,9 @@ void PopupChatDialog::addIncomingChatMsg(const ChatInfo& info) } } -void PopupChatDialog::addButton(QPushButton *button) +void PopupChatDialog::addChatBarWidget(QWidget *w) { - getChatWidget()->addChatButton(button) ; + getChatWidget()->addChatBarWidget(w) ; } void PopupChatDialog::onChatChanged(int list, int type) diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.h b/retroshare-gui/src/gui/chat/PopupChatDialog.h index 620d84afc..a53aa24dd 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.h @@ -57,7 +57,7 @@ protected: void processSettings(bool load); // used by plugins - void addButton(QPushButton *button) ; + void addChatBarWidget(QWidget *w) ; protected: virtual void addIncomingChatMsg(const ChatInfo& info); diff --git a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp index 5f7149bf0..9bd826db4 100644 --- a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp @@ -22,6 +22,11 @@ #include #include "PopupDistantChatDialog.h" +#define IMAGE_RED_LED ":/images/redled.png" +#define IMAGE_YEL_LED ":/images/yellowled.png" +#define IMAGE_GRN_LED ":/images/greenled.png" +#define IMAGE_GRY_LED ":/images/grayled.png" + PopupDistantChatDialog::~PopupDistantChatDialog() { delete _tunnel_check_timer ; @@ -36,6 +41,10 @@ PopupDistantChatDialog::PopupDistantChatDialog(QWidget *parent, Qt::WFlags flags QObject::connect(_tunnel_check_timer,SIGNAL(timeout()),this,SLOT(checkTunnel())) ; _tunnel_check_timer->start() ; + _status_label = new QLabel ; + + addChatBarWidget(_status_label) ; + checkTunnel() ; } void PopupDistantChatDialog::init(const std::string& hash,const QString & title) @@ -53,17 +62,27 @@ void PopupDistantChatDialog::checkTunnel() // make sure about the tunnel status // - uint32_t status = rsMsgs->getDistantChatStatus(_hash) ; + uint32_t status= RS_DISTANT_CHAT_STATUS_UNKNOWN; + std::string pgp_id ; + rsMsgs->getDistantChatStatus(_hash,status,pgp_id) ; switch(status) { case RS_DISTANT_CHAT_STATUS_UNKNOWN: std::cerr << "Unknown hash. Error!" << std::endl; + _status_label->setPixmap(QPixmap(IMAGE_GRY_LED)) ; + _status_label->setText(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->setText(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->setText(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->setText(tr("Tunnel is working")) ; break ; } } diff --git a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.h b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.h index 468b11383..a67c7ba1a 100644 --- a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.h +++ b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.h @@ -47,6 +47,7 @@ protected: QTimer *_tunnel_check_timer ; std::string _hash ; std::string _virtual_peer_id ; + QLabel *_status_label ; };