Commit 1258e37e authored by Volker Krause's avatar Volker Krause

Share KPublicTransport::Manager

parent 184c5122
......@@ -35,7 +35,6 @@ using namespace KItinerary;
JourneyQueryController::JourneyQueryController(QObject *parent)
: QObject(parent)
{
m_ptMgr.reset(new KPublicTransport::Manager);
}
JourneyQueryController::~JourneyQueryController() = default;
......@@ -45,6 +44,11 @@ void JourneyQueryController::setReservationManager(ReservationManager *mgr)
m_resMgr = mgr;
}
void JourneyQueryController::setPublicTransportManager(KPublicTransport::Manager *mgr)
{
m_ptMgr = mgr;
}
bool JourneyQueryController::isLoading() const
{
return m_isLoading;
......
......@@ -21,7 +21,6 @@
#include <QObject>
#include <QString>
#include <memory>
#include <vector>
namespace KPublicTransport {
......@@ -44,6 +43,7 @@ public:
~JourneyQueryController();
void setReservationManager(ReservationManager *mgr);
void setPublicTransportManager(KPublicTransport::Manager *mgr);
Q_INVOKABLE void queryJourney(const QString &batchId);
......@@ -58,7 +58,7 @@ Q_SIGNALS:
private:
ReservationManager *m_resMgr;
std::unique_ptr<KPublicTransport::Manager> m_ptMgr; // TODO share with LiveDataManager!
KPublicTransport::Manager *m_ptMgr;
bool m_isLoading = false;
QString m_errorMsg;
std::vector<KPublicTransport::Journey> m_journeys;
......
......@@ -54,8 +54,6 @@ LiveDataManager::LiveDataManager(QObject *parent)
: QObject(parent)
{
m_ptMgr.reset(new KPublicTransport::Manager);
m_pollTimer.setSingleShot(true);
connect(&m_pollTimer, &QTimer::timeout, this, &LiveDataManager::poll);
......@@ -90,6 +88,11 @@ void LiveDataManager::setPkPassManager(PkPassManager *pkPassMgr)
connect(m_pkPassMgr, &PkPassManager::passUpdated, this, &LiveDataManager::pkPassUpdated);
}
void LiveDataManager::setPublicTransportManager(KPublicTransport::Manager *mgr)
{
m_ptMgr = mgr;
}
void LiveDataManager::setPollingEnabled(bool pollingEnabled)
{
if (pollingEnabled) {
......@@ -100,11 +103,6 @@ void LiveDataManager::setPollingEnabled(bool pollingEnabled)
}
}
void LiveDataManager::setAllowInsecureServices(bool allowInsecure)
{
m_ptMgr->setAllowInsecureBackends(allowInsecure);
}
QVariant LiveDataManager::arrival(const QString &resId)
{
return QVariant::fromValue(m_arrivals.value(resId).change);
......
......@@ -25,7 +25,6 @@
#include <QObject>
#include <QTimer>
#include <memory>
#include <vector>
namespace KItinerary {
......@@ -50,9 +49,9 @@ public:
void setReservationManager(ReservationManager *resMgr);
void setPkPassManager(PkPassManager *pkPassMgr);
void setPublicTransportManager(KPublicTransport::Manager *mgr);
void setPollingEnabled(bool pollingEnabled);
void setAllowInsecureServices(bool allowInsecure);
Q_INVOKABLE QVariant arrival(const QString &resId);
Q_INVOKABLE QVariant departure(const QString &resId);
......@@ -110,7 +109,7 @@ private:
ReservationManager *m_resMgr;
PkPassManager *m_pkPassMgr;
std::unique_ptr<KPublicTransport::Manager> m_ptMgr;
KPublicTransport::Manager *m_ptMgr;
std::vector<QString> m_reservations;
QHash <QString, TrainChange> m_arrivals;
QHash <QString, TrainChange> m_departures;
......
......@@ -43,6 +43,7 @@
#include <KPublicTransport/Journey>
#include <KPublicTransport/Line>
#include <KPublicTransport/Manager>
#include <KPkPass/Field>
#include <KPkPass/Barcode>
......@@ -139,16 +140,20 @@ int main(int argc, char **argv)
appController.setPkPassManager(&passMgr);
BrightnessManager brightnessManager;
KPublicTransport::Manager ptMgr;
ptMgr.setAllowInsecureBackends(settings.allowInsecureServices());
QObject::connect(&settings, &Settings::allowInsecureServicesChanged, [&ptMgr](bool insec) { ptMgr.setAllowInsecureBackends(insec); });
LiveDataManager liveDataMgr;
liveDataMgr.setPublicTransportManager(&ptMgr);
liveDataMgr.setPkPassManager(&passMgr);
liveDataMgr.setReservationManager(&resMgr);
liveDataMgr.setPollingEnabled(settings.queryLiveData());
liveDataMgr.setAllowInsecureServices(settings.allowInsecureServices());
QObject::connect(&settings, &Settings::queryLiveDataChanged, &liveDataMgr, &LiveDataManager::setPollingEnabled);
QObject::connect(&settings, &Settings::allowInsecureServicesChanged, &liveDataMgr, &LiveDataManager::setAllowInsecureServices);
JourneyQueryController journeyQueryController;
journeyQueryController.setReservationManager(&resMgr);
journeyQueryController.setPublicTransportManager(&ptMgr);
#ifndef Q_OS_ANDROID
QObject::connect(&service, &KDBusService::activateRequested, [&parser, &appController](const QStringList &args, const QString &workingDir) {
......
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