chore: make use of Qt::Literals::StringLiterals u""_s

Migrate string literal handling to Qt’s built‐in `u""_s` literals for consistency and readability.
This commit is contained in:
2025-05-31 13:10:21 +08:00
committed by GitHub
parent 291a98ea97
commit 3f7ebd2f6c
5 changed files with 154 additions and 150 deletions

View File

@ -14,6 +14,8 @@
#include <QPushButton> #include <QPushButton>
#include <QFile> #include <QFile>
using namespace Qt::Literals::StringLiterals;
AboutDialog::AboutDialog(QWidget *parent) AboutDialog::AboutDialog(QWidget *parent)
: QDialog(parent) : QDialog(parent)
, m_tabWidget(new QTabWidget) , m_tabWidget(new QTabWidget)
@ -27,60 +29,60 @@ AboutDialog::AboutDialog(QWidget *parent)
this->setWindowTitle(tr("About")); this->setWindowTitle(tr("About"));
const QStringList helpStr { const QStringList helpStr {
QStringLiteral("<p>%1</p>").arg(tr("Launch application with image file path as argument to load the file.")), u"<p>%1</p>"_s.arg(tr("Launch application with image file path as argument to load the file.")),
QStringLiteral("<p>%1</p>").arg(tr("Drag and drop image file onto the window is also supported.")), u"<p>%1</p>"_s.arg(tr("Drag and drop image file onto the window is also supported.")),
QStringLiteral("<p>%1</p>").arg(tr("None of the operations in this application will alter the pictures on disk.")), u"<p>%1</p>"_s.arg(tr("None of the operations in this application will alter the pictures on disk.")),
QStringLiteral("<p>%1</p>").arg(tr("Context menu option explanation:")), u"<p>%1</p>"_s.arg(tr("Context menu option explanation:")),
QStringLiteral("<ul>"), u"<ul>"_s,
// blumia: Chain two arg() here since it seems lupdate will remove one of them if we use // blumia: Chain two arg() here since it seems lupdate will remove one of them if we use
// the old `arg(QCoreApp::translate(), tr())` way, but it's worth to mention // the old `arg(QCoreApp::translate(), tr())` way, but it's worth to mention
// `arg(QCoreApp::translate(), this->tr())` works, but lupdate will complain about the usage. // `arg(QCoreApp::translate(), this->tr())` works, but lupdate will complain about the usage.
QStringLiteral("<li><b>%1</b>:<br/>%2</li>") u"<li><b>%1</b>:<br/>%2</li>"_s
.arg(QCoreApplication::translate("MainWindow", "Stay on top")) .arg(QCoreApplication::translate("MainWindow", "Stay on top"))
.arg(tr("Make window stay on top of all other windows.")), .arg(tr("Make window stay on top of all other windows.")),
QStringLiteral("<li><b>%1</b>:<br/>%2</li>") u"<li><b>%1</b>:<br/>%2</li>"_s
.arg(QCoreApplication::translate("MainWindow", "Protected mode")) .arg(QCoreApplication::translate("MainWindow", "Protected mode"))
.arg(tr("Avoid close window accidentally. (eg. by double clicking the window)")), .arg(tr("Avoid close window accidentally. (eg. by double clicking the window)")),
QStringLiteral("<li><b>%1</b>:<br/>%2</li>") u"<li><b>%1</b>:<br/>%2</li>"_s
.arg(QCoreApplication::translate("MainWindow", "Keep transformation", "The 'transformation' means the flip/rotation status that currently applied to the image view")) .arg(QCoreApplication::translate("MainWindow", "Keep transformation", "The 'transformation' means the flip/rotation status that currently applied to the image view"))
.arg(tr("Avoid resetting the zoom/rotation/flip state that was applied to the image view when switching between images.")), .arg(tr("Avoid resetting the zoom/rotation/flip state that was applied to the image view when switching between images.")),
QStringLiteral("</ul>") u"</ul>"_s
}; };
const QStringList aboutStr { const QStringList aboutStr {
QStringLiteral("<center><img width='128' height='128' src=':/icons/app-icon.svg'/><br/>"), u"<center><img width='128' height='128' src=':/icons/app-icon.svg'/><br/>"_s,
qApp->applicationDisplayName(), qApp->applicationDisplayName(),
(QStringLiteral("<br/>") + tr("Version: %1").arg( (u"<br/>"_s + tr("Version: %1").arg(
#ifdef GIT_DESCRIBE_VERSION_STRING #ifdef GIT_DESCRIBE_VERSION_STRING
GIT_DESCRIBE_VERSION_STRING GIT_DESCRIBE_VERSION_STRING
#else #else
qApp->applicationVersion() qApp->applicationVersion()
#endif // GIT_DESCRIBE_VERSION_STRING #endif // GIT_DESCRIBE_VERSION_STRING
)), )),
QStringLiteral("<hr/>"), u"<hr/>"_s,
tr("Copyright (c) %1 %2", "%1 is year, %2 is the name of copyright holder(s)") tr("Copyright (c) %1 %2", "%1 is year, %2 is the name of copyright holder(s)")
.arg(QStringLiteral("2025"), QStringLiteral("<a href='https://github.com/BLumia'>@BLumia</a>")), .arg(u"2025"_s, u"<a href='https://github.com/BLumia'>@BLumia</a>"_s),
QStringLiteral("<br/>"), u"<br/>"_s,
tr("Logo designed by %1").arg(QStringLiteral("<a href='https://github.com/Lovelyblack'>@Lovelyblack</a>")), tr("Logo designed by %1").arg(u"<a href='https://github.com/Lovelyblack'>@Lovelyblack</a>"_s),
QStringLiteral("<hr/>"), u"<hr/>"_s,
tr("Built with Qt %1 (%2)").arg(QT_VERSION_STR, QSysInfo::buildCpuArchitecture()), tr("Built with Qt %1 (%2)").arg(QT_VERSION_STR, QSysInfo::buildCpuArchitecture()),
QStringLiteral("<br/><a href='%1'>%2</a>").arg("https://github.com/BLumia/pineapple-pictures", tr("Source code")), QStringLiteral("<br/><a href='%1'>%2</a>").arg("https://github.com/BLumia/pineapple-pictures", tr("Source code")),
QStringLiteral("</center>") u"</center>"_s
}; };
QFile translaterHtml(":/plain/translators.html"); QFile translaterHtml(u":/plain/translators.html"_s);
bool canOpenFile = translaterHtml.open(QIODevice::ReadOnly); bool canOpenFile = translaterHtml.open(QIODevice::ReadOnly);
const QByteArray & translatorList = canOpenFile ? translaterHtml.readAll() : QByteArrayLiteral(""); const QByteArray & translatorList = canOpenFile ? translaterHtml.readAll() : QByteArrayLiteral("");
const QStringList specialThanksStr { const QStringList specialThanksStr {
QStringLiteral("<h1 align='center'>%1</h1><a href='%2'>%3</a><p>%4</p>").arg( u"<h1 align='center'>%1</h1><a href='%2'>%3</a><p>%4</p>"_s.arg(
tr("Contributors"), tr("Contributors"),
QStringLiteral("https://github.com/BLumia/pineapple-pictures/graphs/contributors"), u"https://github.com/BLumia/pineapple-pictures/graphs/contributors"_s,
tr("List of contributors on GitHub"), tr("List of contributors on GitHub"),
tr("Thanks to all people who contributed to this project.") tr("Thanks to all people who contributed to this project.")
), ),
QStringLiteral("<h1 align='center'>%1</h1><p>%2</p>%3").arg( u"<h1 align='center'>%1</h1><p>%2</p>%3"_s.arg(
tr("Translators"), tr("Translators"),
tr("I would like to thank the following people who volunteered to translate this application."), tr("I would like to thank the following people who volunteered to translate this application."),
translatorList translatorList
@ -88,17 +90,17 @@ AboutDialog::AboutDialog(QWidget *parent)
}; };
const QStringList licenseStr { const QStringList licenseStr {
QStringLiteral("<h1 align='center'><b>%1</b></h1>").arg(tr("Your Rights")), u"<h1 align='center'><b>%1</b></h1>"_s.arg(tr("Your Rights")),
QStringLiteral("<p>%1</p><p>%2</p><ul><li>%3</li><li>%4</li><li>%5</li><li>%6</li></ul>").arg( u"<p>%1</p><p>%2</p><ul><li>%3</li><li>%4</li><li>%5</li><li>%6</li></ul>"_s.arg(
tr("%1 is released under the MIT License."), // %1 tr("%1 is released under the MIT License."), // %1
tr("This license grants people a number of freedoms:"), // %2 tr("This license grants people a number of freedoms:"), // %2
tr("You are free to use %1, for any purpose"), // %3 tr("You are free to use %1, for any purpose"), // %3
tr("You are free to distribute %1"), // %4 tr("You are free to distribute %1"), // %4
tr("You can study how %1 works and change it"), // %5 tr("You can study how %1 works and change it"), // %5
tr("You can distribute changed versions of %1") // %6 tr("You can distribute changed versions of %1") // %6
).arg(QStringLiteral("<i>%1</i>")), ).arg(u"<i>%1</i>"_s),
QStringLiteral("<p>%1</p>").arg(tr("The MIT license guarantees you this freedom. Nobody is ever permitted to take it away.")), u"<p>%1</p>"_s.arg(tr("The MIT license guarantees you this freedom. Nobody is ever permitted to take it away.")),
QStringLiteral("<hr/><pre>%2</pre>") u"<hr/><pre>%2</pre>"_s
}; };
const QString mitLicense(QStringLiteral(R"(Expat/MIT License const QString mitLicense(QStringLiteral(R"(Expat/MIT License
@ -125,14 +127,14 @@ SOFTWARE.
)")); )"));
const QStringList thirdPartyLibsStr { const QStringList thirdPartyLibsStr {
QStringLiteral("<h1 align='center'><b>%1</b></h1>").arg(tr("Third-party Libraries used by %1")), u"<h1 align='center'><b>%1</b></h1>"_s.arg(tr("Third-party Libraries used by %1")),
tr("%1 is built on the following free software libraries:", "Free as in freedom"), tr("%1 is built on the following free software libraries:", "Free as in freedom"),
QStringLiteral("<ul>"), u"<ul>"_s,
#ifdef HAVE_EXIV2_VERSION #ifdef HAVE_EXIV2_VERSION
QStringLiteral("<li><a href='%1'>%2</a>: %3</li>").arg("https://www.exiv2.org/", "Exiv2", "GPLv2"), u"<li><a href='%1'>%2</a>: %3</li>"_s.arg("https://www.exiv2.org/", "Exiv2", "GPLv2"),
#endif // EXIV2_VERSION #endif // EXIV2_VERSION
QStringLiteral("<li><a href='%1'>%2</a>: %3</li>").arg("https://www.qt.io/", "Qt", "GPLv2 + GPLv3 + LGPLv2.1 + LGPLv3"), u"<li><a href='%1'>%2</a>: %3</li>"_s.arg("https://www.qt.io/", "Qt", "GPLv2 + GPLv3 + LGPLv2.1 + LGPLv3"),
QStringLiteral("</ul>") u"</ul>"_s
}; };
m_helpTextEdit->setText(helpStr.join('\n')); m_helpTextEdit->setText(helpStr.join('\n'));
@ -145,7 +147,7 @@ SOFTWARE.
m_licenseTextEdit->setText(licenseStr.join('\n').arg(qApp->applicationDisplayName(), mitLicense)); m_licenseTextEdit->setText(licenseStr.join('\n').arg(qApp->applicationDisplayName(), mitLicense));
m_3rdPartyLibsTextEdit->setText(thirdPartyLibsStr.join('\n').arg(QStringLiteral("<i>%1</i>").arg(qApp->applicationDisplayName()))); m_3rdPartyLibsTextEdit->setText(thirdPartyLibsStr.join('\n').arg(u"<i>%1</i>"_s).arg(qApp->applicationDisplayName()));
m_3rdPartyLibsTextEdit->setOpenExternalLinks(true); m_3rdPartyLibsTextEdit->setOpenExternalLinks(true);
m_tabWidget->addTab(m_helpTextEdit, tr("&Help")); m_tabWidget->addTab(m_helpTextEdit, tr("&Help"));

View File

@ -6,8 +6,6 @@
#include "opacityhelper.h" #include "opacityhelper.h"
#include <functional>
#include <QToolButton> #include <QToolButton>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QDebug> #include <QDebug>

View File

@ -17,9 +17,11 @@
#include <QTranslator> #include <QTranslator>
#include <QUrl> #include <QUrl>
using namespace Qt::Literals::StringLiterals;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QCoreApplication::setApplicationName("Pineapple Pictures"); QCoreApplication::setApplicationName(u"Pineapple Pictures"_s);
QCoreApplication::setApplicationVersion(PPIC_VERSION_STRING); QCoreApplication::setApplicationVersion(PPIC_VERSION_STRING);
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Settings::instance()->hiDpiScaleFactorBehavior()); QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Settings::instance()->hiDpiScaleFactorBehavior());
@ -27,20 +29,20 @@ int main(int argc, char *argv[])
QTranslator translator; QTranslator translator;
#if defined(TRANSLATION_RESOURCE_EMBEDDING) #if defined(TRANSLATION_RESOURCE_EMBEDDING)
const QString qmDir = QLatin1String(":/i18n/"); const QString qmDir = u":/i18n/"_s;
#elif defined(QM_FILE_INSTALL_ABSOLUTE_DIR) #elif defined(QM_FILE_INSTALL_ABSOLUTE_DIR)
const QString qmDir = QT_STRINGIFY(QM_FILE_INSTALL_ABSOLUTE_DIR); const QString qmDir = QT_STRINGIFY(QM_FILE_INSTALL_ABSOLUTE_DIR);
#else #else
const QString qmDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations"); const QString qmDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations");
#endif #endif
if (translator.load(QLocale(), QLatin1String("PineapplePictures"), QLatin1String("_"), qmDir)) { if (translator.load(QLocale(), u"PineapplePictures"_s, u"_"_s, qmDir)) {
QCoreApplication::installTranslator(&translator); QCoreApplication::installTranslator(&translator);
} }
QGuiApplication::setApplicationDisplayName(QCoreApplication::translate("main", "Pineapple Pictures")); QGuiApplication::setApplicationDisplayName(QCoreApplication::translate("main", "Pineapple Pictures"));
// commandline options // commandline options
QCommandLineOption supportedImageFormats(QStringLiteral("supported-image-formats"), QCoreApplication::translate("main", "List supported image format suffixes, and quit program.")); QCommandLineOption supportedImageFormats(u"supported-image-formats"_s, QCoreApplication::translate("main", "List supported image format suffixes, and quit program."));
// parse commandline arguments // parse commandline arguments
QCommandLineParser parser; QCommandLineParser parser;
parser.addOption(supportedImageFormats); parser.addOption(supportedImageFormats);

View File

@ -44,6 +44,8 @@
#include <QDBusConnectionInterface> #include <QDBusConnectionInterface>
#endif // HAVE_QTDBUS #endif // HAVE_QTDBUS
using namespace Qt::Literals::StringLiterals;
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: FramelessWindow(parent) : FramelessWindow(parent)
, m_am(new ActionManager) , m_am(new ActionManager)
@ -56,17 +58,17 @@ MainWindow::MainWindow(QWidget *parent)
this->setAttribute(Qt::WA_TranslucentBackground, true); this->setAttribute(Qt::WA_TranslucentBackground, true);
this->setMinimumSize(350, 330); this->setMinimumSize(350, 330);
this->setWindowIcon(QIcon(":/icons/app-icon.svg")); this->setWindowIcon(QIcon(u":/icons/app-icon.svg"_s));
this->setMouseTracking(true); this->setMouseTracking(true);
this->setAcceptDrops(true); this->setAcceptDrops(true);
m_pm->setAutoLoadFilterSuffixes(supportedImageFormats()); m_pm->setAutoLoadFilterSuffixes(supportedImageFormats());
m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity"); m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity"_ba);
m_fadeOutAnimation->setDuration(300); m_fadeOutAnimation->setDuration(300);
m_fadeOutAnimation->setStartValue(1); m_fadeOutAnimation->setStartValue(1);
m_fadeOutAnimation->setEndValue(0); m_fadeOutAnimation->setEndValue(0);
m_floatUpAnimation = new QPropertyAnimation(this, "geometry"); m_floatUpAnimation = new QPropertyAnimation(this, "geometry"_ba);
m_floatUpAnimation->setDuration(300); m_floatUpAnimation->setDuration(300);
m_floatUpAnimation->setEasingCurve(QEasingCurve::OutCirc); m_floatUpAnimation->setEasingCurve(QEasingCurve::OutCirc);
m_exitAnimationGroup = new QParallelAnimationGroup(this); m_exitAnimationGroup = new QParallelAnimationGroup(this);
@ -92,7 +94,7 @@ MainWindow::MainWindow(QWidget *parent)
m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio); m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio);
connect(m_graphicsView, &GraphicsView::navigatorViewRequired, connect(m_graphicsView, &GraphicsView::navigatorViewRequired,
this, [ = ](bool required, const QTransform & tf){ this, [this](bool required, const QTransform & tf){
m_gv->setTransform(GraphicsView::resetScale(tf)); m_gv->setTransform(GraphicsView::resetScale(tf));
m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio); m_gv->fitInView(m_gv->sceneRect(), Qt::KeepAspectRatio);
m_gv->setVisible(required); m_gv->setVisible(required);
@ -447,13 +449,11 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event)
QMenu * menu = new QMenu; QMenu * menu = new QMenu;
QMenu * copyMenu = new QMenu(tr("&Copy")); QMenu * copyMenu = new QMenu(tr("&Copy"));
QUrl currentFileUrl = currentImageFileUrl(); QUrl currentFileUrl = currentImageFileUrl();
QImage clipboardImage;
QUrl clipboardFileUrl;
QAction * copyPixmap = m_am->actionCopyPixmap; QAction * copyPixmap = m_am->actionCopyPixmap;
QAction * copyFilePath = m_am->actionCopyFilePath; QAction * copyFilePath = m_am->actionCopyFilePath;
copyMenu->setIcon(QIcon::fromTheme(QLatin1String("edit-copy"))); copyMenu->setIcon(QIcon::fromTheme(u"edit-copy"_s));
copyMenu->addAction(copyPixmap); copyMenu->addAction(copyPixmap);
if (currentFileUrl.isValid()) { if (currentFileUrl.isValid()) {
copyMenu->addAction(copyFilePath); copyMenu->addAction(copyFilePath);
@ -780,7 +780,7 @@ void MainWindow::on_actionTrash_triggered()
if (result == QMessageBox::Yes) { if (result == QMessageBox::Yes) {
bool succ = file.moveToTrash(); bool succ = file.moveToTrash();
if (!succ) { if (!succ) {
QMessageBox::warning(this, "Failed to move file to trash", QMessageBox::warning(this, tr("Failed to move file to trash"),
tr("Move to trash failed, it might caused by file permission issue, file system limitation, or platform limitation.")); tr("Move to trash failed, it might caused by file permission issue, file system limitation, or platform limitation."));
} else { } else {
m_pm->removeAt(index); m_pm->removeAt(index);
@ -891,9 +891,9 @@ void MainWindow::on_actionLocateInFileManager_triggered()
QDesktopServices::openUrl(folderUrl); QDesktopServices::openUrl(folderUrl);
return; return;
} }
QDBusInterface fm1Iface(QStringLiteral("org.freedesktop.FileManager1"), QDBusInterface fm1Iface(u"org.freedesktop.FileManager1"_s,
QStringLiteral("/org/freedesktop/FileManager1"), u"/org/freedesktop/FileManager1"_s,
QStringLiteral("org.freedesktop.FileManager1")); u"org.freedesktop.FileManager1"_s);
fm1Iface.setTimeout(1000); fm1Iface.setTimeout(1000);
fm1Iface.callWithArgumentList(QDBus::Block, "ShowItems", { fm1Iface.callWithArgumentList(QDBus::Block, "ShowItems", {
QStringList{currentFileUrl.toString()}, QStringList{currentFileUrl.toString()},

View File

@ -11,6 +11,8 @@
#include <QFileInfo> #include <QFileInfo>
#include <QImageReader> #include <QImageReader>
using namespace Qt::Literals::StringLiterals;
MetadataModel::MetadataModel(QObject *parent) MetadataModel::MetadataModel(QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
{ {
@ -37,131 +39,131 @@ void MetadataModel::setFile(const QString &imageFilePath)
const QString & imageDimensionsString = imageSize(imgReader.size()); const QString & imageDimensionsString = imageSize(imgReader.size());
const QString & imageRatioString = imageSizeRatio(imgReader.size()); const QString & imageRatioString = imageSizeRatio(imgReader.size());
appendSection(QStringLiteral("Description"), tr("Description", "Section name.")); appendSection(u"Description"_s, tr("Description", "Section name."));
appendSection(QStringLiteral("Origin"), tr("Origin", "Section name.")); appendSection(u"Origin"_s, tr("Origin", "Section name."));
appendSection(QStringLiteral("Image"), tr("Image", "Section name.")); appendSection(u"Image"_s, tr("Image", "Section name."));
appendSection(QStringLiteral("Camera"), tr("Camera", "Section name.")); appendSection(u"Camera"_s, tr("Camera", "Section name."));
appendSection(QStringLiteral("AdvancedPhoto"), tr("Advanced photo", "Section name.")); appendSection(u"AdvancedPhoto"_s, tr("Advanced photo", "Section name."));
appendSection(QStringLiteral("GPS"), tr("GPS", "Section name.")); appendSection(u"GPS"_s, tr("GPS", "Section name."));
appendSection(QStringLiteral("File"), tr("File", "Section name.")); appendSection(u"File"_s, tr("File", "Section name."));
if (imgReader.supportsOption(QImageIOHandler::Size)) { if (imgReader.supportsOption(QImageIOHandler::Size)) {
appendProperty(QStringLiteral("Image"), QStringLiteral("Image.Dimensions"), appendProperty(u"Image"_s, u"Image.Dimensions"_s,
tr("Dimensions"), imageDimensionsString); tr("Dimensions"), imageDimensionsString);
appendProperty(QStringLiteral("Image"), QStringLiteral("Image.SizeRatio"), appendProperty(u"Image"_s, u"Image.SizeRatio"_s,
tr("Aspect ratio"), imageRatioString); tr("Aspect ratio"), imageRatioString);
} }
if (imgReader.supportsAnimation() && imgReader.imageCount() > 1) { if (imgReader.supportsAnimation() && imgReader.imageCount() > 1) {
appendProperty(QStringLiteral("Image"), QStringLiteral("Image.FrameCount"), appendProperty(u"Image"_s, u"Image.FrameCount"_s,
tr("Frame count"), QString::number(imgReader.imageCount())); tr("Frame count"), QString::number(imgReader.imageCount()));
} }
appendProperty(QStringLiteral("File"), QStringLiteral("File.Name"), appendProperty(u"File"_s, u"File.Name"_s,
tr("Name"), fileInfo.fileName()); tr("Name"), fileInfo.fileName());
appendProperty(QStringLiteral("File"), QStringLiteral("File.ItemType"), appendProperty(u"File"_s, u"File.ItemType"_s,
tr("Item type"), itemTypeString); tr("Item type"), itemTypeString);
appendProperty(QStringLiteral("File"), QStringLiteral("File.Path"), appendProperty(u"File"_s, u"File.Path"_s,
tr("Folder path"), QDir::toNativeSeparators(fileInfo.path())); tr("Folder path"), QDir::toNativeSeparators(fileInfo.path()));
appendProperty(QStringLiteral("File"), QStringLiteral("File.Size"), appendProperty(u"File"_s, u"File.Size"_s,
tr("Size"), sizeString); tr("Size"), sizeString);
appendProperty(QStringLiteral("File"), QStringLiteral("File.CreatedTime"), appendProperty(u"File"_s, u"File.CreatedTime"_s,
tr("Date created"), birthTimeString); tr("Date created"), birthTimeString);
appendProperty(QStringLiteral("File"), QStringLiteral("File.LastModified"), appendProperty(u"File"_s, u"File.LastModified"_s,
tr("Date modified"), lastModifiedTimeString); tr("Date modified"), lastModifiedTimeString);
Exiv2Wrapper wrapper; Exiv2Wrapper wrapper;
if (wrapper.load(imageFilePath)) { if (wrapper.load(imageFilePath)) {
wrapper.cacheSections(); wrapper.cacheSections();
appendExivPropertyIfExist(wrapper, QStringLiteral("Description"), appendExivPropertyIfExist(wrapper, u"Description"_s,
QStringLiteral("Xmp.dc.title"), tr("Title"), true); u"Xmp.dc.title"_s, tr("Title"), true);
appendExivPropertyIfExist(wrapper, QStringLiteral("Description"), appendExivPropertyIfExist(wrapper, u"Description"_s,
QStringLiteral("Exif.Image.ImageDescription"), tr("Subject"), true); u"Exif.Image.ImageDescription"_s, tr("Subject"), true);
appendExivPropertyIfExist(wrapper, QStringLiteral("Description"), appendExivPropertyIfExist(wrapper, u"Description"_s,
QStringLiteral("Exif.Image.Rating"), tr("Rating")); u"Exif.Image.Rating"_s, tr("Rating"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Description"), appendExivPropertyIfExist(wrapper, u"Description"_s,
QStringLiteral("Xmp.dc.subject"), tr("Tags")); u"Xmp.dc.subject"_s, tr("Tags"));
appendPropertyIfNotEmpty(QStringLiteral("Description"), QStringLiteral("Description.Comments"), appendPropertyIfNotEmpty(u"Description"_s, u"Description.Comments"_s,
tr("Comments"), wrapper.comment()); tr("Comments"), wrapper.comment());
appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"), appendExivPropertyIfExist(wrapper, u"Origin"_s,
QStringLiteral("Exif.Image.Artist"), tr("Authors")); u"Exif.Image.Artist"_s, tr("Authors"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"), appendExivPropertyIfExist(wrapper, u"Origin"_s,
QStringLiteral("Exif.Photo.DateTimeOriginal"), tr("Date taken")); u"Exif.Photo.DateTimeOriginal"_s, tr("Date taken"));
// FIXME: We may fetch the same type of metadata from different metadata collection. // 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... // Current implementation is not pretty and may need to do a rework...
// appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"), // appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"),
// QStringLiteral("Xmp.xmp.CreatorTool"), tr("Program name")); // QStringLiteral("Xmp.xmp.CreatorTool"), tr("Program name"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"), appendExivPropertyIfExist(wrapper, u"Origin"_s,
QStringLiteral("Exif.Image.Software"), tr("Program name")); u"Exif.Image.Software"_s, tr("Program name"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Origin"), appendExivPropertyIfExist(wrapper, u"Origin"_s,
QStringLiteral("Exif.Image.Copyright"), tr("Copyright")); u"Exif.Image.Copyright"_s, tr("Copyright"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Image"), appendExivPropertyIfExist(wrapper, u"Image"_s,
QStringLiteral("Exif.Image.XResolution"), tr("Horizontal resolution")); u"Exif.Image.XResolution"_s, tr("Horizontal resolution"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Image"), appendExivPropertyIfExist(wrapper, u"Image"_s,
QStringLiteral("Exif.Image.YResolution"), tr("Vertical resolution")); u"Exif.Image.YResolution"_s, tr("Vertical resolution"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Image"), appendExivPropertyIfExist(wrapper, u"Image"_s,
QStringLiteral("Exif.Image.ResolutionUnit"), tr("Resolution unit")); u"Exif.Image.ResolutionUnit"_s, tr("Resolution unit"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Image"), appendExivPropertyIfExist(wrapper, u"Image"_s,
QStringLiteral("Exif.Photo.ColorSpace"), tr("Colour representation")); u"Exif.Photo.ColorSpace"_s, tr("Colour representation"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"), appendExivPropertyIfExist(wrapper, u"Camera"_s,
QStringLiteral("Exif.Image.Make"), tr("Camera maker")); u"Exif.Image.Make"_s, tr("Camera maker"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"), appendExivPropertyIfExist(wrapper, u"Camera"_s,
QStringLiteral("Exif.Image.Model"), tr("Camera model")); u"Exif.Image.Model"_s, tr("Camera model"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"), appendExivPropertyIfExist(wrapper, u"Camera"_s,
QStringLiteral("Exif.Photo.FNumber"), tr("F-stop")); u"Exif.Photo.FNumber"_s, tr("F-stop"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"), appendExivPropertyIfExist(wrapper, u"Camera"_s,
QStringLiteral("Exif.Photo.ExposureTime"), tr("Exposure time")); u"Exif.Photo.ExposureTime"_s, tr("Exposure time"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"), appendExivPropertyIfExist(wrapper, u"Camera"_s,
QStringLiteral("Exif.Photo.ISOSpeedRatings"), tr("ISO speed")); u"Exif.Photo.ISOSpeedRatings"_s, tr("ISO speed"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"), appendExivPropertyIfExist(wrapper, u"Camera"_s,
QStringLiteral("Exif.Photo.ExposureBiasValue"), tr("Exposure bias")); u"Exif.Photo.ExposureBiasValue"_s, tr("Exposure bias"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"), appendExivPropertyIfExist(wrapper, u"Camera"_s,
QStringLiteral("Exif.Photo.FocalLength"), tr("Focal length")); u"Exif.Photo.FocalLength"_s, tr("Focal length"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"), appendExivPropertyIfExist(wrapper, u"Camera"_s,
QStringLiteral("Exif.Photo.MaxApertureValue"), tr("Max aperture")); u"Exif.Photo.MaxApertureValue"_s, tr("Max aperture"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"), appendExivPropertyIfExist(wrapper, u"Camera"_s,
QStringLiteral("Exif.Photo.MeteringMode"), tr("Metering mode")); u"Exif.Photo.MeteringMode"_s, tr("Metering mode"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"), appendExivPropertyIfExist(wrapper, u"Camera"_s,
QStringLiteral("Exif.Photo.SubjectDistance"), tr("Subject distance")); u"Exif.Photo.SubjectDistance"_s, tr("Subject distance"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"), appendExivPropertyIfExist(wrapper, u"Camera"_s,
QStringLiteral("Exif.Photo.Flash"), tr("Flash mode")); u"Exif.Photo.Flash"_s, tr("Flash mode"));
appendExivPropertyIfExist(wrapper, QStringLiteral("Camera"), appendExivPropertyIfExist(wrapper, u"Camera"_s,
QStringLiteral("Exif.Photo.FocalLengthIn35mmFilm"), tr("35mm focal length")); u"Exif.Photo.FocalLengthIn35mmFilm"_s, tr("35mm focal length"));
appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"), appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s,
QStringLiteral("Exif.Photo.LensModel"), tr("Lens model")); u"Exif.Photo.LensModel"_s, tr("Lens model"));
appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"), appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s,
QStringLiteral("Exif.Photo.Contrast"), tr("Contrast")); u"Exif.Photo.Contrast"_s, tr("Contrast"));
appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"), appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s,
QStringLiteral("Exif.Photo.BrightnessValue"), tr("Brightness")); u"Exif.Photo.BrightnessValue"_s, tr("Brightness"));
appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"), appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s,
QStringLiteral("Exif.Photo.ExposureProgram"), tr("Exposure program")); u"Exif.Photo.ExposureProgram"_s, tr("Exposure program"));
appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"), appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s,
QStringLiteral("Exif.Photo.Saturation"), tr("Saturation")); u"Exif.Photo.Saturation"_s, tr("Saturation"));
appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"), appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s,
QStringLiteral("Exif.Photo.Sharpness"), tr("Sharpness")); u"Exif.Photo.Sharpness"_s, tr("Sharpness"));
appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"), appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s,
QStringLiteral("Exif.Photo.WhiteBalance"), tr("White balance")); u"Exif.Photo.WhiteBalance"_s, tr("White balance"));
appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"), appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s,
QStringLiteral("Exif.Photo.DigitalZoomRatio"), tr("Digital zoom")); u"Exif.Photo.DigitalZoomRatio"_s, tr("Digital zoom"));
appendExivPropertyIfExist(wrapper, QStringLiteral("AdvancedPhoto"), appendExivPropertyIfExist(wrapper, u"AdvancedPhoto"_s,
QStringLiteral("Exif.Photo.ExifVersion"), tr("EXIF version")); u"Exif.Photo.ExifVersion"_s, tr("EXIF version"));
appendExivPropertyIfExist(wrapper, QStringLiteral("GPS"), appendExivPropertyIfExist(wrapper, u"GPS"_s,
QStringLiteral("Exif.GPSInfo.GPSLatitudeRef"), tr("Latitude reference")); u"Exif.GPSInfo.GPSLatitudeRef"_s, tr("Latitude reference"));
appendExivPropertyIfExist(wrapper, QStringLiteral("GPS"), appendExivPropertyIfExist(wrapper, u"GPS"_s,
QStringLiteral("Exif.GPSInfo.GPSLatitude"), tr("Latitude")); u"Exif.GPSInfo.GPSLatitude"_s, tr("Latitude"));
appendExivPropertyIfExist(wrapper, QStringLiteral("GPS"), appendExivPropertyIfExist(wrapper, u"GPS"_s,
QStringLiteral("Exif.GPSInfo.GPSLongitudeRef"), tr("Longitude reference")); u"Exif.GPSInfo.GPSLongitudeRef"_s, tr("Longitude reference"));
appendExivPropertyIfExist(wrapper, QStringLiteral("GPS"), appendExivPropertyIfExist(wrapper, u"GPS"_s,
QStringLiteral("Exif.GPSInfo.GPSLongitude"), tr("Longitude")); u"Exif.GPSInfo.GPSLongitude"_s, tr("Longitude"));
appendExivPropertyIfExist(wrapper, QStringLiteral("GPS"), appendExivPropertyIfExist(wrapper, u"GPS"_s,
QStringLiteral("Exif.GPSInfo.GPSAltitudeRef"), tr("Altitude reference")); u"Exif.GPSInfo.GPSAltitudeRef"_s, tr("Altitude reference"));
appendExivPropertyIfExist(wrapper, QStringLiteral("GPS"), appendExivPropertyIfExist(wrapper, u"GPS"_s,
QStringLiteral("Exif.GPSInfo.GPSAltitude"), tr("Altitude")); u"Exif.GPSInfo.GPSAltitude"_s, tr("Altitude"));
} }
} }