From c90c389a8a8d9d8661e9772ec4144c5cf2039f23 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- libkdegames/kgame/dialogs/Makefile.am | 17 + libkdegames/kgame/dialogs/kgameconnectdialog.cpp | 278 ++++++++ libkdegames/kgame/dialogs/kgameconnectdialog.h | 169 +++++ libkdegames/kgame/dialogs/kgamedebugdialog.cpp | 548 ++++++++++++++++ libkdegames/kgame/dialogs/kgamedebugdialog.h | 149 +++++ libkdegames/kgame/dialogs/kgamedialog.cpp | 347 ++++++++++ libkdegames/kgame/dialogs/kgamedialog.h | 320 ++++++++++ libkdegames/kgame/dialogs/kgamedialogconfig.cpp | 773 +++++++++++++++++++++++ libkdegames/kgame/dialogs/kgamedialogconfig.h | 362 +++++++++++ libkdegames/kgame/dialogs/kgameerrordialog.cpp | 129 ++++ libkdegames/kgame/dialogs/kgameerrordialog.h | 113 ++++ 11 files changed, 3205 insertions(+) create mode 100644 libkdegames/kgame/dialogs/Makefile.am create mode 100644 libkdegames/kgame/dialogs/kgameconnectdialog.cpp create mode 100644 libkdegames/kgame/dialogs/kgameconnectdialog.h create mode 100644 libkdegames/kgame/dialogs/kgamedebugdialog.cpp create mode 100644 libkdegames/kgame/dialogs/kgamedebugdialog.h create mode 100644 libkdegames/kgame/dialogs/kgamedialog.cpp create mode 100644 libkdegames/kgame/dialogs/kgamedialog.h create mode 100644 libkdegames/kgame/dialogs/kgamedialogconfig.cpp create mode 100644 libkdegames/kgame/dialogs/kgamedialogconfig.h create mode 100644 libkdegames/kgame/dialogs/kgameerrordialog.cpp create mode 100644 libkdegames/kgame/dialogs/kgameerrordialog.h (limited to 'libkdegames/kgame/dialogs') diff --git a/libkdegames/kgame/dialogs/Makefile.am b/libkdegames/kgame/dialogs/Makefile.am new file mode 100644 index 00000000..1b9de53c --- /dev/null +++ b/libkdegames/kgame/dialogs/Makefile.am @@ -0,0 +1,17 @@ + +noinst_LTLIBRARIES = libkgamedialogs.la + +# compile-order doesn't matter here but maybe we will split these section soon + + +libkgamedialogs_la_SOURCES = kgamedialog.cpp kgameconnectdialog.cpp kgameerrordialog.cpp kgamedebugdialog.cpp kgamedialogconfig.cpp + +libkgamedialogsincludedir=$(includedir)/kgame +libkgamedialogsinclude_HEADERS = kgamedialog.h kgameconnectdialog.h kgameerrordialog.h kgamedebugdialog.h kgamedialogconfig.h + +INCLUDES = -I$(top_srcdir)/libkdegames -I$(top_srcdir)/libkdegames/kgame $(all_includes) +METASOURCES = AUTO + +messages: +# $(XGETTEXT) `find . -name \*.h -o -name \*.cpp -o -name \*.cc` -o $(podir)/libkdegames.pot + diff --git a/libkdegames/kgame/dialogs/kgameconnectdialog.cpp b/libkdegames/kgame/dialogs/kgameconnectdialog.cpp new file mode 100644 index 00000000..4d2d90e0 --- /dev/null +++ b/libkdegames/kgame/dialogs/kgameconnectdialog.cpp @@ -0,0 +1,278 @@ +/* + This file is part of the KDE games library + Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) + Copyright (C) 2001 Martin Heni (martin@heni-online.de) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + + +#include "kgameconnectdialog.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class KGameConnectWidgetPrivate +{ + public: + KGameConnectWidgetPrivate() + { + mPort = 0; + mHost = 0; + mButtonGroup = 0; + mBrowser = 0; + } + + KIntNumInput* mPort; + QLineEdit* mHost; //KLineEdit? + QVButtonGroup* mButtonGroup; + QComboBox *mClientName; + QLabel *mClientNameLabel; + DNSSD::ServiceBrowser *mBrowser; + QLabel *mServerNameLabel; + QLineEdit *mServerName; + QString mType; +}; + +KGameConnectWidget::KGameConnectWidget(QWidget* parent) : QWidget(parent) +{ + d = new KGameConnectWidgetPrivate; + + QVBoxLayout* vb = new QVBoxLayout(this, KDialog::spacingHint()); + d->mButtonGroup = new QVButtonGroup(this); + vb->addWidget(d->mButtonGroup); + connect(d->mButtonGroup, SIGNAL(clicked(int)), this, SLOT(slotTypeChanged(int))); + (void)new QRadioButton(i18n("Create a network game"), d->mButtonGroup); + (void)new QRadioButton(i18n("Join a network game"), d->mButtonGroup); + + QGrid* g = new QGrid(2, this); + vb->addWidget(g); + g->setSpacing(KDialog::spacingHint()); + d->mServerNameLabel = new QLabel(i18n("Game name:"), g); + d->mServerName = new QLineEdit(g); + d->mClientNameLabel = new QLabel(i18n("Network games:"), g); + d->mClientName = new QComboBox(g); + connect(d->mClientName,SIGNAL(activated(int)),SLOT(slotGameSelected(int))); + (void)new QLabel(i18n("Port to connect to:"), g); + d->mPort = new KIntNumInput(g); + (void)new QLabel(i18n("Host to connect to:"), g); + d->mHost = new QLineEdit(g); + + QPushButton *button=new QPushButton(i18n("&Start Network"), this); + connect(button, SIGNAL(clicked()), this, SIGNAL(signalNetworkSetup())); + vb->addWidget(button); + // Hide until type is set + d->mClientName->hide(); + d->mClientNameLabel->hide(); + d->mServerName->hide(); + d->mServerNameLabel->hide(); +} + +void KGameConnectWidget::showDnssdControls() +{ + if (!d->mBrowser) return; + if (d->mHost->isEnabled()) { // client + d->mClientName->show(); + d->mClientNameLabel->show(); + d->mServerName->hide(); + d->mServerNameLabel->hide(); + slotGameSelected(d->mClientName->currentItem()); + } else { + d->mClientName->hide(); + d->mClientNameLabel->hide(); + d->mServerName->show(); + d->mServerNameLabel->show(); + } +} + +void KGameConnectWidget::setType(const QString& type) +{ + d->mType = type; + delete d->mBrowser; + d->mBrowser = new DNSSD::ServiceBrowser(type); + connect(d->mBrowser,SIGNAL(finished()),SLOT(slotGamesFound())); + d->mBrowser->startBrowse(); + showDnssdControls(); +} + +void KGameConnectWidget::slotGamesFound() +{ + bool autoselect=false; + if (!d->mClientName->count()) autoselect=true; + d->mClientName->clear(); + QStringList names; + QValueList::ConstIterator itEnd = d->mBrowser->services().end(); + for (QValueList::ConstIterator it = d->mBrowser->services().begin(); + it!=itEnd; ++it) names << (*it)->serviceName(); + d->mClientName->insertStringList(names); + if (autoselect && d->mClientName->count()) slotGameSelected(0); +} + +void KGameConnectWidget::setName(const QString& name) +{ + d->mServerName->setText(name); +} + +QString KGameConnectWidget::gameName() const +{ + return d->mServerName->text(); +} + +QString KGameConnectWidget::type() const +{ + return d->mType; +} + +void KGameConnectWidget::slotGameSelected(int nr) +{ + if (nr>=(d->mBrowser->services().count()) || nr<0) return; + if (!d->mHost->isEnabled()) return; // this is server mode, do not overwrite host and port controls + DNSSD::RemoteService::Ptr srv = d->mBrowser->services()[nr]; + if (!srv->isResolved() && !srv->resolve()) return; + d->mHost->setText(srv->hostName()); + d->mPort->setValue(srv->port()); +} +KGameConnectWidget::~KGameConnectWidget() +{ + delete d->mBrowser; + delete d; +} + +QString KGameConnectWidget::host() const +{ + if (d->mHost->isEnabled()) { + return d->mHost->text(); + } else { + return QString::null; + } +} + +unsigned short int KGameConnectWidget::port() const +{ + return d->mPort->value(); +} + +void KGameConnectWidget::setHost(const QString& host) +{ + d->mHost->setText(host); +} + +void KGameConnectWidget::setPort(unsigned short int port) +{ + d->mPort->setValue(port); +} + +void KGameConnectWidget::setDefault(int state) +{ + d->mButtonGroup->setButton(state); + slotTypeChanged(state); +} + +void KGameConnectWidget::slotTypeChanged(int t) +{ + if (t == 0) { + d->mHost->setEnabled(false); + } else if (t == 1) { + d->mHost->setEnabled(true); + } + showDnssdControls(); + emit signalServerTypeChanged(t); +} + +class KGameConnectDialogPrivate +{ + public: + KGameConnectDialogPrivate() + { + mConnect = 0; + } + + KGameConnectWidget* mConnect; +}; + +// buttonmask =Ok|Cancel +KGameConnectDialog::KGameConnectDialog(QWidget* parent,int buttonmask) : KDialogBase(Plain, + i18n("Network Game"),buttonmask , Ok, parent, 0, true, buttonmask!=0) +{ + d = new KGameConnectDialogPrivate; + QVBoxLayout* vb = new QVBoxLayout(plainPage(), spacingHint()); + d->mConnect = new KGameConnectWidget(plainPage()); + vb->addWidget(d->mConnect); +} + +KGameConnectDialog::~KGameConnectDialog() +{ + delete d; +} + +int KGameConnectDialog::initConnection( unsigned short int& port, + QString& host, QWidget* parent, bool server) +{ + KGameConnectDialog d(parent); + d.setHost(host); + d.setPort(port); + if (server) { + d.setDefault(0); + } else { + d.setDefault(1); + } + + int result = d.exec(); + if (result == QDialog::Accepted) { + host = d.host(); + port = d.port(); + } + return result; +} + +QString KGameConnectDialog::host() const +{ + return d->mConnect->host(); +} + +unsigned short int KGameConnectDialog::port() const +{ + return d->mConnect->port(); +} + +void KGameConnectDialog::setHost(const QString& host) +{ + d->mConnect->setHost(host); +} + +void KGameConnectDialog::setPort(unsigned short int port) +{ + d->mConnect->setPort(port); +} + +void KGameConnectDialog::setDefault(int state) +{ + d->mConnect->setDefault(state); +} + + + +#include "kgameconnectdialog.moc" + diff --git a/libkdegames/kgame/dialogs/kgameconnectdialog.h b/libkdegames/kgame/dialogs/kgameconnectdialog.h new file mode 100644 index 00000000..acbf21d2 --- /dev/null +++ b/libkdegames/kgame/dialogs/kgameconnectdialog.h @@ -0,0 +1,169 @@ +/* + This file is part of the KDE games library + Copyright (C) 2001 Martin Heni (martin@heni-online.de) + Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KGAMECONNECTDIALOG_H__ +#define __KGAMECONNECTDIALOG_H__ + +#include + +class KGameConnectDialogPrivate; +class KGameConnectWidgetPrivate; + +class KGameConnectWidget : public QWidget +{ + Q_OBJECT +public: + KGameConnectWidget(QWidget* parent); + virtual ~KGameConnectWidget(); + + /** + * @param host The host to connect to by default + **/ + void setHost(const QString& host); + + /** + * @return The host to connect to or QString::null if the user wants to + * be the MASTER + **/ + QString host() const; + + /** + * @param port The port that will be shown by default + **/ + void setPort(unsigned short int port); + + /** + * @return The port to connect to / to listen + **/ + unsigned short int port() const; + + /** + * Specifies which state is the default (0 = server game; 1 = join game) + * @param state The default state. 0 For a server game, 1 to join a game + **/ + void setDefault(int state); + + /** + * Sets DNS-SD service type, both for publishing and browsing + * @param type Service type (something like _kwin4._tcp). + * It should be unique for application. + * @since 3.4 + **/ + void setType(const QString& type); + + /** + * @return service type + */ + QString type() const; + + /** + * Set game name for publishing. + * @param name Game name. Important only for server mode. If not + * set hostname will be used. In case of name conflict -2, -3 and so on will be added to name. + */ + void setName(const QString& name); + + /** + * @return game name. + */ + QString gameName() const; + +protected slots: + /** + * The type has changed, ie the user switched between creating or + * joining. + **/ + void slotTypeChanged(int); + void slotGamesFound(); + void slotGameSelected(int); + +signals: + void signalNetworkSetup(); + void signalServerTypeChanged(int); + +private: + void showDnssdControls(); + KGameConnectWidgetPrivate* d; + +}; + +/** + * @short Dialog to ask for host and port + * + * This Dialog is used to create a game. You call initConnection(port, + * QString::null, parent, true) to create a network game (as a server) + * or initConnection(port, host, parent) to join a network game. + * + * @author Andreas Beckermann + **/ +class KGameConnectDialog : public KDialogBase +{ + Q_OBJECT +public: + KGameConnectDialog(QWidget* parent = 0,int buttonmask=Ok|Cancel); + virtual ~KGameConnectDialog(); + + /** + * Shows a dialog to either connect to an existing game or to create a + * server game, depending on user's choice. + * @param port The port the user wants to connect to. + * @param host The host the user wants to connect to. Will be + * QString::null if server game is chosen + * @param parent The parent of the dialog + * @param server True to create a network game per default, false to + * join a game by default + **/ + static int initConnection(unsigned short int& port, QString& host, QWidget* parent, bool server = false); + + /** + * @param host The host to connect to by default + **/ + void setHost(const QString& host); + + /** + * @return The host to connect to or QString::null if the user wants to + * be the MASTER + **/ + QString host() const; + + /** + * @param port The port that will be shown by default + **/ + void setPort(unsigned short int port); + + /** + * @return The port to connect to / to listen + **/ + unsigned short int port() const; + + /** + * Specifies which state is the default (0 = server game; 1 = join game) + * @param state The default state. 0 For a server game, 1 to join a game + **/ + void setDefault(int state); + +signals: + void signalNetworkSetup(); + +private: + KGameConnectDialogPrivate* d; +}; + +#endif diff --git a/libkdegames/kgame/dialogs/kgamedebugdialog.cpp b/libkdegames/kgame/dialogs/kgamedebugdialog.cpp new file mode 100644 index 00000000..b112b04c --- /dev/null +++ b/libkdegames/kgame/dialogs/kgamedebugdialog.cpp @@ -0,0 +1,548 @@ +/* + This file is part of the KDE games library + Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) + Copyright (C) 2001 Martin Heni (martin@heni-online.de) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kgamedebugdialog.h" + +#include "kgamemessage.h" +#include "kgame.h" +#include "kplayer.h" +#include "kgamepropertyhandler.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + + +class KGameDebugDialogPrivate +{ +public: + KGameDebugDialogPrivate() + { + mGame = 0; + + mGamePage = 0; + mGameProperties = 0; + mGameAddress = 0; + mGameId = 0; + mGameCookie = 0; + mGameMaster = 0; + mGameAdmin = 0; + mGameOffering = 0; + mGameStatus = 0; + mGameRunning = 0; + mGameMaxPlayers = 0; + mGameMinPlayers = 0; + mGamePlayerCount = 0; + + mPlayerPage = 0; + mPlayerList = 0; + mPlayerProperties = 0; + mPlayerAddress = 0; + mPlayerId = 0; + mPlayerName = 0; + mPlayerGroup = 0; + mPlayerUserId = 0; + mPlayerMyTurn = 0; + mPlayerAsyncInput= 0; + mPlayerKGameAddress = 0; + mPlayerVirtual = 0; + mPlayerActive = 0; + mPlayerRtti = 0; + mPlayerNetworkPriority = 0; + + mMessagePage = 0; + mMessageList = 0; + mHideIdList = 0; + } + + const KGame* mGame; + + QFrame* mGamePage; + KListView* mGameProperties; + QListViewItem* mGameAddress; + QListViewItem* mGameId; + QListViewItem* mGameCookie; + QListViewItem* mGameMaster; + QListViewItem* mGameAdmin; + QListViewItem* mGameOffering; + QListViewItem* mGameStatus; + QListViewItem* mGameRunning; + QListViewItem* mGameMaxPlayers; + QListViewItem* mGameMinPlayers; + QListViewItem* mGamePlayerCount; + + QFrame* mPlayerPage; + KListBox* mPlayerList; + KListView* mPlayerProperties; + QListViewItem* mPlayerAddress; + QListViewItem* mPlayerId; + QListViewItem* mPlayerName; + QListViewItem* mPlayerGroup; + QListViewItem* mPlayerUserId; + QListViewItem* mPlayerMyTurn; + QListViewItem* mPlayerAsyncInput; + QListViewItem* mPlayerKGameAddress; + QListViewItem* mPlayerVirtual; + QListViewItem* mPlayerActive; + QListViewItem* mPlayerRtti; + QListViewItem* mPlayerNetworkPriority; + + QFrame* mMessagePage; + KListView* mMessageList; + KListBox* mHideIdList; +}; + +KGameDebugDialog::KGameDebugDialog(KGame* g, QWidget* parent, bool modal) : + KDialogBase(Tabbed, i18n("KGame Debug Dialog"), Close, Close, + parent, 0, modal, true) +{ + d = new KGameDebugDialogPrivate; + + initGamePage(); + initPlayerPage(); + initMessagePage(); + + setKGame(g); +} + +KGameDebugDialog::~KGameDebugDialog() +{ + delete d; +} + +void KGameDebugDialog::initGamePage() +{ + d->mGamePage = addPage(i18n("Debug &KGame")); + QVBoxLayout* topLayout = new QVBoxLayout(d->mGamePage, marginHint(), spacingHint()); + QHBoxLayout* layout = new QHBoxLayout(topLayout); + + KListView* v = new KListView(d->mGamePage); + v->addColumn(i18n("Data")); + v->addColumn(i18n("Value")); + layout->addWidget(v); + + d->mGameProperties = new KListView(d->mGamePage); + d->mGameProperties->addColumn(i18n("Property")); + d->mGameProperties->addColumn(i18n("Value")); + d->mGameProperties->addColumn(i18n("Policy")); + layout->addWidget(d->mGameProperties); + + QPushButton* b = new QPushButton(i18n("Update"), d->mGamePage); + connect(b, SIGNAL(pressed()), this, SLOT(slotUpdateGameData())); + topLayout->addWidget(b); + +// game data + d->mGameAddress = new QListViewItem(v, i18n("KGame Pointer")); + d->mGameId = new QListViewItem(v, i18n("Game ID")); + d->mGameCookie = new QListViewItem(v, i18n("Game Cookie")); + d->mGameMaster = new QListViewItem(v, i18n("Is Master")); + d->mGameAdmin = new QListViewItem(v, i18n("Is Admin")); + d->mGameOffering = new QListViewItem(v, i18n("Is Offering Connections")); + d->mGameStatus = new QListViewItem(v, i18n("Game Status")); + d->mGameRunning = new QListViewItem(v, i18n("Game is Running")); + d->mGameMaxPlayers = new QListViewItem(v, i18n("Maximal Players")); + d->mGameMinPlayers = new QListViewItem(v, i18n("Minimal Players")); + d->mGamePlayerCount = new QListViewItem(v, i18n("Players")); +} + +void KGameDebugDialog::initPlayerPage() +{ + d->mPlayerPage = addPage(i18n("Debug &Players")); + QVBoxLayout* topLayout = new QVBoxLayout(d->mPlayerPage, marginHint(), spacingHint()); + QHBoxLayout* layout = new QHBoxLayout(topLayout); + + //TODO: connect to the KGame signals for joined/removed players!!! + QVBoxLayout* listLayout = new QVBoxLayout(layout); + QLabel* listLabel = new QLabel(i18n("Available Players"), d->mPlayerPage); + listLayout->addWidget(listLabel); + d->mPlayerList = new KListBox(d->mPlayerPage); + connect(d->mPlayerList, SIGNAL(executed(QListBoxItem*)), this, SLOT(slotUpdatePlayerData(QListBoxItem*))); + listLayout->addWidget(d->mPlayerList); + d->mPlayerList->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding)); + + KListView* v = new KListView(d->mPlayerPage); + layout->addWidget(v); + v->addColumn(i18n("Data")); + v->addColumn(i18n("Value")); + + d->mPlayerProperties = new KListView(d->mPlayerPage); + d->mPlayerProperties->addColumn(i18n("Property")); + d->mPlayerProperties->addColumn(i18n("Value")); + d->mPlayerProperties->addColumn(i18n("Policy")); + layout->addWidget(d->mPlayerProperties); + + QPushButton* b = new QPushButton(i18n("Update"), d->mPlayerPage); + connect(b, SIGNAL(pressed()), this, SLOT(slotUpdatePlayerList())); + topLayout->addWidget(b); + + d->mPlayerAddress = new QListViewItem(v, i18n("Player Pointer")); + d->mPlayerId = new QListViewItem(v, i18n("Player ID")); + d->mPlayerName = new QListViewItem(v, i18n("Player Name")); + d->mPlayerGroup = new QListViewItem(v, i18n("Player Group")); + d->mPlayerUserId = new QListViewItem(v, i18n("Player User ID")); + d->mPlayerMyTurn = new QListViewItem(v, i18n("My Turn")); + d->mPlayerAsyncInput = new QListViewItem(v, i18n("Async Input")); + d->mPlayerKGameAddress = new QListViewItem(v, i18n("KGame Address")); + d->mPlayerVirtual = new QListViewItem(v, i18n("Player is Virtual")); + d->mPlayerActive = new QListViewItem(v, i18n("Player is Active")); + d->mPlayerRtti = new QListViewItem(v, i18n("RTTI")); + d->mPlayerNetworkPriority = new QListViewItem(v, i18n("Network Priority")); +} + +void KGameDebugDialog::initMessagePage() +{ + d->mMessagePage = addPage(i18n("Debug &Messages")); + QGridLayout* layout = new QGridLayout(d->mMessagePage, 11, 7, marginHint(), spacingHint()); + d->mMessageList = new KListView(d->mMessagePage); + layout->addMultiCellWidget(d->mMessageList, 0, 9, 0, 3); + d->mMessageList->addColumn(i18n("Time")); + d->mMessageList->addColumn(i18n("ID")); + d->mMessageList->addColumn(i18n("Receiver")); + d->mMessageList->addColumn(i18n("Sender")); + d->mMessageList->addColumn(i18n("ID - Text")); + + QPushButton* hide = new QPushButton(i18n("&>>"), d->mMessagePage); + connect(hide, SIGNAL(pressed()), this, SLOT(slotHideId())); + layout->addWidget(hide, 4, 4); + + QPushButton* show = new QPushButton(i18n("&<<"), d->mMessagePage); + connect(show, SIGNAL(pressed()), this, SLOT(slotShowId())); + layout->addWidget(show, 6, 4); + + QLabel* l = new QLabel(i18n("Do not show IDs:"), d->mMessagePage); + layout->addMultiCellWidget(l, 0, 0, 5, 6); + d->mHideIdList = new KListBox(d->mMessagePage); + layout->addMultiCellWidget(d->mHideIdList, 1, 8, 5, 6); + + QPushButton* clear = new KPushButton(KStdGuiItem::clear(), d->mMessagePage); + connect(clear, SIGNAL(pressed()), this, SLOT(slotClearMessages())); + layout->addMultiCellWidget(clear, 10, 10, 0, 6); + //TODO: "show all but..." and "show nothing but..." +} + +void KGameDebugDialog::clearPlayerData() +{ + d->mPlayerAddress->setText(1, ""); + d->mPlayerId->setText(1, ""); + d->mPlayerName->setText(1, ""); + d->mPlayerGroup->setText(1, ""); + d->mPlayerUserId->setText(1, ""); + d->mPlayerMyTurn->setText(1, ""); + d->mPlayerAsyncInput->setText(1, ""); + d->mPlayerKGameAddress->setText(1, ""); + d->mPlayerVirtual->setText(1, ""); + d->mPlayerActive->setText(1, ""); + d->mPlayerRtti->setText(1, ""); + d->mPlayerNetworkPriority->setText(1, ""); + + d->mPlayerProperties->clear(); +} + +void KGameDebugDialog::clearGameData() +{ + d->mGameAddress->setText(1, ""); + d->mGameId->setText(1, ""); + d->mGameCookie->setText(1, ""); + d->mGameMaster->setText(1, ""); + d->mGameAdmin->setText(1, ""); + d->mGameOffering->setText(1, ""); + d->mGameStatus->setText(1, ""); + d->mGameRunning->setText(1, ""); + d->mGameMaxPlayers->setText(1, ""); + d->mGameMinPlayers->setText(1, ""); + + d->mGameProperties->clear(); +} + +void KGameDebugDialog::slotUpdatePlayerData() +{ + if (!d->mGame || d->mPlayerList->currentItem() == -1) { + return; + } + slotUpdatePlayerData(d->mPlayerList->item(d->mPlayerList->currentItem())); +} + +void KGameDebugDialog::slotUpdatePlayerList() +{ + QListBoxItem* i = d->mPlayerList->firstItem(); + for (; i; i = d->mPlayerList->firstItem()) { + removePlayer(i); + } + + QPtrList list = *d->mGame->playerList(); + for (KPlayer* p = list.first(); p; p = list.next()) { + addPlayer(p); + } +} + +void KGameDebugDialog::slotUpdateGameData() +{ + if (!d->mGame) { + d->mGameAddress->setText(1, i18n("NULL pointer")); + return; +} + + clearGameData(); + + QString buf; + buf.sprintf("%p", d->mGame); + d->mGameAddress->setText(1, buf); + d->mGameId->setText(1, QString::number(d->mGame->gameId())); + d->mGameCookie->setText(1, QString::number(d->mGame->cookie())); + d->mGameMaster->setText(1, d->mGame->isMaster() ? i18n("True") : i18n("False")); + d->mGameAdmin->setText(1, d->mGame->isAdmin() ? i18n("True") : i18n("False")); + d->mGameOffering->setText(1, d->mGame->isOfferingConnections() ? i18n("True") : i18n("False")); + d->mGameStatus->setText(1, QString::number(d->mGame->gameStatus())); + d->mGameRunning->setText(1, d->mGame->isRunning() ? i18n("True") : i18n("False")); + d->mGameMaxPlayers->setText(1, QString::number(d->mGame->maxPlayers())); + d->mGameMinPlayers->setText(1, QString::number(d->mGame->minPlayers())); + d->mGamePlayerCount->setText(1, QString::number(d->mGame->playerCount())); + +//TODO ios + + KGamePropertyHandler* handler = d->mGame->dataHandler(); + QIntDictIterator it(handler->dict()); + while (it.current()) { + QString policy; + switch (it.current()->policy()) { + case KGamePropertyBase::PolicyClean: + policy = i18n("Clean"); + break; + case KGamePropertyBase::PolicyDirty: + policy = i18n("Dirty"); + break; + case KGamePropertyBase::PolicyLocal: + policy = i18n("Local"); + break; + case KGamePropertyBase::PolicyUndefined: + default: + policy = i18n("Undefined"); + break; + } + (void) new QListViewItem(d->mGameProperties, + handler->propertyName(it.current()->id()), + handler->propertyValue(it.current()), + policy); +// kdDebug(11001) << k_funcinfo << ": checking for all game properties: found property name " << name << endl; + ++it; + } +} + +void KGameDebugDialog::slotUpdatePlayerData(QListBoxItem* item) +{ + if (!item || !d->mGame) { + return; + } + + KPlayer* p = d->mGame->findPlayer(item->text().toInt()); + + if (!p) { + kdError(11001) << k_funcinfo << ": cannot find player" << endl; + return; + } + + clearPlayerData(); + + QString buf; + buf.sprintf("%p", p); + d->mPlayerAddress->setText(1, buf); + d->mPlayerId->setText(1, QString::number(p->id())); + d->mPlayerName->setText(1, p->name()); + d->mPlayerGroup->setText(1, p->group()); + d->mPlayerUserId->setText(1, QString::number(p->userId())); + d->mPlayerMyTurn->setText(1, p->myTurn() ? i18n("True") : i18n("False")); + d->mPlayerAsyncInput->setText(1, p->asyncInput() ? i18n("True") : i18n("False")); + buf.sprintf("%p", p->game()); + d->mPlayerKGameAddress->setText(1, buf); + d->mPlayerVirtual->setText(1, p->isVirtual() ? i18n("True") : i18n("False")); + d->mPlayerActive->setText(1, p->isActive() ? i18n("True") : i18n("False")); + d->mPlayerRtti->setText(1, QString::number(p->rtti())); + d->mPlayerNetworkPriority->setText(1, QString::number(p->networkPriority())); + +//TODO ios + +// Properties + KGamePropertyHandler * handler = p->dataHandler(); + QIntDictIterator it((handler->dict())); + while (it.current()) { + QString policy; + switch (it.current()->policy()) { + case KGamePropertyBase::PolicyClean: + policy = i18n("Clean"); + break; + case KGamePropertyBase::PolicyDirty: + policy = i18n("Dirty"); + break; + case KGamePropertyBase::PolicyLocal: + policy = i18n("Local"); + break; + case KGamePropertyBase::PolicyUndefined: + default: + policy = i18n("Undefined"); + break; + } + (void)new QListViewItem(d->mPlayerProperties, + handler->propertyName(it.current()->id()), + handler->propertyValue(it.current()), + policy); + ++it; + } +} + +void KGameDebugDialog::clearPages() +{ + clearPlayerData(); + clearGameData(); + d->mPlayerList->clear(); + slotClearMessages(); +} + +void KGameDebugDialog::setKGame(const KGame* g) +{ + slotUnsetKGame(); + d->mGame = g; + if (g) { + //TODO: connect to the KGame signals for joined/removed players!!! + connect(d->mGame, SIGNAL(destroyed()), this, SLOT(slotUnsetKGame())); +// connect(); + + QPtrList list = *d->mGame->playerList(); + for (KPlayer* p = list.first(); p; p = list.next()) { + addPlayer(p); + } + + slotUpdateGameData(); + + connect(d->mGame, SIGNAL(signalMessageUpdate(int, Q_UINT32, Q_UINT32)), this, SLOT(slotMessageUpdate(int, Q_UINT32, Q_UINT32))); + } +} + +void KGameDebugDialog::slotUnsetKGame() +{ + if (d->mGame) { + disconnect(d->mGame, 0, this, 0); + } + d->mGame = 0; + clearPages(); +} + +void KGameDebugDialog::addPlayer(KPlayer* p) +{ + if (!p) { + kdError(11001) << "trying to add NULL player" << endl; + return; + } + + (void) new QListBoxText(d->mPlayerList, QString::number(p->id())); + //TODO connect to signals, like deleted/removed, ... +} + +void KGameDebugDialog::removePlayer(QListBoxItem* i) +{ + if (!i || !d->mGame) { + return; + } + KPlayer* p = d->mGame->findPlayer(i->text().toInt()); + if (!p) { + return; + } + disconnect(p, 0, this, 0); + if (i->isSelected()) { + clearPlayerData(); + } + delete i; +} + +void KGameDebugDialog::slotMessageUpdate(int msgid, Q_UINT32 receiver, Q_UINT32 sender) +{ + if (!showId(msgid)) { + return; + } + QString msgidText = KGameMessage::messageId2Text(msgid); + if (msgidText.isNull()) { + if (msgid > KGameMessage::IdUser) { + emit signalRequestIdName(msgid-KGameMessage::IdUser, true, msgidText); + } else { + emit signalRequestIdName(msgid, false, msgidText); + } + if (msgidText.isNull()) { + msgidText = i18n("Unknown"); + } + } + (void) new QListViewItem( d->mMessageList, QTime::currentTime().toString(), + QString::number(msgid), QString::number(receiver), + QString::number(sender), msgidText); +} + +void KGameDebugDialog::slotClearMessages() +{ + d->mMessageList->clear(); +} + +void KGameDebugDialog::slotShowId() +{ +/* QListBoxItem* i = d->mHideIdList->firstItem(); + for (; i; i = i->next()) { + if (i->selected()) { + d->mHideIdList->removeItem(i->); + } + }*/ + if (!d->mHideIdList->currentItem()) { + return; + } + d->mHideIdList->removeItem(d->mHideIdList->currentItem()); +} + +void KGameDebugDialog::slotHideId() +{ + if (!d->mMessageList->currentItem()) { + return; + } + int msgid = d->mMessageList->currentItem()->text(1).toInt(); + if (!showId(msgid)) { + return; + } + (void)new QListBoxText(d->mHideIdList, QString::number(msgid)); +} + +bool KGameDebugDialog::showId(int msgid) +{ + QListBoxItem* i = d->mHideIdList->firstItem(); + for (; i; i = i->next()) { + if (i->text().toInt() == msgid) { + return false; + } + } + return true; +} + + +#include "kgamedebugdialog.moc" diff --git a/libkdegames/kgame/dialogs/kgamedebugdialog.h b/libkdegames/kgame/dialogs/kgamedebugdialog.h new file mode 100644 index 00000000..65afc92a --- /dev/null +++ b/libkdegames/kgame/dialogs/kgamedebugdialog.h @@ -0,0 +1,149 @@ +/* + This file is part of the KDE games library + Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) + Copyright (C) 2001 Martin Heni (martin@heni-online.de) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KGAMEDEBUGDIALOG_H__ +#define __KGAMEDEBUGDIALOG_H__ + +#include +#include + +class KGame; +class KGameIO; +class KPlayer; +class KGamePropertyBase; + +class KGameDebugDialogPrivate; + +class KDE_EXPORT KGameDebugDialog : public KDialogBase +{ + Q_OBJECT +public: + KGameDebugDialog(KGame* g, QWidget* parent, bool modal = false); + ~KGameDebugDialog(); + + /** + * Automatically connects the KGame object to all error dependant slots. + * Create a KGameErrorDialog object, call this function and forget + * everything. + * @param g The KGame which will emit the erorrs (or not ;-) ) + **/ + void setKGame(const KGame* g); + +public slots: + /** + * Unsets a @ref KGame which has been set using @ref setKGame before. + * This is called automatically when the @ref KGame object is destroyed + * and you normally don't have to call this yourself. + * + * Note that @ref setKGame also unsets an already existing @ref KGame + * object if exising. + **/ + void slotUnsetKGame(); + + /** + * Update the data of the @ref KGame object + **/ + void slotUpdateGameData(); + + /** + * Update the properties of the currently selected player + **/ + void slotUpdatePlayerData(); + + /** + * Updates the list of players and calls @ref clearPlayerData. Note that + * after this call NO player is selected anymore. + **/ + void slotUpdatePlayerList(); + + void slotClearMessages(); + +signals: + /** + * This signal is emitted when the "debug messages" page couldn't find + * the name of a message id. This is usually the case for user-defined + * messages. KGameDebugDialog asks you to give the msgid a name. + * @param messageid The ID of the message. As given to @ref + * KGame::sendMessage + * @param userid User defined msgIds are internally increased by + * @ref KGameMessage::IdUser. You don't have to care about this but if + * this signal is emitted with userid=false (shouldn't happen) then the + * name of an internal message as defined in @ref + * KGameMessage::GameMessageIds couldn't be found. + * @param name The name of the msgid. You have to fill this! + **/ + void signalRequestIdName(int messageid, bool userid, QString& name); + +protected: + void clearPages(); + + /** + * Clear the data of the player view. Note that the player list is NOT + * cleared. + **/ + void clearPlayerData(); + + /** + * Clear the data view of the @ref KGame object + **/ + void clearGameData(); + + /** + * Add a new player to the player list + **/ + void addPlayer(KPlayer* p); + + /** + * Remove a player from the list + **/ + void removePlayer(QListBoxItem* item); + + /** + * @return Whether messages with this msgid shall be displayed or not + **/ + bool showId(int msgid); + +protected slots: + /** + * Update the data of the player specified in item + * @param item The @ref QListBoxItem of the player to be updated. Note + * that the text of this item MUST be the ID of the player + **/ + void slotUpdatePlayerData(QListBoxItem* item); + + void slotShowId(); + void slotHideId(); + + /** + * A message has been received - see @ref KGame::signalMessageUpdate + **/ + void slotMessageUpdate(int msgid, Q_UINT32 receiver, Q_UINT32 sender); + +private: + void initGamePage(); + void initPlayerPage(); + void initMessagePage(); + +private: + KGameDebugDialogPrivate* d; +}; + + +#endif diff --git a/libkdegames/kgame/dialogs/kgamedialog.cpp b/libkdegames/kgame/dialogs/kgamedialog.cpp new file mode 100644 index 00000000..dc564b8e --- /dev/null +++ b/libkdegames/kgame/dialogs/kgamedialog.cpp @@ -0,0 +1,347 @@ +/* + This file is part of the KDE games library + Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) + Copyright (C) 2001 Martin Heni (martin@heni-online.de) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include + +#include + +#include "kgame.h" +#include "kplayer.h" +#include "kgamedialogconfig.h" + +#include "kgamedialog.h" + +#include "kgamedialog.moc" + +class KGameDialogPrivate +{ +public: + KGameDialogPrivate() + { + mGamePage = 0; + mNetworkPage = 0; + mMsgServerPage = 0; + mTopLayout = 0; + + mNetworkConfig = 0; + mGameConfig = 0; + + mOwner = 0; + mGame = 0; + } + + QVBox* mGamePage; + QVBox* mNetworkPage; + QVBox* mMsgServerPage;// unused here? + QVBoxLayout* mTopLayout; + KGameDialogNetworkConfig* mNetworkConfig; + KGameDialogGeneralConfig* mGameConfig; + +// a list of all config widgets added to this dialog + QPtrList mConfigWidgets; + +// just pointers: + KPlayer* mOwner; + KGame* mGame; +}; + +KGameDialog::KGameDialog(KGame* g, KPlayer* owner, const QString& title, + QWidget* parent, bool modal) + : KDialogBase(Tabbed, title, Ok|Default|Apply, + Ok, parent, 0, modal, true) +{ + init(g, owner); +} + +KGameDialog::KGameDialog(KGame* g, KPlayer* owner, const QString& title, + QWidget* parent, long initConfigs, int chatMsgId, bool modal) + : KDialogBase(Tabbed, title, Ok|Default|Apply, + Ok, parent, 0, modal, true) +{ + init(g, owner); + if ((ConfigOptions)initConfigs!=NoConfig) { + initDefaultDialog((ConfigOptions)initConfigs, chatMsgId); + } +} + +void KGameDialog::init(KGame* g, KPlayer* owner) +{ +//AB: do we need a "Cancel" Button? currently removed + +// kdDebug(11001) << k_funcinfo << ": this=" << this << endl; + d = new KGameDialogPrivate; + + setOwner(owner); + setKGame(g); + if (g) { + setAdmin(g->isAdmin()); + } else { + setAdmin(false); + } +} + +void KGameDialog::initDefaultDialog(ConfigOptions initConfigs, int chatMsgId) +{ + if (initConfigs & GameConfig) { + kdDebug() << "add gameconf" << endl; + addGameConfig(new KGameDialogGeneralConfig(0)); + } + if (initConfigs & NetworkConfig) { + addNetworkConfig(new KGameDialogNetworkConfig(0)); + } + if (initConfigs & (MsgServerConfig) ) { + addMsgServerConfig(new KGameDialogMsgServerConfig(0)); + } + if (initConfigs & ChatConfig) { + KGameDialogChatConfig * c = new KGameDialogChatConfig(chatMsgId, 0); + if (d->mGamePage) { + addChatWidget(c, d->mGamePage); + } else { + addConfigPage(c, i18n("&Chat")); + } + } + if (initConfigs & BanPlayerConfig) { + // add the connection management system - ie the widget where the ADMIN can + // kick players out + if (d->mNetworkPage) { + // put it on the network page + addConnectionList(new KGameDialogConnectionConfig(0), d->mNetworkPage); + } else { + // if no network page available put it on an own page + addConfigPage(new KGameDialogConnectionConfig(0), i18n("C&onnections")); + } + } +} + +KGameDialog::~KGameDialog() +{ +// kdDebug(11001) << "DESTRUCT KGameDialog" << this << endl; + d->mConfigWidgets.setAutoDelete(true); + d->mConfigWidgets.clear(); + delete d; +} + +void KGameDialog::addGameConfig(KGameDialogGeneralConfig* conf) +{ + if (!conf) { + return; + } + d->mGameConfig = conf; + d->mGamePage = addConfigPage(d->mGameConfig, i18n("&Game")); +} + +void KGameDialog::addNetworkConfig(KGameDialogNetworkConfig* netConf) +{ + if (!netConf) { + return; + } + d->mNetworkConfig = netConf; + d->mNetworkPage = addConfigPage(netConf, i18n("&Network")); +} + +void KGameDialog::addMsgServerConfig(KGameDialogMsgServerConfig* msgConf) +{ + if (!msgConf) { + return; + } + d->mMsgServerPage = addConfigPage(msgConf, i18n("&Message Server")); +} + +void KGameDialog::addChatWidget(KGameDialogChatConfig* chat, QVBox* parent) +{ + if (!chat) { + return; + } + if (!parent) { + parent = d->mGamePage; + } + if (!parent) { + kdError(11001) << "cannot add chat widget without page" << endl; + return; + } + addConfigWidget(chat, parent); +} + +void KGameDialog::addConnectionList(KGameDialogConnectionConfig* c, QVBox* parent) +{ + if (!c) { + return; + } + if (!parent) { + parent = d->mNetworkPage; + } + if (!parent) { + kdError(11001) << "Cannot add connection list without page" << endl; + return; + } + addConfigWidget(c, parent); +} + +QVBox *KGameDialog::configPage(ConfigOptions which) +{ + QVBox *box = 0; + switch(which) + { + case NetworkConfig: + box = d->mNetworkPage; + break; + case GameConfig: + box = d->mGamePage; + break; + case MsgServerConfig: + box = d->mMsgServerPage; + break; + default: + kdError(11001) << k_funcinfo << ": Parameter " << which << " not supported" << endl; + } + return box; +} + +QVBox* KGameDialog::addConfigPage(KGameDialogConfig* widget, const QString& title) +{ + if (!widget) { + kdError(11001) << "Cannot add NULL config widget" << endl; + return 0; + } + QVBox* page = addVBoxPage(title); + addConfigWidget(widget, page); + return page; +} + +void KGameDialog::addConfigWidget(KGameDialogConfig* widget, QWidget* parent) +{ + if (!widget) { + kdError(11001) << "Cannot add NULL config widget" << endl; + return; + } + if (!parent) { + kdError(11001) << "Cannot reparent to NULL widget" << endl; + return; + } +// kdDebug(11001) << "reparenting widget" << endl; + widget->reparent(parent, QPoint(0,0)); + d->mConfigWidgets.append(widget); + connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(slotRemoveConfigWidget(QObject*))); + if (!d->mGame) { + kdWarning(11001) << "No game has been set!" << endl; + } else { + widget->setKGame(d->mGame); + widget->setAdmin(d->mGame->isAdmin()); + } + if (!d->mOwner) { + kdWarning(11001) << "No player has been set!" << endl; + } else { + widget->setOwner(d->mOwner); + } + widget->show(); +} + +KGameDialogGeneralConfig* KGameDialog::gameConfig() const +{ return d->mGameConfig; } +KGameDialogNetworkConfig* KGameDialog::networkConfig() const +{ return d->mNetworkConfig; } + +void KGameDialog::slotApply() +{ + submitToKGame(); +} + +void KGameDialog::slotDefault() +{ + if (!d->mGame) { + return; + } + +//TODO *only* call setKGame/setOwner for the *current* page!! + setKGame(d->mGame); + setOwner(d->mOwner); +} + +void KGameDialog::slotOk() +{ + slotApply(); + QDialog::accept(); +} + +void KGameDialog::setOwner(KPlayer* owner) +{ +//AB: note: NULL player is ok! + d->mOwner = owner; + for (int unsigned i = 0; i < d->mConfigWidgets.count(); i++) { + if (d->mConfigWidgets.at(i)) { + d->mConfigWidgets.at(i)->setOwner(d->mOwner); + //TODO: hide playerName in KGameDialogGeneralConfig + } else { + kdError(11001) << "NULL widget??" << endl; + } + } +} + +void KGameDialog::setKGame(KGame* g) +{ + if (d->mGame) { + disconnect(d->mGame, 0, this, 0); + } + d->mGame = g; + for (int unsigned i = 0; i < d->mConfigWidgets.count(); i++) { + d->mConfigWidgets.at(i)->setKGame(d->mGame); + } + if (d->mGame) { + setAdmin(d->mGame->isAdmin()); + connect(d->mGame, SIGNAL(destroyed()), this, SLOT(slotUnsetKGame())); + connect(d->mGame, SIGNAL(signalAdminStatusChanged(bool)), + this, SLOT(setAdmin(bool))); + } +} + +void KGameDialog::setAdmin(bool admin) +{ + for (int unsigned i = 0; i < d->mConfigWidgets.count(); i++) { + d->mConfigWidgets.at(i)->setAdmin(admin); + } +} + +void KGameDialog::slotUnsetKGame() // called when KGame is destroyed +{ setKGame(0); } + +void KGameDialog::submitToKGame() +{ + if (!d->mGame) { + kdError(11001) << k_funcinfo << ": no game has been set" << endl; + return; + } + if (!d->mOwner) { + kdError(11001) << k_funcinfo << ": no player has been set" << endl; + return; + } + + for (int unsigned i = 0; i < d->mConfigWidgets.count(); i++) { +// kdDebug(11001) << "submit to kgame " << i << endl; + d->mConfigWidgets.at(i)->submitToKGame(d->mGame, d->mOwner); +// kdDebug(11001) << "done: submit to kgame " << i << endl; + } +} + +void KGameDialog::slotRemoveConfigWidget(QObject* configWidget) +{ + d->mConfigWidgets.removeRef((KGameDialogConfig*)configWidget); +} + diff --git a/libkdegames/kgame/dialogs/kgamedialog.h b/libkdegames/kgame/dialogs/kgamedialog.h new file mode 100644 index 00000000..f7a0c6e5 --- /dev/null +++ b/libkdegames/kgame/dialogs/kgamedialog.h @@ -0,0 +1,320 @@ +/* + This file is part of the KDE games library + Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) + Copyright (C) 2001 Martin Heni (martin@heni-online.de) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +// NAMING +// please follow these naming rules if you add/change classes: +// the main dialog is named KGameDialog and the base config widget +// KGameDialogConfig. All config widgets are named KGameDialogXYZConfig (where +// XYZ = the name of the config widget, like "general" or "network") and are +// inherited from KGameDialogConfig. + +#ifndef __KGAMEDIALOG_H__ +#define __KGAMEDIALOG_H__ + +#include +#include +class QGridLayout; +class QVBoxLayout; +class QListBoxItem; + +class KGame; +class KPlayer; +class KGamePropertyBase; + +class KGameDialogConfig; +class KGameDialogGeneralConfig; +class KGameDialogNetworkConfig; +class KGameDialogMsgServerConfig; +class KGameDialogChatConfig; +class KGameDialogConnectionConfig; + +class KGameDialogPrivate; +/** + * TODO: rewrite entire documentation. Nearly nothing is valid anymore. + * The main configuration dialog for KGame. Here all players meat each other, + * every player can see how many players connected (and their names) and the + * ADMIN can even "kick" players out. You can talk to each other (using + * KGameChat and the ADMIN can define the maxPlayers/minPlayers as well as the + * number of computer players. + * + * + * AB: setDefaultXYZ is obsolete!! + * You will usually create an instance of KGameDialog or any derived class and + * call setDefaultXYZ methods. Example (maybe + * obsoleted parameters - docu is currently changing very fast): + * \code + * KGameDialog dlg(kgame, i18n("New Game"), localPlayer, this, true, + * ID_CHAT); + * dlg.setDefaultNetworkInfo(port, host); // AB: obsolete! + * dlg.exec(); + * \endcode + * This will create a default modal dialog with the title "New Game". You don't + * have to do more than this. + * + * @short Main configuration dialog for KGame + * @author Andreas Beckermann + **/ +class KDE_EXPORT KGameDialog : public KDialogBase +{ + Q_OBJECT +public: + + enum ConfigOptions + { + NoConfig = 0, + ChatConfig = 1, + GameConfig = 2, + NetworkConfig = 4, + MsgServerConfig = 8, + BanPlayerConfig = 16, + AllConfig = 0xffff + }; + + /** + * Create an empty KGameDialog. You can add widgets using + * addConfigPage. + * @param g The KGame object of this game + * @param owner The KPlayer object who is responsible for this + * dialog, aka "the local player" + * @param title The title of the dialog - see KDialog::setCaption + * @param parent The parent of the dialog + * @param modal Whether the dialog is modal or not + **/ + KGameDialog(KGame* g, KPlayer* owner, const QString& title, + QWidget* parent, bool modal = false); + + /** + * Create a KGameDialog with the standard configuration widgets. This + * creates the following widgets: + *
    + *
  • KGameDialogGeneralConfig + *
  • KGameDialogNetworkConfig + *
  • KGameDialogMsgServerConfig + *
  • KGameDialogChatConfig + *
  • KGameDialogConnectionConfig + *
+ * If you want to use your own implementations (or none) of the widgets + * above you should subclass KGameDialog. Use addGameConfig, + * addNetworkConfig, addMsgConfig, addChatWidget and + * addConnectionList in this case. + * + * If you want to add further configuration widget you can simply use + * addConfigPage + * @param g The KGame object of this game + * @param owner The KPlayer object who is responsible for this + * dialog, aka "the local player" + * @param title The title of the dialog - see KDialog::setCaption + * @param parent The parent of the dialog + * @param modal Whether the dialog is modal or not + * @param initConfigs whether the default KGameDialogConfig widgets + * shall be created using initDefaultDialog. Use false if you want + * to use custom widgets. + * @param chatMsgId The ID of Chat messages. See KGameChat. Unused + * if initConfigs = false + **/ + KGameDialog(KGame* g, KPlayer* owner, const QString& title, + QWidget* parent, long initConfigs = AllConfig, + int chatMsgId = 15432, bool modal = false); + + virtual ~KGameDialog(); + + + /** + * Change the owner of the dialog. This will be used as the fromPlayer in + * KGameChat and will receive the entered player name. + * @param owner The owner of the dialog. It must already be added to the + * KGame object! + * + * Calls the KGameDialogConfig::setOwner implementation of all + * widgets that have been added by addConfigWidget + * @param owner The new owner player of this dialog must already be + * added to the KGame object. Can even be NULL (then no player + * configuration is made) + **/ + void setOwner(KPlayer* owner); + + /** + * Change the KGame object this dialog is used for. + * + * Calls the KGameDialogConfig::setKGame implementation of all + * widgets that have been added by addConfigWidget + * @param g The new KGame object + **/ + void setKGame(KGame* g); + + /** + * This will submit all configuration data to the KGame object. + * Automatically called by slotApply and slotOk + * There is no need to replace this unless you + * want to add widgets which are not derived from those classes + **/ + virtual void submitToKGame(); + + /** + * Adds a KGameChat to the dialog. If no parent is specified the + * game page will be used. + * @param chat The chat widget + * @param parent The parent of the chat widget. This MUST be an + * already added config widget. Note that the game page will be used + * if parent is 0. + **/ + void addChatWidget(KGameDialogChatConfig* chat, QVBox* parent = 0); + + /** + * Add a connection list to the dialog. The list consists of a + * KLisBox containing all players in the current game (see + * KGame::playerList). The admin can "ban" players, ie kick them out of + * the game. + * + * This is another not-really-config-config-widget. It just displays the + * connections and lets you ban players. + * @param c The KGameDialogConnectionConfig object + * @param parent The parent of the widget. If 0 the networkConfig + * page is used. + **/ + void addConnectionList(KGameDialogConnectionConfig* c, QVBox* parent = 0); + + /** + * Add a new page to the dialog. The page will contain you new config + * widget and will have your provided title. + * + * The widget will be reparented to this dialog. This also calls + * KGameDialogConfig::setKGame and KGameDialogConfig::setOwner. + * @param widget The new config widget + * @param title The title of the newly added page. + * @return The newly added page which contains your config widget. + **/ + QVBox* addConfigPage(KGameDialogConfig* widget, const QString& title); + + /** + * @return The QVBox of the given key, The key is from ConfigOptions + * Note that not all are supported yet + **/ + QVBox *configPage(ConfigOptions which); + + /** + * @return The default netowrk config. Note that this always returns 0 if + * you did not specify NetworkConfig in the constructor! + **/ + KGameDialogNetworkConfig* networkConfig() const; + + /** + * @return The default game config. Note that this always returns 0 if + * you did not specify GameConfig in the constructor! + **/ + KGameDialogGeneralConfig* gameConfig() const; + + /** + * Add a config widget to the specified parent. Usually you call + * addConfigPage for one widget and addConfigWidget for another to add + * it to the same page. Just use the returned page of + * addConfigPage. + **/ + void addConfigWidget(KGameDialogConfig* widget, QWidget* parent); + + /** + * Used to add the main network config widget in a new page. Use this to + * make networkConfig return something useful. + **/ + void addNetworkConfig(KGameDialogNetworkConfig* netConf); + + /** + * Add the main game config widget in a new page. Use this to make + * gameConfig return something useful. + **/ + void addGameConfig(KGameDialogGeneralConfig* conf); + + /** + * Used to add the message server config widget in a new page. + **/ + void addMsgServerConfig(KGameDialogMsgServerConfig* conf); + +protected: + + /** + * This is used to create a dialog containing all the default widgets. + * + * You may want to use this if you just want to use your own + * configuration widgets which inherit the standard ones. + * + * Note that if one of the widgets is NULL the default implementation + * will be used! (except the chat widget - you need to create it + * yourself as you have to provide a message id) + * @param initConfigs The widgets to be created + * @param chatMsgId The msgid for the chat config (only if specified in + * initConfigs) - see KGameDialogChatConfig + **/ + void initDefaultDialog(ConfigOptions initConfigs, int chatMsgId = 15432); + + /** + * Go through all config widgets and call their + * KGameDialogConfig::setKGame and KGameDialogConfig::setOwner implementation + * + * This function could be private and probably will be very soon. + * Don't use it yourself + **/ + void configureConfigWidgets(); + +protected slots: + /** + * Called when the user clicks on Ok. Calls slotApply and + * QDialog::accept() + **/ + virtual void slotOk(); + + /** + * Just calls submitToKGame() + **/ + virtual void slotApply(); + + /** + * Sets the default values for the configuration widgets. Set these + * values by (e.g.) setDefaultMaxPlayers() + * @deprecated + **/ + virtual void slotDefault(); + + /** + * Called when the KGame object is destroyed. Calls setKGame(0) so + * that all widgets can disconnect their slots and so on. + **/ + void slotUnsetKGame(); + + /** + * Called when the ADMIN status of this KGame client changes. See + * KGameNetwork::signalAdminStatusChanged + * @param isAdmin TRUE if this client is now the ADMIN otherwise FALSE + **/ + void setAdmin(bool isAdmin); + + /** + * Remove a config widget from the widget list. + * @see QObject::destroyed + **/ + void slotRemoveConfigWidget(QObject* configWidget); + +private: + void init(KGame*, KPlayer*); + +private: + KGameDialogPrivate* d; +}; + +#endif diff --git a/libkdegames/kgame/dialogs/kgamedialogconfig.cpp b/libkdegames/kgame/dialogs/kgamedialogconfig.cpp new file mode 100644 index 00000000..27f91cd1 --- /dev/null +++ b/libkdegames/kgame/dialogs/kgamedialogconfig.cpp @@ -0,0 +1,773 @@ +/* + This file is part of the KDE games library + Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) + Copyright (C) 2001 Martin Heni (martin@heni-online.de) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kgamedialogconfig.h" + +#include "kgame.h" +#include "kplayer.h" +#include "kgamechat.h" +#include "kgameconnectdialog.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "kgamedialogconfig.moc" + +class KGameDialogConfigPrivate +{ +public: + KGameDialogConfigPrivate() + { + mOwner = 0; + mGame = 0; + + mAdmin = false; + } + + bool mAdmin; + KGame* mGame; + KPlayer* mOwner; +}; + +KGameDialogConfig::KGameDialogConfig(QWidget* parent) : QWidget(parent) +{ + d = new KGameDialogConfigPrivate; +} + +KGameDialogConfig::~KGameDialogConfig() +{ + kdDebug(11001) << k_funcinfo << endl; + delete d; +} + +void KGameDialogConfig::setKGame(KGame* g) +{ + d->mGame = g; +} + +void KGameDialogConfig::setOwner(KPlayer* p) +{ + d->mOwner = p; +} + +void KGameDialogConfig::setAdmin(bool a) +{ + d->mAdmin = a; +} + +KGame* KGameDialogConfig::game() const +{ return d->mGame; } +bool KGameDialogConfig::admin() const +{ return d->mAdmin; } +KPlayer* KGameDialogConfig::owner() const +{ return d->mOwner; } + +/////////////////////////// KGameDialogNetworkConfig ///////////////////////// +class KGameDialogNetworkConfigPrivate +{ +public: + KGameDialogNetworkConfigPrivate() + { + mInitConnection = 0; + mNetworkLabel = 0; + mDisconnectButton = 0; + mConnect = 0; + mDefaultServer=true; + + } + + // QPushButton* mInitConnection; + QHGroupBox* mInitConnection; + QLabel* mNetworkLabel; + QPushButton *mDisconnectButton; + + bool mDefaultServer; + QString mDefaultHost; + unsigned short int mDefaultPort; + KGameConnectWidget *mConnect; +}; + + +KGameDialogNetworkConfig::KGameDialogNetworkConfig(QWidget* parent) + : KGameDialogConfig(parent) +{ +// kdDebug(11001) << k_funcinfo << ": this=" << this << endl; + d = new KGameDialogNetworkConfigPrivate(); + + QVBoxLayout* topLayout = new QVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint(), "toplayout"); + + QHBoxLayout *hb = new QHBoxLayout(topLayout, KDialog::spacingHint()); + + d->mNetworkLabel = new QLabel(this); + hb->addWidget(d->mNetworkLabel); + + d->mDisconnectButton=new QPushButton(i18n("Disconnect"),this); + connect(d->mDisconnectButton, SIGNAL(clicked()), this, SLOT(slotExitConnection())); + hb->addWidget(d->mDisconnectButton); + + d->mInitConnection = new QHGroupBox(i18n("Network Configuration"), this); + topLayout->addWidget(d->mInitConnection); + + d->mConnect = new KGameConnectWidget(d->mInitConnection); + connect(d->mConnect, SIGNAL(signalNetworkSetup()), this, SLOT(slotInitConnection())); + connect(d->mConnect, SIGNAL(signalServerTypeChanged(int)), + this, SIGNAL(signalServerTypeChanged(int))); + + // Needs to be AFTER the creation of the dialogs + setConnected(false); + setDefaultNetworkInfo("localhost", 7654,true); +} + +KGameDialogNetworkConfig::~KGameDialogNetworkConfig() +{ + kdDebug(11001) << k_funcinfo << endl; + delete d; +} + +void KGameDialogNetworkConfig::slotExitConnection() +{ + kdDebug(11001) << k_funcinfo << " !!!!!!!!!!!!!!!!!!!!!!!" << endl; + if (game()) game()->disconnect(); + setConnected(false,false); +} + +void KGameDialogNetworkConfig::slotInitConnection() +{ + kdDebug(11001) << k_funcinfo << endl; + bool connected = false; + bool master = true; + unsigned short int port = d->mConnect->port(); + QString host = d->mConnect->host(); + + if (host.isNull()) { + master = true; + if (game()) { + game()->setDiscoveryInfo(d->mConnect->type(),d->mConnect->gameName()); + connected = game()->offerConnections(port); + } + } else { + master = false; + if (game()) { + connected = game()->connectToServer(host, port); + } + // We need to learn about failed connections + if (game()) { + connect(game(), SIGNAL(signalConnectionBroken()), + this, SLOT(slotConnectionBroken())); + } + } + setConnected(connected, master); +} + +void KGameDialogNetworkConfig::slotConnectionBroken() +{ + kdDebug(11001) << k_funcinfo << endl; + setConnected(false,false); + KMessageBox::error(this, i18n("Cannot connect to the network")); +} + +void KGameDialogNetworkConfig::setConnected(bool connected, bool master) +{ + if (!connected) { + d->mNetworkLabel->setText(i18n("Network status: No Network")); + d->mInitConnection->setEnabled(true); + d->mDisconnectButton->setEnabled(false); + return; + } + if (master) { + d->mNetworkLabel->setText(i18n("Network status: You are MASTER")); + } else { + d->mNetworkLabel->setText(i18n("Network status: You are connected")); + } + d->mInitConnection->setEnabled(false); + d->mDisconnectButton->setEnabled(true); +} + +void KGameDialogNetworkConfig::submitToKGame(KGame* , KPlayer* ) +{ +} + +void KGameDialogNetworkConfig::setKGame(KGame* g) +{ + KGameDialogConfig::setKGame(g); + if (!game()) { + setConnected(false); + return; + } + setConnected(game()->isNetwork(), game()->isMaster()); +} + +void KGameDialogNetworkConfig::setDefaultNetworkInfo(const QString& host, unsigned short int port,bool server) +{ + d->mDefaultPort = port; + d->mDefaultHost = host; + d->mDefaultServer = server; + + d->mConnect->setHost(host); + d->mConnect->setPort(port); + if (server) { + d->mConnect->setDefault(0); + } else { + d->mConnect->setDefault(1); + } +} + +void KGameDialogNetworkConfig::setDiscoveryInfo(const QString& type, const QString& name) +{ + d->mConnect->setType(type); + d->mConnect->setName(name); +} + +/////////////////////////// KGameDialogGeneralConfig ///////////////////////// +class KGameDialogGeneralConfigPrivate +{ +public: + KGameDialogGeneralConfigPrivate() + { + mTopLayout = 0; + mName = 0; + } + + QLineEdit* mName; + + QVBoxLayout* mTopLayout; +}; + +KGameDialogGeneralConfig::KGameDialogGeneralConfig(QWidget* parent, bool initializeGUI) + : KGameDialogConfig(parent) +{ +// kdDebug(11001) << k_funcinfo << ": this=" << this << endl; + d = new KGameDialogGeneralConfigPrivate; + + if (initializeGUI) { + d->mTopLayout = new QVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint()); + d->mTopLayout->setAutoAdd(true); + + QWidget* nameWidget = new QWidget(this); + QHBoxLayout* l = new QHBoxLayout(nameWidget); + QLabel* nameLabel = new QLabel(i18n("Your name:"), nameWidget); + l->addWidget(nameLabel); + d->mName = new QLineEdit(nameWidget); + l->addWidget(d->mName); + } +} + +KGameDialogGeneralConfig::~KGameDialogGeneralConfig() +{ + kdDebug(11001) << k_funcinfo << endl; + delete d; +} + +void KGameDialogGeneralConfig::setPlayerName(const QString& name) +{ + if (d->mName) { + d->mName->setText(name); + } +} + +QString KGameDialogGeneralConfig::playerName() const +{ + return d->mName ? d->mName->text() : QString::null; +} + +void KGameDialogGeneralConfig::setOwner(KPlayer* p) +{ + if (owner()) { + owner()->disconnect(this); + } + KGameDialogConfig::setOwner(p); + if (!owner()) { + // can this config be used at all? + // maybe call hide() + return; + } + connect(owner(), SIGNAL(signalPropertyChanged(KGamePropertyBase*, KPlayer*)), + this, SLOT(slotPropertyChanged(KGamePropertyBase*, KPlayer*))); + setPlayerName(p->name()); + //TODO: connect signalPropertyChanged and check for playername changes! +} + +void KGameDialogGeneralConfig::setKGame(KGame* g) +{ + KGameDialogConfig::setKGame(g); + if (!g) { + // TODO + // can this config be used at all? + // maybe call hide() + return; + } +} + +void KGameDialogGeneralConfig::setAdmin(bool admin) +{ + KGameDialogConfig::setAdmin(admin); +// enable/disable widgets + +} + +void KGameDialogGeneralConfig::submitToKGame(KGame* g, KPlayer* p) +{ +//FIXME + if (p) { + p->setName(playerName()); + } + if (g) { + } +} + +void KGameDialogGeneralConfig::slotPropertyChanged(KGamePropertyBase* prop, KPlayer* p) +{ + if (!prop || !p || p != owner()) { + return; + } + switch (prop->id()) { + case KGamePropertyBase::IdName: + setPlayerName(p->name()); + break; + default: + break; + } +} + +class KGameDialogMsgServerConfigPrivate +{ +public: + KGameDialogMsgServerConfigPrivate() + { + senderLayout = 0; + localLayout = 0; + + changeMaxClients = 0; + changeAdmin= 0; + removeClient= 0; + noAdmin = 0; + + noMaster = 0; + } + + QVBoxLayout* senderLayout; + QHBoxLayout* localLayout; + + QPushButton* changeMaxClients; + QPushButton* changeAdmin; + QPushButton* removeClient; + QLabel* noAdmin; + + QLabel* noMaster; +}; + + +// TODO: change ADMIN ID, remove CLIENTS, change MAXCLIENTS +// we do everything here with QPushButtons as we want to wait a moment before +// continuing - the message must be sent over network first +KGameDialogMsgServerConfig::KGameDialogMsgServerConfig(QWidget* parent) + : KGameDialogConfig(parent) +{ + d = new KGameDialogMsgServerConfigPrivate; + + QVBoxLayout* topLayout = new QVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint()); + d->senderLayout = new QVBoxLayout(topLayout); + d->localLayout = new QHBoxLayout(topLayout); +} + +KGameDialogMsgServerConfig::~KGameDialogMsgServerConfig() +{ + kdDebug(11001) << k_funcinfo << endl; + delete d; +} + +void KGameDialogMsgServerConfig::setKGame(KGame* g) +{ + KGameDialogConfig::setKGame(g); + //TODO display the ID of the admin if we aren't + // connect(g, SIGNAL(signalAdminChanged(int)), this, SLOT(slotChangeIsAdmin(int)));//TODO + if (!game()) { + // we cannot do anything without a KGame object! + setAdmin(false); + return; + } + setAdmin(game()->isAdmin()); + setHasMsgServer(game()->messageServer()); +} + + +void KGameDialogMsgServerConfig::slotChangeMaxClients() +{ + if (!game()) { + kdError(11001) << k_funcinfo << ": no valid game object available!" << endl; + return; + } + if (!game()->isAdmin()) { + kdError(11001) << k_funcinfo << ": only ADMIN is allowed to call this!" << endl; + return; + } + int max; +// edit->setText(QString::number()); // current max clients! //TODO + + QDialog* dialog = new QDialog(); + dialog->setCaption(i18n("Maximal Number of Clients")); + QHBoxLayout* l = new QHBoxLayout(dialog, KDialog::marginHint(), KDialog::spacingHint()); + l->setAutoAdd(true); + + (void) new QLabel(i18n("Maximal number of clients (-1 = infinite):"), dialog); + QLineEdit* edit = new QLineEdit(dialog);//TODO: use KIntNumInput +// edit->setText(QString::number(max)); // current max clients! //TODO + if (dialog->exec() == QDialog::Accepted) { + bool ok; + max = edit->text().toInt(&ok); + if (ok) { + game()->setMaxClients(max); + } + } + +} + +void KGameDialogMsgServerConfig::slotRemoveClient() +{ +} + +void KGameDialogMsgServerConfig::slotChangeAdmin() +{ + if (!game()) { + kdError(11001) << k_funcinfo << ": no valid game object available!" << endl; + return; + } + if (!admin()) { + kdError(11001) << k_funcinfo << ": only ADMIN is allowed to call this!" << endl; + return; + } + //TODO + Q_UINT32 newAdmin = 0; +// newAdmin = ; + game()->electAdmin(newAdmin); +} + +void KGameDialogMsgServerConfig::removeClient(Q_UINT32 /*id*/) +{ +//TODO +} + +void KGameDialogMsgServerConfig::setAdmin(bool a) +{ + if (admin() == a) { + // no need to do anything + return; + } + KGameDialogConfig::setAdmin(a); + if (admin()) { + if (d->noAdmin) { + delete d->noAdmin; + d->noAdmin = 0; + } + d->changeMaxClients = new QPushButton(i18n("Change Maximal Number of Clients"), this); + connect(d->changeMaxClients, SIGNAL(pressed()), this, SLOT(slotChangeMaxClients())); + d->changeAdmin = new QPushButton(i18n("Change Admin"), this); + connect(d->changeAdmin, SIGNAL(pressed()), this, SLOT(slotChangeAdmin())); + d->removeClient = new QPushButton(i18n("Remove Client with All Players"), this); + connect(d->removeClient, SIGNAL(pressed()), this, SLOT(slotRemoveClient())); + d->senderLayout->addWidget(d->changeMaxClients); + d->senderLayout->addWidget(d->changeAdmin); + d->senderLayout->addWidget(d->removeClient); + } else { + if (d->changeMaxClients) { + delete d->changeMaxClients; + d->changeMaxClients = 0; + } + if (d->changeAdmin) { + delete d->changeAdmin; + d->changeAdmin = 0; + } + if (d->removeClient) { + delete d->removeClient; + d->removeClient = 0; + } + d->noAdmin = new QLabel(i18n("Only the admin can configure the message server!"), this); + d->senderLayout->addWidget(d->noAdmin); + } +} + + +void KGameDialogMsgServerConfig::setHasMsgServer(bool has) +{ + if (!has) { + // delete all inputs + if (!d->noMaster) { + d->noMaster = new QLabel(i18n("You don't own the message server"), this); + d->localLayout->addWidget(d->noMaster); + } + return; + } + if (d->noMaster) { + delete d->noMaster; + d->noMaster = 0; + } + //TODO + // list all connections, data (max clients) and so on + // cannot be done above (together with QPushButtons) as it is possible that + // this client is ADMIN but not MASTER (i.e. doesn't own the messageserver) +} + + +class KGameDialogChatConfigPrivate +{ +public: + KGameDialogChatConfigPrivate() + { + mChat = 0; + } + + KGameChat* mChat; +}; + +KGameDialogChatConfig::KGameDialogChatConfig(int chatMsgId, QWidget* parent) + : KGameDialogConfig(parent) +{ + d = new KGameDialogChatConfigPrivate; + QVBoxLayout* topLayout = new QVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint()); + topLayout->setAutoAdd(true); + QHGroupBox* b = new QHGroupBox(i18n("Chat"), this); + d->mChat = new KGameChat(0, chatMsgId, b); +} + +KGameDialogChatConfig::~KGameDialogChatConfig() +{ + kdDebug(11001) << k_funcinfo << endl; + delete d; +} + +void KGameDialogChatConfig::setKGame(KGame* g) +{ + KGameDialogConfig::setKGame(g); + d->mChat->setKGame(game()); + if (!game()) { + hide(); + } else { + show(); + } +} + +void KGameDialogChatConfig::setOwner(KPlayer* p) +{ + KGameDialogConfig::setOwner(p); + if (!owner()) { + hide(); + return; + } + d->mChat->setFromPlayer(owner()); + show(); +} + + + +class KGameDialogConnectionConfigPrivate +{ +public: + KGameDialogConnectionConfigPrivate() + { + mPlayerBox = 0; + } + + QPtrDict mItem2Player; + KListBox* mPlayerBox; +}; + +KGameDialogConnectionConfig::KGameDialogConnectionConfig(QWidget* parent) + : KGameDialogConfig(parent) +{ + //TODO: prevent player to ban himself + d = new KGameDialogConnectionConfigPrivate; + QVBoxLayout* topLayout = new QVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint()); + topLayout->setAutoAdd(true); + QHGroupBox* b = new QHGroupBox(i18n("Connected Players"), this); + d->mPlayerBox = new KListBox(b); + setMinimumHeight(100); +} + +KGameDialogConnectionConfig::~KGameDialogConnectionConfig() +{ + kdDebug(11001) << k_funcinfo << endl; + // d->mIem2Player.clear(); + delete d; +} + +void KGameDialogConnectionConfig::setKGame(KGame* g) +{ + if (game()) { + disconnect(game(), 0, this, 0); + } + KGameDialogConfig::setKGame(g); + slotClearPlayers(); + if (game()) { +// react to changes in KGame::playerList() + connect(game(), SIGNAL(signalPlayerJoinedGame(KPlayer*)), + this, SLOT(slotPlayerJoinedGame(KPlayer*))); + connect(game(), SIGNAL(signalPlayerLeftGame(KPlayer*)), + this, SLOT(slotPlayerLeftGame(KPlayer*))); + + KGame::KGamePlayerList l = *game()->playerList(); + for (KPlayer* p = l.first(); p; p = l.next()) { + slotPlayerJoinedGame(p); + } + } +} + +void KGameDialogConnectionConfig::setOwner(KPlayer* p) +{ + KGameDialogConfig::setOwner(p); +} + +void KGameDialogConnectionConfig::setAdmin(bool a) +{ + if (!game()) {// not possible... in theory + return; + } + if (admin()) { + disconnect(game(), SIGNAL(executed(QListBoxItem*)), this, 0); + } + KGameDialogConfig::setAdmin(a); + if (admin()) { + connect(d->mPlayerBox, SIGNAL(executed(QListBoxItem*)), this, + SLOT(slotKickPlayerOut(QListBoxItem*))); + } +} + +QListBoxItem* KGameDialogConnectionConfig::item(KPlayer* p) const +{ + QPtrDictIterator it(d->mItem2Player); + while (it.current()) { + if (it.current() == p) { + return (QListBoxItem*)it.currentKey(); + } + ++it; + } + return 0; +} + +void KGameDialogConnectionConfig::slotClearPlayers() +{ + QPtrDictIterator it(d->mItem2Player); + while (it.current()) { + slotPlayerLeftGame(it.current()); + ++it; + } + + if (d->mItem2Player.count() > 0) { + kdWarning(11001) << k_funcinfo << ": itemList wasn't cleared properly" << endl; + d->mItem2Player.clear(); + } + if (d->mPlayerBox->count() > 0) { + kdWarning(11001) << k_funcinfo << ": listBox wasn't cleared properly" << endl; + d->mPlayerBox->clear(); + } + +} + +void KGameDialogConnectionConfig::slotPlayerJoinedGame(KPlayer* p) +{ + if (!p) { + kdError(11001) << k_funcinfo << ": Cannot add NULL player" << endl; + } + if (d->mItem2Player[p]) { + kdError(11001) << k_funcinfo << ": attempt to double add player" << endl; + return; + } + kdDebug(11001) << k_funcinfo << ": add player " << p->id() << endl; + QListBoxText* t = new QListBoxText(p->name()); + d->mItem2Player.insert(t, p); + d->mPlayerBox->insertItem(t); + + connect(p, SIGNAL(signalPropertyChanged(KGamePropertyBase*, KPlayer*)), + this, SLOT(slotPropertyChanged(KGamePropertyBase*, KPlayer*))); + +} + +void KGameDialogConnectionConfig::slotPlayerLeftGame(KPlayer* p) +{ + // disconnect first + this->disconnect(p); + if (!item(p)) { + kdError(11001) << k_funcinfo << ": cannot find " << p->id() + << " in list" << endl; + return; + } + d->mPlayerBox->removeItem(d->mPlayerBox->index(item(p))); + +} + +void KGameDialogConnectionConfig::slotKickPlayerOut(QListBoxItem* item) +{ + kdDebug(11001) << "kick player out" << endl; + KPlayer* p = d->mItem2Player[item]; + if (!p) { + kdError(11001) << "invalid item selected - no player found" << endl; + return; + } + if (!game()) { + kdWarning(11001) << "no game set" << endl; + return; + } + if (!admin()) { + kdDebug(11001) << "Only the ADMIN can kick players" << endl; + return; + } + if (p == owner()) { // you wanna ban the ADMIN ?? + kdDebug(11001) << "you cannot kick the ADMIN" << endl; + return; + } + + if (KMessageBox::questionYesNo(this, i18n("Do you want to ban player \"%1\" from the game?").arg( + p->name()), QString::null, i18n("Ban Player"), i18n("Do Not Ban")) == KMessageBox::Yes) { + kdDebug(11001) << "will remove player " << p << endl; + game()->removePlayer(p); +// d->mPlayerBox->removeItem(d->mPlayerBox->index(item)); // should be done by signalPlayerLeftGame + } else { + kdDebug(11001) << "will NOT remove player " << p << endl; + } +} + +void KGameDialogConnectionConfig::slotPropertyChanged(KGamePropertyBase* prop, KPlayer* player) +{ + if(prop->id() == KGamePropertyBase::IdName) { + QListBoxText* old = 0; + QPtrDictIterator it(d->mItem2Player); + while (it.current() && !old) { + if (it.current() == player) { + old = (QListBoxText*)it.currentKey(); + } + ++it; + } + QListBoxText* t = new QListBoxText(player->name()); + d->mPlayerBox->changeItem(t, d->mPlayerBox->index(old)); + d->mItem2Player.remove(old); + d->mItem2Player.insert(t, player); + } +} + diff --git a/libkdegames/kgame/dialogs/kgamedialogconfig.h b/libkdegames/kgame/dialogs/kgamedialogconfig.h new file mode 100644 index 00000000..b7d30b23 --- /dev/null +++ b/libkdegames/kgame/dialogs/kgamedialogconfig.h @@ -0,0 +1,362 @@ +/* + This file is part of the KDE games library + Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) + Copyright (C) 2001 Martin Heni (martin@heni-online.de) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +// NAMING +// please follow these naming rules if you add/change classes: +// the main dialog is named KGameDialog and the base config widget +// KGameDialogConfig. All config widgets are named KGameDialogXYZConfig (where +// XYZ = the name of the config widget, like "general" or "network") and are +// inherited from KGameDialogConfig. + +#ifndef __KGAMEDIALOGCONFIG_H__ +#define __KGAMEDIALOGCONFIG_H__ + +#include +#include + +class QGridLayout; +class QVBoxLayout; +class QListBoxItem; + +class KGame; +class KPlayer; +class KGamePropertyBase; + +class KGameDialogConfigPrivate; +/** + * Base class for configuration widgets. + * + * You can inherit from this and implement @ref submitToKGame, @ref + * setOwner and @ref setKGame to create your personal @ref KGame configuration widget :-) + * @short Base class for configuration widgets + * @author Andreas Beckermann + **/ +class KDE_EXPORT KGameDialogConfig : public QWidget +{ + Q_OBJECT +public: + KGameDialogConfig(QWidget* parent = 0); + virtual ~KGameDialogConfig(); + + /** + * Called by @ref KGameDialog to submit all settings to the KGame + * Object. + * You have to replace this if you add your own widgets! + * @param g A pointer to your KGame. + * @param p A pointer to the player owning this dialog + **/ + virtual void submitToKGame(KGame* g, KPlayer* p) = 0; + + /** + * The owner player of the dialog has been changed. The default + * changes the pointer for owner so don't forget to call the + * default implementation if you overwrite this! + * + * You can use this e.g. to change a line edit widget containing the + * player name. + * + * Note: even NULL players are allowed! + * @param p The new owner player of the dialog + **/ + virtual void setOwner(KPlayer* p); + + /** + * The KGame object of the dialog has been changed. The default + * implementation changes the pointer for game so don't forget to + * call the default implementation if you overwrite this! + * + * You can use this e.g. to re-read the min/max player settings. + * @param g The KGame object + **/ + virtual void setKGame(KGame* g); + + /** + * The admin status has been changed. + * If the KGame object of this config widget is the + * admin the user is allowed to configure it. Otherwise most + * widgets will have to be disabled. Note that you don't necessarily + * need to deactivate all widget - e.g. the player name must be + * configured by the player. Mainly the KGame configuration can be done + * by the admin only. + * + * By default this does nothing. Changes the value for admin so + * don't forget to call the default implementation in derived classes! + * @param admin Whether the KGame object of this dialog can be + * configured + **/ + virtual void setAdmin(bool admin); + + /** + * A pointer to the KGame object that has been set by @ref setKGame. + * + * Note that NULL is allowed! + * @return The KGame object assigned to this dialog + **/ + KGame* game() const; + + /** + * A pointer to the KPlayer object that has been set by @ref + * setOwner. + * + * Note that NULL is allowed! + * @return The owner of the dialog + **/ + KPlayer* owner() const; + + /** + * @return True if the owner is ADMIN otherwise FALSE. See also + * @ref setAdmin + **/ + bool admin() const; + +protected: + +private: + KGameDialogConfigPrivate* d; +}; + +/** + * The main game configuration widget. + * + * It currently contains a line edit for the name of the player only. You can + * add widgets by using the KGameDialogGeneralConfig as parent parameter as it + * uses QLayout::autoAdd == true. + * @author Andreas Beckermann + **/ +class KGameDialogGeneralConfigPrivate; +class KGameDialogGeneralConfig : public KGameDialogConfig +{ + Q_OBJECT +public: + /** + * Construct a KGameDialogGeneralConfig. Currently it contains a line + * edit widget to change the player name only. + * + * If you just want to add more widgets you can just create your widgets + * with the KGameDialogGeneralConfig as parent as it uses + * QLayout::setAutoAdd(true). + * + * @param parent Parent widget for this dialog. + * @param initializeGUI If you really don't want to use the + * predefined widget and/or layout use FALSE here. Note that then none + * of the predefined widgets (currently only the name of the player) + * will exist anymore. + * + **/ + KGameDialogGeneralConfig(QWidget* parent = 0, bool initializeGUI = true); + virtual ~KGameDialogGeneralConfig(); + + /** + * Called by @ref KGameDialog to submit all settings to the KGame + * Object. + * You have to replace this if you add your own widgets! + * @param g A pointer to your KGame. + * @param p A pointer to the player owning this dialog + **/ + virtual void submitToKGame(KGame* g, KPlayer* p); + + /** + * Change the owner of the config widget. + * + * Changes the playername in the line edit + * @param p The new owner player + **/ + virtual void setOwner(KPlayer* p); + + /** + * See @ref KGameDialogConfig::setKGame + * + * Sets the default values of all KGame related predefined widgets + * (currently none) + **/ + virtual void setKGame(KGame* g); + + /** + * See @ref KGameDialogConfig::setAdmin + * + * This deactivates the min/max player widgets + **/ + virtual void setAdmin(bool admin); + +protected slots: + void slotPropertyChanged(KGamePropertyBase*, KPlayer*); + +protected: + void setPlayerName(const QString& name); + + QString playerName() const; + +private: + KGameDialogGeneralConfigPrivate* d; +}; + +class KGameDialogNetworkConfigPrivate; +class KDE_EXPORT KGameDialogNetworkConfig : public KGameDialogConfig +{ + Q_OBJECT +public: + KGameDialogNetworkConfig(QWidget* parent = 0); + virtual ~KGameDialogNetworkConfig(); + + + void disableInitConnection(); + + /** + * Called by @ref KGameDialog to submit all settings to the KGame + * Object. + * You have to replace this if you add your own widgets! + * @param g A pointer to your KGame. + * @param p A pointer to the player owning this dialog + **/ + virtual void submitToKGame(KGame* g, KPlayer* p); + + virtual void setKGame(KGame* g); + + /** + * This sets the default port and host used in @ref KGameConnectDialog. + * The user will be able to change these defaults! + * + * If you don't call this then host "localhost" and port "0" is used. + * You are strongly encouraged to change at least the port! + * @param port The default port to connect to / listen on + * @param host The default host to connect to + **/ + void setDefaultNetworkInfo(const QString& host, unsigned short int port,bool server=true); + + /** + * Set service type that will be published or browsed for and game name that will be displayed in + * server browser. Without this publishing and discovery of LAN servers will not be enabled. + * @param name Game name. Important only for server mode. If not + * set hostname will be used. In case of name conflict -2, -3 and so on will be added to name. + * @param type Service type (something like _kwin4._tcp). It should be unique for application. + * @since 3.4 + **/ + void setDiscoveryInfo(const QString& type, const QString& name=QString::null); + +signals: + /** + * This signal is emmited if the user changes the server type (client/server) + * in the network configuration dialog. + * + * @param t - type type (0/1) of the connection + **/ + void signalServerTypeChanged(int); + + +protected: + void setConnected(bool connected, bool master = false); + +protected slots: + void slotInitConnection(); + void slotExitConnection(); + void slotConnectionBroken(); + + +private: + KGameDialogNetworkConfigPrivate* d; +}; + +class KGameDialogMsgServerConfigPrivate; +class KGameDialogMsgServerConfig : public KGameDialogConfig +{ + Q_OBJECT +public: + KGameDialogMsgServerConfig(QWidget* parent = 0); + virtual ~KGameDialogMsgServerConfig(); + + virtual void submitToKGame(KGame*, KPlayer*) {} + + void setHasMsgServer(bool); + + virtual void setKGame(KGame* g); + virtual void setAdmin(bool); + +protected slots: + void slotChangeMaxClients(); + void slotChangeAdmin(); + void slotRemoveClient(); + +protected: + void removeClient(Q_UINT32 id); + +private: + KGameDialogMsgServerConfigPrivate* d; +}; + +class KGameDialogChatConfigPrivate; +/** + * This is not really a configuration widget but rather a simple chat widget. + * This widget does nothing but just providing a @ref KGameChat object. + * @short A chat widget inside a @ref KGameDialog + * @author Andreas Beckermann + **/ +class KGameDialogChatConfig : public KGameDialogConfig +{ + Q_OBJECT +public: + KGameDialogChatConfig(int chatMsgId, QWidget* parent = 0); + virtual ~KGameDialogChatConfig(); + + virtual void setKGame(KGame* g); + virtual void setOwner(KPlayer* p); + + virtual void submitToKGame(KGame* g, KPlayer* p) { Q_UNUSED(g); Q_UNUSED(p); } + +private: + KGameDialogChatConfigPrivate* d; +}; + +/** + * @short Lists all connected players and gives the ability to kick them off the + * game + **/ +class KGameDialogConnectionConfigPrivate; +class KGameDialogConnectionConfig : public KGameDialogConfig +{ + Q_OBJECT +public: + KGameDialogConnectionConfig(QWidget* parent = 0); + virtual ~KGameDialogConnectionConfig(); + + virtual void setKGame(KGame* g); + virtual void setOwner(KPlayer* p); + virtual void setAdmin(bool admin); + + virtual void submitToKGame(KGame* g, KPlayer* p) { Q_UNUSED(g); Q_UNUSED(p); } + +protected: + /** + * @param p A player + * @return The QListBoxItem that belongs to the player @p p + **/ + QListBoxItem* item(KPlayer* p) const; + +protected slots: + void slotKickPlayerOut(QListBoxItem* item); + void slotPropertyChanged(KGamePropertyBase* prop, KPlayer* p); + void slotPlayerLeftGame(KPlayer* p); + void slotPlayerJoinedGame(KPlayer* p); + void slotClearPlayers(); + +private: + KGameDialogConnectionConfigPrivate* d; + +}; +#endif diff --git a/libkdegames/kgame/dialogs/kgameerrordialog.cpp b/libkdegames/kgame/dialogs/kgameerrordialog.cpp new file mode 100644 index 00000000..1750892c --- /dev/null +++ b/libkdegames/kgame/dialogs/kgameerrordialog.cpp @@ -0,0 +1,129 @@ +/* + This file is part of the KDE games library + Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) + Copyright (C) 2001 Martin Heni (martin@heni-online.de) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include "kgame.h" + +#include "kgameerrordialog.h" + +class KGameErrorDialogPrivate +{ +public: + KGameErrorDialogPrivate() + { + mGame = 0; + } + + const KGame* mGame; +}; + +KGameErrorDialog::KGameErrorDialog(QWidget* parent) : QObject(parent) +{ + d = new KGameErrorDialogPrivate; +} + +KGameErrorDialog::~KGameErrorDialog() +{ + delete d; +} + +void KGameErrorDialog::setKGame(const KGame* g) +{ + slotUnsetKGame(); + d->mGame = g; + + connect(d->mGame, SIGNAL(destroyed()), this, SLOT(slotUnsetKGame())); + +// the error signals: + connect(d->mGame, SIGNAL(signalNetworkErrorMessage(int, QString)), + this, SLOT(slotError(int, QString))); + connect(d->mGame, SIGNAL(signalConnectionBroken()), + this, SLOT(slotServerConnectionLost())); + connect(d->mGame, SIGNAL(signalClientDisconnected(Q_UINT32,bool)), + this, SLOT(slotClientConnectionLost(Q_UINT32,bool))); +} + +void KGameErrorDialog::slotUnsetKGame() +{ + if (d->mGame) { + disconnect(d->mGame, 0, this, 0); + } + d->mGame = 0; +} + +void KGameErrorDialog::error(const QString& errorText, QWidget* parent) +{ KMessageBox::error(parent, errorText); } + +void KGameErrorDialog::slotServerConnectionLost() +{ +// TODO: add IP/port of the server + QString message = i18n("Connection to the server has been lost!"); + error(message, (QWidget*)parent()); +} + +void KGameErrorDialog::slotClientConnectionLost(Q_UINT32 /*id*/,bool) +{ +//TODO: add IP/port of the client + QString message; +// if (c) { +// message = i18n("Connection to client has been lost!\nID: %1\nIP: %2").arg(c->id()).arg(c->IP()); +// } else { +// message = i18n("Connection to client has been lost!"); +// } + message = i18n("Connection to client has been lost!"); + error(message, (QWidget*)parent()); +} + +void KGameErrorDialog::slotError(int errorNo, QString text) +{ + QString message = i18n("Received a network error!\nError number: %1\nError message: %2").arg(errorNo).arg(text); + error(message, (QWidget*)parent()); +} + +void KGameErrorDialog::connectionError(QString s) +{ + QString message; + if (s.isNull()) { + message = i18n("No connection could be created."); + } else { + message = i18n("No connection could be created.\nThe error message was:\n%1").arg(s); + } + error(message, (QWidget*)parent()); +} + + + +// should become the real dialog - currently we just use messageboxes +// -> maybe unused forever +KGameErrorMessageDialog::KGameErrorMessageDialog(QWidget* parent) + : KDialogBase(Plain, i18n("Error"), Ok, Ok, parent, 0, true, true) +{ +} + +KGameErrorMessageDialog::~KGameErrorMessageDialog() +{ +} + + + +#include "kgameerrordialog.moc" diff --git a/libkdegames/kgame/dialogs/kgameerrordialog.h b/libkdegames/kgame/dialogs/kgameerrordialog.h new file mode 100644 index 00000000..c1dbd1ca --- /dev/null +++ b/libkdegames/kgame/dialogs/kgameerrordialog.h @@ -0,0 +1,113 @@ +/* + This file is part of the KDE games library + Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de) + Copyright (C) 2001 Martin Heni (martin@heni-online.de) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KGAMEERRORDIALOG_H__ +#define __KGAMEERRORDIALOG_H__ + +#include + +class KGame; +class KGameErrorDialogPrivate; + +/** + * Use error(), warning() and information() to display the information about a + * network game. Maybe a better solution is to use KMessageBoxes + * You can connect to the public slots, too - they will call the static + * functions, so that you can always have a KGameErrorDialog object lying around + * without losing much memory (a KGameErrorMessageDialog Object will be + * created) + * @short Error handling for KGame + * @author Andreas Beckermann + **/ +class KGameErrorDialog : public QObject +{ + Q_OBJECT +public: + KGameErrorDialog(QWidget* parent); + ~KGameErrorDialog(); + + /** + * Automatically connects the KGame object to all error dependant slots. + * Create a KGameErrorDialog object, call this function and forget + * everything. + * @param g The KGame which will emit the erorrs (or not ;-) ) + **/ + void setKGame(const KGame* g); + + /** + * KGame couldn't establish a connection. Use this if + * KGame::initConnection returns false + * @param s A string that describes the error further (like port is + * already in use). Will be ignored if QString::null + **/ + void connectionError(QString s = QString::null); + +public slots: + void slotError(int error, QString text); + + /** + * The connection to the @ref KMessageServer has been lost + * + * See @ref KGameNetwork::signalConnectionBroken + **/ + void slotServerConnectionLost(); + + /** + * The connection to a client has been lost by accident + * + * See @ref KGameNetwork::signalClientDisconnected + **/ + void slotClientConnectionLost(Q_UINT32 clientID,bool broken); + + /** + * Unsets a @ref KGame which has been set using @ref setKGame before. + * This is called automatically when the @ref KGame object is destroyed + * and you normally don't have to call this yourself. + * + * Note that @ref setKGame also unsets an already existing @ref KGame + * object if exising. + **/ + void slotUnsetKGame(); + +protected: + void error(const QString& errorText, QWidget* parent = 0); + +private: + KGameErrorDialogPrivate* d; +}; + +/** + * The real class for error messages. KGameErrorDialog uses this to create error + * messages (not yet). + * Use @ref KGameErrorDialog instead. + * @short Internally used by @ref KGameErrorDialog + * @author Andreas Beckermann + **/ +class KGameErrorMessageDialog : public KDialogBase +{ + Q_OBJECT +public: + KGameErrorMessageDialog(QWidget* parent); + ~KGameErrorMessageDialog(); + +private: +}; + +#endif -- cgit v1.2.1