Support all known fields in renaming utility
* Generalize and simplify code for populating tag object
This commit is contained in:
parent
e8c0450c1c
commit
90d2d7bde4
|
@ -1,6 +1,7 @@
|
||||||
#ifndef CLI_FIELDMAPPING
|
#ifndef CLI_FIELDMAPPING
|
||||||
#define CLI_FIELDMAPPING
|
#define CLI_FIELDMAPPING
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
namespace TagParser {
|
namespace TagParser {
|
||||||
|
@ -10,8 +11,14 @@ enum class KnownField : unsigned int;
|
||||||
namespace Cli {
|
namespace Cli {
|
||||||
namespace FieldMapping {
|
namespace FieldMapping {
|
||||||
|
|
||||||
|
struct Mapping {
|
||||||
|
const char *knownDenotation;
|
||||||
|
TagParser::KnownField knownField;
|
||||||
|
};
|
||||||
|
|
||||||
const char *fieldDenotation(TagParser::KnownField knownField);
|
const char *fieldDenotation(TagParser::KnownField knownField);
|
||||||
TagParser::KnownField knownField(const char *fieldDenotation, std::size_t fieldDenotationSize);
|
TagParser::KnownField knownField(const char *fieldDenotation, std::size_t fieldDenotationSize);
|
||||||
|
const std::array<Mapping, 99> &mapping();
|
||||||
|
|
||||||
} // namespace FieldMapping
|
} // namespace FieldMapping
|
||||||
} // namespace Cli
|
} // namespace Cli
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "./filesystemitem.h"
|
#include "./filesystemitem.h"
|
||||||
#include "./jsincludes.h"
|
#include "./jsincludes.h"
|
||||||
|
|
||||||
|
#include "../cli/fieldmapping.h"
|
||||||
#include "../misc/utility.h"
|
#include "../misc/utility.h"
|
||||||
|
|
||||||
#include <tagparser/abstracttrack.h>
|
#include <tagparser/abstracttrack.h>
|
||||||
|
@ -47,44 +48,39 @@ TAGEDITOR_JS_VALUE &operator<<(TAGEDITOR_JS_VALUE &diagObject, const Diagnostics
|
||||||
/// \brief Add fields and notifications from \a tag to \a tagObject.
|
/// \brief Add fields and notifications from \a tag to \a tagObject.
|
||||||
TAGEDITOR_JS_VALUE &operator<<(TAGEDITOR_JS_VALUE &tagObject, const Tag &tag)
|
TAGEDITOR_JS_VALUE &operator<<(TAGEDITOR_JS_VALUE &tagObject, const Tag &tag)
|
||||||
{
|
{
|
||||||
// add text fields
|
for (const auto &mapping : Cli::FieldMapping::mapping()) {
|
||||||
static const char *const fieldNames[]
|
const auto fieldName = [&] {
|
||||||
= { "title", "artist", "albumartist", "album", "year", "comment", "genre", "encoder", "language", "description", nullptr };
|
auto v = mapping.knownField == KnownField::PartNumber ? QStringLiteral("partNumber") : QString::fromUtf8(mapping.knownDenotation);
|
||||||
static const KnownField fields[] = { KnownField::Title, KnownField::Artist, KnownField::AlbumArtist, KnownField::Album, KnownField::RecordDate,
|
v.front() = v.front().toLower();
|
||||||
KnownField::Comment, KnownField::Genre, KnownField::Encoder, KnownField::Language, KnownField::Description };
|
return v;
|
||||||
const char *const *fieldName = fieldNames;
|
}();
|
||||||
const KnownField *field = fields;
|
switch (mapping.knownField) {
|
||||||
for (; *fieldName; ++fieldName, ++field) {
|
case KnownField::PartNumber:
|
||||||
try {
|
case KnownField::TotalParts:
|
||||||
tagObject.setProperty(*fieldName, tagValueToQString(tag.value(*field)) TAGEDITOR_JS_READONLY);
|
try {
|
||||||
} catch (const ConversionException &) {
|
tagObject.setProperty(fieldName, tag.value(mapping.knownField).toInteger() TAGEDITOR_JS_READONLY);
|
||||||
|
} catch (const ConversionException &) {
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case KnownField::TrackPosition:
|
||||||
|
case KnownField::DiskPosition:
|
||||||
|
try {
|
||||||
|
const auto pos = tag.value(mapping.knownField).toPositionInSet();
|
||||||
|
tagObject.setProperty(fieldName + QStringLiteral("Pos"), pos.position() TAGEDITOR_JS_READONLY);
|
||||||
|
tagObject.setProperty(fieldName + QStringLiteral("Total"), pos.total() TAGEDITOR_JS_READONLY);
|
||||||
|
} catch (const ConversionException &) {
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case KnownField::Cover:
|
||||||
|
case KnownField::SynchronizedLyrics:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
try {
|
||||||
|
tagObject.setProperty(fieldName, tagValueToQString(tag.value(mapping.knownField)) TAGEDITOR_JS_READONLY);
|
||||||
|
} catch (const ConversionException &) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add numeric fields
|
|
||||||
try {
|
|
||||||
tagObject.setProperty("partNumber", tag.value(KnownField::PartNumber).toInteger() TAGEDITOR_JS_READONLY);
|
|
||||||
} catch (const ConversionException &) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
tagObject.setProperty("totalParts", tag.value(KnownField::TotalParts).toInteger() TAGEDITOR_JS_READONLY);
|
|
||||||
} catch (const ConversionException &) {
|
|
||||||
}
|
|
||||||
PositionInSet pos;
|
|
||||||
try {
|
|
||||||
pos = tag.value(KnownField::TrackPosition).toPositionInSet();
|
|
||||||
} catch (const ConversionException &) {
|
|
||||||
}
|
|
||||||
tagObject.setProperty("trackPos", pos.position() TAGEDITOR_JS_READONLY);
|
|
||||||
tagObject.setProperty("trackTotal", pos.total() TAGEDITOR_JS_READONLY);
|
|
||||||
pos = PositionInSet();
|
|
||||||
try {
|
|
||||||
pos = tag.value(KnownField::DiskPosition).toPositionInSet();
|
|
||||||
} catch (const ConversionException &) {
|
|
||||||
}
|
|
||||||
tagObject.setProperty("diskPos", pos.position() TAGEDITOR_JS_READONLY);
|
|
||||||
tagObject.setProperty("diskTotal", pos.total() TAGEDITOR_JS_READONLY);
|
|
||||||
|
|
||||||
return tagObject;
|
return tagObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue