Commit fbb7d684 authored by Volker Krause's avatar Volker Krause
Browse files

Add API to check for the presence of image assets

parent 6271b908
Pipeline #165223 passed with stages
in 2 minutes and 29 seconds
......@@ -75,6 +75,8 @@ private Q_SLOTS:
QCOMPARE(loc.relevantText(), QLatin1String("LX962 Boarding 20:25"));
QCOMPARE(pass->maximumDistance(), 500);
QCOMPARE(pass->hasIcon(), false);
QCOMPARE(pass->hasLogo(), true);
auto img = pass->logo(3);
img = pass->image(QStringLiteral("I don't exist"));
......@@ -346,6 +346,49 @@ QString Pass::logoText() const
return d->message(d->passObj.value(QLatin1String("logoText")).toString());
bool Pass::hasImage(const QString &baseName) const
const auto entries = d->zip->directory()->entries();
for (const auto &entry : entries) {
if (entry.startsWith(baseName)
&& (QStringView(entry).mid(baseName.size()).startsWith(QLatin1Char('@')) || QStringView(entry).mid(baseName.size()).startsWith(QLatin1Char('.')))
&& entry.endsWith(QLatin1String(".png"))) {
return true;
return false;
bool Pass::hasIcon() const
return hasImage(QStringLiteral("icon"));
bool Pass::hasLogo() const
return hasImage(QStringLiteral("logo"));
bool Pass::hasStrip() const
return hasImage(QStringLiteral("strip"));
bool Pass::hasBackground() const
return hasImage(QStringLiteral("background"));
bool Pass::hasFooter() const
return hasImage(QStringLiteral("footer"));
bool Pass::hasThumbnail() const
return hasImage(QStringLiteral("thumbnail"));
QImage Pass::image(const QString &baseName, unsigned int devicePixelRatio) const
const KArchiveFile *file = nullptr;
......@@ -52,6 +52,13 @@ class KPKPASS_EXPORT Pass : public QObject
Q_PROPERTY(QColor labelColor READ labelColor CONSTANT)
Q_PROPERTY(QString logoText READ logoText CONSTANT)
Q_PROPERTY(bool hasIcon READ hasIcon CONSTANT)
Q_PROPERTY(bool hasLogo READ hasLogo CONSTANT)
Q_PROPERTY(bool hasStrip READ hasStrip CONSTANT)
Q_PROPERTY(bool hasBackground READ hasBackground CONSTANT)
Q_PROPERTY(bool hasFooter READ hasFooter CONSTANT)
Q_PROPERTY(bool hasThumbnail READ hasThumbnail CONSTANT)
// needs to be QVariantList just for QML (Grantlee would also work with QVector<Field>
Q_PROPERTY(QVariantList barcodes READ barcodesVariant CONSTANT)
Q_PROPERTY(QVariantList auxiliaryFields READ auxiliaryFieldsVariant CONSTANT)
......@@ -96,6 +103,18 @@ public:
Q_REQUIRED_RESULT QColor labelColor() const;
Q_REQUIRED_RESULT QString logoText() const;
/** Returns @c true if an image asset with the given base name exists.
* @param baseName The name of the asset, without the file type and high dpi extensions.
* @since 5.20.41
bool hasImage(const QString &baseName) const;
bool hasIcon() const;
bool hasLogo() const;
bool hasStrip() const;
bool hasBackground() const;
bool hasFooter() const;
bool hasThumbnail() const;
/** Returns an image asset of this pass.
* @param baseName The name of the asset, without the file name extension.
* @param devicePixelRatio The device pixel ration, for loading highdpi assets.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment