added a volume option to the sound backend. stop sound when notification timed out

This commit is contained in:
Patrick von Reth 2015-04-10 10:06:16 +02:00
parent a7f5181aaf
commit 2cb4f41964
4 changed files with 24 additions and 10 deletions

View File

@ -19,6 +19,7 @@
#include "soundsettings.h"
#include <QtMultimedia/QMediaPlayer>
#include <QTimer>
using namespace Snore;
@ -26,7 +27,8 @@ Sound::Sound():
SnoreSecondaryBackend("Sound", false),
m_player(new QMediaPlayer(this))
{
m_player->setVolume(50);
setDefaultValue("Volume",50);
m_player->setVolume(value("Volume").toInt());
// connect(m_player,QMediaPlayer::positionChanged,[](qint64 pos){
// snoreDebug(SNORE_DEBUG) << "Player: " << pos;
// });
@ -60,6 +62,12 @@ void Sound::slotNotify(Snore::Notification notification)
m_player->setMedia(QUrl::fromLocalFile(sound));
snoreDebug(SNORE_DEBUG) << "SoundFile:" << m_player->media().canonicalUrl();
m_player->play();
QTimer *timeout = new QTimer(this);
timeout->setSingleShot(true);
timeout->setInterval(notification.timeout() * 1000);
connect(timeout, &QTimer::timeout, [&m_player,timeout]{
m_player->stop();
timeout->deleteLater();
});
}
}

View File

@ -33,7 +33,6 @@ public:
public slots:
void slotNotify(Snore::Notification notification) override;
private:
class QMediaPlayer *m_player;
};

View File

@ -20,23 +20,26 @@
#include <QFileDialog>
#include <QLineEdit>
#include <QSpinBox>
#include <QPushButton>
using namespace Snore;
SoundSettings::SoundSettings(SnorePlugin *snorePlugin, QWidget *parent) :
PluginSettingsWidget(snorePlugin, parent),
m_lineEdit(new QLineEdit)
m_lineEditFileName(new QLineEdit),
m_spinBoxVolume(new QSpinBox)
{
addRow(tr("Audio file:"), m_lineEdit);
addRow(tr("Volume:"), m_spinBoxVolume);
addRow(tr("Audio file:"), m_lineEditFileName);
QPushButton *button = new QPushButton(tr("Select a audio file"));
connect(button, &QPushButton::clicked, [this]() {
QFileDialog dialog;
dialog.setNameFilter(tr("All Audio files").append("(*.mp3 *.wav *.ogg)"));
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setDirectory(m_lineEdit->text());
dialog.setDirectory(m_lineEditFileName->text());
if (dialog.exec()) {
m_lineEdit->setText(dialog.selectedFiles().first());
m_lineEditFileName->setText(dialog.selectedFiles().first());
}
});
addRow("", button);
@ -48,11 +51,13 @@ SoundSettings::~SoundSettings()
void SoundSettings::load()
{
m_lineEdit->setText(value("Sound").toString());
m_lineEditFileName->setText(value("Sound").toString());
m_spinBoxVolume->setValue(value("Volume").toInt());
}
void SoundSettings::save()
{
setValue("Sound", m_lineEdit->text());
setValue("Sound", m_lineEditFileName->text());
setValue("Volume", m_spinBoxVolume->value());
}

View File

@ -5,6 +5,7 @@
#include "plugins/pluginsettingswidget.h"
class QLineEdit;
class QSpinBox;
class SoundSettings : public Snore::PluginSettingsWidget
{
Q_OBJECT
@ -17,7 +18,8 @@ public:
void save() override;
private:
QLineEdit *m_lineEdit;
QLineEdit *m_lineEditFileName;
QSpinBox *m_spinBoxVolume;
};