• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdegames
 

libtdegames

  • libtdegames
  • kgame
  • dialogs
kgamedialog.cpp
1 /*
2  This file is part of the TDE games library
3  Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
4  Copyright (C) 2001 Martin Heni (martin@heni-online.de)
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include <tqlayout.h>
22 #include <tqvbox.h>
23 
24 #include <tdelocale.h>
25 
26 #include "kgame.h"
27 #include "kplayer.h"
28 #include "kgamedialogconfig.h"
29 
30 #include "kgamedialog.h"
31 
32 #include "kgamedialog.moc"
33 
34 class KGameDialogPrivate
35 {
36 public:
37  KGameDialogPrivate()
38  {
39  mGamePage = 0;
40  mNetworkPage = 0;
41  mMsgServerPage = 0;
42  mTopLayout = 0;
43 
44  mNetworkConfig = 0;
45  mGameConfig = 0;
46 
47  mOwner = 0;
48  mGame = 0;
49  }
50 
51  TQVBox* mGamePage;
52  TQVBox* mNetworkPage;
53  TQVBox* mMsgServerPage;// unused here?
54  TQVBoxLayout* mTopLayout;
55  KGameDialogNetworkConfig* mNetworkConfig;
56  KGameDialogGeneralConfig* mGameConfig;
57 
58 // a list of all config widgets added to this dialog
59  TQPtrList<KGameDialogConfig> mConfigWidgets;
60 
61 // just pointers:
62  KPlayer* mOwner;
63  KGame* mGame;
64 };
65 
66 KGameDialog::KGameDialog(KGame* g, KPlayer* owner, const TQString& title,
67  TQWidget* parent, bool modal)
68  : KDialogBase(Tabbed, title, Ok|Default|Apply,
69  Ok, parent, 0, modal, true)
70 {
71  init(g, owner);
72 }
73 
74 KGameDialog::KGameDialog(KGame* g, KPlayer* owner, const TQString& title,
75  TQWidget* parent, long initConfigs, int chatMsgId, bool modal)
76  : KDialogBase(Tabbed, title, Ok|Default|Apply,
77  Ok, parent, 0, modal, true)
78 {
79  init(g, owner);
80  if ((ConfigOptions)initConfigs!=NoConfig) {
81  initDefaultDialog((ConfigOptions)initConfigs, chatMsgId);
82  }
83 }
84 
85 void KGameDialog::init(KGame* g, KPlayer* owner)
86 {
87 //AB: do we need a "Cancel" Button? currently removed
88 
89 // kdDebug(11001) << k_funcinfo << ": this=" << this << endl;
90  d = new KGameDialogPrivate;
91 
92  setOwner(owner);
93  setKGame(g);
94  if (g) {
95  setAdmin(g->isAdmin());
96  } else {
97  setAdmin(false);
98  }
99 }
100 
101 void KGameDialog::initDefaultDialog(ConfigOptions initConfigs, int chatMsgId)
102 {
103  if (initConfigs & GameConfig) {
104  kdDebug() << "add gameconf" << endl;
105  addGameConfig(new KGameDialogGeneralConfig(0));
106  }
107  if (initConfigs & NetworkConfig) {
108  addNetworkConfig(new KGameDialogNetworkConfig(0));
109  }
110  if (initConfigs & (MsgServerConfig) ) {
111  addMsgServerConfig(new KGameDialogMsgServerConfig(0));
112  }
113  if (initConfigs & ChatConfig) {
114  KGameDialogChatConfig * c = new KGameDialogChatConfig(chatMsgId, 0);
115  if (d->mGamePage) {
116  addChatWidget(c, d->mGamePage);
117  } else {
118  addConfigPage(c, i18n("&Chat"));
119  }
120  }
121  if (initConfigs & BanPlayerConfig) {
122  // add the connection management system - ie the widget where the ADMIN can
123  // kick players out
124  if (d->mNetworkPage) {
125  // put it on the network page
126  addConnectionList(new KGameDialogConnectionConfig(0), d->mNetworkPage);
127  } else {
128  // if no network page available put it on an own page
129  addConfigPage(new KGameDialogConnectionConfig(0), i18n("C&onnections"));
130  }
131  }
132 }
133 
134 KGameDialog::~KGameDialog()
135 {
136 // kdDebug(11001) << "DESTRUCT KGameDialog" << this << endl;
137  d->mConfigWidgets.setAutoDelete(true);
138  d->mConfigWidgets.clear();
139  delete d;
140 }
141 
142 void KGameDialog::addGameConfig(KGameDialogGeneralConfig* conf)
143 {
144  if (!conf) {
145  return;
146  }
147  d->mGameConfig = conf;
148  d->mGamePage = addConfigPage(d->mGameConfig, i18n("&Game"));
149 }
150 
151 void KGameDialog::addNetworkConfig(KGameDialogNetworkConfig* netConf)
152 {
153  if (!netConf) {
154  return;
155  }
156  d->mNetworkConfig = netConf;
157  d->mNetworkPage = addConfigPage(netConf, i18n("&Network"));
158 }
159 
160 void KGameDialog::addMsgServerConfig(KGameDialogMsgServerConfig* msgConf)
161 {
162  if (!msgConf) {
163  return;
164  }
165  d->mMsgServerPage = addConfigPage(msgConf, i18n("&Message Server"));
166 }
167 
168 void KGameDialog::addChatWidget(KGameDialogChatConfig* chat, TQVBox* parent)
169 {
170  if (!chat) {
171  return;
172  }
173  if (!parent) {
174  parent = d->mGamePage;
175  }
176  if (!parent) {
177  kdError(11001) << "cannot add chat widget without page" << endl;
178  return;
179  }
180  addConfigWidget(chat, parent);
181 }
182 
183 void KGameDialog::addConnectionList(KGameDialogConnectionConfig* c, TQVBox* parent)
184 {
185  if (!c) {
186  return;
187  }
188  if (!parent) {
189  parent = d->mNetworkPage;
190  }
191  if (!parent) {
192  kdError(11001) << "Cannot add connection list without page" << endl;
193  return;
194  }
195  addConfigWidget(c, parent);
196 }
197 
198 TQVBox *KGameDialog::configPage(ConfigOptions which)
199 {
200  TQVBox *box = 0;
201  switch(which)
202  {
203  case NetworkConfig:
204  box = d->mNetworkPage;
205  break;
206  case GameConfig:
207  box = d->mGamePage;
208  break;
209  case MsgServerConfig:
210  box = d->mMsgServerPage;
211  break;
212  default:
213  kdError(11001) << k_funcinfo << ": Parameter " << which << " not supported" << endl;
214  }
215  return box;
216 }
217 
218 TQVBox* KGameDialog::addConfigPage(KGameDialogConfig* widget, const TQString& title)
219 {
220  if (!widget) {
221  kdError(11001) << "Cannot add NULL config widget" << endl;
222  return 0;
223  }
224  TQVBox* page = addVBoxPage(title);
225  addConfigWidget(widget, page);
226  return page;
227 }
228 
229 void KGameDialog::addConfigWidget(KGameDialogConfig* widget, TQWidget* parent)
230 {
231  if (!widget) {
232  kdError(11001) << "Cannot add NULL config widget" << endl;
233  return;
234  }
235  if (!parent) {
236  kdError(11001) << "Cannot reparent to NULL widget" << endl;
237  return;
238  }
239 // kdDebug(11001) << "reparenting widget" << endl;
240  widget->reparent(parent, TQPoint(0,0));
241  d->mConfigWidgets.append(widget);
242  connect(widget, TQ_SIGNAL(destroyed(TQObject*)), this, TQ_SLOT(slotRemoveConfigWidget(TQObject*)));
243  if (!d->mGame) {
244  kdWarning(11001) << "No game has been set!" << endl;
245  } else {
246  widget->setKGame(d->mGame);
247  widget->setAdmin(d->mGame->isAdmin());
248  }
249  if (!d->mOwner) {
250  kdWarning(11001) << "No player has been set!" << endl;
251  } else {
252  widget->setOwner(d->mOwner);
253  }
254  widget->show();
255 }
256 
257 KGameDialogGeneralConfig* KGameDialog::gameConfig() const
258 { return d->mGameConfig; }
259 KGameDialogNetworkConfig* KGameDialog::networkConfig() const
260 { return d->mNetworkConfig; }
261 
262 void KGameDialog::slotApply()
263 {
264  submitToKGame();
265 }
266 
267 void KGameDialog::slotDefault()
268 {
269  if (!d->mGame) {
270  return;
271  }
272 
273 //TODO *only* call setKGame/setOwner for the *current* page!!
274  setKGame(d->mGame);
275  setOwner(d->mOwner);
276 }
277 
278 void KGameDialog::slotOk()
279 {
280  slotApply();
281  TQDialog::accept();
282 }
283 
284 void KGameDialog::setOwner(KPlayer* owner)
285 {
286 //AB: note: NULL player is ok!
287  d->mOwner = owner;
288  for (int unsigned i = 0; i < d->mConfigWidgets.count(); i++) {
289  if (d->mConfigWidgets.at(i)) {
290  d->mConfigWidgets.at(i)->setOwner(d->mOwner);
291  //TODO: hide playerName in KGameDialogGeneralConfig
292  } else {
293  kdError(11001) << "NULL widget??" << endl;
294  }
295  }
296 }
297 
298 void KGameDialog::setKGame(KGame* g)
299 {
300  if (d->mGame) {
301  disconnect(d->mGame, 0, this, 0);
302  }
303  d->mGame = g;
304  for (int unsigned i = 0; i < d->mConfigWidgets.count(); i++) {
305  d->mConfigWidgets.at(i)->setKGame(d->mGame);
306  }
307  if (d->mGame) {
308  setAdmin(d->mGame->isAdmin());
309  connect(d->mGame, TQ_SIGNAL(destroyed()), this, TQ_SLOT(slotUnsetKGame()));
310  connect(d->mGame, TQ_SIGNAL(signalAdminStatusChanged(bool)),
311  this, TQ_SLOT(setAdmin(bool)));
312  }
313 }
314 
315 void KGameDialog::setAdmin(bool admin)
316 {
317  for (int unsigned i = 0; i < d->mConfigWidgets.count(); i++) {
318  d->mConfigWidgets.at(i)->setAdmin(admin);
319  }
320 }
321 
322 void KGameDialog::slotUnsetKGame() // called when KGame is destroyed
323 { setKGame(0); }
324 
325 void KGameDialog::submitToKGame()
326 {
327  if (!d->mGame) {
328  kdError(11001) << k_funcinfo << ": no game has been set" << endl;
329  return;
330  }
331  if (!d->mOwner) {
332  kdError(11001) << k_funcinfo << ": no player has been set" << endl;
333  return;
334  }
335 
336  for (int unsigned i = 0; i < d->mConfigWidgets.count(); i++) {
337 // kdDebug(11001) << "submit to kgame " << i << endl;
338  d->mConfigWidgets.at(i)->submitToKGame(d->mGame, d->mOwner);
339 // kdDebug(11001) << "done: submit to kgame " << i << endl;
340  }
341 }
342 
343 void KGameDialog::slotRemoveConfigWidget(TQObject* configWidget)
344 {
345  d->mConfigWidgets.removeRef((KGameDialogConfig*)configWidget);
346 }
347 
KGameDialog::addConfigPage
TQVBox * addConfigPage(KGameDialogConfig *widget, const TQString &title)
Add a new page to the dialog.
Definition: kgamedialog.cpp:218
KGameDialog::addConnectionList
void addConnectionList(KGameDialogConnectionConfig *c, TQVBox *parent=0)
Add a connection list to the dialog.
Definition: kgamedialog.cpp:183
KGameDialog::submitToKGame
virtual void submitToKGame()
This will submit all configuration data to the KGame object.
Definition: kgamedialog.cpp:325
KGameDialog::addConfigWidget
void addConfigWidget(KGameDialogConfig *widget, TQWidget *parent)
Add a config widget to the specified parent.
Definition: kgamedialog.cpp:229
KGameDialogConfig::setAdmin
virtual void setAdmin(bool admin)
The admin status has been changed.
Definition: kgamedialogconfig.cpp:81
KGameDialog::initDefaultDialog
void initDefaultDialog(ConfigOptions initConfigs, int chatMsgId=15432)
This is used to create a dialog containing all the default widgets.
Definition: kgamedialog.cpp:101
KGameDialogConfig::setKGame
virtual void setKGame(KGame *g)
The KGame object of the dialog has been changed.
Definition: kgamedialogconfig.cpp:71
KGameDialog::addNetworkConfig
void addNetworkConfig(KGameDialogNetworkConfig *netConf)
Used to add the main network config widget in a new page.
Definition: kgamedialog.cpp:151
KGameDialog::addChatWidget
void addChatWidget(KGameDialogChatConfig *chat, TQVBox *parent=0)
Adds a KGameChat to the dialog.
Definition: kgamedialog.cpp:168
KGameDialog::slotOk
virtual void slotOk()
Called when the user clicks on Ok.
Definition: kgamedialog.cpp:278
KGameDialog::networkConfig
KGameDialogNetworkConfig * networkConfig() const
Definition: kgamedialog.cpp:259
KGameDialogConfig
Base class for configuration widgets.
Definition: kgamedialogconfig.h:51
KGameDialog::configPage
TQVBox * configPage(ConfigOptions which)
Definition: kgamedialog.cpp:198
KGameDialog::KGameDialog
KGameDialog(KGame *g, KPlayer *owner, const TQString &title, TQWidget *parent, bool modal=false)
Create an empty KGameDialog.
Definition: kgamedialog.cpp:66
KGameDialog::setAdmin
void setAdmin(bool isAdmin)
Called when the ADMIN status of this KGame client changes.
Definition: kgamedialog.cpp:315
KGameNetwork::isAdmin
bool isAdmin() const
The admin of a game is the one who initializes newly connected clients using negotiateNetworkGame and...
Definition: kgamenetwork.cpp:104
KPlayer
Base class for a game player.
Definition: kplayer.h:69
KGameDialog::slotApply
virtual void slotApply()
Just calls submitToKGame()
Definition: kgamedialog.cpp:262
KGameDialog::gameConfig
KGameDialogGeneralConfig * gameConfig() const
Definition: kgamedialog.cpp:257
KGameDialogChatConfig
This is not really a configuration widget but rather a simple chat widget.
Definition: kgamedialogconfig.h:314
KGameDialogConfig::setOwner
virtual void setOwner(KPlayer *p)
The owner player of the dialog has been changed.
Definition: kgamedialogconfig.cpp:76
KGameDialog::slotDefault
virtual void slotDefault()
Sets the default values for the configuration widgets.
Definition: kgamedialog.cpp:267
KGame
The main KDE game object.
Definition: kgame.h:62
KGameDialog::setKGame
void setKGame(KGame *g)
Change the KGame object this dialog is used for.
Definition: kgamedialog.cpp:298
KGameDialog::slotRemoveConfigWidget
void slotRemoveConfigWidget(TQObject *configWidget)
Remove a config widget from the widget list.
Definition: kgamedialog.cpp:343
KGameDialog::addMsgServerConfig
void addMsgServerConfig(KGameDialogMsgServerConfig *conf)
Used to add the message server config widget in a new page.
Definition: kgamedialog.cpp:160
KGameDialog::setOwner
void setOwner(KPlayer *owner)
Change the owner of the dialog.
Definition: kgamedialog.cpp:284
KGameDialog::addGameConfig
void addGameConfig(KGameDialogGeneralConfig *conf)
Add the main game config widget in a new page.
Definition: kgamedialog.cpp:142
KGameDialog::slotUnsetKGame
void slotUnsetKGame()
Called when the KGame object is destroyed.
Definition: kgamedialog.cpp:322

libtdegames

Skip menu "libtdegames"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdegames

Skip menu "libtdegames"
  • libtdegames
Generated for libtdegames by doxygen 1.8.13
This website is maintained by Timothy Pearson.