Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Itinerary
Commits
f29006cc
Commit
f29006cc
authored
Oct 28, 2021
by
Volker Krause
Browse files
Also use the VDV organization id to select KPublicTransport backends
parent
477578ac
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/app/publictransport.cpp
View file @
f29006cc
...
...
@@ -472,21 +472,34 @@ KPublicTransport::JourneySection PublicTransport::lastTransportSection(const KPu
QStringList
PublicTransport
::
suitableBackendsForReservation
(
KPublicTransport
::
Manager
*
mgr
,
const
QVariant
&
res
)
{
using
namespace
KPublicTransport
;
QStringList
backendIds
;
const
auto
companyCode
=
ReservationHelper
::
uicCompanyCode
(
res
);
if
(
companyCode
.
size
()
!=
4
)
{
return
{};
if
(
companyCode
.
size
()
==
4
)
{
for
(
const
auto
&
backend
:
mgr
->
backends
())
{
if
(
!
mgr
->
isBackendEnabled
(
backend
.
identifier
()))
{
continue
;
}
for
(
const
auto
cov
:
{
CoverageArea
::
Realtime
,
CoverageArea
::
Regular
,
CoverageArea
::
Any
})
{
if
(
backend
.
coverageArea
(
cov
).
uicCompanyCodes
().
contains
(
companyCode
))
{
backendIds
.
push_back
(
backend
.
identifier
());
break
;
}
}
}
}
QStringList
backendIds
;
for
(
const
auto
&
backend
:
mgr
->
backends
())
{
if
(
!
mgr
->
isBackendEnabled
(
backend
.
identifier
()))
{
continue
;
}
for
(
const
auto
cov
:
{
CoverageArea
::
Realtime
,
CoverageArea
::
Regular
,
CoverageArea
::
Any
})
{
if
(
backend
.
coverageArea
(
cov
).
uicCompanyCodes
().
contains
(
companyCode
))
{
backendIds
.
push_back
(
backend
.
identifier
());
break
;
const
auto
vdvOrgId
=
ReservationHelper
::
vdvOrganizationId
(
res
);
if
(
!
vdvOrgId
.
isEmpty
())
{
for
(
const
auto
&
backend
:
mgr
->
backends
())
{
if
(
!
mgr
->
isBackendEnabled
(
backend
.
identifier
()))
{
continue
;
}
for
(
const
auto
cov
:
{
CoverageArea
::
Realtime
,
CoverageArea
::
Regular
,
CoverageArea
::
Any
})
{
if
(
backend
.
coverageArea
(
cov
).
vdvOrganizationIds
().
contains
(
vdvOrgId
))
{
backendIds
.
push_back
(
backend
.
identifier
());
break
;
}
}
}
}
...
...
src/app/reservationhelper.cpp
View file @
f29006cc
...
...
@@ -63,13 +63,19 @@ bool ReservationHelper::equals(const QVariant &lhs, const QVariant &rhs)
return
false
;
}
QString
ReservationHelper
::
uicCompanyCode
(
const
QVariant
&
res
)
static
QString
providerIdentifier
(
const
QVariant
&
res
)
{
QString
id
;
if
(
JsonLd
::
isA
<
TrainReservation
>
(
res
))
{
id
=
res
.
value
<
TrainReservation
>
().
reservationFor
().
value
<
TrainTrip
>
().
provider
().
identifier
();
}
// TODO in theory we can also have this for bus reservations
return
res
.
value
<
TrainReservation
>
().
reservationFor
().
value
<
TrainTrip
>
().
provider
().
identifier
();
}
else
if
(
JsonLd
::
isA
<
BusReservation
>
(
res
))
{
return
res
.
value
<
BusReservation
>
().
reservationFor
().
value
<
BusTrip
>
().
provider
().
identifier
();
}
return
{};
}
QString
ReservationHelper
::
uicCompanyCode
(
const
QVariant
&
res
)
{
auto
id
=
providerIdentifier
(
res
);
if
(
!
id
.
startsWith
(
QLatin1String
(
"uic:"
))
||
id
.
size
()
>
8
)
{
return
{};
}
...
...
@@ -80,3 +86,12 @@ QString ReservationHelper::uicCompanyCode(const QVariant &res)
}
return
id
;
}
QString
ReservationHelper
::
vdvOrganizationId
(
const
QVariant
&
res
)
{
const
auto
id
=
providerIdentifier
(
res
);
if
(
!
id
.
startsWith
(
QLatin1String
(
"vdv:"
)))
{
return
id
.
mid
(
4
);
}
return
{};
}
src/app/reservationhelper.h
View file @
f29006cc
...
...
@@ -27,6 +27,8 @@ namespace ReservationHelper
/** Returns the UIC company code for @p res, if any. */
QString
uicCompanyCode
(
const
QVariant
&
res
);
/** Returns the VDV org id for @p res, if any. */
QString
vdvOrganizationId
(
const
QVariant
&
res
);
}
#endif // RESERVATIONHELPER_H
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