diff options
author | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2021-07-12 12:54:17 +0200 |
---|---|---|
committer | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2021-07-12 12:54:17 +0200 |
commit | c8dc8bda03b27a76d31c358e4b642a5687611178 (patch) | |
tree | 7a9e5f0029a72ba2b28cca28a7260a6a4c0f2cdd /src | |
parent | 8e0e0ee3bac6ae037df12026aa1cdd396931b739 (diff) | |
download | RWA.Support.DesktopApp-c8dc8bda03b27a76d31c358e4b642a5687611178.tar.gz RWA.Support.DesktopApp-c8dc8bda03b27a76d31c358e4b642a5687611178.tar.bz2 RWA.Support.DesktopApp-c8dc8bda03b27a76d31c358e4b642a5687611178.zip |
MainQMLAdaptor: removeRWAHost() and setRWAHostSelected()
Diffstat (limited to 'src')
-rw-r--r-- | src/main_qmladaptor.cpp | 60 | ||||
-rw-r--r-- | src/main_qmladaptor.h | 3 |
2 files changed, 35 insertions, 28 deletions
diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 419f794..a89d085 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -45,7 +45,7 @@ void MainQMLAdaptor::onRwaHostSelected(QString host_uuid) { RWAHost *_host = nullptr; for (int i = 0; i < getRWAHostModel().size(); i++) { - QObject *obj = getRWAHostModel().value(i); + QObject *obj = _rwaHostModel->value(i); RWAHost *host = qobject_cast<RWAHost *>(obj); Q_ASSERT(host != nullptr); @@ -57,13 +57,7 @@ void MainQMLAdaptor::onRwaHostSelected(QString host_uuid) { qDebug() << "RWAHost was selected!" << _host->uuid() << "aka" << _host->alias(); - // Find item via 'objectName' - QObject *sidebar_drawer = _engine->rootObjects().takeFirst()->findChild<QObject*>("sidebar_drawer"); - if (sidebar_drawer) { - sidebar_drawer->setProperty("rwaHostIsSelected", true); - } else { - qWarning() << "Unable to find 'sidebar_drawer' Item!"; - } + setRWAHostSelected(true); } void MainQMLAdaptor::setRWAHostModel(QList<QObject*> *rwa_hosts) { @@ -76,21 +70,45 @@ void MainQMLAdaptor::addRWAHost(RWAHost *rwa_host) { emit rwaHostModelChanged(*_rwaHostModel); } +void MainQMLAdaptor::removeRWAHost(RWAHost *rwa_host) { + _rwaHostModel->removeOne(rwa_host); + emit rwaHostModelChanged(*_rwaHostModel); +} + QList<QObject*> MainQMLAdaptor::getRWAHostModel() { return *_rwaHostModel; } +void MainQMLAdaptor::setRWAHostSelected(bool value) { + // Find item via 'objectName' + QObject *sidebar_drawer = _engine->rootObjects().takeFirst()->findChild<QObject*>("sidebar_drawer"); + if (sidebar_drawer) { + sidebar_drawer->setProperty("rwaHostIsSelected", value); + } else { + qWarning() << "Unable to find 'sidebar_drawer' Item!"; + } + + QObject *server_chooser = _engine->rootObjects().takeFirst()->findChild<QObject*>("server_chooser"); + if (server_chooser) { + server_chooser->setProperty("displayText", value ? server_chooser->property("currentText") : tr("No RWA host available!")); + server_chooser->setProperty("enabled", value); + } else { + qWarning() << "Unable to find 'server_chooser' Item!"; + } +} + void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { + // Q_ASSERT lets the program crash immediatly at startup, + // when the session service is not started. // Don't use Q_ASSERT(doc != nullptr); instead use: if (doc == nullptr) { - showToast(tr("Can't connect to underlying session service!"), 10000); + setRWAHostSelected(false); + + showToast(tr("Can't connect to underlying session service!"), 9800); return; } - // Q_ASSERT lets the program crash immediatly at startup, - // when the session service is not started. - delete _rwaHostModel; - setRWAHostModel(new QList<QObject*>); + bool atLeastOneHostAvailable = false; // Get the QJsonObject @@ -151,21 +169,9 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { if (!atLeastOneHostAvailable) { main_content_replace("scenes/Scene_no_server_available.qml"); - // Find item via 'objectName' - QObject *sidebar_drawer = _engine->rootObjects().takeFirst()->findChild<QObject*>("sidebar_drawer"); - if (sidebar_drawer) { - sidebar_drawer->setProperty("rwaHostIsSelected", false); - } else { - qWarning() << "Unable to find 'sidebar_drawer' Item!"; - } - } - QObject *server_chooser = _engine->rootObjects().takeFirst()->findChild<QObject*>("server_chooser"); - if (server_chooser) { - server_chooser->setProperty("displayText", atLeastOneHostAvailable ? server_chooser->property("currentText") : tr("No RWA host available!")); - server_chooser->setProperty("enabled", atLeastOneHostAvailable); - } else { - qWarning() << "Unable to find 'server_chooser' Item!"; } + + setRWAHostSelected(atLeastOneHostAvailable); } void MainQMLAdaptor::main_content_push(QString scene) { diff --git a/src/main_qmladaptor.h b/src/main_qmladaptor.h index d928acd..d7f1783 100644 --- a/src/main_qmladaptor.h +++ b/src/main_qmladaptor.h @@ -26,7 +26,6 @@ #pragma once -#include <QObject> #include <QQmlApplicationEngine> #include <QQuickItem> #include <QMessageBox> @@ -128,6 +127,8 @@ public slots: void setURL(QString URL); void setSessionID(QString session_id); void addRWAHost(RWAHost *rwa_host); + void removeRWAHost(RWAHost *rwa_host); + void setRWAHostSelected(bool value); QString getURL(); QString getPin(); QString getSessionID(); |