aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main_qmladaptor.cpp60
-rw-r--r--src/main_qmladaptor.h3
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();