Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KPkPass
Commits
2fbddc5d
Commit
2fbddc5d
authored
Mar 04, 2018
by
Volker Krause
Browse files
Add pass type property
parent
a04cb943
Changes
3
Hide whitespace changes
Inline
Side-by-side
autotests/pkpasstest.cpp
View file @
2fbddc5d
...
...
@@ -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
);
...
...
src/pkpass/pass.cpp
View file @
2fbddc5d
...
...
@@ -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
{
...
...
src/pkpass/pass.h
View file @
2fbddc5d
...
...
@@ -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. */
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment