From dc3b77a1e3c8b8ff9a9299fd17c13b0428f1fa14 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Thu, 8 Jul 2021 15:50:22 +0200 Subject: Add: 'Scene_no_server_available.qml' --- qml.qrc | 1 + src/main.qml | 56 ++++++++++++++++--------- src/main_qmladaptor.cpp | 50 ++++++++++++++++++++--- src/main_qmladaptor.h | 15 +++++-- src/scenes/Scene_no_server_available.qml | 70 ++++++++++++++++++++++++++++++++ 5 files changed, 163 insertions(+), 29 deletions(-) create mode 100644 src/scenes/Scene_no_server_available.qml diff --git a/qml.qrc b/qml.qrc index 07b6bd2..b472fe7 100644 --- a/qml.qrc +++ b/qml.qrc @@ -29,6 +29,7 @@ src/scenes/Scene_remote_view.qml src/scenes/Scene_settings.qml src/scenes/Scene_placeholder.qml + src/scenes/Scene_no_server_available.qml src/scenes/add_server_wizard/Scene_step_1.qml src/scenes/add_server_wizard/add_server_wizard.cpp src/scenes/add_server_wizard/add_server_wizard.h diff --git a/src/main.qml b/src/main.qml index 12c4668..4494526 100644 --- a/src/main.qml +++ b/src/main.qml @@ -66,25 +66,25 @@ ApplicationWindow { console.log("Opening window now..."); } - function main_content_pop(item, operation) { + function main_content_pop(item) { if(item) { if(item.search(main_content.currentItem.objectName) >= 0) return } - return main_content.pop(item, operation) + return main_content.pop(item) } - function main_content_push(item, operation) { + function main_content_push(item) { if(item) { if(item.search(main_content.currentItem.objectName) >= 0) return } - return main_content.push(item, operation) + return main_content.push(item) } - function main_content_replace(item, operation) { + function main_content_replace(item) { if(item) { if(item.search(main_content.currentItem.objectName) >= 0) return } - return main_content.replace(item, operation) + return main_content.replace(item) } MessageDialog { @@ -206,18 +206,29 @@ ApplicationWindow { anchors.fill: parent model: mainModel - header: ComboBox { - id: server_chooser - objectName: "server_chooser" - width: parent.width + header: Rectangle { height: 50 - model: mainqmladaptor.rwaHostModel - textRole: "alias" + width: parent.width + color: Material.background + + ComboBox { + id: server_chooser + objectName: "server_chooser" + + padding: 0 + width: parent.width + height: 56 - y + y: -6 + clip: false + + model: mainqmladaptor.rwaHostModel + textRole: "alias" - onCurrentIndexChanged: { - var rwa_host = mainqmladaptor.rwaHostModel - sidebar_drawer.rwaHostSelected(rwa_host[currentIndex].uuid) - sidebar_drawer.rwaHostIsSelected = true + onCurrentIndexChanged: { + var rwa_host = mainqmladaptor.rwaHostModel + if (rwa_host[currentIndex] !== undefined) + sidebar_drawer.rwaHostSelected(rwa_host[currentIndex].uuid) + } } } @@ -225,13 +236,15 @@ ApplicationWindow { id: footer text: " " + qsTr("Settings") width: parent.width + enabled: false onClicked: { var scene_url = "scenes/Scene_placeholder.qml" header_text.text = qsTr("Settings") if(inPortrait) sidebar_drawer.close() - main_content_replace(scene_url, StackView.Transition) + if(scene_url.search(main_content.currentItem.objectName) >= 0) return + main_content.replace(scene_url, StackView.Transition) } MenuSeparator { @@ -251,7 +264,8 @@ ApplicationWindow { header_text.text = qsTr("Allow remote control") if(inPortrait) sidebar_drawer.close() - main_content_replace(scene_url, StackView.Transition) + if(scene_url.search(main_content.currentItem.objectName) >= 0) return + main_content.replace(scene_url, StackView.Transition) } // Disabled till a RWAHost object is selected. @@ -264,7 +278,8 @@ ApplicationWindow { header_text.text = qsTr("Allow remote view") if(inPortrait) sidebar_drawer.close() - main_content_replace(scene_url, StackView.Transition) + if(scene_url.search(main_content.currentItem.objectName) >= 0) return + main_content.replace(scene_url, StackView.Transition) } // Disabled till a RWAHost object is selected. @@ -277,7 +292,8 @@ ApplicationWindow { header_text.text = qsTr("Server addition wizard") if(inPortrait) sidebar_drawer.close() - main_content_push(scene_url, StackView.ReplaceTransition) + if(scene_url.search(main_content.currentItem.objectName) >= 0) return + main_content.push(scene_url, StackView.ReplaceTransition) } } } diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 5fcce5f..c1d3f14 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -49,12 +49,19 @@ void MainQMLAdaptor::onRwaHostSelected(QString host_uuid) { Q_ASSERT(_host != nullptr); qDebug() << "RWAHost was selected!" << _host->uuid() << "aka" << _host->alias(); -} -void MainQMLAdaptor::setRWAHostModel(QList rwa_hosts) { + // Find item via 'objectName' + QObject *sidebar_drawer = _engine->rootObjects().takeFirst()->findChild("sidebar_drawer"); + if (sidebar_drawer) { + sidebar_drawer->setProperty("rwaHostIsSelected", true); + } else { + qWarning() << "Unable to find 'sidebar_drawer' Item!"; + } +} - _rwaHostModel = &rwa_hosts; - emit rwaHostModelChanged(rwa_hosts); +void MainQMLAdaptor::setRWAHostModel(QList *rwa_hosts) { + _rwaHostModel = rwa_hosts; + emit rwaHostModelChanged(*rwa_hosts); } void MainQMLAdaptor::addRWAHost(RWAHost *rwa_host) { @@ -69,6 +76,10 @@ QList MainQMLAdaptor::getRWAHostModel() { void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { Q_ASSERT(doc != nullptr); + delete _rwaHostModel; + setRWAHostModel(new QList); + bool atLeastOneHostAvailable = false; + // Get the QJsonObject QJsonObject jObject = doc->object(); QVariantMap mainMap = jObject.toVariantMap(); @@ -90,7 +101,6 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { "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; } @@ -104,6 +114,7 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { // Now built RWAHost object. RWAHost *rwa_host = new RWAHost(host_uuid, host_alias, host_url); addRWAHost(rwa_host); + atLeastOneHostAvailable = true; qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")).arg(rwa_host->alias()); } @@ -124,6 +135,35 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { return; } + + if (!atLeastOneHostAvailable) { + main_content_replace("scenes/Scene_no_server_available.qml"); + //addRWAHost(new RWAHost("-","Kein Server verfügbar!","-")); + } +} + +void MainQMLAdaptor::main_content_push(QString scene) { + // Find item via 'objectName' + QObject *main_content = _engine->rootObjects().takeFirst()->findChild("main_content"); + Q_ASSERT(main_content != nullptr); + QMetaObject::invokeMethod(main_content, "push", Q_ARG(QString, scene)); +} + +void MainQMLAdaptor::main_content_pop(QString scene) { + // Find item via 'objectName' + QObject *main_content = _engine->rootObjects().takeFirst()->findChild("main_content"); + Q_ASSERT(main_content != nullptr); + QMetaObject::invokeMethod(main_content, "pop", Q_ARG(QString, scene)); +} + +void MainQMLAdaptor::main_content_replace(QString scene) { + // Find item via 'objectName' + QObject *window = _engine->rootObjects().takeFirst(); + Q_ASSERT(window != nullptr); + + QVariant arg = QVariant::fromValue(scene); + if(!QMetaObject::invokeMethod(window, "main_content_replace", Q_ARG(QVariant, arg))) + qDebug() << "Failed to invoke push"; } bool MainQMLAdaptor::setConnectButtonEnabled(bool enabled) { diff --git a/src/main_qmladaptor.h b/src/main_qmladaptor.h index 05de1fd..a289a74 100644 --- a/src/main_qmladaptor.h +++ b/src/main_qmladaptor.h @@ -42,7 +42,7 @@ class MainQMLAdaptor : public QObject { Q_OBJECT // this makes url available as a QML property - Q_PROPERTY(QList rwaHostModel READ getRWAHostModel WRITE setRWAHostModel NOTIFY rwaHostModelChanged) + Q_PROPERTY(QList rwaHostModel READ getRWAHostModel NOTIFY rwaHostModelChanged) // this makes url available as a QML property Q_PROPERTY(QString url READ getURL WRITE setURL NOTIFY urlChanged) // this makes pin available as a QML property @@ -61,11 +61,15 @@ class MainQMLAdaptor : public QObject public: explicit MainQMLAdaptor(QObject *parent, QQmlApplicationEngine *engine = nullptr); -// void setSession(Session session); + void setRWAHostModel(QList *rwa_hosts); bool setConnectButtonEnabled(bool enabled); bool setConnectButtonChecked(bool checked); + void main_content_push(QString); + void main_content_pop(QString); + void main_content_replace(QString); + bool setStatusIndicator(bool active, QColor color = QColor(255,255,255)); bool setStatus(QString status); @@ -100,7 +104,8 @@ protected: QString _url; QString _pin; QString _session_id; - QList* _rwaHostModel; + DBusAPI *_dbus_api; + QList *_rwaHostModel; private: QQmlApplicationEngine* _engine; @@ -119,11 +124,13 @@ public slots: void setPin(QString pin); void setURL(QString URL); void setSessionID(QString session_id); - void setRWAHostModel(QList); void addRWAHost(RWAHost *rwa_host); QString getURL(); QString getPin(); QString getSessionID(); + + // No pointer because QML doesn't + // like this type much with pointer QList getRWAHostModel(); void onRwaHostSelected(QString host_uuid); diff --git a/src/scenes/Scene_no_server_available.qml b/src/scenes/Scene_no_server_available.qml new file mode 100644 index 0000000..112c6e0 --- /dev/null +++ b/src/scenes/Scene_no_server_available.qml @@ -0,0 +1,70 @@ +import QtQuick 2.9 +import QtQuick.Window 2.2 +import QtQuick.Extras 1.4 +import QtQuick.Controls 2.2 +import QtQuick.Dialogs 1.2 +import QtQuick.Controls.Material 2.3 + +/*! + This .qml file is a Scene which can be loaded through for example a StackView (main_content in main.qml). + */ + +Item { + id: scene_no_server_available + objectName: "Scene_no_server_available" + + Rectangle { + id: rectangle + anchors.fill: parent + color: Material.background + + Text { + color: Material.foreground + id: title + + text: qsTr("Welcome!") + font.pointSize: 20 + font.bold: true + wrapMode: Text.WordWrap + + horizontalAlignment: Text.AlignLeft + + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: 15 + } + + Text { + color: Material.foreground + anchors.top: title.bottom + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: 15 + + horizontalAlignment: Text.AlignLeft + wrapMode: Text.WordWrap + /*: 'Add RWA-Server' has to be replaced with the correct translation in file main.qml .*/ + font.pointSize: 13 + text: qsTr("You need to add and select the remote \ +web app server to which you want to connect. \ +You can see a button to the left in the menu \ +which says 'Add RWA-Server'. Follow the steps \ +listed there and you can start your remote \ +support session afterwards using the buttons \ +above 'Add RWA-Server'.") + } + } +} + + + + + + + +/*##^## Designer { + D{i:0;autoSize:true;height:480;width:640} +} + ##^##*/ -- cgit v1.2.3