Use C++11 enum class

This commit is contained in:
Jonas Kvinge
2023-02-18 14:09:27 +01:00
parent e6c5f76872
commit dd72fb4ca5
237 changed files with 2915 additions and 2840 deletions

View File

@@ -49,7 +49,7 @@ class AsxIniParser : public ParserBase {
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(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_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

View File

@@ -119,7 +119,7 @@ return_song:
Song song = LoadSong(ref, 0, dir, collection_search);
// Override metadata with what was in the playlist
if (song.source() != Song::Source_Collection) {
if (song.source() != Song::Source::Collection) {
if (!title.isEmpty()) song.set_title(title);
if (!artist.isEmpty()) song.set_artist(artist);
if (!album.isEmpty()) song.set_album(album);

View File

@@ -51,7 +51,7 @@ class ASXParser : public XMLParser {
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(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_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;

View File

@@ -70,7 +70,7 @@ class CueParser : public ParserBase {
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(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_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);

View File

@@ -42,7 +42,7 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
Q_UNUSED(playlist_path);
M3UType type = STANDARD;
M3UType type = M3UType::STANDARD;
Metadata current_metadata;
QString data = QString::fromUtf8(device->readAll());
@@ -55,7 +55,7 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
QString line = QString::fromUtf8(buffer.readLine()).trimmed();
if (line.startsWith("#EXTM3U")) {
// This is in extended M3U format.
type = EXTENDED;
type = M3UType::EXTENDED;
line = QString::fromUtf8(buffer.readLine()).trimmed();
}
@@ -63,7 +63,7 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
forever {
if (line.startsWith('#')) {
// Extended info or comment.
if (type == EXTENDED && line.startsWith("#EXT")) {
if (type == M3UType::EXTENDED && line.startsWith("#EXT")) {
if (!ParseMetadata(line, &current_metadata)) {
qLog(Warning) << "Failed to parse metadata: " << line;
}

View File

@@ -52,10 +52,10 @@ class M3UParser : public ParserBase {
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(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_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 {
enum class M3UType {
STANDARD = 0,
EXTENDED, // Includes extended info (track, artist, etc.)
LINK, // Points to a directory.

View File

@@ -47,12 +47,12 @@ void ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning
if (filename_or_url.contains(QRegularExpression("^[a-z]{2,}:", QRegularExpression::CaseInsensitiveOption))) {
QUrl url(filename_or_url);
song->set_source(Song::SourceFromURL(url));
if (song->source() == Song::Source_LocalFile) {
if (song->source() == Song::Source::LocalFile) {
filename = url.toLocalFile();
}
else if (song->is_stream()) {
song->set_url(QUrl::fromUserInput(filename_or_url));
song->set_filetype(Song::FileType_Stream);
song->set_filetype(Song::FileType::Stream);
song->set_valid(true);
return;
}
@@ -94,7 +94,7 @@ void ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning
Song ParserBase::LoadSong(const QString &filename_or_url, const qint64 beginning, const QDir &dir, const bool collection_search) const {
Song song(Song::Source_LocalFile);
Song song(Song::Source::LocalFile);
LoadSong(filename_or_url, beginning, dir, &song, collection_search);
return song;
@@ -107,10 +107,10 @@ QString ParserBase::URLOrFilename(const QUrl &url, const QDir &dir, const Playli
const QString filename = url.toLocalFile();
if (path_type != PlaylistSettingsPage::PathType_Absolute && QDir::isAbsolutePath(filename)) {
if (path_type != PlaylistSettingsPage::PathType::Absolute && QDir::isAbsolutePath(filename)) {
const QString relative = dir.relativeFilePath(filename);
if (!relative.startsWith("../") || path_type == PlaylistSettingsPage::PathType_Relative) {
if (!relative.startsWith("../") || path_type == PlaylistSettingsPage::PathType::Relative) {
return relative;
}
}

View File

@@ -57,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(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_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.

View File

@@ -98,7 +98,7 @@ QString PlaylistParser::filters(const Type type) const {
}
}
if (type == Type_Load) {
if (type == Type::Load) {
filters.prepend(tr("All playlists (%1)").arg(all_extensions.join(" ")));
}
@@ -168,7 +168,7 @@ SongList PlaylistParser::LoadFromFile(const QString &filename) const {
QFileInfo fileinfo(filename);
// Find a parser that supports this file extension
ParserBase *parser = ParserForExtension(Type_Load, fileinfo.suffix());
ParserBase *parser = ParserForExtension(Type::Load, fileinfo.suffix());
if (!parser) {
qLog(Warning) << "Unknown filetype:" << filename;
return SongList();
@@ -208,16 +208,16 @@ void PlaylistParser::Save(const SongList &songs, const QString &filename, const
}
// Find a parser that supports this file extension
ParserBase *parser = ParserForExtension(Type_Save, fileinfo.suffix());
ParserBase *parser = ParserForExtension(Type::Save, fileinfo.suffix());
if (!parser) {
qLog(Warning) << "Unknown filetype" << filename;
return;
}
if (path_type == PlaylistSettingsPage::PathType_Absolute && dir.path() != dir.absolutePath()) {
if (path_type == PlaylistSettingsPage::PathType::Absolute && dir.path() != dir.absolutePath()) {
dir.setPath(dir.absolutePath());
}
else if (path_type != PlaylistSettingsPage::PathType_Absolute && !dir.canonicalPath().isEmpty() && dir.path() != dir.canonicalPath()) {
else if (path_type != PlaylistSettingsPage::PathType::Absolute && !dir.canonicalPath().isEmpty() && dir.path() != dir.canonicalPath()) {
dir.setPath(dir.canonicalPath());
}
@@ -236,6 +236,6 @@ void PlaylistParser::Save(const SongList &songs, const QString &filename, const
bool PlaylistParser::ParserIsSupported(const Type type, ParserBase *parser) const {
return ((type == Type_Load && parser->load_supported()) || (type == Type_Save && parser->save_supported()));
return ((type == Type::Load && parser->load_supported()) || (type == Type::Save && parser->save_supported()));
}

View File

@@ -43,9 +43,9 @@ class PlaylistParser : public QObject {
public:
explicit PlaylistParser(CollectionBackendInterface *collection = nullptr, QObject *parent = nullptr);
enum Type {
Type_Load,
Type_Save,
enum class Type {
Load,
Save
};
static const int kMagicSize;

View File

@@ -51,7 +51,7 @@ class PLSParser : public ParserBase {
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(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_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

View File

@@ -54,7 +54,7 @@ class WplParser : public XMLParser {
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, const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_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;

View File

@@ -122,7 +122,7 @@ return_song:
Song song = LoadSong(location, 0, dir, collection_search);
// Override metadata with what was in the playlist
if (song.source() != Song::Source_Collection) {
if (song.source() != Song::Source::Collection) {
if (!title.isEmpty()) song.set_title(title);
if (!artist.isEmpty()) song.set_artist(artist);
if (!album.isEmpty()) song.set_album(album);

View File

@@ -51,7 +51,7 @@ class XSPFParser : public XMLParser {
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(), const PlaylistSettingsPage::PathType path_type = PlaylistSettingsPage::PathType_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;