diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index b750d6981..2380ef5f6 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -156,6 +156,7 @@ public: #define RS_DISTANT_CHAT_ERROR_DECRYPTION_FAILED 0x0001 #define RS_DISTANT_CHAT_ERROR_SIGNATURE_MISMATCH 0x0002 #define RS_DISTANT_CHAT_ERROR_UNKNOWN_KEY 0x0003 +#define RS_DISTANT_CHAT_ERROR_UNKNOWN_HASH 0x0004 class ChatInfo { @@ -328,9 +329,11 @@ 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 bool initiateDistantChatConnexion(const std::string& encrypted_string,time_t validity_time,std::string& hash,uint32_t& error_code) = 0; +virtual bool initiateDistantChatConnexion(const 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; +virtual bool removeDistantChatInvite(const std::string& hash) = 0 ; }; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index c1ba30b1c..296ebde31 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -352,9 +352,13 @@ bool p3Msgs::getDistantChatInviteList(std::vector& invite { return mChatSrv->getDistantChatInviteList(invites) ; } -bool p3Msgs::initiateDistantChatConnexion(const std::string& encrypted_str,std::string& hash,uint32_t& error_code) +bool p3Msgs::initiateDistantChatConnexion(const std::string& encrypted_str,time_t validity_time,std::string& hash,uint32_t& error_code) { - return mChatSrv->initiateDistantChatConnexion(encrypted_str,hash,error_code) ; + return mChatSrv->initiateDistantChatConnexion(encrypted_str,validity_time,hash,error_code) ; +} +bool p3Msgs::initiateDistantChatConnexion(const std::string& hash,uint32_t& error_code) +{ + return mChatSrv->initiateDistantChatConnexion(hash,error_code) ; } bool p3Msgs::getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) { @@ -364,4 +368,8 @@ bool p3Msgs::closeDistantChatConnexion(const std::string& hash) { return mChatSrv->closeDistantChatConnexion(hash) ; } +bool p3Msgs::removeDistantChatInvite(const std::string& hash) +{ + return mChatSrv->removeDistantChatInvite(hash) ; +} diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 565e56086..4a5084af6 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -189,9 +189,11 @@ 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 bool initiateDistantChatConnexion(const std::string& encrypted_string,time_t validity_time,std::string& hash,uint32_t& error_code) ; + virtual bool initiateDistantChatConnexion(const 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) ; + virtual bool removeDistantChatInvite(const std::string& hash) ; private: diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index f10854eb5..e3a2cd43d 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -49,6 +49,7 @@ * #define CHAT_DEBUG 1 * #define DEBUG_DISTANT_CHAT 1 ****/ +#define DEBUG_DISTANT_CHAT 1 static const int CONNECTION_CHALLENGE_MAX_COUNT = 20 ; // sends a connexion challenge every 20 messages static const time_t CONNECTION_CHALLENGE_MAX_MSG_AGE = 30 ; // maximum age of a message to be used in a connexion challenge @@ -3233,10 +3234,8 @@ bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t tim return true ; } -bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_str,std::string& hash,uint32_t& error_code) +bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_str,time_t time_of_validity,std::string& hash,uint32_t& error_code) { - RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ - // Un-radix the string. // char *encrypted_data_bin = NULL ; @@ -3283,19 +3282,87 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st #ifdef DEBUG_DISTANT_CHAT std::cerr << "Signature successfuly verified!" << std::endl; #endif - hash = t_RsGenericIdType(data).toStdString(false) ; + + startClientDistantChatConnection(hash,pgp_id.toStdString(),data+DISTANT_CHAT_HASH_SIZE) ; + + // Finally, save the decrypted chat info, so that we can display some info in the GUI in case we want to re-use the link + // + DistantChatInvite dinvite ; + + dinvite.encrypted_radix64_string = "" ; // means that it's not issued by us + dinvite.destination_pgp_id = pgp_id.toStdString() ; + dinvite.time_of_validity = time_of_validity ; + dinvite.last_hit_time = time(NULL) ; + memcpy(dinvite.aes_key,data+DISTANT_CHAT_HASH_SIZE,DISTANT_CHAT_AES_KEY_SIZE) ; + + { + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + _distant_chat_invites[hash] = dinvite ; + } +#ifdef DEBUG_DISTANT_CHAT + std::cerr << "Saving info for decrypted link, for later use:" << std::endl; + std::cerr << " destination pgp id: " << dinvite.destination_pgp_id << std::endl; + std::cerr << " validity : " << dinvite.time_of_validity << std::endl; + std::cerr << " last hit time : " << dinvite.last_hit_time << std::endl; +#endif + + delete[] data ; + + // And notify about chatting. + + error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ; + getPqiNotify()->AddPopupMessage(RS_POPUP_CHAT, hash, "Distant peer", "Conversation starts..."); + + // Save config, since a new invite was added. + // + IndicateConfigChanged() ; + return true ; +} + +bool p3ChatService::initiateDistantChatConnexion(const std::string& hash,uint32_t& error_code) +{ + std::string pgp_id ; + unsigned char aes_key[DISTANT_CHAT_AES_KEY_SIZE] ; + + { + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + + std::map::iterator it = _distant_chat_invites.find(hash) ; + + if(it == _distant_chat_invites.end()) + { + error_code = RS_DISTANT_CHAT_ERROR_UNKNOWN_HASH ; + return false ; + } + it->second.last_hit_time = time(NULL) ; + pgp_id = it->second.destination_pgp_id; + + memcpy(aes_key,it->second.aes_key,DISTANT_CHAT_AES_KEY_SIZE) ; + } + + startClientDistantChatConnection(hash,pgp_id,aes_key) ; + + getPqiNotify()->AddPopupMessage(RS_POPUP_CHAT, hash, "Distant peer", "Conversation starts..."); + + error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ; + return true ; +} + +void p3ChatService::startClientDistantChatConnection(const std::string& hash,const std::string& pgp_id,const unsigned char *aes_key_buf) +{ DistantChatPeerInfo info ; info.last_contact = time(NULL) ; info.status = RS_DISTANT_CHAT_STATUS_TUNNEL_DN ; - info.pgp_id = pgp_id.toStdString() ; + info.pgp_id = pgp_id ; info.direction = RsTurtleGenericTunnelItem::DIRECTION_SERVER ; - memcpy(info.aes_key,data+DISTANT_CHAT_HASH_SIZE,DISTANT_CHAT_AES_KEY_SIZE) ; + memcpy(info.aes_key,aes_key_buf,DISTANT_CHAT_AES_KEY_SIZE) ; - _distant_chat_peers[hash] = info ; - - delete[] data ; + { + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + _distant_chat_peers[hash] = info ; + } // Now ask the turtle router to manage a tunnel for that hash. @@ -3304,13 +3371,6 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st #endif mTurtle->monitorTunnels(hash,this) ; - - // And notify about chatting. - - error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ; - - getPqiNotify()->AddPopupMessage(RS_POPUP_CHAT, hash, "Distant peer", "Conversation starts..."); - return true ; } void p3ChatService::cleanDistantChatInvites() @@ -3445,7 +3505,23 @@ void p3ChatService::markDistantChatAsClosed(const std::string& hash) it->second.status = RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED ; } - +bool p3ChatService::removeDistantChatInvite(const std::string& hash) +{ + RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/ + std::map::iterator it = _distant_chat_invites.find(hash) ; + + if(it == _distant_chat_invites.end()) // server side. Nothing to do. + { + std::cerr << "Cannot find distant chat invite for hash " << hash << std::endl; + return false; + } + + _distant_chat_invites.erase(it) ; + + IndicateConfigChanged() ; + + return true ; +} diff --git a/libretroshare/src/services/p3chatservice.h b/libretroshare/src/services/p3chatservice.h index b4003f14c..34fd30d02 100644 --- a/libretroshare/src/services/p3chatservice.h +++ b/libretroshare/src/services/p3chatservice.h @@ -312,8 +312,10 @@ 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) ; + bool initiateDistantChatConnexion(const std::string& encrypted_string,time_t time_of_validity,std::string& hash,uint32_t& error_code) ; // from encrypted data + bool initiateDistantChatConnexion(const std::string& hash,uint32_t& error_code) ; // from known hash of a decrypted link bool closeDistantChatConnexion(const std::string& hash) ; + bool removeDistantChatInvite(const std::string& hash) ; virtual bool getDistantChatStatus(const std::string& hash,uint32_t& status,std::string& pgp_id) ; @@ -352,6 +354,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi void addVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&,RsTurtleGenericTunnelItem::Direction dir) ; void removeVirtualPeer(const TurtleFileHash&, const TurtleVirtualPeerId&) ; void markDistantChatAsClosed(const TurtleFileHash& hash) ; + void startClientDistantChatConnection(const std::string& hash,const std::string& pgp_id,const unsigned char *aes_key_buf) ; // Utility functions diff --git a/retroshare-gui/src/gui/CreateMsgLinkDialog.cpp b/retroshare-gui/src/gui/CreateMsgLinkDialog.cpp index 0ea17394d..752454f0f 100644 --- a/retroshare-gui/src/gui/CreateMsgLinkDialog.cpp +++ b/retroshare-gui/src/gui/CreateMsgLinkDialog.cpp @@ -36,145 +36,23 @@ CreateMsgLinkDialog::CreateMsgLinkDialog() setAttribute(Qt::WA_DeleteOnClose, false); - _info_GB->layout()->addWidget( _gpg_selection = new FriendSelectionWidget(this) ) ; - - QObject::connect(_link_type_CB,SIGNAL(currentIndexChanged(int)),this,SLOT(update())) ; + layout()->addWidget( _gpg_selection = new FriendSelectionWidget(this) ) ; 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) ; _gpg_selection->setHeaderText(QObject::tr("Select who can contact you:")) ; _gpg_selection->start() ; - toggleCreateLink(false) ; + layout()->update() ; update() ; - updateCurrentRow(-1) ; } -void CreateMsgLinkDialog::copyLinkToClipboard() +void CreateMsgLinkDialog::createNewChatLink() { - QList selected = _existing_links_LW->selectedItems() ; - - QList links ; - - for(QList::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) - { - _current_link_type_LE->setText("") ; - _current_link_dst_LE->setText("") ; - _current_link_date_DE->setDateTime(QDateTime::fromTime_t(0)) ; - return ; - } - - QUrl text = _existing_links_LW->item(r)->data(Qt::UserRole).toUrl() ; - - std::cerr << "Parsing link : " << text.toString().toStdString() << std::endl; - RetroShareLink link(text) ; - - RsPeerDetails detail ; - rsPeers->getPeerDetails(link.GPGId().toStdString(),detail) ; - - if( link.type() == RetroShareLink::TYPE_PRIVATE_CHAT ) - { - _current_link_type_LE->setText( tr("Private chat invite") ) ; - _usable_LB->setText(tr("Usable only by :")) ; - } - else - { - _current_link_type_LE->setText( tr("Public message invite") ) ; - _usable_LB->setText(tr("Usable to contact :")) ; - } - - _current_link_dst_LE->setText(QString::fromStdString(detail.name)+" ("+link.GPGId()+")") ; - _current_link_date_DE->setDateTime(QDateTime::fromTime_t(link.timeStamp())) ; -} - -void CreateMsgLinkDialog::toggleCreateLink(bool b) -{ - _new_link_F->setHidden(!b) ; -} -void CreateMsgLinkDialog::update() -{ - if(_link_type_CB->currentIndex() == 0) - { - QString s ; - - s += "A private chat invite allows a specific peer to contact you using encrypted private chat. You need to select a destination peer from your PGP keyring before creating the link. The link contains the encryption code and your PGP signature, so that the peer can authenticate you." ; - - _info_TB->setHtml(s) ; - _gpg_selection->setHidden(false) ; - } - else - { - QString s ; - - s += "A public message link allows any peer in the nearby network to send a private message to you. The message is encrypted and only you can read it." ; - - _info_TB->setHtml(s) ; - _gpg_selection->setHidden(true) ; - } - - std::vector invites ; - - rsMsgs->getDistantChatInviteList(invites) ; - - _existing_links_LW->clear() ; - - for(uint32_t i=0;igetPeerDetails(link.GPGId().toStdString(),detail) ; - - QListWidgetItem *item = new QListWidgetItem; - item->setData(Qt::DisplayRole,tr("Private chat invite to ")+QString::fromStdString(detail.name)+" ("+QString::fromStdString(invites[i].destination_pgp_id)+")") ; - item->setData(Qt::UserRole,link.toString()) ; - - _existing_links_LW->insertItem(0,item) ; - } - - std::vector invites2 ; - rsMsgs->getDistantOfflineMessengingInvites(invites2) ; - - for(uint32_t i=0;isetData(Qt::DisplayRole,tr("Public message link")) ; - item->setData(Qt::UserRole,link.toString()) ; - - _existing_links_LW->insertItem(0,item) ; - } - } - - + std::cerr << "In static method..." << std::endl; + CreateMsgLinkDialog dialog ; + dialog.exec() ; } time_t CreateMsgLinkDialog::computeValidityDuration() const @@ -203,8 +81,6 @@ void CreateMsgLinkDialog::createLink() { std::cerr << "Creating link!" << std::endl; - if(_link_type_CB->currentIndex() == 0) - { time_t validity_duration = computeValidityDuration() ; FriendSelectionWidget::IdType type ; std::string current_pgp_id = _gpg_selection->selectedId(type) ; @@ -226,10 +102,11 @@ void CreateMsgLinkDialog::createLink() if(!res) QMessageBox::critical(NULL,tr("Private chat invite creation failed"),tr("The creation of the chat invite failed")) ; else - QMessageBox::information(NULL,tr("Private chat invite created"),tr("Your new chat invite has been copied to clipboard. You can now paste it as a Retroshare link.")) ; - } - else - { + QMessageBox::information(NULL,tr("Private chat invite created"),tr("Your new chat invite has been created. You can now copy/paste it as a Retroshare link.")) ; + +#ifdef TO_REMOVE + /* OLD CODE TO CREATE A MSG LINK */ + time_t validity_duration = computeValidityDuration() ; std::string hash; std::string issuer_pgp_id = rsPeers->getGPGOwnId() ; @@ -253,8 +130,6 @@ void CreateMsgLinkDialog::createLink() QMessageBox::critical(NULL,tr("Messenging invite creation failed"),tr("The creation of the messenging invite failed")) ; else QMessageBox::information(NULL,tr("Messenging invite created"),tr("Your new messenging chat invite has been copied to clipboard. You can now paste it as a Retroshare link.")) ; - } - - QTimer::singleShot(100,this,SLOT(update())) ; +#endif } diff --git a/retroshare-gui/src/gui/CreateMsgLinkDialog.h b/retroshare-gui/src/gui/CreateMsgLinkDialog.h index 6120e5071..1a7656fe7 100644 --- a/retroshare-gui/src/gui/CreateMsgLinkDialog.h +++ b/retroshare-gui/src/gui/CreateMsgLinkDialog.h @@ -30,16 +30,15 @@ class CreateMsgLinkDialog : public QDialog, public Ui::CreateMsgLinkDialog Q_OBJECT public: + static void createNewChatLink() ; + + protected: CreateMsgLinkDialog(); virtual ~CreateMsgLinkDialog() {} private slots: /* actions to take.... */ void createLink(); - void update() ; - void toggleCreateLink(bool) ; - void updateCurrentRow(int) ; - void copyLinkToClipboard() ; private: time_t computeValidityDuration() const ; diff --git a/retroshare-gui/src/gui/CreateMsgLinkDialog.ui b/retroshare-gui/src/gui/CreateMsgLinkDialog.ui index 0e9d38e1c..89e873df5 100644 --- a/retroshare-gui/src/gui/CreateMsgLinkDialog.ui +++ b/retroshare-gui/src/gui/CreateMsgLinkDialog.ui @@ -7,94 +7,13 @@ 0 0 590 - 388 + 179 - Dialog + Create distant chat invite - - - - - - - 0 - 0 - - - - - - - - - - - - - - Valid until: - - - - - - - Type: - - - - - - - Usable by: - - - - - - - - - - - - - - - - - - - - - - - - - - Copy to clipboard - - - - - - - Create new - - - true - - - - - - - - - @@ -105,113 +24,99 @@ - - - - - Invite type: - - - - - - - - Private chat - - - - - Public message - - - - - - - - Validity time : - - - - - - - 1 - - - 30 - - - 5 - - - - - - - - hour - - - - - day - - - - - week - - - - - month - - - - - year - - - - - - - - Create! - - - - - - - - - Information + + + <html><head/><body><p align="justify">To create a private chat invite for a non-friend person, select his key below and a validity time for your invite, then press &quot;Create&quot;. The invite will contain the information required to open a tunnel to chat with you. </p><p align="justify">The invite is encrypted, and does not reveal your identity. Only the selected peer can decrypt the link, and use it to contact you.</p></body></html> + + + Qt::RichText + + + true + + + true - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - + + + + + Invite type: + + + + + + + + Private chat + + + + + + + + Validity time : + + + + + + + 1 + + + 30 + + + 5 + + + + + + + + hour + + + + + day + + + + + week + + + + + month + + + + + year + + + + + + + + Create! + + + + diff --git a/retroshare-gui/src/gui/NetworkDialog.cpp b/retroshare-gui/src/gui/NetworkDialog.cpp index 46dc67654..b96e45b56 100644 --- a/retroshare-gui/src/gui/NetworkDialog.cpp +++ b/retroshare-gui/src/gui/NetworkDialog.cpp @@ -231,10 +231,6 @@ void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint /*point*/ ) contextMnu->addAction(QIcon(IMAGE_PEERDETAILS), tr("Peer details..."), this, SLOT(peerdetails())); contextMnu->addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyLink())); contextMnu->addSeparator() ; -#ifdef ENABLE_DISTANT_CHAT_AND_MSGS - contextMnu->addAction(QIcon(IMAGE_COPYLINK), tr("Create a distant chat invitation..."), this, SLOT(createChatLink())); - contextMnu->addSeparator() ; -#endif contextMnu->addAction(QIcon(IMAGE_CLEAN_UNUSED), tr("Remove unused keys..."), this, SLOT(removeUnusedKeys())); contextMnu->exec(QCursor::pos()); @@ -334,19 +330,6 @@ void NetworkDialog::makeFriend() ConfCertDialog::showIt(getCurrentNeighbour()->text(COLUMN_PEERID).toStdString(), ConfCertDialog::PageTrust); } -void NetworkDialog::createChatLink() -{ - std::string pgp_id = getCurrentNeighbour()->text(COLUMN_PEERID).toStdString() ; - - std::cerr << "Creating chat link for pgp id " << pgp_id << std::endl; - - std::string hash,estr ; - rsMsgs->createDistantChatInvite(pgp_id,time(NULL)+3600,estr) ; - - std::cerr << "Created invite:" << std::endl; - std::cerr << " estr = " << estr << std::endl; -} - /** Shows Peer Information/Auth Dialog */ void NetworkDialog::peerdetails() { diff --git a/retroshare-gui/src/gui/NetworkDialog.h b/retroshare-gui/src/gui/NetworkDialog.h index b15228698..036b2cf30 100644 --- a/retroshare-gui/src/gui/NetworkDialog.h +++ b/retroshare-gui/src/gui/NetworkDialog.h @@ -69,7 +69,6 @@ private slots: void removeUnusedKeys() ; void makeFriend() ; void denyFriend() ; - void createChatLink() ; void deleteCert() ; void peerdetails(); void copyLink(); diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index b52f1d981..e158f5cb9 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -1226,7 +1226,7 @@ static void processList(const QStringList &list, const QString &textSingular, co std::string hash ; uint32_t error_code ; - if(!rsMsgs->initiateDistantChatConnexion(link._encrypted_chat_info.toStdString(),hash,error_code)) + if(!rsMsgs->initiateDistantChatConnexion(link._encrypted_chat_info.toStdString(),link._time_stamp,hash,error_code)) { QString error_msg ; switch(error_code) diff --git a/retroshare-gui/src/gui/chat/ChatDialog.cpp b/retroshare-gui/src/gui/chat/ChatDialog.cpp index f57460621..ec23b79ab 100644 --- a/retroshare-gui/src/gui/chat/ChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatDialog.cpp @@ -217,6 +217,15 @@ void ChatDialog::init(const std::string &peerId, const QString &title) return; } + std::string distant_chat_pgp_id ; + uint32_t distant_peer_status ; + + if(rsMsgs->getDistantChatStatus(peerId,distant_peer_status,distant_chat_pgp_id)) + { + getChat(peerId,RS_CHAT_OPEN | RS_CHAT_FOCUS); // use own flags + return ; + } + ChatLobbyId lid; if (rsMsgs->isLobbyId(peerId, lid)) { getChat(peerId, RS_CHAT_OPEN | RS_CHAT_FOCUS); diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 64dcb1fef..bc51e8be4 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -38,6 +38,7 @@ #include "gui/RetroShareLink.h" #include "gui/CreateMsgLinkDialog.h" #include "gui/settings/rsharesettings.h" +#include "gui/settings/rsettingswin.h" #include "gui/settings/RsharePeerSettings.h" #include "gui/im_history/ImHistoryBrowser.h" #include "gui/common/StatusDefs.h" @@ -549,9 +550,9 @@ void ChatWidget::contextMenu(QPoint point) QAction *action = contextMnu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste RetroShare Link"), this, SLOT(pasteLink())); action->setDisabled(RSLinkClipboard::empty()); contextMnu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste my certificate link"), this, SLOT(pasteOwnCertificateLink())); -#ifdef ENABLE_DISTANT_CHAT_AND_MSGS - contextMnu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste/Create private chat or Message link..."), this, SLOT(pasteCreateMsgLink())); -#endif +//#ifdef ENABLE_DISTANT_CHAT_AND_MSGS +// contextMnu->addAction(QIcon(":/images/pasterslink.png"), tr("Paste/Create private chat or Message link..."), this, SLOT(pasteCreateMsgLink())); +//#endif contextMnu->exec(QCursor::pos()); delete(contextMnu); @@ -559,10 +560,7 @@ void ChatWidget::contextMenu(QPoint point) void ChatWidget::pasteCreateMsgLink() { - CreateMsgLinkDialog dialog ; - dialog.exec() ; - - ui->chatTextEdit->insertHtml(RSLinkClipboard::toHtml()); + RSettingsWin::showYourself(this, RSettingsWin::Chat); } void ChatWidget::contextMenuTextBrowser(QPoint point) diff --git a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp index 03f3055d3..7a1826180 100644 --- a/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupDistantChatDialog.cpp @@ -95,7 +95,7 @@ void PopupDistantChatDialog::updateDisplay() _status_label->setPixmap(QPixmap(IMAGE_YEL_LED)) ; _status_label->setToolTip(QObject::tr("Secured tunnel established!")) ; break ; - case RS_DISTANT_CHAT_STATUS_CAN_TALK: std::cerr << "Tunnel is ok and works. You can talk!" << std::endl; + case RS_DISTANT_CHAT_STATUS_CAN_TALK: std::cerr << "Tunnel is ok and data is transmitted." << std::endl; _status_label->setPixmap(QPixmap(IMAGE_GRN_LED)) ; _status_label->setToolTip(QObject::tr("Secured tunnel is working")) ; break ; diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp index b07c4596a..c10dbdd58 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp @@ -340,7 +340,7 @@ void FriendSelectionWidget::fillList() gpgItem = new RSTreeWidgetItem(mCompareRole, IDTYPE_GPG); QString name = QString::fromUtf8(detail.name.c_str()); - gpgItem->setText(COLUMN_NAME, name); + gpgItem->setText(COLUMN_NAME, name + " ("+QString::fromStdString(*gpgIt)+")"); sslIds.clear(); rsPeers->getAssociatedSSLIds(*gpgIt, sslIds); diff --git a/retroshare-gui/src/gui/settings/ChatPage.cpp b/retroshare-gui/src/gui/settings/ChatPage.cpp index 27cd2e4e9..b697af116 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.cpp +++ b/retroshare-gui/src/gui/settings/ChatPage.cpp @@ -20,11 +20,18 @@ ****************************************************************/ #include +#include +#include #include #include +#include +#include #include "ChatPage.h" +#include +#include #include "gui/chat/ChatStyle.h" +#include "gui/chat/ChatDialog.h" #include "gui/notifyqt.h" #include "rsharesettings.h" @@ -32,6 +39,10 @@ #include #define VARIANT_STANDARD "Standard" +#define IMAGE_CHAT_CREATE ":/images/add_24x24.png" +#define IMAGE_CHAT_OPEN ":/images/typing.png" +#define IMAGE_CHAT_DELETE ":/images/deletemail24.png" +#define IMAGE_CHAT_COPY ":/images/copyrslink.png" static QString loadStyleInfo(ChatStyle::enumStyleType type, QListWidget *listWidget, QComboBox *comboBox, QString &styleVariant) { @@ -94,12 +105,147 @@ ChatPage::ChatPage(QWidget * parent, Qt::WFlags flags) ui.minimumContrast->hide(); #endif + connect(ui._personal_invites_LW, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(personalInvites_customPopupMenu(QPoint))); + connect(ui._collected_contacts_LW, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(collectedContacts_customPopupMenu(QPoint))); + /* Hide platform specific features */ #ifdef Q_WS_WIN #endif } +void ChatPage::collectedContacts_customPopupMenu(QPoint p) +{ + // items: chat with this person, copy to clipboard, delete + std::cerr << "In custom popup menu" << std::endl; + + QListWidgetItem *item = ui._collected_contacts_LW->itemAt(p) ; + + if(item == NULL) + return ; + + QList selected = ui._collected_contacts_LW->selectedItems() ; + + QMenu contextMnu( this ); + + if(selected.size() == 1) + contextMnu.addAction( QIcon(IMAGE_CHAT_OPEN), tr("Open secured chat tunnel"), this, SLOT(collectedInvite_openDistantChat()) ) ; + + contextMnu.addAction( QIcon(IMAGE_CHAT_DELETE), tr("Delete this invite"), this, SLOT(collectedInvite_delete()) ) ; + + contextMnu.exec(QCursor::pos()); +} + +void ChatPage::collectedInvite_openDistantChat() +{ + QList selected = ui._collected_contacts_LW->selectedItems() ; + + std::string hash = (*selected.begin())->data(Qt::UserRole).toString().toStdString() ; + + std::cerr << "Openning secured chat tunnel for hash " << hash << ". Please wait..." << std::endl; + uint32_t error_code ; + + if(!rsMsgs->initiateDistantChatConnexion(hash,error_code)) + QMessageBox::critical(NULL,tr("Can't open distant chat"),tr("Cannot open distant chat. Error code=")+QString::number(error_code)) ; + else + ChatDialog::chatFriend(hash); +} + +void ChatPage::collectedInvite_delete() +{ + QList selected = ui._collected_contacts_LW->selectedItems() ; + + for(QList::const_iterator it(selected.begin());it!=selected.end();++it) + { + std::string hash = (*it)->data(Qt::UserRole).toString().toStdString() ; + + std::cerr << "Removing chat invite for hash " << hash << std::endl; + + if(!rsMsgs->removeDistantChatInvite(hash)) + QMessageBox::critical(NULL,tr("Can't open distant chat"),tr("Cannot remove distant chat invite.")) ; + } + + load() ; +} + +void ChatPage::personalInvites_customPopupMenu(QPoint p) +{ + // items: create invite, copy to clipboard, delete + std::cerr << "In custom popup menu" << std::endl; + + QList selected = ui._personal_invites_LW->selectedItems() ; + + QMenu contextMnu( this ); + + contextMnu.addAction( QIcon(IMAGE_CHAT_CREATE), tr("Create a chat invitation"), this, SLOT(personalInvites_create()) ) ; + + if(!selected.empty()) + { + contextMnu.addAction( QIcon(IMAGE_CHAT_COPY), tr("Copy link to clipboard"), this, SLOT(personalInvites_copyLink()) ) ; + contextMnu.addAction( QIcon(IMAGE_CHAT_DELETE), tr("Delete this invite"), this, SLOT(personalInvites_delete()) ) ; + } + + contextMnu.exec(QCursor::pos()); +} + +void ChatPage::personalInvites_copyLink() +{ + QList selected = ui._personal_invites_LW->selectedItems() ; + QList links ; + + std::vector invites ; + rsMsgs->getDistantChatInviteList(invites) ; + + for(QList::const_iterator it(selected.begin());it!=selected.end();++it) + { + std::string hash = (*it)->data(Qt::UserRole).toString().toStdString() ; + + bool found = false ; + for(uint32_t i=0;i selected = ui._personal_invites_LW->selectedItems() ; + QList links ; + + for(QList::const_iterator it(selected.begin());it!=selected.end();++it) + { + std::string hash = (*it)->data(Qt::UserRole).toString().toStdString() ; + + rsMsgs->removeDistantChatInvite(hash) ; + } + load() ; +} + +void ChatPage::personalInvites_create() +{ + // Call the link creation box + + CreateMsgLinkDialog::createNewChatLink() ; + + // Now update the page + // + load() ; +} + /** Saves the changes on this page */ bool ChatPage::save(QString &/*errmsg*/) @@ -229,6 +375,37 @@ ChatPage::load() uint chatLobbyFlags = Settings->getChatLobbyFlags(); ui.chatLobby_Blink->setChecked(chatLobbyFlags & RS_CHATLOBBY_BLINK); + + // load personal invites + // + std::vector invites ; + rsMsgs->getDistantChatInviteList(invites) ; + + ui._personal_invites_LW->clear() ; + ui._collected_contacts_LW->clear() ; + + for(uint32_t i=0;igetPeerDetails(invites[i].destination_pgp_id,detail) ; + + if(invites[i].encrypted_radix64_string.empty()) + { + QListWidgetItem *item = new QListWidgetItem; + item->setData(Qt::DisplayRole,tr("Private chat invite from ")+QString::fromStdString(detail.name)+" ("+QString::fromStdString(invites[i].destination_pgp_id)+", " + QString::fromStdString(detail.name) + ", valid until " + QDateTime::fromTime_t(invites[i].time_of_validity).toString() + ")") ; + item->setData(Qt::UserRole,QString::fromStdString(invites[i].hash)) ; + + ui._collected_contacts_LW->insertItem(0,item) ; + } + else + { + QListWidgetItem *item = new QListWidgetItem; + item->setData(Qt::DisplayRole,tr("Private chat invite to ")+QString::fromStdString(detail.name)+" ("+QString::fromStdString(invites[i].destination_pgp_id)+", " + QString::fromStdString(detail.name) + ", valid until " + QDateTime::fromTime_t(invites[i].time_of_validity).toString() + ")") ; + item->setData(Qt::UserRole,QString::fromStdString(invites[i].hash)) ; + + ui._personal_invites_LW->insertItem(0,item) ; + } + } } void ChatPage::on_pushButtonChangeChatFont_clicked() diff --git a/retroshare-gui/src/gui/settings/ChatPage.h b/retroshare-gui/src/gui/settings/ChatPage.h index 6b76ba716..fac3e30d5 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.h +++ b/retroshare-gui/src/gui/settings/ChatPage.h @@ -52,6 +52,16 @@ class ChatPage : public ConfigPage void on_privateList_currentRowChanged(int currentRow); void on_historyList_currentRowChanged(int currentRow); + void personalInvites_customPopupMenu(QPoint) ; + void collectedContacts_customPopupMenu(QPoint) ; + + void personalInvites_copyLink() ; + void personalInvites_delete() ; + void personalInvites_create() ; + + void collectedInvite_openDistantChat() ; + void collectedInvite_delete() ; + private: void setPreviewMessages(QString &stylePath, QString styleVariant, QTextBrowser *textBrowser); void fillPreview(QListWidget *listWidget, QComboBox *comboBox, QTextBrowser *textBrowser); diff --git a/retroshare-gui/src/gui/settings/ChatPage.ui b/retroshare-gui/src/gui/settings/ChatPage.ui index 2810fb58d..00d2194c2 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.ui +++ b/retroshare-gui/src/gui/settings/ChatPage.ui @@ -6,15 +6,15 @@ 0 0 - 444 - 390 + 646 + 544 - 0 + 1 @@ -317,6 +317,67 @@ + + + Distant chat + + + + + + + 0 + 0 + + + + <html><head/><body><p align="justify">Retroshare allows you to anonymously chat to nearby people beyond your friends in the network, using encrypted tunnels. In your personal invites list you keep chat links for people to contact you. In the &quot;collected contacts&quot; list, you keep such chat links that people sent you to contact them.</p></body></html> + + + Qt::RichText + + + true + + + true + + + + + + + Your personnal invites + + + + + + Qt::CustomContextMenu + + + + + + + + + + Collected contacts + + + + + + Qt::CustomContextMenu + + + + + + + + History