Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
PIM
Itinerary
Commits
784c411c
Commit
784c411c
authored
Dec 27, 2018
by
Volker Krause
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prepare for handling reservation changes
parent
ac419423
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
7 deletions
+49
-7
src/app/livedatamanager.cpp
src/app/livedatamanager.cpp
+43
-7
src/app/livedatamanager.h
src/app/livedatamanager.h
+6
-0
No files found.
src/app/livedatamanager.cpp
View file @
784c411c
...
...
@@ -61,18 +61,15 @@ LiveDataManager::~LiveDataManager() = default;
void
LiveDataManager
::
setReservationManager
(
ReservationManager
*
resMgr
)
{
m_resMgr
=
resMgr
;
// TODO set up change monitoring
connect
(
resMgr
,
&
ReservationManager
::
reservationAdded
,
this
,
&
LiveDataManager
::
reservationAdded
);
connect
(
resMgr
,
&
ReservationManager
::
reservationUpdated
,
this
,
&
LiveDataManager
::
reservationChanged
);
connect
(
resMgr
,
&
ReservationManager
::
reservationRemoved
,
this
,
&
LiveDataManager
::
reservationRemoved
);
const
auto
resIds
=
resMgr
->
reservations
();
for
(
const
auto
&
resId
:
resIds
)
{
const
auto
res
=
resMgr
->
reservation
(
resId
);
if
(
!
LocationUtil
::
isLocationChange
(
res
))
{
// we only care about transit reservations
if
(
!
isRelevant
(
resId
))
{
continue
;
}
if
(
SortUtil
::
endtDateTime
(
res
)
<
QDateTime
::
currentDateTime
().
addDays
(
-
1
))
{
continue
;
// we don't care about past events
}
m_reservations
.
push_back
(
resId
);
}
...
...
@@ -304,4 +301,43 @@ void LiveDataManager::storePublicTransportData(const QString &resId, const KPubl
file
.
write
(
QJsonDocument
(
KPublicTransport
::
Departure
::
toJson
(
dep
)).
toJson
());
}
bool
LiveDataManager
::
isRelevant
(
const
QString
&
resId
)
const
{
const
auto
res
=
m_resMgr
->
reservation
(
resId
);
if
(
!
LocationUtil
::
isLocationChange
(
res
))
{
// we only care about transit reservations
return
false
;
}
if
(
SortUtil
::
endtDateTime
(
res
)
<
QDateTime
::
currentDateTime
().
addDays
(
-
1
))
{
return
false
;
// we don't care about past events
}
// we can only handle train trips and reservations with pkpass files so far
if
(
!
JsonLd
::
canConvert
<
Reservation
>
(
res
))
{
return
false
;
}
return
JsonLd
::
isA
<
TrainReservation
>
(
res
)
||
!
JsonLd
::
convert
<
Reservation
>
(
res
).
pkpassSerialNumber
().
isEmpty
();
}
void
LiveDataManager
::
reservationAdded
(
const
QString
&
resId
)
{
if
(
!
isRelevant
(
resId
))
{
return
;
}
// TODO
}
void
LiveDataManager
::
reservationChanged
(
const
QString
&
resId
)
{
// TODO
}
void
LiveDataManager
::
reservationRemoved
(
const
QString
&
resId
)
{
const
auto
it
=
std
::
find
(
m_reservations
.
begin
(),
m_reservations
.
end
(),
resId
);
if
(
it
!=
m_reservations
.
end
())
{
m_reservations
.
erase
(
it
);
}
}
#include "moc_livedatamanager.cpp"
src/app/livedatamanager.h
View file @
784c411c
...
...
@@ -59,6 +59,12 @@ signals:
void
departureUpdated
(
const
QString
&
resId
);
private:
bool
isRelevant
(
const
QString
&
resId
)
const
;
void
reservationAdded
(
const
QString
&
resId
);
void
reservationChanged
(
const
QString
&
resId
);
void
reservationRemoved
(
const
QString
&
resId
);
void
checkTrainTrip
(
const
KItinerary
::
TrainTrip
&
trip
,
const
QString
&
resId
);
void
updateArrivalData
(
const
KPublicTransport
::
Departure
&
arr
,
const
QString
&
resId
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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