From b113b78e7cd033bbc790537014b5f5f95b9fe836 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sun, 23 Aug 2009 16:53:51 +0200 Subject: [PATCH] chat fix --- cockatrice/src/chatwidget.cpp | 18 +++++++++++++++--- cockatrice/src/chatwidget.h | 4 +++- cockatrice/src/window_main.cpp | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cockatrice/src/chatwidget.cpp b/cockatrice/src/chatwidget.cpp index 604ffb62..ae8350fd 100644 --- a/cockatrice/src/chatwidget.cpp +++ b/cockatrice/src/chatwidget.cpp @@ -2,8 +2,8 @@ #include "chatwidget.h" #include "client.h" -ChannelWidget::ChannelWidget(Client *_client, const QString &_name, bool readOnly, QWidget *parent) - : QWidget(parent), client(_client), name(_name) +ChannelWidget::ChannelWidget(Client *_client, const QString &_name, bool readOnly, bool _virtualChannel, QWidget *parent) + : QWidget(parent), client(_client), name(_name), virtualChannel(_virtualChannel) { playerList = new QListWidget; @@ -27,6 +27,12 @@ ChannelWidget::ChannelWidget(Client *_client, const QString &_name, bool readOnl setLayout(hbox); } +ChannelWidget::~ChannelWidget() +{ + if (!virtualChannel) + client->chatLeaveChannel(name); +} + void ChannelWidget::sendMessage() { if (sayEdit->text().isEmpty()) @@ -111,6 +117,12 @@ void ChatWidget::enableChat() void ChatWidget::disableChat() { disconnect(client, 0, this, 0); + while (tab->count()) { + ChannelWidget *cw = qobject_cast(tab->widget(0)); + tab->removeTab(0); + delete cw; + } + channelList->clear(); hide(); } @@ -177,7 +189,7 @@ void ChatWidget::chatEvent(const ChatEventData &data) if (msg[0].isEmpty()) { w = getChannel("Server"); if (!w) { - w = new ChannelWidget(client, "Server", true); + w = new ChannelWidget(client, "Server", true, true); tab->addTab(w, "Server"); } } else diff --git a/cockatrice/src/chatwidget.h b/cockatrice/src/chatwidget.h index 6e891293..c4075f6f 100644 --- a/cockatrice/src/chatwidget.h +++ b/cockatrice/src/chatwidget.h @@ -20,10 +20,12 @@ private: QLineEdit *sayEdit; Client *client; QString name; + bool virtualChannel; private slots: void sendMessage(); public: - ChannelWidget(Client *_client, const QString &_name, bool readOnly = false, QWidget *parent = 0); + ChannelWidget(Client *_client, const QString &_name, bool readOnly = false, bool _virtualChannel = false, QWidget *parent = 0); + ~ChannelWidget(); const QString &getName() const { return name; } void joinEvent(const QString &playerName); diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index d04bab30..b9d76deb 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -350,6 +350,8 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent) void MainWindow::closeEvent(QCloseEvent */*event*/) { delete game; + chatWidget->disableChat(); + gameSelector->disableGameList(); } void MainWindow::changeEvent(QEvent *event)