blob: b1fa584e723034968c7b13c7ede3126a250511fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include "Swift/Controllers/SoundEventController.h"
#include <boost/bind.hpp>
#include "Swift/Controllers/EventController.h"
#include "Swift/Controllers/SoundPlayer.h"
#include "Swift/Controllers/UIEvents/UIEventStream.h"
#include "Swift/Controllers/UIEvents/ToggleSoundsUIEvent.h"
namespace Swift {
SoundEventController::SoundEventController(EventController* eventController, SoundPlayer* soundPlayer, SettingsProvider* settings, UIEventStream* uiEvents) {
uiEvents_ = uiEvents;
settings_ = settings;
eventController_ = eventController;
soundPlayer_ = soundPlayer;
uiEvents_->onUIEvent.connect(boost::bind(&SoundEventController::handleUIEvent, this, _1));
eventController_->onEventQueueEventAdded.connect(boost::bind(&SoundEventController::handleEventQueueEventAdded, this, _1));
bool playSounds = settings->getBoolSetting("playSounds", true);
playSounds_ = !playSounds;
setPlaySounds(playSounds);
}
void SoundEventController::handleEventQueueEventAdded(boost::shared_ptr<StanzaEvent>) {
if (playSounds_) soundPlayer_->playSound(SoundPlayer::MessageReceived);
}
void SoundEventController::setPlaySounds(bool playSounds) {
bool transmit = playSounds != playSounds_;
playSounds_ = playSounds;
settings_->storeBool("playSounds", playSounds);
if (transmit) {
uiEvents_->send(boost::shared_ptr<ToggleSoundsUIEvent>(new ToggleSoundsUIEvent(playSounds_)));
}
}
void SoundEventController::handleUIEvent(boost::shared_ptr<UIEvent> event) {
boost::shared_ptr<ToggleSoundsUIEvent> soundEvent = boost::dynamic_pointer_cast<ToggleSoundsUIEvent>(event);
if (soundEvent) {
setPlaySounds(soundEvent->getEnabled());
}
}
}
|