1 /***************************************************************************
2 * KBlocks, a falling blocks game for KDE *
3 * Copyright (C) 20078 Mauricio Piacentini <piacentini@kde.org> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
10 //Uses routines from Kapman sound manager (game.cpp)
12 #include "kblockssound.h"
14 #include <KStandardDirs>
21 KBlocksSound::KBlocksSound ( const QString
& themeFile
)
25 m_theme
= new KGameTheme();
26 if (!m_theme
->load(themeFile
)) {
27 kDebug(11000) << "Error loading KBlocks .desktop theme" << themeFile
<< endl
;
28 m_theme
->loadDefault();
32 setSoundsEnabled(Settings::sounds());
35 KBlocksSound::~KBlocksSound()
42 bool KBlocksSound::loadTheme ( const QString
& themeFile
)
44 if (!m_theme
->load(themeFile
)) {
45 kDebug(11000) << "Error loading KBlocks .desktop theme" << themeFile
<< endl
;
53 void KBlocksSound::readThemeValues()
55 //Extract sound directory info
56 //This functionality should be exposed by KGameTheme
57 QFile
themefile(m_theme
->path());
58 sndDirectory
= QFileInfo(themefile
).absolutePath() + '/';
62 void KBlocksSound::setSoundsEnabled(bool p_enabled
) {
63 sndActive
= p_enabled
;
66 m_media1
= Phonon::createPlayer(Phonon::GameCategory
);
69 m_media2
= Phonon::createPlayer(Phonon::GameCategory
);
79 void KBlocksSound::playSound(const QString
& p_soundkey
) {
80 Phonon::MediaObject
* m_usedMedia
;
81 QString p_sound
= sndDirectory
+m_theme
->themeProperty(p_soundkey
);
84 // Choose the media object with the smallest remaining time
85 if (m_media1
->remainingTime() <= m_media2
->remainingTime()) {
86 m_usedMedia
= m_media1
;
88 m_usedMedia
= m_media2
;
90 m_usedMedia
->setCurrentSource(p_sound
);