Replace QLatin1String with operator _L1
This commit is contained in:
@@ -31,6 +31,8 @@
|
||||
#include "parserbase.h"
|
||||
#include "asxiniparser.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
AsxIniParser::AsxIniParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
|
||||
@@ -48,11 +50,11 @@ SongList AsxIniParser::Load(QIODevice *device, const QString &playlist_path, con
|
||||
|
||||
while (!device->atEnd()) {
|
||||
QString line = QString::fromUtf8(device->readLine()).trimmed();
|
||||
qint64 equals = line.indexOf(QLatin1Char('='));
|
||||
qint64 equals = line.indexOf(u'=');
|
||||
QString key = line.left(equals).toLower();
|
||||
QString value = line.mid(equals + 1);
|
||||
|
||||
if (key.startsWith(QLatin1String("ref"))) {
|
||||
if (key.startsWith("ref"_L1)) {
|
||||
Song song = LoadSong(value, 0, 0, dir, collection_lookup);
|
||||
if (song.is_valid()) {
|
||||
ret << song;
|
||||
|
||||
@@ -50,7 +50,7 @@ class AsxIniParser : public ParserBase {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = ""_L1, const QDir &dir = QDir(), const bool collection_lookup = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include "xmlparser.h"
|
||||
#include "asxparser.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
ASXParser::ASXParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
|
||||
@@ -94,20 +96,20 @@ Song ASXParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool
|
||||
switch (type) {
|
||||
case QXmlStreamReader::StartElement:{
|
||||
const QString name = reader->name().toString().toLower();
|
||||
if (name == QLatin1String("ref")) {
|
||||
ref = reader->attributes().value(QLatin1String("href")).toString();
|
||||
if (name == "ref"_L1) {
|
||||
ref = reader->attributes().value("href"_L1).toString();
|
||||
}
|
||||
else if (name == QLatin1String("title")) {
|
||||
else if (name == "title"_L1) {
|
||||
title = reader->readElementText();
|
||||
}
|
||||
else if (name == QLatin1String("author")) {
|
||||
else if (name == "author"_L1) {
|
||||
artist = reader->readElementText();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QXmlStreamReader::EndElement:{
|
||||
const QString name = reader->name().toString().toLower();
|
||||
if (name == QLatin1String("entry")) {
|
||||
if (name == "entry"_L1) {
|
||||
goto return_song;
|
||||
}
|
||||
break;
|
||||
@@ -139,16 +141,16 @@ void ASXParser::Save(const SongList &songs, QIODevice *device, const QDir&, cons
|
||||
writer.writeStartDocument();
|
||||
{
|
||||
StreamElement asx(QStringLiteral("asx"), &writer);
|
||||
writer.writeAttribute(QLatin1String("version"), QLatin1String("3.0"));
|
||||
writer.writeAttribute("version"_L1, "3.0"_L1);
|
||||
for (const Song &song : songs) {
|
||||
StreamElement entry(QStringLiteral("entry"), &writer);
|
||||
writer.writeTextElement(QLatin1String("title"), song.title());
|
||||
writer.writeTextElement("title"_L1, song.title());
|
||||
{
|
||||
StreamElement ref(QStringLiteral("ref"), &writer);
|
||||
writer.writeAttribute(QLatin1String("href"), song.url().toString());
|
||||
writer.writeAttribute("href"_L1, song.url().toString());
|
||||
}
|
||||
if (!song.artist().isEmpty()) {
|
||||
writer.writeTextElement(QLatin1String("author"), song.artist());
|
||||
writer.writeTextElement("author"_L1, song.artist());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class ASXParser : public XMLParser {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = ""_L1, const QDir &dir = QDir(), const bool collection_lookup = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
#include "parserbase.h"
|
||||
#include "cueparser.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
namespace {
|
||||
@@ -161,7 +163,7 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
}
|
||||
|
||||
// If this is a data file, all of its tracks will be ignored
|
||||
bool valid_file = file_type.compare(QLatin1String("BINARY"), Qt::CaseInsensitive) != 0 && file_type.compare(QLatin1String("MOTOROLA"), Qt::CaseInsensitive) != 0;
|
||||
bool valid_file = file_type.compare("BINARY"_L1, Qt::CaseInsensitive) != 0 && file_type.compare("MOTOROLA"_L1, Qt::CaseInsensitive) != 0;
|
||||
|
||||
QString track_type;
|
||||
QString index;
|
||||
@@ -182,7 +184,7 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
|
||||
const QString &line_name = splitted[0];
|
||||
const QString &line_value = splitted[1];
|
||||
QString line_additional = splitted.size() > 2 ? splitted[2].toLower() : QLatin1String("");
|
||||
QString line_additional = splitted.size() > 2 ? splitted[2].toLower() : ""_L1;
|
||||
|
||||
if (line_name.compare(QLatin1String(kTrack), Qt::CaseInsensitive) == 0) {
|
||||
|
||||
@@ -193,7 +195,7 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
}
|
||||
|
||||
// Clear the state
|
||||
track_type = index = artist = composer = title = date = genre = QLatin1String("");
|
||||
track_type = index = artist = composer = title = date = genre = ""_L1;
|
||||
|
||||
if (!line_additional.isEmpty()) {
|
||||
track_type = line_additional;
|
||||
@@ -206,7 +208,7 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
if (!line_additional.isEmpty()) {
|
||||
|
||||
// If there's none "01" index, we'll just take the first one also, we'll take the "01" index even if it's the last one
|
||||
if (line_value == QLatin1String("01") || index.isEmpty()) {
|
||||
if (line_value == "01"_L1 || index.isEmpty()) {
|
||||
|
||||
index = line_additional;
|
||||
}
|
||||
@@ -300,7 +302,7 @@ QStringList CueParser::SplitCueLine(const QString &line) {
|
||||
// Let's remove the empty entries while we're at it
|
||||
static const QRegularExpression regex_entry(QStringLiteral(".+"));
|
||||
static const QRegularExpression regex_exclude(QStringLiteral("^\"\"$"));
|
||||
return re_match.capturedTexts().filter(regex_entry).mid(1, -1).replaceInStrings(regex_exclude, QLatin1String(""));
|
||||
return re_match.capturedTexts().filter(regex_entry).mid(1, -1).replaceInStrings(regex_exclude, ""_L1);
|
||||
|
||||
}
|
||||
|
||||
@@ -392,7 +394,7 @@ void CueParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
|
||||
// Looks for a track starting with one of the .cue's keywords.
|
||||
bool CueParser::TryMagic(const QByteArray &data) const {
|
||||
|
||||
QStringList splitted = QString::fromUtf8(data.constData()).split(QLatin1Char('\n'));
|
||||
QStringList splitted = QString::fromUtf8(data.constData()).split(u'\n');
|
||||
|
||||
for (int i = 0; i < splitted.length(); i++) {
|
||||
QString line = splitted.at(i).trimmed();
|
||||
@@ -411,7 +413,7 @@ bool CueParser::TryMagic(const QByteArray &data) const {
|
||||
QString CueParser::FindCueFilename(const QString &filename) {
|
||||
|
||||
const QStringList cue_files = QStringList() << filename + QStringLiteral(".cue")
|
||||
<< filename.section(QLatin1Char('.'), 0, -2) + QStringLiteral(".cue");
|
||||
<< filename.section(u'.', 0, -2) + QStringLiteral(".cue");
|
||||
|
||||
for (const QString &cuefile : cue_files) {
|
||||
if (QFileInfo::exists(cuefile)) return cuefile;
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "parserbase.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
class QIODevice;
|
||||
class CollectionBackendInterface;
|
||||
|
||||
@@ -55,7 +57,7 @@ class CueParser : public ParserBase {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = ""_L1, const QDir &dir = QDir(), const bool collection_lookup = true) 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);
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include "parserbase.h"
|
||||
#include "m3uparser.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
M3UParser::M3UParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
|
||||
@@ -48,14 +50,14 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
Metadata current_metadata;
|
||||
|
||||
QString data = QString::fromUtf8(device->readAll());
|
||||
data.replace(QLatin1Char('\r'), QLatin1Char('\n'));
|
||||
data.replace(QLatin1String("\n\n"), QLatin1String("\n"));
|
||||
data.replace(u'\r', u'\n');
|
||||
data.replace("\n\n"_L1, "\n"_L1);
|
||||
QByteArray bytes = data.toUtf8();
|
||||
QBuffer buffer(&bytes);
|
||||
if (!buffer.open(QIODevice::ReadOnly)) return SongList();
|
||||
|
||||
QString line = QString::fromUtf8(buffer.readLine()).trimmed();
|
||||
if (line.startsWith(QLatin1String("#EXTM3U"))) {
|
||||
if (line.startsWith("#EXTM3U"_L1)) {
|
||||
// This is in extended M3U format.
|
||||
type = M3UType::EXTENDED;
|
||||
line = QString::fromUtf8(buffer.readLine()).trimmed();
|
||||
@@ -63,9 +65,9 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
|
||||
SongList ret;
|
||||
Q_FOREVER {
|
||||
if (line.startsWith(QLatin1Char('#'))) {
|
||||
if (line.startsWith(u'#')) {
|
||||
// Extended info or comment.
|
||||
if (type == M3UType::EXTENDED && line.startsWith(QLatin1String("#EXT"))) {
|
||||
if (type == M3UType::EXTENDED && line.startsWith("#EXT"_L1)) {
|
||||
if (!ParseMetadata(line, ¤t_metadata)) {
|
||||
qLog(Warning) << "Failed to parse metadata: " << line;
|
||||
}
|
||||
@@ -102,8 +104,8 @@ bool M3UParser::ParseMetadata(const QString &line, M3UParser::Metadata *metadata
|
||||
|
||||
// Extended info, eg.
|
||||
// #EXTINF:123,Sample Artist - Sample title
|
||||
QString info = line.section(QLatin1Char(':'), 1);
|
||||
QString l = info.section(QLatin1Char(','), 0, 0);
|
||||
QString info = line.section(u':', 1);
|
||||
QString l = info.section(u',', 0, 0);
|
||||
bool ok = false;
|
||||
int length = l.toInt(&ok);
|
||||
if (!ok) {
|
||||
@@ -111,7 +113,7 @@ bool M3UParser::ParseMetadata(const QString &line, M3UParser::Metadata *metadata
|
||||
}
|
||||
metadata->length = length * kNsecPerSec;
|
||||
|
||||
QString track_info = info.section(QLatin1Char(','), 1);
|
||||
QString track_info = info.section(u',', 1);
|
||||
QStringList list = track_info.split(QStringLiteral(" - "));
|
||||
if (list.size() <= 1) {
|
||||
metadata->title = track_info;
|
||||
|
||||
@@ -52,7 +52,7 @@ class M3UParser : public ParserBase {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = ""_L1, const QDir &dir = QDir(), const bool collection_lookup = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "parserbase.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
ParserBase::ParserBase(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
|
||||
: QObject(parent), collection_backend_(collection_backend) {}
|
||||
|
||||
@@ -128,7 +130,7 @@ QString ParserBase::URLOrFilename(const QUrl &url, const QDir &dir, const Playli
|
||||
if (path_type != PlaylistSettingsPage::PathType::Absolute && QDir::isAbsolutePath(filename)) {
|
||||
const QString relative = dir.relativeFilePath(filename);
|
||||
|
||||
if (!relative.startsWith(QLatin1String("../")) || path_type == PlaylistSettingsPage::PathType::Relative) {
|
||||
if (!relative.startsWith("../"_L1) || path_type == PlaylistSettingsPage::PathType::Relative) {
|
||||
return relative;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#include "core/song.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
class QIODevice;
|
||||
class CollectionBackendInterface;
|
||||
|
||||
@@ -58,7 +60,7 @@ class ParserBase : public QObject {
|
||||
// This method might not return all the songs found in the playlist.
|
||||
// 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 = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const = 0;
|
||||
virtual SongList Load(QIODevice *device, const QString &playlist_path = ""_L1, 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;
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
#include "wplparser.h"
|
||||
#include "xspfparser.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
const int PlaylistParser::kMagicSize = 512;
|
||||
|
||||
PlaylistParser::PlaylistParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent) : QObject(parent), default_parser_(nullptr) {
|
||||
@@ -110,10 +112,10 @@ QString PlaylistParser::filters(const Type type) const {
|
||||
}
|
||||
|
||||
if (type == Type::Load) {
|
||||
filters.prepend(tr("All playlists (%1)").arg(all_extensions.join(QLatin1Char(' '))));
|
||||
filters.prepend(tr("All playlists (%1)").arg(all_extensions.join(u' ')));
|
||||
}
|
||||
|
||||
return filters.join(QLatin1String(";;"));
|
||||
return filters.join(";;"_L1);
|
||||
|
||||
}
|
||||
|
||||
@@ -128,7 +130,7 @@ QString PlaylistParser::FilterForParser(const ParserBase *parser, QStringList *a
|
||||
|
||||
if (all_extensions) *all_extensions << extensions;
|
||||
|
||||
return tr("%1 playlists (%2)").arg(parser->name(), extensions.join(QLatin1Char(' ')));
|
||||
return tr("%1 playlists (%2)").arg(parser->name(), extensions.join(u' '));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "parserbase.h"
|
||||
#include "plsparser.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
PLSParser::PLSParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
|
||||
@@ -48,14 +50,14 @@ SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
|
||||
while (!device->atEnd()) {
|
||||
QString line = QString::fromUtf8(device->readLine()).trimmed();
|
||||
qint64 equals = line.indexOf(QLatin1Char('='));
|
||||
qint64 equals = line.indexOf(u'=');
|
||||
QString key = line.left(equals).toLower();
|
||||
QString value = line.mid(equals + 1);
|
||||
|
||||
QRegularExpressionMatch re_match = n_re.match(key);
|
||||
int n = re_match.captured(0).toInt();
|
||||
|
||||
if (key.startsWith(QLatin1String("file"))) {
|
||||
if (key.startsWith("file"_L1)) {
|
||||
Song song = LoadSong(value, 0, 0, dir, collection_lookup);
|
||||
|
||||
// Use the title and length we've already loaded if any
|
||||
@@ -66,10 +68,10 @@ SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
|
||||
songs[n] = song;
|
||||
}
|
||||
else if (key.startsWith(QLatin1String("title"))) {
|
||||
else if (key.startsWith("title"_L1)) {
|
||||
songs[n].set_title(value);
|
||||
}
|
||||
else if (key.startsWith(QLatin1String("length"))) {
|
||||
else if (key.startsWith("length"_L1)) {
|
||||
qint64 seconds = value.toLongLong();
|
||||
if (seconds > 0) {
|
||||
songs[n].set_length_nanosec(seconds * kNsecPerSec);
|
||||
|
||||
@@ -51,7 +51,7 @@ class PLSParser : public ParserBase {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = ""_L1, const QDir &dir = QDir(), const bool collection_lookup = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include "xmlparser.h"
|
||||
#include "wplparser.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
WplParser::WplParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
|
||||
@@ -69,8 +71,8 @@ void WplParser::ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *so
|
||||
QString name = reader->name().toString();
|
||||
switch (type) {
|
||||
case QXmlStreamReader::StartElement:{
|
||||
if (name == QLatin1String("media")) {
|
||||
QString src = reader->attributes().value(QLatin1String("src")).toString();
|
||||
if (name == "media"_L1) {
|
||||
QString src = reader->attributes().value("src"_L1).toString();
|
||||
if (!src.isEmpty()) {
|
||||
Song song = LoadSong(src, 0, 0, dir, collection_lookup);
|
||||
if (song.is_valid()) {
|
||||
@@ -84,7 +86,7 @@ void WplParser::ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *so
|
||||
break;
|
||||
}
|
||||
case QXmlStreamReader::EndElement:{
|
||||
if (name == QLatin1String("seq")) {
|
||||
if (name == "seq"_L1) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -101,14 +103,14 @@ void WplParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
|
||||
QXmlStreamWriter writer(device);
|
||||
writer.setAutoFormatting(true);
|
||||
writer.setAutoFormattingIndent(2);
|
||||
writer.writeProcessingInstruction(QLatin1String("wpl"), QLatin1String("version=\"1.0\""));
|
||||
writer.writeProcessingInstruction("wpl"_L1, "version=\"1.0\""_L1);
|
||||
|
||||
StreamElement smil(QStringLiteral("smil"), &writer);
|
||||
|
||||
{
|
||||
StreamElement head(QStringLiteral("head"), &writer);
|
||||
WriteMeta(QLatin1String("Generator"), QLatin1String("Strawberry -- ") + QLatin1String(STRAWBERRY_VERSION_DISPLAY), &writer);
|
||||
WriteMeta(QLatin1String("ItemCount"), QString::number(songs.count()), &writer);
|
||||
WriteMeta("Generator"_L1, "Strawberry -- "_L1 + QLatin1String(STRAWBERRY_VERSION_DISPLAY), &writer);
|
||||
WriteMeta("ItemCount"_L1, QString::number(songs.count()), &writer);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -116,8 +118,8 @@ void WplParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
|
||||
{
|
||||
StreamElement seq(QStringLiteral("seq"), &writer);
|
||||
for (const Song &song : songs) {
|
||||
writer.writeStartElement(QLatin1String("media"));
|
||||
writer.writeAttribute(QLatin1String("src"), URLOrFilename(song.url(), dir, path_type));
|
||||
writer.writeStartElement("media"_L1);
|
||||
writer.writeAttribute("src"_L1, URLOrFilename(song.url(), dir, path_type));
|
||||
writer.writeEndElement();
|
||||
}
|
||||
}
|
||||
@@ -126,9 +128,9 @@ void WplParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
|
||||
|
||||
void WplParser::WriteMeta(const QString &name, const QString &content, QXmlStreamWriter *writer) {
|
||||
|
||||
writer->writeStartElement(QLatin1String("meta"));
|
||||
writer->writeAttribute(QLatin1String("name"), name);
|
||||
writer->writeAttribute(QLatin1String("content"), content);
|
||||
writer->writeStartElement("meta"_L1);
|
||||
writer->writeAttribute("name"_L1, name);
|
||||
writer->writeAttribute("content"_L1, content);
|
||||
writer->writeEndElement();
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#include "xmlparser.h"
|
||||
#include "xspfparser.h"
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
XSPFParser::XSPFParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
|
||||
@@ -75,22 +77,22 @@ Song XSPFParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const boo
|
||||
QString name = reader->name().toString();
|
||||
switch (type) {
|
||||
case QXmlStreamReader::StartElement:{
|
||||
if (name == QLatin1String("location")) {
|
||||
if (name == "location"_L1) {
|
||||
location = QUrl::fromPercentEncoding(reader->readElementText().toUtf8());
|
||||
}
|
||||
else if (name == QLatin1String("title")) {
|
||||
else if (name == "title"_L1) {
|
||||
title = reader->readElementText();
|
||||
}
|
||||
else if (name == QLatin1String("creator")) {
|
||||
else if (name == "creator"_L1) {
|
||||
artist = reader->readElementText();
|
||||
}
|
||||
else if (name == QLatin1String("album")) {
|
||||
else if (name == "album"_L1) {
|
||||
album = reader->readElementText();
|
||||
}
|
||||
else if (name == QLatin1String("image")) {
|
||||
else if (name == "image"_L1) {
|
||||
art = QUrl::fromPercentEncoding(reader->readElementText().toUtf8());
|
||||
}
|
||||
else if (name == QLatin1String("duration")) { // in milliseconds.
|
||||
else if (name == "duration"_L1) { // in milliseconds.
|
||||
const QString duration = reader->readElementText();
|
||||
bool ok = false;
|
||||
nanosec = duration.toInt(&ok) * kNsecPerMsec;
|
||||
@@ -98,7 +100,7 @@ Song XSPFParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const boo
|
||||
nanosec = -1;
|
||||
}
|
||||
}
|
||||
else if (name == QLatin1String("trackNum")) {
|
||||
else if (name == "trackNum"_L1) {
|
||||
const QString track_num_str = reader->readElementText();
|
||||
bool ok = false;
|
||||
track_num = track_num_str.toInt(&ok);
|
||||
@@ -106,13 +108,13 @@ Song XSPFParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const boo
|
||||
track_num = -1;
|
||||
}
|
||||
}
|
||||
else if (name == QLatin1String("info")) {
|
||||
else if (name == "info"_L1) {
|
||||
// TODO: Do something with extra info?
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QXmlStreamReader::EndElement:{
|
||||
if (name == QLatin1String("track")) {
|
||||
if (name == "track"_L1) {
|
||||
goto return_song;
|
||||
}
|
||||
}
|
||||
@@ -145,8 +147,8 @@ void XSPFParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
|
||||
writer.setAutoFormattingIndent(2);
|
||||
writer.writeStartDocument();
|
||||
StreamElement playlist(QStringLiteral("playlist"), &writer);
|
||||
writer.writeAttribute(QLatin1String("version"), QLatin1String("1"));
|
||||
writer.writeDefaultNamespace(QLatin1String("http://xspf.org/ns/0/"));
|
||||
writer.writeAttribute("version"_L1, "1"_L1);
|
||||
writer.writeDefaultNamespace("http://xspf.org/ns/0/"_L1);
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(PlaylistSettingsPage::kSettingsGroup);
|
||||
@@ -158,23 +160,23 @@ void XSPFParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
|
||||
QString filename_or_url = QString::fromLatin1(QUrl::toPercentEncoding(URLOrFilename(song.url(), dir, path_type), "/ "));
|
||||
|
||||
StreamElement track(QStringLiteral("track"), &writer);
|
||||
writer.writeTextElement(QLatin1String("location"), filename_or_url);
|
||||
writer.writeTextElement("location"_L1, filename_or_url);
|
||||
|
||||
if (write_metadata || (song.is_stream() && !song.is_radio())) {
|
||||
writer.writeTextElement(QLatin1String("title"), song.title());
|
||||
writer.writeTextElement("title"_L1, song.title());
|
||||
if (!song.artist().isEmpty()) {
|
||||
writer.writeTextElement(QLatin1String("creator"), song.artist());
|
||||
writer.writeTextElement("creator"_L1, song.artist());
|
||||
}
|
||||
if (!song.album().isEmpty()) {
|
||||
writer.writeTextElement(QLatin1String("album"), song.album());
|
||||
writer.writeTextElement("album"_L1, song.album());
|
||||
}
|
||||
if (song.length_nanosec() != -1) {
|
||||
writer.writeTextElement(QLatin1String("duration"), QString::number(song.length_nanosec() / kNsecPerMsec));
|
||||
writer.writeTextElement("duration"_L1, QString::number(song.length_nanosec() / kNsecPerMsec));
|
||||
}
|
||||
}
|
||||
|
||||
if ((write_metadata || song.has_cue() || (song.is_stream() && !song.is_radio())) && song.track() > 0) {
|
||||
writer.writeTextElement(QLatin1String("trackNum"), QString::number(song.track()));
|
||||
writer.writeTextElement("trackNum"_L1, QString::number(song.track()));
|
||||
}
|
||||
|
||||
if (write_metadata || (song.is_stream() && !song.is_radio())) {
|
||||
@@ -182,7 +184,7 @@ void XSPFParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
|
||||
// Ignore images that are in our resource bundle.
|
||||
if (!cover_url.isEmpty() && cover_url.isValid()) {
|
||||
const QString cover_filename = QString::fromLatin1(QUrl::toPercentEncoding(URLOrFilename(cover_url, dir, path_type), "/ "));
|
||||
writer.writeTextElement(QLatin1String("image"), cover_filename);
|
||||
writer.writeTextElement("image"_L1, cover_filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class XSPFParser : public XMLParser {
|
||||
|
||||
bool TryMagic(const QByteArray &data) const override;
|
||||
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = QLatin1String(""), const QDir &dir = QDir(), const bool collection_lookup = true) const override;
|
||||
SongList Load(QIODevice *device, const QString &playlist_path = ""_L1, const QDir &dir = QDir(), const bool collection_lookup = true) const override;
|
||||
void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType::Automatic) const override;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user