From 8957dad3bba7e1683f9040af04b1bfe84ef1facf Mon Sep 17 00:00:00 2001 From: David Sansome Date: Tue, 29 Dec 2009 16:12:08 +0000 Subject: [PATCH] Flags for playlist items --- src/lastfmservice.h | 3 +++ src/player.cpp | 13 ++++++++----- src/playlistitem.h | 18 ++++++++++++++++-- src/radioplaylistitem.cpp | 26 ++++++++++++++++++-------- src/radioplaylistitem.h | 5 +++-- src/radioservice.h | 3 +++ 6 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/lastfmservice.h b/src/lastfmservice.h index f48887c89..69f112c56 100644 --- a/src/lastfmservice.h +++ b/src/lastfmservice.h @@ -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: diff --git a/src/player.cpp b/src/player.cpp index b00885fbd..354c2c4c3 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -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()); } diff --git a/src/playlistitem.h b/src/playlistitem.h index 96a96cc99..bd045daf5 100644 --- a/src/playlistitem.h +++ b/src/playlistitem.h @@ -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 diff --git a/src/radioplaylistitem.cpp b/src/radioplaylistitem.cpp index 3f2f9e0ec..ac99a4e15 100644 --- a/src/radioplaylistitem.cpp +++ b/src/radioplaylistitem.cpp @@ -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; } diff --git a/src/radioplaylistitem.h b/src/radioplaylistitem.h index 4a9c8205d..ad40b3568 100644 --- a/src/radioplaylistitem.h +++ b/src/radioplaylistitem.h @@ -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(); diff --git a/src/radioservice.h b/src/radioservice.h index aa2d3a60c..82fea96c2 100644 --- a/src/radioservice.h +++ b/src/radioservice.h @@ -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();