From 2f6a6a14b1ca265da95a7e7e9579c8c3382fb274 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 6 Mar 2015 20:43:21 +0000 Subject: [PATCH] added menu to select identity when entering lobby; removed debug info git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-LobbiesWithGXSIds@7985 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/chat/distributedchat.cc | 18 +++- retroshare-gui/src/gui/ChatLobbyWidget.cpp | 115 +++++++++++++++------ retroshare-gui/src/gui/ChatLobbyWidget.h | 7 +- 3 files changed, 103 insertions(+), 37 deletions(-) diff --git a/libretroshare/src/chat/distributedchat.cc b/libretroshare/src/chat/distributedchat.cc index 4f5b70c15..0b55a03e6 100644 --- a/libretroshare/src/chat/distributedchat.cc +++ b/libretroshare/src/chat/distributedchat.cc @@ -37,7 +37,7 @@ #include "gxs/gxssecurity.h" #include "services/p3idservice.h" -#define DEBUG_CHAT_LOBBIES 1 +//#define DEBUG_CHAT_LOBBIES 1 static const int CONNECTION_CHALLENGE_MAX_COUNT = 20 ; // sends a connection challenge every 20 messages static const time_t CONNECTION_CHALLENGE_MAX_MSG_AGE = 30 ; // maximum age of a message to be used in a connection challenge @@ -122,7 +122,7 @@ bool DistributedChatService::handleRecvChatLobbyMsgItem(RsChatMsgItem *ci) } if(!checkSignature(cli,cli->PeerId())) // check the object's signature and possibly request missing keys { - std::cerr << "Signature mismatched for this lobby event item: " << std::endl; + std::cerr << "Signature mismatched for this lobby event item. Item will be dropped: " << std::endl; cli->print(std::cerr) ; std::cerr << std::endl; return false; @@ -152,13 +152,17 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const std::list peer_list ; peer_list.push_back(peer_id) ; - bool key_available = mIdService->requestKey(obj->signature.keyId,peer_list); + // network pre-request key to allow message authentication. + + mIdService->requestKey(obj->signature.keyId,peer_list); uint32_t size = obj->signed_serial_size() ; unsigned char *memory = (unsigned char *)malloc(size) ; +#ifdef DEBUG_CHAT_LOBBIES std::cerr << "Checking object signature: " << std::endl; std::cerr << " signature id: " << obj->signature.keyId << std::endl; +#endif if(!obj->serialise_signed_part(memory,size)) { @@ -178,20 +182,26 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const return true ; } +#ifdef DEBUG_CHAT_LOBBIES std::cerr << " key available. " << key_available << std::endl; std::cerr << " data hash: " << RsDirUtil::sha1sum(memory,obj->signed_serial_size()) << std::endl; std::cerr << " signed data: " << RsUtil::BinToHex((char*)memory,obj->signed_serial_size()) << std::endl; +#endif if(!GxsSecurity::validateSignature((const char *)memory,obj->signed_serial_size(),signature_public_key,obj->signature)) { +#ifdef DEBUG_CHAT_LOBBIES std::cerr << " Signature: FAILS." << std::endl; +#endif free(memory) ; return false ; } free(memory) ; +#ifdef DEBUG_CHAT_LOBBIES std::cerr << " signature: CHECKS" << std::endl; +#endif return true ; } @@ -769,8 +779,6 @@ bool DistributedChatService::bounceLobbyObject(RsChatLobbyBouncingObject *item,c if(!locked_bouncingObjectCheck(item,peer_id,lobby.participating_friends.size())) return false; - bool is_message = (NULL != dynamic_cast(item)) ; - // Forward to allparticipating friends, except this peer. for(std::set::const_iterator it(lobby.participating_friends.begin());it!=lobby.participating_friends.end();++it) diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.cpp b/retroshare-gui/src/gui/ChatLobbyWidget.cpp index 86ec122fb..42d2e067c 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.cpp +++ b/retroshare-gui/src/gui/ChatLobbyWidget.cpp @@ -13,11 +13,13 @@ #include "chat/ChatLobbyUserNotify.h" #include "util/HandleRichText.h" #include "util/QtVersion.h" -#include +#include "gui/settings/rsharesettings.h" +#include "gui/gxs/GxsIdDetails.h" #include "retroshare/rsmsgs.h" #include "retroshare/rspeers.h" #include "retroshare/rsnotify.h" +#include "retroshare/rsidentity.h" #define COLUMN_NAME 0 #define COLUMN_USER_COUNT 1 @@ -212,31 +214,66 @@ void ChatLobbyWidget::lobbyTreeWidgetCustomPopupMenu(QPoint) action->setData(item->data(COLUMN_DATA, ROLE_PRIVACYLEVEL).toInt()); } - if (item && item->type() == TYPE_LOBBY) { - if (item->data(COLUMN_DATA, ROLE_SUBSCRIBED).toBool()) { - contextMnu.addAction(QIcon(IMAGE_UNSUBSCRIBE), tr("Unsubscribe"), this, SLOT(unsubscribeItem())); - } else { - contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Subscribe"), this, SLOT(subscribeItem())); - } - if (item->data(COLUMN_DATA, ROLE_AUTOSUBSCRIBE).toBool()) { - contextMnu.addAction(QIcon(IMAGE_AUTOSUBSCRIBE), tr("Remove Auto Subscribe"), this, SLOT(autoSubscribeItem())); - } else { - contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Add Auto Subscribe"), this, SLOT(autoSubscribeItem())); + if (item && item->type() == TYPE_LOBBY) + { + if (item->data(COLUMN_DATA, ROLE_SUBSCRIBED).toBool()) + contextMnu.addAction(QIcon(IMAGE_UNSUBSCRIBE), tr("Leave this lobby"), this, SLOT(unsubscribeItem())); + else + { + std::list own_identities ; + rsIdentity->getOwnIds(own_identities) ; + + QTreeWidgetItem *item = ui.lobbyTreeWidget->currentItem(); + uint32_t item_flags = item->data(COLUMN_DATA,ROLE_ID).toUInt() ; + + if(own_identities.size() <= 1) + { + QAction *action = contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Enter this lobby"), this, SLOT(subscribeChatLobbyAs())); + + if(own_identities.empty()) + action->setEnabled(false) ; + else + action->setData(QString::fromStdString((own_identities.front()).toStdString())) ; + } + else + { + QMenu *mnu = contextMnu.addMenu(QIcon(IMAGE_SUBSCRIBE),tr("Enter this lobby as...")) ; + + for(std::list::const_iterator it=own_identities.begin();it!=own_identities.end();++it) + { + RsIdentityDetails idd ; + rsIdentity->getIdDetails(*it,idd) ; + + QPixmap pixmap ; + + if(idd.mAvatar.mSize == 0 || !pixmap.loadFromData(idd.mAvatar.mData, idd.mAvatar.mSize, "PNG")) + pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(*it)) ; + + QAction *action = mnu->addAction(QIcon(pixmap), QString("%1 (%2)").arg(QString::fromUtf8(idd.mNickname.c_str()), QString::fromStdString((*it).toStdString())), this, SLOT(subscribeChatLobbyAs())); + action->setData(QString::fromStdString((*it).toStdString())) ; + } + } + + if (item->data(COLUMN_DATA, ROLE_AUTOSUBSCRIBE).toBool()) + contextMnu.addAction(QIcon(IMAGE_AUTOSUBSCRIBE), tr("Remove Auto Subscribe"), this, SLOT(autoSubscribeItem())); + else + contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Add Auto Subscribe"), this, SLOT(autoSubscribeItem())); + } - } + } - contextMnu.addSeparator();//------------------------------------------------------------------- + contextMnu.addSeparator();//------------------------------------------------------------------- - showUserCountAct->setChecked(!ui.lobbyTreeWidget->isColumnHidden(COLUMN_USER_COUNT)); - showTopicAct->setChecked(!ui.lobbyTreeWidget->isColumnHidden(COLUMN_TOPIC)); - showSubscribeAct->setChecked(!ui.lobbyTreeWidget->isColumnHidden(COLUMN_SUBSCRIBED)); + showUserCountAct->setChecked(!ui.lobbyTreeWidget->isColumnHidden(COLUMN_USER_COUNT)); + showTopicAct->setChecked(!ui.lobbyTreeWidget->isColumnHidden(COLUMN_TOPIC)); + showSubscribeAct->setChecked(!ui.lobbyTreeWidget->isColumnHidden(COLUMN_SUBSCRIBED)); - QMenu *menu = contextMnu.addMenu(tr("Columns")); - menu->addAction(showUserCountAct); - menu->addAction(showTopicAct); - menu->addAction(showSubscribeAct); + QMenu *menu = contextMnu.addMenu(tr("Columns")); + menu->addAction(showUserCountAct); + menu->addAction(showTopicAct); + menu->addAction(showSubscribeAct); - contextMnu.exec(QCursor::pos()); + contextMnu.exec(QCursor::pos()); } void ChatLobbyWidget::lobbyChanged() @@ -579,12 +616,30 @@ void ChatLobbyWidget::showLobby(QTreeWidgetItem *item) else ui.stackedWidget->setCurrentWidget(_lobby_infos[id].dialog) ; } - -static void subscribeLobby(QTreeWidgetItem *item) +void ChatLobbyWidget::subscribeChatLobbyAs() { - if (item == NULL || item->type() != TYPE_LOBBY) { - return; - } + QTreeWidgetItem *item = ui.lobbyTreeWidget->currentItem(); + + if(!item) + return ; + + ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong(); + + QAction *action = qobject_cast(QObject::sender()); + if (!action) + return ; + + RsGxsId gxs_id(action->data().toString().toStdString()); + uint32_t error_code ; + + if(rsMsgs->joinVisibleChatLobby(id,gxs_id)) + ChatDialog::chatFriend(ChatId(id),true) ; +} +void ChatLobbyWidget::subscribeChatLobbyAtItem(QTreeWidgetItem *item) +{ + if (item == NULL || item->type() != TYPE_LOBBY) { + return; + } ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong(); RsGxsId gxs_id ; @@ -602,7 +657,7 @@ void ChatLobbyWidget::autoSubscribeLobby(QTreeWidgetItem *item) ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong(); bool isAutoSubscribe = rsMsgs->getLobbyAutoSubscribe(id); rsMsgs->setLobbyAutoSubscribe(id, !isAutoSubscribe); - if (!isAutoSubscribe) subscribeLobby(item); + if (!isAutoSubscribe) subscribeChatLobbyAtItem(item); } void ChatLobbyWidget::showBlankPage(ChatLobbyId id) @@ -639,12 +694,12 @@ void ChatLobbyWidget::showBlankPage(ChatLobbyId id) void ChatLobbyWidget::subscribeItem() { - subscribeLobby(ui.lobbyTreeWidget->currentItem()); + subscribeChatLobbyAtItem(ui.lobbyTreeWidget->currentItem()); } void ChatLobbyWidget::autoSubscribeItem() { - autoSubscribeLobby(ui.lobbyTreeWidget->currentItem()); + autoSubscribeLobby(ui.lobbyTreeWidget->currentItem()); } QTreeWidgetItem *ChatLobbyWidget::getTreeWidgetItem(ChatLobbyId id) @@ -822,7 +877,7 @@ void ChatLobbyWidget::updateMessageChanged(ChatLobbyId id) void ChatLobbyWidget::itemDoubleClicked(QTreeWidgetItem *item, int /*column*/) { - subscribeLobby(item); + subscribeChatLobbyAtItem(item); } void ChatLobbyWidget::displayChatLobbyEvent(qulonglong lobby_id, int event_type, const QString& gxs_id, const QString& str) diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.h b/retroshare-gui/src/gui/ChatLobbyWidget.h index b9166b537..3296a51c4 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.h +++ b/retroshare-gui/src/gui/ChatLobbyWidget.h @@ -62,8 +62,9 @@ protected slots: void readChatLobbyInvites(); void showLobby(QTreeWidgetItem *lobby_item) ; void showBlankPage(ChatLobbyId id) ; - void unsubscribeChatLobby(ChatLobbyId id) ; - void updateTypingStatus(ChatLobbyId id) ; + void unsubscribeChatLobby(ChatLobbyId id) ; + void subscribeChatLobbyAs() ; + void updateTypingStatus(ChatLobbyId id) ; void resetLobbyTreeIcons() ; void updateMessageChanged(ChatLobbyId); void updatePeerEntering(ChatLobbyId); @@ -81,6 +82,8 @@ private slots: private: void autoSubscribeLobby(QTreeWidgetItem *item); + void subscribeChatLobby(ChatLobbyId id) ; + void subscribeChatLobbyAtItem(QTreeWidgetItem *item) ; bool filterItem(QTreeWidgetItem *item, const QString &text, int filterColumn);