Skip to content

Commit

Permalink
Bugfix: #340 ‘availableVoices’ not a member
Browse files Browse the repository at this point in the history
  • Loading branch information
Isarhamster committed May 23, 2023
1 parent 4fab4d2 commit 9797d46
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/dialogs/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,23 +645,23 @@ void PreferencesDialog::restoreSettings()

#if defined(USE_SOUND) || defined(USE_SPEECH)
ui.cbSoundOn->setCurrentIndex(AppSettings->getValue("Move").toInt());

QStringList voiceNames = ChessXSettings::availableVoices(lang);
ui.cbVoice->addItems(voiceNames);

ui.cbVoice->setCurrentText(AppSettings->getValue("Voice").toString());
ui.volume->setValue(AppSettings->getValue("Volume").toInt());
ui.cbScreenReader->setChecked(AppSettings->getValue("ScreenReader").toBool());
ui.cbMoveSound->setChecked(AppSettings->getValue("MoveSound").toBool());
ui.plyReadAhead->setValue(AppSettings->getValue("PlyReadAhead").toInt());
ui.delayReadAhead->setValue(AppSettings->getValue("DelayReadAhead").toInt());

#ifdef USE_SPEECH
QStringList voiceNames = ChessXSettings::availableVoices(lang);
ui.cbVoice->addItems(voiceNames);
ui.cbVoice->setCurrentText(AppSettings->getValue("Voice").toString());
if (!QTextToSpeech::availableEngines().count())
{
ui.cbVoice->setEnabled(false);
ui.cbScreenReader->setChecked(false);
ui.plyReadAhead->setEnabled(false);
ui.delayReadAhead->setEnabled(false);
ui.cbScreenReader->setEnabled(false);
}
#endif

Expand Down
12 changes: 8 additions & 4 deletions src/gui/chessxsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include <QWidget>
#include <QMainWindow>
#include <QSplitter>
#ifdef USE_SPEECH
#include <QTextToSpeech>
#endif
#include <QLayout>

using namespace chessx;
Expand Down Expand Up @@ -161,9 +163,9 @@ bool ChessXSettings::layout(QWidget* w)
return valid;
}

#ifdef USE_SPEECH
void ChessXSettings::configureSpeech(QTextToSpeech* speech)
{
#ifdef USE_SPEECH
speech->setLocale(ChessXSettings::locale());

QVector<QVoice> voices = speech->availableVoices();
Expand All @@ -180,8 +182,8 @@ void ChessXSettings::configureSpeech(QTextToSpeech* speech)
break;
}
}
#endif
}
#endif

QLocale ChessXSettings::locale()
{
Expand All @@ -190,10 +192,11 @@ QLocale ChessXSettings::locale()
return cxLocale;
}

#ifdef USE_SPEECH
QStringList ChessXSettings::availableVoices(QString lang)
{
QStringList list;
#ifdef USE_SPEECH

QLocale cxLocale(lang);

QTextToSpeech* speech = new QTextToSpeech();
Expand All @@ -204,9 +207,10 @@ QStringList ChessXSettings::availableVoices(QString lang)
for (const QVoice &voice : qAsConst(voices)) {
list << voice.name();
}
#endif

return list;
}
#endif

void ChessXSettings::setLayout(const QWidget* w)
{
Expand Down
3 changes: 3 additions & 0 deletions src/gui/chessxsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include <QStringList>
#include <QLocale>

#ifdef USE_SPEECH
class QTextToSpeech;
#endif

class Widget;

class ChessXSettings : public Settings
Expand Down

0 comments on commit 9797d46

Please sign in to comment.