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,6 +1,8 @@
#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))
@ -11,9 +13,23 @@ Speech::Speech()
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();
}
}

View File

@ -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;
}; };