Stop speech notification if it was dismissed
This commit is contained in:
parent
e70006cf02
commit
406781534d
|
@ -1,19 +1,35 @@
|
||||||
#include "speech.h"
|
#include "speech.h"
|
||||||
|
|
||||||
#include <QtTextToSpeech/QTextToSpeech>
|
#include <QtTextToSpeech/QTextToSpeech>
|
||||||
|
|
||||||
|
#include <snore.h>
|
||||||
Speech::Speech()
|
Speech::Speech()
|
||||||
: Snore::SnoreSecondaryBackend()
|
: Snore::SnoreSecondaryBackend()
|
||||||
, m_speech(new QTextToSpeech(this))
|
, m_speech(new QTextToSpeech(this))
|
||||||
{
|
{
|
||||||
connect(m_speech, &QTextToSpeech::stateChanged, this, [this](QTextToSpeech::State state){
|
connect(m_speech, &QTextToSpeech::stateChanged, this, [this](QTextToSpeech::State state) {
|
||||||
qCDebug(SNORE) << state;
|
qCDebug(SNORE) << state;
|
||||||
if (state == QTextToSpeech::BackendError) {
|
if (state == QTextToSpeech::BackendError) {
|
||||||
setErrorString(tr("System Backend Error"));
|
setErrorString(tr("System Backend Error"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
connect(this, &Speech::enabledChanged, this, [this](bool b) {
|
||||||
|
if (b) {
|
||||||
|
connect(&Snore::SnoreCore::instance(), &Snore::SnoreCore::notificationClosed, this, &Speech::slotNotificationClosed);
|
||||||
|
} else {
|
||||||
|
disconnect(&Snore::SnoreCore::instance(), &Snore::SnoreCore::notificationClosed, this, &Speech::slotNotificationClosed);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Speech::slotNotificationDisplayed(Snore::Notification notification)
|
void Speech::slotNotificationDisplayed(Snore::Notification notification)
|
||||||
{
|
{
|
||||||
m_speech->say(tr("%1: %2 %3").arg(notification.application().name(), notification.title(), notification.text()));
|
m_speech->say(tr("%1: %2 %3").arg(notification.application().name(), notification.title(), notification.text()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Speech::slotNotificationClosed(Snore::Notification notificatiom) {
|
||||||
|
// TODO: que notifications on our side and make sure to only stop playback of the canceled notification
|
||||||
|
if (notificatiom.closeReason() != Snore::Notification::TimedOut && m_speech->state() == QTextToSpeech::Speaking) {
|
||||||
|
m_speech->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,9 @@ public:
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void slotNotificationDisplayed(Snore::Notification notification) override;
|
void slotNotificationDisplayed(Snore::Notification notification) override;
|
||||||
|
|
||||||
|
void slotNotificationClosed(Snore::Notification notificatiom);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTextToSpeech *m_speech;
|
QTextToSpeech *m_speech;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue