File lazy-load-QTextToSpeech-object.patch of Package kpimtextedit
diff --git a/src/texttospeech/texttospeech.cpp b/src/texttospeech/texttospeech.cpp
index 99a1474..1eb758c 100644
--- a/src/texttospeech/texttospeech.cpp
+++ b/src/texttospeech/texttospeech.cpp
@@ -25,6 +25,7 @@
#include <QVector>
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
#include <QtTextToSpeech/QTextToSpeech>
+#include <QDebug>
#endif
namespace KPIMTextEdit {
@@ -41,27 +41,35 @@ TextToSpeech::~TextToSpeech()
{
}
+#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
+void TextToSpeech::init_mTextToSpeech()
+{ qDebug() << "TextToSpeech::init_mTextToSpeech() called";
+ mTextToSpeech = new QTextToSpeech(mDefaultEngine, this);
+ connect(mTextToSpeech, &QTextToSpeech::stateChanged, this, &TextToSpeech::slotStateChanged);
+ mTextToSpeech->setRate(mRate);
+ mTextToSpeech->setPitch(mPitch);
+ mTextToSpeech->setVolume(mVolume);
+ mTextToSpeech->setLocale(mLocale);
+ //It doesn't have api for it mTextToSpeech->setVoice(mVoice);
+}
+#endif
+
void TextToSpeech::reloadSettings()
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
KConfig config(QStringLiteral("texttospeechrc"));
KConfigGroup grp = config.group("Settings");
const QString engineName = grp.readEntry("engine");
- if (!mTextToSpeech) {
- mTextToSpeech = new QTextToSpeech(engineName, this);
- connect(mTextToSpeech, &QTextToSpeech::stateChanged, this, &TextToSpeech::slotStateChanged);
- } else if (mDefaultEngine != engineName) {
+ if (mTextToSpeech && (mDefaultEngine != engineName)) {
disconnect(mTextToSpeech, &QTextToSpeech::stateChanged, this, &TextToSpeech::slotStateChanged);
delete mTextToSpeech;
- mTextToSpeech = new QTextToSpeech(engineName, this);
- connect(mTextToSpeech, &QTextToSpeech::stateChanged, this, &TextToSpeech::slotStateChanged);
}
mDefaultEngine = engineName;
- mTextToSpeech->setRate(grp.readEntry("rate", 0.0));
- mTextToSpeech->setPitch(grp.readEntry("pitch", 0.0));
- mTextToSpeech->setVolume(grp.readEntry("volume", 0));
- mTextToSpeech->setLocale(QLocale(grp.readEntry("localeName")));
- //It doesn't have api for it mTextToSpeech->setVoice(grp.readEntry("voice"));
+ mRate=grp.readEntry("rate", 0.0);
+ mPitch=grp.readEntry("pitch", 0.0);
+ mVolume=grp.readEntry("volume", 0);
+ mLocale=QLocale(grp.readEntry("localeName"));
+ //It doesn't have api for it mVoice=grp.readEntry("voice");
#endif
}
@@ -75,6 +83,7 @@ void TextToSpeech::slotStateChanged()
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
TextToSpeech::State state;
+ if(!mTextToSpeech) init_mTextToSpeech();
switch (mTextToSpeech->state()) {
case QTextToSpeech::Ready:
state = TextToSpeech::Ready;
@@ -96,6 +105,7 @@ void TextToSpeech::slotStateChanged()
bool TextToSpeech::isReady() const
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
+// if(!mTextToSpeech) init_mTextToSpeech();
return mTextToSpeech->state() != QTextToSpeech::BackendError;
#else
return false;
@@ -105,6 +115,7 @@ bool TextToSpeech::isReady() const
void TextToSpeech::say(const QString &text)
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
+ if(!mTextToSpeech) init_mTextToSpeech();
mTextToSpeech->say(text);
#else
Q_UNUSED(text);
@@ -114,6 +125,7 @@ void TextToSpeech::say(const QString &text)
void TextToSpeech::stop()
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
+ if(!mTextToSpeech) init_mTextToSpeech();
mTextToSpeech->stop();
#endif
}
@@ -121,6 +133,7 @@ void TextToSpeech::stop()
void TextToSpeech::pause()
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
+ if(!mTextToSpeech) init_mTextToSpeech();
mTextToSpeech->pause();
#endif
}
@@ -128,6 +141,7 @@ void TextToSpeech::pause()
void TextToSpeech::resume()
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
+ if(!mTextToSpeech) init_mTextToSpeech();
mTextToSpeech->resume();
#endif
}
@@ -135,7 +149,8 @@ void TextToSpeech::resume()
void TextToSpeech::setRate(double rate)
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
- mTextToSpeech->setRate(rate);
+ mRate=rate;
+ if(!mTextToSpeech) mTextToSpeech->setRate(rate);
#else
Q_UNUSED(rate);
#endif
@@ -144,7 +159,8 @@ void TextToSpeech::setRate(double rate)
void TextToSpeech::setPitch(double pitch)
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
- mTextToSpeech->setPitch(pitch);
+ mPitch=pitch;
+ if(mTextToSpeech) mTextToSpeech->setPitch(pitch);
#else
Q_UNUSED(pitch);
#endif
@@ -153,7 +169,8 @@ void TextToSpeech::setPitch(double pitch)
void TextToSpeech::setVolume(int volume)
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
- mTextToSpeech->setVolume(volume);
+ mVolume=volume;
+ if(mTextToSpeech) mTextToSpeech->setVolume(volume);
#else
Q_UNUSED(volume);
#endif
@@ -162,7 +179,7 @@ void TextToSpeech::setVolume(int volume)
int TextToSpeech::volume() const
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
- return mTextToSpeech->volume();
+ return mTextToSpeech ? mTextToSpeech->volume() : mVolume;
#else
return 0;
#endif
@@ -171,6 +188,7 @@ int TextToSpeech::volume() const
QVector<QLocale> TextToSpeech::availableLocales() const
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
+// if(!mTextToSpeech) init_mTextToSpeech();
return mTextToSpeech->availableLocales();
#else
return QVector<QLocale>();
@@ -181,6 +199,7 @@ QStringList TextToSpeech::availableVoices() const
{
QStringList lst;
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
+// if(!mTextToSpeech) init_mTextToSpeech();
const QVector<QVoice> voices = mTextToSpeech->availableVoices();
lst.reserve(voices.count());
for (const QVoice &voice : voices) {
@@ -193,6 +212,7 @@ QStringList TextToSpeech::availableVoices() const
QStringList TextToSpeech::availableEngines() const
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
+// if(!mTextToSpeech) init_mTextToSpeech();
return QTextToSpeech::availableEngines();
#else
return QStringList();
@@ -202,7 +222,8 @@ QStringList TextToSpeech::availableEngines() const
void TextToSpeech::setLocale(const QLocale &locale) const
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
- mTextToSpeech->setLocale(locale);
+// mLocale=locale;
+ /*if(mTextToSpeech)*/ mTextToSpeech->setLocale(locale);
#else
Q_UNUSED(locale);
#endif
@@ -211,7 +232,7 @@ void TextToSpeech::setLocale(const QLocale &locale) const
QLocale TextToSpeech::locale() const
{
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
- return mTextToSpeech->locale();
+ return mTextToSpeech ? mTextToSpeech->locale() : mLocale;
#else
return QLocale();
#endif
diff --git a/src/texttospeech/texttospeech.h b/src/texttospeech/texttospeech.h
index dd094e3..2d64609 100644
--- a/src/texttospeech/texttospeech.h
+++ b/src/texttospeech/texttospeech.h
@@ -23,6 +23,7 @@
#include "kpimtextedit_export.h"
#include "config-kpimtextedit.h"
#include <QObject>
+#include <QLocale>
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
class QTextToSpeech;
@@ -74,8 +75,13 @@ private:
friend class TextToSpeechPrivate;
#if KPIMTEXTEDIT_HAVE_TEXTTOSPEECH
+ void init_mTextToSpeech();
QString mDefaultEngine;
QTextToSpeech *mTextToSpeech = nullptr;
+ double mRate;
+ double mPitch;
+ int mVolume;
+ QLocale mLocale;
#endif
};
}