255
255
d->mConnect->setName(name);
258
/////////////////////////// KGameDialogGeneralConfig /////////////////////////
259
class KGameDialogGeneralConfigPrivate
262
KGameDialogGeneralConfigPrivate()
270
QVBoxLayout* mTopLayout;
273
KGameDialogGeneralConfig::KGameDialogGeneralConfig(QWidget* parent, bool initializeGUI)
274
: KGameDialogConfig(parent)
276
// kDebug(11001) << ": this=" << this;
277
d = new KGameDialogGeneralConfigPrivate;
280
d->mTopLayout = new QVBoxLayout(this);
281
d->mTopLayout->setMargin( KDialog::marginHint() );
282
d->mTopLayout->setSpacing( KDialog::spacingHint() );
284
QWidget* nameWidget = new QWidget(this);
285
d->mTopLayout->addWidget(nameWidget);
286
QHBoxLayout* l = new QHBoxLayout(nameWidget);
287
QLabel* nameLabel = new QLabel(i18n("Your name:"), nameWidget);
288
l->addWidget(nameLabel);
289
d->mName = new KLineEdit(nameWidget);
290
l->addWidget(d->mName);
294
KGameDialogGeneralConfig::~KGameDialogGeneralConfig()
300
void KGameDialogGeneralConfig::setPlayerName(const QString& name)
303
d->mName->setText(name);
307
QString KGameDialogGeneralConfig::playerName() const
309
return d->mName ? d->mName->text() : QString();
312
void KGameDialogGeneralConfig::setOwner(KPlayer* p)
315
owner()->disconnect(this);
317
KGameDialogConfig::setOwner(p);
319
// can this config be used at all?
323
connect(owner(), SIGNAL(signalPropertyChanged(KGamePropertyBase*,KPlayer*)),
324
this, SLOT(slotPropertyChanged(KGamePropertyBase*,KPlayer*)));
325
setPlayerName(p->name());
326
//TODO: connect signalPropertyChanged and check for playername changes!
329
void KGameDialogGeneralConfig::setKGame(KGame* g)
331
KGameDialogConfig::setKGame(g);
334
// can this config be used at all?
340
void KGameDialogGeneralConfig::setAdmin(bool admin)
342
KGameDialogConfig::setAdmin(admin);
343
// enable/disable widgets
347
void KGameDialogGeneralConfig::submitToKGame(KGame* g, KPlayer* p)
351
p->setName(playerName());
357
void KGameDialogGeneralConfig::slotPropertyChanged(KGamePropertyBase* prop, KPlayer* p)
359
if (!prop || !p || p != owner()) {
362
switch (prop->id()) {
363
case KGamePropertyBase::IdName:
364
setPlayerName(p->name());
371
class KGameDialogMsgServerConfigPrivate
374
KGameDialogMsgServerConfigPrivate()
379
changeMaxClients = 0;
387
QVBoxLayout* senderLayout;
388
QHBoxLayout* localLayout;
390
QPushButton* changeMaxClients;
391
QPushButton* changeAdmin;
392
QPushButton* removeClient;
399
// TODO: change ADMIN ID, remove CLIENTS, change MAXCLIENTS
400
// we do everything here with QPushButtons as we want to wait a moment before
401
// continuing - the message must be sent over network first
402
KGameDialogMsgServerConfig::KGameDialogMsgServerConfig(QWidget* parent)
403
: KGameDialogConfig(parent)
405
d = new KGameDialogMsgServerConfigPrivate;
407
QVBoxLayout* topLayout = new QVBoxLayout(this);
408
topLayout->setMargin( KDialog::marginHint() );
409
topLayout->setSpacing( KDialog::spacingHint() );
410
d->senderLayout = new QVBoxLayout;
411
d->localLayout = new QHBoxLayout;
412
topLayout->addLayout( d->senderLayout );
413
topLayout->addLayout( d->localLayout );
416
KGameDialogMsgServerConfig::~KGameDialogMsgServerConfig()
422
void KGameDialogMsgServerConfig::setKGame(KGame* g)
424
KGameDialogConfig::setKGame(g);
425
//TODO display the ID of the admin if we aren't
426
// connect(g, SIGNAL(signalAdminChanged(int)), this, SLOT(slotChangeIsAdmin(int)));//TODO
428
// we cannot do anything without a KGame object!
432
setAdmin(game()->isAdmin());
433
setHasMsgServer(game()->messageServer());
437
void KGameDialogMsgServerConfig::slotChangeMaxClients()
440
kError(11001) << ": no valid game object available!";
443
if (!game()->isAdmin()) {
444
kError(11001) << ": only ADMIN is allowed to call this!";
448
// edit->setText(QString::number()); // current max clients! //TODO
450
QDialog* dialog = new QDialog();
451
dialog->setWindowTitle(i18n("Maximal Number of Clients"));
452
QHBoxLayout* l = new QHBoxLayout(dialog);
453
l->setMargin( KDialog::marginHint() );
454
l->setSpacing( KDialog::spacingHint() );
456
l->addWidget(new QLabel(i18n("Maximal number of clients (-1 = infinite):"), dialog));
457
KLineEdit* edit = new KLineEdit(dialog);//TODO: use KIntNumInput
459
// edit->setText(QString::number(max)); // current max clients! //TODO
460
if (dialog->exec() == QDialog::Accepted) {
462
max = edit->text().toInt(&ok);
464
game()->setMaxClients(max);
470
void KGameDialogMsgServerConfig::slotRemoveClient()
474
void KGameDialogMsgServerConfig::slotChangeAdmin()
477
kError(11001) << ": no valid game object available!";
481
kError(11001) << ": only ADMIN is allowed to call this!";
485
quint32 newAdmin = 0;
487
game()->electAdmin(newAdmin);
490
void KGameDialogMsgServerConfig::removeClient(quint32 /*id*/)
495
void KGameDialogMsgServerConfig::setAdmin(bool a)
498
// no need to do anything
501
KGameDialogConfig::setAdmin(a);
505
d->changeMaxClients = new QPushButton(i18n("Change Maximal Number of Clients"), this);
506
connect(d->changeMaxClients, SIGNAL(pressed()), this, SLOT(slotChangeMaxClients()));
507
d->changeAdmin = new QPushButton(i18n("Change Admin"), this);
508
connect(d->changeAdmin, SIGNAL(pressed()), this, SLOT(slotChangeAdmin()));
509
d->removeClient = new QPushButton(i18n("Remove Client with All Players"), this);
510
connect(d->removeClient, SIGNAL(pressed()), this, SLOT(slotRemoveClient()));
511
d->senderLayout->addWidget(d->changeMaxClients);
512
d->senderLayout->addWidget(d->changeAdmin);
513
d->senderLayout->addWidget(d->removeClient);
515
delete d->changeMaxClients;
516
d->changeMaxClients = 0;
517
delete d->changeAdmin;
519
delete d->removeClient;
521
d->noAdmin = new QLabel(i18n("Only the admin can configure the message server!"), this);
522
d->senderLayout->addWidget(d->noAdmin);
527
void KGameDialogMsgServerConfig::setHasMsgServer(bool has)
532
d->noMaster = new QLabel(i18n("You do not own the message server"), this);
533
d->localLayout->addWidget(d->noMaster);
542
// list all connections, data (max clients) and so on
543
// cannot be done above (together with QPushButtons) as it is possible that
544
// this client is ADMIN but not MASTER (i.e. doesn't own the messageserver)
548
class KGameDialogChatConfigPrivate
551
KGameDialogChatConfigPrivate()
559
KGameDialogChatConfig::KGameDialogChatConfig(int chatMsgId, QWidget* parent)
560
: KGameDialogConfig(parent)
562
d = new KGameDialogChatConfigPrivate;
563
QVBoxLayout* topLayout = new QVBoxLayout(this);
564
topLayout->setMargin( KDialog::marginHint() );
565
topLayout->setSpacing( KDialog::spacingHint() );
566
QGroupBox* b = new QGroupBox(i18n("Chat"), this);
567
topLayout->addWidget(b);
568
QHBoxLayout* gboxLay = new QHBoxLayout(b);
569
d->mChat = new KGameChat(0, chatMsgId, b);
570
gboxLay->addWidget(d->mChat);
573
KGameDialogChatConfig::~KGameDialogChatConfig()
579
void KGameDialogChatConfig::setKGame(KGame* g)
581
KGameDialogConfig::setKGame(g);
582
d->mChat->setKGame(game());
590
void KGameDialogChatConfig::setOwner(KPlayer* p)
592
KGameDialogConfig::setOwner(p);
597
d->mChat->setFromPlayer(owner());
603
class KGameDialogConnectionConfigPrivate
606
KGameDialogConnectionConfigPrivate()
611
QHash<QListWidgetItem*, KPlayer*> mItem2Player;
612
KListWidget* mPlayerBox;
615
KGameDialogConnectionConfig::KGameDialogConnectionConfig(QWidget* parent)
616
: KGameDialogConfig(parent)
618
//TODO: prevent player to ban himself
619
d = new KGameDialogConnectionConfigPrivate;
620
QVBoxLayout* topLayout = new QVBoxLayout(this);
621
topLayout->setMargin( KDialog::marginHint() );
622
topLayout->setSpacing( KDialog::spacingHint() );
623
QGroupBox* b = new QGroupBox(i18n("Connected Players"), this);
624
topLayout->addWidget(b);
625
QHBoxLayout* gboxLay = new QHBoxLayout(b);
626
d->mPlayerBox = new KListWidget(b);
627
gboxLay->addWidget(d->mPlayerBox);
628
setMinimumHeight(100);
631
KGameDialogConnectionConfig::~KGameDialogConnectionConfig()
634
// d->mIem2Player.clear();
638
void KGameDialogConnectionConfig::setKGame(KGame* g)
641
disconnect(game(), 0, this, 0);
643
KGameDialogConfig::setKGame(g);
646
// react to changes in KGame::playerList()
647
connect(game(), SIGNAL(signalPlayerJoinedGame(KPlayer*)),
648
this, SLOT(slotPlayerJoinedGame(KPlayer*)));
649
connect(game(), SIGNAL(signalPlayerLeftGame(KPlayer*)),
650
this, SLOT(slotPlayerLeftGame(KPlayer*)));
652
const QList<KPlayer*> *playerList = game()->playerList();
653
for ( QList<KPlayer*>::const_iterator it = playerList->begin(); it!=playerList->end();++it )
655
slotPlayerJoinedGame(*it);
660
void KGameDialogConnectionConfig::setOwner(KPlayer* p)
662
KGameDialogConfig::setOwner(p);
665
void KGameDialogConnectionConfig::setAdmin(bool a)
667
if (!game()) {// not possible... in theory
671
disconnect(game(), SIGNAL(executed(QListWidgetItem*)), this, 0);
673
KGameDialogConfig::setAdmin(a);
675
connect(d->mPlayerBox, SIGNAL(executed(QListWidgetItem*)), this,
676
SLOT(slotKickPlayerOut(QListWidgetItem*)));
680
QListWidgetItem* KGameDialogConnectionConfig::item(KPlayer* p) const
682
QHash<QListWidgetItem*, KPlayer*>::const_iterator it, itEnd;
683
it = d->mItem2Player.constBegin();
684
itEnd = d->mItem2Player.constEnd();
685
for ( ; it != itEnd; ++it ) {
686
if (it.value() == p) return it.key();
691
void KGameDialogConnectionConfig::slotClearPlayers()
693
QHash<QListWidgetItem*, KPlayer*>::const_iterator it, itEnd;
694
it = d->mItem2Player.constBegin();
695
itEnd = d->mItem2Player.constEnd();
696
for ( ; it != itEnd; ++it ) {
697
slotPlayerLeftGame(it.value());
700
if (d->mItem2Player.count() > 0) {
701
kWarning(11001) << ": itemList wasn't cleared properly";
702
d->mItem2Player.clear();
704
if (d->mPlayerBox->count() > 0) {
705
kWarning(11001) << ": listBox wasn't cleared properly";
706
d->mPlayerBox->clear();
711
void KGameDialogConnectionConfig::slotPlayerJoinedGame(KPlayer* p)
714
kError(11001) << ": Cannot add NULL player";
717
bool playerFound = false;
718
QHash<QListWidgetItem*, KPlayer*>::const_iterator it, itEnd;
719
it = d->mItem2Player.constBegin();
720
itEnd = d->mItem2Player.constEnd();
721
for ( ; !playerFound && it != itEnd; ++it ) playerFound = it.value() == p;
723
kError(11001) << ": attempt to double add player";
726
kDebug(11001) << ": add player" << p->id();
727
QListWidgetItem* t = new QListWidgetItem(p->name(), d->mPlayerBox);
728
d->mItem2Player.insert(t, p);
730
connect(p, SIGNAL(signalPropertyChanged(KGamePropertyBase*,KPlayer*)),
731
this, SLOT(slotPropertyChanged(KGamePropertyBase*,KPlayer*)));
735
void KGameDialogConnectionConfig::slotPlayerLeftGame(KPlayer* p)
740
kError(11001) << ": cannot find" << p->id()
744
d->mPlayerBox->takeItem(d->mPlayerBox->row(item(p)));
748
void KGameDialogConnectionConfig::slotKickPlayerOut(QListWidgetItem* item)
750
kDebug(11001) << "kick player out";
751
KPlayer* p = d->mItem2Player[item];
753
kError(11001) << "invalid item selected - no player found";
757
kWarning(11001) << "no game set";
761
kDebug(11001) << "Only the ADMIN can kick players";
764
if (p == owner()) { // you wanna ban the ADMIN ??
765
kDebug(11001) << "you cannot kick the ADMIN";
769
if (KMessageBox::questionYesNo(this, i18n("Do you want to ban player \"%1\" from the game?",
770
p->name()), QString(), KGuiItem (i18n("Ban Player")), KGuiItem (i18n("Do Not Ban"))) == KMessageBox::Yes) {
771
kDebug(11001) << "will remove player" << p;
772
game()->removePlayer(p);
773
// d->mPlayerBox->removeItem(d->mPlayerBox->index(item)); // should be done by signalPlayerLeftGame
775
kDebug(11001) << "will NOT remove player" << p;
779
void KGameDialogConnectionConfig::slotPropertyChanged(KGamePropertyBase* prop, KPlayer* player)
781
if(prop->id() == KGamePropertyBase::IdName) {
782
QListWidgetItem* old = item(player);
783
QListWidgetItem* t = new QListWidgetItem(player->name());
784
int row = d->mPlayerBox->row(old);
785
d->mPlayerBox->takeItem( row );
786
d->mPlayerBox->insertItem(row, t);
787
d->mItem2Player.remove(old);
788
d->mItem2Player.insert(t, player);