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 "mainwindow.hpp"
#include "ui_mainwindow.h"
#include <settings.hpp>
#include <QApplication>
#include <QMediaPlayer>
@ -24,6 +25,9 @@ void notifications::notifyNolog(QString title, QString body, QSystemTrayIcon::Me
}
void notifications::playSound(notifications::Sound soundType) {
if(!settings::settings().value("playSound", true).toBool()) return;
try {
QMediaPlayer*mediaPlayer = new QMediaPlayer(MainWindow::inst());
switch (soundType) {
@ -48,5 +52,7 @@ void notifications::playSound(notifications::Sound soundType) {
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);
}
}