added try-for sound and disable via sound

This commit is contained in:
Niklas 2020-02-15 20:34:21 +01:00
parent 523271a890
commit e94a0d67cb

View File

@ -3,6 +3,7 @@
#include "systemnotification.h" #include "systemnotification.h"
#include "mainwindow.hpp" #include "mainwindow.hpp"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <settings.hpp>
#include <QApplication> #include <QApplication>
#include <QMediaPlayer> #include <QMediaPlayer>
@ -24,29 +25,34 @@ void notifications::notifyNolog(QString title, QString body, QSystemTrayIcon::Me
} }
void notifications::playSound(notifications::Sound soundType) { void notifications::playSound(notifications::Sound soundType) {
QMediaPlayer*mediaPlayer = new QMediaPlayer(MainWindow::inst()); if(!settings::settings().value("playSound", true).toBool()) return;
switch (soundType) { try {
case notifications::Sound::CAPTURE: QMediaPlayer*mediaPlayer = new QMediaPlayer(MainWindow::inst());
mediaPlayer->setMedia(QUrl("qrc:/capturesound.wav"));
break;
case notifications::Sound::SUCCESS: switch (soundType) {
mediaPlayer->setMedia(QUrl("qrc:/successsound.wav")); case notifications::Sound::CAPTURE:
break; mediaPlayer->setMedia(QUrl("qrc:/capturesound.wav"));
break;
case notifications::Sound::ERROR: case notifications::Sound::SUCCESS:
mediaPlayer->setMedia(QUrl("qrc:/errorsound.wav")); mediaPlayer->setMedia(QUrl("qrc:/successsound.wav"));
break; break;
default: case notifications::Sound::ERROR:
break; mediaPlayer->setMedia(QUrl("qrc:/errorsound.wav"));
break;
default:
break;
}
mediaPlayer->setVolume(25);
mediaPlayer->play();
if(mediaPlayer->error() != QMediaPlayer::NoError && mediaPlayer->error() != QMediaPlayer::ServiceMissingError)
notifications::notify(QString::number(mediaPlayer->error()), mediaPlayer->errorString(), QSystemTrayIcon::Warning);
} catch (...) {
notifications::notifyNolog(QObject::tr("KShare: No sound driver"), "No sound driver found. Install libqt5multimedia5-plugins for notifcation sound support.", QSystemTrayIcon::Warning);
} }
mediaPlayer->setVolume(25);
mediaPlayer->play();
if(mediaPlayer->error() != QMediaPlayer::NoError && mediaPlayer->error() != QMediaPlayer::ServiceMissingError)
notifications::notify(QString::number(mediaPlayer->error()), mediaPlayer->errorString(), QSystemTrayIcon::Warning);
} }