From 06065ef62359991df2e859e36e93d3e70fb6be44 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 18 Nov 2014 15:55:31 +0000 Subject: [PATCH] added selection of which identity we talk as when multiple GXS identities are available git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7691 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/chat/distantchat.cc | 34 +++++++++------- libretroshare/src/chat/distantchat.h | 2 +- libretroshare/src/retroshare/rsmsgs.h | 2 +- libretroshare/src/rsserver/p3msgs.cc | 4 +- libretroshare/src/rsserver/p3msgs.h | 2 +- retroshare-gui/src/gui/Identity/IdDialog.cpp | 42 ++++++++++++++++---- 6 files changed, 60 insertions(+), 26 deletions(-) diff --git a/libretroshare/src/chat/distantchat.cc b/libretroshare/src/chat/distantchat.cc index 9916dc31b..7d16c1d36 100644 --- a/libretroshare/src/chat/distantchat.cc +++ b/libretroshare/src/chat/distantchat.cc @@ -501,8 +501,6 @@ void DistantChatService::handleRecvDHPublicKey(RsChatDHPublicKeyItem *item) // Looks for the DH params. If not there yet, create them. // - bool should_send = false ; - int size = DH_size(it->second.dh) ; unsigned char *key_buff = new unsigned char[size] ; @@ -777,31 +775,39 @@ void DistantChatService::sendTurtleData(RsChatItem *item) mTurtle->sendTurtleData(virtual_peer_id,gitem) ; } -bool DistantChatService::initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code) +bool DistantChatService::initiateDistantChatConnexion(const RsGxsId& to_gxs_id,const RsGxsId& from_gxs_id,uint32_t& error_code) { - TurtleFileHash hash = hashFromGxsId(gxs_id) ; + TurtleFileHash hash = hashFromGxsId(to_gxs_id) ; // should be a parameter. - std::list lst ; + std::list lst ; mIdService->getOwnIds(lst) ; - if(lst.empty()) - { - std::cerr << " (EE) Cannot start distant chat, since no GXS id is available." << std::endl; - return false ; - } - RsGxsId own_gxs_id = lst.front() ; + bool found = false ; + for(std::list::const_iterator it = lst.begin();it!=lst.end();++it) + if(*it == from_gxs_id) + { + found=true; + break ; + } + + if(!found) + { + std::cerr << " (EE) Cannot start distant chat, since GXS id " << from_gxs_id << " is not available." << std::endl; + return false ; + } + RsGxsId own_gxs_id = from_gxs_id ; // - startClientDistantChatConnection(hash,gxs_id,own_gxs_id) ; + startClientDistantChatConnection(hash,to_gxs_id,own_gxs_id) ; error_code = RS_DISTANT_CHAT_ERROR_NO_ERROR ; // spawn a status item so as to open the chat window. RsChatMsgItem *item = new RsChatMsgItem; - item->message = "Starting distant chat. Please wait for secure tunnel to be established." ; + item->message = "[Starting distant chat. Please wait for secure tunnel to be established.]" ; item->chatFlags = RS_CHAT_FLAG_PRIVATE ; - item->PeerId(RsPeerId(gxs_id)) ; + item->PeerId(RsPeerId(to_gxs_id)) ; handleRecvChatMsgItem(item) ; return true ; diff --git a/libretroshare/src/chat/distantchat.h b/libretroshare/src/chat/distantchat.h index af0311895..39bd1b19b 100644 --- a/libretroshare/src/chat/distantchat.h +++ b/libretroshare/src/chat/distantchat.h @@ -50,7 +50,7 @@ public: // Creates the invite if the public key of the distant peer is available. // Om success, stores the invite in the map above, so that we can respond to tunnel requests. // - bool initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code) ; + bool initiateDistantChatConnexion(const RsGxsId& to_gxs_id,const RsGxsId &from_gxs_id, uint32_t &error_code) ; bool closeDistantChatConnexion(const RsGxsId& pid) ; virtual bool getDistantChatStatus(const RsGxsId &gxs_id,uint32_t &status) ; diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index 9336bca74..4410d9aeb 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -425,7 +425,7 @@ virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::str /* Distant chat */ /****************************************/ -virtual bool initiateDistantChatConnexion(const RsGxsId& pid,uint32_t& error_code) = 0; +virtual bool initiateDistantChatConnexion(const RsGxsId& to_pid,const RsGxsId& from_pid,uint32_t& error_code) = 0; virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status) = 0; virtual bool closeDistantChatConnexion(const RsGxsId& pid) = 0; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index 35fa08f7f..029666c07 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -364,9 +364,9 @@ void p3Msgs::getPendingChatLobbyInvites(std::list& invites) { mChatSrv->getPendingChatLobbyInvites(invites) ; } -bool p3Msgs::initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code) +bool p3Msgs::initiateDistantChatConnexion(const RsGxsId& to_gxs_id,const RsGxsId& from_gxs_id,uint32_t& error_code) { - return mChatSrv->initiateDistantChatConnexion(gxs_id,error_code) ; + return mChatSrv->initiateDistantChatConnexion(to_gxs_id,from_gxs_id,error_code) ; } bool p3Msgs::getDistantChatStatus(const RsGxsId &gxs_id,uint32_t &status) { diff --git a/libretroshare/src/rsserver/p3msgs.h b/libretroshare/src/rsserver/p3msgs.h index 0cea676d4..eb22e6ac7 100644 --- a/libretroshare/src/rsserver/p3msgs.h +++ b/libretroshare/src/rsserver/p3msgs.h @@ -196,7 +196,7 @@ class p3Msgs: public RsMsgs virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id); virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const std::string& lobby_topic,const std::list& invited_friends,uint32_t privacy_type) ; - virtual bool initiateDistantChatConnexion(const RsGxsId& gxs_id,uint32_t& error_code) ; + virtual bool initiateDistantChatConnexion(const RsGxsId& to_gxs_id,const RsGxsId& from_gxs_id,uint32_t& error_code) ; virtual bool getDistantChatStatus(const RsGxsId& gxs_id,uint32_t& status) ; virtual bool closeDistantChatConnexion(const RsGxsId &pid) ; diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 58860a925..0453672b8 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -876,7 +876,7 @@ void IdDialog::loadRequest(const TokenQueue * /*queue*/, const TokenRequest &req case IDDIALOG_IDDETAILS: insertIdDetails(req.mToken); - break; + break; case IDDIALOG_REPLIST: insertRepList(req.mToken); @@ -901,8 +901,31 @@ void IdDialog::IdListCustomPopupMenu( QPoint ) QMenu contextMnu( this ); contextMnu.addAction(ui.editIdentity); - contextMnu.addAction(ui.removeIdentity); - contextMnu.addAction(ui.chatIdentity); + contextMnu.addAction(ui.removeIdentity); + + std::list own_identities ; + rsIdentity->getOwnIds(own_identities) ; + + if(own_identities.size() == 1) + { + QAction * action = contextMnu.addAction(QIcon(),"Chat with this peer",this,SLOT(chatIdentity())); + action->setData(QString::fromStdString((own_identities.front()).toStdString())) ; + } + else + { + QMenu *mnu = contextMnu.addMenu("Chat with this peer as...") ; + + for(std::list::const_iterator it=own_identities.begin();it!=own_identities.end();++it) + { + RsIdentityDetails idd ; + rsIdentity->getIdDetails(*it,idd) ; + + QPixmap pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(*it)) ; + + QAction * action = mnu->addAction(QIcon(pixmap),QString::fromStdString(idd.mNickname) + " (" + QString::fromStdString((*it).toStdString())+ ")",this,SLOT(chatIdentity())); + action->setData(QString::fromStdString((*it).toStdString())) ; + } + } contextMnu.exec(QCursor::pos()); } @@ -917,12 +940,17 @@ void IdDialog::chatIdentity() return; } - std::string keyId = item->text(RSID_COL_KEYID).toStdString(); + std::string keyId = item->text(RSID_COL_KEYID).toStdString(); - uint32_t error_code ; + QAction *action = qobject_cast(QObject::sender()); + if (!action) + return ; - if(!rsMsgs->initiateDistantChatConnexion(RsGxsId(keyId), error_code)) - QMessageBox::information(NULL,"Distant cannot work","Distant chat refused with this peer. Reason: "+QString::number(error_code)) ; + RsGxsId from_gxs_id(action->data().toString().toStdString()); + uint32_t error_code ; + + if(!rsMsgs->initiateDistantChatConnexion(RsGxsId(keyId), from_gxs_id, error_code)) + QMessageBox::information(NULL,"Distant chat cannot work","Distant chat refused with this peer. Error code: "+QString::number(error_code)) ; }