Commit a6683d70 authored by Volker Krause's avatar Volker Krause
Browse files

Move backend metadata loading code to the Backend class

This is a preparation for implementing proper support for the Transport API
coverage area data, as well as for removing the duplicate backend vectors
in Manager.
parent 7a9312ef
Pipeline #57778 passed with stage
in 25 seconds
......@@ -5,23 +5,14 @@
*/
#include "backend.h"
#include "backend_p.h"
#include "datatypes_p.h"
#include "json_p.h"
#include <QString>
#include <QJsonObject>
using namespace KPublicTransport;
namespace KPublicTransport {
class BackendPrivate : public QSharedData {
public:
QString identifier;
QString name;
QString description;
bool isSecure;
};
}
KPUBLICTRANSPORT_MAKE_GADGET(Backend)
KPUBLICTRANSPORT_MAKE_PROPERTY(Backend, QString, identifier, setIdentifier)
KPUBLICTRANSPORT_MAKE_PROPERTY(Backend, QString, name, setName)
......@@ -36,4 +27,14 @@ QString Backend::primaryCountryCode() const
return {};
}
Backend BackendPrivate::fromJson(const QJsonObject &obj, const QString &backendId)
{
Backend b;
b.d->identifier = backendId;
const auto jsonMetaData = obj.value(QLatin1String("KPlugin")).toObject();
b.d->name = Json::translatedValue(jsonMetaData, QStringLiteral("Name"));
b.d->description = Json::translatedValue(jsonMetaData, QStringLiteral("Description"));
return b;
}
#include "moc_backend.cpp"
/*
SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KPUBLICTRANSPORT_BACKEND_P_H
#define KPUBLICTRANSPORT_BACKEND_P_H
#include <QSharedData>
#include <QString>
class QJsonObject;
namespace KPublicTransport {
class Backend;
class BackendPrivate : public QSharedData {
public:
static Backend fromJson(const QJsonObject &obj, const QString &backendId);
QString identifier;
QString name;
QString description;
bool isSecure;
};
}
#endif // KPUBLICTRANSPORT_BACKEND_P_H
......@@ -37,6 +37,7 @@ public: \
Class& operator=(const Class&); \
operator QVariant () const; \
private: \
friend class Class ## Private; \
QExplicitlySharedDataPointer<Class ## Private> d;
#define KPUBLICTRANSPORT_PROPERTY(Type, Getter, Setter) \
......
......@@ -18,6 +18,7 @@
#include "vehiclelayoutreply.h"
#include "datatypes/attributionutil_p.h"
#include "datatypes/backend.h"
#include "datatypes/backend_p.h"
#include "datatypes/disruption.h"
#include "datatypes/json_p.h"
#include "datatypes/platform.h"
......@@ -140,11 +141,7 @@ void ManagerPrivate::loadNetworks()
m_attributions.push_back(net->attribution());
}
Backend metaData;
metaData.setIdentifier(net->backendId());
const auto jsonMetaData = doc.object().value(QLatin1String("KPlugin")).toObject();
metaData.setName(Json::translatedValue(jsonMetaData, QStringLiteral("Name")));
metaData.setDescription(Json::translatedValue(jsonMetaData, QStringLiteral("Description")));
auto metaData = BackendPrivate::fromJson(doc.object(), net->backendId());
metaData.setIsSecure(net->capabilities() & AbstractBackend::Secure);
m_backendMetaData.push_back(std::move(metaData));
......
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