Chat lobby:

- added new notifier to p3ChatService
GUI:
- list all public and private chat lobbies
- added subscribe/unsubscribe
- added new basic widget ChatTabWidget and use it in PopupChatWindow and ChatLobbyDialog
- added a tabbed dialog for every subscribed chat lobby

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4782 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-01-12 00:13:25 +00:00
parent fc949ce5d0
commit 6c626e180f
21 changed files with 934 additions and 420 deletions

View file

@ -45,41 +45,56 @@
#include <algorithm>
#include "ChatLobbyDialog.h"
#include "gui/ChatLobbyWidget.h"
/** Default constructor */
ChatLobbyDialog::ChatLobbyDialog(const std::string& dialog_id,const ChatLobbyId& lid, const QString &name, QWidget *parent, Qt::WFlags flags)
: PopupChatDialog(dialog_id,name,parent,flags),lobby_id(lid)
ChatLobbyDialog::ChatLobbyDialog(const std::string& dialog_id, const ChatLobbyId& lid, const QString &name, QWidget *parent, Qt::WFlags flags)
: PopupChatDialog(dialog_id, name, parent, flags), lobby_id(lid)
{
// remove the avatar widget. Replace it with a friends list.
ui.avatarWidget->hide() ;
PopupChatDialog::updateStatus(QString::fromStdString(getPeerId()),RS_STATUS_ONLINE) ;
ui.avatarWidget->hide();
ui.ownAvatarWidget->hide();
PopupChatDialog::updateStatus(QString::fromStdString(getPeerId()),RS_STATUS_ONLINE);
QObject::connect(this,SIGNAL(close()),this,SLOT(closeAndAsk())) ;
// hide history buttons
ui.actionClearOfflineMessages->setVisible(false);
ui.actionDelete_Chat_History->setVisible(false);
ui.actionMessageHistory->setVisible(false);
ui.avatarframe->layout()->addWidget(new QLabel(tr("Participants:"))) ;
friendsListWidget = new QListWidget ;
ui.avatarframe->layout()->addWidget(friendsListWidget) ;
ui.avatarframe->layout()->addItem(new QSpacerItem(12, 335, QSizePolicy::Minimum, QSizePolicy::Expanding)) ;
ui.avatarFrameButton->setToolTip(tr("Hide participants"));
ui.avatarframe->layout()->addWidget(new QLabel(tr("Participants:")));
friendsListWidget = new QListWidget;
ui.avatarframe->layout()->addWidget(friendsListWidget);
ui.avatarframe->layout()->addItem(new QSpacerItem(12, 335, QSizePolicy::Minimum, QSizePolicy::Expanding));
}
/** Destructor. */
ChatLobbyDialog::~ChatLobbyDialog()
{
// announce leaving of lobby
// check that the lobby still exists.
ChatLobbyId lid ;
if(!rsMsgs->isLobbyId(getPeerId(),lid))
return ;
if(QMessageBox::Yes == QMessageBox::question(NULL,tr("Unsubscribe to lobby?"),tr("Do you want to unsubscribe to this chat lobby?"),QMessageBox::Yes | QMessageBox::No))
rsMsgs->unsubscribeChatLobby(lobby_id) ;
// check that the lobby still exists.
ChatLobbyId lid;
if (rsMsgs->isLobbyId(getPeerId(),lid)) {
rsMsgs->unsubscribeChatLobby(lobby_id);
}
}
bool ChatLobbyDialog::addToParent()
{
ChatTabWidget *tabWidget = ChatLobbyWidget::getTabWidget();
if (tabWidget) {
tabWidget->addDialog(this);
return true;
}
return false;
}
void ChatLobbyDialog::setNickName(const QString& nick)
{
rsMsgs->setNickNameForChatLobby(lobby_id,nick.toUtf8().constData()) ;
rsMsgs->setNickNameForChatLobby(lobby_id, nick.toUtf8().constData());
}
void ChatLobbyDialog::addIncomingChatMsg(const ChatInfo& info)
@ -87,7 +102,7 @@ void ChatLobbyDialog::addIncomingChatMsg(const ChatInfo& info)
QDateTime sendTime = QDateTime::fromTime_t(info.sendTime);
QDateTime recvTime = QDateTime::fromTime_t(info.recvTime);
QString message = QString::fromStdWString(info.msg);
QString name = QString::fromUtf8(info.peer_nickname.c_str()) ;
QString name = QString::fromUtf8(info.peer_nickname.c_str());
addChatMsg(true, name, sendTime, recvTime, message, TYPE_NORMAL);
@ -96,42 +111,44 @@ void ChatLobbyDialog::addIncomingChatMsg(const ChatInfo& info)
static time_t last = 0 ;
time_t now = time(NULL) ;
if(now > last)
{
last = now ;
updateFriendsList() ;
if (now > last) {
last = now;
updateFriendsList();
}
}
void ChatLobbyDialog::updateFriendsList()
{
friendsListWidget->clear() ;
friendsListWidget->clear();
std::list<ChatLobbyInfo> linfos ;
std::list<ChatLobbyInfo> linfos;
rsMsgs->getChatLobbyList(linfos);
std::list<ChatLobbyInfo>::const_iterator it(linfos.begin());
for(;it!=linfos.end() && (*it).lobby_id != lobby_id;++it) ;
for (; it!=linfos.end() && (*it).lobby_id != lobby_id; ++it);
if(it!=linfos.end())
for(std::set<std::string>::const_iterator it2( (*it).nick_names.begin());it2!=(*it).nick_names.end();++it2)
friendsListWidget->addItem(QString::fromUtf8((*it2).c_str())) ;
if (it != linfos.end()) {
for (std::set<std::string>::const_iterator it2((*it).nick_names.begin()); it2 != (*it).nick_names.end(); ++it2) {
friendsListWidget->addItem(QString::fromUtf8((*it2).c_str()));
}
}
}
void ChatLobbyDialog::displayLobbyEvent(int event_type,const QString& nickname,const QString& str)
void ChatLobbyDialog::displayLobbyEvent(int event_type, const QString& nickname, const QString& str)
{
switch(event_type)
{
case RS_CHAT_LOBBY_EVENT_PEER_LEFT: addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), str + tr(" has left the lobby."), TYPE_NORMAL);
break ;
case RS_CHAT_LOBBY_EVENT_PEER_JOINED:
addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), str + tr(" joined the lobby."), TYPE_NORMAL);
break ;
case RS_CHAT_LOBBY_EVENT_PEER_STATUS:
updateStatusString(nickname,str) ;
break ;
case RS_CHAT_LOBBY_EVENT_PEER_LEFT:
addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the lobby.").arg(str), TYPE_NORMAL);
break;
case RS_CHAT_LOBBY_EVENT_PEER_JOINED:
addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the lobby.").arg(str), TYPE_NORMAL);
break;
case RS_CHAT_LOBBY_EVENT_PEER_STATUS:
updateStatusString(nickname,str);
break;
default:
std::cerr << "ChatLobbyDialog::displayLobbyEvent() Unhandled lobby event type " << event_type << std::endl;
std::cerr << "ChatLobbyDialog::displayLobbyEvent() Unhandled lobby event type " << event_type << std::endl;
}
}
@ -140,3 +157,17 @@ QString ChatLobbyDialog::makeStatusString(const QString& peer_id, const QString&
return QString::fromUtf8(peer_id.toStdString().c_str()) + " " + tr(status_string.toAscii());
}
bool ChatLobbyDialog::canClose()
{
// check that the lobby still exists.
ChatLobbyId lid;
if (!rsMsgs->isLobbyId(getPeerId(),lid)) {
return true;
}
if (QMessageBox::Yes == QMessageBox::question(NULL, tr("Unsubscribe to lobby?"), tr("Do you want to unsubscribe to this chat lobby?"), QMessageBox::Yes | QMessageBox::No)) {
return true;
}
return false;
}