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
9b4db881
Commit
9b4db881
authored
Mar 04, 2018
by
Volker Krause
Browse files
Clean up pass type handling, and actually support all pass types
parent
6c1cfdc5
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/pkpass/boardingpass.cpp
View file @
9b4db881
...
...
@@ -23,10 +23,12 @@
using
namespace
KPkPass
;
BoardingPass
::
BoardingPass
(
QObject
*
parent
)
:
Pass
(
QStringLiteral
(
"b
oardingPass
"
)
,
parent
)
:
Pass
(
Pass
::
B
oardingPass
,
parent
)
{
}
BoardingPass
::~
BoardingPass
()
=
default
;
BoardingPass
::
TransitType
BoardingPass
::
transitType
()
const
{
const
auto
t
=
d
->
passData
().
value
(
QLatin1String
(
"transitType"
)).
toString
();
...
...
src/pkpass/boardingpass.h
View file @
9b4db881
...
...
@@ -40,7 +40,7 @@ public:
Q_ENUM
(
TransitType
)
explicit
BoardingPass
(
QObject
*
parent
=
nullptr
);
~
BoardingPass
()
=
default
;
~
BoardingPass
();
TransitType
transitType
()
const
;
};
...
...
src/pkpass/pass.cpp
View file @
9b4db881
...
...
@@ -37,6 +37,9 @@
using
namespace
KPkPass
;
static
const
char
*
passTypes
[]
=
{
"boardingPass"
,
"coupon"
,
"eventTicket"
,
"generic"
,
"storeCard"
};
static
const
auto
passTypesCount
=
sizeof
(
passTypes
)
/
sizeof
(
passTypes
[
0
]);
QJsonObject
PassPrivate
::
data
()
const
{
return
passObj
;
...
...
@@ -44,7 +47,7 @@ QJsonObject PassPrivate::data() const
QJsonObject
PassPrivate
::
passData
()
const
{
return
passObj
.
value
(
passType
).
toObject
();
return
passObj
.
value
(
QLatin1String
(
passTypes
[
passType
])
).
toObject
();
}
QString
PassPrivate
::
message
(
const
QString
&
key
)
const
...
...
@@ -203,13 +206,27 @@ Pass *PassPrivate::fromData(std::unique_ptr<QIODevice> device, QObject *parent)
return
nullptr
;
}
Pass
*
pass
=
nullptr
;
if
(
passObj
.
contains
(
QLatin1String
(
"boardingPass"
)))
{
pass
=
new
KPkPass
::
BoardingPass
(
parent
);
// determine pass type
int
passTypeIdx
=
-
1
;
for
(
unsigned
int
i
=
0
;
i
<
passTypesCount
;
++
i
)
{
if
(
passObj
.
contains
(
QLatin1String
(
passTypes
[
i
])))
{
passTypeIdx
=
i
;
break
;
}
}
// TODO: coupon, eventTicket, storeCard, generic
else
{
pass
=
new
Pass
(
QStringLiteral
(
"generic"
),
parent
);
if
(
passTypeIdx
<
0
)
{
qCWarning
(
Log
)
<<
"pkpass file has no pass data structure!"
;
return
nullptr
;
}
Pass
*
pass
=
nullptr
;
switch
(
passTypeIdx
)
{
case
Pass
::
BoardingPass
:
pass
=
new
KPkPass
::
BoardingPass
(
parent
);
break
;
default:
pass
=
new
Pass
(
static_cast
<
Pass
::
Type
>
(
passTypeIdx
),
parent
);
break
;
}
pass
->
d
->
buffer
=
std
::
move
(
device
);
...
...
@@ -220,7 +237,7 @@ Pass *PassPrivate::fromData(std::unique_ptr<QIODevice> device, QObject *parent)
}
Pass
::
Pass
(
const
QString
&
passType
,
QObject
*
parent
)
Pass
::
Pass
(
Type
passType
,
QObject
*
parent
)
:
QObject
(
parent
)
,
d
(
new
PassPrivate
)
{
...
...
@@ -239,18 +256,9 @@ QString Pass::serialNumber() const
return
d
->
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
Pass
::
Type
Pass
::
type
()
const
{
for
(
unsigned
int
i
=
0
;
i
<
passTypesCount
;
++
i
)
{
if
(
d
->
data
().
contains
(
QLatin1String
(
passTypes
[
i
])))
{
return
static_cast
<
Type
>
(
i
);
}
}
qCWarning
(
Log
)
<<
"pkpass file has no pass data structure!"
;
return
Generic
;
return
d
->
passType
;
}
static
QColor
parseColor
(
const
QString
&
s
)
...
...
src/pkpass/pass.h
View file @
9b4db881
...
...
@@ -24,11 +24,8 @@
#include
"barcode.h"
#include
"field.h"
#include
<QByteArray>
#include
<QColor>
#include
<QDateTime>
#include
<QHash>
#include
<QJsonObject>
#include
<QObject>
#include
<QVariant>
#include
<QVector>
...
...
@@ -36,8 +33,8 @@
#include
<memory>
class
KZip
;
class
QByteArray
;
class
QIODevice
;
class
QJsonObject
;
class
QLatin1String
;
class
QString
;
...
...
@@ -113,7 +110,7 @@ protected:
friend
class
Barcode
;
friend
class
Field
;
friend
class
PassPrivate
;
explicit
Pass
(
const
QString
&
passType
,
QObject
*
parent
=
nullptr
);
explicit
Pass
(
Type
passType
,
QObject
*
parent
=
nullptr
);
std
::
unique_ptr
<
PassPrivate
>
d
;
///@endcond
...
...
src/pkpass/pass_p.h
View file @
9b4db881
...
...
@@ -47,7 +47,7 @@ public:
std
::
unique_ptr
<
KZip
>
zip
;
QJsonObject
passObj
;
QHash
<
QString
,
QString
>
messages
;
QString
passType
;
Pass
::
Type
passType
;
};
}
...
...
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