97
104
stream->id = engine_->AddBackgroundStream(stream->url);
98
105
engine_->SetBackgroundStreamVolume(stream->id, stream->volume);
99
106
emit StreamStarted(stream->name);
108
if (stream->action) {
109
stream->action->setChecked(true);
102
113
void BackgroundStreams::StopStream(Stream* stream) {
103
114
engine_->StopBackgroundStream(stream->id);
105
116
emit StreamStopped(stream->name);
118
if (stream->action) {
119
stream->action->setChecked(false);
108
int BackgroundStreams::GetStreamVolume(const QString& name) {
123
int BackgroundStreams::GetStreamVolume(const QString& name) const {
109
124
return streams_[name]->volume;
112
bool BackgroundStreams::IsPlaying(const QString& name) {
127
bool BackgroundStreams::IsPlaying(const QString& name) const {
113
128
return streams_[name]->id != -1;
116
void BackgroundStreams::MakeItRain(bool enable) {
117
if (!streams_.contains("Rain")) {
118
AddStream("Rain", QUrl(kRainUrl));
120
EnableStream("Rain", enable);
123
void BackgroundStreams::AllGloryToTheHypnotoad(bool enable) {
124
if (!streams_.contains("Hypnotoad")) {
125
AddStream("Hypnotoad", QUrl(kHypnotoadUrl));
127
EnableStream("Hypnotoad", enable);
131
void BackgroundStreams::AddAction(const QString& name, QAction* action) {
132
if (!streams_.contains(name)) {
133
qLog(Error) << "Tried to add action for stream" << name << "which doesn't exist";
137
Stream* stream = streams_[name];
138
if (stream->action) {
139
qLog(Error) << "Tried to add multiple actions for stream" << name;
143
stream->action = action;
144
action->setChecked(IsPlaying(name));
145
connect(action, SIGNAL(toggled(bool)), SLOT(StreamActionToggled(bool)));
146
connect(action, SIGNAL(destroyed()), SLOT(StreamActionDestroyed()));
149
void BackgroundStreams::StreamActionDestroyed() {
150
QAction* action = static_cast<QAction*>(sender());
155
foreach (Stream* stream, streams_.values()) {
156
if (stream->action == action) {
157
stream->action = NULL;
162
void BackgroundStreams::StreamActionToggled(bool checked) {
163
QAction* action = static_cast<QAction*>(sender());
168
foreach (Stream* stream, streams_.values()) {
169
if (stream->action == action) {
170
EnableStream(stream->name, checked);