~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/core/backgroundstreams.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "backgroundstreams.h"
2
2
 
 
3
#include <QAction>
3
4
#include <QSettings>
4
5
#include <QtDebug>
5
6
 
 
7
#include "core/logging.h"
6
8
#include "engines/enginebase.h"
7
9
 
8
10
const char* BackgroundStreams::kSettingsGroup = "BackgroundStreams";
74
76
}
75
77
 
76
78
void BackgroundStreams::EnableStream(const QString& name, bool enable) {
 
79
  if (!streams_.contains(name)) {
 
80
    qLog(Warning) << "Tried to toggle a stream" << name << "which didn't exist";
 
81
    return;
 
82
  }
 
83
 
77
84
  Stream* stream = streams_[name];
78
85
  if (enable == (stream->id != -1)) {
79
86
    return;
97
104
  stream->id = engine_->AddBackgroundStream(stream->url);
98
105
  engine_->SetBackgroundStreamVolume(stream->id, stream->volume);
99
106
  emit StreamStarted(stream->name);
 
107
 
 
108
  if (stream->action) {
 
109
    stream->action->setChecked(true);
 
110
  }
100
111
}
101
112
 
102
113
void BackgroundStreams::StopStream(Stream* stream) {
103
114
  engine_->StopBackgroundStream(stream->id);
104
115
  stream->id = -1;
105
116
  emit StreamStopped(stream->name);
 
117
 
 
118
  if (stream->action) {
 
119
    stream->action->setChecked(false);
 
120
  }
106
121
}
107
122
 
108
 
int BackgroundStreams::GetStreamVolume(const QString& name) {
 
123
int BackgroundStreams::GetStreamVolume(const QString& name) const {
109
124
  return streams_[name]->volume;
110
125
}
111
126
 
112
 
bool BackgroundStreams::IsPlaying(const QString& name) {
 
127
bool BackgroundStreams::IsPlaying(const QString& name) const {
113
128
  return streams_[name]->id != -1;
114
129
}
115
130
 
116
 
void BackgroundStreams::MakeItRain(bool enable) {
117
 
  if (!streams_.contains("Rain")) {
118
 
    AddStream("Rain", QUrl(kRainUrl));
119
 
  }
120
 
  EnableStream("Rain", enable);
121
 
}
122
 
 
123
 
void BackgroundStreams::AllGloryToTheHypnotoad(bool enable) {
124
 
  if (!streams_.contains("Hypnotoad")) {
125
 
    AddStream("Hypnotoad", QUrl(kHypnotoadUrl));
126
 
  }
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";
 
134
    return;
 
135
  }
 
136
 
 
137
  Stream* stream = streams_[name];
 
138
  if (stream->action) {
 
139
    qLog(Error) << "Tried to add multiple actions for stream" << name;
 
140
    return;
 
141
  }
 
142
 
 
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()));
 
147
}
 
148
 
 
149
void BackgroundStreams::StreamActionDestroyed() {
 
150
  QAction* action = static_cast<QAction*>(sender());
 
151
  if (!action) {
 
152
    return;
 
153
  }
 
154
 
 
155
  foreach (Stream* stream, streams_.values()) {
 
156
    if (stream->action == action) {
 
157
      stream->action = NULL;
 
158
    }
 
159
  }
 
160
}
 
161
 
 
162
void BackgroundStreams::StreamActionToggled(bool checked) {
 
163
  QAction* action = static_cast<QAction*>(sender());
 
164
  if (!action) {
 
165
    return;
 
166
  }
 
167
 
 
168
  foreach (Stream* stream, streams_.values()) {
 
169
    if (stream->action == action) {
 
170
      EnableStream(stream->name, checked);
 
171
    }
 
172
  }
128
173
}