diff --git a/KBlocksScene.cpp b/KBlocksScene.cpp --- a/KBlocksScene.cpp +++ b/KBlocksScene.cpp @@ -34,7 +34,7 @@ QString themeFile(Settings::theme()); mpGrafx = new KBlocksGraphics(themeFile); - mpSnd = new KBlocksSound(); + mpSnd = new KBlocksSound(themeFile); int width = (capacity >= mSceneGamesPerLine) ? mSceneGamesPerLine : (capacity % mSceneGamesPerLine); int height = (int)(capacity / (mSceneGamesPerLine + 1)) + 1; diff --git a/KBlocksSound.h b/KBlocksSound.h --- a/KBlocksSound.h +++ b/KBlocksSound.h @@ -11,6 +11,9 @@ #ifndef KBLOCKSSOUND_H #define KBLOCKSSOUND_H +#define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API +#include + class KgSound; enum class Sound { @@ -22,18 +25,23 @@ class KBlocksSound { public: - KBlocksSound(); + KBlocksSound(const QString &themeFile); ~KBlocksSound(); public: void setSoundsEnabled(bool p_enabled); void playSound(Sound soundType); + KGameTheme *theme() + { + return m_theme; + } private: KgSound *m_blockFallSound = nullptr; KgSound *m_blockMoveSound = nullptr; KgSound *m_blockRemoveSound = nullptr; bool sndActive; + KGameTheme *m_theme; }; diff --git a/KBlocksSound.cpp b/KBlocksSound.cpp --- a/KBlocksSound.cpp +++ b/KBlocksSound.cpp @@ -19,19 +19,51 @@ #include "kblocks_sound_debug.h" #include "settings.h" -KBlocksSound::KBlocksSound() +KBlocksSound::KBlocksSound(const QString &themeFile) { - m_blockFallSound = new KgSound(QStandardPaths::locate( - QStandardPaths::AppDataLocation, QStringLiteral("sounds/block-fall.ogg"))); - m_blockMoveSound = new KgSound(QStandardPaths::locate( - QStandardPaths::AppDataLocation, QStringLiteral("sounds/block-move.ogg"))); - m_blockRemoveSound = new KgSound(QStandardPaths::locate( - QStandardPaths::AppDataLocation, QStringLiteral("sounds/block-remove.ogg"))); - setSoundsEnabled(Settings::sounds()); + m_theme = new KGameTheme(); + if (!m_theme->load(themeFile)) { + qCWarning(KBSound) << "Error loading KBlocks .desktop theme" + << themeFile << endl; + m_theme->loadDefault(); + } + + QString m_themeMoveSound ; + if (m_theme->themeProperty("Sound_Block_Move") != "") { + m_themeMoveSound = m_theme->prefix() + m_theme->themeProperty("Sound_Block_Move"); + } else { + m_themeMoveSound = QStandardPaths::locate( + QStandardPaths::AppDataLocation, QStringLiteral("sounds/block-move.ogg")); + } + + QString m_themeFallSound ; + if (m_theme->themeProperty("Sound_Block_Fall") != "") { + m_themeFallSound = m_theme->prefix() + m_theme->themeProperty("Sound_Block_Fall"); + } else { + m_themeFallSound = QStandardPaths::locate( + QStandardPaths::AppDataLocation, QStringLiteral("sounds/block-fall.ogg")); + } + + QString m_themeRemoveSound ; + if (m_theme->themeProperty("Sound_Block_Remove") != "") { + m_themeRemoveSound = m_theme->prefix() + m_theme->themeProperty("Sound_Block_Remove"); + } else { + m_themeRemoveSound = QStandardPaths::locate( + QStandardPaths::AppDataLocation, QStringLiteral("sounds/block-remove.ogg")); + } + + qCWarning(KBSound) << "Fall sound : " << m_themeFallSound << endl; + qCWarning(KBSound) << "Move sound : " << m_themeMoveSound << endl; + qCWarning(KBSound) << "Remove sound : " << m_themeRemoveSound << endl; + + m_blockFallSound = new KgSound(m_themeFallSound); + m_blockMoveSound = new KgSound(m_themeMoveSound); + m_blockRemoveSound = new KgSound(m_themeRemoveSound); } KBlocksSound::~KBlocksSound() { + delete m_theme; delete m_blockFallSound; delete m_blockMoveSound; delete m_blockRemoveSound;