From 11787ea278bc6ff6d5bc797b597df3f26e2ec9b4 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Tue, 6 Jul 2021 19:55:13 +0200 Subject: Introduce DBusAPI and RWAHost classes --- src/scenes/add_server_wizard/add_server_wizard.cpp | 133 ++++++++++++--------- src/scenes/add_server_wizard/add_server_wizard.h | 44 +++++-- 2 files changed, 110 insertions(+), 67 deletions(-) (limited to 'src/scenes') diff --git a/src/scenes/add_server_wizard/add_server_wizard.cpp b/src/scenes/add_server_wizard/add_server_wizard.cpp index f8d4b7b..bd1dd3c 100644 --- a/src/scenes/add_server_wizard/add_server_wizard.cpp +++ b/src/scenes/add_server_wizard/add_server_wizard.cpp @@ -1,100 +1,121 @@ -#include "add_server_wizard.h" -#include "../../RWADBusAdaptor.h" +/* + * 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 #include #include -Add_Server_wizard::Add_Server_wizard(QObject *parent) : QObject(parent) { - _initDBus(); +#include "add_server_wizard.h" +#include "../../RWADBusAdaptor.h" +#include "../../RWAHost.h" +Add_Server_wizard::Add_Server_wizard(QObject *parent) : QObject(parent) { + _dbus_api = new DBusAPI(); + // _dbus_api --serviceAddWebAppHostResponse-> this.add_web_app_host_response() + QObject::connect(_dbus_api, + SIGNAL(serviceAddWebAppHostResponse(QJsonDocument*)), + this, + SLOT(add_web_app_host_response(QJsonDocument*))); } -bool Add_Server_wizard::processStep1(QString host_url) { +void Add_Server_wizard::processStep1(QString host_url) { qDebug() << "Processing Step 1 with args: " << host_url; if(host_url == "") { emit step1Failed(tr("This field can't be empty!")); - return false; + return; } - return _add_server(host_url); + return add_server(host_url); } -bool Add_Server_wizard::processStep2() { +void Add_Server_wizard::processStep2() { qDebug() << "Processing Step 2 with args: No Args."; - emit step2Failed(tr("The feature you expected here are not yet implemented.")); + emit step2Failed(tr("The features you expected here are not yet implemented.")); // Just show placeholder scene now. emit step2Success(); - return false; } -bool Add_Server_wizard::_add_server(QString host_url) { - return _add_web_app_host(host_url); +void Add_Server_wizard::add_server(QString host_url) { + _dbus_api->add_web_app_host_request(host_url); } -void Add_Server_wizard::_initDBus() { - if (!QDBusConnection::sessionBus().isConnected()) { - qCritical() << "Cannot connect to the D-Bus session bus."; - } - - // Create DBus object - _dbus_rwa = new OrgArcticaProjectRWASupportSessionServiceInterface("org.ArcticaProject.RWASupportSessionService", "/RWASupportSessionService", - QDBusConnection::sessionBus(), this->parent()); - - qDebug("Initialized DBus object!"); -} - -bool Add_Server_wizard::_add_web_app_host(QString host_url) { - qDebug() << "Requesting D-Bus session service to add a new host: " << host_url; - - // Make an asynchrous 'add_web_app_host' call (Response will be sent to '_add_web_app_host_dbus_replied') - QDBusPendingCall async = _dbus_rwa->asyncCall("add_web_app_host", host_url); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); +void Add_Server_wizard::add_web_app_host_response(QJsonDocument *doc) { + // Get the QJsonObject + QJsonObject jObject = doc->object(); + QVariantMap mainMap = jObject.toVariantMap(); - QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - this, SLOT(_add_web_app_host_dbus_replied(QDBusPendingCallWatcher*))); + // Status of request + QString request_status = mainMap["status"].toString(); + if (request_status == "success") { + // Building host_object + QJsonObject host_object = jObject.value(QString("host")).toObject(); - return true; -} + QString host_uuid = host_object["uuid"].toString(); + QString host_alias = host_object["alias"].toString(); + QString host_url = host_object["url"].toString(); -void Add_Server_wizard::_add_web_app_host_dbus_replied(QDBusPendingCallWatcher *call) { - QString result = ""; + if (host_url == "" || host_uuid == "") { + // This two values are required and can't be omitted. + QString reason = tr("Response of D-Bus service lacks necessary host object."); + qCritical().noquote() << tr("An error occured while adding a new host:") + << reason; + emit step1Failed(reason); - QDBusPendingReply reply = *call; - if (reply.isError()) { - qDebug() << "D-Bus 'add_web_app_host' request failed, this was the reply:"; - qDebug() << reply.error(); - return; - } else { - result = reply.argumentAt<0>(); - } - call->deleteLater(); + return; + } - qDebug() << "Raw JSON from starting session is:" << result.toUtf8().replace('"', ""); - QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8()); + 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; + } - // Get the QJsonObject - QJsonObject jObject = doc.object(); - QVariantMap mainMap = jObject.toVariantMap(); + // Now built RWAHost object. + QScopedPointer rwa_host (new RWAHost(host_uuid, host_alias, host_url)); - // Status of request - QString request_status = mainMap["status"].toString(); - if (request_status == "success") { - qDebug() << "Successfully started a Session."; + qInfo() << "Successfully added a new RWAHost."; emit step1Success(); } else { - qCritical() << "An error occured while adding a new host!"; + qCritical().noquote() << tr("An error occured while adding a new host!"); - QString reason = "An error occured while adding a new host!"; + 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!"); + qCritical().noquote() << reason; } else if (type == "duplicate") { reason = tr("The specified host was already added!"); + qCritical().noquote() << reason; } else if (type == "invalid_url") { reason = tr("The specified host address is not valid!"); + qCritical().noquote() << reason; } emit step1Failed(reason); + + return; } } diff --git a/src/scenes/add_server_wizard/add_server_wizard.h b/src/scenes/add_server_wizard/add_server_wizard.h index 1feec9b..554f6af 100644 --- a/src/scenes/add_server_wizard/add_server_wizard.h +++ b/src/scenes/add_server_wizard/add_server_wizard.h @@ -1,21 +1,45 @@ +/* + * 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 "../../RWADBusAdaptor.h" #include +#include "../../RWADBusAdaptor.h" +#include "../../DBusAPI.h" + class Add_Server_wizard : public QObject { Q_OBJECT public: explicit Add_Server_wizard(QObject *parent = nullptr); + void add_server(QString host_url); private: - bool _add_server(QString host_url); - bool _add_web_app_host(QString host_url); - - OrgArcticaProjectRWASupportSessionServiceInterface *_dbus_rwa; - void _initDBus(); + DBusAPI *_dbus_api; signals: void step1Success(); @@ -24,12 +48,10 @@ signals: void step2Failed(QString reason); public slots: - bool processStep1(QString host_url); - bool processStep2(); + void processStep1(QString host_url); + void processStep2(); - void _add_web_app_host_dbus_replied(QDBusPendingCallWatcher *call); - //void _get_web_app_hosts_dbus_replied(QDBusPendingCallWatcher *call); - //void _remove_web_app_host_dbus_replied(QDBusPendingCallWatcher *call); + void add_web_app_host_response(QJsonDocument *doc); }; #endif // ADD_SERVER_WIZARD_H -- cgit v1.2.3 From 61b4ee3b8f1d4c5d85b7a561551167fa41b12400 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Tue, 6 Jul 2021 20:04:48 +0200 Subject: Tidy up some debug statements or long strings --- src/scenes/Scene_placeholder.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/scenes') diff --git a/src/scenes/Scene_placeholder.qml b/src/scenes/Scene_placeholder.qml index a5ceac9..29e15a9 100644 --- a/src/scenes/Scene_placeholder.qml +++ b/src/scenes/Scene_placeholder.qml @@ -43,7 +43,7 @@ Item { anchors.right: parent.right wrapMode: Text.WordWrap - text: qsTr("The feature you expected here are not yet implemented.") + text: qsTr("The features you expected here are not yet implemented.") horizontalAlignment: Text.AlignHCenter } } -- cgit v1.2.3 From d0d6402c46b3fc074002849f4e8071407d06df4f Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Tue, 6 Jul 2021 20:21:46 +0200 Subject: Drop add_server_wizard/Scene_step_2.qml --- src/scenes/add_server_wizard/Scene_step_1.qml | 4 +- src/scenes/add_server_wizard/Scene_step_2.qml | 70 --------------------------- 2 files changed, 2 insertions(+), 72 deletions(-) delete mode 100644 src/scenes/add_server_wizard/Scene_step_2.qml (limited to 'src/scenes') diff --git a/src/scenes/add_server_wizard/Scene_step_1.qml b/src/scenes/add_server_wizard/Scene_step_1.qml index e76462a..a80e4f4 100644 --- a/src/scenes/add_server_wizard/Scene_step_1.qml +++ b/src/scenes/add_server_wizard/Scene_step_1.qml @@ -15,9 +15,9 @@ Item { Connections { target: add_server_wizard onStep1Success: { - //main_content_push("scenes/add_server_wizard/Scene_step_2.qml", StackView.Transition) + // Go onto the first page of the stack. main_content_pop(null) - mainqmladaptor.showToast(qsTr("Successfully added server address."), 5000); + mainqmladaptor.showToast(qsTr("Successfully added remote web app host."), 5000); } } diff --git a/src/scenes/add_server_wizard/Scene_step_2.qml b/src/scenes/add_server_wizard/Scene_step_2.qml deleted file mode 100644 index 5cfbe46..0000000 --- a/src/scenes/add_server_wizard/Scene_step_2.qml +++ /dev/null @@ -1,70 +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 - -/*! - 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_2 - objectName: "Scene_step_2" - - Connections { - target: add_server_wizard - onStep2Success: { - main_content_pop(null, StackView.Transition) - //main_content_replace("scenes/Scene_placeholder.qml", StackView.Transition) - } - } - - Connections { - target: add_server_wizard - onStep2Failed: { - mainqmladaptor.showToast(reason, 3000); - } - } - - Rectangle { - id: rectangle - anchors.fill: parent - color: Material.background - - Text { - color: Material.foreground - id: title - - text: qsTr("Step 2") - font.pointSize: 18 - wrapMode: Text.WordWrap - - font.bold: true - horizontalAlignment: Text.AlignHCenter - anchors.verticalCenter: parent.verticalCenter - anchors.left: parent.left - anchors.right: parent.right - anchors.margins: 5 - } - - Button { - id: next_step2_button - text: qsTr("Next Step") - anchors.bottom: parent.bottom - anchors.bottomMargin: 10 - anchors.right: parent.right - anchors.rightMargin: 10 - - onClicked: { - add_server_wizard.processStep2() - } - } - } -} - -/*##^## Designer { - D{i:0;autoSize:true;height:480;width:640} -} - ##^##*/ -- 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. --- src/scenes/add_server_wizard/add_server_wizard.cpp | 10 +++++----- src/scenes/add_server_wizard/add_server_wizard.h | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src/scenes') 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(); -- 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' --- src/scenes/Scene_no_server_available.qml | 70 ++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/scenes/Scene_no_server_available.qml (limited to 'src/scenes') 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 0f73c7ff3f8a84bcacf077644d6a199301f58945 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Thu, 8 Jul 2021 15:54:20 +0200 Subject: User can decide on host_alias now. --- src/scenes/add_server_wizard/Scene_step_1.qml | 105 +++++++++++++++++++-- src/scenes/add_server_wizard/add_server_wizard.cpp | 43 ++------- src/scenes/add_server_wizard/add_server_wizard.h | 7 +- 3 files changed, 112 insertions(+), 43 deletions(-) (limited to 'src/scenes') diff --git a/src/scenes/add_server_wizard/Scene_step_1.qml b/src/scenes/add_server_wizard/Scene_step_1.qml index a80e4f4..abd761d 100644 --- a/src/scenes/add_server_wizard/Scene_step_1.qml +++ b/src/scenes/add_server_wizard/Scene_step_1.qml @@ -42,11 +42,11 @@ Item { anchors.rightMargin: 15 onClicked: { - add_server_wizard.processStep1(host_url.text) + add_server_wizard.processStep1(host_url.text, host_alias.text) } } - Text { + /*Text { color: Material.foreground id: step_indicator @@ -61,7 +61,7 @@ Item { horizontalAlignment: Text.AlignHCenter anchors.left: parent.left anchors.margins: 5 - } + }*/ Text { color: Material.foreground @@ -74,12 +74,12 @@ Item { "administrator about it please.\nBefore you can "+ "start any remote sessions you will have to "+ "be approved for remote support.") - font.pointSize: 13 + font.pointSize: 12 anchors.right: parent.right anchors.rightMargin: 15 anchors.leftMargin: 15 - anchors.top: step_indicator.bottom - anchors.topMargin: 30 + anchors.top: parent.top //step_indicator.bottom + anchors.topMargin: 15 wrapMode: Text.WordWrap anchors.left: parent.left @@ -160,7 +160,7 @@ Item { Text { color: Material.foreground - text: qsTr("RWA-server address") + text: qsTr("RWA host address") anchors.left: parent.left anchors.leftMargin: 15 anchors.verticalCenterOffset: - host_url.height / 2 @@ -176,6 +176,97 @@ Item { } } } + + 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 + } + } + } + } } } diff --git a/src/scenes/add_server_wizard/add_server_wizard.cpp b/src/scenes/add_server_wizard/add_server_wizard.cpp index d06108c..09db898 100644 --- a/src/scenes/add_server_wizard/add_server_wizard.cpp +++ b/src/scenes/add_server_wizard/add_server_wizard.cpp @@ -40,15 +40,17 @@ Add_Server_wizard::Add_Server_wizard(QObject *parent, MainQMLAdaptor *main_gui) SLOT(add_web_app_host_response(QJsonDocument*))); } -void Add_Server_wizard::processStep1(QString host_url) { - qDebug() << "Processing Step 1 with args: " << host_url; +void Add_Server_wizard::processStep1(QString host_url, QString host_alias) { + qDebug() << "Processing Step 1 with args: " << host_url << host_alias; - if(host_url == "") { - emit step1Failed(tr("This field can't be empty!")); + if(host_alias == "" || host_url == "") { + QString reason = tr("Both textfields can't be empty!"); + emit step1Failed(reason); + qDebug().noquote() << reason; return; } - return add_server(host_url); + return add_server(host_url, host_alias); } void Add_Server_wizard::processStep2() { @@ -58,8 +60,8 @@ void Add_Server_wizard::processStep2() { emit step2Success(); } -void Add_Server_wizard::add_server(QString host_url) { - _dbus_api->add_web_app_host_request(host_url); +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) { @@ -70,32 +72,7 @@ void Add_Server_wizard::add_web_app_host_response(QJsonDocument *doc) { // Status of request QString request_status = mainMap["status"].toString(); if (request_status == "success") { - // Building host_object - QJsonObject host_object = jObject.value(QString("host")).toObject(); - - 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("Response of D-Bus service lacks necessary host object."); - 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. - QScopedPointer rwa_host (new RWAHost(host_uuid, host_alias, host_url)); - _main_gui->addRWAHost(rwa_host.data()); + _dbus_api->get_web_app_hosts_request(); 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 e4d62df..03af824 100644 --- a/src/scenes/add_server_wizard/add_server_wizard.h +++ b/src/scenes/add_server_wizard/add_server_wizard.h @@ -37,8 +37,9 @@ class Add_Server_wizard : public QObject Q_OBJECT public: explicit Add_Server_wizard(QObject *parent = nullptr, - MainQMLAdaptor *main_gui = nullptr); - void add_server(QString host_url); + MainQMLAdaptor *main_gui = nullptr, + DBusAPI *dbus_api = nullptr); + void add_server(QString host_url, QString host_alias); private: DBusAPI *_dbus_api; @@ -51,7 +52,7 @@ signals: void step2Failed(QString reason); public slots: - void processStep1(QString host_url); + void processStep1(QString host_url, QString host_alias); void processStep2(); void add_web_app_host_response(QJsonDocument *doc); -- 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/scenes/add_server_wizard/add_server_wizard.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/scenes') 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 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/scenes/add_server_wizard/add_server_wizard.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/scenes') 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 7b1fa0b22598305b8c50fda543131d2d14d1df63 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Mon, 12 Jul 2021 12:48:28 +0200 Subject: Don't crash on startup if the session service isn't reachable. --- src/scenes/add_server_wizard/add_server_wizard.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/scenes') diff --git a/src/scenes/add_server_wizard/add_server_wizard.cpp b/src/scenes/add_server_wizard/add_server_wizard.cpp index e398b19..9b67ebc 100644 --- a/src/scenes/add_server_wizard/add_server_wizard.cpp +++ b/src/scenes/add_server_wizard/add_server_wizard.cpp @@ -67,6 +67,15 @@ void Add_Server_wizard::add_server(QString host_url, QString 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); + return; + } + // Get the QJsonObject QJsonObject jObject = doc->object(); QVariantMap mainMap = jObject.toVariantMap(); -- 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/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 ++++++++++----- 5 files changed, 24 insertions(+), 7 deletions(-) (limited to 'src/scenes') 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 0a48722a1ddeccfc89f1812c44b7582358671697 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Sun, 1 Aug 2021 02:01:35 +0200 Subject: Introducing remote_control_manager.(h, cpp) The remote_control_manager class takes care of the GUI and the creation, deletion and maintaining of session objects. --- src/scenes/remote_control/Scene_remote_control.qml | 382 +++++++++++++++ .../remote_control/remote_control_manager.cpp | 511 +++++++++++++++++++++ src/scenes/remote_control/remote_control_manager.h | 78 ++++ 3 files changed, 971 insertions(+) create mode 100644 src/scenes/remote_control/Scene_remote_control.qml create mode 100644 src/scenes/remote_control/remote_control_manager.cpp create mode 100644 src/scenes/remote_control/remote_control_manager.h (limited to 'src/scenes') diff --git a/src/scenes/remote_control/Scene_remote_control.qml b/src/scenes/remote_control/Scene_remote_control.qml new file mode 100644 index 0000000..dc152ef --- /dev/null +++ b/src/scenes/remote_control/Scene_remote_control.qml @@ -0,0 +1,382 @@ +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_remote_control + objectName: "Scene_remote_control" + + Label { + id: dbus_api_status_text + text: qsTr("Unknown state of session service.") + anchors.leftMargin: 10 + 5 + dbus_api_status_indicator.width + anchors.bottom: parent.bottom + anchors.bottomMargin: 10 + wrapMode: Text.WordWrap + anchors.rightMargin: 10 + verticalAlignment: Text.AlignVCenter + font.pointSize: 11 + fontSizeMode: Text.Fit + objectName: "dbus_api_status_text" + anchors.left: parent.left + anchors.right: parent.right + + StatusIndicator { + id: dbus_api_status_indicator + width: height + height: 20 + 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.") + wrapMode: Text.WordWrap + font.pixelSize: 18 + anchors.topMargin: 10 + anchors.leftMargin: 10 + anchors.rightMargin: 10 + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + horizontalAlignment: Text.AlignLeft + + color: Material.theme == Material.Light ? "#000000" : "#FFFFFF" + } + + Rectangle { + id: dbus_api_status_line + 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: remote_control_manager.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: { + remote_control_manager.handleCopyToClipboardButtonClick(url_text.text); + toast.show(qsTr("Copied access address into clipboard!"), + "5000", + mainqmladaptor.ToastInfo); + } + + ToolTip.text: qsTr("Copy the access address into the clipboard") + hoverEnabled: true + + ToolTip.delay: 600 + 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: remote_control_manager.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: session_id_text.height + // whole line + copy-into-clipboard button + some margin + width: session_id_text.width + copy_session_id_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: { + remote_control_manager.handleCopyToClipboardButtonClick(session_id_text.text); + toast.show(qsTr("Copied session-ID into clipboard!"), + "5000", + mainqmladaptor.ToastInfo); + } + + ToolTip.text: qsTr("Copy the session-ID into the clipboard") + hoverEnabled: true + + ToolTip.delay: 600 + 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: remote_control_manager.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: { + remote_control_manager.handleCopyToClipboardButtonClick(pin_text.text); + toast.show(qsTr("Copied PIN into clipboard!"), + "5000", + mainqmladaptor.ToastInfo); + } + + ToolTip.text: qsTr("Copy the pin into the clipboard") + hoverEnabled: true + + ToolTip.delay: 600 + ToolTip.timeout: 5000 + ToolTip.visible: hovered + } + } + } + + } + + Button { + id: start_support_button + height: Math.min(50) + objectName: "start_support_button" + text: checked ? qsTr("Stop remote support session") : 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: remote_control_manager.handleConnectButtonClick(checked); + } +} + +/*##^## +Designer { + D{i:0;autoSize:true;height:480;width:640} +} +##^##*/ diff --git a/src/scenes/remote_control/remote_control_manager.cpp b/src/scenes/remote_control/remote_control_manager.cpp new file mode 100644 index 0000000..b76ea2a --- /dev/null +++ b/src/scenes/remote_control/remote_control_manager.cpp @@ -0,0 +1,511 @@ +#include "remote_control_manager.h" + +#ifndef QT_NO_DEBUG +#define CHECK_TRUE(instruction) Q_ASSERT(instruction) +#else +#define CHECK_TRUE(instruction) (instruction) +#endif + +RemoteControlManager::RemoteControlManager(QQmlApplicationEngine *engine, + MainQMLAdaptor *main_gui, + DBusAPI *dbus_api) : QObject() { + Q_ASSERT(dbus_api != nullptr); + Q_ASSERT(main_gui != nullptr); + Q_ASSERT(engine != nullptr); + + _current_session = nullptr; + _sessions = new QSet; + _dbus_api = dbus_api; + _main_gui = main_gui; + _engine = engine; +} + +bool RemoteControlManager::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 RemoteControlManager::setConnectButtonChecked(bool checked) { + // 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("checked", checked); + } else { + qWarning() << "Unable to find 'start_support_button' Item!"; + return false; + } + + return true; +} + +bool RemoteControlManager::setStatusIndicatorText(QString status_text) { + // Find item via 'objectName' + QQuickItem *scene_remote_control = _engine->rootObjects().takeFirst()-> + findChild("Scene_remote_control"); + QQuickItem *item = scene_remote_control-> + findChild("dbus_api_status_text"); + if (item) { + item->setProperty("text", status_text); + } else { + qWarning() << "Unable to find 'dbus_api_status_text' Item!"; + return false; + } + + return true; +} + +bool RemoteControlManager::setStatusIndicatorColor(bool active, QColor color) { + // Find item via 'objectName' + QQuickItem *scene_remote_control = _engine->rootObjects().takeFirst()-> + 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 RemoteControlManager::handleCopyToClipboardButtonClick(QString copy_data) { + QClipboard *clipboard = QApplication::clipboard(); + QString originalText = clipboard->text(); + clipboard->setText(copy_data); + qDebug() << "Copied into clipboard:" << copy_data; +} + +QString RemoteControlManager::getURL() { + if (getCurrentSession() == nullptr) { + return tr("Not available yet"); + } + return getCurrentSession()->getURL(); +} + +QString RemoteControlManager::getPin() { + if (getCurrentSession() == nullptr) { + return "-----"; + } + return getCurrentSession()->getPin(); +} + +QString RemoteControlManager::getSessionID() { + if (getCurrentSession() == nullptr) { + return "-----"; + } + return getCurrentSession()->getSessionID(); +} + +Session* RemoteControlManager::getCurrentSession() { + return _current_session; +} + +void RemoteControlManager::addSession(Session *session) { + _sessions->insert(session); +} + +bool RemoteControlManager::removeSession(Session *session) { + if (getCurrentSession() == session) { + setCurrentSession(nullptr); + } + + bool ok = _sessions->remove(session); + + if (session != nullptr) { + session->disconnect(); + session->deleteLater(); + } + + setConnectButtonChecked(false); + setConnectButtonEnabled(true); + + currentSessionUrlChanged(tr("Not available yet")); + currentSessionPinChanged("-----"); + currentSessionSessionIDChanged("-----"); + + return ok; +} + +void RemoteControlManager::setCurrentSession(Session *session) { + if (session == nullptr) { + qDebug() << "Deselecting currentSession."; + _current_session = nullptr; + + return; + } + + if (_sessions->contains(session)) { + qDebug() << "Set currentSession to new session."; + _current_session = session; + + connectSession(_current_session); + } else { + qDebug() << "Given session was not in _sessions!"; + } +} + +void RemoteControlManager::connectSession(Session *session) { + // session --statusChanged-> this.currentSessionStatusChanged() + CHECK_TRUE(QObject::connect(session, + &Session::statusChanged, + this, + &RemoteControlManager::currentSessionStatusChanged)); + + // session --pinChanged-> this.currentSessionPinChanged() + CHECK_TRUE(QObject::connect(session, + &Session::pinChanged, + this, + &RemoteControlManager::currentSessionPinChanged)); + + // session --urlChanged-> this.currentSessionUrlChanged() + CHECK_TRUE(QObject::connect(session, + &Session::urlChanged, + this, + &RemoteControlManager::currentSessionUrlChanged)); + + // session --sessionIDChanged-> this.currentSessionSessionIDChanged() + CHECK_TRUE(QObject::connect(session, + &Session::sessionIDChanged, + this, + &RemoteControlManager::currentSessionSessionIDChanged)); + + + // session --startSucceeded -> this.currentSessionStartSucceeded() + CHECK_TRUE(QObject::connect(session, + &Session::startSucceeded, + this, + &RemoteControlManager::currentSessionStartSucceeded)); + + // session --startFailed-> this.currentSessionStartFailed() + CHECK_TRUE(QObject::connect(session, + &Session::startFailed, + this, + &RemoteControlManager::currentSessionStartFailed)); + + + // session --stopSucceeded-> this.currentSessionStopSucceeded() + CHECK_TRUE(QObject::connect(session, + &Session::stopSucceeded, + this, + &RemoteControlManager::currentSessionStopSucceeded)); + + // session --stopFailed-> this.currentSessionStopFailed() + CHECK_TRUE(QObject::connect(session, + &Session::stopFailed, + this, + &RemoteControlManager::currentSessionStopFailed)); + + + // session --statusSucceeded-> this.currentSessionStatusSucceeded() + CHECK_TRUE(QObject::connect(session, + &Session::statusSucceeded, + this, + &RemoteControlManager::currentSessionStatusSucceeded)); + + // session --statusFailed-> this.currentSessionStatusFailed() + CHECK_TRUE(QObject::connect(session, + &Session::statusFailed, + this, + &RemoteControlManager::currentSessionStatusFailed)); +} + +void RemoteControlManager::currentSessionStartFailed(QString error_message) { + _main_gui->showToast(error_message, 6000, Toast::ToastType::ToastError); + + // Start failed. No need to stop session, so remove it directly. + removeSession(getCurrentSession()); + + setConnectButtonChecked(false); + setConnectButtonEnabled(true); + + emit _main_gui->showWindow(); +} + +void RemoteControlManager::currentSessionStopFailed(QString error_message) { + _main_gui->showToast(error_message, 6000, Toast::ToastType::ToastError); + + // Stop failed, so don't do anything! The user should try again. + + // Set status indicator to the corresponding error message. + QString translated = translateStatusIndicatorText("stop_session_error"); + setStatusIndicatorText(translated); + + setConnectButtonChecked(true); + setConnectButtonEnabled(true); + + emit _main_gui->showWindow(); +} + +void RemoteControlManager::currentSessionStatusFailed(QString error_message) { + _main_gui->showToast(error_message, 6000, Toast::ToastType::ToastError); + + // Set status indicator to the corresponding error message. + QString translated = translateStatusIndicatorText("status_session_error"); + setStatusIndicatorText(translated); + + setConnectButtonChecked(false); + setConnectButtonEnabled(true); + + currentSessionUrlChanged(tr("Not available yet")); + currentSessionPinChanged("-----"); + currentSessionSessionIDChanged("-----"); + + emit _main_gui->showWindow(); +} + +void RemoteControlManager::currentSessionStartSucceeded() { + Session *current_session = getCurrentSession(); + if (current_session != nullptr) { + _main_gui->showToast( + tr("Session was started on '%0' successfully") + .arg(current_session->getHost()->alias()), + 6000, + Toast::ToastType::ToastSuccess + ); + } else { + qCritical().noquote() << tr("currentSessionStartSucceeded(): " + "Current Session is nullptr!"); + _engine->exit(1); + } + + // Set status indicator to the corresponding error message. + QString translated = translateStatusIndicatorText("start_session_success"); + setStatusIndicatorText(translated); + + setConnectButtonChecked(true); + setConnectButtonEnabled(true); +} + +void RemoteControlManager::currentSessionStopSucceeded() { + qDebug() << "Session stop succeeded: Delete current session object now."; + bool ok = removeSession(getCurrentSession()); + if (!ok) { + qWarning() << tr("Couldn't remove current session out of '_sessions' list."); + } + + _main_gui->showToast(tr("Remote support session was stopped."), + 6000, + Toast::ToastType::ToastSuccess); + + // Set status indicator to the corresponding error message. + QString translated = translateStatusIndicatorText("stop_session_success"); + setStatusIndicatorText(translated); + + setConnectButtonChecked(false); + setConnectButtonEnabled(true); +} + +void RemoteControlManager::currentSessionUnexpectedStop(QString error_message) { + _main_gui->showToast(error_message, 6000, Toast::ToastType::ToastError); + + setConnectButtonChecked(false); + setConnectButtonEnabled(true); + + qDebug() << "Delete current session object now."; + bool ok = removeSession(getCurrentSession()); + if (!ok) { + qWarning() << tr("Couldn't remove current session out of '_sessions' list."); + } +} + +void RemoteControlManager::currentSessionStatusSucceeded() { + // Nothing to do. +} + +void RemoteControlManager::currentSessionStatusChanged(QString new_status_code) { + Session *current_session = getCurrentSession(); + if (current_session == nullptr || !current_session->started) { + qDebug() << "RemoteControlManager::currentSessionStatusChanged(QString): " + "got called even though the session isn't even started."; + return; + } + QString translated = translateStatusIndicatorText(new_status_code); + setStatusIndicatorText(translated); +} + +QString RemoteControlManager::translateStatusIndicatorText(QString status_code) { + QString guiString = tr("Unknown state of service"); + setStatusIndicatorColor(false); + + if (status_code == "dead") { + + /* Session died */ + guiString = tr("Remote Support session was stopped ungracefully"); + + // Red color + setStatusIndicatorColor(true, QColor(255, 0, 0, 127)); + + currentSessionUnexpectedStop(guiString); + + } else if (status_code == "stopped") { + + /* Session was stopped normally somehow other than the users request. + * Remote support partner could have clicked exit for example */ + guiString = tr("Remote Support session was stopped"); + + // Green color + setStatusIndicatorColor(true, QColor(0, 255, 0, 127)); + + currentSessionUnexpectedStop(guiString); + + } else if (status_code == "active") { + + /* Partner is connected */ + guiString = tr("Your partner is connected to the Remote Support session"); + + // Green color + setStatusIndicatorColor(true, QColor(0, 255, 0, 127)); + + } else if (status_code == "start_session_success" || status_code == "running") { + + /* Session successfully started */ + guiString = tr("Remote Support session successfully started! " + "Waiting for your remote support partner to connect."); + + // yellow color (will be green when partner is connected) + setStatusIndicatorColor(true, QColor(255, 255, 0, 127)); + + } else if (status_code == "start_session_error") { + + /* Session couldn't be started */ + guiString = tr("Remote Support session couldn't be started!"); + + // Red color + setStatusIndicatorColor(true, QColor(255, 0, 0, 127)); + + } else if (status_code == "stop_session_success") { + + /* Session was successfully stopped by the users request */ + guiString = tr("Session stopped successfully."); + + // Green color + setStatusIndicatorColor(true, QColor(0, 255, 0, 127)); + + } else if (status_code == "stop_session_error") { + + /* Session couldn't be stopped */ + guiString = tr("Session could not be stopped!") + "\n" + + tr("remote support partner could still be connected!"); + + // Red color + setStatusIndicatorColor(true, QColor(255, 0, 0, 127)); + + } else if (status_code == "status_session_error") { + + /* Session's status couldn't be refreshed */ + guiString = tr("Session status could not be refreshed! " + "Your remote support partner could still be connected!"); + + // Red color + setStatusIndicatorColor(true, QColor(255, 0, 0, 127)); + + } + + qDebug().noquote() << QString("Translating status code '%0' to '%1'") + .arg(status_code) + .arg(guiString); + return guiString; +} + +void RemoteControlManager::currentSessionPinChanged(QString pin) { + emit pinChanged(pin); +} + +void RemoteControlManager::currentSessionUrlChanged(QString url) { + emit urlChanged(url); +} + +void RemoteControlManager::currentSessionSessionIDChanged(QString session_id) { + emit sessionIDChanged(session_id); +} + +void RemoteControlManager::connectToDBusAPI(Session *session) { + // _dbus_api --sessionStartResponse-> this.start_response() + CHECK_TRUE(QObject::connect(_dbus_api, + &DBusAPI::serviceStartResponse, + session, + &Session::start_response)); + + // _dbus_api --serviceStopResponse-> this.stop_response() + CHECK_TRUE(QObject::connect(_dbus_api, + &DBusAPI::serviceStopResponse, + session, + &Session::stop_response, + Qt::DirectConnection)); + + // _dbus_api --sessionStatusResponse-> this.status_response() + CHECK_TRUE(QObject::connect(_dbus_api, + &DBusAPI::serviceStatusResponse, + session, + &Session::status_response)); +} + +void RemoteControlManager::handleConnectButtonClick(bool checked) { + if (checked) { + // Create a Session object and start it. + qDebug() << "Creating and starting a new session object now."; + RWAHost *selected_host = _main_gui->getSelectedRWAHost(); + if (selected_host) { + qInfo() << tr("Creating a new session object."); + Session *new_session = new Session(_dbus_api, selected_host); + + connectToDBusAPI(new_session); + + qDebug() << "Adding session to QSet"; + addSession(new_session); + + qDebug() << "Setting session as current session."; + setCurrentSession(new_session); + + qInfo().noquote() << tr("Starting a remote support session on host '%0' " + "using the new session object.") + .arg(selected_host->uuid()); + new_session->start(); + } else { + qCritical().noquote() << tr("Can't start a remote support session. " + "There is no RWA host is selected!"); + } + + setConnectButtonChecked(false); + setConnectButtonEnabled(false); + } else { + Session *current_session = getCurrentSession(); + if (current_session != nullptr) { + emit current_session->stop(); + } else { + qCritical().noquote() << tr("RemoteControlManager::" + "handleConnectButtonClick(): Current Session " + "is nullptr!"); + setConnectButtonChecked(false); + setConnectButtonEnabled(true); + } + } +} + +/*void RemoteControlManager::onCloseHandler() { + // To cleanup things here + // check current session nullptr + getCurrentSession()->stop(); +}*/ diff --git a/src/scenes/remote_control/remote_control_manager.h b/src/scenes/remote_control/remote_control_manager.h new file mode 100644 index 0000000..6f2fbdb --- /dev/null +++ b/src/scenes/remote_control/remote_control_manager.h @@ -0,0 +1,78 @@ +#ifndef REMOTECONTROLMANAGER_H +#define REMOTECONTROLMANAGER_H + +#include + +#include "../../main_qmladaptor.h" +#include "../../DBusAPI.h" +#include "../../session.h" + +class RemoteControlManager : public QObject { + + Q_OBJECT + // 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) + // this makes session_id available as a QML property + Q_PROPERTY(QString session_id READ getSessionID NOTIFY sessionIDChanged) + +public: + explicit RemoteControlManager(QQmlApplicationEngine *engine = nullptr, + MainQMLAdaptor *main_gui = nullptr, + DBusAPI *dbus_api = nullptr); + + bool setConnectButtonEnabled(bool enabled); + bool setConnectButtonChecked(bool checked); + bool setStatusIndicatorColor(bool active, QColor color = QColor(255,255,255)); + + QString translateStatusIndicatorText(QString status_code); + bool setStatusIndicatorText(QString status_text); + +private: + DBusAPI *_dbus_api; + MainQMLAdaptor *_main_gui; + QQmlApplicationEngine *_engine; + Session *_current_session; + QSet *_sessions; + + void connectSession(Session *session); + void connectToDBusAPI(Session *session); + + bool refreshTimerIsRunning; + +signals: + void onConnectButtonClick(bool checked); + void pinChanged(QString pin); + void urlChanged(QString URL); + void sessionIDChanged(QString session_id); + +public slots: + void handleCopyToClipboardButtonClick(QString copy_data); + void handleConnectButtonClick(bool checked); + + void setCurrentSession(Session *session); + void addSession(Session *session); + bool removeSession(Session *session); + + void currentSessionStatusChanged(QString); + void currentSessionPinChanged(QString); + void currentSessionSessionIDChanged(QString); + void currentSessionUrlChanged(QString); + + QString getURL(); + QString getPin(); + QString getSessionID(); + Session* getCurrentSession(); + + void currentSessionStartFailed(QString error_message); + void currentSessionStopFailed(QString error_message); + void currentSessionStatusFailed(QString error_message); + void currentSessionUnexpectedStop(QString error_message); + + void currentSessionStartSucceeded(); + void currentSessionStopSucceeded(); + void currentSessionStatusSucceeded(); +}; + +#endif // REMOTECONTROLMANAGER_H -- 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/scenes/Scene_remote_control.qml | 368 ------------------------------------ 1 file changed, 368 deletions(-) delete mode 100644 src/scenes/Scene_remote_control.qml (limited to 'src/scenes') 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} -} - ##^##*/ -- 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/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 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src/scenes') 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); -- 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 --- 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 +- 7 files changed, 469 insertions(+), 469 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/scenes') 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