2012-01-22 17:58:23 -05:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 RetroShare Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include <QSound>
|
|
|
|
|
|
|
|
#include "SoundManager.h"
|
|
|
|
#include "settings/rsharesettings.h"
|
|
|
|
|
|
|
|
#define GROUP_MAIN "Sound"
|
|
|
|
#define GROUP_ENABLE "Enable"
|
|
|
|
#define GROUP_SOUNDFILE "SoundFilePath"
|
|
|
|
|
|
|
|
SoundManager *soundManager = NULL;
|
|
|
|
|
2012-10-21 17:38:55 -04:00
|
|
|
SoundEvents::SoundEvents()
|
2012-01-22 17:58:23 -05:00
|
|
|
{
|
2012-10-21 17:38:55 -04:00
|
|
|
}
|
2012-01-22 17:58:23 -05:00
|
|
|
|
2012-10-21 17:38:55 -04:00
|
|
|
void SoundEvents::addEvent(const QString &groupName, const QString &eventName, const QString &event)
|
|
|
|
{
|
|
|
|
SoundEventInfo info;
|
|
|
|
info.mGroupName = groupName;
|
|
|
|
info.mEventName = eventName;
|
|
|
|
info.mEvent = event;
|
|
|
|
|
|
|
|
mEventInfos.push_back(info);
|
2012-01-22 17:58:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::create()
|
|
|
|
{
|
|
|
|
if (soundManager == NULL) {
|
|
|
|
soundManager = new SoundManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SoundManager::SoundManager() : QObject()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::setMute(bool mute)
|
|
|
|
{
|
|
|
|
Settings->beginGroup(GROUP_MAIN);
|
|
|
|
Settings->setValue("mute", mute);
|
|
|
|
Settings->endGroup();
|
|
|
|
|
|
|
|
emit SoundManager::mute(mute);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SoundManager::isMute()
|
|
|
|
{
|
|
|
|
Settings->beginGroup(GROUP_MAIN);
|
|
|
|
bool mute = Settings->value("mute", false).toBool();
|
|
|
|
Settings->endGroup();
|
|
|
|
|
|
|
|
return mute;
|
|
|
|
}
|
|
|
|
|
2012-10-21 17:38:55 -04:00
|
|
|
bool SoundManager::eventEnabled(const QString &event)
|
2012-01-22 17:58:23 -05:00
|
|
|
{
|
|
|
|
Settings->beginGroup(GROUP_MAIN);
|
|
|
|
Settings->beginGroup(GROUP_ENABLE);
|
2012-10-21 17:38:55 -04:00
|
|
|
bool enabled = Settings->value(event, false).toBool();
|
2012-01-22 17:58:23 -05:00
|
|
|
Settings->endGroup();
|
|
|
|
Settings->endGroup();
|
|
|
|
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
2012-10-21 17:38:55 -04:00
|
|
|
void SoundManager::setEventEnabled(const QString &event, bool enabled)
|
2012-01-22 17:58:23 -05:00
|
|
|
{
|
|
|
|
Settings->beginGroup(GROUP_MAIN);
|
|
|
|
Settings->beginGroup(GROUP_ENABLE);
|
2012-10-21 17:38:55 -04:00
|
|
|
Settings->setValue(event, enabled);
|
2012-01-22 17:58:23 -05:00
|
|
|
Settings->endGroup();
|
|
|
|
Settings->endGroup();
|
|
|
|
}
|
|
|
|
|
2012-10-21 17:38:55 -04:00
|
|
|
QString SoundManager::eventFilename(const QString &event)
|
2012-01-22 17:58:23 -05:00
|
|
|
{
|
|
|
|
Settings->beginGroup(GROUP_MAIN);
|
|
|
|
Settings->beginGroup(GROUP_SOUNDFILE);
|
2012-10-21 17:38:55 -04:00
|
|
|
QString filename = Settings->value(event).toString();
|
2012-01-22 17:58:23 -05:00
|
|
|
Settings->endGroup();
|
|
|
|
Settings->endGroup();
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2012-10-21 17:38:55 -04:00
|
|
|
void SoundManager::setEventFilename(const QString &event, const QString &filename)
|
2012-01-22 17:58:23 -05:00
|
|
|
{
|
|
|
|
Settings->beginGroup(GROUP_MAIN);
|
|
|
|
Settings->beginGroup(GROUP_SOUNDFILE);
|
2012-10-21 17:38:55 -04:00
|
|
|
Settings->setValue(event, filename);
|
2012-01-22 17:58:23 -05:00
|
|
|
Settings->endGroup();
|
|
|
|
Settings->endGroup();
|
|
|
|
}
|
|
|
|
|
2012-10-21 17:38:55 -04:00
|
|
|
void SoundManager::play(const QString &event)
|
2012-01-22 17:58:23 -05:00
|
|
|
{
|
|
|
|
if (isMute() || !QSound::isAvailable() || !eventEnabled(event)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString filename = eventFilename(event);
|
|
|
|
playFile(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundManager::playFile(const QString &filename)
|
|
|
|
{
|
|
|
|
if (filename.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QSound::play(filename);
|
|
|
|
}
|