Git commit 3b0cba195bdb3dd8c6320c7a625b68eaae5b7007 by Miha Čančula. Committed on 06/03/2011 at 19:38. Pushed by mihac into branch 'master'. Use KSpeech to speak computer's moves. M +1 -0 src/CMakeLists.txt M +51 -2 src/gamemanager.cpp M +6 -0 src/knights.kcfg http://commits.kde.org/knights/3b0cba195bdb3dd8c6320c7a625b68eaae5b7007 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2b89031..fff01fe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,6 +52,7 @@ kde4_add_ui_files(knights_SRCS popup.ui ) kde4_add_kcfg_files(knights_SRCS settings.kcfgc ) +qt4_add_dbus_interfaces(knights_SRCS ${KDE4_DBUS_INTERFACES_DIR}/org.kde.KSpeech.xml) kde4_add_executable(knights ${knights_SRCS}) target_link_libraries(knights ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} ${KDE4_PLASMA_LIBS} ${KDEGAMES_LIBRARY} ${QT_QTNETWORK_LIBRARY}) diff --git a/src/gamemanager.cpp b/src/gamemanager.cpp index 3460760..4195f23 100644 --- a/src/gamemanager.cpp +++ b/src/gamemanager.cpp @@ -32,6 +32,9 @@ #include #include +#include +#include "kspeechinterface.h" + using namespace Knights; const int TimerInterval = 100; @@ -63,8 +66,9 @@ public: QStack moveUndoStack; Rules* rules; - QMap offers; + + org::kde::KSpeech* speech; }; GameManagerPrivate::GameManagerPrivate() @@ -72,7 +76,8 @@ GameManagerPrivate::GameManagerPrivate() running(false), gameStarted(false), timer(0), - rules(0) + rules(0), + speech(0) { } @@ -88,11 +93,20 @@ Manager::Manager(QObject* parent) : QObject(parent), d_ptr(new GameManagerPrivate) { kDebug() << "creating a GameManager"; + Q_D(GameManager); + d->speech = new org::kde::KSpeech( + QLatin1String("org.kde.kttsd"), + QLatin1String("/KSpeech"), + QDBusConnection::sessionBus() + ); + d->speech->setApplicationName(qAppName()); } Manager::~Manager() { kDebug() << " !!! ----- Destroying a Game Manager ----- !!!"; + Q_D(GameManager); + delete d->speech; delete d_ptr; } @@ -588,6 +602,41 @@ void Manager::sendPendingMove() Protocol::byColor ( oppositeColor ( d->activePlayer ) )->move ( pendingMove ); emit pieceMoved ( pendingMove ); rules()->moveMade ( pendingMove ); + if ( Settings::speakOpponentsMoves() + && !Protocol::byColor(d->activePlayer)->isLocal() + && Protocol::byColor(oppositeColor(d->activePlayer))->isLocal() ) + { + QString toSpeak; + QString name = Protocol::byColor(d->activePlayer)->playerName(); + if ( pendingMove.flag(Move::Castle) ) + { + if ( pendingMove.to().first == 3 ) + { + toSpeak = i18nc("string to be spoken when the opponent castles queenside", + "%1 castles queenside", name); + } + else + { + toSpeak = i18nc("string to be spoken when the opponent castles queenside", + "%1 castles kingside", name); + } + } + else + { + toSpeak = i18nc("string to be spoken when the opponent makes a normal move", + "%1 to %2", + pieceTypeName ( pendingMove.pieceData().second ), + pendingMove.to().string() + ); + } + kDebug() << toSpeak; + d->speech->say(toSpeak, KSpeech::soPlainText); + if ( pendingMove.flag(Move::Check) ) + { + d->speech->say ( i18nc( "Your king is under attack", "Check" ), KSpeech::soPlainText ); + } + } + pendingMove = Move(); Color winner = rules()->winner(); diff --git a/src/knights.kcfg b/src/knights.kcfg index 7e76d94..d435b37 100644 --- a/src/knights.kcfg +++ b/src/knights.kcfg @@ -141,4 +141,10 @@ 500 + + + + true + +