Finish the last of my Playlist path preferences patch.
This commit is contained in:
parent
a0bbe2cfaf
commit
c026b599b4
@ -105,6 +105,12 @@ bool M3UParser::ParseMetadata(const QString& line,
|
||||
void M3UParser::Save(const SongList& songs, QIODevice* device,
|
||||
const QDir& dir) const {
|
||||
device->write("#EXTM3U\n");
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(Playlist::kSettingsGroup);
|
||||
bool writeMetadata = s.value("write_metadata", true).toBool();
|
||||
s.endGroup();
|
||||
|
||||
for (const Song& song : songs) {
|
||||
if (song.url().isEmpty()) {
|
||||
continue;
|
||||
|
@ -24,11 +24,8 @@
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
ParserBase::ParserBase(LibraryBackendInterface* library, QSettings *settings, QObject* parent)
|
||||
: QObject(parent), library_(library) {
|
||||
path = settings->value("path_type", Playlist::Path_Automatic);
|
||||
writeMetadata = settings->value("write_metadata", true).toBool();
|
||||
}
|
||||
ParserBase::ParserBase(LibraryBackendInterface* library, QObject* parent)
|
||||
: QObject(parent), library_(library) {}
|
||||
|
||||
void ParserBase::LoadSong(const QString& filename_or_url, qint64 beginning,
|
||||
const QDir& dir, Song* song) const {
|
||||
@ -91,8 +88,15 @@ Song ParserBase::LoadSong(const QString& filename_or_url, qint64 beginning,
|
||||
|
||||
QString ParserBase::URLOrRelativeFilename(const QUrl& url,
|
||||
const QDir& dir) const {
|
||||
|
||||
if (url.scheme() != "file") return url.toString();
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(Playlist::kSettingsGroup);
|
||||
int p = s.value("path_type", Playlist::Path_Automatic).toInt();
|
||||
const Playlist::Path path = static_cast<Playlist::Path>(p);
|
||||
s.endGroup();
|
||||
|
||||
const QString filename = url.toLocalFile();
|
||||
|
||||
if (path != Playlist::Path_Absolute && QDir::isAbsolutePath(filename)) {
|
||||
|
@ -30,7 +30,7 @@ class ParserBase : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ParserBase(LibraryBackendInterface* library, QSettings* settings, QObject* parent = nullptr);
|
||||
ParserBase(LibraryBackendInterface* library, QObject* parent = nullptr);
|
||||
|
||||
virtual QString name() const = 0;
|
||||
virtual QStringList file_extensions() const = 0;
|
||||
@ -71,9 +71,6 @@ class ParserBase : public QObject {
|
||||
// This function should always be used when saving a playlist.
|
||||
QString URLOrRelativeFilename(const QUrl& url, const QDir& dir) const;
|
||||
|
||||
Playlist::Path path;
|
||||
bool writeMetadata;
|
||||
|
||||
private:
|
||||
LibraryBackendInterface* library_;
|
||||
};
|
||||
|
@ -111,16 +111,14 @@ void XSPFParser::Save(const SongList& songs, QIODevice* device,
|
||||
writer.writeAttribute("version", "1");
|
||||
writer.writeDefaultNamespace("http://xspf.org/ns/0/");
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(Playlist::kSettingsGroup);
|
||||
bool writeMetadata = s.value("write_metadata", true).toBool();
|
||||
s.endGroup();
|
||||
|
||||
StreamElement tracklist("trackList", &writer);
|
||||
for (const Song& song : songs) {
|
||||
QString filename_or_url;
|
||||
if (song.url().scheme() == "file") {
|
||||
// Make the filename relative to the directory we're saving the playlist.
|
||||
filename_or_url = dir.relativeFilePath(
|
||||
QFileInfo(song.url().toLocalFile()).absoluteFilePath());
|
||||
} else {
|
||||
filename_or_url = song.url().toEncoded();
|
||||
}
|
||||
QString filename_or_url = URLOrRelativeFilename(song.url(), dir).toUtf8();
|
||||
|
||||
StreamElement track("track", &writer);
|
||||
writer.writeTextElement("location", filename_or_url);
|
||||
@ -149,11 +147,12 @@ void XSPFParser::Save(const SongList& songs, QIODevice* device,
|
||||
art_filename = QUrl(art).toLocalFile();
|
||||
}
|
||||
|
||||
if (!art_filename.isEmpty()) {
|
||||
if (!art_filename.isEmpty() && !(art_filename == "(embedded)")) {
|
||||
// Make this filename relative to the directory we're saving the
|
||||
// playlist.
|
||||
art_filename = dir.relativeFilePath(
|
||||
QFileInfo(art_filename).absoluteFilePath());
|
||||
QUrl url = QUrl(art_filename);
|
||||
url.setScheme("file"); // Need to explicitly set this.
|
||||
art_filename = URLOrRelativeFilename(url, dir).toUtf8();
|
||||
} else {
|
||||
// Just use whatever URL was in the Song.
|
||||
art_filename = art;
|
||||
|
Loading…
x
Reference in New Issue
Block a user