PlaylistParser: Refactor code and exclude CUE from save playlist filters
Fixes #953
This commit is contained in:
@@ -26,8 +26,9 @@
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "parserbase.h"
|
||||
#include "asxiniparser.h"
|
||||
#include "playlistparsers/parserbase.h"
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
@@ -68,7 +69,7 @@ SongList AsxIniParser::Load(QIODevice *device, const QString &playlist_path, con
|
||||
|
||||
}
|
||||
|
||||
void AsxIniParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, Playlist::Path path_type) const {
|
||||
void AsxIniParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, const PlaylistSettingsPage::PathType path_type) const {
|
||||
|
||||
QTextStream s(device);
|
||||
s << "[Reference]" << qt_endl;
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "core/song.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "parserbase.h"
|
||||
#include "playlist/playlist.h"
|
||||
|
||||
class QIODevice;
|
||||
class CollectionBackendInterface;
|
||||
@@ -43,11 +43,13 @@ class AsxIniParser : public ParserBase {
|
||||
|
||||
QString name() const override { return "ASX/INI"; }
|
||||
QStringList file_extensions() const override { return QStringList() << "asxini"; }
|
||||
bool load_supported() const override { return true; }
|
||||
bool save_supported() const override { return true; }
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_Automatic) const override;
|
||||
};
|
||||
|
||||
#endif // ASXINIPARSER_H
|
||||
|
||||
@@ -32,9 +32,10 @@
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "asxparser.h"
|
||||
#include "core/utilities.h"
|
||||
#include "playlistparsers/xmlparser.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "xmlparser.h"
|
||||
#include "asxparser.h"
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
@@ -131,7 +132,7 @@ return_song:
|
||||
|
||||
}
|
||||
|
||||
void ASXParser::Save(const SongList &songs, QIODevice *device, const QDir&, Playlist::Path) const {
|
||||
void ASXParser::Save(const SongList &songs, QIODevice *device, const QDir&, const PlaylistSettingsPage::PathType) const {
|
||||
|
||||
QXmlStreamWriter writer(device);
|
||||
writer.setAutoFormatting(true);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "core/song.h"
|
||||
#include "playlist/playlist.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "xmlparser.h"
|
||||
|
||||
class QIODevice;
|
||||
@@ -45,11 +45,13 @@ class ASXParser : public XMLParser {
|
||||
|
||||
QString name() const override { return "ASX"; }
|
||||
QStringList file_extensions() const override { return QStringList() << "asx"; }
|
||||
bool load_supported() const override { return true; }
|
||||
bool save_supported() const override { return true; }
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_Automatic) const override;
|
||||
|
||||
private:
|
||||
Song ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_search) const;
|
||||
|
||||
@@ -35,8 +35,9 @@
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/timeconstants.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "parserbase.h"
|
||||
#include "cueparser.h"
|
||||
#include "playlistparsers/parserbase.h"
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
@@ -350,7 +351,7 @@ qint64 CueParser::IndexToMarker(const QString &index) {
|
||||
|
||||
}
|
||||
|
||||
void CueParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, Playlist::Path path_type) const {
|
||||
void CueParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, const PlaylistSettingsPage::PathType path_type) const {
|
||||
|
||||
Q_UNUSED(songs);
|
||||
Q_UNUSED(device);
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
#include <QDir>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "parserbase.h"
|
||||
#include "playlist/playlist.h"
|
||||
|
||||
class QIODevice;
|
||||
class CollectionBackendInterface;
|
||||
@@ -64,11 +64,13 @@ class CueParser : public ParserBase {
|
||||
QString name() const override { return "CUE"; }
|
||||
QStringList file_extensions() const override { return QStringList() << "cue"; }
|
||||
QString mime_type() const override { return "application/x-cue"; }
|
||||
bool load_supported() const override { return true; }
|
||||
bool save_supported() const override { return false; }
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_Automatic) const override;
|
||||
|
||||
static QString FindCueFilename(const QString &filename);
|
||||
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/timeconstants.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "parserbase.h"
|
||||
#include "m3uparser.h"
|
||||
#include "playlist/playlist.h"
|
||||
#include "playlistparsers/parserbase.h"
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
@@ -125,13 +125,13 @@ bool M3UParser::ParseMetadata(const QString &line, M3UParser::Metadata *metadata
|
||||
|
||||
}
|
||||
|
||||
void M3UParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, Playlist::Path path_type) const {
|
||||
void M3UParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, const PlaylistSettingsPage::PathType path_type) const {
|
||||
|
||||
device->write("#EXTM3U\n");
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(Playlist::kSettingsGroup);
|
||||
bool write_metadata = s.value(Playlist::kWriteMetadata, true).toBool();
|
||||
s.beginGroup(PlaylistSettingsPage::kSettingsGroup);
|
||||
bool write_metadata = s.value("write_metadata", true).toBool();
|
||||
s.endGroup();
|
||||
|
||||
for (const Song &song : songs) {
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
#include <QDir>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "parserbase.h"
|
||||
#include "playlist/playlist.h"
|
||||
|
||||
class QIODevice;
|
||||
class CollectionBackendInterface;
|
||||
@@ -46,11 +46,13 @@ class M3UParser : public ParserBase {
|
||||
QString name() const override { return "M3U"; }
|
||||
QStringList file_extensions() const override { return QStringList() << "m3u" << "m3u8"; }
|
||||
QString mime_type() const override { return "text/uri-list"; }
|
||||
bool load_supported() const override { return true; }
|
||||
bool save_supported() const override { return true; }
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_Automatic) const override;
|
||||
|
||||
private:
|
||||
enum M3UType {
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "core/logging.h"
|
||||
#include "core/tagreaderclient.h"
|
||||
#include "collection/collectionbackend.h"
|
||||
#include "playlist/playlist.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "parserbase.h"
|
||||
|
||||
ParserBase::ParserBase(CollectionBackendInterface *collection, QObject *parent)
|
||||
@@ -101,19 +101,20 @@ Song ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning
|
||||
|
||||
}
|
||||
|
||||
QString ParserBase::URLOrFilename(const QUrl &url, const QDir &dir, Playlist::Path path_type) {
|
||||
QString ParserBase::URLOrFilename(const QUrl &url, const QDir &dir, const PlaylistSettingsPage::PathType path_type) {
|
||||
|
||||
if (!url.isLocalFile()) return url.toString();
|
||||
|
||||
const QString filename = url.toLocalFile();
|
||||
|
||||
if (path_type != Playlist::Path_Absolute && QDir::isAbsolutePath(filename)) {
|
||||
if (path_type != PlaylistSettingsPage::PathType_Absolute && QDir::isAbsolutePath(filename)) {
|
||||
const QString relative = dir.relativeFilePath(filename);
|
||||
|
||||
if (!relative.startsWith("../") || path_type == Playlist::Path_Relative) {
|
||||
if (!relative.startsWith("../") || path_type == PlaylistSettingsPage::PathType_Relative) {
|
||||
return relative;
|
||||
}
|
||||
}
|
||||
|
||||
return filename;
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "core/song.h"
|
||||
#include "playlist/playlist.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
|
||||
class QIODevice;
|
||||
class CollectionBackendInterface;
|
||||
@@ -45,6 +45,8 @@ class ParserBase : public QObject {
|
||||
|
||||
virtual QString name() const = 0;
|
||||
virtual QStringList file_extensions() const = 0;
|
||||
virtual bool load_supported() const = 0;
|
||||
virtual bool save_supported() const = 0;
|
||||
virtual QString mime_type() const { return QString(); }
|
||||
|
||||
virtual bool TryMagic(const QByteArray &data) const = 0;
|
||||
@@ -55,7 +57,7 @@ class ParserBase : public QObject {
|
||||
// Any playlist parser may decide to leave out some entries if it finds them incomplete or invalid.
|
||||
// This means that the final resulting SongList should be considered valid (at least from the parser's point of view).
|
||||
virtual SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_lookup = true) const = 0;
|
||||
virtual void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const = 0;
|
||||
virtual void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_Automatic) const = 0;
|
||||
|
||||
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.
|
||||
@@ -67,7 +69,7 @@ class ParserBase : public QObject {
|
||||
|
||||
// If the URL is a file:// URL then returns its path, absolute or relative to the directory depending on the path_type option.
|
||||
// Otherwise returns the URL as is. This function should always be used when saving a playlist.
|
||||
static QString URLOrFilename(const QUrl &url, const QDir &dir, Playlist::Path path_type);
|
||||
static QString URLOrFilename(const QUrl &url, const QDir &dir, const PlaylistSettingsPage::PathType path_type);
|
||||
|
||||
private:
|
||||
CollectionBackendInterface *collection_;
|
||||
|
||||
@@ -31,13 +31,14 @@
|
||||
#include <QStringList>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "playlistparser.h"
|
||||
#include "parserbase.h"
|
||||
#include "asxiniparser.h"
|
||||
#include "asxparser.h"
|
||||
#include "core/logging.h"
|
||||
#include "cueparser.h"
|
||||
#include "m3uparser.h"
|
||||
#include "playlistparser.h"
|
||||
#include "playlistparsers/parserbase.h"
|
||||
#include "plsparser.h"
|
||||
#include "wplparser.h"
|
||||
#include "xspfparser.h"
|
||||
@@ -47,8 +48,8 @@ const int PlaylistParser::kMagicSize = 512;
|
||||
PlaylistParser::PlaylistParser(CollectionBackendInterface *collection, QObject *parent) : QObject(parent) {
|
||||
|
||||
default_parser_ = new XSPFParser(collection, this);
|
||||
parsers_ << new M3UParser(collection, this);
|
||||
parsers_ << default_parser_;
|
||||
parsers_ << new M3UParser(collection, this);
|
||||
parsers_ << new PLSParser(collection, this);
|
||||
parsers_ << new ASXParser(collection, this);
|
||||
parsers_ << new AsxIniParser(collection, this);
|
||||
@@ -57,12 +58,14 @@ PlaylistParser::PlaylistParser(CollectionBackendInterface *collection, QObject *
|
||||
|
||||
}
|
||||
|
||||
QStringList PlaylistParser::file_extensions() const {
|
||||
QStringList PlaylistParser::file_extensions(const Type type) const {
|
||||
|
||||
QStringList ret;
|
||||
|
||||
for (ParserBase *parser : parsers_) {
|
||||
ret << parser->file_extensions();
|
||||
if (ParserIsSupported(type, parser)) {
|
||||
ret << parser->file_extensions();
|
||||
}
|
||||
}
|
||||
|
||||
std::stable_sort(ret.begin(), ret.end());
|
||||
@@ -70,29 +73,36 @@ QStringList PlaylistParser::file_extensions() const {
|
||||
|
||||
}
|
||||
|
||||
QStringList PlaylistParser::mime_types() const {
|
||||
QStringList PlaylistParser::mime_types(const Type type) const {
|
||||
|
||||
QStringList ret;
|
||||
|
||||
for (ParserBase *parser : parsers_) {
|
||||
if (!parser->mime_type().isEmpty()) ret << parser->mime_type();
|
||||
if (ParserIsSupported(type, parser) && !parser->mime_type().isEmpty()) {
|
||||
ret << parser->mime_type();
|
||||
}
|
||||
}
|
||||
|
||||
std::stable_sort(ret.begin(), ret.end());
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
QString PlaylistParser::filters() const {
|
||||
QString PlaylistParser::filters(const Type type) const {
|
||||
|
||||
QStringList filters;
|
||||
filters.reserve(parsers_.count() + 1);
|
||||
QStringList all_extensions;
|
||||
for (ParserBase *parser : parsers_) {
|
||||
filters << FilterForParser(parser, &all_extensions);
|
||||
if (ParserIsSupported(type, parser)) {
|
||||
filters << FilterForParser(parser, &all_extensions);
|
||||
}
|
||||
}
|
||||
|
||||
filters.prepend(tr("All playlists (%1)").arg(all_extensions.join(" ")));
|
||||
if (type == Type_Load) {
|
||||
filters.prepend(tr("All playlists (%1)").arg(all_extensions.join(" ")));
|
||||
}
|
||||
|
||||
return filters.join(";;");
|
||||
|
||||
@@ -122,20 +132,22 @@ QString PlaylistParser::default_filter() const {
|
||||
return FilterForParser(default_parser_);
|
||||
}
|
||||
|
||||
ParserBase *PlaylistParser::ParserForExtension(const QString &suffix) const {
|
||||
ParserBase *PlaylistParser::ParserForExtension(const Type type, const QString &suffix) const {
|
||||
|
||||
for (ParserBase *p : parsers_) {
|
||||
if (p->file_extensions().contains(suffix)) return p;
|
||||
for (ParserBase *parser : parsers_) {
|
||||
if (ParserIsSupported(type, parser) && parser->file_extensions().contains(suffix)) {
|
||||
return parser;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
||||
ParserBase *PlaylistParser::ParserForMimeType(const QString &mime_type) const {
|
||||
ParserBase *PlaylistParser::ParserForMimeType(const Type type, const QString &mime_type) const {
|
||||
|
||||
for (ParserBase *p : parsers_) {
|
||||
if (!p->mime_type().isEmpty() && (QString::compare(p->mime_type(), mime_type, Qt::CaseInsensitive) == 0)) {
|
||||
return p;
|
||||
for (ParserBase *parser : parsers_) {
|
||||
if (ParserIsSupported(type, parser) && !parser->mime_type().isEmpty() && QString::compare(parser->mime_type(), mime_type, Qt::CaseInsensitive) == 0) {
|
||||
return parser;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -144,9 +156,9 @@ ParserBase *PlaylistParser::ParserForMimeType(const QString &mime_type) const {
|
||||
|
||||
ParserBase *PlaylistParser::ParserForMagic(const QByteArray &data, const QString &mime_type) const {
|
||||
|
||||
for (ParserBase *p : parsers_) {
|
||||
if ((!mime_type.isEmpty() && mime_type == p->mime_type()) || p->TryMagic(data)) {
|
||||
return p;
|
||||
for (ParserBase *parser : parsers_) {
|
||||
if ((!mime_type.isEmpty() && mime_type == parser->mime_type()) || parser->TryMagic(data)) {
|
||||
return parser;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@@ -155,10 +167,10 @@ ParserBase *PlaylistParser::ParserForMagic(const QByteArray &data, const QString
|
||||
|
||||
SongList PlaylistParser::LoadFromFile(const QString &filename) const {
|
||||
|
||||
QFileInfo info(filename);
|
||||
QFileInfo fileinfo(filename);
|
||||
|
||||
// Find a parser that supports this file extension
|
||||
ParserBase *parser = ParserForExtension(info.suffix());
|
||||
ParserBase *parser = ParserForExtension(Type_Load, fileinfo.suffix());
|
||||
if (!parser) {
|
||||
qLog(Warning) << "Unknown filetype:" << filename;
|
||||
return SongList();
|
||||
@@ -168,7 +180,7 @@ SongList PlaylistParser::LoadFromFile(const QString &filename) const {
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::ReadOnly)) return SongList();
|
||||
|
||||
SongList ret = parser->Load(&file, filename, info.absolutePath());
|
||||
SongList ret = parser->Load(&file, filename, fileinfo.absolutePath());
|
||||
file.close();
|
||||
|
||||
return ret;
|
||||
@@ -187,12 +199,12 @@ SongList PlaylistParser::LoadFromDevice(QIODevice *device, const QString &path_h
|
||||
|
||||
}
|
||||
|
||||
void PlaylistParser::Save(const SongList &songs, const QString &filename, const Playlist::Path path_type) const {
|
||||
void PlaylistParser::Save(const SongList &songs, const QString &filename, const PlaylistSettingsPage::PathType path_type) const {
|
||||
|
||||
QFileInfo info(filename);
|
||||
QFileInfo fileinfo(filename);
|
||||
|
||||
// Find a parser that supports this file extension
|
||||
ParserBase *parser = ParserForExtension(info.suffix());
|
||||
ParserBase *parser = ParserForExtension(Type_Save, fileinfo.suffix());
|
||||
if (!parser) {
|
||||
qLog(Warning) << "Unknown filetype:" << filename;
|
||||
return;
|
||||
@@ -202,8 +214,14 @@ void PlaylistParser::Save(const SongList &songs, const QString &filename, const
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::WriteOnly)) return;
|
||||
|
||||
parser->Save(songs, &file, info.absolutePath(), path_type);
|
||||
parser->Save(songs, &file, fileinfo.absolutePath(), path_type);
|
||||
|
||||
file.close();
|
||||
|
||||
}
|
||||
|
||||
bool PlaylistParser::ParserIsSupported(const Type type, ParserBase *parser) const {
|
||||
|
||||
return ((type == Type_Load && parser->load_supported()) || (type == Type_Save && parser->save_supported()));
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#ifndef PLAYLISTPARSER_H
|
||||
#define PLAYLISTPARSER_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QDir>
|
||||
#include <QByteArray>
|
||||
@@ -28,9 +30,8 @@
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include "config.h"
|
||||
#include "core/song.h"
|
||||
#include "playlist/playlist.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
|
||||
class QIODevice;
|
||||
class CollectionBackendInterface;
|
||||
@@ -42,28 +43,34 @@ class PlaylistParser : public QObject {
|
||||
public:
|
||||
explicit PlaylistParser(CollectionBackendInterface *collection = nullptr, QObject *parent = nullptr);
|
||||
|
||||
enum Type {
|
||||
Type_Load,
|
||||
Type_Save,
|
||||
};
|
||||
|
||||
static const int kMagicSize;
|
||||
|
||||
QStringList file_extensions() const;
|
||||
QString filters() const;
|
||||
QStringList file_extensions(const Type type) const;
|
||||
QString filters(const Type type) const;
|
||||
|
||||
QStringList mime_types() const;
|
||||
QStringList mime_types(const Type type) const;
|
||||
|
||||
QString default_extension() const;
|
||||
QString default_filter() const;
|
||||
|
||||
ParserBase *ParserForMagic(const QByteArray &data, const QString &mime_type = QString()) const;
|
||||
ParserBase *ParserForExtension(const QString &suffix) const;
|
||||
ParserBase *ParserForMimeType(const QString &mime) const;
|
||||
ParserBase *ParserForExtension(const Type type, const QString &suffix) const;
|
||||
ParserBase *ParserForMimeType(const Type type, const QString &mime) const;
|
||||
|
||||
SongList LoadFromFile(const QString &filename) const;
|
||||
SongList LoadFromDevice(QIODevice *device, const QString &path_hint = QString(), const QDir &dir_hint = QDir()) const;
|
||||
void Save(const SongList &songs, const QString &filename, const Playlist::Path) const;
|
||||
void Save(const SongList &songs, const QString &filename, const PlaylistSettingsPage::PathType) const;
|
||||
|
||||
private:
|
||||
private:
|
||||
bool ParserIsSupported(const Type type, ParserBase *parser) const;
|
||||
static QString FilterForParser(const ParserBase *parser, QStringList *all_extensions = nullptr);
|
||||
|
||||
private:
|
||||
private:
|
||||
QList<ParserBase*> parsers_;
|
||||
ParserBase *default_parser_;
|
||||
};
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
#include <QTextStream>
|
||||
|
||||
#include "core/timeconstants.h"
|
||||
#include "playlistparsers/parserbase.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "parserbase.h"
|
||||
#include "plsparser.h"
|
||||
|
||||
class CollectionBackendInterface;
|
||||
@@ -86,7 +87,7 @@ SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
|
||||
}
|
||||
|
||||
void PLSParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, Playlist::Path path_type) const {
|
||||
void PLSParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, const PlaylistSettingsPage::PathType path_type) const {
|
||||
|
||||
QTextStream s(device);
|
||||
s << "[playlist]" << qt_endl;
|
||||
|
||||
@@ -21,16 +21,17 @@
|
||||
#ifndef PLSPARSER_H
|
||||
#define PLSPARSER_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QDir>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include "config.h"
|
||||
#include "core/song.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "parserbase.h"
|
||||
#include "playlist/playlist.h"
|
||||
|
||||
class QIODevice;
|
||||
class CollectionBackendInterface;
|
||||
@@ -44,11 +45,13 @@ class PLSParser : public ParserBase {
|
||||
QString name() const override { return "PLS"; }
|
||||
QStringList file_extensions() const override { return QStringList() << "pls"; }
|
||||
QString mime_type() const override { return "audio/x-scpls"; }
|
||||
bool load_supported() const override { return true; }
|
||||
bool save_supported() const override { return true; }
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_Automatic) const override;
|
||||
};
|
||||
|
||||
#endif // PLSPARSER_H
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QIODevice>
|
||||
@@ -28,8 +30,8 @@
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "core/utilities.h"
|
||||
#include "playlistparsers/xmlparser.h"
|
||||
#include "version.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "xmlparser.h"
|
||||
#include "wplparser.h"
|
||||
|
||||
class CollectionBackendInterface;
|
||||
@@ -93,7 +95,7 @@ void WplParser::ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *so
|
||||
|
||||
}
|
||||
|
||||
void WplParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, Playlist::Path path_type) const {
|
||||
void WplParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, const PlaylistSettingsPage::PathType path_type) const {
|
||||
|
||||
QXmlStreamWriter writer(device);
|
||||
writer.setAutoFormatting(true);
|
||||
|
||||
@@ -21,15 +21,16 @@
|
||||
#ifndef WPLPARSER_H
|
||||
#define WPLPARSER_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QDir>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include "config.h"
|
||||
#include "core/song.h"
|
||||
#include "playlist/playlist.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "xmlparser.h"
|
||||
|
||||
class QIODevice;
|
||||
@@ -47,11 +48,13 @@ class WplParser : public XMLParser {
|
||||
QString name() const override { return "WPL"; }
|
||||
QStringList file_extensions() const override { return QStringList() << "wpl"; }
|
||||
QString mime_type() const override { return "application/vnd.ms-wpl"; }
|
||||
bool load_supported() const override { return true; }
|
||||
bool save_supported() const override { return true; }
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path, const QDir &dir, const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir, Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir, const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_Automatic) const override;
|
||||
|
||||
private:
|
||||
void ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *songs, const bool collection_search = true) const;
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "playlistparsers/parserbase.h"
|
||||
#include "xmlparser.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "parserbase.h"
|
||||
#include "xmlparser.h"
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
XMLParser::XMLParser(CollectionBackendInterface *collection, QObject *parent)
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
|
||||
#include "core/timeconstants.h"
|
||||
#include "core/utilities.h"
|
||||
#include "playlist/playlist.h"
|
||||
#include "playlistparsers/xmlparser.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "xmlparser.h"
|
||||
#include "xspfparser.h"
|
||||
|
||||
class CollectionBackendInterface;
|
||||
@@ -137,7 +137,7 @@ return_song:
|
||||
|
||||
}
|
||||
|
||||
void XSPFParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, Playlist::Path path_type) const {
|
||||
void XSPFParser::Save(const SongList &songs, QIODevice *device, const QDir &dir, const PlaylistSettingsPage::PathType path_type) const {
|
||||
|
||||
QXmlStreamWriter writer(device);
|
||||
writer.setAutoFormatting(true);
|
||||
@@ -148,8 +148,8 @@ void XSPFParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
|
||||
writer.writeDefaultNamespace("http://xspf.org/ns/0/");
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(Playlist::kSettingsGroup);
|
||||
bool write_metadata = s.value(Playlist::kWriteMetadata, true).toBool();
|
||||
s.beginGroup(PlaylistSettingsPage::kSettingsGroup);
|
||||
bool write_metadata = s.value("write_metadata", true).toBool();
|
||||
s.endGroup();
|
||||
|
||||
StreamElement tracklist("trackList", &writer);
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <QStringList>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "playlist/playlist.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "xmlparser.h"
|
||||
|
||||
class QIODevice;
|
||||
@@ -45,11 +45,13 @@ class XSPFParser : public XMLParser {
|
||||
|
||||
QString name() const override { return "XSPF"; }
|
||||
QStringList file_extensions() const override { return QStringList() << "xspf"; }
|
||||
bool load_supported() const override { return true; }
|
||||
bool save_supported() const override { return true; }
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir(), const bool collection_search = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_Automatic) const override;
|
||||
|
||||
private:
|
||||
Song ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool collection_search) const;
|
||||
|
||||
Reference in New Issue
Block a user