Changed some internals in the chat dialog handling (private chat and lobby).

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4855 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-01-27 14:49:48 +00:00
parent 44ff9fe4f7
commit 2aa1ede192
7 changed files with 62 additions and 8 deletions

View File

@ -21,6 +21,7 @@
****************************************************************/
#include <QMessageBox>
#include <QCloseEvent>
#include "ChatDialog.h"
#include "gui/common/PeerDefs.h"
@ -40,6 +41,7 @@ static std::map<std::string, ChatDialog*> chatDialogs;
ChatDialog::ChatDialog(QWidget *parent, Qt::WFlags flags) :
QWidget(parent, flags)
{
setAttribute(Qt::WA_DeleteOnClose, true);
}
ChatDialog::~ChatDialog()
@ -50,6 +52,15 @@ ChatDialog::~ChatDialog()
}
}
void ChatDialog::closeEvent(QCloseEvent *event)
{
if (!canClose()) {
event->ignore();
return;
}
emit dialogClose(this);
}
void ChatDialog::init(const std::string &peerId, const QString &title)
{
this->peerId = peerId;

View File

@ -41,7 +41,6 @@ public:
static void closeChat(const std::string &peerId);
static void chatChanged(int list, int type);
virtual bool canClose() { return true; }
virtual void showDialog(uint chatflags) {}
virtual ChatWidget *getChatWidget() = 0;
@ -66,6 +65,7 @@ public:
signals:
void infoChanged(ChatDialog *dialog);
void newMessage(ChatDialog *dialog);
void dialogClose(ChatDialog *dialog);
private slots:
void chatInfoChanged(ChatWidget*);
@ -75,6 +75,9 @@ protected:
explicit ChatDialog(QWidget *parent = 0, Qt::WFlags flags = 0);
virtual ~ChatDialog();
void closeEvent(QCloseEvent *event);
virtual bool canClose() { return true; }
virtual void init(const std::string &peerId, const QString &title);
virtual void onChatChanged(int list, int type) {}

View File

@ -35,7 +35,6 @@ class ChatLobbyDialog: public ChatDialog
public:
void displayLobbyEvent(int event_type, const QString& nickname, const QString& str);
virtual bool canClose();
virtual void showDialog(uint chatflags);
virtual ChatWidget *getChatWidget();
virtual bool hasPeerStatus() { return false; }
@ -53,6 +52,7 @@ protected:
void processSettings(bool load);
virtual void init(const std::string &peerId, const QString &title);
virtual bool canClose();
virtual void addIncomingChatMsg(const ChatInfo& info);
protected slots:

View File

@ -50,6 +50,7 @@ void ChatTabWidget::addDialog(ChatDialog *dialog)
dialog->addToParent(this);
QObject::connect(dialog, SIGNAL(infoChanged(ChatDialog*)), this, SLOT(tabInfoChanged(ChatDialog*)));
QObject::connect(dialog, SIGNAL(dialogClose(ChatDialog*)), this, SLOT(dialogClose(ChatDialog*)));
tabInfoChanged(dialog);
}
@ -57,11 +58,13 @@ void ChatTabWidget::addDialog(ChatDialog *dialog)
void ChatTabWidget::removeDialog(ChatDialog *dialog)
{
QObject::disconnect(dialog, SIGNAL(infoChanged(ChatDialog*)), this, SLOT(tabInfoChanged(ChatDialog*)));
QObject::disconnect(dialog, SIGNAL(dialogClose(ChatDialog*)), this, SLOT(dialogClose(ChatDialog*)));
int tab = indexOf(dialog);
if (tab >= 0) {
dialog->removeFromParent(this);
removeTab(tab);
emit tabClosed(dialog);
}
}
@ -70,11 +73,7 @@ void ChatTabWidget::tabClose(int tab)
ChatDialog *dialog = dynamic_cast<ChatDialog*>(widget(tab));
if (dialog) {
if (dialog->canClose()) {
removeDialog(dialog);
emit tabClosed(dialog);
dialog->deleteLater();
}
dialog->close();
}
}
@ -105,6 +104,11 @@ void ChatTabWidget::tabInfoChanged(ChatDialog *dialog)
emit infoChanged();
}
void ChatTabWidget::dialogClose(ChatDialog *dialog)
{
removeDialog(dialog);
}
void ChatTabWidget::getInfo(bool &isTyping, bool &hasNewMessage, QIcon *icon)
{
isTyping = false;

View File

@ -53,6 +53,7 @@ private slots:
void tabClose(int tab);
void tabChanged(int tab);
void tabInfoChanged(ChatDialog *dialog);
void dialogClose(ChatDialog *dialog);
private:
Ui::ChatTabWidget *ui;

View File

@ -21,6 +21,7 @@
****************************************************************/
#include <QPixmap>
#include <QCloseEvent>
#include "PopupChatWindow.h"
#include "ChatDialog.h"
@ -137,6 +138,27 @@ void PopupChatWindow::showEvent(QShowEvent */*event*/)
}
}
void PopupChatWindow::closeEvent(QCloseEvent *event)
{
if (tabbedWindow) {
for (int index = ui.tabWidget->count() - 1; index >= 0; --index) {
ChatDialog *dialog = dynamic_cast<ChatDialog*>(ui.tabWidget->widget(0));
if (dialog == NULL) {
continue;
}
if (!dialog->close()) {
event->ignore();
break;
}
}
} else {
if (chatDialog && !chatDialog->close()) {
event->ignore();
}
}
}
ChatDialog *PopupChatWindow::getCurrentDialog()
{
if (tabbedWindow) {
@ -160,6 +182,8 @@ void PopupChatWindow::addDialog(ChatDialog *dialog)
/* signal toggled is called */
ui.actionSetOnTop->setChecked(PeerSettings->getPrivateChatOnTop(peerId));
QObject::connect(dialog, SIGNAL(dialogClose(ChatDialog*)), this, SLOT(dialogClose(ChatDialog*)));
}
QObject::connect(dialog, SIGNAL(infoChanged(ChatDialog*)), this, SLOT(tabInfoChanged(ChatDialog*)));
@ -178,6 +202,8 @@ void PopupChatWindow::removeDialog(ChatDialog *dialog)
deleteLater();
}
} else {
QObject::disconnect(dialog, SIGNAL(dialogClose(ChatDialog*)), this, SLOT(dialogClose(ChatDialog*)));
if (chatDialog == dialog) {
saveSettings();
dialog->removeFromParent(this);
@ -280,6 +306,13 @@ void PopupChatWindow::tabClosed(ChatDialog *dialog)
}
}
void PopupChatWindow::dialogClose(ChatDialog *dialog)
{
if (!tabbedWindow) {
removeDialog(dialog);
}
}
void PopupChatWindow::tabChanged(ChatDialog *dialog)
{
calculateStyle(dialog);

View File

@ -49,7 +49,8 @@ protected:
/** Default destructor */
~PopupChatWindow();
virtual void showEvent(QShowEvent *event);
void showEvent(QShowEvent *event);
void closeEvent(QCloseEvent *event);
private slots:
void getAvatar();
@ -57,6 +58,7 @@ private slots:
void tabInfoChanged(ChatDialog *dialog);
void tabNewMessage(ChatDialog *dialog);
void tabClosed(ChatDialog *dialog);
void dialogClose(ChatDialog *dialog);
void dockTab();
void undockTab();
void setStyle();