ErrorScreen now displays the Go engine error that occured and GoEngine reports more sane errors.
svn path=/trunk/playground/games/kgo/; revision=842540
This commit is contained in:
parent
08ac1e6f65
commit
24815b9c9c
8 changed files with 127 additions and 97 deletions
|
@ -93,7 +93,6 @@ GoEngine::GoEngine()
|
|||
: m_currentPlayer(BlackPlayer)
|
||||
, m_fixedHandicapPlaced(false)
|
||||
{
|
||||
connect(&m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStandardError()));
|
||||
connect(&m_process, SIGNAL(error(QProcess::ProcessError)), SIGNAL(error(QProcess::ProcessError)));
|
||||
}
|
||||
|
||||
|
@ -107,19 +106,19 @@ bool GoEngine::run(const QString &command)
|
|||
quit(); // Close old session if there's one
|
||||
m_process.start(command.toLatin1()); // Start new process with provided command
|
||||
|
||||
if (!m_process.waitForStarted()) // Blocking wait for process start
|
||||
if (!m_process.waitForStarted()) { // Blocking wait for process start
|
||||
m_response = "Execute Go engine command \"" + command + "\" failed!";
|
||||
return false;
|
||||
|
||||
}
|
||||
m_engineCommand = command; // Save for retrieval
|
||||
|
||||
kDebug() << "Run new GTP engine session";
|
||||
kDebug() << "Starting new GTP engine session...";
|
||||
|
||||
if (protocolVersion() == 2) { // We support only GTP version 2 for now
|
||||
if (protocolVersion() >= 0) { // Check for supported GTP protocol version
|
||||
clearBoard(); // Start with blank board
|
||||
} else {
|
||||
kDebug() << "Protocol version error:" << protocolVersion();
|
||||
quit();
|
||||
m_response = "Protocol version error";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -850,15 +849,18 @@ QString GoEngine::echo(const QString &command)
|
|||
return waitResponse() ? m_response : QString();
|
||||
}
|
||||
|
||||
void GoEngine::readStandardError()
|
||||
{
|
||||
kWarning() << "Go engine I/O error occurred:\n" << m_process.readAllStandardError();
|
||||
}
|
||||
|
||||
bool GoEngine::waitResponse()
|
||||
{
|
||||
if (m_process.state() != QProcess::Running) { // No GTP connection means no computing fun!
|
||||
kWarning() << "Go engine command failed because no GTP session is running!";
|
||||
switch (m_process.error()) {
|
||||
case QProcess::FailedToStart: m_response = "No Go engine is running!"; break;
|
||||
case QProcess::Crashed: m_response = "The Go engine crashed!"; break;
|
||||
case QProcess::Timedout: m_response = "The Go engine timed out!"; break;
|
||||
case QProcess::WriteError: m_response = m_process.readAllStandardError(); break;
|
||||
case QProcess::ReadError: m_response = m_process.readAllStandardError(); break;
|
||||
case QProcess::UnknownError: m_response = "Unknown error!"; break;
|
||||
}
|
||||
kWarning() << "Command failed:" << m_response;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -756,13 +756,6 @@ signals:
|
|||
void currentPlayerChanged(PlayerColor);
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* This slot reads everything from the process's stderr. This is
|
||||
* mainly for debugging purposes, because this should only happen
|
||||
* if a bug occurred.
|
||||
*/
|
||||
void readStandardError();
|
||||
|
||||
/**
|
||||
* Wait gracefully for a response from the Go engine. The returned string
|
||||
* from the Go engine is stored in 'm_response'.
|
||||
|
|
|
@ -69,6 +69,7 @@ MainWindow::MainWindow(QWidget *parent, bool startDemo)
|
|||
m_newGameAction->setEnabled(false);
|
||||
m_loadGameAction->setEnabled(false);
|
||||
m_mainWidget->setCurrentWidget(errorScreen());
|
||||
m_errorScreen->setErrorMessage(m_gameScene->engine()->response());
|
||||
} else {
|
||||
m_newGameAction->setEnabled(true);
|
||||
m_loadGameAction->setEnabled(true);
|
||||
|
@ -79,7 +80,7 @@ MainWindow::MainWindow(QWidget *parent, bool startDemo)
|
|||
void MainWindow::newGame()
|
||||
{
|
||||
m_saveAsAction->setEnabled(false);
|
||||
m_endTurnAction->setEnabled(false);
|
||||
m_passAction->setEnabled(false);
|
||||
m_setupScreen->setupNewGame();
|
||||
m_mainWidget->setCurrentWidget(setupScreen());
|
||||
statusBar()->showMessage(i18n("Play a new game..."), 3000);
|
||||
|
@ -88,11 +89,11 @@ void MainWindow::newGame()
|
|||
void MainWindow::loadGame()
|
||||
{
|
||||
m_saveAsAction->setEnabled(false);
|
||||
m_endTurnAction->setEnabled(false);
|
||||
m_passAction->setEnabled(false);
|
||||
QString fileName = KFileDialog::getOpenFileName(KUrl(QDir::homePath()), "*.sgf");
|
||||
if (!fileName.isEmpty()) {
|
||||
setupScreen()->setupLoadedGame(fileName);
|
||||
m_mainWidget->setCurrentWidget(setupScreen());
|
||||
m_mainWidget->setCurrentWidget(m_setupScreen);
|
||||
statusBar()->showMessage(i18n("Play a loaded game..."), 3000);
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +112,7 @@ void MainWindow::saveGame()
|
|||
void MainWindow::startGame()
|
||||
{
|
||||
m_saveAsAction->setEnabled(true);
|
||||
m_endTurnAction->setEnabled(true);
|
||||
m_passAction->setEnabled(true);
|
||||
// The GameScene should be configured and just be waiting for further input
|
||||
// so we only need to show the GameScreen and allow direct user-interaction
|
||||
m_mainWidget->setCurrentWidget(gameScreen());
|
||||
|
@ -128,7 +129,7 @@ void MainWindow::redo()
|
|||
kDebug() << "Undo";
|
||||
}
|
||||
|
||||
void MainWindow::endTurn()
|
||||
void MainWindow::pass()
|
||||
{
|
||||
kDebug() << "End turn";
|
||||
}
|
||||
|
@ -157,13 +158,13 @@ void MainWindow::updatePreferences()
|
|||
|
||||
// Restart the Go engine if the engine command was changed by the user.
|
||||
GoEngine *engine = m_gameScene->engine();
|
||||
//FIXME: There seems to be an issue with not-updated preferences here
|
||||
if (engine->engineCommand() != Preferences::engineCommand()) {
|
||||
kDebug() << "Engine command changed or engine not running, (re)start engine...";
|
||||
if (!m_gameScene->engine()->run(Preferences::engineCommand())) {
|
||||
m_newGameAction->setEnabled(false);
|
||||
m_loadGameAction->setEnabled(false);
|
||||
m_mainWidget->setCurrentWidget(errorScreen());
|
||||
m_errorScreen->setErrorMessage(m_gameScene->engine()->response());
|
||||
} else {
|
||||
m_newGameAction->setEnabled(true);
|
||||
m_loadGameAction->setEnabled(true);
|
||||
|
@ -176,8 +177,8 @@ ErrorScreen *MainWindow::errorScreen()
|
|||
{
|
||||
if (!m_errorScreen) {
|
||||
m_errorScreen = new ErrorScreen;
|
||||
connect(m_errorScreen, SIGNAL(configureClicked()), this, SLOT(showPreferences()));
|
||||
connect(m_errorScreen, SIGNAL(quitClicked()), this, SLOT(close()));
|
||||
connect(m_errorScreen, SIGNAL(configureButtonClicked()), this, SLOT(showPreferences()));
|
||||
connect(m_errorScreen, SIGNAL(quitButtonClicked()), this, SLOT(close()));
|
||||
m_mainWidget->addWidget(m_errorScreen);
|
||||
}
|
||||
return m_errorScreen;
|
||||
|
@ -218,8 +219,9 @@ void MainWindow::setupActions()
|
|||
m_previousMoveAction->setEnabled(false);
|
||||
m_nextMoveAction = KStandardGameAction::redo(this, SLOT(redo()), actionCollection());
|
||||
m_nextMoveAction->setEnabled(false);
|
||||
m_endTurnAction = KStandardGameAction::endTurn(this, SLOT(endTurn()), actionCollection());
|
||||
m_endTurnAction->setEnabled(false);
|
||||
m_passAction = KStandardGameAction::endTurn(this, SLOT(pass()), actionCollection());
|
||||
m_passAction->setText(i18n("Pass move"));
|
||||
m_passAction->setEnabled(false);
|
||||
m_demoAction = KStandardGameAction::demo(this, SLOT(toggleDemoMode()), actionCollection());
|
||||
m_demoAction->setEnabled(false);
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ private slots:
|
|||
void startGame(); ///< React on setupscreen start button
|
||||
void undo(); ///< Undo last move
|
||||
void redo(); ///< Redo last move
|
||||
void endTurn(); ///< Pass current move
|
||||
void pass(); ///< Pass current move
|
||||
void toggleDemoMode(); ///<
|
||||
void showPreferences(); ///< Show configuration dialog
|
||||
void updatePreferences(); ///< React on user changed configuration
|
||||
|
@ -95,7 +95,7 @@ private:
|
|||
KAction *m_previousMoveAction; ///< Action to jump to the previous move
|
||||
KAction *m_nextMoveAction; ///< Action to jump to the next move
|
||||
KAction *m_lastMoveAction; ///< Action to jump to the last move
|
||||
KAction *m_endTurnAction; ///< Action to pass current move
|
||||
KAction *m_passAction; ///< Action to pass current move
|
||||
KToggleAction *m_demoAction; ///< Action to change to demo mode
|
||||
};
|
||||
|
||||
|
|
|
@ -42,15 +42,19 @@ ErrorScreen::ErrorScreen(QWidget *parent)
|
|||
configureButton->setIcon(configureItem.icon());
|
||||
configureButton->setToolTip(configureItem.toolTip());
|
||||
configureButton->setWhatsThis(configureItem.whatsThis());
|
||||
connect(configureButton, SIGNAL(clicked()), this, SIGNAL(configureButtonClicked()));
|
||||
|
||||
KGuiItem quitItem = KStandardGuiItem::quit();
|
||||
quitButton->setText(quitItem.text());
|
||||
quitButton->setIcon(quitItem.icon());
|
||||
quitButton->setToolTip(quitItem.toolTip());
|
||||
quitButton->setWhatsThis(quitItem.whatsThis());
|
||||
connect(quitButton, SIGNAL(clicked()), this, SIGNAL(quitButtonClicked()));
|
||||
}
|
||||
|
||||
connect(configureButton, SIGNAL(clicked()), this, SIGNAL(configureClicked()));
|
||||
connect(quitButton, SIGNAL(clicked()), this, SIGNAL(quitClicked()));
|
||||
void ErrorScreen::setErrorMessage(const QString &errorMessage)
|
||||
{
|
||||
errorMessageLabel->setText(errorMessage);
|
||||
}
|
||||
|
||||
} // End of namespace KGo
|
||||
|
|
|
@ -53,9 +53,12 @@ public:
|
|||
*/
|
||||
explicit ErrorScreen(QWidget *parent = 0);
|
||||
|
||||
public slots:
|
||||
void setErrorMessage(const QString &errorMessage);
|
||||
|
||||
signals:
|
||||
void configureClicked();
|
||||
void quitClicked();
|
||||
void configureButtonClicked();
|
||||
void quitButtonClicked();
|
||||
};
|
||||
|
||||
} // End of namespace KGo
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>500</width>
|
||||
<height>431</height>
|
||||
<width>530</width>
|
||||
<height>474</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
|
@ -41,6 +41,12 @@
|
|||
</item>
|
||||
<item row="1" column="1" >
|
||||
<widget class="QGroupBox" name="errorBox" >
|
||||
<property name="minimumSize" >
|
||||
<size>
|
||||
<width>350</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title" >
|
||||
<string/>
|
||||
</property>
|
||||
|
@ -60,7 +66,7 @@
|
|||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Sans Serif'; font-size:12pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#ff0000;">KGo was unable to find a suitable Go engine</span></p></body></html></string>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#ff0000;">KGo failed to start the Go engine</span></p></body></html></string>
|
||||
</property>
|
||||
<property name="alignment" >
|
||||
<set>Qt::AlignCenter</set>
|
||||
|
@ -87,13 +93,6 @@ p, li { white-space: pre-wrap; }
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2" >
|
||||
<widget class="Line" name="line_2" >
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" >
|
||||
<widget class="KPushButton" name="configureButton" >
|
||||
<property name="text" >
|
||||
|
@ -108,6 +107,30 @@ p, li { white-space: pre-wrap; }
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2" >
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<property name="title" >
|
||||
<string>Error message</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" >
|
||||
<item>
|
||||
<widget class="QLabel" name="errorMessageLabel" >
|
||||
<property name="font" >
|
||||
<font>
|
||||
<italic>true</italic>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>-</string>
|
||||
</property>
|
||||
<property name="wordWrap" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>674</width>
|
||||
<height>478</height>
|
||||
<height>477</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
|
@ -42,6 +42,16 @@
|
|||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2" >
|
||||
<item row="1" column="1" >
|
||||
<widget class="KLineEdit" name="whitePlayerName" >
|
||||
<property name="enabled" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" >
|
||||
<widget class="QLabel" name="label_4" >
|
||||
<property name="text" >
|
||||
|
@ -55,6 +65,19 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QLabel" name="label_3" >
|
||||
<property name="text" >
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
<property name="alignment" >
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>whitePlayerName</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" >
|
||||
<widget class="KComboBox" name="whitePlayerCombo" >
|
||||
<item>
|
||||
|
@ -69,30 +92,11 @@
|
|||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QLabel" name="label_3" >
|
||||
<property name="text" >
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
<property name="alignment" >
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>whitePlayerName</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" >
|
||||
<widget class="KLineEdit" name="whitePlayerName" >
|
||||
<property name="enabled" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>label_4</zorder>
|
||||
<zorder>label_3</zorder>
|
||||
<zorder>whitePlayerName</zorder>
|
||||
<zorder>whitePlayerCombo</zorder>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -128,6 +132,16 @@
|
|||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" >
|
||||
<widget class="KLineEdit" name="blackPlayerName" >
|
||||
<property name="enabled" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QLabel" name="label_6" >
|
||||
<property name="text" >
|
||||
|
@ -141,16 +155,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" >
|
||||
<widget class="KLineEdit" name="blackPlayerName" >
|
||||
<property name="enabled" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -161,8 +165,14 @@
|
|||
<property name="enabled" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize" >
|
||||
<size>
|
||||
<width>150</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title" >
|
||||
<string>Computer Setup</string>
|
||||
<string>Computer setup</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4" >
|
||||
<item row="0" column="0" colspan="2" >
|
||||
|
@ -232,8 +242,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>306</width>
|
||||
<height>217</height>
|
||||
<width>304</width>
|
||||
<height>207</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4" >
|
||||
|
@ -246,13 +256,13 @@
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="title" >
|
||||
<string>Game Setup</string>
|
||||
<string>Game setup</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_5" >
|
||||
<item rowspan="3" row="0" column="0" >
|
||||
<widget class="KButtonGroup" name="sizeGroupBox" >
|
||||
<property name="title" >
|
||||
<string>BoardSize</string>
|
||||
<string>Board size</string>
|
||||
</property>
|
||||
<property name="flat" >
|
||||
<bool>false</bool>
|
||||
|
@ -342,7 +352,10 @@
|
|||
<item row="1" column="1" >
|
||||
<widget class="QGroupBox" name="handicapGroupBox" >
|
||||
<property name="title" >
|
||||
<string>Fixed Handicap</string>
|
||||
<string>Fixed handicap</string>
|
||||
</property>
|
||||
<property name="flat" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="checkable" >
|
||||
<bool>true</bool>
|
||||
|
@ -368,17 +381,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" >
|
||||
<spacer name="verticalSpacer" >
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0" >
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>18</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<spacer name="verticalSpacer" />
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -489,7 +492,7 @@
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Start Game</string>
|
||||
<string>Start game</string>
|
||||
</property>
|
||||
<property name="shortcut" >
|
||||
<string>Ctrl+S</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue