in ChatLobbyWidget: show dialog to create a new identity when there is no own identity

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8269 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
electron128 2015-05-17 10:13:32 +00:00
parent 789b76f7b4
commit 699dc50b3f
8 changed files with 70 additions and 23 deletions

View file

@ -1578,13 +1578,11 @@ bool DistributedChatService::setDefaultIdentityForChatLobby(const RsGxsId& nick)
triggerConfigSave() ; triggerConfigSave() ;
return true ; return true ;
} }
bool DistributedChatService::getDefaultIdentityForChatLobby(RsGxsId& nick) void DistributedChatService::getDefaultIdentityForChatLobby(RsGxsId& nick)
{ {
RsStackMutex stack(mDistributedChatMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mDistributedChatMtx); /********** STACK LOCKED MTX ******/
nick = locked_getDefaultIdentity() ; nick = locked_getDefaultIdentity() ;
return true ;
} }
RsGxsId DistributedChatService::locked_getDefaultIdentity() RsGxsId DistributedChatService::locked_getDefaultIdentity()

View file

@ -71,7 +71,7 @@ class DistributedChatService
bool setIdentityForChatLobby(const ChatLobbyId& lobby_id,const RsGxsId& nick) ; bool setIdentityForChatLobby(const ChatLobbyId& lobby_id,const RsGxsId& nick) ;
bool getIdentityForChatLobby(const ChatLobbyId& lobby_id,RsGxsId& nick) ; bool getIdentityForChatLobby(const ChatLobbyId& lobby_id,RsGxsId& nick) ;
bool setDefaultIdentityForChatLobby(const RsGxsId& nick) ; bool setDefaultIdentityForChatLobby(const RsGxsId& nick) ;
bool getDefaultIdentityForChatLobby(RsGxsId& nick) ; void getDefaultIdentityForChatLobby(RsGxsId& nick) ;
void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe); void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe);
bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id); bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id);
void sendLobbyStatusString(const ChatLobbyId& id,const std::string& status_string) ; void sendLobbyStatusString(const ChatLobbyId& id,const std::string& status_string) ;

View file

@ -471,7 +471,7 @@ virtual void unsubscribeChatLobby(const ChatLobbyId& lobby_id) = 0;
virtual bool setIdentityForChatLobby(const ChatLobbyId& lobby_id,const RsGxsId& nick) = 0; virtual bool setIdentityForChatLobby(const ChatLobbyId& lobby_id,const RsGxsId& nick) = 0;
virtual bool getIdentityForChatLobby(const ChatLobbyId& lobby_id,RsGxsId& nick) = 0 ; virtual bool getIdentityForChatLobby(const ChatLobbyId& lobby_id,RsGxsId& nick) = 0 ;
virtual bool setDefaultIdentityForChatLobby(const RsGxsId& nick) = 0; virtual bool setDefaultIdentityForChatLobby(const RsGxsId& nick) = 0;
virtual bool getDefaultIdentityForChatLobby(RsGxsId& id) = 0 ; virtual void getDefaultIdentityForChatLobby(RsGxsId& id) = 0 ;
virtual void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe) = 0 ; virtual void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe) = 0 ;
virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id) = 0 ; virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id) = 0 ;
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const RsGxsId& lobby_identity,const std::string& lobby_topic,const std::set<RsPeerId>& invited_friends,ChatLobbyFlags lobby_privacy_type) = 0 ; virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const RsGxsId& lobby_identity,const std::string& lobby_topic,const std::set<RsPeerId>& invited_friends,ChatLobbyFlags lobby_privacy_type) = 0 ;

View file

@ -471,9 +471,9 @@ bool p3Msgs::setDefaultIdentityForChatLobby(const RsGxsId& nick)
{ {
return mChatSrv->setDefaultIdentityForChatLobby(nick) ; return mChatSrv->setDefaultIdentityForChatLobby(nick) ;
} }
bool p3Msgs::getDefaultIdentityForChatLobby(RsGxsId& nick_name) void p3Msgs::getDefaultIdentityForChatLobby(RsGxsId& nick_name)
{ {
return mChatSrv->getDefaultIdentityForChatLobby(nick_name) ; mChatSrv->getDefaultIdentityForChatLobby(nick_name) ;
} }
bool p3Msgs::setIdentityForChatLobby(const ChatLobbyId& lobby_id,const RsGxsId& nick) bool p3Msgs::setIdentityForChatLobby(const ChatLobbyId& lobby_id,const RsGxsId& nick)

View file

@ -150,7 +150,7 @@ class p3Msgs: public RsMsgs
virtual bool setIdentityForChatLobby(const ChatLobbyId& lobby_id,const RsGxsId&) ; virtual bool setIdentityForChatLobby(const ChatLobbyId& lobby_id,const RsGxsId&) ;
virtual bool getIdentityForChatLobby(const ChatLobbyId&,RsGxsId& nick) ; virtual bool getIdentityForChatLobby(const ChatLobbyId&,RsGxsId& nick) ;
virtual bool setDefaultIdentityForChatLobby(const RsGxsId&) ; virtual bool setDefaultIdentityForChatLobby(const RsGxsId&) ;
virtual bool getDefaultIdentityForChatLobby(RsGxsId& nick) ; virtual void getDefaultIdentityForChatLobby(RsGxsId& nick) ;
virtual void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe); virtual void setLobbyAutoSubscribe(const ChatLobbyId& lobby_id, const bool autoSubscribe);
virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id); virtual bool getLobbyAutoSubscribe(const ChatLobbyId& lobby_id);
virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const RsGxsId& lobby_identity,const std::string& lobby_topic,const std::set<RsPeerId>& invited_friends,ChatLobbyFlags privacy_type) ; virtual ChatLobbyId createChatLobby(const std::string& lobby_name,const RsGxsId& lobby_identity,const std::string& lobby_topic,const std::set<RsPeerId>& invited_friends,ChatLobbyFlags privacy_type) ;

View file

@ -439,7 +439,10 @@ bool p3IdService::getOwnIds(std::list<RsGxsId> &ownIds)
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
if(!mOwnIdsLoaded) if(!mOwnIdsLoaded)
{
std::cerr << "p3IdService::getOwnIds(): own identities are not loaded yet." << std::endl;
return false ; return false ;
}
ownIds = mOwnIds; ownIds = mOwnIds;
return true ; return true ;

View file

@ -15,6 +15,7 @@
#include "util/QtVersion.h" #include "util/QtVersion.h"
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
#include "gui/Identity/IdEditDialog.h"
#include "retroshare/rsmsgs.h" #include "retroshare/rsmsgs.h"
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
@ -244,13 +245,13 @@ void ChatLobbyWidget::lobbyTreeWidgetCustomPopupMenu(QPoint)
QTreeWidgetItem *item = ui.lobbyTreeWidget->currentItem(); QTreeWidgetItem *item = ui.lobbyTreeWidget->currentItem();
uint32_t item_flags = item->data(COLUMN_DATA,ROLE_ID).toUInt() ; uint32_t item_flags = item->data(COLUMN_DATA,ROLE_ID).toUInt() ;
if(own_identities.size() <= 1) if(own_identities.empty())
{
contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Create a nickname and enter this lobby"), this, SLOT(createIdentityAndSubscribe()));
}
else if(own_identities.size() == 1)
{ {
QAction *action = contextMnu.addAction(QIcon(IMAGE_SUBSCRIBE), tr("Enter this lobby"), this, SLOT(subscribeChatLobbyAs())); 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())) ; action->setData(QString::fromStdString((own_identities.front()).toStdString())) ;
} }
else else
@ -636,6 +637,28 @@ void ChatLobbyWidget::showLobby(QTreeWidgetItem *item)
ui.stackedWidget->setCurrentWidget(_lobby_infos[id].dialog) ; ui.stackedWidget->setCurrentWidget(_lobby_infos[id].dialog) ;
} }
// this function is for the case where we don't have any identity yet
void ChatLobbyWidget::createIdentityAndSubscribe()
{
QTreeWidgetItem *item = ui.lobbyTreeWidget->currentItem();
if(!item)
return ;
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
IdEditDialog dlg(this);
dlg.setupNewId(false);
dlg.exec();
// fetch new id
std::list<RsGxsId> own_ids;
if(!rsIdentity->getOwnIds(own_ids) || own_ids.empty())
return;
if(rsMsgs->joinVisibleChatLobby(id,own_ids.front()))
ChatDialog::chatFriend(ChatId(id),true) ;
}
void ChatLobbyWidget::subscribeChatLobbyAs() void ChatLobbyWidget::subscribeChatLobbyAs()
{ {
QTreeWidgetItem *item = ui.lobbyTreeWidget->currentItem(); QTreeWidgetItem *item = ui.lobbyTreeWidget->currentItem();
@ -689,7 +712,29 @@ void ChatLobbyWidget::subscribeChatLobbyAtItem(QTreeWidgetItem *item)
ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong(); ChatLobbyId id = item->data(COLUMN_DATA, ROLE_ID).toULongLong();
RsGxsId gxs_id ; RsGxsId gxs_id ;
if(rsMsgs->getDefaultIdentityForChatLobby(gxs_id) && !gxs_id.isNull() && rsMsgs->joinVisibleChatLobby(id,gxs_id)) std::list<RsGxsId> own_ids;
// not using rsMsgs->getDefaultIdentityForChatLobby(), to check if we have an identity
// to work around the case when the identity was deleted and is invalid
// (the chatservervice does not know if a default identity was deleted)
// only rsIdentity knows the truth at the moment!
if(!rsIdentity->getOwnIds(own_ids))
return;
// if there is no identity yet, show the dialog to create a new identity
if(own_ids.empty())
{
IdEditDialog dlg(this);
dlg.setupNewId(false);
dlg.exec();
// fetch new id
if(!rsIdentity->getOwnIds(own_ids) || own_ids.empty())
return;
gxs_id = own_ids.front();
}
else
rsMsgs->getDefaultIdentityForChatLobby(gxs_id);
if(rsMsgs->joinVisibleChatLobby(id,gxs_id))
ChatDialog::chatFriend(ChatId(id),true) ; ChatDialog::chatFriend(ChatId(id),true) ;
} }

View file

@ -64,6 +64,7 @@ protected slots:
void showLobby(QTreeWidgetItem *lobby_item) ; void showLobby(QTreeWidgetItem *lobby_item) ;
void showBlankPage(ChatLobbyId id) ; void showBlankPage(ChatLobbyId id) ;
void unsubscribeChatLobby(ChatLobbyId id) ; void unsubscribeChatLobby(ChatLobbyId id) ;
void createIdentityAndSubscribe();
void subscribeChatLobbyAs() ; void subscribeChatLobbyAs() ;
void updateTypingStatus(ChatLobbyId id) ; void updateTypingStatus(ChatLobbyId id) ;
void resetLobbyTreeIcons() ; void resetLobbyTreeIcons() ;