Stop speech notification if it was dismissed

This commit is contained in:
Hannah von Reth 2017-01-24 12:13:58 +01:00
parent e70006cf02
commit 406781534d
2 changed files with 20 additions and 1 deletions

View File

@ -1,19 +1,35 @@
#include "speech.h"
#include <QtTextToSpeech/QTextToSpeech>
#include <snore.h>
Speech::Speech()
: Snore::SnoreSecondaryBackend()
, 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;
if (state == QTextToSpeech::BackendError) {
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)
{
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();
}
}

View File

@ -16,6 +16,9 @@ public:
public Q_SLOTS:
void slotNotificationDisplayed(Snore::Notification notification) override;
void slotNotificationClosed(Snore::Notification notificatiom);
private:
QTextToSpeech *m_speech;
};