aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Teichmann <daniel.teichmann@das-netzwerkteam.de>2020-07-29 17:45:34 +0200
committerDaniel Teichmann <daniel.teichmann@das-netzwerkteam.de>2020-07-29 17:45:34 +0200
commit8a67a7b1a78084fed6934e44f72a02153e99e6bb (patch)
treedc07666ace2d0b8f06a4eceb43b4f25c4ee779b4 /src
parent4168bcb67de27e85ebbffc4f9f3ef3fdbdc3fd8e (diff)
downloadRWA.Support.DesktopApp-8a67a7b1a78084fed6934e44f72a02153e99e6bb.tar.gz
RWA.Support.DesktopApp-8a67a7b1a78084fed6934e44f72a02153e99e6bb.tar.bz2
RWA.Support.DesktopApp-8a67a7b1a78084fed6934e44f72a02153e99e6bb.zip
Renamed dbus request functions && Add features to comply with API
Diffstat (limited to 'src')
-rw-r--r--src/session.cpp99
-rw-r--r--src/session.h13
2 files changed, 76 insertions, 36 deletions
diff --git a/src/session.cpp b/src/session.cpp
index 55360ef..9b308cd 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -114,6 +114,30 @@ void Session::setStatus(QString status) {
} else if (status == "waiting_start_request_answer") {
/* When pressing on start button display following message while waiting */
guiString = tr("Trying to reach session service...");
+ } else if (status == "start_session_error") {
+ /* Session couldn't be started */
+ guiString = tr("Remote Support session couldn't be started!");
+ _main_gui->setStatusIndicator(true, QColor(255, 0, 0, 127));
+
+ _main_gui->showToast(tr("An error occured while trying to start a session!"));
+ } else if (status == "start_session_success") {
+ /* Session successfully started */
+ guiString = tr("Remote Support session successfully started!");
+ _main_gui->setStatusIndicator(true, QColor(255, 255, 0, 127));
+
+ _main_gui->showToast(tr("Session was started successfully"));
+ } else if (status == "status_session_error") {
+ _main_gui->showToast(tr("Session status could not be refreshed!"));
+ guiString = tr("Session status could not be refreshed, remote support partner could still be connected!");
+ _main_gui->setStatusIndicator(true, QColor(255, 0, 0, 127));
+
+ emit _main_gui->showWindow();
+ } else if (status == "stop_session_error") {
+ _main_gui->showToast(tr("Session could not be stopped!"));
+ guiString = tr("Session could not be stopped, remote support partner could still be connected!");
+ _main_gui->setStatusIndicator(true, QColor(255, 0, 0, 127));
+
+ emit _main_gui->showWindow();
}
_main_gui->setStatus(guiString);
@@ -140,11 +164,11 @@ void Session::handleConnectButtonClick(bool checked) {
qDebug() << "-----Connect button handler-----\nCurrent session #" << this->getId();
// Stopping even if nothing is running
- this->stop(this->getId());
+ this->stop_request_dbus(this->getId());
if (checked) {
// Start the Session again
- this->start();
+ this->start_request_dbus();
}
qDebug() << "-----\\Connect button handler-----";
}
@@ -161,7 +185,7 @@ void Session::_initDBus() {
qDebug("Initialized DBus object!");
}
-void Session::start() {
+void Session::start_request_dbus() {
qDebug() << "Requesting D-Bus session service to start a new session";
// Make an asynchrous 'start' call (Response will be sent to 'start_dbus_replied')
@@ -183,15 +207,14 @@ void Session::start_dbus_replied(QDBusPendingCallWatcher *call) {
QDBusPendingReply<QString> reply = *call;
if (reply.isError()) {
- qCritical("Error: cannot parse 'start' reply from D-Bus service");
- qDebug() << "The reply" << reply.error();
+ qDebug() << "D-Bus 'start' request failed, this was the reply:";
+ qDebug() << reply.error();
// The user should have the oportunity to try again.
this->init_vars();
- _main_gui->openMessageDialog(tr("Remote Support for your Desktop"),
- tr("D-Bus response was invalid.\nFunction call: '%1'\nMaybe service isn't listening?").arg("start"),
- QMessageBox::Icon::Critical);
+ qCritical() << "An error occured while creating a new session!";
+ this->setStatus("start_session_error");
return;
} else {
@@ -206,6 +229,21 @@ void Session::start_dbus_replied(QDBusPendingCallWatcher *call) {
QJsonObject jObject = doc.object();
QVariantMap mainMap = jObject.toVariantMap();
+ // Status of request
+ QString request_status = mainMap["status"].toString();
+ if (request_status == "success") {
+ qDebug() << "Successfully started a Session.";
+ this->setStatus("start_session_success");
+
+ // Immediately ask for the status of the session
+ QTimer::singleShot(0, this, &Session::statusTimerEvent);
+ } else {
+ qCritical() << "An error occured while creating a new session!";
+ this->init_vars();
+ this->setStatus("start_session_error");
+ return;
+ }
+
// Session ID == PID
int sessionid = mainMap["id"].toInt();
this->setId(sessionid);
@@ -222,15 +260,12 @@ void Session::start_dbus_replied(QDBusPendingCallWatcher *call) {
qDebug() << "Got url:" << url;
qDebug() << "Got pin:" << pin;
- this->getStatus();
emit pinChanged(pin);
emit urlChanged(url);
emit idChanged(sessionid);
-
- statusTimer->start(1000);
}
-void Session::stop(int pid) {
+void Session::stop_request_dbus(int pid) {
if (pid <= 0 ){
qDebug() << "Won't send a request to D-Bus service to stop a session when session ID <= 0";
return;
@@ -260,14 +295,11 @@ void Session::stop_dbus_replied(QDBusPendingCallWatcher *call) {
QDBusPendingReply<QString> reply = *call;
if (reply.isError()) {
- qCritical("Error: cannot parse 'stop' reply from D-Bus service");
- qDebug() << "The reply" << reply.error();
+ qDebug() << "D-Bus 'stop' request failed, this was the reply:";
+ qDebug() << reply.error();
this->init_vars();
-
- _main_gui->openMessageDialog(tr("Remote Support for your Desktop"),
- tr("D-Bus response was invalid.\nFunction call: '%1'\nMaybe service isn't listening?").arg("stop"),
- QMessageBox::Icon::Critical);
+ this->setStatus("stop_session_error");
return;
} else {
@@ -286,7 +318,12 @@ void Session::stop_dbus_replied(QDBusPendingCallWatcher *call) {
this->init_vars();
}
-void Session::status(int pid) {
+void Session::status_request_dbus(int pid) {
+ if (pid <= 0 ){
+ qDebug() << "Won't send a request to D-Bus service of a session's status when session ID <= 0";
+ return;
+ }
+
// Requesting status now.
qDebug() << "Requesting status for session #" << pid;
@@ -298,7 +335,12 @@ void Session::status(int pid) {
this, SLOT(stop_dbus_replied(QDBusPendingCallWatcher*)));
}
-void Session::refresh_status(int pid) {
+void Session::refresh_status_request_dbus(int pid) {
+ if (pid <= 0 ){
+ qDebug() << "Won't send a request to D-Bus service to refresh the status of a session when session ID <= 0";
+ return;
+ }
+
// Refreshing status
qDebug() << "Requesting status refresh for session #" << pid;
@@ -315,16 +357,13 @@ void Session::status_dbus_replied(QDBusPendingCallWatcher *call) {
QDBusPendingReply<QString> reply = *call;
if (reply.isError()) {
- qCritical("Error: cannot parse 'status' reply from D-Bus service");
- qDebug() << "The reply" << reply.error();
-
- _main_gui->openMessageDialog(tr("Remote Support for your Desktop"),
- tr("D-Bus response was invalid.\nFunction call: '%1'\nMaybe service isn't listening?").arg("status"),
- QMessageBox::Icon::Critical);
+ qDebug() << "D-Bus '(refresh_)status' request failed, this was the reply:";
+ qDebug() << reply.error();
- // Includes stopping status-refreshing timer
this->init_vars();
+ this->setStatus("status_session_error");
+
return;
} else {
result = reply.argumentAt<0>();
@@ -335,8 +374,8 @@ void Session::status_dbus_replied(QDBusPendingCallWatcher *call) {
QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8());
QJsonObject jObject = doc.object();
QVariantMap mainMap = jObject.toVariantMap();
- qDebug() << "Refreshed status:" << mainMap["status"].toString();
- this->setStatus(mainMap["status"].toString());
+ QString new_status = mainMap["status"].toString();
+ qDebug() << "Refreshed status:" << new_status;
// Enable (dis)connect button
_main_gui->setConnectButtonEnabled(true);
@@ -349,5 +388,5 @@ void Session::status_dbus_replied(QDBusPendingCallWatcher *call) {
void Session::onCloseHandler() {
// To cleanup things here
- this->stop(this->getId());
+ this->stop_request_dbus(this->getId());
}
diff --git a/src/session.h b/src/session.h
index 5005cb4..2b39a78 100644
--- a/src/session.h
+++ b/src/session.h
@@ -20,7 +20,6 @@ class Session : public QObject
Q_PROPERTY(QString pin READ getPin NOTIFY pinChanged ) // this makes pin available as a QML property
public:
explicit Session(QObject *parent, MainQMLAdaptor *main_gui = nullptr);
- void init_vars();
QString getStatus();
QString getURL();
@@ -33,18 +32,20 @@ public:
void setPin(QString pin);
// Starts a VNC Session
- void start();
+ void start_request_dbus();
// Refreshes a VNC Session's status
- void refresh_status(int pid);
+ void refresh_status_request_dbus(int pid);
// Stop the Session
- void stop(int pid);
+ void stop_request_dbus(int pid);
// Gets a VNC Session's status
- void status(int pid);
+ void status_request_dbus(int pid);
+ // Returns true if Session is somewhat usable (Running, Alive, etc..)
+ bool isSessionAliveOrRunning(QString status);
protected:
QString _status;
- QTimer *statusTimer;
void statusTimerEvent();
+ void init_vars();
private:
MainQMLAdaptor* _main_gui;
int _id;