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

Generalize access to pass image assets

parent f0560a2c
......@@ -85,6 +85,11 @@ private slots:
QCOMPARE((int)loc.longitude(), 8);
QCOMPARE(loc.relevantText(), QLatin1String("LX962 Boarding 20:25"));
QCOMPARE(pass->maximumDistance(), 500);
auto img = pass->logo(3);
QVERIFY(!img.isNull());
img = pass->image(QLatin1String("I don't exist"));
QVERIFY(img.isNull());
}
};
......
......@@ -340,16 +340,16 @@ QString Pass::logoText() const
return d->message(d->passObj.value(QLatin1String("logoText")).toString());
}
QImage Pass::logo(unsigned int devicePixelRatio) const
QImage Pass::image(const QString& baseName, unsigned int devicePixelRatio) const
{
const KArchiveFile *file = nullptr;
for (; devicePixelRatio > 1; --devicePixelRatio) {
file = d->zip->directory()->file(QLatin1String("logo@") + QString::number(devicePixelRatio) + QLatin1String("x.png"));
file = d->zip->directory()->file(baseName + QLatin1Char('@') + QString::number(devicePixelRatio) + QLatin1String("x.png"));
if (file)
break;
}
if (!file)
file = d->zip->directory()->file(QLatin1String("logo.png"));
file = d->zip->directory()->file(baseName + QLatin1String(".png"));
if (!file)
return {};
std::unique_ptr<QIODevice> dev(file->createDevice());
......@@ -358,6 +358,16 @@ QImage Pass::logo(unsigned int devicePixelRatio) const
return img;
}
QImage Pass::icon(unsigned int devicePixelRatio) const
{
return image(QStringLiteral("icon"), devicePixelRatio);
}
QImage Pass::logo(unsigned int devicePixelRatio) const
{
return image(QStringLiteral("logo"), devicePixelRatio);
}
QString Pass::authenticationToken() const
{
return d->passObj.value(QLatin1String("authenticationToken")).toString();
......
......@@ -115,6 +115,14 @@ public:
QColor labelColor() const;
QString logoText() 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.
*/
QImage image(const QString &baseName, unsigned int devicePixelRatio = 1) const;
/** Returns the pass icon. */
QImage icon(unsigned int devicePixelRatio = 1) const;
/** Returns the pass logo. */
QImage logo(unsigned int devicePixelRatio = 1) const;
// web service keys
......
Markdown is supported
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