diff --git a/autotests/taglibextractortest.cpp b/autotests/taglibextractortest.cpp index 5e61abc..b8072e0 100644 --- a/autotests/taglibextractortest.cpp +++ b/autotests/taglibextractortest.cpp @@ -1,621 +1,613 @@ /* * TagLibExtractor tests. * * Copyright (C) 2015 Juan Palacios * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "taglibextractortest.h" #include "simpleextractionresult.h" #include "propertyinfo.h" //TODO: use QTESTFINDDATA and remove this #include "indexerextractortestsconfig.h" #include "extractors/taglibextractor.h" #include "mimeutils.h" #include #include #include Q_DECLARE_METATYPE(KFileMetaData::Property::Property) using namespace KFileMetaData; QString TagLibExtractorTest::testFilePath(const QString& fileName) const { return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; } const QStringList TagLibExtractorTest::propertyEnumNames(const QList& keys) const { QStringList result; for (auto key : keys) { result.append(PropertyInfo(key).name()); } return result; } void TagLibExtractorTest::testPropertyTypes() { TagLibExtractor plugin{this}; SimpleExtractionResult resultOpus(testFilePath("test.opus"), "audio/opus"); plugin.extract(&resultOpus); auto testForType = [](SimpleExtractionResult &result, Property::Property prop) { QCOMPARE(result.properties().value(prop).type(), PropertyInfo(prop).valueType()); }; QCOMPARE(resultOpus.types().size(), 1); QCOMPARE(resultOpus.types().constFirst(), Type::Audio); testForType(resultOpus, Property::Title); - QEXPECT_FAIL("", "Will be fixed in a following release", Continue); testForType(resultOpus, Property::Artist); testForType(resultOpus, Property::Album); - QEXPECT_FAIL("", "Will be fixed in a following release", Continue); testForType(resultOpus, Property::AlbumArtist); - QEXPECT_FAIL("", "Will be fixed in a following release", Continue); testForType(resultOpus, Property::Genre); testForType(resultOpus, Property::Comment); testForType(resultOpus, Property::Composer); - QEXPECT_FAIL("", "Will be fixed in a following release", Continue); testForType(resultOpus, Property::Lyricist); - QEXPECT_FAIL("", "Will be fixed in a following release", Continue); testForType(resultOpus, Property::Conductor); - QEXPECT_FAIL("", "Will be fixed in a following release", Continue); testForType(resultOpus, Property::Arranger); testForType(resultOpus, Property::Ensemble); testForType(resultOpus, Property::Location); - QEXPECT_FAIL("", "Will be fixed in a following release", Continue); testForType(resultOpus, Property::Performer); testForType(resultOpus, Property::Langauge); testForType(resultOpus, Property::Publisher); testForType(resultOpus, Property::Label); - QEXPECT_FAIL("", "Will be fixed in a following release", Continue); testForType(resultOpus, Property::Author); testForType(resultOpus, Property::Copyright); testForType(resultOpus, Property::Compilation); testForType(resultOpus, Property::License); testForType(resultOpus, Property::Opus); testForType(resultOpus, Property::TrackNumber); testForType(resultOpus, Property::ReleaseYear); testForType(resultOpus, Property::Channels); testForType(resultOpus, Property::DiscNumber); testForType(resultOpus, Property::Rating); testForType(resultOpus, Property::ReplayGainAlbumGain); testForType(resultOpus, Property::ReplayGainAlbumPeak); testForType(resultOpus, Property::ReplayGainTrackGain); testForType(resultOpus, Property::ReplayGainTrackPeak); } void TagLibExtractorTest::testCommonData() { QFETCH(QString, fileType); QString fileName = testFilePath(QStringLiteral("test.") + fileType); QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); TagLibExtractor plugin{this}; QVERIFY(plugin.mimetypes().contains(mimeType)); SimpleExtractionResult result(fileName, mimeType); plugin.extract(&result); QCOMPARE(result.types().size(), 1); QCOMPARE(result.types().constFirst(), Type::Audio); QCOMPARE(result.properties().value(Property::Title), QVariant(QStringLiteral("Title"))); QCOMPARE(result.properties().value(Property::Artist), QVariant(QStringLiteral("Artist"))); QCOMPARE(result.properties().value(Property::Album), QVariant(QStringLiteral("Album"))); QCOMPARE(result.properties().value(Property::Genre), QVariant(QStringLiteral("Genre"))); QCOMPARE(result.properties().value(Property::Comment), QVariant(QStringLiteral("Comment"))); QCOMPARE(result.properties().value(Property::TrackNumber).toInt(), 1); QCOMPARE(result.properties().value(Property::ReleaseYear).toInt(), 2015); } void TagLibExtractorTest::testCommonData_data() { QTest::addColumn("fileType"); QTest::addRow("aiff") << QStringLiteral("aif") ; QTest::addRow("ape") << QStringLiteral("ape") ; QTest::addRow("flac") << QStringLiteral("flac") ; QTest::addRow("m4a") << QStringLiteral("m4a") ; QTest::addRow("mp3") << QStringLiteral("mp3") ; QTest::addRow("mpc") << QStringLiteral("mpc") ; QTest::addRow("ogg") << QStringLiteral("ogg") ; QTest::addRow("opus") << QStringLiteral("opus") ; QTest::addRow("speex") << QStringLiteral("spx") ; QTest::addRow("wav") << QStringLiteral("wav") ; QTest::addRow("wavpack") << QStringLiteral("wv") ; QTest::addRow("wma") << QStringLiteral("wma") ; } void TagLibExtractorTest::testVorbisComment() { QFETCH(QString, fileType); QString fileName = testFilePath(QStringLiteral("test.") + fileType); QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); TagLibExtractor plugin{this}; SimpleExtractionResult result(fileName, mimeType); plugin.extract(&result); QCOMPARE(result.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(result.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(result.properties().value(Property::Lyricist), QVariant(QStringLiteral("Lyricist"))); QCOMPARE(result.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(result.properties().value(Property::Arranger), QVariant(QStringLiteral("Arranger"))); QCOMPARE(result.properties().value(Property::Ensemble), QVariant(QStringLiteral("Ensemble"))); QCOMPARE(result.properties().value(Property::Location), QVariant(QStringLiteral("Location"))); QCOMPARE(result.properties().value(Property::Performer), QVariant(QStringLiteral("Performer"))); QCOMPARE(result.properties().value(Property::Language), QVariant(QStringLiteral("Language"))); QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); QCOMPARE(result.properties().value(Property::Label), QVariant(QStringLiteral("Label"))); QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); QCOMPARE(result.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); QCOMPARE(result.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); QCOMPARE(result.properties().value(Property::License), QVariant(QStringLiteral("License"))); QCOMPARE(result.properties().value(Property::Lyrics), QVariant(QStringLiteral("Lyrics"))); QCOMPARE(result.properties().value(Property::Opus).toInt(), 1); QCOMPARE(result.properties().value(Property::Channels).toInt(), 1); QCOMPARE(result.properties().value(Property::DiscNumber).toInt(), 1); QCOMPARE(result.properties().value(Property::Rating).toInt(), 5); QCOMPARE(result.properties().value(Property::ReplayGainAlbumGain), QVariant(-9.90)); QCOMPARE(result.properties().value(Property::ReplayGainAlbumPeak), QVariant(1.512)); QCOMPARE(result.properties().value(Property::ReplayGainTrackGain), QVariant(-10.44)); QCOMPARE(result.properties().value(Property::ReplayGainTrackPeak), QVariant(1.301)); } void TagLibExtractorTest::testVorbisComment_data() { QTest::addColumn("fileType"); QTest::addRow("flac") << QStringLiteral("flac") ; QTest::addRow("ogg") << QStringLiteral("ogg") ; QTest::addRow("opus") << QStringLiteral("opus") ; QTest::addRow("speex") << QStringLiteral("spx") ; } void TagLibExtractorTest::testVorbisCommentMultivalue() { QFETCH(QString, fileName); QFETCH(QString, mimeType); TagLibExtractor plugin{this}; SimpleExtractionResult result(testFilePath(fileName), mimeType); plugin.extract(&result); QCOMPARE(result.properties().values(Property::Artist), QVariantList({QStringLiteral("Artist1"), QStringLiteral("Artist2")})); QCOMPARE(result.properties().values(Property::Genre), QVariantList({QStringLiteral("Genre1"), QStringLiteral("Genre2")})); } void TagLibExtractorTest::testVorbisCommentMultivalue_data() { QTest::addColumn("fileName"); QTest::addColumn("mimeType"); QTest::addRow("ogg multivalue") << QStringLiteral("test_multivalue.ogg") << QStringLiteral("audio/ogg") ; } void TagLibExtractorTest::testId3() { QFETCH(QString, fileType); QString fileName = testFilePath(QStringLiteral("test.") + fileType); QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); TagLibExtractor plugin{this}; SimpleExtractionResult result(fileName, mimeType); plugin.extract(&result); QCOMPARE(result.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(result.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(result.properties().value(Property::Lyricist), QVariant(QStringLiteral("Lyricist"))); QCOMPARE(result.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); QCOMPARE(result.properties().value(Property::Language), QVariant(QStringLiteral("Language"))); QCOMPARE(result.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); QCOMPARE(result.properties().value(Property::Lyrics), QVariant(QStringLiteral("Lyrics"))); QCOMPARE(result.properties().value(Property::Channels).toInt(), 1); QCOMPARE(result.properties().value(Property::DiscNumber).toInt(), 1); QCOMPARE(result.properties().value(Property::Rating).toInt(), 10); QCOMPARE(result.properties().value(Property::ReplayGainAlbumGain), QVariant(-3.33)); QCOMPARE(result.properties().value(Property::ReplayGainAlbumPeak), QVariant(1.333)); QCOMPARE(result.properties().value(Property::ReplayGainTrackGain), QVariant(3.33)); QCOMPARE(result.properties().value(Property::ReplayGainTrackPeak), QVariant(1.369)); } void TagLibExtractorTest::testId3_data() { QTest::addColumn("fileType"); QTest::addRow("aiff") << QStringLiteral("aif") ; QTest::addRow("mp3") << QStringLiteral("mp3") ; QTest::addRow("wav") << QStringLiteral("wav") ; } void TagLibExtractorTest::testApe() { QFETCH(QString, fileType); QString fileName = testFilePath(QStringLiteral("test.") + fileType); QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); TagLibExtractor plugin{this}; SimpleExtractionResult result(fileName, mimeType); plugin.extract(&result); QCOMPARE(result.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(result.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(result.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(result.properties().value(Property::Arranger), QVariant(QStringLiteral("Arranger"))); QCOMPARE(result.properties().value(Property::Ensemble), QVariant(QStringLiteral("Ensemble"))); QCOMPARE(result.properties().value(Property::Location), QVariant(QStringLiteral("Location"))); QCOMPARE(result.properties().value(Property::Performer), QVariant(QStringLiteral("Performer"))); QCOMPARE(result.properties().value(Property::Language), QVariant(QStringLiteral("Language"))); QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); QCOMPARE(result.properties().value(Property::Label), QVariant(QStringLiteral("Label"))); QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); QCOMPARE(result.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); QCOMPARE(result.properties().value(Property::Compilation), QVariant(QStringLiteral("Compilation"))); QCOMPARE(result.properties().value(Property::License), QVariant(QStringLiteral("License"))); QCOMPARE(result.properties().value(Property::Lyrics), QVariant(QStringLiteral("Lyrics"))); QCOMPARE(result.properties().value(Property::Channels).toInt(), 1); QCOMPARE(result.properties().value(Property::DiscNumber).toInt(), 1); QCOMPARE(result.properties().value(Property::Rating).toInt(), 4); QCOMPARE(result.properties().value(Property::ReplayGainAlbumGain), QVariant(-9.44)); QCOMPARE(result.properties().value(Property::ReplayGainAlbumPeak), QVariant(1.099)); QCOMPARE(result.properties().value(Property::ReplayGainTrackGain), QVariant(-5.23)); QCOMPARE(result.properties().value(Property::ReplayGainTrackPeak), QVariant(1.234)); } void TagLibExtractorTest::testApe_data() { QTest::addColumn("fileType"); QTest::addRow("ape") << QStringLiteral("ape") ; QTest::addRow("musepack") << QStringLiteral("mpc") ; QTest::addRow("wavpack") << QStringLiteral("wv") ; } void TagLibExtractorTest::testMp4() { QFETCH(QString, fileType); QString fileName = testFilePath(QStringLiteral("test.") + fileType); QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); TagLibExtractor plugin{this}; SimpleExtractionResult resultMp4(fileName, mimeType); plugin.extract(&resultMp4); QCOMPARE(resultMp4.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(resultMp4.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(resultMp4.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); QCOMPARE(resultMp4.properties().value(Property::Lyrics), QVariant(QStringLiteral("Lyrics"))); QCOMPARE(resultMp4.properties().value(Property::Channels).toInt(), 2); QCOMPARE(resultMp4.properties().value(Property::DiscNumber).toInt(), 1); QCOMPARE(resultMp4.properties().value(Property::Rating).toInt(), 8); } void TagLibExtractorTest::testMp4_data() { QTest::addColumn("fileType"); QTest::addRow("mp4") << QStringLiteral("m4a") ; } void TagLibExtractorTest::testAsf() { QFETCH(QString, fileType); QString fileName = testFilePath(QStringLiteral("test.") + fileType); QString mimeType = MimeUtils::strictMimeType(fileName, mimeDb).name(); TagLibExtractor plugin{this}; SimpleExtractionResult result(fileName, mimeType); plugin.extract(&result); QCOMPARE(result.properties().value(Property::AlbumArtist), QVariant(QStringLiteral("Album Artist"))); QCOMPARE(result.properties().value(Property::Rating).toInt(), 6); QCOMPARE(result.properties().value(Property::DiscNumber).toInt(), 1); QCOMPARE(result.properties().value(Property::Conductor), QVariant(QStringLiteral("Conductor"))); QCOMPARE(result.properties().value(Property::Composer), QVariant(QStringLiteral("Composer"))); QCOMPARE(result.properties().value(Property::Author), QVariant(QStringLiteral("Author"))); QCOMPARE(result.properties().value(Property::Lyricist), QVariant(QStringLiteral("Lyricist"))); QCOMPARE(result.properties().value(Property::Copyright), QVariant(QStringLiteral("Copyright"))); QCOMPARE(result.properties().value(Property::Publisher), QVariant(QStringLiteral("Publisher"))); } void TagLibExtractorTest::testAsf_data() { QTest::addColumn("fileType"); QTest::addRow("asf") << QStringLiteral("wma") ; } void TagLibExtractorTest::testId3Rating_data() { QTest::addColumn("path"); QTest::addColumn("expectedRating"); QTest::addRow("WMP") << QFINDTESTDATA("samplefiles/mp3_rating/testWMP.mp3") << 0 ; QTest::addRow("WMP1") << QFINDTESTDATA("samplefiles/mp3_rating/testWMP1.mp3") << 2 ; QTest::addRow("WMP2") << QFINDTESTDATA("samplefiles/mp3_rating/testWMP2.mp3") << 4 ; QTest::addRow("WMP3") << QFINDTESTDATA("samplefiles/mp3_rating/testWMP3.mp3") << 6 ; QTest::addRow("WMP4") << QFINDTESTDATA("samplefiles/mp3_rating/testWMP4.mp3") << 8 ; QTest::addRow("WMP5") << QFINDTESTDATA("samplefiles/mp3_rating/testWMP5.mp3") << 10 ; QTest::addRow("MM") << QFINDTESTDATA("samplefiles/mp3_rating/testMM.mp3") << 0 ; QTest::addRow("MM1") << QFINDTESTDATA("samplefiles/mp3_rating/testMM1.mp3") << 1 ; QTest::addRow("MM2") << QFINDTESTDATA("samplefiles/mp3_rating/testMM2.mp3") << 2 ; QTest::addRow("MM3") << QFINDTESTDATA("samplefiles/mp3_rating/testMM3.mp3") << 3 ; QTest::addRow("MM4") << QFINDTESTDATA("samplefiles/mp3_rating/testMM4.mp3") << 4 ; QTest::addRow("MM5") << QFINDTESTDATA("samplefiles/mp3_rating/testMM5.mp3") << 5 ; QTest::addRow("MM6") << QFINDTESTDATA("samplefiles/mp3_rating/testMM6.mp3") << 6 ; QTest::addRow("MM7") << QFINDTESTDATA("samplefiles/mp3_rating/testMM7.mp3") << 7 ; QTest::addRow("MM8") << QFINDTESTDATA("samplefiles/mp3_rating/testMM8.mp3") << 8 ; QTest::addRow("MM9") << QFINDTESTDATA("samplefiles/mp3_rating/testMM9.mp3") << 9 ; QTest::addRow("MM10") << QFINDTESTDATA("samplefiles/mp3_rating/testMM10.mp3") << 10 ; } void TagLibExtractorTest::testId3Rating() { QFETCH(QString, path); QFETCH(int, expectedRating); TagLibExtractor plugin{this}; SimpleExtractionResult result(path, "audio/mpeg"); plugin.extract(&result); QCOMPARE(result.properties().value(Property::Rating).toInt(), expectedRating); } void TagLibExtractorTest::testWmaRating() { QFETCH(QString, path); QFETCH(int, expectedRating); TagLibExtractor plugin{this}; SimpleExtractionResult result(path, "audio/x-ms-wma"); plugin.extract(&result); QCOMPARE(result.properties().value(Property::Rating).toInt(), expectedRating); } void TagLibExtractorTest::testWmaRating_data() { QTest::addColumn("path"); QTest::addColumn("expectedRating"); QTest::addRow("WMP0") << QFINDTESTDATA("samplefiles/wma_rating/test0.wma") << 0 ; QTest::addRow("WMP1") << QFINDTESTDATA("samplefiles/wma_rating/test1.wma") << 2 ; QTest::addRow("WMP2") << QFINDTESTDATA("samplefiles/wma_rating/test2.wma") << 4 ; QTest::addRow("WMP3") << QFINDTESTDATA("samplefiles/wma_rating/test3.wma") << 6 ; QTest::addRow("WMP4") << QFINDTESTDATA("samplefiles/wma_rating/test4.wma") << 8 ; QTest::addRow("WMP5") << QFINDTESTDATA("samplefiles/wma_rating/test5.wma") << 10 ; } void TagLibExtractorTest::testNoMetadata_data() { const auto expectedKeys = QList{ Property::BitRate, Property::Channels, Property::Duration, Property::SampleRate, }; QTest::addColumn("path"); QTest::addColumn("mimeType"); QTest::addColumn>("expectedKeys"); QTest::addColumn("failMessage"); QTest::addRow("mp3") << QFINDTESTDATA("samplefiles/no-meta/test.mp3") << QStringLiteral("audio/mpeg") << expectedKeys << QString() ; QTest::addRow("m4a") << QFINDTESTDATA("samplefiles/no-meta/test.m4a") << QStringLiteral("audio/mp4") << expectedKeys << QString() ; QTest::addRow("flac") << QFINDTESTDATA("samplefiles/no-meta/test.flac") << QStringLiteral("audio/flac") << expectedKeys << QString() ; QTest::addRow("opus") << QFINDTESTDATA("samplefiles/no-meta/test.opus") << QStringLiteral("audio/opus") << expectedKeys << QString() ; QTest::addRow("ogg") << QFINDTESTDATA("samplefiles/no-meta/test.ogg") << QStringLiteral("audio/ogg") << expectedKeys << QString() ; QTest::addRow("mpc") << QFINDTESTDATA("samplefiles/no-meta/test.mpc") << QStringLiteral("audio/x-musepack") << expectedKeys << QString() ; } void TagLibExtractorTest::testNoMetadata() { QFETCH(QString, path); QFETCH(QString, mimeType); QFETCH(QList, expectedKeys); QFETCH(QString, failMessage); TagLibExtractor plugin{this}; SimpleExtractionResult extracted(path, mimeType); plugin.extract(&extracted); const auto resultList = extracted.properties(); const auto resultKeys = resultList.uniqueKeys(); const auto excessKeys = resultKeys.toSet() - expectedKeys.toSet(); const auto missingKeys = expectedKeys.toSet() - resultKeys.toSet(); if (!excessKeys.isEmpty()) { const auto propNames = propertyEnumNames(excessKeys.toList()).join(QLatin1String(", ")); if (failMessage.isEmpty()) { const auto message = QStringLiteral("Excess properties: %1").arg(propNames); QWARN(qPrintable(message)); } else { QEXPECT_FAIL("", qPrintable(QStringLiteral("%1: %2").arg(failMessage).arg(propNames)), Continue); } } else if (!missingKeys.isEmpty()) { const auto message = QStringLiteral("Missing properties: %1") .arg(propertyEnumNames(missingKeys.toList()).join(QLatin1String(", "))); QWARN(qPrintable(message)); } QCOMPARE(resultKeys, expectedKeys); if (!failMessage.isEmpty()) { auto excessKeys = resultKeys.toSet() - expectedKeys.toSet(); const auto message = QStringLiteral("%1: %2") .arg(failMessage) .arg(propertyEnumNames(excessKeys.toList()).join(QLatin1String(", "))); QEXPECT_FAIL("", qPrintable(message), Continue); } QCOMPARE(resultKeys, expectedKeys); } QTEST_GUILESS_MAIN(TagLibExtractorTest) diff --git a/src/formatstrings.cpp b/src/formatstrings.cpp index b3c8889..38b4782 100644 --- a/src/formatstrings.cpp +++ b/src/formatstrings.cpp @@ -1,159 +1,154 @@ /* * Copyright (C) 2018 Alexander Stippich * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "formatstrings_p.h" #include #include #include #include using namespace KFileMetaData; int significantDigits(int value) { if (value == 0) { return 0; } int before_decimal_point = static_cast(log10(value > 0 ? value : -value)) % 3; return 2 - before_decimal_point; } QString FormatStrings::toStringFunction(const QVariant& value) { return value.toString(); } -QString FormatStrings::joinStringListFunction(const QVariant& value) -{ - return QLocale().createSeparatedList(value.toStringList()); -} - QString FormatStrings::formatDate(const QVariant& value) { KFormat form; QDateTime dt; if (value.type() == QVariant::DateTime) { dt = value.toDateTime(); } else { dt = QDateTime::fromString(value.toString(), Qt::ISODate); } if (dt.isValid()) { return form.formatRelativeDateTime(dt, QLocale::LongFormat); } return QString(); } QString FormatStrings::formatDuration(const QVariant& value) { KFormat form; return form.formatDuration(value.toInt() * 1000); } QString FormatStrings::formatBitRate(const QVariant& value) { KFormat form; return i18nc("@label bitrate (per second)", "%1/s", form.formatValue(value.toInt(), KFormat::Unit::Bit, significantDigits(value.toInt()), KFormat::UnitPrefix::AutoAdjust, KFormat::MetricBinaryDialect)); } QString FormatStrings::formatSampleRate(const QVariant& value) { KFormat form; return form.formatValue(value.toInt(), KFormat::Unit::Hertz, significantDigits(value.toInt()), KFormat::UnitPrefix::AutoAdjust, KFormat::MetricBinaryDialect); } QString FormatStrings::formatOrientationValue(const QVariant& value) { QString string; switch (value.toInt()) { case 1: string = i18nc("Description of image orientation", "Unchanged"); break; case 2: string = i18nc("Description of image orientation", "Horizontally flipped"); break; case 3: string = i18nc("Description of image orientation", "180° rotated"); break; case 4: string = i18nc("Description of image orientation", "Vertically flipped"); break; case 5: string = i18nc("Description of image orientation", "Transposed"); break; case 6: string = i18nc("Description of image orientation, counter clock-wise rotated", "90° rotated CCW "); break; case 7: string = i18nc("Description of image orientation", "Transversed"); break; case 8: string = i18nc("Description of image orientation, counter clock-wise rotated", "270° rotated CCW"); break; default: break; } return string; } QString FormatStrings::formatPhotoFlashValue(const QVariant& value) { // copied from exiv2 tags_int.cpp const QMap flashTranslation = { { 0x00, i18nc("Description of photo flash", "No flash") }, { 0x01, i18nc("Description of photo flash", "Fired") }, { 0x05, i18nc("Description of photo flash", "Fired, return light not detected") }, { 0x07, i18nc("Description of photo flash", "Fired, return light detected") }, { 0x08, i18nc("Description of photo flash", "Yes, did not fire") }, { 0x09, i18nc("Description of photo flash", "Yes, compulsory") }, { 0x0d, i18nc("Description of photo flash", "Yes, compulsory, return light not detected") }, { 0x0f, i18nc("Description of photo flash", "Yes, compulsory, return light detected") }, { 0x10, i18nc("Description of photo flash", "No, compulsory") }, { 0x14, i18nc("Description of photo flash", "No, did not fire, return light not detected") }, { 0x18, i18nc("Description of photo flash", "No, auto") }, { 0x19, i18nc("Description of photo flash", "Yes, auto") }, { 0x1d, i18nc("Description of photo flash", "Yes, auto, return light not detected") }, { 0x1f, i18nc("Description of photo flash", "Yes, auto, return light detected") }, { 0x20, i18nc("Description of photo flash", "No flash function") }, { 0x30, i18nc("Description of photo flash", "No, no flash function") }, { 0x41, i18nc("Description of photo flash", "Yes, red-eye reduction") }, { 0x45, i18nc("Description of photo flash", "Yes, red-eye reduction, return light not detected") }, { 0x47, i18nc("Description of photo flash", "Yes, red-eye reduction, return light detected") }, { 0x49, i18nc("Description of photo flash", "Yes, compulsory, red-eye reduction") }, { 0x4d, i18nc("Description of photo flash", "Yes, compulsory, red-eye reduction, return light not detected") }, { 0x4f, i18nc("Description of photo flash", "Yes, compulsory, red-eye reduction, return light detected") }, { 0x50, i18nc("Description of photo flash", "No, red-eye reduction") }, { 0x58, i18nc("Description of photo flash", "No, auto, red-eye reduction") }, { 0x59, i18nc("Description of photo flash", "Yes, auto, red-eye reduction") }, { 0x5d, i18nc("Description of photo flash", "Yes, auto, red-eye reduction, return light not detected") }, { 0x5f, i18nc("Description of photo flash", "Yes, auto, red-eye reduction, return light detected") } }; if (flashTranslation.contains(value.toInt())) { return flashTranslation.value(value.toInt()); } else { return i18n("Unknown"); } } QString FormatStrings::formatAsDegree(const QVariant& value) { return i18nc("Symbol of degree, no space", "%1°", QLocale().toString(value.toDouble())); } QString FormatStrings::formatAsMeter(const QVariant& value) { KFormat form; return form.formatValue(value.toDouble(), KFormat::Unit::Meter, 1, KFormat::UnitPrefix::AutoAdjust, KFormat::MetricBinaryDialect); } QString FormatStrings::formatAsFrameRate(const QVariant& value) { return i18nc("Symbol of frames per second, with space", "%1 fps", QLocale().toString(round(value.toDouble() * 100) / 100)); } QString FormatStrings::formatAspectRatio(const QVariant& value) { return i18nc("Aspect ratio, normalized to one", "%1:1", QLocale().toString(round(value.toDouble() * 100) / 100)); } diff --git a/src/formatstrings_p.h b/src/formatstrings_p.h index 1ceb46e..6171d8a 100644 --- a/src/formatstrings_p.h +++ b/src/formatstrings_p.h @@ -1,60 +1,58 @@ /* * Copyright (C) 2018 Alexander Stippich * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef KFILEMETADATA_FORMATSTRINGS_P_H #define KFILEMETADATA_FORMATSTRINGS_P_H #include #include #include namespace KFileMetaData { class Q_DECL_HIDDEN FormatStrings { public: static QString toStringFunction(const QVariant& value); - static QString joinStringListFunction(const QVariant& value); - static QString formatDate(const QVariant& value); static QString formatDuration(const QVariant& value); static QString formatBitRate(const QVariant& value); static QString formatSampleRate(const QVariant& value); static QString formatOrientationValue(const QVariant& value); static QString formatPhotoFlashValue(const QVariant& value); static QString formatAsDegree(const QVariant& value); static QString formatAsMeter(const QVariant& value); static QString formatAsFrameRate(const QVariant& value); static QString formatAspectRatio(const QVariant& value); }; } #endif diff --git a/src/propertyinfo.cpp b/src/propertyinfo.cpp index 4fc7a8b..1194b69 100644 --- a/src/propertyinfo.cpp +++ b/src/propertyinfo.cpp @@ -1,743 +1,731 @@ /* * This file is part of the KFileMetaData project * Copyright (C) 2014 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #include "propertyinfo.h" #include #include "formatstrings_p.h" using namespace KFileMetaData; class Q_DECL_HIDDEN PropertyInfo::Private { public: Property::Property prop; QString name; QString displayName; QVariant::Type valueType; bool shouldBeIndexed; QString (*formatAsString)(const QVariant& value) = nullptr; }; PropertyInfo::PropertyInfo() : d(new Private) { d->prop = Property::Empty; d->name = QStringLiteral("empty"); d->valueType = QVariant::Invalid; d->shouldBeIndexed = false; d->formatAsString = &FormatStrings::toStringFunction; } PropertyInfo::PropertyInfo(Property::Property property) : d(new Private) { d->prop = property; d->shouldBeIndexed = true; d->formatAsString = &FormatStrings::toStringFunction; switch (property) { case Property::Album: d->name = QStringLiteral("album"); d->displayName = i18nc("@label music album", "Album"); d->valueType = QVariant::String; break; case Property::AlbumArtist: d->name = QStringLiteral("albumArtist"); d->displayName = i18nc("@label", "Album Artist"); - d->valueType = QVariant::StringList; - d->formatAsString = &FormatStrings::joinStringListFunction; + d->valueType = QVariant::String; break; case Property::Artist: d->name = QStringLiteral("artist"); d->displayName = i18nc("@label", "Artist"); - d->valueType = QVariant::StringList; - d->formatAsString = &FormatStrings::joinStringListFunction; + d->valueType = QVariant::String; break; case Property::AspectRatio: d->name = QStringLiteral("aspectRatio"); d->displayName = i18nc("@label", "Aspect Ratio"); d->valueType = QVariant::Double; d->formatAsString = &FormatStrings::formatAspectRatio; break; case Property::Author: d->name = QStringLiteral("author"); d->displayName = i18nc("@label", "Author"); - d->valueType = QVariant::StringList; - d->formatAsString = &FormatStrings::joinStringListFunction; + d->valueType = QVariant::String; break; case Property::BitRate: d->name = QStringLiteral("bitRate"); d->displayName = i18nc("@label", "Bitrate"); d->valueType = QVariant::Int; d->formatAsString = &FormatStrings::formatBitRate; break; case Property::Channels: d->name = QStringLiteral("channels"); d->displayName = i18nc("@label", "Channels"); d->valueType = QVariant::Int; break; case Property::Comment: d->name = QStringLiteral("comment"); d->displayName = i18nc("@label", "Comment"); d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::Description: d->name = QStringLiteral("description"); d->displayName = i18nc("@label", "Description"); d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::Composer: d->name = QStringLiteral("composer"); d->displayName = i18nc("@label", "Composer"); d->valueType = QVariant::String; - d->shouldBeIndexed = false; break; case Property::Copyright: d->name = QStringLiteral("copyright"); d->displayName = i18nc("@label", "Copyright"); d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::CreationDate: d->name = QStringLiteral("creationDate"); d->displayName = i18nc("@label", "Creation Date"); - d->valueType = QVariant::String; + d->valueType = QVariant::DateTime; d->formatAsString = &FormatStrings::formatDate; break; case Property::Duration: d->name = QStringLiteral("duration"); d->displayName = i18nc("@label", "Duration"); d->valueType = QVariant::Int; d->formatAsString = &FormatStrings::formatDuration; break; case Property::Empty: d->name = QStringLiteral("empty"); d->valueType = QVariant::Invalid; break; case Property::FrameRate: d->name = QStringLiteral("frameRate"); d->displayName = i18nc("@label", "Frame Rate"); d->valueType = QVariant::Double; d->formatAsString = &FormatStrings::formatAsFrameRate; break; case Property::Generator: d->name = QStringLiteral("generator"); d->displayName = i18nc("@label", "Document Generated By"); d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::Genre: d->name = QStringLiteral("genre"); d->displayName = i18nc("@label music genre", "Genre"); - d->valueType = QVariant::StringList; - d->formatAsString = &FormatStrings::joinStringListFunction; - d->shouldBeIndexed = false; + d->valueType = QVariant::String; break; case Property::Height: d->name = QStringLiteral("height"); d->displayName = i18nc("@label", "Height"); d->valueType = QVariant::Int; break; case Property::ImageDateTime: d->name = QStringLiteral("imageDateTime"); d->displayName = i18nc("@label EXIF", "Image Date Time"); d->valueType = QVariant::DateTime; d->formatAsString = &FormatStrings::formatDate; break; case Property::ImageMake: d->name = QStringLiteral("imageMake"); d->displayName = i18nc("@label EXIF", "Image Make"); d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::ImageModel: d->name = QStringLiteral("imageModel"); d->displayName = i18nc("@label EXIF", "Image Model"); d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::ImageOrientation: d->name = QStringLiteral("imageOrientation"); d->displayName = i18nc("@label EXIF", "Image Orientation"); d->valueType = QVariant::Int; d->formatAsString = &FormatStrings::formatOrientationValue; break; case Property::Keywords: d->name = QStringLiteral("keywords"); d->displayName = i18nc("@label", "Keywords"); - d->valueType = QVariant::StringList; - d->formatAsString = &FormatStrings::joinStringListFunction; + d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::Language: d->name = QStringLiteral("language"); d->displayName = i18nc("@label", "Language"); d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::LineCount: d->name = QStringLiteral("lineCount"); d->displayName = i18nc("@label number of lines", "Line Count"); d->valueType = QVariant::Int; break; case Property::Lyricist: d->name = QStringLiteral("lyricist"); d->displayName = i18nc("@label", "Lyricist"); - d->valueType = QVariant::StringList; - d->formatAsString = &FormatStrings::joinStringListFunction; - d->shouldBeIndexed = false; + d->valueType = QVariant::String; break; case Property::PageCount: d->name = QStringLiteral("pageCount"); d->displayName = i18nc("@label", "Page Count"); d->valueType = QVariant::Int; break; case Property::PhotoApertureValue: d->name = QStringLiteral("photoApertureValue"); d->displayName = i18nc("@label EXIF", "Photo Aperture Value"); d->valueType = QVariant::Double; break; case Property::PhotoDateTimeOriginal: d->name = QStringLiteral("photoDateTimeOriginal"); d->displayName = i18nc("@label EXIF", "Photo Original Date Time"); d->valueType = QVariant::DateTime; d->formatAsString = &FormatStrings::formatDate; break; case Property::PhotoExposureBiasValue: d->name = QStringLiteral("photoExposureBiasValue"); d->displayName = i18nc("@label EXIF", "Photo Exposure Bias"); d->valueType = QVariant::Double; break; case Property::PhotoExposureTime: d->name = QStringLiteral("photoExposureTime"); d->displayName = i18nc("@label EXIF", "Photo Exposure Time"); d->valueType = QVariant::Double; break; case Property::PhotoFlash: d->name = QStringLiteral("photoFlash"); d->displayName = i18nc("@label EXIF", "Photo Flash"); d->valueType = QVariant::Int; d->formatAsString = &FormatStrings::formatPhotoFlashValue; break; case Property::PhotoFNumber: d->name = QStringLiteral("photoFNumber"); d->displayName = i18nc("@label EXIF", "Photo F Number"); d->valueType = QVariant::Int; break; case Property::PhotoFocalLength: d->name = QStringLiteral("photoFocalLength"); d->displayName = i18nc("@label EXIF", "Photo Focal Length"); d->valueType = QVariant::Double; break; case Property::PhotoFocalLengthIn35mmFilm: d->name = QStringLiteral("photoFocalLengthIn35mmFilm"); d->displayName = i18nc("@label EXIF", "Photo Focal Length 35mm"); d->valueType = QVariant::Double; break; case Property::PhotoGpsLatitude: d->name = QStringLiteral("photoGpsLatitude"); d->displayName = i18nc("@label EXIF", "Photo GPS Latitude"); d->valueType = QVariant::Double; d->formatAsString = &FormatStrings::formatAsDegree; break; case Property::PhotoGpsLongitude: d->name = QStringLiteral("photoGpsLongitude"); d->displayName = i18nc("@label EXIF", "Photo GPS Longitude"); d->valueType = QVariant::Double; d->formatAsString = &FormatStrings::formatAsDegree; break; case Property::PhotoGpsAltitude: d->name = QStringLiteral("photoGpsAltitude"); d->displayName = i18nc("@label EXIF", "Photo GPS Altitude"); d->valueType = QVariant::Double; d->formatAsString = &FormatStrings::formatAsMeter; break; case Property::PhotoISOSpeedRatings: d->name = QStringLiteral("photoISOSpeedRatings"); d->displayName = i18nc("@label EXIF", "Photo ISO Speed Rating"); d->valueType = QVariant::Int; break; case Property::PhotoMeteringMode: d->name = QStringLiteral("photoMeteringMode"); d->displayName = i18nc("@label EXIF", "Photo Metering Mode"); d->valueType = QVariant::Int; break; case Property::PhotoPixelXDimension: d->name = QStringLiteral("photoPixelXDimension"); d->displayName = i18nc("@label EXIF", "Photo X Dimension"); d->valueType = QVariant::Int; break; case Property::PhotoPixelYDimension: d->name = QStringLiteral("photoPixelYDimension"); d->displayName = i18nc("@label EXIF", "Photo Y Dimension"); d->valueType = QVariant::Int; break; case Property::PhotoSaturation: d->name = QStringLiteral("photoSaturation"); d->displayName = i18nc("@label EXIF", "Photo Saturation"); d->valueType = QVariant::Int; break; case Property::PhotoSharpness: d->name = QStringLiteral("photoSharpness"); d->displayName = i18nc("@label EXIF", "Photo Sharpness"); d->valueType = QVariant::Int; break; case Property::PhotoWhiteBalance: d->name = QStringLiteral("photoWhiteBalance"); d->displayName = i18nc("@label EXIF", "Photo White Balance"); d->valueType = QVariant::Int; break; case Property::Publisher: d->name = QStringLiteral("publisher"); d->displayName = i18nc("@label", "Publisher"); d->valueType = QVariant::String; break; case Property::Label: d->name = QStringLiteral("label"); d->displayName = i18nc("@label", "Label"); d->valueType = QVariant::String; break; case Property::ReleaseYear: d->name = QStringLiteral("releaseYear"); d->displayName = i18nc("@label", "Release Year"); d->valueType = QVariant::Int; break; case Property::SampleRate: d->name = QStringLiteral("sampleRate"); d->displayName = i18nc("@label", "Sample Rate"); d->valueType = QVariant::Int; d->formatAsString = &FormatStrings::formatSampleRate; break; case Property::Subject: d->name = QStringLiteral("subject"); d->displayName = i18nc("@label", "Subject"); d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::Title: d->name = QStringLiteral("title"); d->displayName = i18nc("@label", "Title"); d->valueType = QVariant::String; break; case Property::TrackNumber: d->name = QStringLiteral("trackNumber"); d->displayName = i18nc("@label music track number", "Track Number"); d->valueType = QVariant::Int; break; case Property::DiscNumber: d->name = QStringLiteral("discNumber"); d->displayName = i18nc("@label music disc number", "Disc Number"); d->valueType = QVariant::Int; break; case Property::Location: d->name = QStringLiteral("location"); d->displayName = i18nc("@label", "Location"); d->valueType = QVariant::String; break; case Property::Performer: d->name = QStringLiteral("performer"); d->displayName = i18nc("@label", "Performer"); - d->valueType = QVariant::StringList; - d->formatAsString = &FormatStrings::joinStringListFunction; + d->valueType = QVariant::String; break; case Property::Ensemble: d->name = QStringLiteral("ensemble"); d->displayName = i18nc("@label", "Ensemble"); d->valueType = QVariant::String; break; case Property::Arranger: d->name = QStringLiteral("arranger"); d->displayName = i18nc("@label", "Arranger"); - d->valueType = QVariant::StringList; - d->formatAsString = &FormatStrings::joinStringListFunction; + d->valueType = QVariant::String; break; case Property::Conductor: d->name = QStringLiteral("conductor"); d->displayName = i18nc("@label", "Conductor"); - d->valueType = QVariant::StringList; - d->formatAsString = &FormatStrings::joinStringListFunction; + d->valueType = QVariant::String; break; case Property::Compilation: d->name = QStringLiteral("compilation"); d->displayName = i18nc("@label", "Compilation"); d->valueType = QVariant::String; break; case Property::License: d->name = QStringLiteral("license"); d->displayName = i18nc("@label", "License"); d->valueType = QVariant::String; break; case Property::Lyrics: d->name = QStringLiteral("lyrics"); d->displayName = i18nc("@label", "Lyrics"); d->valueType = QVariant::String; break; case Property::Opus: d->name = QStringLiteral("opus"); d->displayName = i18nc("@label", "Opus"); d->valueType = QVariant::Int; break; case Property::Rating: d->name = QStringLiteral("embeddedRating"); d->displayName = i18nc("@label", "Rating"); d->valueType = QVariant::Int; break; case Property::ReplayGainAlbumPeak: d->name = QStringLiteral("replayGainAlbumPeak"); d->displayName = i18nc("@label", "Replay Gain Album Peak"); d->valueType = QVariant::Double; break; case Property::ReplayGainAlbumGain: d->name = QStringLiteral("replayGainAlbumGain"); d->displayName = i18nc("@label", "Replay Gain Album Gain"); d->valueType = QVariant::Double; break; case Property::ReplayGainTrackPeak: d->name = QStringLiteral("replayGainTrackPeak"); d->displayName = i18nc("@label", "Replay Gain Track Peak"); d->valueType = QVariant::Double; break; case Property::ReplayGainTrackGain: d->name = QStringLiteral("replayGainTrackGain"); d->displayName = i18nc("@label", "Replay Gain Track Gain"); d->valueType = QVariant::Double; break; case Property::Width: d->name = QStringLiteral("width"); d->displayName = i18nc("@label", "Width"); d->valueType = QVariant::Int; break; case Property::WordCount: d->name = QStringLiteral("wordCount"); d->displayName = i18nc("@label number of words", "Word Count"); d->valueType = QVariant::Int; break; case Property::TranslationUnitsTotal: d->name = QStringLiteral("translationUnitsTotal"); d->displayName = i18nc("@label number of translatable strings", "Translatable Units"); d->valueType = QVariant::Int; d->shouldBeIndexed = false; break; case Property::TranslationUnitsWithTranslation: d->name = QStringLiteral("translationUnitsWithTranslation"); d->displayName = i18nc("@label number of translated strings", "Translations"); d->valueType = QVariant::Int; d->shouldBeIndexed = false; break; case Property::TranslationUnitsWithDraftTranslation: d->name = QStringLiteral("translationUnitsWithDraftTranslation"); d->displayName = i18nc("@label number of fuzzy translated strings", "Draft Translations"); d->valueType = QVariant::Int; d->shouldBeIndexed = false; break; case Property::TranslationLastAuthor: d->name = QStringLiteral("translationLastAuthor"); d->displayName = i18nc("@label translation author", "Author"); d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::TranslationLastUpDate: d->name = QStringLiteral("translationLastUpDate"); d->displayName = i18nc("@label translations last update", "Last Update"); d->valueType = QVariant::String; d->shouldBeIndexed = false; d->formatAsString = &FormatStrings::formatDate; break; case Property::TranslationTemplateDate: d->name = QStringLiteral("translationTemplateDate"); d->displayName = i18nc("@label date of template creation8", "Template Creation"); d->valueType = QVariant::String; d->shouldBeIndexed = false; d->formatAsString = &FormatStrings::formatDate; break; case Property::OriginUrl: d->name = QStringLiteral("originUrl"); d->displayName = i18nc("@label the URL a file was originally downloaded from", "Downloaded From"); d->valueType = QVariant::Url; d->shouldBeIndexed = false; break; case Property::OriginEmailSubject: d->name = QStringLiteral("originEmailSubject"); d->displayName = i18nc("@label the subject of an email this file was attached to", "E-Mail Attachment Subject"); d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::OriginEmailSender: d->name = QStringLiteral("originEmailSender"); d->displayName = i18nc("@label the sender of an email this file was attached to", "E-Mail Attachment Sender"); d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::OriginEmailMessageId: d->name = QStringLiteral("originEmailMessageId"); d->displayName = i18nc("@label the message ID of an email this file was attached to", "E-Mail Attachment Message ID"); d->valueType = QVariant::String; d->shouldBeIndexed = false; break; case Property::PropertyCount: // To silence the compiler. break; // NOTE: new properties must also be added to ::fromName() } if (d->valueType == QVariant::Int || d->valueType == QVariant::DateTime || d->valueType == QVariant::Double) { d->shouldBeIndexed = false; } } PropertyInfo::PropertyInfo(const PropertyInfo& pi) : d(new Private(*pi.d)) { } PropertyInfo::~PropertyInfo() { delete d; } PropertyInfo& PropertyInfo::operator=(const PropertyInfo& rhs) { *d = *rhs.d; return *this; } bool PropertyInfo::operator==(const PropertyInfo& rhs) const { return d->name == rhs.d->name && d->displayName == rhs.d->displayName && d->prop == rhs.d->prop && d->shouldBeIndexed == rhs.d->shouldBeIndexed; } QString PropertyInfo::displayName() const { return d->displayName; } QString PropertyInfo::name() const { return d->name; } Property::Property PropertyInfo::property() const { return d->prop; } QVariant::Type PropertyInfo::valueType() const { return d->valueType; } bool PropertyInfo::shouldBeIndexed() const { return d->shouldBeIndexed; } QString PropertyInfo::formatAsDisplayString(const QVariant &value) const { - if (value.type() == QVariant::List) { - if (d->valueType == QVariant::StringList || d->valueType == QVariant::String) { + if (value.type() == QVariant::List || value.type() == QVariant::StringList) { + if (d->valueType == QVariant::String) { return QLocale().createSeparatedList(value.toStringList()); } else { QStringList displayList; const auto valueList = value.toList(); for (const auto& entry : valueList) { displayList << d->formatAsString(entry); } return QLocale().createSeparatedList(displayList); } } else { - return (d->formatAsString)(value); + return d->formatAsString(value); } } PropertyInfo PropertyInfo::fromName(const QString& name) { static QHash propertyHash = { { QStringLiteral("bitrate"), Property::BitRate }, { QStringLiteral("channels"), Property::Channels }, { QStringLiteral("duration"), Property::Duration }, { QStringLiteral("genre"), Property::Genre }, { QStringLiteral("samplerate"), Property::SampleRate }, { QStringLiteral("tracknumber"), Property::TrackNumber }, { QStringLiteral("discnumber"), Property::DiscNumber }, { QStringLiteral("releaseyear"), Property::ReleaseYear }, { QStringLiteral("comment"), Property::Comment }, { QStringLiteral("description"), Property::Description }, { QStringLiteral("artist"), Property::Artist }, { QStringLiteral("album"), Property::Album }, { QStringLiteral("albumartist"), Property::AlbumArtist }, { QStringLiteral("composer"), Property::Composer }, { QStringLiteral("lyricist"), Property::Lyricist }, { QStringLiteral("location"), Property::Location }, { QStringLiteral("performer"), Property::Performer }, { QStringLiteral("ensemble"), Property::Ensemble }, { QStringLiteral("arranger"), Property::Arranger }, { QStringLiteral("conductor"), Property::Conductor }, { QStringLiteral("opus"), Property::Opus }, { QStringLiteral("embeddedrating"), Property::Rating }, { QStringLiteral("author"), Property::Author }, { QStringLiteral("title"), Property::Title }, { QStringLiteral("subject"), Property::Subject }, { QStringLiteral("generator"), Property::Generator }, { QStringLiteral("pagecount"), Property::PageCount }, { QStringLiteral("wordcount"), Property::WordCount }, { QStringLiteral("linecount"), Property::LineCount }, { QStringLiteral("language"), Property::Language }, { QStringLiteral("copyright"), Property::Copyright }, { QStringLiteral("publisher"), Property::Publisher }, { QStringLiteral("label"), Property::Label }, { QStringLiteral("compilation"), Property::Compilation }, { QStringLiteral("license"), Property::License }, { QStringLiteral("lyrics"), Property::Lyrics }, { QStringLiteral("replaygainalbumpeak"), Property::ReplayGainAlbumPeak }, { QStringLiteral("replaygainalbumgain"), Property::ReplayGainAlbumGain }, { QStringLiteral("replaygaintrackpeak"), Property::ReplayGainTrackPeak }, { QStringLiteral("replaygaintrackgain"), Property::ReplayGainTrackGain }, { QStringLiteral("creationdate"), Property::CreationDate }, { QStringLiteral("keywords"), Property::Keywords }, { QStringLiteral("width"), Property::Width }, { QStringLiteral("height"), Property::Height }, { QStringLiteral("aspectratio"), Property::AspectRatio }, { QStringLiteral("framerate"), Property::FrameRate }, { QStringLiteral("imagemake"), Property::ImageMake }, { QStringLiteral("imagemodel"), Property::ImageModel }, { QStringLiteral("imagedatetime"), Property::ImageDateTime }, { QStringLiteral("imageorientation"), Property::ImageOrientation }, { QStringLiteral("photoflash"), Property::PhotoFlash }, { QStringLiteral("photopixelxdimension"), Property::PhotoPixelXDimension }, { QStringLiteral("photopixelydimension"), Property::PhotoPixelYDimension }, { QStringLiteral("photodatetimeoriginal"), Property::PhotoDateTimeOriginal }, { QStringLiteral("photofocallength"), Property::PhotoFocalLength }, { QStringLiteral("photofocallengthin35mmfilm"), Property::PhotoFocalLengthIn35mmFilm }, { QStringLiteral("photoexposuretime"), Property::PhotoExposureTime }, { QStringLiteral("photofnumber"), Property::PhotoFNumber }, { QStringLiteral("photoaperturevalue"), Property::PhotoApertureValue }, { QStringLiteral("photoexposurebiasvalue"), Property::PhotoExposureBiasValue }, { QStringLiteral("photowhitebalance"), Property::PhotoWhiteBalance }, { QStringLiteral("photometeringmode"), Property::PhotoMeteringMode }, { QStringLiteral("photoisospeedratings"), Property::PhotoISOSpeedRatings }, { QStringLiteral("photosaturation"), Property::PhotoSaturation }, { QStringLiteral("photosharpness"), Property::PhotoSharpness }, { QStringLiteral("photogpslatitude"), Property::PhotoGpsLatitude }, { QStringLiteral("photogpslongitude"), Property::PhotoGpsLongitude }, { QStringLiteral("photogpsaltitude"), Property::PhotoGpsAltitude }, { QStringLiteral("translationunitstotal"), Property::TranslationUnitsTotal }, { QStringLiteral("translationunitswithtranslation"), Property::TranslationUnitsWithTranslation }, { QStringLiteral("translationunitswithdrafttranslation"), Property::TranslationUnitsWithDraftTranslation }, { QStringLiteral("translationlastauthor"), Property::TranslationLastAuthor }, { QStringLiteral("translationlastupdate"), Property::TranslationLastUpDate }, { QStringLiteral("translationtemplatedate"), Property::TranslationTemplateDate }, { QStringLiteral("originurl"), Property::OriginUrl }, { QStringLiteral("originemailsubject"), Property::OriginEmailSubject }, { QStringLiteral("originemailsender"), Property::OriginEmailSender }, { QStringLiteral("originemailmessageid"), Property::OriginEmailMessageId } }; return PropertyInfo(propertyHash.value(name.toLower())); }