1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
/*
This file is part of the KDE games library
Copyright (C) 2001 Andreas Beckermann ([email protected])
Copyright (C) 2001 Martin Heni ([email protected])
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 <layout.h>
#include <tqvbox.h>
#include <klocale.h>
#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;
}
TQVBox* mGamePage;
TQVBox* mNetworkPage;
TQVBox* mMsgServerPage;// unused here?
TQVBoxLayout* mTopLayout;
KGameDialogNetworkConfig* mNetworkConfig;
KGameDialogGeneralConfig* mGameConfig;
// a list of all config widgets added to this dialog
TQPtrList<KGameDialogConfig> mConfigWidgets;
// just pointers:
KPlayer* mOwner;
KGame* mGame;
};
KGameDialog::KGameDialog(KGame* g, KPlayer* owner, const TQString& title,
TQWidget* parent, bool modal)
: KDialogBase(Tabbed, title, Ok|Default|Apply,
Ok, parent, 0, modal, true)
{
init(g, owner);
}
KGameDialog::KGameDialog(KGame* g, KPlayer* owner, const TQString& title,
TQWidget* 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, TQVBox* 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, TQVBox* parent)
{
if (!c) {
return;
}
if (!parent) {
parent = d->mNetworkPage;
}
if (!parent) {
kdError(11001) << "Cannot add connection list without page" << endl;
return;
}
addConfigWidget(c, parent);
}
TQVBox *KGameDialog::configPage(ConfigOptions which)
{
TQVBox *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;
}
TQVBox* KGameDialog::addConfigPage(KGameDialogConfig* widget, const TQString& title)
{
if (!widget) {
kdError(11001) << "Cannot add NULL config widget" << endl;
return 0;
}
TQVBox* page = addVBoxPage(title);
addConfigWidget(widget, page);
return page;
}
void KGameDialog::addConfigWidget(KGameDialogConfig* widget, TQWidget* 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, TQPoint(0,0));
d->mConfigWidgets.append(widget);
connect(widget, TQT_SIGNAL(destroyed(TQObject*)), this, TQT_SLOT(slotRemoveConfigWidget(TQObject*)));
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();
TQDialog::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, TQT_SIGNAL(destroyed()), this, TQT_SLOT(slotUnsetKGame()));
connect(d->mGame, TQT_SIGNAL(signalAdminStatusChanged(bool)),
this, TQT_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(TQObject* configWidget)
{
d->mConfigWidgets.removeRef((KGameDialogConfig*)configWidget);
}
|