aboutsummaryrefslogtreecommitdiff
path: root/src/scenes/add_server_wizard/add_server_wizard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/scenes/add_server_wizard/add_server_wizard.cpp')
-rw-r--r--src/scenes/add_server_wizard/add_server_wizard.cpp133
1 files changed, 77 insertions, 56 deletions
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 <daniel.teichmann@das-netzwerkteam.de>
+ * 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 <https://www.gnu.org/licenses/>.
+ */
+
#include <QDebug>
#include <QtDBus>
#include <QDBusPendingCallWatcher>
-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<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();
+ 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<RWAHost> 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;
}
}