summaryrefslogtreecommitdiffstats
path: root/knights/dlg_engine.cpp
blob: c2f767e722661602f29f14b95bd0d4db224ef70c (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
/***************************************************************************
                          dlg_engine.cpp  -  description
                             -------------------
    begin                : Wed Jul 18 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 <kfiledialog.h>
#include <kicontheme.h>
#include "dlg_engine.moc"

dlg_engine::dlg_engine(QWidget *parent, const char *name, resource *Rsrc, QString ItemName ) :
	KDialogBase(	parent,
								name,
								TRUE,
								i18n("Configure Engine"),
								Help|Ok|Apply|Cancel,
								Ok,
								TRUE )
{
	Resource = Rsrc;
	Name = ItemName;

	BOX_Parent = makeVBoxMainWidget();
	BOX_NameProto = new QHBox( BOX_Parent );
	BOX_Name = new QGroupBox( 1,
														Qt::Horizontal,
														i18n( "Engine Name" ),
														BOX_NameProto );
	EDIT_Name = new KLineEdit( BOX_Name );
	BOX_Protocol = new QGroupBox( 1,
																Qt::Horizontal,
																i18n( "Protocol" ),
																BOX_NameProto );
	EDIT_Protocol = new KComboBox( BOX_Protocol );
	BOX_Filename = new QGroupBox( 2,
																Qt::Horizontal,
																i18n( "Engine Filename" ),
																BOX_Parent );
	EDIT_Filename = new KLineEdit( BOX_Filename );
	BUTTON_Filename = new QPushButton( BOX_Filename );
	BOX_Arguments = new QGroupBox( 1,
																	Qt::Horizontal,
																	i18n( "Command Line Arguments" ),
																	BOX_Parent );
	EDIT_Arguments = new KLineEdit( BOX_Arguments );
	BOX_LogFile = new QGroupBox( 2,
																Qt::Horizontal,
																i18n( "Log File" ),
																BOX_Parent );
	EDIT_LogFile = new KLineEdit( BOX_LogFile );
	BUTTON_LogFile = new QPushButton( BOX_LogFile );
	setMainWidget( BOX_Parent );
	BUTTON_Filename->setPixmap( Resource->LoadIcon( QString( "fileopen" ), KIcon::Toolbar ) );
	BUTTON_LogFile->setPixmap( Resource->LoadIcon( QString( "fileopen" ), KIcon::Toolbar ) );
	EDIT_Name->setMinimumWidth( 150 );
	EDIT_Filename->setMinimumWidth( 300 );
	EDIT_Arguments->setMinimumWidth( 300 );
	/* Protocol ComboBox */
	EDIT_Protocol->insertItem( QString( "XBoard" ) );
	EDIT_Protocol->insertItem( QString( "UCI" ) );
	EDIT_Protocol->setEditable( FALSE );
	/* Load in data if this is a modification */
	if( !Name.isEmpty() )
	{
		for ( enginesIT = Resource->engines.begin(); enginesIT != Resource->engines.end(); ++enginesIT )
		{
			if( (*enginesIT).Name == Name ) break;
		}
		EDIT_Name->setText( (*enginesIT).Name );
		EDIT_Filename->setText( (*enginesIT).Filename );
		EDIT_Arguments->setText( (*enginesIT).Arguments );
		EDIT_LogFile->setText( (*enginesIT).LogFile );
		switch( (*enginesIT).Protocol )
		{
			case XBoard:
				EDIT_Protocol->setCurrentItem(0);
				break;
			case UCI:
				EDIT_Protocol->setCurrentItem(1);
				break;
			default:
				break;
		}
	}
	/* Init the buttons */
	showButtonCancel( TRUE );
	showButtonOK( TRUE );
	showButtonApply( TRUE );
	showButton( Help, TRUE );

	enableButtonCancel( TRUE );
	enableButtonOK( TRUE );
	enableButtonApply( FALSE );
	enableButton( Help, TRUE );

	setHelp( QString( "configure-engines" ) );
	/* Make Connections */
	connect( BUTTON_Filename, SIGNAL( clicked() ), this, SLOT( slotFilenameDialog() ) );
	connect( BUTTON_LogFile, SIGNAL( clicked() ), this, SLOT( slotLogFileDialog() ) );
	connect( EDIT_Protocol, SIGNAL( activated(int) ), this, SLOT( slotProtocol(int) ) );
	show();
}
///////////////////////////////////////
//
//	dlg_engine::~dlg_engine
//
///////////////////////////////////////
dlg_engine::~dlg_engine()
{
}
///////////////////////////////////////
//
//	dlg_engine::slotOk
//
///////////////////////////////////////
void dlg_engine::slotOk( void )
{
	slotApply();
	slotDelayedDestruct();
}
///////////////////////////////////////
//
//	dlg_engine::slotApply
//
///////////////////////////////////////
void dlg_engine::slotApply( void )
{
	engineResource newEngine;

	if( Name.isEmpty() )
	{
		enginesIT = Resource->engines.append( newEngine );
		Name = "notemptyanymore";
		(*enginesIT).Wins = 0;
		(*enginesIT).Losses = 0;
		(*enginesIT).Draws = 0;
		(*enginesIT).CurrentRef = 0;
	}
	(*enginesIT).Name = EDIT_Name->text();
	(*enginesIT).Filename = EDIT_Filename->text();
	(*enginesIT).Arguments = EDIT_Arguments->text();
	(*enginesIT).LogFile = EDIT_LogFile->text();
	switch( EDIT_Protocol->currentItem() )
	{
		case 0:
			(*enginesIT).Protocol = XBoard;
			break;
		case 1:
			(*enginesIT).Protocol = UCI;
			break;
		default:
			break;
	}
	enableButtonApply( FALSE );
}
///////////////////////////////////////
//
//	dlg_engine::slotCancel
//
///////////////////////////////////////
void dlg_engine::slotCancel( void )
{
	slotDelayedDestruct();
}
///////////////////////////////////////
//
//	dlg_engine::slotFilenameDialog
//
///////////////////////////////////////
void dlg_engine::slotFilenameDialog( void )
{
	QString temp;
	int tmp;

	temp = KFileDialog::getOpenFileName(	QString::null,
																				QString( "*" ),
																				this,
																				QString( "Find Engine..." ) );
	if( temp.isEmpty() ) return;
	EDIT_Filename->setText( temp );
	if( EDIT_Name->text().isEmpty() )
	{
		tmp = temp.findRev( '/' );
		EDIT_Name->setText( temp.remove( 0, tmp + 1 ) );
	}
	enableButtonApply( TRUE );
}
///////////////////////////////////////
//
//	dlg_engine::slotLogFileDialog
//
///////////////////////////////////////
void dlg_engine::slotLogFileDialog( void )
{
	QString temp;

	temp = KFileDialog::getOpenFileName(	QString::null,
																				QString( "*" ),
																				this,
																				QString( "Find Log..." ) );
	if( temp.isEmpty() ) return;
	EDIT_LogFile->setText( temp );
	enableButtonApply( TRUE );
}
///////////////////////////////////////
//
//	dlg_engine::slotProtocol
//
///////////////////////////////////////
void dlg_engine::slotProtocol( int Index )
{
	if(Index);	// No-op to stop compile warning.
	enableButtonApply( TRUE );
}