From 54249d9c37ce3994b03123ee6367c7f5519d3b40 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Wed, 7 Jul 2021 15:03:13 +0200 Subject: Introduce RWAHostModel. RWAHost's are now loaded on start. Scene_remote_{view, control} are no longer available if no host is selected. --- src/main_qmladaptor.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'src/main_qmladaptor.cpp') diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index b34c9d4..d75b15c 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -30,6 +30,100 @@ MainQMLAdaptor::MainQMLAdaptor(QObject *parent, QQmlApplicationEngine* engine) : Q_ASSERT(engine != nullptr); _engine = engine; + _rwaHostModel = new QList; +} + +void MainQMLAdaptor::onRwaHostSelected(QString host_uuid) { + Q_ASSERT(host_uuid != ""); + + RWAHost *_host = nullptr; + for (int i = 0; i < getRWAHostModel().size(); i++) { + QObject *obj = getRWAHostModel().value(i); + RWAHost *host = qobject_cast(obj); + Q_ASSERT(host != nullptr); + + if (host->uuid() == host_uuid) { + _host = host; + } + } + Q_ASSERT(_host != nullptr); + + qDebug() << "RWAHost was selected!" << _host->uuid() << "aka" << _host->alias(); +} + +void MainQMLAdaptor::setRWAHostModel(QList rwa_hosts) { + + _rwaHostModel = &rwa_hosts; + emit rwaHostModelChanged(rwa_hosts); +} + +void MainQMLAdaptor::addRWAHost(RWAHost *rwa_host) { + _rwaHostModel->append(rwa_host); + emit rwaHostModelChanged(*_rwaHostModel); +} + +QList MainQMLAdaptor::getRWAHostModel() { + return *_rwaHostModel; +} + +void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { + Q_ASSERT(doc != nullptr); + + // Get the QJsonObject + QJsonObject jObject = doc->object(); + QVariantMap mainMap = jObject.toVariantMap(); + + // Status of request + QString request_status = mainMap["status"].toString(); + if (request_status == "success") { + // Building host_objects + QJsonArray host_objects = jObject.value("hosts").toArray(); + + foreach (const QJsonValue &host_object, host_objects) { + QString host_uuid = host_object["uuid"].toString(); + QString host_alias = host_object["alias"].toString(); + QString host_url = host_object["url"].toString(); + + if (host_url == "" || host_uuid == "") { + // This two values are required and can't be omitted. + QString reason = tr("A host object in the response of D-Bus " + "service lacks a necessary value. (host_url or host_uuid)"); + qCritical().noquote() << tr("An error occured while adding a new host:") + << reason; + //emit step1Failed(reason); + + return; + } + + if (host_alias == "") { + qDebug().noquote() << QString("An alias for the host wasn't delivered " + "so just use '%0' as alias.").arg(host_url); + host_alias = host_url; + } + + // Now built RWAHost object. + RWAHost *rwa_host = new RWAHost(host_uuid, host_alias, host_url); + addRWAHost(rwa_host); + + qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")).arg(rwa_host->alias()); + } + } else { + QString reason = tr("An error occured while adding a new host:"); + qCritical().noquote() << reason; + + QString type = mainMap["type"].toString(); + if (type != "") { + reason = QString(tr("The error is not clear. The session service " + "responded with status type '%0'")).arg(type); + qCritical().noquote() << reason; + } else { + reason = QString(tr("The error is not clear. The session service " + "responded with no status type!")); + qCritical().noquote() << reason; + } + + return; + } } bool MainQMLAdaptor::setConnectButtonEnabled(bool enabled) { -- cgit v1.2.3