summaryrefslogtreecommitdiffstats
path: root/knights/wiz_setup.cpp
blob: 593d09b261762af101c6d2006a40dd504632aec9 (plain)
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
348
349
350
351
352
353
354
355
356
357
358
359
360
/***************************************************************************
                          wiz_setup.cpp  -  description
                             -------------------
    begin                : Wed Nov 21 2001
    copyright            : (C) 2003 by Troy Corbin Jr.
    email                : tcorbin@users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <tdeglobalsettings.h>
#include <kprocess.h>
#include <kstddirs.h>
#include <tqstringlist.h>
#include <tqfile.h>
#include <tqtextstream.h>
#include <tqregexp.h>
#include "wiz_setup.moc"

wiz_setup::wiz_setup(TQWidget *parent, const char *name, resource *Rsrc ) : KWizard(parent,name,TRUE)
{                                                                                                            	
	myResource = Rsrc;
	steps = 0;
	setMaximumSize( 800, 600 );

	/*
			Call Order Of Pages:

				Page 1 - Introduction
				Page 6 - Accept License
				Page 3 - Setup Engines
				Page 4 - Setup Servers
				Page 5 - Finished
	*/
	initPage1();
//	initPage6();
	if( myResource->Config_Version < 1 )
	{
//		initPage2();
		initPage3();
		initPage4();
	}
	initPage5();
	setCaption( i18n( "Knights Setup Wizard" ) );

	connect( this, TQT_SIGNAL( selected(const TQString&) ), this, TQT_SLOT( slot_Work(const TQString&) ) );
}
wiz_setup::~wiz_setup()
{
}
///////////////////////////////////////
//
//	wiz_setup::initPage1
//
///////////////////////////////////////
void wiz_setup::initPage1( void )
{
	Page1 = new TQFrame( this );
	P1B1 = new TQGridLayout( Page1, 1, 4, 8 );

	SideImage1 = new TQLabel( Page1 );
	SideImage1->setPixmap( locate("data", "knights/wizard.png" ) );
	P1B1->addWidget( SideImage1, 1, 1 );

	WelcomeMessage = new TQLabel( Page1 );
	WelcomeMessage->setAlignment( TQt::AlignLeft | TQt::AlignTop | TQt::WordBreak );
	WelcomeMessage->setText( i18n( "Thank you for installing Knights, the graphical chess interface for TDE. To help you get started quickly, there are a few things Knights will need to setup. You should click 'Next' to see what they are." ) );
	P1B1->addWidget( WelcomeMessage, 1, 3 );

	addPage( Page1, i18n("Welcome to Knights v%1!").arg(_VERSION_) );
	setNextEnabled( Page1, TRUE );
	setHelpEnabled( Page1, FALSE );
}
///////////////////////////////////////
//
//	wiz_setup::initPage2
//
///////////////////////////////////////
void wiz_setup::initPage2( void )
{
	Page2 = new TQFrame( this );
	P2B1 = new TQGridLayout( Page2, 2, 4, 8 );

	SideImage2 = new TQLabel( Page2 );
	SideImage2->setPixmap( locate("data", "knights/wizard.png" ) );
	P2B1->addMultiCellWidget( SideImage2, 1, 2, 1, 1 );

	pgnExplain = new TQLabel( Page2 );
	pgnExplain->setAlignment( TQt::AlignLeft | TQt::AlignTop | TQt::WordBreak );
	pgnExplain->setText( i18n( "When Knights saves a match to disk, it uses Portable Game Notation (PGN) to store the match. Several other computer chess games use PGN too. If you like, Knights can be the default PGN viewer on this system." ) );
	P2B1->addWidget( pgnExplain, 1, 3 );

	pgnButtons = new TQButtonGroup( 2, TQt::Vertical, i18n( "Let Knights handle PGN files?" ), Page2 );
		pgnYes = new TQRadioButton( i18n( "Yes" ), pgnButtons );
		pgnNo = new TQRadioButton( i18n( "No" ), pgnButtons );
	pgnButtons->setButton( 0 );
	P2B1->addWidget( pgnButtons, 2, 3 );

	addPage( Page2, i18n("Let Knights handle your .pgn files?") );
	setHelpEnabled( Page2, FALSE );
}
///////////////////////////////////////
//
//	wiz_setup::initPage3
//
///////////////////////////////////////
void wiz_setup::initPage3( void )
{
	Page3 = new TQFrame( this );
	P3B1 = new TQGridLayout( Page3, 2, 4, 8 );

	SideImage3 = new TQLabel( Page3 );
	SideImage3->setPixmap( locate("data", "knights/wizard.png" ) );
	P3B1->addMultiCellWidget( SideImage3, 1, 2, 1, 1 );

	engineExplain = new TQLabel( Page3 );
	engineExplain->setAlignment( TQt::AlignLeft | TQt::AlignTop | TQt::WordBreak );
	engineExplain->setText( i18n( "Knights can not play a chess match against you without help. Known as Chess Engines, these helpers can be found on the Internet and are often included with your distribution. Knights can look for Chess Engines that you may already have. If found, Knights will configure itself to use them." ) );
	P3B1->addWidget( engineExplain, 1, 3 );

	engineButtons = new TQButtonGroup( 2, TQt::Vertical, i18n( "Let Knights search for chess engines?" ), Page3 );
		engineYes = new TQRadioButton( i18n( "Yes" ), engineButtons );
		engineNo = new TQRadioButton( i18n( "No" ), engineButtons );
	engineButtons->setButton( 0 );
	P3B1->addWidget( engineButtons, 2, 3 );

	addPage( Page3, i18n("Let Knights search for chess engines?") );
	setHelpEnabled( Page3, FALSE );
}
///////////////////////////////////////
//
//	wiz_setup::initPage4
//
///////////////////////////////////////
void wiz_setup::initPage4( void )
{
	Page4 = new TQFrame( this );
	P4B1 = new TQGridLayout( Page4, 2, 4, 8 );

	SideImage4 = new TQLabel( Page4 );
	SideImage4->setPixmap( locate("data", "knights/wizard.png" ) );
	P4B1->addMultiCellWidget( SideImage4, 1, 2, 1, 1 );

	serverExplain = new TQLabel( Page4 );
	serverExplain->setAlignment( TQt::AlignLeft | TQt::AlignTop | TQt::WordBreak );
	serverExplain->setText( i18n( "In order for you to play chess online, Knights will have to connect to a chess server. Knights has a list of several of these servers. If you like, this list can be used to automatically configure Knights." ) );
	P4B1->addWidget( serverExplain, 1, 3 );

	serverButtons = new TQButtonGroup( 2, TQt::Vertical, i18n( "Let Knights configure chess servers?" ), Page4 );
		serverYes = new TQRadioButton( i18n( "Yes" ), serverButtons );
		serverNo = new TQRadioButton( i18n( "No" ), serverButtons );
	serverButtons->setButton( 0 );
	P4B1->addWidget( serverButtons, 2, 3 );

	addPage( Page4, i18n("Let Knights configure chess servers?") );
	setHelpEnabled( Page4, FALSE );
}
///////////////////////////////////////
//
//	wiz_setup::initPage5
//
///////////////////////////////////////
void wiz_setup::initPage5( void )
{
	Page5 = new TQFrame( this );
	P5B1 = new TQGridLayout( Page5, 2, 4, 8 );

	SideImage5 = new TQLabel( Page5 );
	SideImage5->setPixmap( locate("data", "knights/wizard.png" ) );
	P5B1->addMultiCellWidget( SideImage5, 1, 2, 1, 1 );

	FinishExplain = new TQLabel( Page5 );
	FinishExplain->setAlignment( TQt::AlignLeft | TQt::AlignTop | TQt::WordBreak );
	FinishExplain->setText( i18n( "Knights has now configured itself according to your choices. We strongly recommend that you read the documentation to make full use of all that Knights has to offer. You can access it by pressing F1." ) );
	P5B1->addWidget( FinishExplain, 1, 3 );

	addPage( Page5, i18n("Setup Complete") );
	setFinish( Page5, TRUE );
	setHelpEnabled( Page5, FALSE );
}
///////////////////////////////////////
//
//	wiz_setup::initPage6
//
///////////////////////////////////////
void wiz_setup::initPage6( void )
{
	TQString f( locate("data", "LICENSES/GPL_V2") );
	TQString licenseText("<K_STD>");
	Page6 = new TQVBox( this );

	/* Setup License View */
	licenseView = new KnightsTextView( Page6, myResource );
	if (!f.isEmpty())
	{
		TQFile file(f);
		if (file.open(IO_ReadOnly))
		{
			TQTextStream str(&file);
			licenseText += str.read();
		}
	}
	licenseText.append( "</K_STD>" );
	licenseView->setText( licenseText );

	licenseButtons = new TQButtonGroup( 2, TQt::Horizontal, i18n( "Do you accept the terms of our license?" ), Page6 );
		licenseYes = new TQRadioButton( i18n( "Yes" ), licenseButtons );
		licenseNo = new TQRadioButton( i18n( "No" ), licenseButtons );
	licenseButtons->setButton( 1 );

	addPage( Page6, i18n("Please read and accept our license:") );
	setHelpEnabled( Page6, FALSE );
	connect( licenseButtons, TQT_SIGNAL( clicked(int) ), this, TQT_SLOT( slot_License(int) ) );
}
///////////////////////////////////////
//
//	wiz_setup::slot_Work
//
///////////////////////////////////////
void wiz_setup::slot_Work( const TQString& pageTitle )
{
	/* Don't let 'em past the license */
	if( pageTitle == title( Page6 ) )
	{
		setNextEnabled( Page6, FALSE );
	}

	/* Don't proceed unless we're ready to work */
	if( pageTitle != title( Page5 ) ) return;
	setBackEnabled( Page5, FALSE );
	if( myResource->Config_Version < 1 )
	{
//		if( pgnButtons->selected() == pgnYes )
//			setupPGN();
		if( engineButtons->selected() == engineYes )
			findEngines();
		if( serverButtons->selected() == serverYes )
			setupServers();
	}
	myResource->ConfigWrite();
	setFinishEnabled( Page5, TRUE );
}
///////////////////////////////////////
//
//	wiz_setup::setupPGN
//
///////////////////////////////////////
void wiz_setup::setupPGN( void )
{
}
///////////////////////////////////////
//
//	wiz_setup::setupServers
//
///////////////////////////////////////
void wiz_setup::setupServers( void )
{
	serverResource *newServer;
	TQStringList names, urls, ports;
	unsigned int loop;

	names << i18n("Free Internet Chess Server") << i18n("Internet Chess Club") << i18n("Global Chess Server") << i18n("Chess.Net");
	names << i18n("Chess-Square.Com") << i18n("Australian FICS") << i18n("Brazilian FICS") << i18n("Chilean FICS");
	names << i18n("Croatian FICS") << i18n("Dutch FICS") << i18n("French FICS") << i18n("German FICS") << i18n("Swedish FICS");
	urls << "freechess.org" << "chessclub.com" << "global.chessparlor.com" << "chess.net";
	urls << "chess-square.com" << "zics.org" << "jogo.cex.org.br" << "ajedrez.cec.uchile.cl";
	urls << "fly.cc.fer.hr" << "freechess.nl" << "jeu.echecs.com" << "chess.unix-ag.uni-kl.de" << "chess.mds.mdh.se";
	ports << "5000" << "5000" << "6000" << "5000" << "5000" << "5000" << "5000" << "5000";
	ports << "7890" << "5000" << "5000" << "5000" << "5000";

	for( loop = 0; loop < names.count(); loop++ )
	{
			kdDebug() << "adding " << names[loop] << endl;
			newServer = new serverResource;
			newServer->Name = names[loop];
			newServer->URL = urls[loop];
			newServer->Port = ports[loop].toInt();
			newServer->LogFile = TQString();
			newServer->UserName = TQString();
			newServer->Password = TQString();
			newServer->StorePass = FALSE;
			if( !loop ) newServer->CurrentRef = TRUE;
			else  newServer->CurrentRef = FALSE;
			myResource->servers.append( *newServer );
			delete newServer;
	}
}
///////////////////////////////////////
//
//	wiz_setup::findEngines
//
///////////////////////////////////////
void wiz_setup::findEngines( void )
{
	engineResource *newEngine;
	TQStringList names, filenames;
	TDEProcess *Shell;
	bool foundOne( FALSE );
	unsigned int loop;

	names << "GNUChess" << "Crafty" << "Sjeng" << "KnightCap" << "BabyChess" << "Phalanx-XXII";
	names << "Bowron Abernethy Chess Engine" << "Cilian" << "Faile" << "OliThink" << "Pepito";
	names << "Yace";
	filenames << "gnuchessx" << "crafty" << "sjeng" << "KnightCap" << "babychess-xboard-engine";
	filenames << "phalanx" << "BACE" << "linuxCilian.exe" << "faile" << "olithink" << "pepito";
	filenames << "yace";

	for( loop = 0; loop < filenames.count(); loop++ )
	{
		Shell = new TDEProcess();
		(*Shell) << filenames[loop];
		if( Shell->start() )
		{
			kdWarning() << "Adding " << names[loop] << " to knightsrc" << endl;
			newEngine = new engineResource;
			newEngine->Name = names[loop];
			newEngine->Filename = filenames[loop];
			newEngine->Arguments = TQString();
			newEngine->LogFile = TQString();
			newEngine->Protocol = XBoard;
			newEngine->Wins = 0;
			newEngine->Losses = 0;
			newEngine->Draws = 0;
			if( foundOne )
				newEngine->CurrentRef = 0;
			else
				newEngine->CurrentRef = ENGINE_WHITE | ENGINE_BLACK | ENGINE_WHITE_BK | ENGINE_BLACK_BK;
			myResource->engines.append( *newEngine );
			delete newEngine;
			foundOne = TRUE;
		}
		Shell->kill();
		delete Shell;
	}
}
///////////////////////////////////////
//
//	wiz_setup::slot_License
//
///////////////////////////////////////
void wiz_setup::slot_License( int index )
{
	if( index == 0 )
	{
		setNextEnabled( Page6, TRUE );
		myResource->Accepted_License = TRUE;
	}
	else
	{
		setNextEnabled( Page6, FALSE );
		myResource->Accepted_License = FALSE;
	}
}