Commit 616c21f1 authored by Volker Krause's avatar Volker Krause

Factor out duplicated KPublicTransport utilities

parent db77eada
......@@ -48,6 +48,7 @@ set(itinerary_app_srcs
brightnessmanager.cpp
livedatamanager.cpp
journeyquerycontroller.cpp
publictransport.cpp
)
if (ANDROID)
list(APPEND itinerary_app_srcs androidbrightnessbackend.cpp)
......@@ -81,6 +82,7 @@ if (ANDROID)
kirigami_package_breeze_icons(ICONS
checkmark
clock
dialog-cancel
document-edit
document-open
......
......@@ -18,6 +18,7 @@
#include "journeyquerycontroller.h"
#include "logging.h"
#include "reservationmanager.h"
#include "publictransport.h"
#include <KItinerary/Reservation>
#include <KItinerary/TrainTrip>
......@@ -62,21 +63,6 @@ QVariantList JourneyQueryController::journeys() const
return l;
}
static KPublicTransport::Location locationFromStation(const TrainStation &station) // TODO share with livedatamanager!!
{
using namespace KPublicTransport;
Location loc;
loc.setName(station.name());
loc.setCoordinate(station.geo().latitude(), station.geo().longitude());
if (!station.identifier().isEmpty()) {
const auto idSplit = station.identifier().split(QLatin1Char(':'));
if (idSplit.size() == 2) {
loc.setIdentifier(idSplit.at(0), idSplit.at(1));
}
}
return loc;
}
void JourneyQueryController::queryJourney(const QString &batchId)
{
qDebug() << batchId;
......@@ -93,8 +79,8 @@ void JourneyQueryController::queryJourney(const QString &batchId)
m_isLoading = true;
emit loadingChanged();
const auto from = locationFromStation(trip.departureStation());
const auto to = locationFromStation(trip.arrivalStation());
const auto from = PublicTransport::locationFromStation(trip.departureStation());
const auto to = PublicTransport::locationFromStation(trip.arrivalStation());
// TODO consider scheduled time, if in the future
auto reply = m_ptMgr->queryJourney({from, to});
QObject::connect(reply, &KPublicTransport::JourneyReply::finished, [reply, this]{
......
......@@ -21,6 +21,7 @@
#include "logging.h"
#include "pkpassmanager.h"
#include "reservationmanager.h"
#include "publictransport.h"
#include <KItinerary/LocationUtil>
#include <KItinerary/Place>
......@@ -136,21 +137,6 @@ static bool isSameLine(const QString &lineName, const QString &trainName, const
return lhs.compare(rhs, Qt::CaseInsensitive) == 0;
}
static KPublicTransport::Location locationFromStation(const TrainStation &station)
{
using namespace KPublicTransport;
Location loc;
loc.setName(station.name());
loc.setCoordinate(station.geo().latitude(), station.geo().longitude());
if (!station.identifier().isEmpty()) {
const auto idSplit = station.identifier().split(QLatin1Char(':'));
if (idSplit.size() == 2) {
loc.setIdentifier(idSplit.at(0), idSplit.at(1));
}
}
return loc;
}
void LiveDataManager::checkTrainTrip(const QVariant &res, const QString& resId)
{
Q_ASSERT(JsonLd::isA<TrainReservation>(res));
......@@ -160,7 +146,7 @@ void LiveDataManager::checkTrainTrip(const QVariant &res, const QString& resId)
using namespace KPublicTransport;
if (!hasDeparted(resId, res)) {
DepartureRequest req(locationFromStation(trip.departureStation()));
DepartureRequest req(PublicTransport::locationFromStation(trip.departureStation()));
req.setDateTime(trip.departureTime());
auto reply = m_ptMgr->queryDeparture(req);
connect(reply, &Reply::finished, this, [this, trip, resId, reply]() {
......@@ -183,7 +169,7 @@ void LiveDataManager::checkTrainTrip(const QVariant &res, const QString& resId)
}
if (!hasArrived(resId, res)) {
DepartureRequest req(locationFromStation(trip.arrivalStation()));
DepartureRequest req(PublicTransport::locationFromStation(trip.arrivalStation()));
req.setMode(DepartureRequest::QueryArrival);
req.setDateTime(trip.arrivalTime());
auto reply = m_ptMgr->queryDeparture(req);
......
/*
Copyright (C) 2019 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 <https://www.gnu.org/licenses/>.
*/
#include "publictransport.h"
#include <KItinerary/Place>
#include <KPublicTransport/Location>
KPublicTransport::Location PublicTransport::locationFromStation(const KItinerary::TrainStation& station)
{
using namespace KPublicTransport;
Location loc;
loc.setName(station.name());
loc.setCoordinate(station.geo().latitude(), station.geo().longitude());
if (!station.identifier().isEmpty()) {
const auto idSplit = station.identifier().split(QLatin1Char(':'));
if (idSplit.size() == 2) {
loc.setIdentifier(idSplit.at(0), idSplit.at(1));
}
}
return loc;
}
/*
Copyright (C) 2019 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 <https://www.gnu.org/licenses/>.
*/
#ifndef PUBLICTRANSPORT_H
#define PUBLICTRANSPORT_H
namespace KItinerary {
class TrainStation;
}
namespace KPublicTransport {
class Location;
}
/** Utilities to interface with KPublicTransport. */
namespace PublicTransport
{
/** Obtain a KPublicTransport location object from a KItinerary train station. */
KPublicTransport::Location locationFromStation(const KItinerary::TrainStation &station);
}
#endif // PUBLICTRANSPORT_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment