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
c0d9a2ad
Commit
c0d9a2ad
authored
Mar 10, 2018
by
Volker Krause
Browse files
Add support for pass locations
parent
99adf99d
Changes
6
Hide whitespace changes
Inline
Side-by-side
autotests/pkpasstest.cpp
View file @
c0d9a2ad
...
...
@@ -15,12 +15,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
<
pass
.h>
#include
<
barcode
.h>
#include
<boardingpass.h>
#include
<location.h>
#include
<QLocale>
#include
<QtTest/qtest.h>
#include
<cmath>
class
PkPassTest
:
public
QObject
{
Q_OBJECT
...
...
@@ -72,6 +75,14 @@ private slots:
QVERIFY
(
!
bc
.
message
().
isEmpty
());
QVERIFY
(
bc
.
alternativeText
().
isEmpty
());
QCOMPARE
(
bc
.
messageEncoding
(),
QLatin1String
(
"iso-8859-1"
));
const
auto
locs
=
pass
->
locations
();
QCOMPARE
(
locs
.
size
(),
1
);
const
auto
loc
=
locs
.
at
(
0
);
QVERIFY
(
std
::
isnan
(
loc
.
altitude
()));
QCOMPARE
((
int
)
loc
.
latitude
(),
47
);
QCOMPARE
((
int
)
loc
.
longitude
(),
8
);
QCOMPARE
(
loc
.
relevantText
(),
QLatin1String
(
"LX962 Boarding 20:25"
));
}
};
...
...
src/pkpass/CMakeLists.txt
View file @
c0d9a2ad
...
...
@@ -4,6 +4,7 @@ set(pkpass_srcs
barcode.cpp
boardingpass.cpp
field.cpp
location.cpp
pass.cpp
)
ecm_qt_declare_logging_category
(
pkpass_srcs
...
...
@@ -31,6 +32,7 @@ ecm_generate_headers(KPkPass_HEADERS
Barcode
BoardingPass
Field
Location
Pass
PREFIX KPkPass
REQUIRED_HEADERS KPkPass_HEADERS
...
...
src/pkpass/location.cpp
0 → 100644
View file @
c0d9a2ad
/*
Copyright (C) 2018 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
"location.h"
#include
<QJsonObject>
#include
<cmath>
using
namespace
KPkPass
;
namespace
KPkPass
{
class
LocationPrivate
{
public:
QJsonObject
obj
;
};
}
Location
::
Location
()
:
d
(
new
LocationPrivate
)
{
}
Location
::
Location
(
const
QJsonObject
&
obj
)
:
d
(
new
LocationPrivate
)
{
d
->
obj
=
obj
;
}
Location
::~
Location
()
=
default
;
double
Location
::
altitude
()
const
{
return
d
->
obj
.
value
(
QLatin1String
(
"altitude"
)).
toDouble
(
NAN
);
}
double
Location
::
latitude
()
const
{
return
d
->
obj
.
value
(
QLatin1String
(
"latitude"
)).
toDouble
(
NAN
);
}
double
Location
::
longitude
()
const
{
return
d
->
obj
.
value
(
QLatin1String
(
"longitude"
)).
toDouble
(
NAN
);
}
QString
Location
::
relevantText
()
const
{
return
d
->
obj
.
value
(
QLatin1String
(
"relevantText"
)).
toString
();
}
src/pkpass/location.h
0 → 100644
View file @
c0d9a2ad
/*
Copyright (C) 2018 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KPKPASS_LOCATION_H
#define KPKPASS_LOCATION_H
#include
"kpkpass_export.h"
#include
<QMetaType>
#include
<memory>
class
QJsonObject
;
namespace
KPkPass
{
class
LocationPrivate
;
/** A pass location element.
* @see https://developer.apple.com/library/content/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/LowerLevel.html
*/
class
KPKPASS_EXPORT
Location
{
Q_GADGET
Q_PROPERTY
(
double
altitude
READ
altitude
CONSTANT
)
Q_PROPERTY
(
double
latitude
READ
latitude
CONSTANT
)
Q_PROPERTY
(
double
longitude
READ
longitude
CONSTANT
)
Q_PROPERTY
(
QString
relevantText
READ
relevantText
CONSTANT
)
public:
Location
();
~
Location
();
/** Altitude in meters, NaN if not set. */
double
altitude
()
const
;
/** Latitude in degree. */
double
latitude
()
const
;
/** Longitude in degree. */
double
longitude
()
const
;
/** Text to display when location is reached. */
QString
relevantText
()
const
;
private:
friend
class
Pass
;
explicit
Location
(
const
QJsonObject
&
obj
);
std
::
shared_ptr
<
LocationPrivate
>
d
;
};
}
Q_DECLARE_METATYPE
(
KPkPass
::
Location
)
#endif // KPKPASS_LOCATION_H
src/pkpass/pass.cpp
View file @
c0d9a2ad
...
...
@@ -19,7 +19,9 @@
#include
"pass.h"
#include
"pass_p.h"
#include
"barcode.h"
#include
"boardingpass.h"
#include
"location.h"
#include
"logging.h"
#include
<KZip>
...
...
@@ -276,6 +278,18 @@ bool Pass::isVoided() const
return
d
->
passObj
.
value
(
QLatin1String
(
"voided"
)).
toString
()
==
QLatin1String
(
"true"
);
}
QVector
<
Location
>
Pass
::
locations
()
const
{
QVector
<
Location
>
locs
;
const
auto
a
=
d
->
passObj
.
value
(
QLatin1String
(
"locations"
)).
toArray
();
locs
.
reserve
(
a
.
size
());
for
(
const
auto
&
loc
:
a
)
{
locs
.
push_back
(
Location
(
loc
.
toObject
()));
}
return
locs
;
}
QDateTime
Pass
::
relevantDate
()
const
{
return
QDateTime
::
fromString
(
d
->
passObj
.
value
(
QLatin1String
(
"relevantDate"
)).
toString
(),
Qt
::
ISODate
);
...
...
src/pkpass/pass.h
View file @
c0d9a2ad
...
...
@@ -21,7 +21,6 @@
#define KPKPASS_PASS_H
#include
"kpkpass_export.h"
#include
"barcode.h"
#include
"field.h"
#include
<QColor>
...
...
@@ -38,6 +37,7 @@ class QString;
namespace
KPkPass
{
class
Barcode
;
class
Location
;
class
PassPrivate
;
/** Base class for a pkpass file.
...
...
@@ -100,7 +100,9 @@ public:
bool
isVoided
()
const
;
// relevance keys
// TODO locations, maxDistance
/** Locations associated with this pass. */
QVector
<
Location
>
locations
()
const
;
// TODO maxDistance
QDateTime
relevantDate
()
const
;
// visual appearance keys
...
...
@@ -150,7 +152,6 @@ private:
QVariantList
primaryFieldsVariant
()
const
;
QVariantList
secondaryFieldsVariant
()
const
;
QVariantList
barcodesVariant
()
const
;
};
}
...
...
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