diff --git a/src/playlist/playlistmanager.cpp b/src/playlist/playlistmanager.cpp index a32174455..6e9b4f03d 100644 --- a/src/playlist/playlistmanager.cpp +++ b/src/playlist/playlistmanager.cpp @@ -100,6 +100,8 @@ void PlaylistManager::Init(SharedPtr collection_backend, Shar QObject::connect(&*collection_backend_, &CollectionBackend::SongsStatisticsChanged, this, &PlaylistManager::UpdateCollectionSongs); QObject::connect(&*collection_backend_, &CollectionBackend::SongsRatingChanged, this, &PlaylistManager::UpdateCollectionSongs); + QObject::connect(parser_, &PlaylistParser::Error, this, &PlaylistManager::Error); + for (const PlaylistBackend::Playlist &p : playlist_backend->GetAllOpenPlaylists()) { ++playlists_loading_; Playlist *ret = AddPlaylist(p.id, p.name, p.special_type, p.ui_path, p.favorite); diff --git a/src/playlistparsers/cueparser.cpp b/src/playlistparsers/cueparser.cpp index f968cc95b..e9589c57b 100644 --- a/src/playlistparsers/cueparser.cpp +++ b/src/playlistparsers/cueparser.cpp @@ -394,6 +394,8 @@ void CueParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, Q_UNUSED(dir); Q_UNUSED(path_type); + emit Error(tr("Saving CUE files is not supported.")); + // TODO } diff --git a/src/playlistparsers/parserbase.cpp b/src/playlistparsers/parserbase.cpp index 29f89381e..70636116d 100644 --- a/src/playlistparsers/parserbase.cpp +++ b/src/playlistparsers/parserbase.cpp @@ -59,6 +59,7 @@ void ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning } else { qLog(Error) << "Don't know how to handle" << url; + emit Error(tr("Don't know how to handle %1").arg(filename_or_url)); return; } } diff --git a/src/playlistparsers/parserbase.h b/src/playlistparsers/parserbase.h index e121f9d72..3ab8dd5e6 100644 --- a/src/playlistparsers/parserbase.h +++ b/src/playlistparsers/parserbase.h @@ -61,6 +61,9 @@ class ParserBase : public QObject { virtual SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const = 0; virtual void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const = 0; + signals: + void Error(const QString &error) const; + protected: // Loads a song. If filename_or_url is a URL (with a scheme other than "file") then it is set on the song and the song marked as a stream. // Also sets the song's metadata by searching in the Collection, or loading from the file as a fallback. diff --git a/src/playlistparsers/playlistparser.cpp b/src/playlistparsers/playlistparser.cpp index e97ed9e10..ea640ae38 100644 --- a/src/playlistparsers/playlistparser.cpp +++ b/src/playlistparsers/playlistparser.cpp @@ -44,16 +44,26 @@ const int PlaylistParser::kMagicSize = 512; -PlaylistParser::PlaylistParser(SharedPtr collection_backend, QObject *parent) : QObject(parent) { +PlaylistParser::PlaylistParser(SharedPtr collection_backend, QObject *parent) : QObject(parent), default_parser_(nullptr) { - default_parser_ = new XSPFParser(collection_backend, this); - parsers_ << default_parser_; - parsers_ << new M3UParser(collection_backend, this); - parsers_ << new PLSParser(collection_backend, this); - parsers_ << new ASXParser(collection_backend, this); - parsers_ << new AsxIniParser(collection_backend, this); - parsers_ << new CueParser(collection_backend, this); - parsers_ << new WplParser(collection_backend, this); + AddParser(new XSPFParser(collection_backend, this)); + AddParser(new M3UParser(collection_backend, this)); + AddParser(new PLSParser(collection_backend, this)); + AddParser(new ASXParser(collection_backend, this)); + AddParser(new AsxIniParser(collection_backend, this)); + AddParser(new CueParser(collection_backend, this)); + AddParser(new WplParser(collection_backend, this)); + +} + +void PlaylistParser::AddParser(ParserBase *parser) { + + if (!default_parser_) { + default_parser_ = parser; + } + + parsers_ << parser; + QObject::connect(parser, &ParserBase::Error, this, &PlaylistParser::Error); } @@ -171,7 +181,8 @@ SongList PlaylistParser::LoadFromFile(const QString &filename) const { // Find a parser that supports this file extension ParserBase *parser = ParserForExtension(Type::Load, fileinfo.suffix()); if (!parser) { - qLog(Warning) << "Unknown filetype:" << filename; + qLog(Error) << "Unknown filetype:" << filename; + emit Error(tr("Unknown filetype: %1").arg(filename)); return SongList(); } @@ -204,14 +215,16 @@ void PlaylistParser::Save(const SongList &songs, const QString &filename, const QDir dir(fileinfo.path()); if (!dir.exists()) { - qLog(Warning) << "Directory does not exist" << dir.path(); + qLog(Error) << "Directory" << dir.path() << "does not exist"; + emit Error(tr("Directory %1 does not exist.").arg(dir.path())); return; } // Find a parser that supports this file extension ParserBase *parser = ParserForExtension(Type::Save, fileinfo.suffix()); if (!parser) { - qLog(Warning) << "Unknown filetype" << filename; + qLog(Error) << "Unknown filetype" << filename; + emit Error(tr("Unknown filetype: %1").arg(filename)); return; } @@ -225,7 +238,8 @@ void PlaylistParser::Save(const SongList &songs, const QString &filename, const // Open the file QFile file(fileinfo.absoluteFilePath()); if (!file.open(QIODevice::WriteOnly)) { - qLog(Warning) << "Failed to open" << filename << "for writing."; + qLog(Error) << "Failed to open" << filename << "for writing."; + emit Error(tr("Failed to open %1 for writing.").arg(filename)); return; } diff --git a/src/playlistparsers/playlistparser.h b/src/playlistparsers/playlistparser.h index f31bc8eec..24531545d 100644 --- a/src/playlistparsers/playlistparser.h +++ b/src/playlistparsers/playlistparser.h @@ -67,7 +67,11 @@ class PlaylistParser : public QObject { SongList LoadFromDevice(QIODevice *device, const QString &path_hint = QString(), const QDir &dir_hint = QDir()) const; void Save(const SongList &songs, const QString &filename, const PlaylistSettingsPage::PathType) const; + signals: + void Error(const QString &error) const; + private: + void AddParser(ParserBase *parser); bool ParserIsSupported(const Type type, ParserBase *parser) const; static QString FilterForParser(const ParserBase *parser, QStringList *all_extensions = nullptr);