Disable automatic conversions from 8-bit strings
This commit is contained in:
@@ -54,7 +54,7 @@ SongList AsxIniParser::Load(QIODevice *device, const QString &playlist_path, con
|
||||
|
||||
while (!device->atEnd()) {
|
||||
QString line = QString::fromUtf8(device->readLine()).trimmed();
|
||||
qint64 equals = line.indexOf('=');
|
||||
qint64 equals = line.indexOf(QLatin1Char('='));
|
||||
QString key = line.left(equals).toLower();
|
||||
QString value = line.mid(equals + 1);
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ SongList ASXParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
// Some playlists have unescaped & characters in URLs :(
|
||||
QRegularExpression ex(QStringLiteral("(href\\s*=\\s*\")([^\"]+)\""), QRegularExpression::CaseInsensitiveOption);
|
||||
qint64 index = 0;
|
||||
for (QRegularExpressionMatch re_match = ex.match(data, index); re_match.hasMatch(); re_match = ex.match(data, index)) {
|
||||
for (QRegularExpressionMatch re_match = ex.match(QString::fromUtf8(data), index); re_match.hasMatch(); re_match = ex.match(QString::fromUtf8(data), index)) {
|
||||
index = re_match.capturedStart();
|
||||
QString url = re_match.captured(2);
|
||||
url.replace(QRegularExpression(QStringLiteral("&(?!amp;|quot;|apos;|lt;|gt;)")), QStringLiteral("&"));
|
||||
@@ -91,22 +91,22 @@ Song ASXParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const bool
|
||||
QXmlStreamReader::TokenType type = reader->readNext();
|
||||
|
||||
switch (type) {
|
||||
case QXmlStreamReader::StartElement: {
|
||||
QString name = reader->name().toString().toLower();
|
||||
if (name == "ref") {
|
||||
ref = reader->attributes().value("href").toString();
|
||||
case QXmlStreamReader::StartElement:{
|
||||
const QString name = reader->name().toString().toLower();
|
||||
if (name == QStringLiteral("ref")) {
|
||||
ref = reader->attributes().value(QStringLiteral("href")).toString();
|
||||
}
|
||||
else if (name == "title") {
|
||||
else if (name == QStringLiteral("title")) {
|
||||
title = reader->readElementText();
|
||||
}
|
||||
else if (name == "author") {
|
||||
else if (name == QStringLiteral("author")) {
|
||||
artist = reader->readElementText();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QXmlStreamReader::EndElement: {
|
||||
QString name = reader->name().toString().toLower();
|
||||
if (name == "entry") {
|
||||
case QXmlStreamReader::EndElement:{
|
||||
const QString name = reader->name().toString().toLower();
|
||||
if (name == QStringLiteral("entry")) {
|
||||
goto return_song;
|
||||
}
|
||||
break;
|
||||
@@ -138,16 +138,16 @@ void ASXParser::Save(const SongList &songs, QIODevice *device, const QDir&, cons
|
||||
writer.writeStartDocument();
|
||||
{
|
||||
StreamElement asx(QStringLiteral("asx"), &writer);
|
||||
writer.writeAttribute("version", "3.0");
|
||||
writer.writeAttribute(QStringLiteral("version"), QStringLiteral("3.0"));
|
||||
for (const Song &song : songs) {
|
||||
StreamElement entry(QStringLiteral("entry"), &writer);
|
||||
writer.writeTextElement("title", song.title());
|
||||
writer.writeTextElement(QStringLiteral("title"), song.title());
|
||||
{
|
||||
StreamElement ref(QStringLiteral("ref"), &writer);
|
||||
writer.writeAttribute("href", song.url().toString());
|
||||
writer.writeAttribute(QStringLiteral("href"), song.url().toString());
|
||||
}
|
||||
if (!song.artist().isEmpty()) {
|
||||
writer.writeTextElement("author", song.artist());
|
||||
writer.writeTextElement(QStringLiteral("author"), song.artist());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,22 +43,24 @@
|
||||
|
||||
class CollectionBackendInterface;
|
||||
|
||||
const char *CueParser::kFileLineRegExp = "(\\S+)\\s+(?:\"([^\"]+)\"|(\\S+))\\s*(?:\"([^\"]+)\"|(\\S+))?";
|
||||
const char *CueParser::kIndexRegExp = "(\\d{1,3}):(\\d{2}):(\\d{2})";
|
||||
namespace {
|
||||
constexpr char kFileLineRegExp[] = "(\\S+)\\s+(?:\"([^\"]+)\"|(\\S+))\\s*(?:\"([^\"]+)\"|(\\S+))?";
|
||||
constexpr char kIndexRegExp[] = "(\\d{1,3}):(\\d{2}):(\\d{2})";
|
||||
|
||||
const char *CueParser::kPerformer = "performer";
|
||||
const char *CueParser::kTitle = "title";
|
||||
const char *CueParser::kSongWriter = "songwriter";
|
||||
constexpr char kPerformer[] = "performer";
|
||||
constexpr char kTitle[] = "title";
|
||||
constexpr char kSongWriter[] = "songwriter";
|
||||
// composer may be in cue file and is synonym for songwriter
|
||||
const char *CueParser::kComposer = "composer";
|
||||
const char *CueParser::kFile = "file";
|
||||
const char *CueParser::kTrack = "track";
|
||||
const char *CueParser::kIndex = "index";
|
||||
const char *CueParser::kAudioTrackType = "audio";
|
||||
const char *CueParser::kRem = "rem";
|
||||
const char *CueParser::kGenre = "genre";
|
||||
const char *CueParser::kDate = "date";
|
||||
const char *CueParser::kDisc = "discnumber";
|
||||
constexpr char kComposer[] = "composer";
|
||||
constexpr char kFile[] = "file";
|
||||
constexpr char kTrack[] = "track";
|
||||
constexpr char kIndex[] = "index";
|
||||
constexpr char kAudioTrackType[] = "audio";
|
||||
constexpr char kRem[] = "rem";
|
||||
constexpr char kGenre[] = "genre";
|
||||
constexpr char kDate[] = "date";
|
||||
constexpr char kDisc[] = "discnumber";
|
||||
} // namespace
|
||||
|
||||
CueParser::CueParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent)
|
||||
: ParserBase(collection_backend, parent) {}
|
||||
@@ -106,40 +108,40 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
const QString &line_name = splitted[0];
|
||||
const QString &line_value = splitted[1];
|
||||
|
||||
if (line_name.compare(kPerformer, Qt::CaseInsensitive) == 0) {
|
||||
if (line_name.compare(QLatin1String(kPerformer), Qt::CaseInsensitive) == 0) {
|
||||
album_artist = line_value;
|
||||
}
|
||||
else if (line_name.compare(kTitle, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kTitle), Qt::CaseInsensitive) == 0) {
|
||||
album = line_value;
|
||||
}
|
||||
else if (line_name.compare(kSongWriter, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kSongWriter), Qt::CaseInsensitive) == 0) {
|
||||
album_composer = line_value;
|
||||
}
|
||||
else if (line_name.compare(kComposer, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kComposer), Qt::CaseInsensitive) == 0) {
|
||||
album_composer = line_value;
|
||||
}
|
||||
else if (line_name.compare(kFile, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kFile), Qt::CaseInsensitive) == 0) {
|
||||
file = QDir::isAbsolutePath(line_value) ? line_value : dir.absoluteFilePath(line_value);
|
||||
if (splitted.size() > 2) {
|
||||
file_type = splitted[2];
|
||||
}
|
||||
}
|
||||
else if (line_name.compare(kRem, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kRem), Qt::CaseInsensitive) == 0) {
|
||||
if (splitted.size() < 3) {
|
||||
break;
|
||||
}
|
||||
if (line_value.compare(kGenre, Qt::CaseInsensitive) == 0) {
|
||||
if (line_value.compare(QLatin1String(kGenre), Qt::CaseInsensitive) == 0) {
|
||||
album_genre = splitted[2];
|
||||
}
|
||||
else if (line_value.compare(kDate, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_value.compare(QLatin1String(kDate), Qt::CaseInsensitive) == 0) {
|
||||
album_date = splitted[2];
|
||||
}
|
||||
else if (line_value.compare(kDisc, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_value.compare(QLatin1String(kDisc), Qt::CaseInsensitive) == 0) {
|
||||
disc = splitted[2];
|
||||
}
|
||||
}
|
||||
// end of the header -> go into the track mode
|
||||
else if (line_name.compare(kTrack, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kTrack), Qt::CaseInsensitive) == 0) {
|
||||
files++;
|
||||
break;
|
||||
}
|
||||
@@ -175,11 +177,11 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
const QString &line_value = splitted[1];
|
||||
QString line_additional = splitted.size() > 2 ? splitted[2].toLower() : QLatin1String("");
|
||||
|
||||
if (line_name.compare(kTrack, Qt::CaseInsensitive) == 0) {
|
||||
if (line_name.compare(QLatin1String(kTrack), Qt::CaseInsensitive) == 0) {
|
||||
|
||||
// the beginning of another track's definition - we're saving the current one for later (if it's valid of course)
|
||||
// please note that the same code is repeated just after this 'do-while' loop
|
||||
if (valid_file && !index.isEmpty() && (track_type.isEmpty() || track_type.compare(kAudioTrackType, Qt::CaseInsensitive) == 0)) {
|
||||
if (valid_file && !index.isEmpty() && (track_type.isEmpty() || track_type.compare(QLatin1String(kAudioTrackType), Qt::CaseInsensitive) == 0)) {
|
||||
entries.append(CueEntry(file, index, title, artist, album_artist, album, composer, album_composer, (genre.isEmpty() ? album_genre : genre), (date.isEmpty() ? album_date : date), disc));
|
||||
}
|
||||
|
||||
@@ -191,43 +193,43 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
}
|
||||
|
||||
}
|
||||
else if (line_name.compare(kIndex, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kIndex), Qt::CaseInsensitive) == 0) {
|
||||
|
||||
// We need the index's position field
|
||||
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 == "01" || index.isEmpty()) {
|
||||
if (line_value == QStringLiteral("01") || index.isEmpty()) {
|
||||
|
||||
index = line_additional;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (line_name.compare(kTitle, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kTitle), Qt::CaseInsensitive) == 0) {
|
||||
title = line_value;
|
||||
}
|
||||
else if (line_name.compare(kDate, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kDate), Qt::CaseInsensitive) == 0) {
|
||||
date = line_value;
|
||||
}
|
||||
else if (line_name.compare(kPerformer, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kPerformer), Qt::CaseInsensitive) == 0) {
|
||||
artist = line_value;
|
||||
}
|
||||
else if (line_name.compare(kSongWriter, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kSongWriter), Qt::CaseInsensitive) == 0) {
|
||||
composer = line_value;
|
||||
}
|
||||
else if (line_name.compare(kComposer, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kComposer), Qt::CaseInsensitive) == 0) {
|
||||
composer = line_value;
|
||||
}
|
||||
// End of tracks for the current file -> parse next one
|
||||
else if (line_name.compare(kRem, Qt::CaseInsensitive) == 0 && splitted.size() >= 3) {
|
||||
if (line_value.compare(kGenre, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kRem), Qt::CaseInsensitive) == 0 && splitted.size() >= 3) {
|
||||
if (line_value.compare(QLatin1String(kGenre), Qt::CaseInsensitive) == 0) {
|
||||
genre = splitted[2];
|
||||
}
|
||||
else if (line_value.compare(kDate, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_value.compare(QLatin1String(kDate), Qt::CaseInsensitive) == 0) {
|
||||
date = splitted[2];
|
||||
}
|
||||
}
|
||||
else if (line_name.compare(kFile, Qt::CaseInsensitive) == 0) {
|
||||
else if (line_name.compare(QLatin1String(kFile), Qt::CaseInsensitive) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -235,7 +237,7 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
} while (!(line = text_stream.readLine()).isNull());
|
||||
|
||||
// We didn't add the last song yet...
|
||||
if (valid_file && !index.isEmpty() && (track_type.isEmpty() || track_type.compare(kAudioTrackType, Qt::CaseInsensitive) == 0)) {
|
||||
if (valid_file && !index.isEmpty() && (track_type.isEmpty() || track_type.compare(QLatin1String(kAudioTrackType), Qt::CaseInsensitive) == 0)) {
|
||||
entries.append(CueEntry(file, index, title, artist, album_artist, album, composer, album_composer, (genre.isEmpty() ? album_genre : genre), (date.isEmpty() ? album_date : date), disc));
|
||||
}
|
||||
}
|
||||
@@ -285,7 +287,7 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
// line into logical parts and getting rid of all the unnecessary whitespaces and quoting.
|
||||
QStringList CueParser::SplitCueLine(const QString &line) {
|
||||
|
||||
QRegularExpression line_regexp(kFileLineRegExp);
|
||||
QRegularExpression line_regexp(QString::fromLatin1(kFileLineRegExp));
|
||||
QRegularExpressionMatch re_match = line_regexp.match(line.trimmed());
|
||||
if (!re_match.hasMatch()) {
|
||||
return QStringList();
|
||||
@@ -356,7 +358,7 @@ bool CueParser::UpdateLastSong(const CueEntry &entry, Song *song) {
|
||||
|
||||
qint64 CueParser::IndexToMarker(const QString &index) {
|
||||
|
||||
QRegularExpression index_regexp(kIndexRegExp);
|
||||
QRegularExpression index_regexp(QString::fromLatin1(kIndexRegExp));
|
||||
QRegularExpressionMatch re_match = index_regexp.match(index);
|
||||
if (!re_match.hasMatch()) {
|
||||
return -1;
|
||||
@@ -382,14 +384,14 @@ 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('\n');
|
||||
QStringList splitted = QString::fromUtf8(data.constData()).split(QLatin1Char('\n'));
|
||||
|
||||
for (int i = 0; i < splitted.length(); i++) {
|
||||
QString line = splitted.at(i).trimmed();
|
||||
if (line.startsWith(kPerformer, Qt::CaseInsensitive) ||
|
||||
line.startsWith(kTitle, Qt::CaseInsensitive) ||
|
||||
line.startsWith(kFile, Qt::CaseInsensitive) ||
|
||||
line.startsWith(kTrack, Qt::CaseInsensitive)) {
|
||||
if (line.startsWith(QLatin1String(kPerformer), Qt::CaseInsensitive) ||
|
||||
line.startsWith(QLatin1String(kTitle), Qt::CaseInsensitive) ||
|
||||
line.startsWith(QLatin1String(kFile), Qt::CaseInsensitive) ||
|
||||
line.startsWith(QLatin1String(kTrack), Qt::CaseInsensitive)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -400,8 +402,8 @@ bool CueParser::TryMagic(const QByteArray &data) const {
|
||||
|
||||
QString CueParser::FindCueFilename(const QString &filename) {
|
||||
|
||||
QStringList cue_files = QStringList() << filename + ".cue"
|
||||
<< filename.section('.', 0, -2) + ".cue";
|
||||
QStringList cue_files = QStringList() << filename + QStringLiteral(".cue")
|
||||
<< filename.section(QLatin1Char('.'), 0, -2) + QStringLiteral(".cue");
|
||||
|
||||
for (const QString &cuefile : cue_files) {
|
||||
if (QFileInfo::exists(cuefile)) return cuefile;
|
||||
|
||||
@@ -45,22 +45,6 @@ class CueParser : public ParserBase {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static const char *kFileLineRegExp;
|
||||
static const char *kIndexRegExp;
|
||||
|
||||
static const char *kPerformer;
|
||||
static const char *kTitle;
|
||||
static const char *kSongWriter;
|
||||
static const char *kComposer;
|
||||
static const char *kFile;
|
||||
static const char *kTrack;
|
||||
static const char *kIndex;
|
||||
static const char *kAudioTrackType;
|
||||
static const char *kRem;
|
||||
static const char *kGenre;
|
||||
static const char *kDate;
|
||||
static const char *kDisc;
|
||||
|
||||
explicit CueParser(SharedPtr<CollectionBackendInterface> collection_backend, QObject *parent = nullptr);
|
||||
|
||||
QString name() const override { return QStringLiteral("CUE"); }
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/settings.h"
|
||||
#include "utilities/timeconstants.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
#include "parserbase.h"
|
||||
@@ -47,7 +48,7 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
Metadata current_metadata;
|
||||
|
||||
QString data = QString::fromUtf8(device->readAll());
|
||||
data.replace('\r', '\n');
|
||||
data.replace(QLatin1Char('\r'), QLatin1Char('\n'));
|
||||
data.replace(QLatin1String("\n\n"), QLatin1String("\n"));
|
||||
QByteArray bytes = data.toUtf8();
|
||||
QBuffer buffer(&bytes);
|
||||
@@ -62,7 +63,7 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
|
||||
SongList ret;
|
||||
forever {
|
||||
if (line.startsWith('#')) {
|
||||
if (line.startsWith(QLatin1Char('#'))) {
|
||||
// Extended info or comment.
|
||||
if (type == M3UType::EXTENDED && line.startsWith(QLatin1String("#EXT"))) {
|
||||
if (!ParseMetadata(line, ¤t_metadata)) {
|
||||
@@ -101,8 +102,8 @@ bool M3UParser::ParseMetadata(const QString &line, M3UParser::Metadata *metadata
|
||||
|
||||
// Extended info, eg.
|
||||
// #EXTINF:123,Sample Artist - Sample title
|
||||
QString info = line.section(':', 1);
|
||||
QString l = info.section(',', 0, 0);
|
||||
QString info = line.section(QLatin1Char(':'), 1);
|
||||
QString l = info.section(QLatin1Char(','), 0, 0);
|
||||
bool ok = false;
|
||||
int length = l.toInt(&ok);
|
||||
if (!ok) {
|
||||
@@ -110,7 +111,7 @@ bool M3UParser::ParseMetadata(const QString &line, M3UParser::Metadata *metadata
|
||||
}
|
||||
metadata->length = length * kNsecPerSec;
|
||||
|
||||
QString track_info = info.section(',', 1);
|
||||
QString track_info = info.section(QLatin1Char(','), 1);
|
||||
QStringList list = track_info.split(QStringLiteral(" - "));
|
||||
if (list.size() <= 1) {
|
||||
metadata->title = track_info;
|
||||
@@ -126,7 +127,7 @@ void M3UParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
|
||||
|
||||
device->write("#EXTM3U\n");
|
||||
|
||||
QSettings s;
|
||||
Settings s;
|
||||
s.beginGroup(PlaylistSettingsPage::kSettingsGroup);
|
||||
bool write_metadata = s.value("write_metadata", true).toBool();
|
||||
s.endGroup();
|
||||
|
||||
@@ -65,7 +65,7 @@ void ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning
|
||||
|
||||
// Strawberry always wants / separators internally.
|
||||
// Using QDir::fromNativeSeparators() only works on the same platform the playlist was created on/for, using replace() lets playlists work on any platform.
|
||||
filename = filename.replace('\\', '/');
|
||||
filename = filename.replace(QLatin1Char('\\'), QLatin1Char('/'));
|
||||
|
||||
// Make the path absolute
|
||||
if (!QDir::isAbsolutePath(filename)) {
|
||||
|
||||
@@ -113,7 +113,7 @@ QString PlaylistParser::FilterForParser(const ParserBase *parser, QStringList *a
|
||||
QStringList extensions;
|
||||
extensions.reserve(file_extensions.count());
|
||||
for (const QString &extension : file_extensions) {
|
||||
extensions << "*." + extension;
|
||||
extensions << QStringLiteral("*.") + extension;
|
||||
}
|
||||
|
||||
if (all_extensions) *all_extensions << extensions;
|
||||
|
||||
@@ -54,7 +54,7 @@ SongList PLSParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
|
||||
while (!device->atEnd()) {
|
||||
QString line = QString::fromUtf8(device->readLine()).trimmed();
|
||||
qint64 equals = line.indexOf('=');
|
||||
qint64 equals = line.indexOf(QLatin1Char('='));
|
||||
QString key = line.left(equals).toLower();
|
||||
QString value = line.mid(equals + 1);
|
||||
|
||||
|
||||
@@ -68,9 +68,9 @@ void WplParser::ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *so
|
||||
QXmlStreamReader::TokenType type = reader->readNext();
|
||||
QString name = reader->name().toString();
|
||||
switch (type) {
|
||||
case QXmlStreamReader::StartElement: {
|
||||
if (name == "media") {
|
||||
QString src = reader->attributes().value("src").toString();
|
||||
case QXmlStreamReader::StartElement:{
|
||||
if (name == QStringLiteral("media")) {
|
||||
QString src = reader->attributes().value(QStringLiteral("src")).toString();
|
||||
if (!src.isEmpty()) {
|
||||
Song song = LoadSong(src, 0, 0, dir, collection_search);
|
||||
if (song.is_valid()) {
|
||||
@@ -83,8 +83,8 @@ void WplParser::ParseSeq(const QDir &dir, QXmlStreamReader *reader, SongList *so
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QXmlStreamReader::EndElement: {
|
||||
if (name == "seq") {
|
||||
case QXmlStreamReader::EndElement:{
|
||||
if (name == QStringLiteral("seq")) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -101,13 +101,13 @@ void WplParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
|
||||
QXmlStreamWriter writer(device);
|
||||
writer.setAutoFormatting(true);
|
||||
writer.setAutoFormattingIndent(2);
|
||||
writer.writeProcessingInstruction("wpl", "version=\"1.0\"");
|
||||
writer.writeProcessingInstruction(QStringLiteral("wpl"), QStringLiteral("version=\"1.0\""));
|
||||
|
||||
StreamElement smil(QStringLiteral("smil"), &writer);
|
||||
|
||||
{
|
||||
StreamElement head(QStringLiteral("head"), &writer);
|
||||
WriteMeta(QStringLiteral("Generator"), "Strawberry -- " STRAWBERRY_VERSION_DISPLAY, &writer);
|
||||
WriteMeta(QStringLiteral("Generator"), QStringLiteral("Strawberry -- ") + QLatin1String(STRAWBERRY_VERSION_DISPLAY), &writer);
|
||||
WriteMeta(QStringLiteral("ItemCount"), QString::number(songs.count()), &writer);
|
||||
}
|
||||
|
||||
@@ -116,8 +116,8 @@ void WplParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
|
||||
{
|
||||
StreamElement seq(QStringLiteral("seq"), &writer);
|
||||
for (const Song &song : songs) {
|
||||
writer.writeStartElement("media");
|
||||
writer.writeAttribute("src", URLOrFilename(song.url(), dir, path_type));
|
||||
writer.writeStartElement(QStringLiteral("media"));
|
||||
writer.writeAttribute(QStringLiteral("src"), URLOrFilename(song.url(), dir, path_type));
|
||||
writer.writeEndElement();
|
||||
}
|
||||
}
|
||||
@@ -126,9 +126,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("meta");
|
||||
writer->writeAttribute("name", name);
|
||||
writer->writeAttribute("content", content);
|
||||
writer->writeStartElement(QStringLiteral("meta"));
|
||||
writer->writeAttribute(QStringLiteral("name"), name);
|
||||
writer->writeAttribute(QStringLiteral("content"), content);
|
||||
writer->writeEndElement();
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/settings.h"
|
||||
#include "utilities/xmlutils.h"
|
||||
#include "utilities/timeconstants.h"
|
||||
#include "settings/playlistsettingspage.h"
|
||||
@@ -72,23 +73,23 @@ Song XSPFParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const boo
|
||||
QXmlStreamReader::TokenType type = reader->readNext();
|
||||
QString name = reader->name().toString();
|
||||
switch (type) {
|
||||
case QXmlStreamReader::StartElement: {
|
||||
if (name == "location") {
|
||||
case QXmlStreamReader::StartElement:{
|
||||
if (name == QStringLiteral("location")) {
|
||||
location = QUrl::fromPercentEncoding(reader->readElementText().toUtf8());
|
||||
}
|
||||
else if (name == "title") {
|
||||
else if (name == QStringLiteral("title")) {
|
||||
title = reader->readElementText();
|
||||
}
|
||||
else if (name == "creator") {
|
||||
else if (name == QStringLiteral("creator")) {
|
||||
artist = reader->readElementText();
|
||||
}
|
||||
else if (name == "album") {
|
||||
else if (name == QStringLiteral("album")) {
|
||||
album = reader->readElementText();
|
||||
}
|
||||
else if (name == "image") {
|
||||
else if (name == QStringLiteral("image")) {
|
||||
art = QUrl::fromPercentEncoding(reader->readElementText().toUtf8());
|
||||
}
|
||||
else if (name == "duration") { // in milliseconds.
|
||||
else if (name == QStringLiteral("duration")) { // in milliseconds.
|
||||
const QString duration = reader->readElementText();
|
||||
bool ok = false;
|
||||
nanosec = duration.toInt(&ok) * kNsecPerMsec;
|
||||
@@ -96,7 +97,7 @@ Song XSPFParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const boo
|
||||
nanosec = -1;
|
||||
}
|
||||
}
|
||||
else if (name == "trackNum") {
|
||||
else if (name == QStringLiteral("trackNum")) {
|
||||
const QString track_num_str = reader->readElementText();
|
||||
bool ok = false;
|
||||
track_num = track_num_str.toInt(&ok);
|
||||
@@ -104,13 +105,13 @@ Song XSPFParser::ParseTrack(QXmlStreamReader *reader, const QDir &dir, const boo
|
||||
track_num = -1;
|
||||
}
|
||||
}
|
||||
else if (name == "info") {
|
||||
else if (name == QStringLiteral("info")) {
|
||||
// TODO: Do something with extra info?
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QXmlStreamReader::EndElement: {
|
||||
if (name == "track") {
|
||||
case QXmlStreamReader::EndElement:{
|
||||
if (name == QStringLiteral("track")) {
|
||||
goto return_song;
|
||||
}
|
||||
}
|
||||
@@ -143,44 +144,44 @@ void XSPFParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
|
||||
writer.setAutoFormattingIndent(2);
|
||||
writer.writeStartDocument();
|
||||
StreamElement playlist(QStringLiteral("playlist"), &writer);
|
||||
writer.writeAttribute("version", "1");
|
||||
writer.writeDefaultNamespace("http://xspf.org/ns/0/");
|
||||
writer.writeAttribute(QStringLiteral("version"), QStringLiteral("1"));
|
||||
writer.writeDefaultNamespace(QStringLiteral("http://xspf.org/ns/0/"));
|
||||
|
||||
QSettings s;
|
||||
Settings s;
|
||||
s.beginGroup(PlaylistSettingsPage::kSettingsGroup);
|
||||
bool write_metadata = s.value("write_metadata", true).toBool();
|
||||
s.endGroup();
|
||||
|
||||
StreamElement tracklist(QStringLiteral("trackList"), &writer);
|
||||
for (const Song &song : songs) {
|
||||
QString filename_or_url = QUrl::toPercentEncoding(URLOrFilename(song.url(), dir, path_type), "/ ");
|
||||
QString filename_or_url = QString::fromLatin1(QUrl::toPercentEncoding(URLOrFilename(song.url(), dir, path_type), "/ "));
|
||||
|
||||
StreamElement track(QStringLiteral("track"), &writer);
|
||||
writer.writeTextElement("location", filename_or_url);
|
||||
writer.writeTextElement(QStringLiteral("location"), filename_or_url);
|
||||
|
||||
if (write_metadata || (song.is_stream() && !song.is_radio())) {
|
||||
writer.writeTextElement("title", song.title());
|
||||
writer.writeTextElement(QStringLiteral("title"), song.title());
|
||||
if (!song.artist().isEmpty()) {
|
||||
writer.writeTextElement("creator", song.artist());
|
||||
writer.writeTextElement(QStringLiteral("creator"), song.artist());
|
||||
}
|
||||
if (!song.album().isEmpty()) {
|
||||
writer.writeTextElement("album", song.album());
|
||||
writer.writeTextElement(QStringLiteral("album"), song.album());
|
||||
}
|
||||
if (song.length_nanosec() != -1) {
|
||||
writer.writeTextElement("duration", QString::number(song.length_nanosec() / kNsecPerMsec));
|
||||
writer.writeTextElement(QStringLiteral("duration"), QString::number(song.length_nanosec() / kNsecPerMsec));
|
||||
}
|
||||
}
|
||||
|
||||
if ((write_metadata || song.has_cue() || (song.is_stream() && !song.is_radio())) && song.track() > 0) {
|
||||
writer.writeTextElement("trackNum", QString::number(song.track()));
|
||||
writer.writeTextElement(QStringLiteral("trackNum"), QString::number(song.track()));
|
||||
}
|
||||
|
||||
if (write_metadata || (song.is_stream() && !song.is_radio())) {
|
||||
const QUrl cover_url = song.art_manual().isEmpty() || !song.art_manual().isValid() ? song.art_automatic() : song.art_manual();
|
||||
// Ignore images that are in our resource bundle.
|
||||
if (!cover_url.isEmpty() && cover_url.isValid()) {
|
||||
const QString cover_filename = QUrl::toPercentEncoding(URLOrFilename(cover_url, dir, path_type), "/ ");
|
||||
writer.writeTextElement("image", cover_filename);
|
||||
const QString cover_filename = QString::fromLatin1(QUrl::toPercentEncoding(URLOrFilename(cover_url, dir, path_type), "/ "));
|
||||
writer.writeTextElement(QStringLiteral("image"), cover_filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user