diff options
author | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2021-07-02 20:21:39 +0200 |
---|---|---|
committer | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2021-07-02 20:21:39 +0200 |
commit | 2dc27cddbe35ede34431a6fdf7bf931a7c286bc6 (patch) | |
tree | b318725d3b475231b1f355d2ebb11cc03b197382 /src | |
parent | b285492183f105c9a1fd758d6cd2e767262fd995 (diff) | |
download | RWA.Support.DesktopApp-2dc27cddbe35ede34431a6fdf7bf931a7c286bc6.tar.gz RWA.Support.DesktopApp-2dc27cddbe35ede34431a6fdf7bf931a7c286bc6.tar.bz2 RWA.Support.DesktopApp-2dc27cddbe35ede34431a6fdf7bf931a7c286bc6.zip |
Introduce add_server_wizard.{cpp, h}; drop third add_server_wizard scene
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 6 | ||||
-rw-r--r-- | src/scenes/add_server_wizard/Scene_step_1.qml | 32 | ||||
-rw-r--r-- | src/scenes/add_server_wizard/Scene_step_2.qml | 19 | ||||
-rw-r--r-- | src/scenes/add_server_wizard/Scene_step_3.qml | 54 | ||||
-rw-r--r-- | src/scenes/add_server_wizard/add_server_wizard.cpp | 100 | ||||
-rw-r--r-- | src/scenes/add_server_wizard/add_server_wizard.h | 35 |
6 files changed, 188 insertions, 58 deletions
diff --git a/src/main.cpp b/src/main.cpp index 7bb67de..f6408b3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,6 +38,7 @@ #include "RWADBusAdaptor.cpp" #include "session.h" +#include "scenes/add_server_wizard/add_server_wizard.h" #define BUILD_TIME __DATE__ " " __TIME__ @@ -100,5 +101,10 @@ int main(int argc, char *argv[]) { engine.rootObjects().takeFirst(), SLOT(showWindow())); + QScopedPointer<Add_Server_wizard> wizard (new Add_Server_wizard(&app)); + + // Make add_server_wizard available to QML + engine.rootContext()->setContextProperty("add_server_wizard", wizard.data()); + return app.exec(); } diff --git a/src/scenes/add_server_wizard/Scene_step_1.qml b/src/scenes/add_server_wizard/Scene_step_1.qml index 2061db1..2eb6eaa 100644 --- a/src/scenes/add_server_wizard/Scene_step_1.qml +++ b/src/scenes/add_server_wizard/Scene_step_1.qml @@ -2,7 +2,6 @@ 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 /*! @@ -11,13 +10,42 @@ import QtQuick.Controls.Material 2.3 Item { id: scene_server_wizard_step_1 - objectName: "Scene_server_wizard_step_1" + objectName: "Scene_step_1" + + Connections { + target: add_server_wizard + onStep1Success: { + //main_content_push("scenes/add_server_wizard/Scene_step_2.qml", StackView.Transition) + main_content_pop(null) + mainqmladaptor.showToast(qsTr("Successfully added server address."), 5000); + } + } + + Connections { + target: add_server_wizard + onStep1Failed: { + mainqmladaptor.showToast(reason, 3000); + } + } 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) + } + } + Text { color: Material.foreground id: title diff --git a/src/scenes/add_server_wizard/Scene_step_2.qml b/src/scenes/add_server_wizard/Scene_step_2.qml index acc2a20..5cfbe46 100644 --- a/src/scenes/add_server_wizard/Scene_step_2.qml +++ b/src/scenes/add_server_wizard/Scene_step_2.qml @@ -11,7 +11,22 @@ import QtQuick.Controls.Material 2.3 Item { id: scene_server_wizard_step_2 - objectName: "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 @@ -43,7 +58,7 @@ Item { anchors.rightMargin: 10 onClicked: { - main_content_push("scenes/add_server_wizard/Scene_step_3.qml", StackView.Transition) + add_server_wizard.processStep2() } } } diff --git a/src/scenes/add_server_wizard/Scene_step_3.qml b/src/scenes/add_server_wizard/Scene_step_3.qml deleted file mode 100644 index 337537d..0000000 --- a/src/scenes/add_server_wizard/Scene_step_3.qml +++ /dev/null @@ -1,54 +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_3 - objectName: "Scene_server_wizard_step_3" - - Rectangle { - id: rectangle - anchors.fill: parent - color: Material.background - - Text { - color: Material.foreground - id: title - - text: qsTr("Step 3") - 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_step3_button - text: qsTr("<- First step") - anchors.top: parent.top - anchors.left: parent.left - anchors.margins: 10 - - onClicked: { - main_content_pop(null, StackView.Transition) - } - } - } -} - -/*##^## Designer { - D{i:0;autoSize:true;height:480;width:640} -} - ##^##*/ diff --git a/src/scenes/add_server_wizard/add_server_wizard.cpp b/src/scenes/add_server_wizard/add_server_wizard.cpp new file mode 100644 index 0000000..f8d4b7b --- /dev/null +++ b/src/scenes/add_server_wizard/add_server_wizard.cpp @@ -0,0 +1,100 @@ +#include "add_server_wizard.h" +#include "../../RWADBusAdaptor.h" +#include <QDebug> +#include <QtDBus> +#include <QDBusPendingCallWatcher> + +Add_Server_wizard::Add_Server_wizard(QObject *parent) : QObject(parent) { + _initDBus(); + + +} + +bool 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 _add_server(host_url); +} + +bool Add_Server_wizard::processStep2() { + qDebug() << "Processing Step 2 with args: No Args."; + emit step2Failed(tr("The feature 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::_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); + + QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(_add_web_app_host_dbus_replied(QDBusPendingCallWatcher*))); + + return true; +} + +void Add_Server_wizard::_add_web_app_host_dbus_replied(QDBusPendingCallWatcher *call) { + QString result = ""; + + QDBusPendingReply<QString> 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(); + + qDebug() << "Raw JSON from starting session is:" << result.toUtf8().replace('"', ""); + QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8()); + + // Get the QJsonObject + QJsonObject jObject = doc.object(); + QVariantMap mainMap = jObject.toVariantMap(); + + // Status of request + QString request_status = mainMap["status"].toString(); + if (request_status == "success") { + qDebug() << "Successfully started a Session."; + emit step1Success(); + } else { + qCritical() << "An error occured while adding a new host!"; + + QString reason = "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!"); + } else if (type == "duplicate") { + reason = tr("The specified host was already added!"); + } else if (type == "invalid_url") { + reason = tr("The specified host address is not valid!"); + } + emit step1Failed(reason); + } +} diff --git a/src/scenes/add_server_wizard/add_server_wizard.h b/src/scenes/add_server_wizard/add_server_wizard.h new file mode 100644 index 0000000..1feec9b --- /dev/null +++ b/src/scenes/add_server_wizard/add_server_wizard.h @@ -0,0 +1,35 @@ +#ifndef ADD_SERVER_WIZARD_H +#define ADD_SERVER_WIZARD_H + +#include "../../RWADBusAdaptor.h" +#include <QObject> + +class Add_Server_wizard : public QObject +{ + Q_OBJECT +public: + explicit Add_Server_wizard(QObject *parent = nullptr); + +private: + bool _add_server(QString host_url); + bool _add_web_app_host(QString host_url); + + OrgArcticaProjectRWASupportSessionServiceInterface *_dbus_rwa; + void _initDBus(); + +signals: + void step1Success(); + void step1Failed(QString reason); + void step2Success(); + void step2Failed(QString reason); + +public slots: + bool processStep1(QString host_url); + bool 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); +}; + +#endif // ADD_SERVER_WIZARD_H |