summaryrefslogtreecommitdiffstats
path: root/knights/knights.cpp
blob: ae68539c8f902bba12f801102c65f6883b26b5a0 (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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
/***************************************************************************
                          knights.cpp  -  description
                             -------------------
    begin                : Thu Mar  1 10:43:51 CST 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.                                   *
 *                                                                         *
 ***************************************************************************/

/* Local */
#include "knights.moc"
#include "core.h"
#include "wiz_setup.h"
#include "pgn.h"
#include "splash.h"
#include "dlg_settings.h"
#include "dlg_newmatch.h"
/* KDE */
#include <kmenubar.h>
#include <kmessagebox.h>
#include <kicontheme.h>
#include <kkeydialog.h>
#include <kcombobox.h>
#include <kpopupmenu.h>
#include <klocale.h>
/* KFile */
#include <kfiledialog.h>
/* Qt */
#include <qpalette.h>
#include <qiconset.h>
#include <qlabel.h>
#include <qframe.h>
#include <qstyle.h>

Knights::Knights(KCmdLineArgs *Args, QWidget *parent, const char *name) : KMainWindow(parent, name)
{
	InitAll = TRUE;
	ResizeFlag = TRUE;
	Minimized = FALSE;
	args = Args;
	SplashScreen = NULL;
	setFocusPolicy( ClickFocus );
}
Knights::~Knights()
{
	if( !InitAll )
		KillAll();
}
///////////////////////////////////////
//
//	Knights::BirthAll
//
///////////////////////////////////////
void Knights::BirthAll(void)
{
	SettingsDialog	= NULL;
	Resource				= new resource(args);

	if( Resource->OPTION_Show_Splash )
		SplashScreen = new splash();

	aboutData				= new KAboutData( "knights", I18N_NOOP("Knights"), _VERSION_ );
	topMenu					= menuBar();
	myAccel					= new Accel( this, Resource->myAccel );
	help						= helpMenu();
	fileMenu				= new KPopupMenu( this , "fileMenu");
	settingsMenu		= new KPopupMenu( this, "settingsMenu");
	matchMenu				= new KPopupMenu( this, "matchMenu");
	drawMenu				= new KPopupMenu( this, "drawMenu");
	tutorialMenu		= new KPopupMenu( this, "tutorialMenu");
	MainFrame				= new QFrame( this, "MainFrame" );
	Core						= new core( MainFrame, "Core", Resource );
	Message					= new QLabel( MainFrame, "Message");
	whiteTimeLabel	= new QLabel( MainFrame, "whiteTimeLabel");
	blackTimeLabel	= new QLabel( MainFrame, "blackTimeLabel");
	notationBar			= new KComboBox( MainFrame, "notationBar");
	
	/* Connect all Signals & Slots */
	connect( Core, SIGNAL( requestResize() ), this, SLOT( resizeMainFrame() ) );
	connect( Core, SIGNAL( setStatusBar(const int&, const QString& ) ), this, SLOT( setStatusBar(const int&, const QString& ) ) );
	connect( Core, SIGNAL( setNotation() ), this, SLOT( setNotation() ) );
	connect( Core, SIGNAL( initMatch() ), this, SLOT( initMatch() ) );
	connect( Core, SIGNAL( setClocks() ), this, SLOT( setClocks() ) );
	connect( Core, SIGNAL( serverDestroyed() ), this, SLOT( netConnect() ) );
	connect( notationBar, SIGNAL( activated(int) ), Core, SLOT( review(int) ) );
}
///////////////////////////////////////
//
//	Knights::menuClose
//
///////////////////////////////////////
void Knights::menuClose(void)
{
	if( !queryClose() )
		return;
	qApp->quit();
}
///////////////////////////////////////
//
//	Knights::queryClose
//
///////////////////////////////////////
bool Knights::queryClose(void)
{
	return Core->clearAll();
}
///////////////////////////////////////
//
//	Knights::KillAll
//
///////////////////////////////////////
void Knights::KillAll(void)
{
	delete Core;
	delete fileMenu;
	delete matchMenu;
	delete drawMenu;
	delete tutorialMenu;
	delete settingsMenu;
	delete whiteTimeLabel;
	delete blackTimeLabel;
	delete notationBar;
	delete Message;
	delete aboutData;
	delete MainFrame;
	delete myAccel;
	delete Resource;
	InitAll = TRUE;
}
///////////////////////////////////////
//
//	Knights::init
//
///////////////////////////////////////
bool Knights::init( void )
{
	wiz_setup *Wizard;
	QColorGroup GroupWhite;
	QColorGroup GroupBlack;

	BirthAll();
	SelectTheme(-1,-1);
	Resource->setAudio();
	ResizeFlag = FALSE;

	/*
			Connect Accelerators
	*/
	connect( Resource->myAccel, SIGNAL( board_up() ), this, SLOT( boardBigger() ) );
	connect( Resource->myAccel, SIGNAL( board_down() ), this, SLOT( boardSmaller() ) );
	connect( Resource->myAccel, SIGNAL( move_prev() ), this, SLOT( PrevNotation() ) );
	connect( Resource->myAccel, SIGNAL( move_next() ), this, SLOT( NextNotation() ) );
	connect( this, SIGNAL( focus( const QChar& ) ), Resource->myAccel, SIGNAL( focus( const QChar& ) ) );

	initMenus();

	/* Init Message */
	Message->setAlignment( Qt::AlignAuto | Qt::AlignVCenter | Qt::SingleLine );

	/* Init White Time Label */
	GroupWhite.setColor( QColorGroup::Background, Resource->COLOR_White );
	GroupWhite.setColor( QColorGroup::Foreground, Resource->COLOR_Black );
	whiteTimeLabel->setPalette( QPalette( GroupWhite, GroupWhite, GroupWhite ) );
	whiteTimeLabel->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
	whiteTimeLabel->setAlignment( Qt::AlignCenter | Qt::SingleLine );

	/* Init Black Time Label */
	GroupBlack.setColor( QColorGroup::Background, Resource->COLOR_Black );
	GroupBlack.setColor( QColorGroup::Foreground, Resource->COLOR_White );
	blackTimeLabel->setPalette( QPalette( GroupBlack, GroupBlack, GroupBlack ) );
	blackTimeLabel->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
	blackTimeLabel->setAlignment( Qt::AlignCenter | Qt::SingleLine );

	/* Configure self */
	setCentralWidget( MainFrame );
	InitAll = FALSE;
	resizeMainFrame();
  show();
	setStatusBar( READY );

	/* Remove the Splash Screen */
	if( SplashScreen != NULL )
	{
		delete SplashScreen;
	}

	/* Run the Setup Wizard if needed */
	if( Resource->Config_Version < CONFIG_VERSION )
	{
		Wizard = new wiz_setup( this, "wiz_setup", Resource );
		Wizard->exec();
		delete Wizard;
		resizeMainFrame();
	/*	if( !Resource->Accepted_License )
			return FALSE;*/
		Resource->Config_Version = CONFIG_VERSION;
	}

	/* Begin loading file from command line */
	if( args->count() )
	{
		Core->load( QString( args->arg( 0 ) ) );
	}
	else
	{
		/* Bring up a match or pgn file */
		switch( Resource->OPTION_On_Init )
		{
			case MENU_SOLITARE:
				Core->newMatch( new match_param( Resource, PLAYERLOCAL, PLAYERLOCAL ) );
				break;
			case MENU_VS_PC:
				if( Resource->engines.count() )
				{
					Core->newMatch( new match_param( Resource, PLAYERLOCAL, PLAYERPC ) );
				}
				break;
			case MENU_CONNECT:
				netConnect();
				break;
			default:
				break;
		}
	}
	return TRUE;
}
///////////////////////////////////////
//
//	Knights::initMenus
//
///////////////////////////////////////
void Knights::initMenus( void )
{
	/*
			matchMenu menu
	*/
	matchMenu->setCheckable(TRUE);
	// MENU_DRAW
	matchMenu->insertItem( i18n( "&Draw" ), drawMenu, MENU_DRAW );
	matchMenu->setItemEnabled( MENU_DRAW, FALSE );
	// MENU_RETRACT
	matchMenu->insertItem( QIconSet( Resource->LoadIcon( QString("undo"), KIcon::Small ) ),
												i18n( "&Retract Move" ), Core, SLOT(matchMenu(int)), 0, MENU_RETRACT );
	matchMenu->setItemEnabled( MENU_RETRACT, FALSE );
	matchMenu->setWhatsThis( MENU_RETRACT, i18n( "Select this to retract your last move." ) );
	// MENU_RESIGN
	matchMenu->insertItem( i18n( "Resign" ), Core, SLOT(matchMenu(int)), 0, MENU_RESIGN );
	matchMenu->setItemEnabled( MENU_RESIGN, FALSE );
	matchMenu->setWhatsThis( MENU_RESIGN, i18n( "Use this to concede the match to your opponent." ) );
	// MENU_CALL_FLAG
	matchMenu->insertItem( i18n( "&Call Flag" ), Core, SLOT(matchMenu(int)), 0, MENU_CALL_FLAG );
	matchMenu->setItemEnabled( MENU_CALL_FLAG, FALSE );
	matchMenu->setWhatsThis( MENU_CALL_FLAG, i18n( "Use this to declare the match over, due to your opponent being out of time." ) );
	// MENU_HINT
	matchMenu->insertItem( i18n( "&Hint" ), Core, SLOT(matchMenu(int)), 0, MENU_HINT );
	matchMenu->setItemEnabled( MENU_HINT, FALSE );
	matchMenu->setWhatsThis( MENU_HINT, i18n( "This will ask your opponent for a hint." ) );
	// MENU_MOVE_NOW
	matchMenu->insertItem( i18n( "Move &Now" ), Core, SLOT(matchMenu(int)), 0, MENU_MOVE_NOW );
	matchMenu->setItemEnabled( MENU_MOVE_NOW, FALSE );
	matchMenu->setWhatsThis( MENU_MOVE_NOW, i18n( "Clicking this option will force your opponent to move immediately." ) );
	// MENU_ORIENTATION
	matchMenu->insertItem( i18n( "&Flip View" ), Core, SLOT(matchMenu(int)), Key_F2, MENU_ORIENTATION );
	matchMenu->setItemEnabled( MENU_ORIENTATION, FALSE );
	matchMenu->setWhatsThis( MENU_ORIENTATION, i18n( "This will reverse the chessboard's orientation by 180 degrees." ) );
	// MENU_PONDER
	matchMenu->insertItem( i18n( "&Ponder" ), this, SLOT(Settings(int)), 0, MENU_PONDER );
	matchMenu->setItemChecked( MENU_PONDER, Resource->OPTION_Ponder );
	matchMenu->setItemEnabled( MENU_PONDER, FALSE );
	matchMenu->setWhatsThis( MENU_PONDER, i18n( "This toggles your opponent's ability to think while it's your turn." ) );
	matchMenu->insertSeparator();
	// MENU_PAUSE
	matchMenu->insertItem( QIconSet( Resource->LoadIcon( QString("player_pause"), KIcon::Small ) ),
												i18n( "Pause" ), this, SLOT( Settings(int) ), Key_F12, MENU_PAUSE );
	matchMenu->setItemEnabled( MENU_PAUSE, FALSE );
	matchMenu->setWhatsThis( MENU_PAUSE, i18n( "Select this to pause the clock for this match." ) );
	/*
			drawMenu menu
	*/
	// MENU_OFFER_DRAW
	drawMenu->insertItem( i18n( "&Offer Draw" ), Core, SLOT(matchMenu(int)), 0, MENU_OFFER_DRAW );
	drawMenu->setWhatsThis( MENU_OFFER_DRAW, i18n( "Clicking this will inform your opponent that you are willing draw the match." ) );
	// MENU_ACCEPT_DRAW
	drawMenu->insertItem( i18n( "&Accept Draw" ), Core, SLOT(matchMenu(int)), 0, MENU_ACCEPT_DRAW );
	drawMenu->setWhatsThis( MENU_ACCEPT_DRAW, i18n( "Clicking this will accept a draw offered by your opponent." ) );
	// MENU_REJECT_DRAW
	drawMenu->insertItem( i18n( "&Reject Draw" ), Core, SLOT(matchMenu(int)), 0, MENU_REJECT_DRAW );
	drawMenu->setWhatsThis( MENU_REJECT_DRAW, i18n( "Clicking this will reject a draw offered by your opponent." ) );
	// MENU_IGNORE_DRAW
	drawMenu->insertItem( i18n( "&Ignore Draw" ), Core, SLOT(matchMenu(int)), 0, MENU_IGNORE_DRAW );
	drawMenu->setWhatsThis( MENU_IGNORE_DRAW, i18n( "Clicking this will ignore future draw offers from your opponent." ) );
	/*
			fileMenu menu
	*/
	// MENU_NEWGAME
	fileMenu->insertItem( QIconSet( Resource->LoadIcon( QString("filenew"), KIcon::Small ) ),
												i18n( "&New Match..." ), this, SLOT( openNewMatchDialog() ), CTRL+Key_N, MENU_NEWGAME );
	fileMenu->setWhatsThis( MENU_NEWGAME, i18n( "This allows you to begin a new match." ) );
	// MENU_LOAD
	fileMenu->insertItem( QIconSet( Resource->LoadIcon( QString("fileopen"), KIcon::Small ) ),
												i18n( "&Load Match..." ), Core, SLOT( load() ), CTRL+Key_L, MENU_LOAD );
	fileMenu->setWhatsThis( MENU_LOAD, i18n( "The Load command will allow you to select a previously saved match and play it again." ) );
	fileMenu->insertSeparator();
	// MENU_SAVE
	fileMenu->insertItem( QIconSet( Resource->LoadIcon( QString("filesave"), KIcon::Small ) ),
												i18n( "&Save Match" ), this, SLOT( SaveGame() ), CTRL+Key_S, MENU_SAVE );
	fileMenu->setItemEnabled( MENU_SAVE, FALSE );
	fileMenu->setWhatsThis( MENU_SAVE, i18n( "The Save command will allow you to store a copy of your current match for later use." ) );
	// MENU_SAVEAS
	fileMenu->insertItem( QIconSet( Resource->LoadIcon( QString("filesave"), KIcon::Small ) ),
												i18n( "Save Match &As..." ), this, SLOT( SaveGameAs() ), CTRL+Key_A, MENU_SAVEAS );
	fileMenu->setItemEnabled( MENU_SAVEAS, FALSE );
	fileMenu->setWhatsThis( MENU_SAVEAS, i18n( "The Save command will allow you to store a copy of your current match for later use." ) );
	fileMenu->insertSeparator();
	// MENU_CONNECT
	fileMenu->insertItem( QIconSet( Resource->LoadIcon( QString("connect_creating"), KIcon::Small ) ),
												i18n( "Connect to Server" ), this, SLOT( netConnect() ), CTRL+Key_C, MENU_CONNECT );
	fileMenu->setWhatsThis( MENU_CONNECT, i18n( "Clicking this will connect Knights with an internet chess server." ) );
	fileMenu->insertSeparator();
	// MENU_PRINT
	fileMenu->insertItem( QIconSet( Resource->LoadIcon( QString("fileprint"), KIcon::Small ) ),
												i18n( "&Print Notation..." ), Core, SLOT( print() ), CTRL+Key_P, MENU_PRINT );
	fileMenu->setItemEnabled( MENU_PRINT, FALSE );
	fileMenu->setWhatsThis( MENU_PRINT, i18n( "The Print command will allow you to print this game's notation on your printer." ) );
	fileMenu->insertSeparator();
	// MENU_CLOSE
	fileMenu->insertItem( QIconSet( Resource->LoadIcon( QString("fileclose"), KIcon::Small ) ),
												i18n( "&Close Match" ), Core, SLOT( clearMatch() ), CTRL+Key_W, MENU_CLOSE );
	fileMenu->setItemEnabled( MENU_CLOSE, FALSE );
	fileMenu->setWhatsThis( MENU_CLOSE, i18n( "This command removes the current match." ) );
	// MENU_CLOSEALL
	fileMenu->insertItem( i18n( "Close All" ), Core, SLOT( clearAll() ), 0, MENU_CLOSEALL );
	fileMenu->setItemEnabled( MENU_CLOSEALL, FALSE );
	fileMenu->setWhatsThis( MENU_CLOSEALL, i18n( "This command will remove all matches that are currently loaded." ) );
	fileMenu->insertSeparator();
	// MENU_QUIT
	fileMenu->insertItem( QIconSet( Resource->LoadIcon( QString("exit"), KIcon::Small ) ),
												i18n( "&Quit" ), this, SLOT(menuClose()), CTRL+Key_Q, MENU_QUIT );
	fileMenu->setWhatsThis( MENU_QUIT, i18n( "The Quit command will stop all matches and exit Knights." ) );
	/*
			settingsMenu menu
	*/
	// MENU_INSTALL_THEMES
	settingsMenu->insertItem( i18n( "&Install Themes" ), this, SLOT(installThemes()), 0, MENU_INSTALL_THEMES );
	settingsMenu->setWhatsThis( MENU_INSTALL_THEMES, i18n( "This lets you install downloaded themes into Knights." ) );
	// MENU_BINDINGS_DIALOG
	settingsMenu->insertItem( QIconSet( Resource->LoadIcon( QString("key_bindings"), KIcon::Small ) ),
														i18n( "Configure &Key Bindings..." ), this, SLOT(openKeyBindingDialog()), 0, MENU_BINDINGS_DIALOG );
	settingsMenu->setWhatsThis( MENU_BINDINGS_DIALOG, i18n( "Click this if you want to change the keyboard shortcuts that Knights uses." ) );
	// MENU_SETTINGS_DIALOG
	settingsMenu->insertItem( QIconSet( Resource->LoadIcon( QString("configure"), KIcon::Small ) ),
														i18n( "&Configure Knights..." ), this, SLOT(openSettingsDialog()), 0, MENU_SETTINGS_DIALOG );
	settingsMenu->setWhatsThis( MENU_SETTINGS_DIALOG, i18n( "This opens a new window which allows you to customize Knights to your particular tastes." ) );
	/*
			tutorialMenu menu
	*/
	tutorialMenu->setCheckable(TRUE);
	// MENU_OPEN_TUTORIAL
	tutorialMenu->insertItem( i18n( "Begin a Tutorial" ), this, SLOT(Settings(int)), 0, MENU_OPEN_TUTORIAL );
//	tutorialMenu->setWhatsThis( MENU_OPEN_TUTORIAL, i18n( "" ) );
	/*
			topMenu menu
	*/
	topMenu->insertItem( i18n( "&File" ), fileMenu );
	topMenu->insertItem( i18n( "&Match" ), matchMenu );
	topMenu->insertItem( i18n( "&Settings" ), settingsMenu );
//	topMenu->insertItem( i18n( "&Tutorials" ), tutorialMenu );
	topMenu->insertSeparator();
	topMenu->insertItem( i18n( "&Help" ), help );
}
///////////////////////////////////////
//
//	Knights::resizeMainFrame
//
///////////////////////////////////////
void Knights::resizeMainFrame(void)
{
	QStyle& Style = QApplication::style();
	QSize S_Message;
	QSize S_Menu;
	
	int statusY(0);
	int statusX(0);	
	int statusHeight(0);
	
	/* Get some numbers */
	margin = Style.defaultFrameWidth();
	/* Take care of the Core first */
	Core->move( 0, 0 );
	Core->resize();
	/* Get our size hints */
	S_Message = Message->sizeHint();
	S_Menu = topMenu->sizeHint();
	statusHeight = S_Message.height() + ( margin << 1 );
	statusY += Core->height() + margin + statusHeight + margin;
	statusX = Core->width();

	MainFrame->setFixedSize( statusX, statusY );
	setFixedSize( statusX, statusY + S_Menu.height() );

	/* enable or disable games in the menu */
	if( Resource->servers.count() )
	{
		fileMenu->setItemEnabled( MENU_CONNECT, TRUE );
	}
	else
	{
		fileMenu->setItemEnabled( MENU_CONNECT, FALSE );
	}
}
///////////////////////////////////////
//
//	Knights::event
//
///////////////////////////////////////
bool Knights::event( QEvent *e )
{
	if( e->type() == EVENT_Del_IO_Net )
	{
		netConnect();
		return TRUE;
	}
	return KMainWindow::event( e );
}
///////////////////////////////////////
//
//	Knights::resizeEvent
//
///////////////////////////////////////
void Knights::resizeEvent( QResizeEvent * )
{
	QSize S_Message;
	int tmp(0);
	int statusHeight(0);
	int statusY(0);
	int statusX(0);
	int gridX(0);
	
	if( ResizeFlag ) return;
	/* Get the height & Y of the status bar */
	gridX = Core->width() >> 3;
	S_Message = Message->sizeHint() + QSize( 2, 2 );
	statusHeight = S_Message.height() + ( margin << 1 );
	Resource->Widget_Height = statusHeight;
	statusY += Core->height() + margin;

	if( InitAll ) return;
	/* Do the Message box */
	tmp = gridX * 3;
	Message->setFixedSize( tmp - ( margin << 1 ), statusHeight );
	Message->move( margin, statusY );
	statusX = tmp;
	/* Do the White Time */
	tmp = gridX + ( gridX >> 1 );
	whiteTimeLabel->setFixedSize( tmp - margin, statusHeight );
	whiteTimeLabel->move( statusX, statusY );
	statusX += tmp;
	/* Do the Black Time */
	tmp = gridX + ( gridX >> 1 );
	blackTimeLabel->setFixedSize( tmp - margin, statusHeight );
	blackTimeLabel->move( statusX, statusY );
	statusX += tmp;
	/* Do the Notation Bar */
	tmp = gridX << 1;
	notationBar->setFixedSize( tmp - margin, statusHeight );
	notationBar->move( statusX, statusY );
	statusX += tmp;
}
///////////////////////////////////////
//
//	Knights::keyPressEvent
//
///////////////////////////////////////
void Knights::keyPressEvent( QKeyEvent *e )
{
	QChar input;

	if( ( e->state() | Qt::ShiftButton ) == Qt::ShiftButton )
	{
		input = e->text().at(0);
		if( input.isLetterOrNumber() )
		{
			emit focus( input );
			e->accept();
			return;
		}
	}
	e->ignore();
}
///////////////////////////////////////
//
//	Knights::hideEvent
//
///////////////////////////////////////
void Knights::hideEvent( QHideEvent* )
{
	if( !Resource->OPTION_Pause_On_Minimize )
		return;
	Core->matchMenu( MENU_PAUSEALL );
	Minimized = TRUE;
}
///////////////////////////////////////
//
//	Knights::showEvent
//
///////////////////////////////////////
void Knights::showEvent( QShowEvent* )
{
	if( !Minimized )
		return;
	Core->matchMenu( MENU_PAUSEALL );
	Minimized = FALSE;
}
///////////////////////////////////////
//
//	Knights::wheelEvent
//
///////////////////////////////////////
void Knights::wheelEvent( QWheelEvent *event )
{
	event->accept();
	if( event->delta() > 0 ) PrevNotation();
	if( event->delta() < 0 ) NextNotation();
}
///////////////////////////////////////
//
//	Knights::SelectTheme
//
///////////////////////////////////////
void Knights::SelectTheme( int boardIndex, int chessmenIndex )
{
	Resource->setTheme( boardIndex, chessmenIndex );
	resizeMainFrame();
}
///////////////////////////////////////
//
//	Knights::setStatusBar
//
///////////////////////////////////////
void Knights::setStatusBar( const int &ID, const QString &MSG )
{
	/* Game comments as specified in http://www.schachprobleme.de/chessml/faq/pgn/
			Section 10: Numeric Annotation Glyphs */
	if( ( ID & COMMENT ) == COMMENT )
	{
		Message->setText( pgn::getNAG( ID - COMMENT ) );
		return;
	}
	/* Knights specific messages */
	switch( ID )
	{
		/* Error Codes */
		case BOOK_ERROR_1:
			Message->setText( i18n( "Error with white engine" ) );
			KMessageBox::sorry( this,
													i18n("You selected %1 to play white,\nbut it can only be used as a book engine.\nPlease select another engine to play white.").arg( MSG ),
													i18n("White Engine Problem") );
			break;
		case BOOK_ERROR_2:
			Message->setText( i18n( "Error with white book engine" ) );
			KMessageBox::sorry( this,
													i18n("You selected %1 to play white's book,\nbut it can only be used as a regular engine.\nPlease select another engine to play white's book.").arg( MSG ),
													i18n("White Book Engine Problem") );
			break;
		case BOOK_ERROR_3:
			Message->setText( i18n( "Error with black engine" ) );
			KMessageBox::sorry( this,
													i18n("You selected %1 to play black,\nbut it can only be used as a book engine.\nPlease select another engine to play black.").arg( MSG ),
													i18n("Black Engine Problem") );
			break;
		case BOOK_ERROR_4:
			Message->setText( i18n( "Error with black book engine" ) );
			KMessageBox::sorry( this,
													i18n("You selected %1 to play black's book,\nbut it can only be used as a regular engine.\nPlease select another engine to play black's book.").arg( MSG ),
													i18n("Black Book Engine Problem") );
			break;
		case ENGINE_DIED_ERROR:
			Message->setText( i18n( "The computer opponent assigned to play %1 has crashed" ).arg( MSG ) );
			break;
		case LOAD_ERROR:
			Message->setText( i18n( "There was an error while loading the file" ) );
			break;
		case SAVE_ERROR:
			Message->setText( i18n( "There was an error while saving the file" ) );
			break;
		/* Standard Codes */
		case LOAD_OK:
			Message->setText( i18n( "Loading complete" ) );
			break;
		case SAVE_OK:
			Message->setText( i18n( "Saving complete" ) );
			break;
		case READING_FILE:
			Message->setText( i18n( "Reading File" ) );
			break;
		case NO_MOVE_WHILE_REVIEW:
			Message->setText( i18n( "Can not move a chessman while reviewing the match" ) );
			break;
		case ILLEGAL_MOVE:
			Message->setText( i18n( "Illegal Move" ) );
			break;
		case WHITE_TURN:
			Message->setText( i18n( "White's turn" ) );
			break;
		case BLACK_TURN:
			Message->setText( i18n( "Black's turn" ) );
			break;
		case WHITE_WIN:
			Message->setText( i18n( "White wins" ) );
			break;
		case BLACK_WIN:
			Message->setText( i18n( "Black wins" ) );
			break;
		case WHITE_CHECKMATE:
			Message->setText( i18n( "Checkmate, White wins" ) );
			break;
		case BLACK_CHECKMATE:
			Message->setText( i18n( "Checkmate, Black wins" ) );
			break;
		case WHITE_RESIGN:
			Message->setText( i18n( "White resigns" ) );
			break;
		case BLACK_RESIGN:
			Message->setText( i18n( "Black resigns" ) );
			break;
		case WHITE_FLAG:
			Message->setText( i18n( "White's flag fell" ) );
			break;
		case BLACK_FLAG:
			Message->setText( i18n( "Black's flag fell" ) );
			break;
		case WHITE_CALL_FLAG:
			Message->setText( i18n( "Black's flag was called, White wins" ) );
			break;
		case BLACK_CALL_FLAG:
			Message->setText( i18n( "White's flag was called, Black wins" ) );
			break;
		case GAME_DRAW:
			Message->setText( i18n( "Draw match" ) );
			break;
		case GAME_50_MOVES:
			Message->setText( i18n( "50 moves rule, draw match" ) );
			break;
		case WAITING:
			Message->setText( i18n( "Starting computer players, please wait" ) );
			break;
		case PAUSED:
			Message->setText( i18n( "Match paused" ) );
			break;
		case WHITE_DRAW_OFFER:
			Message->setText( i18n( "White has offered a draw" ) );
			break;
		case BLACK_DRAW_OFFER:
			Message->setText( i18n( "Black has offered a draw" ) );
			break;
		case LOST_CONTACT:
			Message->setText( i18n( "Lost contact with opponent" ) );
  	case READY:
		default:
			Message->setText( i18n( "Ready" ) );
			break;
	}
}
///////////////////////////////////////
//
//	Knights::setClocks
//
///////////////////////////////////////
void Knights::setClocks( void )
{
	whiteTimeLabel->setText( Core->clock( WHITE ) );
	blackTimeLabel->setText( Core->clock( BLACK ) );
	if( Core->flag( WHITE ) )
		if( Core->blackInput() == PLAYERLOCAL )
			matchMenu->setItemEnabled( MENU_CALL_FLAG, TRUE );
		else
			matchMenu->setItemEnabled( MENU_CALL_FLAG, FALSE );
	if( Core->flag( BLACK ) )
		if( Core->whiteInput() == PLAYERLOCAL )
			matchMenu->setItemEnabled( MENU_CALL_FLAG, TRUE );
		else
			matchMenu->setItemEnabled( MENU_CALL_FLAG, FALSE );
}
///////////////////////////////////////
//
//	Knights::setNotation
//
///////////////////////////////////////
void Knights::setNotation( void )
{
	QStringList *list;
	QStringList::Iterator IT;
	int count(0);

	setCaption( Core->caption() );
	notationBar->clear();
	list = Core->notation();
	/*
			Several menu items' status changes based upon the availability
			of notation data. Therefore, we'll enable & disable those here
			since we've gathered the notation data anyway.
	*/
	if( list == NULL )
	{
		/* Disable Save & Print Functions */
		fileMenu->setItemEnabled( MENU_SAVE, FALSE );
		fileMenu->setItemEnabled( MENU_SAVEAS, FALSE );
		fileMenu->setItemEnabled( MENU_PRINT, FALSE );
		matchMenu->setItemEnabled( MENU_RETRACT, FALSE );
		return;
	}
	if( Core->modified() )
		fileMenu->setItemEnabled( MENU_SAVE, TRUE );
	else
		fileMenu->setItemEnabled( MENU_SAVE, FALSE );
	/* Core->onMove is called before it is updated by Match->slot_Move. Because of this, the following
			if statement checks for the wrong player's turn. On purpose */
	if( ( Core->inputOnMove() == PLAYERLOCAL ) && ( Core->inputOnMove(TRUE) == PLAYERPC ) && list->count() )
		matchMenu->setItemEnabled( MENU_RETRACT, TRUE );
	else
		matchMenu->setItemEnabled( MENU_RETRACT, FALSE );
	fileMenu->setItemEnabled( MENU_SAVEAS, TRUE );
	fileMenu->setItemEnabled( MENU_PRINT, TRUE );

	/* Create the List */
	for( IT = list->begin(); IT != list->end(); ++IT )
	{
			notationBar->insertItem( (*IT), count++ );
	}
	notationBar->setCurrentItem( --count );
	delete list;
}
///////////////////////////////////////
//
//	Knights::PrevNotation
//
///////////////////////////////////////
void Knights::PrevNotation( void )
{
	int tmp( notationBar->currentItem() - 1 );
	Core->review( tmp ); // Do this before the bounds checking in case this is examine mode
	if( tmp < 0 )
		return;
	notationBar->setCurrentItem( tmp );
}
///////////////////////////////////////
//
//	Knights::NextNotation
//
///////////////////////////////////////
void Knights::NextNotation( void )
{
	int tmp( notationBar->currentItem() + 1 );
	Core->review( tmp ); // Do this before the bounds checking in case this is examine mode
	if( tmp > ( notationBar->count() - 1 ) )
		return;
	notationBar->setCurrentItem( tmp );
}
///////////////////////////////////////
//
//	Knights::initMatch
//
///////////////////////////////////////
void Knights::initMatch( void )
{
	setNotation();

	/* Are there any players? ( ie - is this a match or a null? */
	if( ( Core->whiteInput() == Null ) || ( Core->blackInput() == Null ) )
	{
		fileMenu->setItemEnabled( MENU_CLOSE, FALSE );
		fileMenu->setItemEnabled( MENU_CLOSEALL, FALSE );
		matchMenu->setItemEnabled( MENU_ORIENTATION, FALSE );
		whiteTimeLabel->setText( "" );
		blackTimeLabel->setText( "" );
		setStatusBar( READY );
	}
	else
	{
		fileMenu->setItemEnabled( MENU_CLOSE, TRUE );
		fileMenu->setItemEnabled( MENU_CLOSEALL, TRUE );
		matchMenu->setItemEnabled( MENU_ORIENTATION, TRUE );
	}

	/* Is there a local player? */
	if( ( Core->whiteInput() == PLAYERLOCAL ) || ( Core->blackInput() == PLAYERLOCAL ) )
	{
		matchMenu->setItemEnabled( MENU_DRAW, TRUE );
		matchMenu->setItemEnabled( MENU_RESIGN, TRUE );
		/* Is there also a PC player? */
		if( ( Core->whiteInput() == PLAYERPC ) || ( Core->blackInput() == PLAYERPC ) )
		{
		}
	}
	else
	{
		matchMenu->setItemEnabled( MENU_DRAW, FALSE );
		matchMenu->setItemEnabled( MENU_RESIGN, FALSE );
	}
	/* Is there a PC player? */
	if( ( Core->whiteInput() == PLAYERPC ) || ( Core->blackInput() == PLAYERPC ) )
	{
		matchMenu->setItemEnabled( MENU_MOVE_NOW, TRUE );
		matchMenu->setItemEnabled( MENU_HINT, TRUE );
		matchMenu->setItemEnabled( MENU_PONDER, TRUE );
		matchMenu->setItemEnabled( MENU_PAUSE, TRUE );
	}
	else
	{
		matchMenu->setItemEnabled( MENU_MOVE_NOW, FALSE );
		matchMenu->setItemEnabled( MENU_HINT, FALSE );
		matchMenu->setItemEnabled( MENU_PONDER, FALSE );
		matchMenu->setItemEnabled( MENU_PAUSE, FALSE );
	}
	/* Is there a TCP player? */
//	if( ( Core->whiteInput() == PLAYERTCP ) || ( Core->blackInput() == PLAYERTCP ) )
//	{
//	}
//	else
//	{
//	}
}
///////////////////////////////////////
//
//	Knights::netConnect
//
///////////////////////////////////////
void Knights::netConnect( void )
{
  if(Core->isOnline())
  {
    fileMenu->changeItem( MENU_CONNECT, QIconSet( Resource->LoadIcon( QString("connect_creating"),
                          KIcon::Small ) ), i18n( "Connect to Server" ));
    Core->goOffline();
		setCursor( Resource->CURSOR_Standard );
  }
  else
  {
    fileMenu->changeItem( MENU_CONNECT, QIconSet( Resource->LoadIcon( QString("connect_no"),
                          KIcon::Small ) ), i18n( "Disconnect from Server" ) );
    /*
      By passing Null as the ID, we're telling core that we're
      creating a new internetio, not reusing an exsisting one.
    */
		Core->createNewIO( PLAYERTCP, Null);
	}
}
///////////////////////////////////////
//
//	Knights::openSettingsDialog
//
///////////////////////////////////////
void Knights::openSettingsDialog( void )
{
	SettingsDialog = new dlg_settings( this, "settings", Resource );
	connect( SettingsDialog, SIGNAL( themeChanged(int,int) ), this, SLOT( SelectTheme(int,int) ) );
	connect( SettingsDialog, SIGNAL( redrawBoard() ), Core, SLOT( resize() ) );
	connect( SettingsDialog, SIGNAL( resetServer() ), Core, SLOT( resetServer() ) );
	connect( this, SIGNAL( themesAdded() ), SettingsDialog, SLOT( slotThemesAdded() ) );
	SettingsDialog->show();
}
///////////////////////////////////////
//
//	Knights::openNewMatchDialog
//
///////////////////////////////////////
void Knights::openNewMatchDialog( void )
{
	NewMatch = new dlg_newmatch( this, "NewMatch", Resource );
	connect( NewMatch, SIGNAL( okClicked() ), this, SLOT( newMatch() ) );
	NewMatch->show();
}
///////////////////////////////////////
//
//	Knights::newMatch
//
///////////////////////////////////////
void Knights::newMatch( void )
{
	Core->newMatch( NewMatch->paramaters() );
}
///////////////////////////////////////
//
//	Knights::openKeyBindingDialog
//
///////////////////////////////////////
void Knights::openKeyBindingDialog( void )
{
	KKeyDialog::configureKeys( myAccel, TRUE, this );
}
///////////////////////////////////////
//
//	Knights::Settings
//
///////////////////////////////////////
void Knights::Settings(int opt)
{
	switch(opt)
	{
		case MENU_PONDER:
			Resource->OPTION_Ponder = 1 - Resource->OPTION_Ponder;
			matchMenu->setItemChecked(MENU_PONDER, Resource->OPTION_Ponder );
			Core->matchMenu( MENU_PONDER );
			break;
		case MENU_PAUSE:
			if( Core->paused() )
			{
				matchMenu->changeItem( MENU_PAUSE,
															QIconSet( Resource->LoadIcon( QString("player_pause"), KIcon::Small ) ),
															i18n( "Pause" ) );
			}
			else
			{
				matchMenu->changeItem( MENU_PAUSE,
															QIconSet( Resource->LoadIcon( QString("1rightarrow"), KIcon::Small ) ),
															i18n( "Resume" ) );
			}
			Core->matchMenu( MENU_PAUSE );
			break;
		default:
			break;
	}
}
///////////////////////////////////////
//
//	Knights::SaveGame & Variants
//
///////////////////////////////////////
bool Knights::SaveGame( void )
{
	/* We use 'Null' to indicate the current match */
	return Core->save( Null, FALSE, FALSE );
}
bool Knights::SaveGamePrompt( void )
{
	return Core->save( Null, TRUE, FALSE );
}
bool Knights::SaveGameAs( void )
{
	return Core->save( Null, FALSE, TRUE );
}
///////////////////////////////////////
//
//	Knights::boardBigger
//
///////////////////////////////////////
void Knights::boardBigger( void )
{
	Resource->resizeTheme( Resource->ThemeSize + 8 );
	resizeMainFrame();
}
///////////////////////////////////////
//
//	Knights::boardSmaller
//
///////////////////////////////////////
void Knights::boardSmaller( void )
{
	Resource->resizeTheme( Resource->ThemeSize - 8 );
	resizeMainFrame();
}

///////////////////////////////////////
//
//	Knights::installThemes
//
///////////////////////////////////////
void Knights::installThemes( void )
{
	bool localFlag(FALSE);
	bool installError(FALSE);
	unsigned int loop;
	QString allerror;
	QString fileFilter( "KB* KC* KS*|" );
	fileFilter += i18n( "Knights Themes" );
	KURL::List files = KFileDialog::getOpenURLs( QString::null, fileFilter, this, i18n( "Install Theme..." ) );
	for( loop = 0; loop < files.count(); loop++ )
	{
		/* Try writing to the global theme dir */
		if( !KIO::NetAccess::copy( files[loop], KURL( QString( Resource->themeDir() + files[loop].filename() ) ) ) )
		{
			/* Nope... Try a local .knights dir */
			allerror += "\n\n" + QString( Resource->themeDir() + files[loop].filename() )
								+ " - " + KIO::NetAccess::lastErrorString();
			if( !KIO::NetAccess::exists( KURL( QString( QDir::homeDirPath() + "/.knights" ) ) ) )
			{
				/* Create local .knights dir */
				KIO::NetAccess::mkdir( KURL( QString( QDir::homeDirPath() + "/.knights" ) ) );
			}
			if( !KIO::NetAccess::copy( files[loop], KURL( QString( QDir::homeDirPath() + "/.knights/" + files[loop].filename() ) ) ) )
			{
				/* Nope, can't copy it anywhere */
				installError = TRUE;
				allerror += "\n\n" + QString( QDir::homeDirPath() + "/.knights/"
									+ files[loop].filename() ) + " - " + KIO::NetAccess::lastErrorString();
			}
			else
			{
				localFlag = TRUE;
			}
		}
	}
	if( localFlag )
	{
		KMessageBox::sorry( this,
												i18n("You do not have permission to install this theme systemwide, so Knights installed it locally."),
												i18n("Installed theme locally") );
	}
	if( installError )
	{
		KMessageBox::sorry( this,
												i18n("The theme could not be installed:\n%1").arg( allerror ),
												i18n("Can not install theme") );
	}
	return;
}