Flags for playlist items

This commit is contained in:
David Sansome 2009-12-29 16:12:08 +00:00
parent 14bdc4294b
commit 8957dad3bb
6 changed files with 51 additions and 17 deletions

View File

@ -31,6 +31,9 @@ class LastFMService : public RadioService {
void StartLoading(const QUrl& url);
void LoadNext(const QUrl& url);
bool IsPauseAllowed() const { return false; }
bool ShowLastFmControls() const { return true; }
void Authenticate(const QString& username, const QString& password);
signals:

View File

@ -40,10 +40,11 @@ void Player::TrackEnded() {
}
// Is this track a radio station (like Last.fm) that can have another track?
if (playlist_->item_at(i)->LoadNext())
return;
Next();
PlaylistItem* item = playlist_->item_at(i);
if (item->options() & PlaylistItem::ContainsMultipleTracks)
item->LoadNext();
else
Next();
}
void Player::PlayPause() {
@ -116,7 +117,9 @@ void Player::PlayAt(int index) {
PlaylistItem* item = playlist_->item_at(index);
if (!item->StartLoading())
if (item->options() & PlaylistItem::SpecialPlayBehaviour)
item->StartLoading();
else
engine_->play(item->Url());
}

View File

@ -20,9 +20,21 @@ class PlaylistItem {
Type_Radio,
};
enum Option {
Default = 0x00,
SpecialPlayBehaviour = 0x01,
ContainsMultipleTracks = 0x02,
PauseDisabled = 0x04,
LastFMControls = 0x08,
};
Q_DECLARE_FLAGS(Options, Option);
virtual Type type() const = 0;
QString type_string() const;
virtual Options options() const { return Default; }
virtual void Save(QSettings& settings) const = 0;
virtual void Restore(const QSettings& settings) = 0;
@ -36,15 +48,17 @@ class PlaylistItem {
// streaming the radio stream), then it should implement StartLoading() and
// return true. If it returns false then the URL from Url() will be passed
// directly to xine instead.
virtual bool StartLoading() { return false; }
virtual void StartLoading() {}
virtual QUrl Url() = 0;
// If the item is a radio station that can play another song after one has
// finished then it should do so and return true
virtual bool LoadNext() { return false; }
virtual void LoadNext() {}
virtual void SetTemporaryMetadata(const Song& metadata) {Q_UNUSED(metadata)}
virtual void ClearTemporaryMetadata() {}
};
Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::Options);
#endif // PLAYLISTITEM_H

View File

@ -58,25 +58,35 @@ int RadioPlaylistItem::Track() const {
return metadata_.is_valid() ? metadata_.track() : -1;
}
bool RadioPlaylistItem::StartLoading() {
void RadioPlaylistItem::StartLoading() {
if (service_)
service_->StartLoading(url_);
return true;
}
bool RadioPlaylistItem::LoadNext() {
if (service_) {
void RadioPlaylistItem::LoadNext() {
if (service_)
service_->LoadNext(url_);
return true;
}
return false;
}
QUrl RadioPlaylistItem::Url() {
return url_;
}
PlaylistItem::Options RadioPlaylistItem::options() const {
PlaylistItem::Options ret = SpecialPlayBehaviour;
if (service_) {
ret |= ContainsMultipleTracks;
if (!service_->IsPauseAllowed())
ret |= PauseDisabled;
if (service_->ShowLastFmControls())
ret |= LastFMControls;
}
return ret;
}
void RadioPlaylistItem::SetTemporaryMetadata(const Song& metadata) {
metadata_ = metadata;
}

View File

@ -14,6 +14,7 @@ class RadioPlaylistItem : public PlaylistItem {
RadioPlaylistItem(RadioService* service, const QUrl& url, const QString& title);
Type type() const { return Type_Radio; }
Options options() const;
void Save(QSettings& settings) const;
void Restore(const QSettings& settings);
@ -24,10 +25,10 @@ class RadioPlaylistItem : public PlaylistItem {
int Length() const;
int Track() const;
bool StartLoading();
void StartLoading();
QUrl Url();
bool LoadNext();
void LoadNext();
void SetTemporaryMetadata(const Song& metadata);
void ClearTemporaryMetadata();

View File

@ -26,6 +26,9 @@ class RadioService : public QObject {
virtual void StartLoading(const QUrl& url) = 0;
virtual void LoadNext(const QUrl& url) = 0;
virtual bool IsPauseAllowed() const { return true; }
virtual bool ShowLastFmControls() const { return false; }
signals:
void LoadingStarted();
void LoadingFinished();