From 98049d1507a6f2ae232782fd79f4f753ad53eead Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Tue, 6 Jul 2021 20:02:31 +0200 Subject: Fix copyright headers --- src/main_qmladaptor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main_qmladaptor.cpp') diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 8a54eb3..731efaf 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -1,8 +1,8 @@ /* * This file is part of Remote Support Desktop * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp - * Copyright 2020-2021 Daniel Teichmann - * Copyright 2020-2021 Mike Gabriel + * Copyright 2020, 2021 Daniel Teichmann + * Copyright 2020, 2021 Mike Gabriel * SPDX-License-Identifier: GPL-2.0-or-later * * This program is free software; you can redistribute it and/or modify -- cgit v1.2.3 From d30e51002393f48c271fc4109f1b6b71ea1d0440 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Tue, 6 Jul 2021 20:07:01 +0200 Subject: MainQMLAdaptor: engine can't be nullptr in constructor --- src/main_qmladaptor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main_qmladaptor.cpp') diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 731efaf..b34c9d4 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -26,8 +26,9 @@ #include "main_qmladaptor.h" -MainQMLAdaptor::MainQMLAdaptor(QObject *parent, QQmlApplicationEngine* engine) : QObject(parent) -{ +MainQMLAdaptor::MainQMLAdaptor(QObject *parent, QQmlApplicationEngine* engine) : QObject(parent) { + Q_ASSERT(engine != nullptr); + _engine = engine; } -- cgit v1.2.3 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. --- qml.qrc | 2 + rwa-support-desktopapp.pro | 4 +- src/RWAHostModel.cpp | 37 +++++++++ src/RWAHostModel.h | 23 ++++++ src/main.cpp | 14 +++- src/main.qml | 27 ++++++- src/main_qmladaptor.cpp | 94 ++++++++++++++++++++++ src/main_qmladaptor.h | 18 +++++ src/scenes/add_server_wizard/add_server_wizard.cpp | 10 +-- src/scenes/add_server_wizard/add_server_wizard.h | 5 +- src/session.cpp | 1 - 11 files changed, 225 insertions(+), 10 deletions(-) create mode 100644 src/RWAHostModel.cpp create mode 100644 src/RWAHostModel.h (limited to 'src/main_qmladaptor.cpp') diff --git a/qml.qrc b/qml.qrc index 5c8d030..07b6bd2 100644 --- a/qml.qrc +++ b/qml.qrc @@ -17,6 +17,8 @@ src/session.h src/RWAHost.h src/RWAHost.cpp + src/RWAHostModel.h + src/RWAHostModel.cpp src/DBusAPI.h src/DBusAPI.cpp src/ListItem.qml diff --git a/rwa-support-desktopapp.pro b/rwa-support-desktopapp.pro index 5c3f24d..a15c4bd 100644 --- a/rwa-support-desktopapp.pro +++ b/rwa-support-desktopapp.pro @@ -48,14 +48,16 @@ SOURCES += src/main.cpp \ src/RWADBusAdaptor.cpp \ src/session.cpp \ src/scenes/add_server_wizard/add_server_wizard.cpp \ + src/RWAHostModel.cpp \ src/RWAHost.cpp \ - src/DBusAPI.cpp + src/DBusAPI.cpp \ HEADERS += src/RWADBusAdaptor.h \ src/main_qmladaptor.h \ src/RWADBusAdaptor.h \ src/session.h \ src/scenes/add_server_wizard/add_server_wizard.h \ + src/RWAHostModel.h \ src/RWAHost.h \ src/DBusAPI.h diff --git a/src/RWAHostModel.cpp b/src/RWAHostModel.cpp new file mode 100644 index 0000000..5f62adc --- /dev/null +++ b/src/RWAHostModel.cpp @@ -0,0 +1,37 @@ +#include "RWAHostModel.h" + +RWAHostModel::RWAHostModel(QObject *parent) { + Q_UNUSED(parent) +} + +int RWAHostModel::rowCount(const QModelIndex& parent) const { + Q_UNUSED(parent); + return mDatas.size(); +} + +int RWAHostModel::columnCount(const QModelIndex& parent) const { + Q_UNUSED(parent); + return 1; +} + +QVariant RWAHostModel::data(const QModelIndex &index, int role) const + { + if (!index.isValid()) + return QVariant(); + if ( role == Qt::DisplayRole) { + return mDatas[index.row()]; + } + return QVariant(); +} + +void RWAHostModel::populate() { + beginResetModel(); + mDatas.clear(); + RWAHost *host1 = new RWAHost("uuid-1", "Erster Server", "url1"); + RWAHost *host2 = new RWAHost("uuid-2", "Zweiter Server", "url2"); + RWAHost *host3 = new RWAHost("uuid-3", "Dritter Server", "url3"); + mDatas.append(host1->alias()); + mDatas.append(host2->alias()); + mDatas.append(host3->alias()); + endResetModel(); +} diff --git a/src/RWAHostModel.h b/src/RWAHostModel.h new file mode 100644 index 0000000..8697df2 --- /dev/null +++ b/src/RWAHostModel.h @@ -0,0 +1,23 @@ +#ifndef RWAHOSTMODEL_H +#define RWAHOSTMODEL_H + +#include +#include + +#include "RWAHost.h" + +class RWAHostModel : public QAbstractListModel { + Q_OBJECT + +public: + explicit RWAHostModel(QObject * parent = nullptr); + int rowCount(const QModelIndex& parent = QModelIndex()) const; + int columnCount(const QModelIndex& parent = QModelIndex()) const; + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; + void populate(); + +private: + QStringList mDatas; +}; + +#endif // RWAHOSTMODEL_H diff --git a/src/main.cpp b/src/main.cpp index 3339840..b85c3fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,6 +39,7 @@ #include "RWADBusAdaptor.cpp" #include "session.h" #include "scenes/add_server_wizard/add_server_wizard.h" +#include "RWAHostModel.h" #include "RWAHost.h" #define BUILD_TIME __DATE__ " " __TIME__ @@ -86,6 +87,13 @@ int main(int argc, char *argv[]) { // Make mainqmladaptor available to QML engine.rootContext()->setContextProperty("mainqmladaptor", main_gui.data()); + QScopedPointer _dbus_api (new DBusAPI()); + QObject::connect(_dbus_api.data(), + SIGNAL(serviceGetWebAppHostsResponse(QJsonDocument*)), + main_gui.data(), + SLOT(get_web_app_hosts_response(QJsonDocument*))); + _dbus_api.data()->get_web_app_hosts_request(); + engine.load(QUrl(QStringLiteral("qrc:/src/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; @@ -102,9 +110,13 @@ int main(int argc, char *argv[]) { engine.rootObjects().takeFirst(), SLOT(showWindow())); - QScopedPointer wizard (new Add_Server_wizard(&app)); + QObject::connect(engine.rootObjects().takeFirst()->findChild("sidebar_drawer"), + SIGNAL(rwaHostSelected(QString)), + main_gui.data(), + SLOT(onRwaHostSelected(QString))); // Make add_server_wizard available to QML + QScopedPointer wizard (new Add_Server_wizard(&app, main_gui.data())); engine.rootContext()->setContextProperty("add_server_wizard", wizard.data()); return app.exec(); diff --git a/src/main.qml b/src/main.qml index 3574a8c..8a19d54 100644 --- a/src/main.qml +++ b/src/main.qml @@ -182,8 +182,9 @@ ApplicationWindow { */ Drawer { id: sidebar_drawer - y: top_menu_bar_frame.height + objectName: "sidebar_drawer" + y: top_menu_bar_frame.height width: !inPortrait ? Math.min(300, Math.max(200, window.width * 0.333)) : (window.width * 0.5) height: window.height - top_menu_bar_frame.height @@ -194,6 +195,9 @@ ApplicationWindow { margins: -2 visible: !inPortrait + signal rwaHostSelected(string host_uuid) + property bool rwaHostIsSelected: false + ListView { id: sidebar_listview boundsBehavior: Flickable.StopAtBounds @@ -202,6 +206,21 @@ ApplicationWindow { anchors.fill: parent model: mainModel + header: ComboBox { + id: server_chooser + objectName: "server_chooser" + width: parent.width + height: 50 + model: mainqmladaptor.rwaHostModel + + textRole: "alias" + onCurrentIndexChanged: { + var rwa_host = mainqmladaptor.rwaHostModel + sidebar_drawer.rwaHostSelected(rwa_host[currentIndex].uuid) + sidebar_drawer.rwaHostIsSelected = true + } + } + footer: ItemDelegate { id: footer text: " " + qsTr("Settings") @@ -234,6 +253,9 @@ ApplicationWindow { main_content_replace(scene_url, StackView.Transition) } + + // Disabled till a RWAHost object is selected. + enabled: sidebar_drawer.rwaHostIsSelected } ListItem { text: " " + qsTr("Remote View") @@ -244,6 +266,9 @@ ApplicationWindow { main_content_replace(scene_url, StackView.Transition) } + + // Disabled till a RWAHost object is selected. + enabled: sidebar_drawer.rwaHostIsSelected } ListItem { text: " " + qsTr("Add RWA-Server") 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) { diff --git a/src/main_qmladaptor.h b/src/main_qmladaptor.h index 3c6e75b..8701fc9 100644 --- a/src/main_qmladaptor.h +++ b/src/main_qmladaptor.h @@ -32,11 +32,18 @@ #include #include #include +#include +#include +#include + +#include "RWAHost.h" class MainQMLAdaptor : public QObject { Q_OBJECT // this makes url available as a QML property + Q_PROPERTY(QList rwaHostModel READ getRWAHostModel WRITE setRWAHostModel 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 Q_PROPERTY(QString pin READ getPin WRITE setPin NOTIFY pinChanged) @@ -67,6 +74,7 @@ public: QString getMessageDialogText(); QMessageBox::Icon getMessageDialogIcon(); bool getShowMessageDialog(); + signals: void showMessageDialogChanged(bool show); void messageDialogTextChanged(QString text); @@ -82,6 +90,8 @@ signals: void urlChanged(QString URL); void sessionIDChanged(QString session_id); + void rwaHostModelChanged(QList); + void onCloseSignal(); void showToastSignal(QString text, QString durationMs); @@ -90,6 +100,8 @@ protected: QString _url; QString _pin; QString _session_id; + QList* _rwaHostModel; + private: QQmlApplicationEngine* _engine; @@ -102,13 +114,19 @@ public slots: void handleCopyToClipboardButtonClick(QString copy_data); void handleConnectButtonClick(bool checked); + void get_web_app_hosts_response(QJsonDocument *doc); + 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(); + QList getRWAHostModel(); + void onRwaHostSelected(QString host_uuid); void onCloseHandler(); void showToast(QString text, uint durationMs = 3000); diff --git a/src/scenes/add_server_wizard/add_server_wizard.cpp b/src/scenes/add_server_wizard/add_server_wizard.cpp index bd1dd3c..d06108c 100644 --- a/src/scenes/add_server_wizard/add_server_wizard.cpp +++ b/src/scenes/add_server_wizard/add_server_wizard.cpp @@ -23,16 +23,15 @@ * along with this program. If not, see . */ -#include -#include -#include - #include "add_server_wizard.h" #include "../../RWADBusAdaptor.h" #include "../../RWAHost.h" -Add_Server_wizard::Add_Server_wizard(QObject *parent) : QObject(parent) { +Add_Server_wizard::Add_Server_wizard(QObject *parent, MainQMLAdaptor *main_gui) : QObject(parent) { + Q_ASSERT(main_gui != nullptr); + _dbus_api = new DBusAPI(); + _main_gui = main_gui; // _dbus_api --serviceAddWebAppHostResponse-> this.add_web_app_host_response() QObject::connect(_dbus_api, @@ -96,6 +95,7 @@ void Add_Server_wizard::add_web_app_host_response(QJsonDocument *doc) { // Now built RWAHost object. QScopedPointer rwa_host (new RWAHost(host_uuid, host_alias, host_url)); + _main_gui->addRWAHost(rwa_host.data()); qInfo() << "Successfully added a new RWAHost."; emit step1Success(); diff --git a/src/scenes/add_server_wizard/add_server_wizard.h b/src/scenes/add_server_wizard/add_server_wizard.h index 554f6af..e4d62df 100644 --- a/src/scenes/add_server_wizard/add_server_wizard.h +++ b/src/scenes/add_server_wizard/add_server_wizard.h @@ -30,16 +30,19 @@ #include "../../RWADBusAdaptor.h" #include "../../DBusAPI.h" +#include "../../main_qmladaptor.h" class Add_Server_wizard : public QObject { Q_OBJECT public: - explicit Add_Server_wizard(QObject *parent = nullptr); + explicit Add_Server_wizard(QObject *parent = nullptr, + MainQMLAdaptor *main_gui = nullptr); void add_server(QString host_url); private: DBusAPI *_dbus_api; + MainQMLAdaptor *_main_gui; signals: void step1Success(); diff --git a/src/session.cpp b/src/session.cpp index 14b6575..32aca7d 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -82,7 +82,6 @@ Session::Session(QObject *parent, MainQMLAdaptor* main_gui, RWAHost *host) : QOb this, SLOT(status_response(QJsonDocument*))); - this->init_vars(); } -- cgit v1.2.3 From 0ed25cd9cd46ba4c3f64eb5e8866becaa07f5344 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Wed, 7 Jul 2021 15:42:42 +0200 Subject: Various small improvements to readability --- src/main.cpp | 4 ++-- src/main.qml | 2 +- src/main_qmladaptor.cpp | 19 ++++++++----------- src/main_qmladaptor.h | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) (limited to 'src/main_qmladaptor.cpp') diff --git a/src/main.cpp b/src/main.cpp index b85c3fc..a72e42b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,6 +36,7 @@ #include #include +#include "DBusAPI.h" #include "RWADBusAdaptor.cpp" #include "session.h" #include "scenes/add_server_wizard/add_server_wizard.h" @@ -82,9 +83,8 @@ int main(int argc, char *argv[]) { QQmlApplicationEngine engine(&app); - QScopedPointer main_gui (new MainQMLAdaptor(&app, &engine)); - // Make mainqmladaptor available to QML + QScopedPointer main_gui (new MainQMLAdaptor(&app, &engine)); engine.rootContext()->setContextProperty("mainqmladaptor", main_gui.data()); QScopedPointer _dbus_api (new DBusAPI()); diff --git a/src/main.qml b/src/main.qml index 8a19d54..12c4668 100644 --- a/src/main.qml +++ b/src/main.qml @@ -212,8 +212,8 @@ ApplicationWindow { width: parent.width height: 50 model: mainqmladaptor.rwaHostModel - textRole: "alias" + onCurrentIndexChanged: { var rwa_host = mainqmladaptor.rwaHostModel sidebar_drawer.rwaHostSelected(rwa_host[currentIndex].uuid) diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index d75b15c..5fcce5f 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -128,7 +128,8 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { bool MainQMLAdaptor::setConnectButtonEnabled(bool enabled) { // Find item via 'objectName' - QQuickItem *item = _engine->rootObjects().at(0)->findChild("start_support_button"); + QQuickItem *scene_remote_control = _engine->rootObjects().at(0)->findChild("Scene_remote_control"); + QQuickItem *item = scene_remote_control->findChild("start_support_button"); if (item) { item->setProperty("enabled", enabled); if (item->property("checked").toBool()) { @@ -146,7 +147,8 @@ bool MainQMLAdaptor::setConnectButtonEnabled(bool enabled) { bool MainQMLAdaptor::setConnectButtonChecked(bool checked) { // Find item via 'objectName' - QQuickItem *item = _engine->rootObjects().at(0)->findChild("start_support_button"); + QQuickItem *scene_remote_control = _engine->rootObjects().at(0)->findChild("Scene_remote_control"); + QQuickItem *item = scene_remote_control->findChild("start_support_button"); if (item) { item->setProperty("checked", checked); } else { @@ -159,7 +161,8 @@ bool MainQMLAdaptor::setConnectButtonChecked(bool checked) { bool MainQMLAdaptor::setStatus(QString status) { // Find item via 'objectName' - QQuickItem *item = _engine->rootObjects().at(0)->findChild("dbus_api_status_text"); + QQuickItem *scene_remote_control = _engine->rootObjects().at(0)->findChild("Scene_remote_control"); + QQuickItem *item = scene_remote_control->findChild("dbus_api_status_text"); if (item) { item->setProperty("text", status); } else { @@ -203,7 +206,8 @@ bool MainQMLAdaptor::getShowMessageDialog() { bool MainQMLAdaptor::setStatusIndicator(bool active, QColor color) { // Find item via 'objectName' - QQuickItem *item = _engine->rootObjects().at(0)->findChild("dbus_api_status_indicator"); + QQuickItem *scene_remote_control = _engine->rootObjects().at(0)->findChild("Scene_remote_control"); + QQuickItem *item = scene_remote_control->findChild("dbus_api_status_indicator"); if (item) { item->setProperty("active", active); item->setProperty("color", color); @@ -256,10 +260,3 @@ void MainQMLAdaptor::onCloseHandler() { void MainQMLAdaptor::showToast(QString text, uint durationMs) { emit showToastSignal(text, QString::number(durationMs)); } - -//void MainQMLAdaptor::onCloseHandler() { -// qDebug() << "Inside MainQMLAdaptor::onCloseHandler()"; - -// // Sending onClose signal to main and there to Session::onCloseHandler() -// emit MainQMLAdaptor::onCloseSignal(); -//} diff --git a/src/main_qmladaptor.h b/src/main_qmladaptor.h index 8701fc9..05de1fd 100644 --- a/src/main_qmladaptor.h +++ b/src/main_qmladaptor.h @@ -61,7 +61,7 @@ class MainQMLAdaptor : public QObject public: explicit MainQMLAdaptor(QObject *parent, QQmlApplicationEngine *engine = nullptr); -// void setSession(Session session); +// void setSession(Session session); bool setConnectButtonEnabled(bool enabled); bool setConnectButtonChecked(bool checked); -- cgit v1.2.3 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 (limited to 'src/main_qmladaptor.cpp') 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 From 36dcf4b27450f04ac60a05cd2837c1b58fd5b24a Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Thu, 8 Jul 2021 15:55:53 +0200 Subject: Classes share one specific D-Bus object now. --- src/main.cpp | 14 +++++++++----- src/main_qmladaptor.cpp | 5 ++++- src/main_qmladaptor.h | 4 +++- src/scenes/add_server_wizard/add_server_wizard.cpp | 6 ++++-- 4 files changed, 20 insertions(+), 9 deletions(-) (limited to 'src/main_qmladaptor.cpp') diff --git a/src/main.cpp b/src/main.cpp index a72e42b..7f86b6d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -83,16 +83,18 @@ int main(int argc, char *argv[]) { QQmlApplicationEngine engine(&app); + QScopedPointer dbus_api (new DBusAPI()); + // Make mainqmladaptor available to QML - QScopedPointer main_gui (new MainQMLAdaptor(&app, &engine)); + QScopedPointer main_gui (new MainQMLAdaptor(&app, &engine, dbus_api.data())); engine.rootContext()->setContextProperty("mainqmladaptor", main_gui.data()); - QScopedPointer _dbus_api (new DBusAPI()); - QObject::connect(_dbus_api.data(), + QObject::connect(dbus_api.data(), SIGNAL(serviceGetWebAppHostsResponse(QJsonDocument*)), main_gui.data(), SLOT(get_web_app_hosts_response(QJsonDocument*))); - _dbus_api.data()->get_web_app_hosts_request(); + dbus_api.data()->get_web_app_hosts_request(); + engine.load(QUrl(QStringLiteral("qrc:/src/main.qml"))); if (engine.rootObjects().isEmpty()) @@ -116,7 +118,9 @@ int main(int argc, char *argv[]) { SLOT(onRwaHostSelected(QString))); // Make add_server_wizard available to QML - QScopedPointer wizard (new Add_Server_wizard(&app, main_gui.data())); + QScopedPointer wizard (new Add_Server_wizard(&app, + main_gui.data(), + dbus_api.data())); engine.rootContext()->setContextProperty("add_server_wizard", wizard.data()); return app.exec(); diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index c1d3f14..2dec33c 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -26,10 +26,13 @@ #include "main_qmladaptor.h" -MainQMLAdaptor::MainQMLAdaptor(QObject *parent, QQmlApplicationEngine* engine) : QObject(parent) { +MainQMLAdaptor::MainQMLAdaptor(QObject *parent, QQmlApplicationEngine* engine, + DBusAPI *dbus_api) : QObject(parent) { Q_ASSERT(engine != nullptr); + Q_ASSERT(dbus_api != nullptr); _engine = engine; + _dbus_api = dbus_api; _rwaHostModel = new QList; } diff --git a/src/main_qmladaptor.h b/src/main_qmladaptor.h index a289a74..48923d5 100644 --- a/src/main_qmladaptor.h +++ b/src/main_qmladaptor.h @@ -37,6 +37,7 @@ #include #include "RWAHost.h" +#include "DBusAPI.h" class MainQMLAdaptor : public QObject { @@ -59,7 +60,8 @@ class MainQMLAdaptor : public QObject Q_PROPERTY(QMessageBox::Icon _messageDialogIcon READ getMessageDialogIcon NOTIFY messageDialogIconChanged) public: - explicit MainQMLAdaptor(QObject *parent, QQmlApplicationEngine *engine = nullptr); + explicit MainQMLAdaptor(QObject *parent, QQmlApplicationEngine *engine = nullptr, + DBusAPI *dbus_api = nullptr); void setRWAHostModel(QList *rwa_hosts); diff --git a/src/scenes/add_server_wizard/add_server_wizard.cpp b/src/scenes/add_server_wizard/add_server_wizard.cpp index 09db898..a5bee47 100644 --- a/src/scenes/add_server_wizard/add_server_wizard.cpp +++ b/src/scenes/add_server_wizard/add_server_wizard.cpp @@ -27,10 +27,12 @@ #include "../../RWADBusAdaptor.h" #include "../../RWAHost.h" -Add_Server_wizard::Add_Server_wizard(QObject *parent, MainQMLAdaptor *main_gui) : QObject(parent) { +Add_Server_wizard::Add_Server_wizard(QObject *parent, + MainQMLAdaptor *main_gui, DBusAPI *dbus_api) : QObject(parent) { Q_ASSERT(main_gui != nullptr); + Q_ASSERT(dbus_api != nullptr); - _dbus_api = new DBusAPI(); + _dbus_api = dbus_api; _main_gui = main_gui; // _dbus_api --serviceAddWebAppHostResponse-> this.add_web_app_host_response() -- cgit v1.2.3 From 5be60cd11d0d9dbde8ca67f0ec88e10540c490db Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Thu, 8 Jul 2021 15:57:44 +0200 Subject: Refresh hosts every 10 seconds. --- src/main_qmladaptor.cpp | 4 ++++ src/main_qmladaptor.h | 1 + 2 files changed, 5 insertions(+) (limited to 'src/main_qmladaptor.cpp') diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 2dec33c..6684d13 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -34,6 +34,10 @@ MainQMLAdaptor::MainQMLAdaptor(QObject *parent, QQmlApplicationEngine* engine, _engine = engine; _dbus_api = dbus_api; _rwaHostModel = new QList; + + QTimer *timer = new QTimer(this); + connect(timer, &QTimer::timeout, _dbus_api, QOverload<>::of(&DBusAPI::get_web_app_hosts_request)); + timer->start(10000); } void MainQMLAdaptor::onRwaHostSelected(QString host_uuid) { diff --git a/src/main_qmladaptor.h b/src/main_qmladaptor.h index 48923d5..d928acd 100644 --- a/src/main_qmladaptor.h +++ b/src/main_qmladaptor.h @@ -35,6 +35,7 @@ #include #include #include +#include #include "RWAHost.h" #include "DBusAPI.h" -- cgit v1.2.3 From 6072a403da8e0743dfc42d62d89a09724650ebfa Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Thu, 8 Jul 2021 15:58:57 +0200 Subject: Add_server_wizard: Add new type-error messages --- src/main_qmladaptor.cpp | 2 +- src/scenes/add_server_wizard/add_server_wizard.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/main_qmladaptor.cpp') diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 6684d13..c321ec8 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -175,7 +175,7 @@ void MainQMLAdaptor::main_content_replace(QString scene) { bool MainQMLAdaptor::setConnectButtonEnabled(bool enabled) { // Find item via 'objectName' - QQuickItem *scene_remote_control = _engine->rootObjects().at(0)->findChild("Scene_remote_control"); + QQuickItem *scene_remote_control = _engine->rootObjects().takeFirst()->findChild("Scene_remote_control"); QQuickItem *item = scene_remote_control->findChild("start_support_button"); if (item) { item->setProperty("enabled", enabled); diff --git a/src/scenes/add_server_wizard/add_server_wizard.cpp b/src/scenes/add_server_wizard/add_server_wizard.cpp index a5bee47..e398b19 100644 --- a/src/scenes/add_server_wizard/add_server_wizard.cpp +++ b/src/scenes/add_server_wizard/add_server_wizard.cpp @@ -92,6 +92,12 @@ void Add_Server_wizard::add_web_app_host_response(QJsonDocument *doc) { } else if (type == "invalid_url") { reason = tr("The specified host address is not valid!"); qCritical().noquote() << reason; + } else if (type == "permission_denied") { + reason = tr("The specified host address does not grant access!"); + qCritical().noquote() << reason; + } else if (type == "unsupported_server") { + reason = tr("The specified host address is not supported!"); + qCritical().noquote() << reason; } emit step1Failed(reason); -- cgit v1.2.3 From b975bb69043c8857bbfb5c152e6e277beadf5853 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Thu, 8 Jul 2021 16:43:20 +0200 Subject: Don't crash on failure but show an error message. --- src/main_qmladaptor.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/main_qmladaptor.cpp') diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index c321ec8..845da0a 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -81,7 +81,13 @@ QList MainQMLAdaptor::getRWAHostModel() { } void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { - Q_ASSERT(doc != nullptr); + // Don't use Q_ASSERT(doc != nullptr); instead use: + if (doc == nullptr) { + showToast(tr("Can't connect to underlying session service!"), 10000); + return; + } + // Q_ASSERT lets the program crash immediatly at startup, + // when the session service is not started. delete _rwaHostModel; setRWAHostModel(new QList); -- cgit v1.2.3 From acf033cbb15641a79a093c301efa3fd478237c2a Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Thu, 8 Jul 2021 16:44:35 +0200 Subject: If there are no hosts available: display it in the sidebar menu. --- src/main_qmladaptor.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/main_qmladaptor.cpp') diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 845da0a..419f794 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -151,7 +151,20 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { if (!atLeastOneHostAvailable) { main_content_replace("scenes/Scene_no_server_available.qml"); - //addRWAHost(new RWAHost("-","Kein Server verfügbar!","-")); + // Find item via 'objectName' + QObject *sidebar_drawer = _engine->rootObjects().takeFirst()->findChild("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("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!"; } } -- cgit v1.2.3 From c8dc8bda03b27a76d31c358e4b642a5687611178 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Mon, 12 Jul 2021 12:54:17 +0200 Subject: MainQMLAdaptor: removeRWAHost() and setRWAHostSelected() --- src/main_qmladaptor.cpp | 60 +++++++++++++++++++++++++++---------------------- src/main_qmladaptor.h | 3 ++- 2 files changed, 35 insertions(+), 28 deletions(-) (limited to 'src/main_qmladaptor.cpp') 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(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("sidebar_drawer"); - if (sidebar_drawer) { - sidebar_drawer->setProperty("rwaHostIsSelected", true); - } else { - qWarning() << "Unable to find 'sidebar_drawer' Item!"; - } + setRWAHostSelected(true); } void MainQMLAdaptor::setRWAHostModel(QList *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 MainQMLAdaptor::getRWAHostModel() { return *_rwaHostModel; } +void MainQMLAdaptor::setRWAHostSelected(bool value) { + // Find item via 'objectName' + QObject *sidebar_drawer = _engine->rootObjects().takeFirst()->findChild("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("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); + 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("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("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 #include #include #include @@ -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(); -- cgit v1.2.3 From 18c2b837d33c040a21f84c444d8c554769f1dc58 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Mon, 12 Jul 2021 13:02:24 +0200 Subject: Don't just reset the _rwaHostModel everytime but add and remove specific items. TODO: Use QSet subtraction feature instead of manual for loops!!! --- src/main_qmladaptor.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 7 deletions(-) (limited to 'src/main_qmladaptor.cpp') diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index a89d085..6d3a60c 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -121,6 +121,7 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { // Building host_objects QJsonArray host_objects = jObject.value("hosts").toArray(); + QList *all_rwa_hosts = new QList; foreach (const QJsonValue &host_object, host_objects) { QString host_uuid = host_object["uuid"].toString(); QString host_alias = host_object["alias"].toString(); @@ -142,12 +143,46 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { host_alias = host_url; } + // Now built RWAHost object. RWAHost *rwa_host = new RWAHost(host_uuid, host_alias, host_url); - addRWAHost(rwa_host); + all_rwa_hosts->append(rwa_host); + + bool found = false; + for (int i = 0; i < this->_rwaHostModel->size(); i++) { + RWAHost* old_host = qobject_cast(_rwaHostModel->value(i)); + Q_ASSERT(old_host != nullptr); + + if (rwa_host->uuid() == old_host->uuid()) { + found = true; + break; + } + } + atLeastOneHostAvailable = true; - qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")).arg(rwa_host->alias()); + if (!found) { + qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")).arg(rwa_host->alias()); + addRWAHost(rwa_host); + } + } + + for (int i = 0; i < this->_rwaHostModel->size(); i++) { + RWAHost* old_host = qobject_cast(_rwaHostModel->value(i)); + Q_ASSERT(old_host != nullptr); + + bool found = false; + for (RWAHost *host : *all_rwa_hosts) { + if (host->uuid() == old_host->uuid()) { + found = true; + break; + } + } + + if (!found) { + removeRWAHost(old_host); + qInfo().noquote() << QString(tr("Removed RWAHost '%0'")).arg(old_host->alias()); + } } } else { QString reason = tr("An error occured while adding a new host:"); @@ -176,16 +211,40 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { void MainQMLAdaptor::main_content_push(QString scene) { // Find item via 'objectName' + QObject *window = _engine->rootObjects().takeFirst(); + Q_ASSERT(window != nullptr); + QObject *main_content = _engine->rootObjects().takeFirst()->findChild("main_content"); Q_ASSERT(main_content != nullptr); - QMetaObject::invokeMethod(main_content, "push", Q_ARG(QString, scene)); + + QVariant to_cast = main_content->property("currentItem"); + QObject *obj = qvariant_cast(to_cast); + if (obj) { + if (!(scene.contains(obj->objectName()))) { + QVariant arg = QVariant::fromValue(scene); + if(!QMetaObject::invokeMethod(window, "main_content_push", Q_ARG(QVariant, arg))) + qDebug() << "Failed to invoke push"; + } + } } void MainQMLAdaptor::main_content_pop(QString scene) { // Find item via 'objectName' + QObject *window = _engine->rootObjects().takeFirst(); + Q_ASSERT(window != nullptr); + QObject *main_content = _engine->rootObjects().takeFirst()->findChild("main_content"); Q_ASSERT(main_content != nullptr); - QMetaObject::invokeMethod(main_content, "pop", Q_ARG(QString, scene)); + + QVariant to_cast = main_content->property("currentItem"); + QObject *obj = qvariant_cast(to_cast); + if (obj) { + if (!(scene.contains(obj->objectName()))) { + QVariant arg = QVariant::fromValue(scene); + if(!QMetaObject::invokeMethod(window, "main_content_pop", Q_ARG(QVariant, arg))) + qDebug() << "Failed to invoke pop"; + } + } } void MainQMLAdaptor::main_content_replace(QString scene) { @@ -193,9 +252,19 @@ void MainQMLAdaptor::main_content_replace(QString scene) { 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"; + QObject *main_content = _engine->rootObjects().takeFirst()->findChild("main_content"); + Q_ASSERT(main_content != nullptr); + + QVariant to_cast = main_content->property("currentItem"); + QObject *obj = qvariant_cast(to_cast); + if (obj) { + QString scene_add_server_wizard = "Scene_step_1"; + if (!(scene.contains(obj->objectName()) || scene_add_server_wizard.contains(obj->objectName()))) { + QVariant arg = QVariant::fromValue(scene); + if(!QMetaObject::invokeMethod(window, "main_content_replace", Q_ARG(QVariant, arg))) + qDebug() << "Failed to invoke replace"; + } + } } bool MainQMLAdaptor::setConnectButtonEnabled(bool enabled) { -- cgit v1.2.3 From efa44c931674e498c39fc59091cf1f8654ac97a5 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Sun, 1 Aug 2021 01:58:32 +0200 Subject: Fix typos, too long lines, various styling stuff --- src/DBusAPI.cpp | 18 +++++++++--------- src/DBusAPI.h | 3 +-- src/Toast.qml | 13 ++++++++----- src/main.cpp | 19 +++++++++---------- src/main.qml | 17 +++++++++++------ src/main_qmladaptor.cpp | 20 +++++++++++++------- src/scenes/Scene_no_server_available.qml | 3 ++- src/scenes/Scene_placeholder.qml | 3 ++- src/scenes/Scene_remote_view.qml | 5 +++++ src/scenes/Scene_settings.qml | 5 +++++ src/scenes/add_server_wizard/Scene_step_1.qml | 15 ++++++++++----- 11 files changed, 75 insertions(+), 46 deletions(-) (limited to 'src/main_qmladaptor.cpp') diff --git a/src/DBusAPI.cpp b/src/DBusAPI.cpp index 760935b..83f38cb 100644 --- a/src/DBusAPI.cpp +++ b/src/DBusAPI.cpp @@ -60,7 +60,7 @@ void DBusAPI::start_request(RWAHost *host) { qDebug() << "Requesting D-Bus service to start a new session on host:" << host->alias(); - // Make an asynchrous 'start' call (Response will be sent to 'start_reply') + // Make an asynchronous 'start' call (Response will be sent to 'start_reply') QDBusPendingCall async = _dbus_rwa->asyncCall("start", host->uuid()); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); @@ -125,7 +125,7 @@ void DBusAPI::stop_request(RWAHost *host, QString session_id) { .arg(session_id) .arg(host->alias()); - // Make an asynchrous 'start' call (Response will be sent to 'stop_reply') + // Make an asynchronous 'stop' call (Response will be sent to 'stop_reply') QDBusPendingCall async = _dbus_rwa->asyncCall("stop", host->uuid(), session_id_number); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); @@ -182,14 +182,14 @@ void DBusAPI::status_request(RWAHost *host, QString session_id) { // Sanity Check if(ok == false){ - qWarning() << QString("Unable to parse '%0' as long long!").arg(session_id); + qWarning().noquote() << QString("Unable to parse session_id '%0' as long long!").arg(session_id); return; } qDebug().noquote() << QString("Requesting D-Bus service for status of session " "#'%0' on host '%1'").arg(session_id).arg(host->alias()); - // Make an asynchrous 'start' call (Response will be sent to 'status_reply') + // Make an asynchronous 'start' call (Response will be sent to 'status_reply') QDBusPendingCall async = _dbus_rwa->asyncCall("status", host->uuid(), session_id_number); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); @@ -213,14 +213,14 @@ void DBusAPI::refresh_status_request(RWAHost *host, QString session_id) { // Sanity Check if(ok == false){ - qWarning() << QString("Unable to parse '%0' as long long!").arg(session_id); + qWarning().noquote() << QString("Unable to parse session_id '%0' as long long!").arg(session_id); return; } qDebug().noquote() << QString("Requesting D-Bus service for refresh_status of session " "#'%0' on host '%1'").arg(session_id).arg(host->alias()); - // Make an asynchrous 'start' call (Response will be sent to 'status_reply') + // Make an asynchronous 'start' call (Response will be sent to 'status_reply') QDBusPendingCall async = _dbus_rwa->asyncCall("refresh_status", host->uuid(), session_id_number); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); @@ -269,7 +269,7 @@ void DBusAPI::get_web_app_hosts_request() { qDebug().noquote() << QString("Requesting D-Bus service to list " "all remote web app hosts"); - // Make an asynchrous 'get_web_app_hosts' call + // Make an asynchronous 'get_web_app_hosts' call // Response will be sent to 'get_web_app_hosts_reply' QDBusPendingCall async = _dbus_rwa->asyncCall("get_web_app_hosts"); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); @@ -291,7 +291,7 @@ void DBusAPI::add_web_app_host_request(QString host_url, QString host_alias) { qDebug().noquote() << QString("Requesting D-Bus service to register new " "remote web app host '%0' with url '%1'").arg(host_alias).arg(host_url); - // Make an asynchrous 'add_web_app_host' call + // Make an asynchronous 'add_web_app_host' call // Response will be sent to 'add_web_app_host_reply' QDBusPendingCall async = _dbus_rwa->asyncCall("add_web_app_host", host_url, host_alias); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); @@ -311,7 +311,7 @@ void DBusAPI::remove_web_app_host_request(QString host_uuid) { qDebug().noquote() << QString("Requesting D-Bus service to list " "all remote web app hosts"); - // Make an asynchrous 'remove_web_app_host' call + // Make an asynchronous 'remove_web_app_host' call // Response will be sent to 'remove_web_app_host_reply' QDBusPendingCall async = _dbus_rwa->asyncCall("remove_web_app_host", host_uuid); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); diff --git a/src/DBusAPI.h b/src/DBusAPI.h index a25fb64..63dbe68 100644 --- a/src/DBusAPI.h +++ b/src/DBusAPI.h @@ -32,8 +32,7 @@ #include "RWAHost.h" #include "RWADBusAdaptor.h" -class DBusAPI : public QObject -{ +class DBusAPI : public QObject { Q_OBJECT public: explicit DBusAPI(); diff --git a/src/Toast.qml b/src/Toast.qml index 60e238c..0de53a9 100644 --- a/src/Toast.qml +++ b/src/Toast.qml @@ -36,7 +36,8 @@ import QtQuick.Controls.Material 2.3 */ /** - * @brief An Android-like timed message text in a box that self-destroys when finished if desired + * @brief An Android-like timed message text in + * a box that self-destroys when finished if desired */ Control { @@ -52,16 +53,18 @@ Control { */ function show(text, duration) { message.text = text; - if (typeof duration !== "undefined") { // checks if parameter was passed + + // checks if parameter was passed + if (typeof duration !== "undefined") { time = Math.max(duration, 2 * fadeTime); - } - else { + } else { time = defaultTime; } animation.start(); } - property bool selfDestroying: false // whether this Toast will self-destroy when it is finished + // whether this Toast will self-destroy when it is finished + property bool selfDestroying: false /** * Private diff --git a/src/main.cpp b/src/main.cpp index bb83d45..7139883 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,13 +40,12 @@ #include "RWADBusAdaptor.cpp" #include "session.h" #include "scenes/add_server_wizard/add_server_wizard.h" +#include "scenes/remote_control/remote_control_manager.h" #include "RWAHostModel.h" #include "RWAHost.h" -#define BUILD_TIME __DATE__ " " __TIME__ - int main(int argc, char *argv[]) { - qDebug() << "This app was built on: " << BUILD_TIME; + qDebug() << "This app was built on: " << __DATE__ << __TIME__; // We don't want users to have multiple instances of this app running QString tmpDirPath = QDir::tempPath() + "/rwa.support.desktopapp"; @@ -85,8 +84,11 @@ int main(int argc, char *argv[]) { QScopedPointer dbus_api (new DBusAPI()); - // Make mainqmladaptor available to QML - QScopedPointer main_gui (new MainQMLAdaptor(&app, &engine, dbus_api.data())); + // Make 'mainqmladaptor' available to QML + QScopedPointer main_gui ( + new MainQMLAdaptor(&app, &engine, dbus_api.data()) + ); + engine.rootContext()->setContextProperty("mainqmladaptor", main_gui.data()); QObject::connect(dbus_api.data(), @@ -100,10 +102,6 @@ int main(int argc, char *argv[]) { if (engine.rootObjects().isEmpty()) return -1; - //QScopedPointer rwa_host (new RWAHost("b9e09715-fe1d-4419-9b57-a0bd5b181ff0", "Lokaler Server", "http://localhost:8000")); - //QScopedPointer session (new Session(&app, main_gui.data(), rwa_host.data())); - //session.data()->start(); - QObject::connect(main_gui.data(), SIGNAL(minimizeWindow()), engine.rootObjects().takeFirst(), @@ -114,7 +112,8 @@ int main(int argc, char *argv[]) { engine.rootObjects().takeFirst(), SLOT(showWindow())); - QObject::connect(engine.rootObjects().takeFirst()->findChild("sidebar_drawer"), + QObject::connect(engine.rootObjects().takeFirst()-> + findChild("sidebar_drawer"), SIGNAL(rwaHostSelected(QString)), main_gui.data(), SLOT(onRwaHostSelected(QString))); diff --git a/src/main.qml b/src/main.qml index 102df11..03f9c5f 100644 --- a/src/main.qml +++ b/src/main.qml @@ -114,7 +114,7 @@ ApplicationWindow { Connections { target: mainqmladaptor - onShowMessageDialogChanged: { + function onShowMessageDialogChanged(show) { message_dialog.visible = show } } @@ -153,21 +153,21 @@ ApplicationWindow { Connections { target: mainqmladaptor - onMessageDialogTextChanged: { + function onMessageDialogTextChanged(text) { message_dialog.text = text } } Connections { target: mainqmladaptor - onMessageDialogTitleChanged: { + function onMessageDialogTitleChanged(title) { message_dialog.title = title } } Connections { target: mainqmladaptor - onMessageDialogIconChanged: { + function onMessageDialogIconChanged(iconindex) { message_dialog.icon = iconindex } } @@ -185,7 +185,9 @@ ApplicationWindow { objectName: "sidebar_drawer" y: top_menu_bar_frame.height - width: !inPortrait ? Math.min(300, Math.max(200, window.width * 0.333)) : (window.width * 0.5) + width: !inPortrait ? + Math.min(300, Math.max(200, window.width * 0.333)) : + (window.width * 0.5) height: window.height - top_menu_bar_frame.height modal: inPortrait @@ -286,7 +288,10 @@ ApplicationWindow { } // Disabled till a RWAHost object is selected. - enabled: sidebar_drawer.rwaHostIsSelected + //enabled: sidebar_drawer.rwaHostIsSelected + + // But remote view is not implemented yet + enabled: false } ListItem { text: " " + qsTr("Add RWA-Server") diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 6d3a60c..7e85157 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -129,8 +129,8 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { 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)"); + 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; @@ -162,7 +162,8 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { atLeastOneHostAvailable = true; if (!found) { - qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")).arg(rwa_host->alias()); + qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")) + .arg(rwa_host->alias()); addRWAHost(rwa_host); } } @@ -233,7 +234,8 @@ void MainQMLAdaptor::main_content_pop(QString scene) { QObject *window = _engine->rootObjects().takeFirst(); Q_ASSERT(window != nullptr); - QObject *main_content = _engine->rootObjects().takeFirst()->findChild("main_content"); + QObject *main_content = _engine->rootObjects().takeFirst()-> + findChild("main_content"); Q_ASSERT(main_content != nullptr); QVariant to_cast = main_content->property("currentItem"); @@ -252,17 +254,21 @@ void MainQMLAdaptor::main_content_replace(QString scene) { QObject *window = _engine->rootObjects().takeFirst(); Q_ASSERT(window != nullptr); - QObject *main_content = _engine->rootObjects().takeFirst()->findChild("main_content"); + QObject *main_content = _engine->rootObjects().takeFirst()-> + findChild("main_content"); Q_ASSERT(main_content != nullptr); QVariant to_cast = main_content->property("currentItem"); QObject *obj = qvariant_cast(to_cast); if (obj) { QString scene_add_server_wizard = "Scene_step_1"; - if (!(scene.contains(obj->objectName()) || scene_add_server_wizard.contains(obj->objectName()))) { + if (!(scene.contains(obj->objectName()) || + scene_add_server_wizard.contains(obj->objectName()))) { QVariant arg = QVariant::fromValue(scene); - if(!QMetaObject::invokeMethod(window, "main_content_replace", Q_ARG(QVariant, arg))) + if (!QMetaObject::invokeMethod(window, "main_content_replace", + Q_ARG(QVariant, arg))) { qDebug() << "Failed to invoke replace"; + } } } } diff --git a/src/scenes/Scene_no_server_available.qml b/src/scenes/Scene_no_server_available.qml index 112c6e0..7b99b55 100644 --- a/src/scenes/Scene_no_server_available.qml +++ b/src/scenes/Scene_no_server_available.qml @@ -6,7 +6,8 @@ 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). + * This .qml file is a Scene which can be loaded through for + * example a StackView (main_content in main.qml). */ Item { diff --git a/src/scenes/Scene_placeholder.qml b/src/scenes/Scene_placeholder.qml index 29e15a9..f492e00 100644 --- a/src/scenes/Scene_placeholder.qml +++ b/src/scenes/Scene_placeholder.qml @@ -6,7 +6,8 @@ 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). + * This .qml file is a Scene which can be loaded through for + * example a StackView (main_content in main.qml). */ Item { diff --git a/src/scenes/Scene_remote_view.qml b/src/scenes/Scene_remote_view.qml index cea5ccf..436d8aa 100644 --- a/src/scenes/Scene_remote_view.qml +++ b/src/scenes/Scene_remote_view.qml @@ -5,6 +5,11 @@ 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_remote_view objectName: "Scene_remote_view" diff --git a/src/scenes/Scene_settings.qml b/src/scenes/Scene_settings.qml index 5a29071..e2f89da 100644 --- a/src/scenes/Scene_settings.qml +++ b/src/scenes/Scene_settings.qml @@ -5,6 +5,11 @@ 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_settings objectName: "Scene_settings" diff --git a/src/scenes/add_server_wizard/Scene_step_1.qml b/src/scenes/add_server_wizard/Scene_step_1.qml index abd761d..e57f8a4 100644 --- a/src/scenes/add_server_wizard/Scene_step_1.qml +++ b/src/scenes/add_server_wizard/Scene_step_1.qml @@ -5,7 +5,8 @@ import QtQuick.Controls 2.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). + * This .qml file is a Scene which can be loaded through for + * example a StackView (main_content in main.qml). */ Item { @@ -14,17 +15,21 @@ Item { Connections { target: add_server_wizard - onStep1Success: { + function onStep1Success() { // Go onto the first page of the stack. main_content_pop(null) - mainqmladaptor.showToast(qsTr("Successfully added remote web app host."), 5000); + mainqmladaptor.showToast(qsTr("Successfully added remote web app host."), + 5000, + ToastType.ToastSuccess); } } Connections { target: add_server_wizard - onStep1Failed: { - mainqmladaptor.showToast(reason, 3000); + function onStep1Failed(reason, toast_type) { + mainqmladaptor.showToast(reason, + 5000, + toast_type) } } -- cgit v1.2.3 From 766a90125df68f065495354c20412faf9e1df77a Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Sun, 1 Aug 2021 02:19:15 +0200 Subject: move scenes/Scene_remote_control.qml into scenes/remote_control/Scene_remote_control.qml --- src/DBusAPI.cpp | 2 +- src/main.qml | 2 +- src/main_qmladaptor.cpp | 57 +----- src/main_qmladaptor.h | 7 +- src/scenes/Scene_remote_control.qml | 368 ------------------------------------ src/session.cpp | 34 +++- 6 files changed, 34 insertions(+), 436 deletions(-) delete mode 100644 src/scenes/Scene_remote_control.qml (limited to 'src/main_qmladaptor.cpp') diff --git a/src/DBusAPI.cpp b/src/DBusAPI.cpp index 83f38cb..9a0f8de 100644 --- a/src/DBusAPI.cpp +++ b/src/DBusAPI.cpp @@ -116,7 +116,7 @@ void DBusAPI::stop_request(RWAHost *host, QString session_id) { // Sanity Check if(ok == false){ - qWarning() << QString("Unable to parse '%0' as long long!").arg(session_id); + qWarning().noquote() << QString("Unable to parse session_id '%0' as long long!").arg(session_id); return; } diff --git a/src/main.qml b/src/main.qml index 03f9c5f..4782f4b 100644 --- a/src/main.qml +++ b/src/main.qml @@ -264,7 +264,7 @@ ApplicationWindow { ListItem { text: " " + qsTr("Remote Control") - scene_url: "scenes/Scene_remote_control.qml" + scene_url: "scenes/remote_control/Scene_remote_control.qml" onListItemClick: { header_text.text = qsTr("Allow remote control") if (inPortrait) sidebar_drawer.close() diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 7e85157..5da0abb 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -81,16 +81,20 @@ QList MainQMLAdaptor::getRWAHostModel() { void MainQMLAdaptor::setRWAHostSelected(bool value) { // Find item via 'objectName' - QObject *sidebar_drawer = _engine->rootObjects().takeFirst()->findChild("sidebar_drawer"); + QObject *sidebar_drawer = _engine->rootObjects().takeFirst()-> + findChild("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("server_chooser"); + QObject *server_chooser = _engine->rootObjects().takeFirst()-> + findChild("server_chooser"); if (server_chooser) { - server_chooser->setProperty("displayText", value ? server_chooser->property("currentText") : tr("No RWA host available!")); + 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!"; @@ -273,53 +277,6 @@ void MainQMLAdaptor::main_content_replace(QString scene) { } } -bool MainQMLAdaptor::setConnectButtonEnabled(bool enabled) { - // Find item via 'objectName' - QQuickItem *scene_remote_control = _engine->rootObjects().takeFirst()->findChild("Scene_remote_control"); - QQuickItem *item = scene_remote_control->findChild("start_support_button"); - if (item) { - item->setProperty("enabled", enabled); - if (item->property("checked").toBool()) { - item->setProperty("text", tr("Stop remote support session")); - } else { - item->setProperty("text", tr("Start remote support session")); - } - } else { - qWarning() << "Unable to find 'start_support_button' Item!"; - return false; - } - - return true; -} - -bool MainQMLAdaptor::setConnectButtonChecked(bool checked) { - // Find item via 'objectName' - QQuickItem *scene_remote_control = _engine->rootObjects().at(0)->findChild("Scene_remote_control"); - QQuickItem *item = scene_remote_control->findChild("start_support_button"); - if (item) { - item->setProperty("checked", checked); - } else { - qWarning() << "Unable to find 'start_support_button' Item!"; - return false; - } - - return true; -} - -bool MainQMLAdaptor::setStatus(QString status) { - // Find item via 'objectName' - QQuickItem *scene_remote_control = _engine->rootObjects().at(0)->findChild("Scene_remote_control"); - QQuickItem *item = scene_remote_control->findChild("dbus_api_status_text"); - if (item) { - item->setProperty("text", status); - } else { - qWarning() << "Unable to find 'dbus_api_status_text' Item!"; - return false; - } - - return true; -} - bool MainQMLAdaptor::openMessageDialog(QString title, QString text, QMessageBox::Icon icon) { _messageDialogText = text; _messageDialogTitle = title; diff --git a/src/main_qmladaptor.h b/src/main_qmladaptor.h index d7f1783..9a2f7c3 100644 --- a/src/main_qmladaptor.h +++ b/src/main_qmladaptor.h @@ -59,22 +59,17 @@ class MainQMLAdaptor : public QObject // this makes showMessageDialogIcon available as a QML property Q_PROPERTY(QMessageBox::Icon _messageDialogIcon READ getMessageDialogIcon NOTIFY messageDialogIconChanged) + public: explicit MainQMLAdaptor(QObject *parent, QQmlApplicationEngine *engine = nullptr, DBusAPI *dbus_api = nullptr); 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); - bool openMessageDialog(QString title, QString text, QMessageBox::Icon); QString getMessageDialogTitle(); QString getMessageDialogText(); diff --git a/src/scenes/Scene_remote_control.qml b/src/scenes/Scene_remote_control.qml deleted file mode 100644 index ea59ea7..0000000 --- a/src/scenes/Scene_remote_control.qml +++ /dev/null @@ -1,368 +0,0 @@ -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 - -Item { - id: scene_remote_control - objectName: "Scene_remote_control" - - Label { - id: dbus_api_status_text - text: "Unknown state of Service" - anchors.leftMargin: 10 + 5 + dbus_api_status_indicator.width - anchors.bottom: parent.bottom - anchors.bottomMargin: 10 - wrapMode: Text.WrapAtWordBoundaryOrAnywhere - verticalAlignment: Text.AlignVCenter - font.pointSize: 11 - fontSizeMode: Text.Fit - objectName: "dbus_api_status_text" - anchors.left: parent.left - - StatusIndicator { - id: dbus_api_status_indicator - width: height - height: parent.height - objectName: "dbus_api_status_indicator" - color: "#73d216" - anchors.verticalCenter: parent.verticalCenter - anchors.right: parent.left - anchors.rightMargin: 5 - active: false - } - } - - Label { - id: explain_function_label - text: qsTr("Please tell your remote support partner your access address and your access-PIN to let your partner connect to this computer.") - font.pixelSize: 18 - fontSizeMode: Text.VerticalFit - wrapMode: Text.WordWrap - anchors.left: parent.left - anchors.leftMargin: 10 - anchors.top: parent.top - anchors.topMargin: 10 - anchors.right: parent.right - anchors.rightMargin: 10 - horizontalAlignment: Text.AlignLeft - enabled: false - - color: Material.theme == Material.Light ? "#000000" : "#FFFFFF" - } - - Rectangle { - id: dbus_api_status_line - y: 379 - height: 1 - radius: 1 - anchors.right: parent.right - anchors.rightMargin: 10 - anchors.bottom: dbus_api_status_text.top - anchors.bottomMargin: 10 - opacity: 0.3 - gradient: Gradient { - GradientStop { - position: 0.391 - color: "#ffffff" - } - - GradientStop { - position: 0.975 - color: "#8b8b8b" - } - } - border.width: 1 - border.color: "#00000000" - anchors.left: parent.left - anchors.leftMargin: 10 - } - - Column { - id: column - spacing: 6 - anchors.right: parent.right - anchors.rightMargin: 10 - anchors.left: parent.left - anchors.leftMargin: 10 - anchors.bottom: dbus_api_status_line.top - anchors.bottomMargin: 10 - anchors.top: explain_function_label.bottom - anchors.topMargin: 10 - - Column { - id: url_group - width: parent.width - height: parent.height * 0.25 - spacing: 5 - - Label { - id: your_url_text - height: parent.height/2 - text: qsTr("Remote Support Address") - font.weight: Font.Bold - font.bold: true - verticalAlignment: Text.AlignBottom - horizontalAlignment: Text.AlignLeft - font.pointSize: 14 - fontSizeMode: Text.Fit - } - - TextEdit { - id: url_text - height: parent.height/2 - text: mainqmladaptor.url - anchors.rightMargin: 10 + copy_url_to_clipboard_button.width - anchors.right: parent.right - wrapMode: Text.WrapAtWordBoundaryOrAnywhere - anchors.leftMargin: 10 - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignLeft - font.pointSize: 15 - - readOnly: true - color: Material.foreground - selectByMouse: true - anchors.left: parent.left - - leftPadding: 5 - Rectangle { - radius: 5 - color: Material.theme == Material.Light ? "#F0F0F0" : "#383838" - height: url_text.height - // whole line + copy-into-clipboard button + some margin - width: url_text.width + copy_url_to_clipboard_button.width + 5 + 5 - x: 0; y: 0 - z: -1 - } - - Button { - id: copy_url_to_clipboard_button - width: copy_url_to_clipboard_image.width + 6 - height: copy_url_to_clipboard_image.height + 6 + 10 - anchors.verticalCenter: parent.verticalCenter - display: AbstractButton.IconOnly - anchors.leftMargin: 5 - anchors.left: url_text.right - highlighted: false - flat: true - - Image { - id: copy_url_to_clipboard_image - x: 0 - y: -26 - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - source: "../../images/into-clipboard.svg" - opacity: 0.65 - } - - onClicked: { - mainqmladaptor.handleCopyToClipboardButtonClick(url_text.text); - toast.show(qsTr("Copied access address into clipboard!"), "1000"); - } - - ToolTip.text: qsTr("Copy the access address into the clipboard") - hoverEnabled: true - - ToolTip.delay: 1000 - ToolTip.timeout: 5000 - ToolTip.visible: hovered - } - } - } - - Column { - id: session_id_group - width: parent.width - height: parent.height * 0.25 - spacing: 5 - - Label { - id: your_session_id_text - height: parent.height/2 - text: qsTr("Session-ID") - font.weight: Font.Bold - font.bold: true - anchors.right: parent.right - anchors.rightMargin: 0 - anchors.left: parent.left - anchors.leftMargin: 0 - font.pointSize: 14 - verticalAlignment: Text.AlignBottom - horizontalAlignment: Text.AlignLeft - fontSizeMode: Text.Fit - } - - TextEdit { - objectName: "session_id_text" - id: session_id_text - height: parent.height/2 - text: mainqmladaptor.session_id - font.letterSpacing: 10 - anchors.rightMargin: 10 + copy_session_id_to_clipboard_button.width - anchors.right: parent.right - font.pointSize: 15 - anchors.left: parent.left - anchors.leftMargin: 10 - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter - - leftPadding: 5 - Rectangle { - radius: 5 - color: Material.theme == Material.Light ? "#F0F0F0" : "#383838" - height: url_text.height - // whole line + copy-into-clipboard button + some margin - width: url_text.width + copy_url_to_clipboard_button.width + 5 + 5 - x: 0; y: 0 - z: -1 - } - - readOnly: true - color: Material.foreground - wrapMode: Text.WordWrap - selectByMouse: true - - Button { - id: copy_session_id_to_clipboard_button - width: copy_session_id_to_clipboard_image.width + 6 - height: copy_session_id_to_clipboard_image.height + 6 + 10 - anchors.verticalCenter: parent.verticalCenter - flat: true - display: AbstractButton.IconOnly - anchors.left: session_id_text.right - anchors.leftMargin: 5 - - Image { - id: copy_session_id_to_clipboard_image - anchors.horizontalCenter: parent.horizontalCenter - opacity: 0.65 - anchors.verticalCenter: parent.verticalCenter - source: "../../images/into-clipboard.svg" - fillMode: Image.PreserveAspectFit - } - - onClicked: { - mainqmladaptor.handleCopyToClipboardButtonClick(pin_text.text); - toast.show(qsTr("Copied session-ID into clipboard!"), "1000"); - } - - ToolTip.text: qsTr("Copy the session-ID into the clipboard") - hoverEnabled: true - - ToolTip.delay: 1000 - ToolTip.timeout: 5000 - ToolTip.visible: hovered - } - } - } - - Column { - id: pin_group - width: parent.width - height: parent.height * 0.25 - spacing: 5 - - Label { - id: your_pin_text - height: parent.height/2 - text: qsTr("Access-PIN") - font.weight: Font.Bold - font.bold: true - anchors.right: parent.right - anchors.rightMargin: 0 - anchors.left: parent.left - anchors.leftMargin: 0 - font.pointSize: 14 - verticalAlignment: Text.AlignBottom - horizontalAlignment: Text.AlignLeft - } - - TextEdit { - objectName: "pin_text" - id: pin_text - height: parent.height/2 - text: mainqmladaptor.pin - anchors.rightMargin: 10 + copy_pin_to_clipboard_button.width - anchors.right: parent.right - font.pointSize: 15 - anchors.left: parent.left - anchors.leftMargin: 10 - font.letterSpacing: 10 - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter - - leftPadding: 5 - Rectangle { - radius: 5 - color: Material.theme == Material.Light ? "#F0F0F0" : "#383838" - height: url_text.height - // whole line + copy-into-clipboard button + some margin - width: url_text.width + copy_url_to_clipboard_button.width + 5 + 5 - x: 0; y: 0 - z: -1 - } - - readOnly: true - color: Material.foreground - wrapMode: Text.WordWrap - selectByMouse: true - - Button { - id: copy_pin_to_clipboard_button - width: copy_pin_to_clipboard_image.width + 6 - height: copy_pin_to_clipboard_image.height + 6 + 10 - anchors.verticalCenter: parent.verticalCenter - flat: true - display: AbstractButton.IconOnly - anchors.left: pin_text.right - anchors.leftMargin: 5 - - Image { - id: copy_pin_to_clipboard_image - anchors.verticalCenter: parent.verticalCenter - opacity: 0.65 - anchors.horizontalCenter: parent.horizontalCenter - source: "../../images/into-clipboard.svg" - fillMode: Image.PreserveAspectFit - } - - onClicked: { - mainqmladaptor.handleCopyToClipboardButtonClick(pin_text.text); - toast.show(qsTr("Copied PIN into clipboard!"), "1000"); - } - - ToolTip.text: qsTr("Copy the pin into the clipboard") - hoverEnabled: true - - ToolTip.delay: 1000 - ToolTip.timeout: 5000 - ToolTip.visible: hovered - } - } - } - - } - - Button { - id: start_support_button - height: Math.min(50) - objectName: "start_support_button" - text: qsTr("Start remote support session") - anchors.rightMargin: column.anchors.leftMargin - anchors.bottom: dbus_api_status_line.top - anchors.bottomMargin: 10 - anchors.right: parent.right - checkable: true - - onClicked: mainqmladaptor.handleConnectButtonClick(checked); - } -} - -/*##^## Designer { - D{i:0;autoSize:true;height:480;width:640} -} - ##^##*/ diff --git a/src/session.cpp b/src/session.cpp index 32aca7d..a524afe 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -310,22 +310,36 @@ void Session::start_response(QJsonDocument *doc) { emit pinChanged(QString::number(pin)); emit urlChanged(url); emit sessionIDChanged(QString::number(session_id)); -} -void Session::stop() { - _dbus_api->stop_request(_host, this->getSessionID()); + started = true; - // Clear current variables - this->init_vars(); + // Ask status every 1000 millisecond - // Disable connect button to reduce spam. - // And don't enable it as long there is no status update. - // (Or something fails) - _main_gui->setConnectButtonEnabled(false); + QTimer *timer = new QTimer(this); + connect(timer, &QTimer::timeout, this, + QOverload<>::of(&Session::statusTimerEvent)); + timer->start(1000); + + qDebug() << "Successfully started a session."; + this->setStatus("start_session_success"); + + emit startSucceeded(); +} + +void Session::stop() { + if (started) + _dbus_api->stop_request(getHost(), getSessionID()); } void Session::stop_response(QJsonDocument *doc) { - Q_ASSERT(doc != nullptr); + // Q_ASSERT lets the program crash immediatly after method call + // when the session service is not started. + // Don't use Q_ASSERT(doc != nullptr); instead use: + if (doc == nullptr) { + emit stopFailed(tr("Can't connect to underlying session service! " + "Is the session service started?")); + return; + } QJsonObject jObject = doc->object(); QVariantMap mainMap = jObject.toVariantMap(); -- cgit v1.2.3 From 35343e5158ca441f8001c0a91685f4e93b53cb03 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Sun, 1 Aug 2021 02:22:57 +0200 Subject: Toast: Add a variety of new toast colors; Session complete rewrite; A lot of bugfixing; New available toast colors/types: ToastType.Standard, ToastType.Info, ToastType.Warning ToastType.Success, ToastType.Error --- src/Toast.qml | 26 +- src/ToastManager.qml | 19 +- src/main.qml | 4 +- src/main_qmladaptor.cpp | 84 ++---- src/main_qmladaptor.h | 63 ++-- src/scenes/add_server_wizard/Scene_step_1.qml | 1 + src/scenes/add_server_wizard/add_server_wizard.cpp | 17 +- src/scenes/add_server_wizard/add_server_wizard.h | 4 +- src/session.cpp | 320 +++++++-------------- src/session.h | 52 ++-- 10 files changed, 248 insertions(+), 342 deletions(-) (limited to 'src/main_qmladaptor.cpp') diff --git a/src/Toast.qml b/src/Toast.qml index 0de53a9..7a18dc8 100644 --- a/src/Toast.qml +++ b/src/Toast.qml @@ -27,6 +27,7 @@ import QtQuick 2.0 import QtQuick.Controls 2.0 import QtQuick.Controls.Material 2.3 +import rwa.toast.type 1.0 /** * adapted from StackOverflow: @@ -50,8 +51,11 @@ Control { * * @param {string} text Text to show * @param {real} duration Duration to show in milliseconds, defaults to 3000 + * @param {enum} type Type of toast. Available is: + * ToastType.Standard, ToastType.Info, ToastType.Warning + * ToastType.Success, ToastType.Error */ - function show(text, duration) { + function show(text, duration, type) { message.text = text; // checks if parameter was passed @@ -60,6 +64,23 @@ Control { } else { time = defaultTime; } + + if (typeof type !== "undefined" ) { + if (type === ToastType.ToastStandard) { + selectedColor = "#dcdedc"; + } else if (type === ToastType.ToastInfo) { + selectedColor = "#0d5eaf"; + } else if (type === ToastType.ToastSuccess) { + selectedColor = "#0daf36"; + } else if (type === ToastType.ToastWarning) { + selectedColor = "#efef2a"; + } else if (type === ToastType.ToastError) { + selectedColor = "#ed1212"; + } + } else { + selectedColor = "#dcdedc"; + } + animation.start(); } @@ -72,6 +93,7 @@ Control { id: root + property color selectedColor: "#dcdedc" readonly property real defaultTime: 3000 property real time: defaultTime readonly property real fadeTime: 300 @@ -88,6 +110,8 @@ Control { background: Rectangle { color: (Material.theme == Material.Dark) ? "#212121" : "#dcdedc" + border.color: selectedColor + border.width: 1.5 radius: margin } diff --git a/src/ToastManager.qml b/src/ToastManager.qml index 1acf8d5..2f1600f 100644 --- a/src/ToastManager.qml +++ b/src/ToastManager.qml @@ -42,9 +42,12 @@ ListView { * * @param {string} text Text to show * @param {real} duration Duration to show in milliseconds, defaults to 3000 + * @param {enum} type Type of toast. Available is: + * ToastType.Standard, ToastType.Info, ToastType.Warning + * ToastType.Success, ToastType.Error */ - function show(text, duration) { - model.insert(0, {text: text, duration: duration}); + function show(text, duration, type) { + model.insert(0, {text: text, duration: duration, type: type}); } /** @@ -71,11 +74,13 @@ ListView { delegate: Toast { Component.onCompleted: { - if (typeof duration === "undefined") { - show(text); - } - else { - show(text, duration); + if (typeof duration === "undefined" && typeof type === "undefined") { + show(text, ToastType.ToastStandard); + } else if (typeof duration === "undefined" && + typeof type !== "undefined") { + show(text, type); + } else { + show(text, duration, type); } } } diff --git a/src/main.qml b/src/main.qml index 4782f4b..af41dd1 100644 --- a/src/main.qml +++ b/src/main.qml @@ -107,8 +107,8 @@ ApplicationWindow { Connections { target: mainqmladaptor - onShowToastSignal: { - toast.show(text, durationMs) + function onShowToastSignal(text, durationMs, type) { + toast.show(text, durationMs, type) } } diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 5da0abb..d30243d 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -33,11 +33,22 @@ MainQMLAdaptor::MainQMLAdaptor(QObject *parent, QQmlApplicationEngine* engine, _engine = engine; _dbus_api = dbus_api; + _selected_rwa_host = nullptr; _rwaHostModel = new QList; QTimer *timer = new QTimer(this); - connect(timer, &QTimer::timeout, _dbus_api, QOverload<>::of(&DBusAPI::get_web_app_hosts_request)); + connect(timer, &QTimer::timeout, _dbus_api, + QOverload<>::of(&DBusAPI::get_web_app_hosts_request)); timer->start(10000); + + qmlRegisterUncreatableMetaObject( + Toast::staticMetaObject, // meta object created by Q_NAMESPACE macro + "rwa.toast.type", // import statement (can be any string) + 1, 0, // major and minor version of the import + "ToastType", // name in QML (does not have to match C++ name) + "Error: only enums" // error if someone tries to create a ToastType object + ); + } void MainQMLAdaptor::onRwaHostSelected(QString host_uuid) { @@ -55,11 +66,19 @@ void MainQMLAdaptor::onRwaHostSelected(QString host_uuid) { } Q_ASSERT(_host != nullptr); - qDebug() << "RWAHost was selected!" << _host->uuid() << "aka" << _host->alias(); + _selected_rwa_host = _host; + qDebug() << "RWAHost was selected!" << + _selected_rwa_host->uuid() << + "aka" << + _selected_rwa_host->alias(); setRWAHostSelected(true); } +RWAHost* MainQMLAdaptor::getSelectedRWAHost() { + return _selected_rwa_host; +} + void MainQMLAdaptor::setRWAHostModel(QList *rwa_hosts) { _rwaHostModel = rwa_hosts; emit rwaHostModelChanged(*rwa_hosts); @@ -108,7 +127,13 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { if (doc == nullptr) { setRWAHostSelected(false); - showToast(tr("Can't connect to underlying session service!"), 9800); + showToast(tr("Can't connect to underlying session service!"), + 9800, + Toast::ToastError); + + // Go to the first page on the stack. + main_content_pop(nullptr); + return; } @@ -308,59 +333,12 @@ bool MainQMLAdaptor::getShowMessageDialog() { return _showMessageDialog; } -bool MainQMLAdaptor::setStatusIndicator(bool active, QColor color) { - // Find item via 'objectName' - QQuickItem *scene_remote_control = _engine->rootObjects().at(0)->findChild("Scene_remote_control"); - QQuickItem *item = scene_remote_control->findChild("dbus_api_status_indicator"); - if (item) { - item->setProperty("active", active); - item->setProperty("color", color); - } else { - qWarning() << "Unable to find 'dbus_api_status_indicator' Item!"; - return false; - } - - return true; -} - -void MainQMLAdaptor::handleCopyToClipboardButtonClick(QString copy_data) { - QClipboard *clipboard = QApplication::clipboard(); - QString originalText = clipboard->text(); - clipboard->setText(copy_data); - qDebug() << "Copied into clipboard:" << copy_data; -} - -void MainQMLAdaptor::handleConnectButtonClick(bool checked) { - emit onConnectButtonClick(checked); -} - -void MainQMLAdaptor::setPin(QString pin) { - _pin = pin; - emit pinChanged(pin); -} -void MainQMLAdaptor::setURL(QString URL) { - _url = URL; - emit urlChanged(URL); -} -void MainQMLAdaptor::setSessionID(QString session_id) { - _session_id = session_id; - emit sessionIDChanged(session_id); -} -QString MainQMLAdaptor::getURL() { - return _url; -} -QString MainQMLAdaptor::getPin() { - return _pin; -} -QString MainQMLAdaptor::getSessionID() { - return _session_id; -} - void MainQMLAdaptor::onCloseHandler() { // Do cleanup things here... emit onCloseSignal(); } -void MainQMLAdaptor::showToast(QString text, uint durationMs) { - emit showToastSignal(text, QString::number(durationMs)); +void MainQMLAdaptor::showToast(QString text, uint durationMs, uint type) { + // type is actually Toast::ToastType + emit showToastSignal(text, QString::number(durationMs), type); } diff --git a/src/main_qmladaptor.h b/src/main_qmladaptor.h index 9a2f7c3..70c075b 100644 --- a/src/main_qmladaptor.h +++ b/src/main_qmladaptor.h @@ -39,17 +39,34 @@ #include "RWAHost.h" #include "DBusAPI.h" -class MainQMLAdaptor : public QObject +namespace Toast { + Q_NAMESPACE + enum ToastType { + ToastStandard, + ToastInfo, + ToastSuccess, + ToastWarning, + ToastError + }; + Q_ENUM_NS(ToastType) +} + +/*#include +namespace MyNamespace { + Q_NAMESPACE // required for meta object creation + enum EnStyle { + STYLE_RADIAL, + STYLE_ENVELOPE, + STYLE_FILLED + }; + Q_ENUM_NS(EnStyle) // register the enum in meta object data +}*/ + +class MainQMLAdaptor : public QObject { Q_OBJECT - // this makes url available as a QML property + // this makes rwaHostModel available as a QML property 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 - Q_PROPERTY(QString pin READ getPin WRITE setPin NOTIFY pinChanged) - // this makes session_id available as a QML property - Q_PROPERTY(QString session_id READ getSessionID WRITE setSessionID NOTIFY sessionIDChanged) // this makes showMessageDialog available as a QML property Q_PROPERTY(bool showMessageDialog READ getShowMessageDialog NOTIFY showMessageDialogChanged) // this makes showMessageDialogTitle available as a QML property @@ -85,27 +102,19 @@ signals: void minimizeWindow(); void showWindow(); - void onConnectButtonClick(bool checked); - - void pinChanged(QString pin); - void urlChanged(QString URL); - void sessionIDChanged(QString session_id); - void rwaHostModelChanged(QList); void onCloseSignal(); - void showToastSignal(QString text, QString durationMs); + void showToastSignal(QString text, QString durationMs, int type); protected: - QString _url; - QString _pin; - QString _session_id; DBusAPI *_dbus_api; QList *_rwaHostModel; private: - QQmlApplicationEngine* _engine; + QQmlApplicationEngine *_engine; + RWAHost *_selected_rwa_host; bool _showMessageDialog; QString _messageDialogTitle; @@ -113,27 +122,23 @@ private: QMessageBox::Icon _messageDialogIcon; public slots: - void handleCopyToClipboardButtonClick(QString copy_data); - void handleConnectButtonClick(bool checked); - void get_web_app_hosts_response(QJsonDocument *doc); - void setPin(QString pin); - 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(); // No pointer because QML doesn't // like this type much with pointer QList getRWAHostModel(); + RWAHost *getSelectedRWAHost(); + void onRwaHostSelected(QString host_uuid); void onCloseHandler(); - void showToast(QString text, uint durationMs = 3000); + // arg type is actually Toast::ToastType + void showToast(QString text, + uint durationMs = 3000, + uint type = 0); }; diff --git a/src/scenes/add_server_wizard/Scene_step_1.qml b/src/scenes/add_server_wizard/Scene_step_1.qml index e57f8a4..bfbe2ae 100644 --- a/src/scenes/add_server_wizard/Scene_step_1.qml +++ b/src/scenes/add_server_wizard/Scene_step_1.qml @@ -3,6 +3,7 @@ import QtQuick.Window 2.2 import QtQuick.Extras 1.4 import QtQuick.Controls 2.2 import QtQuick.Controls.Material 2.3 +import rwa.toast.type 1.0 /*! * This .qml file is a Scene which can be loaded through for diff --git a/src/scenes/add_server_wizard/add_server_wizard.cpp b/src/scenes/add_server_wizard/add_server_wizard.cpp index 9b67ebc..caac344 100644 --- a/src/scenes/add_server_wizard/add_server_wizard.cpp +++ b/src/scenes/add_server_wizard/add_server_wizard.cpp @@ -47,7 +47,7 @@ void Add_Server_wizard::processStep1(QString host_url, QString host_alias) { if(host_alias == "" || host_url == "") { QString reason = tr("Both textfields can't be empty!"); - emit step1Failed(reason); + emit step1Failed(reason, Toast::ToastType::ToastWarning); qDebug().noquote() << reason; return; } @@ -57,7 +57,7 @@ void Add_Server_wizard::processStep1(QString host_url, QString host_alias) { void Add_Server_wizard::processStep2() { qDebug() << "Processing Step 2 with args: No Args."; - emit step2Failed(tr("The features you expected here are not yet implemented.")); + emit step2Failed(tr("The features you expected here are not yet implemented."), Toast::ToastType::ToastWarning); // Just show placeholder scene now. emit step2Success(); } @@ -72,7 +72,9 @@ void Add_Server_wizard::add_web_app_host_response(QJsonDocument *doc) { // Don't use Q_ASSERT(doc != nullptr); instead use: if (doc == nullptr) { _main_gui->setRWAHostSelected(false); - _main_gui->showToast(tr("Can't connect to underlying session service!"), 9800); + _main_gui->showToast(tr("Can't connect to underlying session service!"), + 9800, + Toast::ToastType::ToastError); return; } @@ -90,25 +92,32 @@ void Add_Server_wizard::add_web_app_host_response(QJsonDocument *doc) { } else { qCritical().noquote() << tr("An error occured while adding a new host!"); + uint toast_type = Toast::ToastType::ToastStandard; QString reason = tr("An error occured while adding a new host!"); QString type = mainMap["type"].toString(); + if(type == "connection"){ reason = tr("Couldn't connect to the specified host!"); + toast_type = Toast::ToastType::ToastError; qCritical().noquote() << reason; } else if (type == "duplicate") { reason = tr("The specified host was already added!"); + toast_type = Toast::ToastType::ToastWarning; qCritical().noquote() << reason; } else if (type == "invalid_url") { reason = tr("The specified host address is not valid!"); + toast_type = Toast::ToastType::ToastWarning; qCritical().noquote() << reason; } else if (type == "permission_denied") { reason = tr("The specified host address does not grant access!"); + toast_type = Toast::ToastType::ToastError; qCritical().noquote() << reason; } else if (type == "unsupported_server") { reason = tr("The specified host address is not supported!"); + toast_type = Toast::ToastType::ToastError; qCritical().noquote() << reason; } - emit step1Failed(reason); + emit step1Failed(reason, toast_type); return; } diff --git a/src/scenes/add_server_wizard/add_server_wizard.h b/src/scenes/add_server_wizard/add_server_wizard.h index 03af824..dc205d1 100644 --- a/src/scenes/add_server_wizard/add_server_wizard.h +++ b/src/scenes/add_server_wizard/add_server_wizard.h @@ -47,9 +47,9 @@ private: signals: void step1Success(); - void step1Failed(QString reason); + void step1Failed(QString reason, uint toast_type); void step2Success(); - void step2Failed(QString reason); + void step2Failed(QString reason, uint toast_type); public slots: void processStep1(QString host_url, QString host_alias); diff --git a/src/session.cpp b/src/session.cpp index a524afe..25a8512 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -26,194 +26,60 @@ #include "session.h" -Session::Session(QObject *parent, MainQMLAdaptor* main_gui, RWAHost *host) : QObject(parent) { - Q_ASSERT(main_gui != nullptr); +Session::Session(DBusAPI *dbus_api, RWAHost *host) : QObject() { Q_ASSERT(host != nullptr); + Q_ASSERT(dbus_api != nullptr); - _dbus_api = new DBusAPI(); - _main_gui = main_gui; + _dbus_api = dbus_api; _host = host; - // QML -> MainQMLAdaptor::handleConnectButtonClick --onConnectButtonClick--> this::handleConnectButtonClick - QObject::connect(_main_gui, - SIGNAL(onConnectButtonClick(bool)), - this, - SLOT(handleConnectButtonClick(bool))); - - // session::setPin --pinChanged--> MainQMLAdaptor::setPin --pinChanged--> QML - QObject::connect(this, - SIGNAL(pinChanged(QString)), - main_gui, - SLOT(setPin(QString))); - - // session::setURL --urlChanged--> MainQMLAdaptor::setURL --urlChanged--> QML - QObject::connect(this, - SIGNAL(urlChanged(QString)), - main_gui, - SLOT(setURL(QString))); - - // session::setSessionID --sessionIDChanged--> MainQMLAdaptor::setSessionID --sessionIDChanged--> QML - QObject::connect(this, - SIGNAL(sessionIDChanged(QString)), - main_gui, - SLOT(setSessionID(QString))); - - // QML -> MainQMLAdaptor::onCloseHandler --onCloseSignal--> session::onCloseHandler - QObject::connect(main_gui, - SIGNAL(onCloseSignal()), - this, - SLOT(onCloseHandler())); - - // _dbus_api --sessionStartResponse-> this.start_response() - QObject::connect(_dbus_api, - SIGNAL(serviceStartResponse(QJsonDocument*)), - this, - SLOT(start_response(QJsonDocument*))); - - // _dbus_api --sessionStopResponse-> this.stop_response() - QObject::connect(_dbus_api, - SIGNAL(serviceStopResponse(QJsonDocument*)), - this, - SLOT(stop_response(QJsonDocument*))); - - // _dbus_api --sessionStatusResponse-> this.status_response() - QObject::connect(_dbus_api, - SIGNAL(serviceStatusResponse(QJsonDocument*)), - this, - SLOT(status_response(QJsonDocument*))); - - this->init_vars(); -} - -void Session::statusTimerEvent() { - qDebug() << "Status timer event got triggered just now."; - this->status(); -} - -void Session::init_vars() { setPin("-----"); setSessionID("-----"); setURL(tr("Not available yet")); setStatus("unknown"); - - _main_gui->setConnectButtonChecked(false); - _main_gui->setConnectButtonEnabled(true); - _main_gui->setStatusIndicator(false); - - _minimizedBefore = false; + started = false; } -QString Session::getStatus() { - return _status; +Session::~Session() { + qDebug().noquote() << QString("Session #'%0' on host '%1' will be deconstructed.") + .arg(getSessionID()) + .arg(getHost()->alias()); + stop(); + disconnect(); } -QString Session::getURL() { - return _url; -} - -QString Session::getSessionID() { - return QString(_session_id); -} +void Session::statusTimerEvent() { + qDebug() << "Status timer event triggered"; -QString Session::getPin() { - return _pin; + refresh_status(); } -bool Session::isSessionAliveOrRunning(QString status) { - if (status == "running" || status == "active") { +bool Session::isSessionAliveOrRunning() { + if (getStatus() == "running" || getStatus() == "active") { return true; } else { return false; } } -void Session::minimizeWindow() { - if (!_minimizedBefore) { - qDebug() << "Minimizing window now..."; - emit _main_gui->minimizeWindow(); - _minimizedBefore = true; - } +RWAHost* Session::getHost() { + return _host; } -void Session::setStatus(QString status) { - _status = status; +QString Session::getStatus() { + return _status; +} - QString guiString = tr("Unknown state of service"); - _main_gui->setStatusIndicator(false); - - qDebug() << "setStatus(): Setting status to " << status; - - if (status == "running") { - /* Session is running but no one is connected yet */ - guiString = tr("Remote Support session is ready to be connected to"); - _main_gui->setStatusIndicator(true, QColor(255, 255, 0, 127)); - } else if (status == "dead") { - /* Session died */ - guiString = tr("Remote Support session was stopped ungracefully"); - - // Clear current variables - this->init_vars(); - _main_gui->setStatusIndicator(true, QColor(255, 0, 0, 127)); - - emit _main_gui->showWindow(); - - _main_gui->showToast(tr("Remote Support session was " - "stopped ungracefully"), 5000); - } else if (status == "stopped") { - /* Session is stopped */ - guiString = tr("Remote Support session was stopped"); - - // Clear current variables - this->init_vars(); - - emit _main_gui->showWindow(); - - _main_gui->showToast(tr("Remote Support session was stopped"), 5000); - } else if (status == "active") { - /* Partner is connected */ - QTimer::singleShot(1000, this, &Session::minimizeWindow); - guiString = tr("Your partner is connected to the Remote Support session"); - _main_gui->setStatusIndicator(true, QColor(0, 255, 0, 127)); - - } else if (status == "waiting_start_request_answer") { - /* When pressing on start button display following message while waiting */ - guiString = tr("Trying to reach session service..."); - } else if (status == "start_session_error") { - /* Session couldn't be started */ - guiString = tr("Remote Support session couldn't be started!"); - _main_gui->setStatusIndicator(true, QColor(255, 0, 0, 127)); - - _main_gui->showToast(tr("An error occured while trying " - "to start a session!"), 5000); - } else if (status == "start_session_success") { - /* Session successfully started */ - guiString = tr("Remote Support session successfully started!"); - _main_gui->setStatusIndicator(true, QColor(255, 255, 0, 127)); - - _main_gui->showToast(QString(tr("Session was started " - "on '%0' successfully")) - .arg(_host->alias())); - } else if (status == "status_session_error") { - /* Session's status couldn't be refreshed */ - _main_gui->showToast(tr("Session status could not be refreshed!"), 5000); - guiString = tr("Session status could not be refreshed!") + "\n" + - tr("remote support partner could still be connected!"); - _main_gui->setStatusIndicator(true, QColor(255, 0, 0, 127)); - - emit _main_gui->showWindow(); - } else if (status == "stop_session_error") { - /* Session couldn't be stopped */ - _main_gui->showToast(tr("Session could not be stopped!"), 5000); - guiString = tr("Session could not be stopped!") + "\n" + - tr("remote support partner could still be connected!"); - _main_gui->setStatusIndicator(true, QColor(255, 0, 0, 127)); - - emit _main_gui->showWindow(); - } +QString Session::getURL() { + return _url; +} - _main_gui->setStatus(guiString); +QString Session::getSessionID() { + return _session_id; +} - emit statusChanged(_status); +QString Session::getPin() { + return _pin; } void Session::setURL(QString url) { @@ -231,49 +97,62 @@ void Session::setPin(QString pin) { emit pinChanged(pin); } -void Session::handleConnectButtonClick(bool checked) { - qDebug() << "-----Connect button handler-----" << - "\nCurrent session #" << this->getSessionID(); - - // Stopping even if nothing is running - _dbus_api->stop_request(_host, this->getSessionID()); +void Session::setHost(RWAHost *host) { + _host = host; + emit hostChanged(host); +} - if (checked) { - // Start the Session again - _dbus_api->start_request(_host); - } - qDebug() << "-----\\Connect button handler-----"; +void Session::setStatus(QString status) { + _status = status; + emit statusChanged(status); } void Session::start() { - // Disable connect button to reduce spam. - // And don't enable it as long there is no status update. - // (Or something fails) - _main_gui->setConnectButtonEnabled(false); - this->setStatus("waiting_start_request_answer"); - _dbus_api->start_request(_host); } void Session::start_response(QJsonDocument *doc) { - Q_ASSERT(doc != nullptr); + // Q_ASSERT lets the program crash immediatly after method call + // when the session service is not started. + // Don't use Q_ASSERT(doc != nullptr); instead use: + if (doc == nullptr) { + emit startFailed(tr("Can't connect to underlying session service! " + "Is the session service started?")); + return; + } // Get the QJsonObject QJsonObject jObject = doc->object(); QVariantMap mainMap = jObject.toVariantMap(); // Status of request - QString request_status = mainMap["status"].toString(); - if (request_status == "success") { - qDebug() << "Successfully started a Session."; - this->setStatus("start_session_success"); - - // Immediately ask for the status of the session - QTimer::singleShot(0, this, &Session::statusTimerEvent); - } else { - qCritical() << "An error occured while creating a new session!"; - this->init_vars(); - this->setStatus("start_session_error"); + QString status = mainMap["status"].toString(); + if (status != "success") { + QString type = mainMap["type"].toString(); + QString error_message = tr("An error occured while creating a new session!"); + + if (type == "multiple") { + // TODO: Ask to stop other session via a message dialog. + error_message = tr("The session service is configured " + "to not support multiple sessions " + "and there is already a session running."); + } else if (type == "connection") { + error_message = tr("Couldn't connect to host '%0'.") + .arg(getHost()->alias()); + } else if (type == "host_not_found") { + error_message = tr("The RWA host '%0' couldn't be found.") + .arg(getHost()->alias()); + } else if (type == "permission_denid") { + error_message = tr("The RWA host '%0' doesn't grant access.") + .arg(getHost()->alias()); + } else if (type == "unsupported_server") { + error_message = tr("The RWA host '%0' is not supported.") + .arg(getHost()->alias()); + } + + setStatus("start_session_error"); + qCritical().noquote() << error_message; + emit startFailed(error_message); return; } @@ -285,23 +164,25 @@ void Session::start_response(QJsonDocument *doc) { // PIN long long pin = mainMap["pin"].toLongLong(&ok); - this->setPin(QString::number(pin)); // Sanity Check if(ok == false){ - qErrnoWarning("Unable to parse out of dbus answer!"); - init_vars(); + QString error_message = "Unable to parse into longo long out of dbus answer!"; + qCritical().noquote() << error_message; + emit startFailed(error_message); return; } + this->setPin(QString::number(pin)); // session_id = remote support id from the rwa-server long long session_id = mainMap["session_id"].toLongLong(); - this->setSessionID(QString::number(session_id)); // Sanity Check if(ok == false){ - qErrnoWarning("Unable to parse out of dbus answer!"); - init_vars(); + QString error_message = "Unable to parse into long long out of dbus answer!"; + qCritical().noquote() << error_message; + emit startFailed(error_message); return; } + this->setSessionID(QString::number(session_id)); qDebug() << "Got session_id:" << session_id << "\nGot url:" << url << @@ -347,39 +228,44 @@ void Session::stop_response(QJsonDocument *doc) { QString new_status = mainMap["status"].toString(); qDebug() << "stop_response() retrieved json. Status now:" << new_status; - // Clear current variables - this->init_vars(); + started = false; - // But the status indicator should display that the Session has stopped this->setStatus(new_status); + + emit stopSucceeded(); } void Session::status() { - _dbus_api->status_request(_host, this->getSessionID()); + _dbus_api->status_request(getHost(), this->getSessionID()); +} + +void Session::refresh_status() { + _dbus_api->refresh_status_request(getHost(), this->getSessionID()); } void Session::status_response(QJsonDocument *doc) { - Q_ASSERT(doc != nullptr); + // Q_ASSERT lets the program crash immediatly after method call, + // when the session service is not started. + // Don't use Q_ASSERT(doc != nullptr); instead use: + if (doc == nullptr) { + if (!_emitted_status_error_already) { + emit statusFailed(tr("Can't connect to underlying session service! " + "Is the session service started?")); + + _emitted_status_error_already = true; + } + + return; + } + + _emitted_status_error_already = false; QJsonObject jObject = doc->object(); QVariantMap mainMap = jObject.toVariantMap(); QString new_status = mainMap["status"].toString(); qDebug() << "status_response() retrieved json. Status:" << new_status; - // Enable (dis)connect button - _main_gui->setConnectButtonEnabled(true); - - this->setStatus(new_status); - - if (this->isSessionAliveOrRunning(new_status)) { - qDebug() << "Session is still alive or running. -> Restarting the status timer."; - - // Ask status every 1000 millisecond - QTimer::singleShot(1000, this, &Session::statusTimerEvent); - } -} + setStatus(new_status); -void Session::onCloseHandler() { - // To cleanup things here - _dbus_api->stop_request(_host, this->getSessionID()); + emit statusSucceeded(); } diff --git a/src/session.h b/src/session.h index 5935919..e1c924f 100644 --- a/src/session.h +++ b/src/session.h @@ -33,48 +33,41 @@ #include #include -#include "main_qmladaptor.h" #include "RWAHost.h" #include "DBusAPI.h" -class Session : public QObject -{ +class Session : public QObject { Q_OBJECT - // this makes status available as a QML property - Q_PROPERTY(QString status READ getStatus NOTIFY statusChanged) - // this makes session_id available as a QML property - Q_PROPERTY(QString session_id READ getSessionID NOTIFY sessionIDChanged) - // this makes url available as a QML property - Q_PROPERTY(QString url READ getURL NOTIFY urlChanged) - // this makes pin available as a QML property - Q_PROPERTY(QString pin READ getPin NOTIFY pinChanged) public: - explicit Session(QObject *parent, MainQMLAdaptor *main_gui = nullptr, + explicit Session(DBusAPI *dbus_api = nullptr, RWAHost *host = nullptr); + ~Session(); QString getStatus(); QString getURL(); QString getSessionID(); QString getPin(); + RWAHost* getHost(); void setStatus(QString status); void setURL(QString url); void setSessionID(QString session_id); void setPin(QString pin); + void setHost(RWAHost *host); void start(); void stop(); void status(); void refresh_status(); -protected: - QString _status; - void statusTimerEvent(); - void init_vars(); + bool started; private: - MainQMLAdaptor *_main_gui; + void statusTimerEvent(); + + bool _emitted_status_error_already; + QString _status; RWAHost *_host; DBusAPI *_dbus_api; @@ -82,25 +75,30 @@ private: QString _url; QString _pin; - // Returns true if a session is somewhat usable (Running, Alive, etc..) - bool isSessionAliveOrRunning(QString status); - bool _minimizedBefore = false; - void minimizeWindow(); + signals: - void finished(); void statusChanged(QString); void sessionIDChanged(QString); void urlChanged(QString); void pinChanged(QString); + void hostChanged(RWAHost*); + + void startFailed(QString error_message); + void stopFailed(QString error_message); + void statusFailed(QString error_message); + + void startSucceeded(); + void stopSucceeded(); + void statusSucceeded(); public slots: - void handleConnectButtonClick(bool checked); - void onCloseHandler(); + // Returns true if a session is somewhat usable (Running, Alive, etc..) + bool isSessionAliveOrRunning(); - void start_response(QJsonDocument *doc); - void stop_response(QJsonDocument *doc); - void status_response(QJsonDocument *doc); + void start_response(QJsonDocument*); + void stop_response(QJsonDocument*); + void status_response(QJsonDocument*); }; #endif // SESSION_H -- cgit v1.2.3 From 0e8f295868e826b89114b55a0aa360cb30d7494f Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Sun, 1 Aug 2021 02:36:42 +0200 Subject: add_server_wizard/add_server_wizard -> add_rwahost_wizard/add_rwahost_wizard --- qml.qrc | 6 +- rwa-support-desktopapp.pro | 4 +- src/main.cpp | 10 +- src/main.qml | 2 +- src/main_qmladaptor.cpp | 4 +- src/scenes/add_rwahost_wizard/Scene_step_1.qml | 282 +++++++++++++++++++++ .../add_rwahost_wizard/add_rwahost_wizard.cpp | 124 +++++++++ src/scenes/add_rwahost_wizard/add_rwahost_wizard.h | 61 +++++ src/scenes/add_server_wizard/Scene_step_1.qml | 282 --------------------- src/scenes/add_server_wizard/add_server_wizard.cpp | 124 --------- src/scenes/add_server_wizard/add_server_wizard.h | 61 ----- src/scenes/remote_control/remote_control_manager.h | 4 +- 12 files changed, 482 insertions(+), 482 deletions(-) create mode 100644 src/scenes/add_rwahost_wizard/Scene_step_1.qml create mode 100644 src/scenes/add_rwahost_wizard/add_rwahost_wizard.cpp create mode 100644 src/scenes/add_rwahost_wizard/add_rwahost_wizard.h delete mode 100644 src/scenes/add_server_wizard/Scene_step_1.qml delete mode 100644 src/scenes/add_server_wizard/add_server_wizard.cpp delete mode 100644 src/scenes/add_server_wizard/add_server_wizard.h (limited to 'src/main_qmladaptor.cpp') diff --git a/qml.qrc b/qml.qrc index 35e9142..04ee201 100644 --- a/qml.qrc +++ b/qml.qrc @@ -29,9 +29,9 @@ src/scenes/Scene_settings.qml src/scenes/Scene_placeholder.qml src/scenes/Scene_no_server_available.qml - src/scenes/add_server_wizard/add_server_wizard.cpp - src/scenes/add_server_wizard/add_server_wizard.h - src/scenes/add_server_wizard/Scene_step_1.qml + src/scenes/add_rwahost_wizard/add_rwahost_wizard.cpp + src/scenes/add_rwahost_wizard/add_rwahost_wizard.h + src/scenes/add_rwahost_wizard/Scene_step_1.qml src/scenes/remote_control/remote_control_manager.cpp src/scenes/remote_control/remote_control_manager.h src/scenes/remote_control/Scene_remote_control.qml diff --git a/rwa-support-desktopapp.pro b/rwa-support-desktopapp.pro index f9a05bf..96ecec3 100644 --- a/rwa-support-desktopapp.pro +++ b/rwa-support-desktopapp.pro @@ -52,7 +52,7 @@ SOURCES += src/main.cpp \ src/RWAHost.cpp \ src/DBusAPI.cpp \ src/scenes/remote_control/remote_control_manager.cpp \ - src/scenes/add_server_wizard/add_server_wizard.cpp + src/scenes/add_rwahost_wizard/add_rwahost_wizard.cpp HEADERS += src/RWADBusAdaptor.h \ src/main_qmladaptor.h \ @@ -63,7 +63,7 @@ HEADERS += src/RWADBusAdaptor.h \ src/RWAHost.h \ src/DBusAPI.h \ src/scenes/remote_control/remote_control_manager.h \ - src/scenes/add_server_wizard/add_server_wizard.h + src/scenes/add_rwahost_wizard/add_rwahost_wizard.h TRANSLATIONS += locales/main_en.ts \ locales/de_DE.ts \ diff --git a/src/main.cpp b/src/main.cpp index ff5d2a8..e29c8db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,7 +39,7 @@ #include "DBusAPI.h" #include "RWADBusAdaptor.cpp" #include "session.h" -#include "scenes/add_server_wizard/add_server_wizard.h" +#include "scenes/add_rwahost_wizard/add_rwahost_wizard.h" #include "scenes/remote_control/remote_control_manager.h" #include "RWAHostModel.h" #include "RWAHost.h" @@ -119,14 +119,14 @@ int main(int argc, char *argv[]) { main_gui.data(), SLOT(onRwaHostSelected(QString))); - // Make 'add_server_wizard' available to QML - QScopedPointer wizard ( - new Add_Server_wizard(&app, + // Make 'AddRWAHostWizard' available to QML + QScopedPointer wizard ( + new AddRWAHostWizard(&app, main_gui.data(), dbus_api.data()) ); engine.rootContext()-> - setContextProperty("add_server_wizard", wizard.data()); + setContextProperty("add_rwahost_wizard", wizard.data()); // Make 'remote_control_manager' available to QML QScopedPointer remote_mngr ( diff --git a/src/main.qml b/src/main.qml index af41dd1..a622c18 100644 --- a/src/main.qml +++ b/src/main.qml @@ -295,7 +295,7 @@ ApplicationWindow { } ListItem { text: " " + qsTr("Add RWA-Server") - scene_url: "scenes/add_server_wizard/Scene_step_1.qml" + scene_url: "scenes/add_rwahost_wizard/Scene_step_1.qml" onListItemClick: { header_text.text = qsTr("Server addition wizard") if (inPortrait) sidebar_drawer.close() diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index d30243d..688b993 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -290,9 +290,9 @@ void MainQMLAdaptor::main_content_replace(QString scene) { QVariant to_cast = main_content->property("currentItem"); QObject *obj = qvariant_cast(to_cast); if (obj) { - QString scene_add_server_wizard = "Scene_step_1"; + QString scene_add_rwahost_wizard = "Scene_step_1"; if (!(scene.contains(obj->objectName()) || - scene_add_server_wizard.contains(obj->objectName()))) { + scene_add_rwahost_wizard.contains(obj->objectName()))) { QVariant arg = QVariant::fromValue(scene); if (!QMetaObject::invokeMethod(window, "main_content_replace", Q_ARG(QVariant, arg))) { diff --git a/src/scenes/add_rwahost_wizard/Scene_step_1.qml b/src/scenes/add_rwahost_wizard/Scene_step_1.qml new file mode 100644 index 0000000..873e0fd --- /dev/null +++ b/src/scenes/add_rwahost_wizard/Scene_step_1.qml @@ -0,0 +1,282 @@ +import QtQuick 2.9 +import QtQuick.Window 2.2 +import QtQuick.Extras 1.4 +import QtQuick.Controls 2.2 +import QtQuick.Controls.Material 2.3 +import rwa.toast.type 1.0 + +/*! + * This .qml file is a Scene which can be loaded through for + * example a StackView (main_content in main.qml). + */ + +Item { + id: scene_server_wizard_step_1 + objectName: "Scene_step_1" + + Connections { + target: add_rwahost_wizard + function onStep1Success() { + // Go onto the first page of the stack. + main_content_pop(null) + mainqmladaptor.showToast(qsTr("Successfully added remote web app host."), + 5000, + ToastType.ToastSuccess); + } + } + + Connections { + target: add_rwahost_wizard + function onStep1Failed(reason, toast_type) { + mainqmladaptor.showToast(reason, + 5000, + toast_type) + } + } + + Rectangle { + id: rectangle + anchors.fill: parent + color: Material.background + + Button { + id: next_step1_button + text: qsTr("Next Step") + anchors.bottom: parent.bottom + anchors.bottomMargin: 15 + anchors.right: parent.right + anchors.rightMargin: 15 + + onClicked: { + add_rwahost_wizard.processStep1(host_url.text, host_alias.text) + } + } + + /*Text { + color: Material.foreground + id: step_indicator + + text: qsTr("Step 1") + anchors.leftMargin: 15 + anchors.top: parent.top + anchors.topMargin: 15 + font.pointSize: 21 + wrapMode: Text.WordWrap + + font.bold: true + horizontalAlignment: Text.AlignHCenter + anchors.left: parent.left + anchors.margins: 5 + }*/ + + Text { + color: Material.foreground + id: explaining_text + + text: qsTr("Please input the address for the "+ + "remote web app server which you want "+ + "to connect to.\nIf you don't know "+ + "what this means, ask your local "+ + "administrator about it please.\nBefore you can "+ + "start any remote sessions you will have to "+ + "be approved for remote support.") + font.pointSize: 12 + anchors.right: parent.right + anchors.rightMargin: 15 + anchors.leftMargin: 15 + anchors.top: parent.top //step_indicator.bottom + anchors.topMargin: 15 + wrapMode: Text.WordWrap + + anchors.left: parent.left + anchors.margins: 5 + } + + TextField { + id: host_url + selectByMouse: true + placeholderText: qsTr("http://example.com:8000") + + font.pixelSize: 16 + color: Material.foreground + anchors.topMargin: 30 + + padding: 15 + topPadding: 15 + + anchors.top: explaining_text.bottom + anchors.left: parent.left + anchors.leftMargin: 15 + anchors.right: parent.right + anchors.margins: 30 + + MouseArea { + anchors.fill: parent + hoverEnabled: true + onHoveredChanged: { + if (containsMouse) { + host_url_background.state = "hovered" + } else if (!host_url.focus) { + host_url_background.state = "unhovered" + } + } + onClicked: { + host_url.forceActiveFocus(); + } + } + + onFocusChanged: { + host_url_background.state = host_url.focus ? "hovered" : "unhovered" + } + + background: Rectangle { + id: host_url_background + color: Material.background + border.color: Material.foreground + border.width: 1 + radius: 4 + + states: [ + State { + name: "hovered" + PropertyChanges { + target: host_url_background + border.color: "#0178EF" + } + }, + State { + name: "unhovered" + PropertyChanges { + target: host_url_background + border.color: Material.foreground + } + } + ] + transitions: [ + Transition { + from: "*" + to: "*" + PropertyAnimation { + property: "border.color" + duration: 100 + easing.type: Easing.Linear + } + } + ] + + Text { + color: Material.foreground + text: qsTr("RWA host address") + anchors.left: parent.left + anchors.leftMargin: 15 + anchors.verticalCenterOffset: - host_url.height / 2 + anchors.verticalCenter: parent.verticalCenter + leftPadding: 5 + + Rectangle { + color: Material.background + width: parent.width + 5 + 3 + height: parent.height + z: -1 + } + } + } + } + + TextField { + id: host_alias + selectByMouse: true + placeholderText: qsTr("My example host") + + font.pixelSize: 16 + color: Material.foreground + + padding: 15 + topPadding: 15 + + anchors.top: host_url.bottom + anchors.topMargin: 30 + anchors.left: parent.left + anchors.leftMargin: 15 + anchors.right: parent.right + anchors.margins: 30 + + MouseArea { + anchors.fill: parent + hoverEnabled: true + onHoveredChanged: { + if (containsMouse) { + host_alias_background.state = "hovered" + } else if (!host_alias.focus) { + host_alias_background.state = "unhovered" + } + } + onClicked: { + host_alias.forceActiveFocus(); + } + } + + onFocusChanged: { + host_alias_background.state = host_alias.focus ? "hovered" : "unhovered" + } + + background: Rectangle { + id: host_alias_background + color: Material.background + border.color: Material.foreground + border.width: 1 + radius: 4 + + states: [ + State { + name: "hovered" + PropertyChanges { + target: host_alias_background + border.color: "#0178EF" + } + }, + State { + name: "unhovered" + PropertyChanges { + target: host_alias_background + border.color: Material.foreground + } + } + ] + transitions: [ + Transition { + from: "*" + to: "*" + PropertyAnimation { + property: "border.color" + duration: 100 + easing.type: Easing.Linear + } + } + ] + + Text { + color: Material.foreground + text: qsTr("RWA host alias") + anchors.left: parent.left + anchors.leftMargin: 15 + anchors.verticalCenterOffset: - host_alias.height / 2 + anchors.verticalCenter: parent.verticalCenter + leftPadding: 5 + + Rectangle { + color: Material.background + width: parent.width + 5 + 3 + height: parent.height + z: -1 + } + } + } + } + } +} + +/*##^## Designer { + D{i:0;autoSize:true;height:480;width:640}D{i:4;anchors_width:351;anchors_x:279} +} + ##^##*/ diff --git a/src/scenes/add_rwahost_wizard/add_rwahost_wizard.cpp b/src/scenes/add_rwahost_wizard/add_rwahost_wizard.cpp new file mode 100644 index 0000000..7adbdf9 --- /dev/null +++ b/src/scenes/add_rwahost_wizard/add_rwahost_wizard.cpp @@ -0,0 +1,124 @@ +/* + * This file is part of Remote Support Desktop + * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp + * Copyright 2021 Daniel Teichmann + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "add_rwahost_wizard.h" +#include "../../RWADBusAdaptor.h" +#include "../../RWAHost.h" + +AddRWAHostWizard::AddRWAHostWizard(QObject *parent, + MainQMLAdaptor *main_gui, DBusAPI *dbus_api) : QObject(parent) { + Q_ASSERT(main_gui != nullptr); + Q_ASSERT(dbus_api != nullptr); + + _dbus_api = dbus_api; + _main_gui = main_gui; + + // _dbus_api --serviceAddWebAppHostResponse-> this.add_web_app_host_response() + QObject::connect(_dbus_api, + SIGNAL(serviceAddWebAppHostResponse(QJsonDocument*)), + this, + SLOT(add_web_app_host_response(QJsonDocument*))); +} + +void AddRWAHostWizard::processStep1(QString host_url, QString host_alias) { + qDebug() << "Processing Step 1 with args: " << host_url << host_alias; + + if(host_alias == "" || host_url == "") { + QString reason = tr("Both textfields can't be empty!"); + emit step1Failed(reason, Toast::ToastType::ToastWarning); + qDebug().noquote() << reason; + return; + } + + return add_server(host_url, host_alias); +} + +void AddRWAHostWizard::processStep2() { + qDebug() << "Processing Step 2 with args: No Args."; + emit step2Failed(tr("The features you expected here are not yet implemented."), Toast::ToastType::ToastWarning); + // Just show placeholder scene now. + emit step2Success(); +} + +void AddRWAHostWizard::add_server(QString host_url, QString host_alias) { + _dbus_api->add_web_app_host_request(host_url, host_alias); +} + +void AddRWAHostWizard::add_web_app_host_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) { + _main_gui->setRWAHostSelected(false); + _main_gui->showToast(tr("Can't connect to underlying session service!"), + 9800, + Toast::ToastType::ToastError); + return; + } + + // Get the QJsonObject + QJsonObject jObject = doc->object(); + QVariantMap mainMap = jObject.toVariantMap(); + + // Status of request + QString request_status = mainMap["status"].toString(); + if (request_status == "success") { + _dbus_api->get_web_app_hosts_request(); + + qInfo() << "Successfully added a new RWAHost."; + emit step1Success(); + } else { + qCritical().noquote() << tr("An error occured while adding a new host!"); + + uint toast_type = Toast::ToastType::ToastStandard; + QString reason = tr("An error occured while adding a new host!"); + QString type = mainMap["type"].toString(); + + if(type == "connection"){ + reason = tr("Couldn't connect to the specified host!"); + toast_type = Toast::ToastType::ToastError; + qCritical().noquote() << reason; + } else if (type == "duplicate") { + reason = tr("The specified host was already added!"); + toast_type = Toast::ToastType::ToastWarning; + qCritical().noquote() << reason; + } else if (type == "invalid_url") { + reason = tr("The specified host address is not valid!"); + toast_type = Toast::ToastType::ToastWarning; + qCritical().noquote() << reason; + } else if (type == "permission_denied") { + reason = tr("The specified host address does not grant access!"); + toast_type = Toast::ToastType::ToastError; + qCritical().noquote() << reason; + } else if (type == "unsupported_server") { + reason = tr("The specified host address is not supported!"); + toast_type = Toast::ToastType::ToastError; + qCritical().noquote() << reason; + } + emit step1Failed(reason, toast_type); + + return; + } +} diff --git a/src/scenes/add_rwahost_wizard/add_rwahost_wizard.h b/src/scenes/add_rwahost_wizard/add_rwahost_wizard.h new file mode 100644 index 0000000..f019be1 --- /dev/null +++ b/src/scenes/add_rwahost_wizard/add_rwahost_wizard.h @@ -0,0 +1,61 @@ +/* + * This file is part of Remote Support Desktop + * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp + * Copyright 2021 Daniel Teichmann + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef ADD_RWAHOST_WIZARD_H +#define ADD_RWAHOST_WIZARD_H + +#include + +#include "../../RWADBusAdaptor.h" +#include "../../DBusAPI.h" +#include "../../main_qmladaptor.h" + +class AddRWAHostWizard : public QObject +{ + Q_OBJECT +public: + explicit AddRWAHostWizard(QObject *parent = nullptr, + MainQMLAdaptor *main_gui = nullptr, + DBusAPI *dbus_api = nullptr); + void add_server(QString host_url, QString host_alias); + +private: + DBusAPI *_dbus_api; + MainQMLAdaptor *_main_gui; + +signals: + void step1Success(); + void step1Failed(QString reason, uint toast_type); + void step2Success(); + void step2Failed(QString reason, uint toast_type); + +public slots: + void processStep1(QString host_url, QString host_alias); + void processStep2(); + + void add_web_app_host_response(QJsonDocument *doc); +}; + +#endif // ADD_SERVER_WIZARD_H diff --git a/src/scenes/add_server_wizard/Scene_step_1.qml b/src/scenes/add_server_wizard/Scene_step_1.qml deleted file mode 100644 index bfbe2ae..0000000 --- a/src/scenes/add_server_wizard/Scene_step_1.qml +++ /dev/null @@ -1,282 +0,0 @@ -import QtQuick 2.9 -import QtQuick.Window 2.2 -import QtQuick.Extras 1.4 -import QtQuick.Controls 2.2 -import QtQuick.Controls.Material 2.3 -import rwa.toast.type 1.0 - -/*! - * This .qml file is a Scene which can be loaded through for - * example a StackView (main_content in main.qml). - */ - -Item { - id: scene_server_wizard_step_1 - objectName: "Scene_step_1" - - Connections { - target: add_server_wizard - function onStep1Success() { - // Go onto the first page of the stack. - main_content_pop(null) - mainqmladaptor.showToast(qsTr("Successfully added remote web app host."), - 5000, - ToastType.ToastSuccess); - } - } - - Connections { - target: add_server_wizard - function onStep1Failed(reason, toast_type) { - mainqmladaptor.showToast(reason, - 5000, - toast_type) - } - } - - Rectangle { - id: rectangle - anchors.fill: parent - color: Material.background - - Button { - id: next_step1_button - text: qsTr("Next Step") - anchors.bottom: parent.bottom - anchors.bottomMargin: 15 - anchors.right: parent.right - anchors.rightMargin: 15 - - onClicked: { - add_server_wizard.processStep1(host_url.text, host_alias.text) - } - } - - /*Text { - color: Material.foreground - id: step_indicator - - text: qsTr("Step 1") - anchors.leftMargin: 15 - anchors.top: parent.top - anchors.topMargin: 15 - font.pointSize: 21 - wrapMode: Text.WordWrap - - font.bold: true - horizontalAlignment: Text.AlignHCenter - anchors.left: parent.left - anchors.margins: 5 - }*/ - - Text { - color: Material.foreground - id: explaining_text - - text: qsTr("Please input the address for the "+ - "remote web app server which you want "+ - "to connect to.\nIf you don't know "+ - "what this means, ask your local "+ - "administrator about it please.\nBefore you can "+ - "start any remote sessions you will have to "+ - "be approved for remote support.") - font.pointSize: 12 - anchors.right: parent.right - anchors.rightMargin: 15 - anchors.leftMargin: 15 - anchors.top: parent.top //step_indicator.bottom - anchors.topMargin: 15 - wrapMode: Text.WordWrap - - anchors.left: parent.left - anchors.margins: 5 - } - - TextField { - id: host_url - selectByMouse: true - placeholderText: qsTr("http://example.com:8000") - - font.pixelSize: 16 - color: Material.foreground - anchors.topMargin: 30 - - padding: 15 - topPadding: 15 - - anchors.top: explaining_text.bottom - anchors.left: parent.left - anchors.leftMargin: 15 - anchors.right: parent.right - anchors.margins: 30 - - MouseArea { - anchors.fill: parent - hoverEnabled: true - onHoveredChanged: { - if (containsMouse) { - host_url_background.state = "hovered" - } else if (!host_url.focus) { - host_url_background.state = "unhovered" - } - } - onClicked: { - host_url.forceActiveFocus(); - } - } - - onFocusChanged: { - host_url_background.state = host_url.focus ? "hovered" : "unhovered" - } - - background: Rectangle { - id: host_url_background - color: Material.background - border.color: Material.foreground - border.width: 1 - radius: 4 - - states: [ - State { - name: "hovered" - PropertyChanges { - target: host_url_background - border.color: "#0178EF" - } - }, - State { - name: "unhovered" - PropertyChanges { - target: host_url_background - border.color: Material.foreground - } - } - ] - transitions: [ - Transition { - from: "*" - to: "*" - PropertyAnimation { - property: "border.color" - duration: 100 - easing.type: Easing.Linear - } - } - ] - - Text { - color: Material.foreground - text: qsTr("RWA host address") - anchors.left: parent.left - anchors.leftMargin: 15 - anchors.verticalCenterOffset: - host_url.height / 2 - anchors.verticalCenter: parent.verticalCenter - leftPadding: 5 - - Rectangle { - color: Material.background - width: parent.width + 5 + 3 - height: parent.height - z: -1 - } - } - } - } - - TextField { - id: host_alias - selectByMouse: true - placeholderText: qsTr("My example host") - - font.pixelSize: 16 - color: Material.foreground - - padding: 15 - topPadding: 15 - - anchors.top: host_url.bottom - anchors.topMargin: 30 - anchors.left: parent.left - anchors.leftMargin: 15 - anchors.right: parent.right - anchors.margins: 30 - - MouseArea { - anchors.fill: parent - hoverEnabled: true - onHoveredChanged: { - if (containsMouse) { - host_alias_background.state = "hovered" - } else if (!host_alias.focus) { - host_alias_background.state = "unhovered" - } - } - onClicked: { - host_alias.forceActiveFocus(); - } - } - - onFocusChanged: { - host_alias_background.state = host_alias.focus ? "hovered" : "unhovered" - } - - background: Rectangle { - id: host_alias_background - color: Material.background - border.color: Material.foreground - border.width: 1 - radius: 4 - - states: [ - State { - name: "hovered" - PropertyChanges { - target: host_alias_background - border.color: "#0178EF" - } - }, - State { - name: "unhovered" - PropertyChanges { - target: host_alias_background - border.color: Material.foreground - } - } - ] - transitions: [ - Transition { - from: "*" - to: "*" - PropertyAnimation { - property: "border.color" - duration: 100 - easing.type: Easing.Linear - } - } - ] - - Text { - color: Material.foreground - text: qsTr("RWA host alias") - anchors.left: parent.left - anchors.leftMargin: 15 - anchors.verticalCenterOffset: - host_alias.height / 2 - anchors.verticalCenter: parent.verticalCenter - leftPadding: 5 - - Rectangle { - color: Material.background - width: parent.width + 5 + 3 - height: parent.height - z: -1 - } - } - } - } - } -} - -/*##^## Designer { - D{i:0;autoSize:true;height:480;width:640}D{i:4;anchors_width:351;anchors_x:279} -} - ##^##*/ diff --git a/src/scenes/add_server_wizard/add_server_wizard.cpp b/src/scenes/add_server_wizard/add_server_wizard.cpp deleted file mode 100644 index caac344..0000000 --- a/src/scenes/add_server_wizard/add_server_wizard.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * This file is part of Remote Support Desktop - * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp - * Copyright 2021 Daniel Teichmann - * SPDX-License-Identifier: GPL-2.0-or-later - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "add_server_wizard.h" -#include "../../RWADBusAdaptor.h" -#include "../../RWAHost.h" - -Add_Server_wizard::Add_Server_wizard(QObject *parent, - MainQMLAdaptor *main_gui, DBusAPI *dbus_api) : QObject(parent) { - Q_ASSERT(main_gui != nullptr); - Q_ASSERT(dbus_api != nullptr); - - _dbus_api = dbus_api; - _main_gui = main_gui; - - // _dbus_api --serviceAddWebAppHostResponse-> this.add_web_app_host_response() - QObject::connect(_dbus_api, - SIGNAL(serviceAddWebAppHostResponse(QJsonDocument*)), - this, - SLOT(add_web_app_host_response(QJsonDocument*))); -} - -void Add_Server_wizard::processStep1(QString host_url, QString host_alias) { - qDebug() << "Processing Step 1 with args: " << host_url << host_alias; - - if(host_alias == "" || host_url == "") { - QString reason = tr("Both textfields can't be empty!"); - emit step1Failed(reason, Toast::ToastType::ToastWarning); - qDebug().noquote() << reason; - return; - } - - return add_server(host_url, host_alias); -} - -void Add_Server_wizard::processStep2() { - qDebug() << "Processing Step 2 with args: No Args."; - emit step2Failed(tr("The features you expected here are not yet implemented."), Toast::ToastType::ToastWarning); - // Just show placeholder scene now. - emit step2Success(); -} - -void Add_Server_wizard::add_server(QString host_url, QString host_alias) { - _dbus_api->add_web_app_host_request(host_url, host_alias); -} - -void Add_Server_wizard::add_web_app_host_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) { - _main_gui->setRWAHostSelected(false); - _main_gui->showToast(tr("Can't connect to underlying session service!"), - 9800, - Toast::ToastType::ToastError); - return; - } - - // Get the QJsonObject - QJsonObject jObject = doc->object(); - QVariantMap mainMap = jObject.toVariantMap(); - - // Status of request - QString request_status = mainMap["status"].toString(); - if (request_status == "success") { - _dbus_api->get_web_app_hosts_request(); - - qInfo() << "Successfully added a new RWAHost."; - emit step1Success(); - } else { - qCritical().noquote() << tr("An error occured while adding a new host!"); - - uint toast_type = Toast::ToastType::ToastStandard; - QString reason = tr("An error occured while adding a new host!"); - QString type = mainMap["type"].toString(); - - if(type == "connection"){ - reason = tr("Couldn't connect to the specified host!"); - toast_type = Toast::ToastType::ToastError; - qCritical().noquote() << reason; - } else if (type == "duplicate") { - reason = tr("The specified host was already added!"); - toast_type = Toast::ToastType::ToastWarning; - qCritical().noquote() << reason; - } else if (type == "invalid_url") { - reason = tr("The specified host address is not valid!"); - toast_type = Toast::ToastType::ToastWarning; - qCritical().noquote() << reason; - } else if (type == "permission_denied") { - reason = tr("The specified host address does not grant access!"); - toast_type = Toast::ToastType::ToastError; - qCritical().noquote() << reason; - } else if (type == "unsupported_server") { - reason = tr("The specified host address is not supported!"); - toast_type = Toast::ToastType::ToastError; - qCritical().noquote() << reason; - } - emit step1Failed(reason, toast_type); - - return; - } -} diff --git a/src/scenes/add_server_wizard/add_server_wizard.h b/src/scenes/add_server_wizard/add_server_wizard.h deleted file mode 100644 index dc205d1..0000000 --- a/src/scenes/add_server_wizard/add_server_wizard.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of Remote Support Desktop - * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp - * Copyright 2021 Daniel Teichmann - * SPDX-License-Identifier: GPL-2.0-or-later - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef ADD_SERVER_WIZARD_H -#define ADD_SERVER_WIZARD_H - -#include - -#include "../../RWADBusAdaptor.h" -#include "../../DBusAPI.h" -#include "../../main_qmladaptor.h" - -class Add_Server_wizard : public QObject -{ - Q_OBJECT -public: - explicit Add_Server_wizard(QObject *parent = nullptr, - MainQMLAdaptor *main_gui = nullptr, - DBusAPI *dbus_api = nullptr); - void add_server(QString host_url, QString host_alias); - -private: - DBusAPI *_dbus_api; - MainQMLAdaptor *_main_gui; - -signals: - void step1Success(); - void step1Failed(QString reason, uint toast_type); - void step2Success(); - void step2Failed(QString reason, uint toast_type); - -public slots: - void processStep1(QString host_url, QString host_alias); - void processStep2(); - - void add_web_app_host_response(QJsonDocument *doc); -}; - -#endif // ADD_SERVER_WIZARD_H diff --git a/src/scenes/remote_control/remote_control_manager.h b/src/scenes/remote_control/remote_control_manager.h index 6f2fbdb..4554724 100644 --- a/src/scenes/remote_control/remote_control_manager.h +++ b/src/scenes/remote_control/remote_control_manager.h @@ -1,5 +1,5 @@ -#ifndef REMOTECONTROLMANAGER_H -#define REMOTECONTROLMANAGER_H +#ifndef REMOTE_CONTROL_MANAGER_H +#define REMOTE_CONTROL_MANAGER_H #include -- cgit v1.2.3