From f816a47ad9a8949fd70136611289b3642edc6a43 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Fri, 24 Jan 2014 23:54:38 +1100 Subject: [PATCH] Make SongLoader add URLs as raw streams if there exists a URL handler for that scheme. This fixes a bug where sky:// URLs couldn't be added with MPRIS. --- src/core/player.cpp | 2 +- src/core/songloader.cpp | 19 ++++++++++++------- src/core/songloader.h | 5 ++++- src/playlist/playlist.cpp | 7 +++++-- src/playlist/playlistbackend.h | 2 ++ src/playlist/playlistmanager.cpp | 2 +- src/playlist/songloaderinserter.cpp | 12 +++++++----- src/playlist/songloaderinserter.h | 6 +++++- tests/songloader_test.cpp | 2 +- 9 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/core/player.cpp b/src/core/player.cpp index 4cdf33f18..b8695eb3b 100644 --- a/src/core/player.cpp +++ b/src/core/player.cpp @@ -69,7 +69,7 @@ void Player::Init() { connect(engine_.get(), SIGNAL(TrackAboutToEnd()), SLOT(TrackAboutToEnd())); connect(engine_.get(), SIGNAL(TrackEnded()), SLOT(TrackEnded())); connect(engine_.get(), SIGNAL(MetaData(Engine::SimpleMetaBundle)), - SLOT(EngineMetadataReceived(Engine::SimpleMetaBundle))); + SLOT(EngineMetadataReceived(Engine::SimpleMetaBundle))); engine_->SetVolume(settings_.value("volume", 50).toInt()); diff --git a/src/core/songloader.cpp b/src/core/songloader.cpp index 77ddd227d..34a50b7f9 100644 --- a/src/core/songloader.cpp +++ b/src/core/songloader.cpp @@ -33,16 +33,17 @@ #include "config.h" #include "core/concurrentrun.h" #include "core/logging.h" -#include "core/song.h" +#include "core/player.h" #include "core/signalchecker.h" +#include "core/song.h" #include "core/tagreaderclient.h" #include "core/timeconstants.h" #include "internet/fixlastfm.h" #include "internet/internetmodel.h" #include "library/librarybackend.h" #include "library/sqlrow.h" -#include "playlistparsers/parserbase.h" #include "playlistparsers/cueparser.h" +#include "playlistparsers/parserbase.h" #include "playlistparsers/playlistparser.h" #include "podcasts/podcastparser.h" #include "podcasts/podcastservice.h" @@ -52,7 +53,9 @@ QSet SongLoader::sRawUriSchemes; const int SongLoader::kDefaultTimeout = 5000; -SongLoader::SongLoader(LibraryBackendInterface* library, QObject *parent) +SongLoader::SongLoader(LibraryBackendInterface* library, + const Player* player, + QObject *parent) : QObject(parent), timeout_timer_(new QTimer(this)), playlist_parser_(new PlaylistParser(library, this)), @@ -63,7 +66,8 @@ SongLoader::SongLoader(LibraryBackendInterface* library, QObject *parent) success_(false), parser_(NULL), is_podcast_(false), - library_(library) + library_(library), + player_(player) { if (sRawUriSchemes.isEmpty()) { sRawUriSchemes << "udp" << "mms" << "mmsh" << "mmst" << "mmsu" << "rtsp" @@ -91,9 +95,10 @@ SongLoader::Result SongLoader::Load(const QUrl& url) { return LoadLocal(url_.toLocalFile()); } - if (sRawUriSchemes.contains(url_.scheme())) { - // The URI scheme indicates that it can't possibly be a playlist, so add - // it as a raw stream. + if (sRawUriSchemes.contains(url_.scheme()) || + player_->HandlerForUrl(url) != nullptr) { + // The URI scheme indicates that it can't possibly be a playlist, or we have + // a custom handler for the URL, so add it as a raw stream. AddAsRawStream(); return Success; } diff --git a/src/core/songloader.h b/src/core/songloader.h index 806e0378a..4f335eb31 100644 --- a/src/core/songloader.h +++ b/src/core/songloader.h @@ -33,13 +33,15 @@ class CueParser; class LibraryBackendInterface; class ParserBase; +class Player; class PlaylistParser; class PodcastParser; class SongLoader : public QObject { Q_OBJECT public: - SongLoader(LibraryBackendInterface* library, QObject* parent = 0); + SongLoader(LibraryBackendInterface* library, const Player* player, + QObject* parent = 0); ~SongLoader(); enum Result { @@ -130,6 +132,7 @@ private: bool is_podcast_; QByteArray buffer_; LibraryBackendInterface* library_; + const Player* player_; boost::shared_ptr pipeline_; diff --git a/src/playlist/playlist.cpp b/src/playlist/playlist.cpp index ea07cca42..45c6673f8 100644 --- a/src/playlist/playlist.cpp +++ b/src/playlist/playlist.cpp @@ -25,6 +25,7 @@ #include "songloaderinserter.h" #include "songmimedata.h" #include "songplaylistitem.h" +#include "core/application.h" #include "core/closure.h" #include "core/logging.h" #include "core/modelfuturewatcher.h" @@ -761,7 +762,8 @@ bool Playlist::dropMimeData(const QMimeData* data, Qt::DropAction action, int ro } } } else if (data->hasFormat(kCddaMimeType)) { - SongLoaderInserter* inserter = new SongLoaderInserter(task_manager_, library_); + SongLoaderInserter* inserter = new SongLoaderInserter( + task_manager_, library_, backend_->app()->player()); connect(inserter, SIGNAL(Error(QString)), SIGNAL(LoadTracksError(QString))); inserter->LoadAudioCD(this, row, play_now, enqueue_now); } else if (data->hasUrls()) { @@ -773,7 +775,8 @@ bool Playlist::dropMimeData(const QMimeData* data, Qt::DropAction action, int ro } void Playlist::InsertUrls(const QList &urls, int pos, bool play_now, bool enqueue) { - SongLoaderInserter* inserter = new SongLoaderInserter(task_manager_, library_); + SongLoaderInserter* inserter = new SongLoaderInserter( + task_manager_, library_, backend_->app()->player()); connect(inserter, SIGNAL(Error(QString)), SIGNAL(LoadTracksError(QString))); inserter->Load(this, pos, play_now, enqueue, urls); diff --git a/src/playlist/playlistbackend.h b/src/playlist/playlistbackend.h index d9c4a071c..c908a3a84 100644 --- a/src/playlist/playlistbackend.h +++ b/src/playlist/playlistbackend.h @@ -78,6 +78,8 @@ class PlaylistBackend : public QObject { void FavoritePlaylist(int id, bool is_favorite); void RemovePlaylist(int id); + Application* app() const { return app_; } + public slots: void SavePlaylist(int playlist, const PlaylistItemList& items, int last_played, smart_playlists::GeneratorPtr dynamic); diff --git a/src/playlist/playlistmanager.cpp b/src/playlist/playlistmanager.cpp index 0e8d38337..454b35add 100644 --- a/src/playlist/playlistmanager.cpp +++ b/src/playlist/playlistmanager.cpp @@ -156,7 +156,7 @@ void PlaylistManager::New(const QString& name, const SongList& songs, void PlaylistManager::Load(const QString& filename) { QUrl url = QUrl::fromLocalFile(filename); - SongLoader* loader = new SongLoader(library_backend_, this); + SongLoader* loader = new SongLoader(library_backend_, app_->player(), this); connect(loader, SIGNAL(LoadFinished(bool)), SLOT(LoadFinished(bool))); SongLoader::Result result = loader->Load(url); QFileInfo info(filename); diff --git a/src/playlist/songloaderinserter.cpp b/src/playlist/songloaderinserter.cpp index a2c7d5352..2a22738ec 100644 --- a/src/playlist/songloaderinserter.cpp +++ b/src/playlist/songloaderinserter.cpp @@ -23,8 +23,9 @@ #include "core/songloader.h" #include "core/taskmanager.h" -SongLoaderInserter::SongLoaderInserter( - TaskManager* task_manager, LibraryBackendInterface* library) +SongLoaderInserter::SongLoaderInserter(TaskManager* task_manager, + LibraryBackendInterface* library, + const Player* player) : task_manager_(task_manager), destination_(NULL), row_(-1), @@ -32,7 +33,8 @@ SongLoaderInserter::SongLoaderInserter( enqueue_(false), async_load_id_(0), async_progress_(0), - library_(library) { + library_(library), + player_(player) { } SongLoaderInserter::~SongLoaderInserter() { @@ -53,7 +55,7 @@ void SongLoaderInserter::Load(Playlist *destination, destination, SLOT(UpdateItems(const SongList&))); foreach (const QUrl& url, urls) { - SongLoader* loader = new SongLoader(library_, this); + SongLoader* loader = new SongLoader(library_, player_, this); // we're connecting this before we're even sure if this is an async load // to avoid race conditions (signal emission before we're listening to it) @@ -92,7 +94,7 @@ void SongLoaderInserter::LoadAudioCD(Playlist *destination, play_now_ = play_now; enqueue_ = enqueue; - SongLoader *loader = new SongLoader(library_, this); + SongLoader* loader = new SongLoader(library_, player_, this); connect(loader, SIGNAL(LoadFinished(bool)), SLOT(AudioCDTagsLoaded(bool))); qLog(Info) << "Loading audio CD..."; SongLoader::Result ret = loader->LoadAudioCD(); diff --git a/src/playlist/songloaderinserter.h b/src/playlist/songloaderinserter.h index 50353e7d8..01f6e8c9a 100644 --- a/src/playlist/songloaderinserter.h +++ b/src/playlist/songloaderinserter.h @@ -25,6 +25,7 @@ #include "core/song.h" class LibraryBackendInterface; +class Player; class Playlist; class SongLoader; class TaskManager; @@ -34,7 +35,9 @@ class QModelIndex; class SongLoaderInserter : public QObject { Q_OBJECT public: - SongLoaderInserter(TaskManager* task_manager, LibraryBackendInterface* library); + SongLoaderInserter(TaskManager* task_manager, + LibraryBackendInterface* library, + const Player* player); ~SongLoaderInserter(); void Load(Playlist* destination, int row, bool play_now, bool enqueue, @@ -70,6 +73,7 @@ private: int async_load_id_; int async_progress_; LibraryBackendInterface* library_; + const Player* player_; }; #endif // SONGLOADERINSERTER_H diff --git a/tests/songloader_test.cpp b/tests/songloader_test.cpp index 44913376b..dbbff390b 100644 --- a/tests/songloader_test.cpp +++ b/tests/songloader_test.cpp @@ -51,7 +51,7 @@ public: protected: void SetUp() { library_.reset(new MockLibraryBackend); - loader_.reset(new SongLoader(library_.get())); + loader_.reset(new SongLoader(library_.get(), nullptr)); loader_->set_timeout(20000); // the thing we return is not really important