From c5d1e24df9ff853e96a439e1e8e9c16c1b526102 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Tue, 14 Dec 2021 10:32:23 +0100 Subject: [PATCH] disable buttons --- include/soundbutton.h | 4 ++++ src/soundbutton.cpp | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/soundbutton.h b/include/soundbutton.h index bfcb619..d7856f6 100644 --- a/include/soundbutton.h +++ b/include/soundbutton.h @@ -32,6 +32,8 @@ public slots: void play(); private: + void setDisabled(); + static uint64_t nextid; uint64_t id; @@ -42,6 +44,8 @@ private: uint64_t lengthms = 0; // ignored when length = 0 float volume = 1.f; + bool disabled = false; + QxtGlobalShortcut* globalShortcut = nullptr; QPushButton* button = nullptr; }; \ No newline at end of file diff --git a/src/soundbutton.cpp b/src/soundbutton.cpp index 1a2a736..2d90c08 100644 --- a/src/soundbutton.cpp +++ b/src/soundbutton.cpp @@ -2,6 +2,8 @@ #include "sound.h" +#include + uint64_t SoundButton::nextid = 0; SoundButton::SoundButton(const std::string& filename, const std::string& name_, const std::string& keycombo) : id(nextid++), file(filename), keycombo(keycombo) { @@ -63,6 +65,18 @@ QPushButton* SoundButton::getButton() { } void SoundButton::play() { + if(disabled) return; + uint64_t endms = (lengthms == 0 ? 0 : startms + lengthms); - Sound::instance().addPlayback(file, volume, startms, endms); + try { + Sound::instance().addPlayback(file, volume, startms, endms); + } catch(const std::exception& e) { + Log::error << "Catched Exception when plaing Audio File: " << file; + setDisabled(); + } +} + +void SoundButton::setDisabled() { + disabled = true; + button->setText(QString::fromStdString(name + " DISABLED")); } \ No newline at end of file