Commit 2fbddc5d authored by Volker Krause's avatar Volker Krause
Browse files

Add pass type property

parent a04cb943
......@@ -32,12 +32,14 @@ private slots:
void testBoardingPass()
{
std::unique_ptr<KPkPass::Pass> file(KPkPass::Pass::fromFile(QLatin1String(SOURCE_DIR "/data/boardingpass.pkpass")));
QVERIFY(file);
std::unique_ptr<KPkPass::Pass> pass(KPkPass::Pass::fromFile(QLatin1String(SOURCE_DIR "/data/boardingpass.pkpass")));
QVERIFY(pass);
QCOMPARE(file->logoText(), QLatin1String("Boarding Pass"));
QCOMPARE(pass->type(), KPkPass::Pass::BoardingPass);
QCOMPARE(pass->logoText(), QLatin1String("Boarding Pass"));
QCOMPARE(pass->backgroundColor(), QColor(61, 174, 233));
auto headers = file->headerFields();
auto headers = pass->headerFields();
QCOMPARE(headers.size(), 2);
auto field = headers.at(0);
QCOMPARE(field.label(), QLatin1String("Sitzplatz"));
......@@ -46,11 +48,11 @@ private slots:
QCOMPARE(field.key(), QLatin1String("seat"));
QCOMPARE(field.changeMessage(), QStringLiteral("Sitzplatznummer geändert in 10E"));
auto boardingPass = dynamic_cast<KPkPass::BoardingPass*>(file.get());
auto boardingPass = dynamic_cast<KPkPass::BoardingPass*>(pass.get());
QVERIFY(boardingPass);
QCOMPARE(boardingPass->transitType(), KPkPass::BoardingPass::Air);
auto barcodes = file->barcodes();
auto barcodes = pass->barcodes();
QCOMPARE(barcodes.size(), 1);
auto bc = barcodes.at(0);
QCOMPARE(bc.format(), KPkPass::Barcode::QR);
......
......@@ -73,6 +73,20 @@ QString Pass::serialNumber() const
return m_passObj.value(QLatin1String("serialNumber")).toString();
}
static const char* passTypes[] = { "boardingPass", "coupon", "eventTicket", "generic", "storeCard" };
static const auto passTypesCount = sizeof(passTypes) / sizeof(passTypes[0]);
Pass::Type KPkPass::Pass::type() const
{
for (unsigned int i = 0; i < passTypesCount; ++i) {
if (data().contains(QLatin1String(passTypes[i]))) {
return static_cast<Type>(i);
}
}
qCWarning(Log) << "pkpass file has no pass data structure!";
return Generic;
}
static QColor parseColor(const QString &s)
{
if (s.startsWith(QLatin1String("rgb("), Qt::CaseInsensitive)) {
......@@ -201,7 +215,7 @@ Pass *Pass::fromData(std::unique_ptr<QIODevice> device, QObject *parent)
Pass *pass = nullptr;
if (passObj.contains(QLatin1String("boardingPass"))) {
pass = new BoardingPass(parent);
pass = new KPkPass::BoardingPass(parent);
}
// TODO: coupon, eventTicket, storeCard, generic
else {
......
......@@ -53,6 +53,7 @@ class KPKPASS_EXPORT Pass : public QObject
Q_OBJECT
Q_PROPERTY(QString passTypeIdentifier READ passTypeIdentifier CONSTANT)
Q_PROPERTY(QString serialNumber READ serialNumber CONSTANT)
Q_PROPERTY(Type type READ type CONSTANT)
Q_PROPERTY(QColor backgroundColor READ backgroundColor CONSTANT)
Q_PROPERTY(QColor foregroundColor READ foregroundColor CONSTANT)
Q_PROPERTY(QColor labelColor READ labelColor CONSTANT)
......@@ -71,6 +72,17 @@ class KPKPASS_EXPORT Pass : public QObject
public:
virtual ~Pass();
/** Type of the pass. */
enum Type {
BoardingPass,
Coupon,
EventTicket,
Generic,
StoreCard
};
Q_ENUM(Type)
Type type() const;
/** Content of the pass.json file. */
QJsonObject data() const;
/** The pass data structure of the pass.json file. */
......
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