feat: display more image metadata

This commit is contained in:
Gary Wang 2021-07-04 01:18:24 +08:00
parent 066b8458f4
commit 62f485006f
4 changed files with 38 additions and 14 deletions

View File

@ -99,3 +99,24 @@ QString Exiv2Wrapper::value(const QString &key) const
return m_metadataValue.value(key); return m_metadataValue.value(key);
} }
QString Exiv2Wrapper::XmpValue(const QString &rawValue)
{
QString ignored;
return Exiv2Wrapper::XmpValue(rawValue, ignored);
}
QString Exiv2Wrapper::XmpValue(const QString &rawValue, QString &language)
{
if (rawValue.size() > 6 && rawValue.startsWith(QLatin1String("lang=\""))) {
int pos = rawValue.indexOf('"', 6);
if (pos != -1) {
language = rawValue.mid(6, pos - 6);
return (rawValue.mid(pos + 2));
}
}
language.clear();
return rawValue;
}

View File

@ -23,6 +23,9 @@ public:
QString label(const QString & key) const; QString label(const QString & key) const;
QString value(const QString & key) const; QString value(const QString & key) const;
static QString XmpValue(const QString &rawValue);
static QString XmpValue(const QString &rawValue, QString & language);
private: private:
std::unique_ptr<Exiv2::Image> m_exivImage; std::unique_ptr<Exiv2::Image> m_exivImage;
QMap<QString, QString> m_metadataValue; QMap<QString, QString> m_metadataValue;

View File

@ -66,8 +66,14 @@ void MetadataModel::setFile(const QString &imageFilePath)
if (wrapper.load(imageFilePath)) { if (wrapper.load(imageFilePath)) {
wrapper.cacheSections(); wrapper.cacheSections();
appendExivPropertyIfExist(wrapper, QStringLiteral("Description"),
QStringLiteral("Xmp.dc.title"), tr("Title"), true);
appendExivPropertyIfExist(wrapper, QStringLiteral("Description"),
QStringLiteral("Exif.Image.ImageDescription"), tr("Subject"), true);
appendExivPropertyIfExist(wrapper, QStringLiteral("Description"), appendExivPropertyIfExist(wrapper, QStringLiteral("Description"),
QStringLiteral("Exif.Image.Rating"), tr("Rating")); QStringLiteral("Exif.Image.Rating"), tr("Rating"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Description"),
QStringLiteral("Xmp.dc.subject"), tr("Tags"));
appendPropertyIfNotEmpty(QStringLiteral("Description"), QStringLiteral("Description.Comments"), appendPropertyIfNotEmpty(QStringLiteral("Description"), QStringLiteral("Description.Comments"),
tr("Comments"), wrapper.comment()); tr("Comments"), wrapper.comment());
@ -75,6 +81,10 @@ void MetadataModel::setFile(const QString &imageFilePath)
QStringLiteral("Exif.Image.Artist"), tr("Authors")); QStringLiteral("Exif.Image.Artist"), tr("Authors"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"), appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"),
QStringLiteral("Exif.Photo.DateTimeOriginal"), tr("Date taken")); QStringLiteral("Exif.Photo.DateTimeOriginal"), tr("Date taken"));
// FIXME: We may fetch the same type of metadata from different metadata collection.
// Current implementation is not pretty and may need to do a rework...
// appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"),
// QStringLiteral("Xmp.xmp.CreatorTool"), tr("Program name"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"), appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"),
QStringLiteral("Exif.Image.Software"), tr("Program name")); QStringLiteral("Exif.Image.Software"), tr("Program name"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"), appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"),
@ -206,23 +216,13 @@ bool MetadataModel::appendProperty(const QString &sectionKey, const QString &pro
return true; return true;
} }
bool MetadataModel::updateProperty(const QString &propertyKey, const QString &propertyValue) bool MetadataModel::appendExivPropertyIfExist(const Exiv2Wrapper &wrapper, const QString &sectionKey, const QString &exiv2propertyKey, const QString &propertyDisplayName, bool isXmpString)
{
if (m_properties.contains(propertyKey)) {
m_properties[propertyKey].second = propertyValue;
return true;
}
return false;
}
bool MetadataModel::appendExivPropertyIfExist(const Exiv2Wrapper &wrapper, const QString &sectionKey, const QString &exiv2propertyKey, const QString &propertyDisplayName)
{ {
const QString & value = wrapper.value(exiv2propertyKey); const QString & value = wrapper.value(exiv2propertyKey);
if (!value.isEmpty()) { if (!value.isEmpty()) {
appendProperty(sectionKey, exiv2propertyKey, appendProperty(sectionKey, exiv2propertyKey,
propertyDisplayName.isEmpty() ? wrapper.label(exiv2propertyKey) : propertyDisplayName, propertyDisplayName.isEmpty() ? wrapper.label(exiv2propertyKey) : propertyDisplayName,
value); isXmpString ? Exiv2Wrapper::XmpValue(value) : value);
return true; return true;
} }
return false; return false;

View File

@ -20,9 +20,9 @@ public:
const QString & propertyDisplayName, const QString & propertyValue = QString()); const QString & propertyDisplayName, const QString & propertyValue = QString());
bool appendProperty(const QString & sectionKey, const QString & propertyKey, bool appendProperty(const QString & sectionKey, const QString & propertyKey,
const QString & propertyDisplayName, const QString & propertyValue = QString()); const QString & propertyDisplayName, const QString & propertyValue = QString());
bool updateProperty(const QString & propertyKey, const QString & propertyValue);
bool appendExivPropertyIfExist(const Exiv2Wrapper & wrapper, const QString & sectionKey, bool appendExivPropertyIfExist(const Exiv2Wrapper & wrapper, const QString & sectionKey,
const QString & exiv2propertyKey, const QString & propertyDisplayName = QString()); const QString & exiv2propertyKey, const QString & propertyDisplayName = QString(),
bool isXmpString = false);
private: private:
enum RowType : quintptr { enum RowType : quintptr {