From 0e8f295868e826b89114b55a0aa360cb30d7494f Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Sun, 1 Aug 2021 02:36:42 +0200 Subject: add_server_wizard/add_server_wizard -> add_rwahost_wizard/add_rwahost_wizard --- qml.qrc | 6 +- rwa-support-desktopapp.pro | 4 +- src/main.cpp | 10 +- src/main.qml | 2 +- src/main_qmladaptor.cpp | 4 +- src/scenes/add_rwahost_wizard/Scene_step_1.qml | 282 +++++++++++++++++++++ .../add_rwahost_wizard/add_rwahost_wizard.cpp | 124 +++++++++ src/scenes/add_rwahost_wizard/add_rwahost_wizard.h | 61 +++++ src/scenes/add_server_wizard/Scene_step_1.qml | 282 --------------------- src/scenes/add_server_wizard/add_server_wizard.cpp | 124 --------- src/scenes/add_server_wizard/add_server_wizard.h | 61 ----- src/scenes/remote_control/remote_control_manager.h | 4 +- 12 files changed, 482 insertions(+), 482 deletions(-) create mode 100644 src/scenes/add_rwahost_wizard/Scene_step_1.qml create mode 100644 src/scenes/add_rwahost_wizard/add_rwahost_wizard.cpp create mode 100644 src/scenes/add_rwahost_wizard/add_rwahost_wizard.h delete mode 100644 src/scenes/add_server_wizard/Scene_step_1.qml delete mode 100644 src/scenes/add_server_wizard/add_server_wizard.cpp delete mode 100644 src/scenes/add_server_wizard/add_server_wizard.h diff --git a/qml.qrc b/qml.qrc index 35e9142..04ee201 100644 --- a/qml.qrc +++ b/qml.qrc @@ -29,9 +29,9 @@ src/scenes/Scene_settings.qml src/scenes/Scene_placeholder.qml src/scenes/Scene_no_server_available.qml - src/scenes/add_server_wizard/add_server_wizard.cpp - src/scenes/add_server_wizard/add_server_wizard.h - src/scenes/add_server_wizard/Scene_step_1.qml + src/scenes/add_rwahost_wizard/add_rwahost_wizard.cpp + src/scenes/add_rwahost_wizard/add_rwahost_wizard.h + src/scenes/add_rwahost_wizard/Scene_step_1.qml src/scenes/remote_control/remote_control_manager.cpp src/scenes/remote_control/remote_control_manager.h src/scenes/remote_control/Scene_remote_control.qml diff --git a/rwa-support-desktopapp.pro b/rwa-support-desktopapp.pro index f9a05bf..96ecec3 100644 --- a/rwa-support-desktopapp.pro +++ b/rwa-support-desktopapp.pro @@ -52,7 +52,7 @@ SOURCES += src/main.cpp \ src/RWAHost.cpp \ src/DBusAPI.cpp \ src/scenes/remote_control/remote_control_manager.cpp \ - src/scenes/add_server_wizard/add_server_wizard.cpp + src/scenes/add_rwahost_wizard/add_rwahost_wizard.cpp HEADERS += src/RWADBusAdaptor.h \ src/main_qmladaptor.h \ @@ -63,7 +63,7 @@ HEADERS += src/RWADBusAdaptor.h \ src/RWAHost.h \ src/DBusAPI.h \ src/scenes/remote_control/remote_control_manager.h \ - src/scenes/add_server_wizard/add_server_wizard.h + src/scenes/add_rwahost_wizard/add_rwahost_wizard.h TRANSLATIONS += locales/main_en.ts \ locales/de_DE.ts \ diff --git a/src/main.cpp b/src/main.cpp index ff5d2a8..e29c8db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,7 +39,7 @@ #include "DBusAPI.h" #include "RWADBusAdaptor.cpp" #include "session.h" -#include "scenes/add_server_wizard/add_server_wizard.h" +#include "scenes/add_rwahost_wizard/add_rwahost_wizard.h" #include "scenes/remote_control/remote_control_manager.h" #include "RWAHostModel.h" #include "RWAHost.h" @@ -119,14 +119,14 @@ int main(int argc, char *argv[]) { main_gui.data(), SLOT(onRwaHostSelected(QString))); - // Make 'add_server_wizard' available to QML - QScopedPointer wizard ( - new Add_Server_wizard(&app, + // Make 'AddRWAHostWizard' available to QML + QScopedPointer wizard ( + new AddRWAHostWizard(&app, main_gui.data(), dbus_api.data()) ); engine.rootContext()-> - setContextProperty("add_server_wizard", wizard.data()); + setContextProperty("add_rwahost_wizard", wizard.data()); // Make 'remote_control_manager' available to QML QScopedPointer remote_mngr ( diff --git a/src/main.qml b/src/main.qml index af41dd1..a622c18 100644 --- a/src/main.qml +++ b/src/main.qml @@ -295,7 +295,7 @@ ApplicationWindow { } ListItem { text: " " + qsTr("Add RWA-Server") - scene_url: "scenes/add_server_wizard/Scene_step_1.qml" + scene_url: "scenes/add_rwahost_wizard/Scene_step_1.qml" onListItemClick: { header_text.text = qsTr("Server addition wizard") if (inPortrait) sidebar_drawer.close() diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index d30243d..688b993 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -290,9 +290,9 @@ void MainQMLAdaptor::main_content_replace(QString scene) { QVariant to_cast = main_content->property("currentItem"); QObject *obj = qvariant_cast(to_cast); if (obj) { - QString scene_add_server_wizard = "Scene_step_1"; + QString scene_add_rwahost_wizard = "Scene_step_1"; if (!(scene.contains(obj->objectName()) || - scene_add_server_wizard.contains(obj->objectName()))) { + scene_add_rwahost_wizard.contains(obj->objectName()))) { QVariant arg = QVariant::fromValue(scene); if (!QMetaObject::invokeMethod(window, "main_content_replace", Q_ARG(QVariant, arg))) { diff --git a/src/scenes/add_rwahost_wizard/Scene_step_1.qml b/src/scenes/add_rwahost_wizard/Scene_step_1.qml new file mode 100644 index 0000000..873e0fd --- /dev/null +++ b/src/scenes/add_rwahost_wizard/Scene_step_1.qml @@ -0,0 +1,282 @@ +import QtQuick 2.9 +import QtQuick.Window 2.2 +import QtQuick.Extras 1.4 +import QtQuick.Controls 2.2 +import QtQuick.Controls.Material 2.3 +import rwa.toast.type 1.0 + +/*! + * This .qml file is a Scene which can be loaded through for + * example a StackView (main_content in main.qml). + */ + +Item { + id: scene_server_wizard_step_1 + objectName: "Scene_step_1" + + Connections { + target: add_rwahost_wizard + function onStep1Success() { + // Go onto the first page of the stack. + main_content_pop(null) + mainqmladaptor.showToast(qsTr("Successfully added remote web app host."), + 5000, + ToastType.ToastSuccess); + } + } + + Connections { + target: add_rwahost_wizard + function onStep1Failed(reason, toast_type) { + mainqmladaptor.showToast(reason, + 5000, + toast_type) + } + } + + Rectangle { + id: rectangle + anchors.fill: parent + color: Material.background + + Button { + id: next_step1_button + text: qsTr("Next Step") + anchors.bottom: parent.bottom + anchors.bottomMargin: 15 + anchors.right: parent.right + anchors.rightMargin: 15 + + onClicked: { + add_rwahost_wizard.processStep1(host_url.text, host_alias.text) + } + } + + /*Text { + color: Material.foreground + id: step_indicator + + text: qsTr("Step 1") + anchors.leftMargin: 15 + anchors.top: parent.top + anchors.topMargin: 15 + font.pointSize: 21 + wrapMode: Text.WordWrap + + font.bold: true + horizontalAlignment: Text.AlignHCenter + anchors.left: parent.left + anchors.margins: 5 + }*/ + + Text { + color: Material.foreground + id: explaining_text + + text: qsTr("Please input the address for the "+ + "remote web app server which you want "+ + "to connect to.\nIf you don't know "+ + "what this means, ask your local "+ + "administrator about it please.\nBefore you can "+ + "start any remote sessions you will have to "+ + "be approved for remote support.") + font.pointSize: 12 + anchors.right: parent.right + anchors.rightMargin: 15 + anchors.leftMargin: 15 + anchors.top: parent.top //step_indicator.bottom + anchors.topMargin: 15 + wrapMode: Text.WordWrap + + anchors.left: parent.left + anchors.margins: 5 + } + + TextField { + id: host_url + selectByMouse: true + placeholderText: qsTr("http://example.com:8000") + + font.pixelSize: 16 + color: Material.foreground + anchors.topMargin: 30 + + padding: 15 + topPadding: 15 + + anchors.top: explaining_text.bottom + anchors.left: parent.left + anchors.leftMargin: 15 + anchors.right: parent.right + anchors.margins: 30 + + MouseArea { + anchors.fill: parent + hoverEnabled: true + onHoveredChanged: { + if (containsMouse) { + host_url_background.state = "hovered" + } else if (!host_url.focus) { + host_url_background.state = "unhovered" + } + } + onClicked: { + host_url.forceActiveFocus(); + } + } + + onFocusChanged: { + host_url_background.state = host_url.focus ? "hovered" : "unhovered" + } + + background: Rectangle { + id: host_url_background + color: Material.background + border.color: Material.foreground + border.width: 1 + radius: 4 + + states: [ + State { + name: "hovered" + PropertyChanges { + target: host_url_background + border.color: "#0178EF" + } + }, + State { + name: "unhovered" + PropertyChanges { + target: host_url_background + border.color: Material.foreground + } + } + ] + transitions: [ + Transition { + from: "*" + to: "*" + PropertyAnimation { + property: "border.color" + duration: 100 + easing.type: Easing.Linear + } + } + ] + + Text { + color: Material.foreground + text: qsTr("RWA host address") + anchors.left: parent.left + anchors.leftMargin: 15 + anchors.verticalCenterOffset: - host_url.height / 2 + anchors.verticalCenter: parent.verticalCenter + leftPadding: 5 + + Rectangle { + color: Material.background + width: parent.width + 5 + 3 + height: parent.height + z: -1 + } + } + } + } + + TextField { + id: host_alias + selectByMouse: true + placeholderText: qsTr("My example host") + + font.pixelSize: 16 + color: Material.foreground + + padding: 15 + topPadding: 15 + + anchors.top: host_url.bottom + anchors.topMargin: 30 + anchors.left: parent.left + anchors.leftMargin: 15 + anchors.right: parent.right + anchors.margins: 30 + + MouseArea { + anchors.fill: parent + hoverEnabled: true + onHoveredChanged: { + if (containsMouse) { + host_alias_background.state = "hovered" + } else if (!host_alias.focus) { + host_alias_background.state = "unhovered" + } + } + onClicked: { + host_alias.forceActiveFocus(); + } + } + + onFocusChanged: { + host_alias_background.state = host_alias.focus ? "hovered" : "unhovered" + } + + background: Rectangle { + id: host_alias_background + color: Material.background + border.color: Material.foreground + border.width: 1 + radius: 4 + + states: [ + State { + name: "hovered" + PropertyChanges { + target: host_alias_background + border.color: "#0178EF" + } + }, + State { + name: "unhovered" + PropertyChanges { + target: host_alias_background + border.color: Material.foreground + } + } + ] + transitions: [ + Transition { + from: "*" + to: "*" + PropertyAnimation { + property: "border.color" + duration: 100 + easing.type: Easing.Linear + } + } + ] + + Text { + color: Material.foreground + text: qsTr("RWA host alias") + anchors.left: parent.left + anchors.leftMargin: 15 + anchors.verticalCenterOffset: - host_alias.height / 2 + anchors.verticalCenter: parent.verticalCenter + leftPadding: 5 + + Rectangle { + color: Material.background + width: parent.width + 5 + 3 + height: parent.height + z: -1 + } + } + } + } + } +} + +/*##^## Designer { + D{i:0;autoSize:true;height:480;width:640}D{i:4;anchors_width:351;anchors_x:279} +} + ##^##*/ diff --git a/src/scenes/add_rwahost_wizard/add_rwahost_wizard.cpp b/src/scenes/add_rwahost_wizard/add_rwahost_wizard.cpp new file mode 100644 index 0000000..7adbdf9 --- /dev/null +++ b/src/scenes/add_rwahost_wizard/add_rwahost_wizard.cpp @@ -0,0 +1,124 @@ +/* + * This file is part of Remote Support Desktop + * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp + * Copyright 2021 Daniel Teichmann + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "add_rwahost_wizard.h" +#include "../../RWADBusAdaptor.h" +#include "../../RWAHost.h" + +AddRWAHostWizard::AddRWAHostWizard(QObject *parent, + MainQMLAdaptor *main_gui, DBusAPI *dbus_api) : QObject(parent) { + Q_ASSERT(main_gui != nullptr); + Q_ASSERT(dbus_api != nullptr); + + _dbus_api = dbus_api; + _main_gui = main_gui; + + // _dbus_api --serviceAddWebAppHostResponse-> this.add_web_app_host_response() + QObject::connect(_dbus_api, + SIGNAL(serviceAddWebAppHostResponse(QJsonDocument*)), + this, + SLOT(add_web_app_host_response(QJsonDocument*))); +} + +void AddRWAHostWizard::processStep1(QString host_url, QString host_alias) { + qDebug() << "Processing Step 1 with args: " << host_url << host_alias; + + if(host_alias == "" || host_url == "") { + QString reason = tr("Both textfields can't be empty!"); + emit step1Failed(reason, Toast::ToastType::ToastWarning); + qDebug().noquote() << reason; + return; + } + + return add_server(host_url, host_alias); +} + +void AddRWAHostWizard::processStep2() { + qDebug() << "Processing Step 2 with args: No Args."; + emit step2Failed(tr("The features you expected here are not yet implemented."), Toast::ToastType::ToastWarning); + // Just show placeholder scene now. + emit step2Success(); +} + +void AddRWAHostWizard::add_server(QString host_url, QString host_alias) { + _dbus_api->add_web_app_host_request(host_url, host_alias); +} + +void AddRWAHostWizard::add_web_app_host_response(QJsonDocument *doc) { + // Q_ASSERT lets the program crash immediatly at startup, + // when the session service is not started. + // Don't use Q_ASSERT(doc != nullptr); instead use: + if (doc == nullptr) { + _main_gui->setRWAHostSelected(false); + _main_gui->showToast(tr("Can't connect to underlying session service!"), + 9800, + Toast::ToastType::ToastError); + return; + } + + // Get the QJsonObject + QJsonObject jObject = doc->object(); + QVariantMap mainMap = jObject.toVariantMap(); + + // Status of request + QString request_status = mainMap["status"].toString(); + if (request_status == "success") { + _dbus_api->get_web_app_hosts_request(); + + qInfo() << "Successfully added a new RWAHost."; + emit step1Success(); + } else { + qCritical().noquote() << tr("An error occured while adding a new host!"); + + uint toast_type = Toast::ToastType::ToastStandard; + QString reason = tr("An error occured while adding a new host!"); + QString type = mainMap["type"].toString(); + + if(type == "connection"){ + reason = tr("Couldn't connect to the specified host!"); + toast_type = Toast::ToastType::ToastError; + qCritical().noquote() << reason; + } else if (type == "duplicate") { + reason = tr("The specified host was already added!"); + toast_type = Toast::ToastType::ToastWarning; + qCritical().noquote() << reason; + } else if (type == "invalid_url") { + reason = tr("The specified host address is not valid!"); + toast_type = Toast::ToastType::ToastWarning; + qCritical().noquote() << reason; + } else if (type == "permission_denied") { + reason = tr("The specified host address does not grant access!"); + toast_type = Toast::ToastType::ToastError; + qCritical().noquote() << reason; + } else if (type == "unsupported_server") { + reason = tr("The specified host address is not supported!"); + toast_type = Toast::ToastType::ToastError; + qCritical().noquote() << reason; + } + emit step1Failed(reason, toast_type); + + return; + } +} diff --git a/src/scenes/add_rwahost_wizard/add_rwahost_wizard.h b/src/scenes/add_rwahost_wizard/add_rwahost_wizard.h new file mode 100644 index 0000000..f019be1 --- /dev/null +++ b/src/scenes/add_rwahost_wizard/add_rwahost_wizard.h @@ -0,0 +1,61 @@ +/* + * This file is part of Remote Support Desktop + * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp + * Copyright 2021 Daniel Teichmann + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef ADD_RWAHOST_WIZARD_H +#define ADD_RWAHOST_WIZARD_H + +#include + +#include "../../RWADBusAdaptor.h" +#include "../../DBusAPI.h" +#include "../../main_qmladaptor.h" + +class AddRWAHostWizard : public QObject +{ + Q_OBJECT +public: + explicit AddRWAHostWizard(QObject *parent = nullptr, + MainQMLAdaptor *main_gui = nullptr, + DBusAPI *dbus_api = nullptr); + void add_server(QString host_url, QString host_alias); + +private: + DBusAPI *_dbus_api; + MainQMLAdaptor *_main_gui; + +signals: + void step1Success(); + void step1Failed(QString reason, uint toast_type); + void step2Success(); + void step2Failed(QString reason, uint toast_type); + +public slots: + void processStep1(QString host_url, QString host_alias); + void processStep2(); + + void add_web_app_host_response(QJsonDocument *doc); +}; + +#endif // ADD_SERVER_WIZARD_H diff --git a/src/scenes/add_server_wizard/Scene_step_1.qml b/src/scenes/add_server_wizard/Scene_step_1.qml deleted file mode 100644 index bfbe2ae..0000000 --- a/src/scenes/add_server_wizard/Scene_step_1.qml +++ /dev/null @@ -1,282 +0,0 @@ -import QtQuick 2.9 -import QtQuick.Window 2.2 -import QtQuick.Extras 1.4 -import QtQuick.Controls 2.2 -import QtQuick.Controls.Material 2.3 -import rwa.toast.type 1.0 - -/*! - * This .qml file is a Scene which can be loaded through for - * example a StackView (main_content in main.qml). - */ - -Item { - id: scene_server_wizard_step_1 - objectName: "Scene_step_1" - - Connections { - target: add_server_wizard - function onStep1Success() { - // Go onto the first page of the stack. - main_content_pop(null) - mainqmladaptor.showToast(qsTr("Successfully added remote web app host."), - 5000, - ToastType.ToastSuccess); - } - } - - Connections { - target: add_server_wizard - function onStep1Failed(reason, toast_type) { - mainqmladaptor.showToast(reason, - 5000, - toast_type) - } - } - - Rectangle { - id: rectangle - anchors.fill: parent - color: Material.background - - Button { - id: next_step1_button - text: qsTr("Next Step") - anchors.bottom: parent.bottom - anchors.bottomMargin: 15 - anchors.right: parent.right - anchors.rightMargin: 15 - - onClicked: { - add_server_wizard.processStep1(host_url.text, host_alias.text) - } - } - - /*Text { - color: Material.foreground - id: step_indicator - - text: qsTr("Step 1") - anchors.leftMargin: 15 - anchors.top: parent.top - anchors.topMargin: 15 - font.pointSize: 21 - wrapMode: Text.WordWrap - - font.bold: true - horizontalAlignment: Text.AlignHCenter - anchors.left: parent.left - anchors.margins: 5 - }*/ - - Text { - color: Material.foreground - id: explaining_text - - text: qsTr("Please input the address for the "+ - "remote web app server which you want "+ - "to connect to.\nIf you don't know "+ - "what this means, ask your local "+ - "administrator about it please.\nBefore you can "+ - "start any remote sessions you will have to "+ - "be approved for remote support.") - font.pointSize: 12 - anchors.right: parent.right - anchors.rightMargin: 15 - anchors.leftMargin: 15 - anchors.top: parent.top //step_indicator.bottom - anchors.topMargin: 15 - wrapMode: Text.WordWrap - - anchors.left: parent.left - anchors.margins: 5 - } - - TextField { - id: host_url - selectByMouse: true - placeholderText: qsTr("http://example.com:8000") - - font.pixelSize: 16 - color: Material.foreground - anchors.topMargin: 30 - - padding: 15 - topPadding: 15 - - anchors.top: explaining_text.bottom - anchors.left: parent.left - anchors.leftMargin: 15 - anchors.right: parent.right - anchors.margins: 30 - - MouseArea { - anchors.fill: parent - hoverEnabled: true - onHoveredChanged: { - if (containsMouse) { - host_url_background.state = "hovered" - } else if (!host_url.focus) { - host_url_background.state = "unhovered" - } - } - onClicked: { - host_url.forceActiveFocus(); - } - } - - onFocusChanged: { - host_url_background.state = host_url.focus ? "hovered" : "unhovered" - } - - background: Rectangle { - id: host_url_background - color: Material.background - border.color: Material.foreground - border.width: 1 - radius: 4 - - states: [ - State { - name: "hovered" - PropertyChanges { - target: host_url_background - border.color: "#0178EF" - } - }, - State { - name: "unhovered" - PropertyChanges { - target: host_url_background - border.color: Material.foreground - } - } - ] - transitions: [ - Transition { - from: "*" - to: "*" - PropertyAnimation { - property: "border.color" - duration: 100 - easing.type: Easing.Linear - } - } - ] - - Text { - color: Material.foreground - text: qsTr("RWA host address") - anchors.left: parent.left - anchors.leftMargin: 15 - anchors.verticalCenterOffset: - host_url.height / 2 - anchors.verticalCenter: parent.verticalCenter - leftPadding: 5 - - Rectangle { - color: Material.background - width: parent.width + 5 + 3 - height: parent.height - z: -1 - } - } - } - } - - TextField { - id: host_alias - selectByMouse: true - placeholderText: qsTr("My example host") - - font.pixelSize: 16 - color: Material.foreground - - padding: 15 - topPadding: 15 - - anchors.top: host_url.bottom - anchors.topMargin: 30 - anchors.left: parent.left - anchors.leftMargin: 15 - anchors.right: parent.right - anchors.margins: 30 - - MouseArea { - anchors.fill: parent - hoverEnabled: true - onHoveredChanged: { - if (containsMouse) { - host_alias_background.state = "hovered" - } else if (!host_alias.focus) { - host_alias_background.state = "unhovered" - } - } - onClicked: { - host_alias.forceActiveFocus(); - } - } - - onFocusChanged: { - host_alias_background.state = host_alias.focus ? "hovered" : "unhovered" - } - - background: Rectangle { - id: host_alias_background - color: Material.background - border.color: Material.foreground - border.width: 1 - radius: 4 - - states: [ - State { - name: "hovered" - PropertyChanges { - target: host_alias_background - border.color: "#0178EF" - } - }, - State { - name: "unhovered" - PropertyChanges { - target: host_alias_background - border.color: Material.foreground - } - } - ] - transitions: [ - Transition { - from: "*" - to: "*" - PropertyAnimation { - property: "border.color" - duration: 100 - easing.type: Easing.Linear - } - } - ] - - Text { - color: Material.foreground - text: qsTr("RWA host alias") - anchors.left: parent.left - anchors.leftMargin: 15 - anchors.verticalCenterOffset: - host_alias.height / 2 - anchors.verticalCenter: parent.verticalCenter - leftPadding: 5 - - Rectangle { - color: Material.background - width: parent.width + 5 + 3 - height: parent.height - z: -1 - } - } - } - } - } -} - -/*##^## Designer { - D{i:0;autoSize:true;height:480;width:640}D{i:4;anchors_width:351;anchors_x:279} -} - ##^##*/ diff --git a/src/scenes/add_server_wizard/add_server_wizard.cpp b/src/scenes/add_server_wizard/add_server_wizard.cpp deleted file mode 100644 index caac344..0000000 --- a/src/scenes/add_server_wizard/add_server_wizard.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * This file is part of Remote Support Desktop - * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp - * Copyright 2021 Daniel Teichmann - * SPDX-License-Identifier: GPL-2.0-or-later - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "add_server_wizard.h" -#include "../../RWADBusAdaptor.h" -#include "../../RWAHost.h" - -Add_Server_wizard::Add_Server_wizard(QObject *parent, - MainQMLAdaptor *main_gui, DBusAPI *dbus_api) : QObject(parent) { - Q_ASSERT(main_gui != nullptr); - Q_ASSERT(dbus_api != nullptr); - - _dbus_api = dbus_api; - _main_gui = main_gui; - - // _dbus_api --serviceAddWebAppHostResponse-> this.add_web_app_host_response() - QObject::connect(_dbus_api, - SIGNAL(serviceAddWebAppHostResponse(QJsonDocument*)), - this, - SLOT(add_web_app_host_response(QJsonDocument*))); -} - -void Add_Server_wizard::processStep1(QString host_url, QString host_alias) { - qDebug() << "Processing Step 1 with args: " << host_url << host_alias; - - if(host_alias == "" || host_url == "") { - QString reason = tr("Both textfields can't be empty!"); - emit step1Failed(reason, Toast::ToastType::ToastWarning); - qDebug().noquote() << reason; - return; - } - - return add_server(host_url, host_alias); -} - -void Add_Server_wizard::processStep2() { - qDebug() << "Processing Step 2 with args: No Args."; - emit step2Failed(tr("The features you expected here are not yet implemented."), Toast::ToastType::ToastWarning); - // Just show placeholder scene now. - emit step2Success(); -} - -void Add_Server_wizard::add_server(QString host_url, QString host_alias) { - _dbus_api->add_web_app_host_request(host_url, host_alias); -} - -void Add_Server_wizard::add_web_app_host_response(QJsonDocument *doc) { - // Q_ASSERT lets the program crash immediatly at startup, - // when the session service is not started. - // Don't use Q_ASSERT(doc != nullptr); instead use: - if (doc == nullptr) { - _main_gui->setRWAHostSelected(false); - _main_gui->showToast(tr("Can't connect to underlying session service!"), - 9800, - Toast::ToastType::ToastError); - return; - } - - // Get the QJsonObject - QJsonObject jObject = doc->object(); - QVariantMap mainMap = jObject.toVariantMap(); - - // Status of request - QString request_status = mainMap["status"].toString(); - if (request_status == "success") { - _dbus_api->get_web_app_hosts_request(); - - qInfo() << "Successfully added a new RWAHost."; - emit step1Success(); - } else { - qCritical().noquote() << tr("An error occured while adding a new host!"); - - uint toast_type = Toast::ToastType::ToastStandard; - QString reason = tr("An error occured while adding a new host!"); - QString type = mainMap["type"].toString(); - - if(type == "connection"){ - reason = tr("Couldn't connect to the specified host!"); - toast_type = Toast::ToastType::ToastError; - qCritical().noquote() << reason; - } else if (type == "duplicate") { - reason = tr("The specified host was already added!"); - toast_type = Toast::ToastType::ToastWarning; - qCritical().noquote() << reason; - } else if (type == "invalid_url") { - reason = tr("The specified host address is not valid!"); - toast_type = Toast::ToastType::ToastWarning; - qCritical().noquote() << reason; - } else if (type == "permission_denied") { - reason = tr("The specified host address does not grant access!"); - toast_type = Toast::ToastType::ToastError; - qCritical().noquote() << reason; - } else if (type == "unsupported_server") { - reason = tr("The specified host address is not supported!"); - toast_type = Toast::ToastType::ToastError; - qCritical().noquote() << reason; - } - emit step1Failed(reason, toast_type); - - return; - } -} diff --git a/src/scenes/add_server_wizard/add_server_wizard.h b/src/scenes/add_server_wizard/add_server_wizard.h deleted file mode 100644 index dc205d1..0000000 --- a/src/scenes/add_server_wizard/add_server_wizard.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of Remote Support Desktop - * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp - * Copyright 2021 Daniel Teichmann - * SPDX-License-Identifier: GPL-2.0-or-later - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef ADD_SERVER_WIZARD_H -#define ADD_SERVER_WIZARD_H - -#include - -#include "../../RWADBusAdaptor.h" -#include "../../DBusAPI.h" -#include "../../main_qmladaptor.h" - -class Add_Server_wizard : public QObject -{ - Q_OBJECT -public: - explicit Add_Server_wizard(QObject *parent = nullptr, - MainQMLAdaptor *main_gui = nullptr, - DBusAPI *dbus_api = nullptr); - void add_server(QString host_url, QString host_alias); - -private: - DBusAPI *_dbus_api; - MainQMLAdaptor *_main_gui; - -signals: - void step1Success(); - void step1Failed(QString reason, uint toast_type); - void step2Success(); - void step2Failed(QString reason, uint toast_type); - -public slots: - void processStep1(QString host_url, QString host_alias); - void processStep2(); - - void add_web_app_host_response(QJsonDocument *doc); -}; - -#endif // ADD_SERVER_WIZARD_H diff --git a/src/scenes/remote_control/remote_control_manager.h b/src/scenes/remote_control/remote_control_manager.h index 6f2fbdb..4554724 100644 --- a/src/scenes/remote_control/remote_control_manager.h +++ b/src/scenes/remote_control/remote_control_manager.h @@ -1,5 +1,5 @@ -#ifndef REMOTECONTROLMANAGER_H -#define REMOTECONTROLMANAGER_H +#ifndef REMOTE_CONTROL_MANAGER_H +#define REMOTE_CONTROL_MANAGER_H #include -- cgit v1.2.3