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/DBusAPI.cpp | 351 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 351 insertions(+) create mode 100644 src/DBusAPI.cpp (limited to 'src/DBusAPI.cpp') diff --git a/src/DBusAPI.cpp b/src/DBusAPI.cpp new file mode 100644 index 0000000..0809a51 --- /dev/null +++ b/src/DBusAPI.cpp @@ -0,0 +1,351 @@ +#include "DBusAPI.h" + +/*! + * \class DBusAPI + * \brief The DBusAPI class provides all necessary D-Bus methods and distributes the response via signals. + */ +DBusAPI::DBusAPI() { + _initDBus(); +} + +/*! + * \brief Initializes private _dbus_rwa object. + */ +void DBusAPI::_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!"); +} + +/*! + * \brief Ask the session service to start a session. + * + * \a host RWAHost object which includes all necessary information about a RWA host. + */ +void DBusAPI::start_request(RWAHost *host) { + qDebug() << "Requesting D-Bus service to start a new session on host:" << host->alias(); + + // Make an asynchrous 'start' call (Response will be sent to 'start_reply') + QDBusPendingCall async = _dbus_rwa->asyncCall("start", host->uuid()); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); + + QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(start_reply(QDBusPendingCallWatcher*))); +} + +/*! + * \brief Method gets called when a D-Bus response is ready. + * + * \a call contains the D-Bus response (session service or for example maybe just a error message). + * + * TODO: Example of json input + */ +void DBusAPI::start_reply(QDBusPendingCallWatcher *call) { + QString result = ""; + QDBusPendingReply reply = *call; + if (reply.isError()) { + qDebug() << "D-Bus 'start' request failed, this was the reply:"; + qDebug() << reply.error(); + + emit serviceStartResponse(nullptr); + return; + } else { + result = reply.argumentAt<0>(); + } + call->deleteLater(); + + qDebug() << "Raw JSON from starting session is:" << result.toUtf8().replace('"', ""); + QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8()); + + emit serviceStartResponse(&doc); +} + +/*! + * \brief Ask the session service to stop session #. + * + * \a host RWAHost object which includes all necessary information about a RWA host. + * + * \a session_id Unique identifier for a session in a specific host. + */ +void DBusAPI::stop_request(RWAHost *host, QString session_id) { + bool ok; + long long session_id_number = session_id.toLongLong(&ok); + + // Sanity Check + if(ok == false){ + qWarning() << QString("Unable to parse '%0' as long long!").arg(session_id); + return; + } + + qDebug().noquote() << QString("Requesting D-Bus service to stop " + "session #'%0' on host '%1'") + .arg(session_id) + .arg(host->alias()); + + // Make an asynchrous 'start' call (Response will be sent to 'stop_reply') + QDBusPendingCall async = _dbus_rwa->asyncCall("stop", host->uuid(), session_id_number); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); + + QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(stop_reply(QDBusPendingCallWatcher*))); +} + +/*! + * \brief Method gets called when a D-Bus response is ready. + * + * \a call contains the D-Bus response (session service or for example maybe just a error message). + * + * TODO: Example of json input + */ +void DBusAPI::stop_reply(QDBusPendingCallWatcher *call) { + QString result = ""; + + QDBusPendingReply reply = *call; + if (reply.isError()) { + qDebug() << "D-Bus 'stop' request failed, this was the reply:"; + qDebug() << reply.error(); + + emit serviceStopResponse(nullptr); + } else { + result = reply.argumentAt<0>(); + } + call->deleteLater(); + + qDebug() << "Raw JSON from stopping a session is:" << result.toUtf8().replace('"', ""); + QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8()); + + emit serviceStopResponse(&doc); +} + +/*! + * \brief Ask the session service for status of . + * + * \a host RWAHost object which includes all necessary information about a RWA host. + * + * \a session_id Unique identifier for a session in a specific host. + */ +void DBusAPI::status_request(RWAHost *host, QString session_id) { + bool ok; + long long session_id_number = session_id.toLongLong(&ok); + + // Sanity Check + if(ok == false){ + qWarning() << QString("Unable to parse '%0' as long long!").arg(session_id); + return; + } + + qDebug().noquote() << QString("Requesting D-Bus service for status of session " + "#'%0' on host '%1'").arg(session_id).arg(host->alias()); + + // Make an asynchrous 'start' call (Response will be sent to 'status_reply') + QDBusPendingCall async = _dbus_rwa->asyncCall("status", host->uuid(), session_id_number); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); + + QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(status_reply(QDBusPendingCallWatcher*))); +} + +/*! + * \brief Forces the session service to refresh it's status of and tell us about it then. + * + * \a host RWAHost object which includes all necessary information about a RWA host. + * + * \a session_id Unique identifier for a session in a specific host. + */ +void DBusAPI::refresh_status_request(RWAHost *host, QString session_id) { + bool ok; + long long session_id_number = session_id.toLongLong(&ok); + + // Sanity Check + if(ok == false){ + qWarning() << QString("Unable to parse '%0' as long long!").arg(session_id); + return; + } + + qDebug().noquote() << QString("Requesting D-Bus service for refresh_status of session " + "#'%0' on host '%1'").arg(session_id).arg(host->alias()); + + // Make an asynchrous 'start' call (Response will be sent to 'status_reply') + QDBusPendingCall async = _dbus_rwa->asyncCall("refresh_status", host->uuid(), session_id_number); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); + + QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(status_reply(QDBusPendingCallWatcher*))); +} + +/*! + * \brief Method gets called when a D-Bus response is ready. + * + * \a call contains the D-Bus response (session service or for example maybe just a error message). + * + * TODO: Example of json input + */ +void DBusAPI::status_reply(QDBusPendingCallWatcher *call){ + QString result = ""; + + QDBusPendingReply reply = *call; + if (reply.isError()) { + qDebug() << "D-Bus '(refresh_)status' request failed, this was the reply:"; + qDebug() << reply.error(); + + emit serviceStatusResponse(nullptr); + return; + } else { + result = reply.argumentAt<0>(); + } + call->deleteLater(); + + // Get the QJsonObject + qDebug() << "Raw JSON from a status request for a session is:" << result.toUtf8().replace('"', ""); + QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8()); + + emit serviceStatusResponse(&doc); +} + +/*! + * \brief This method requests the session service to list all RWAHosts. + */ +void DBusAPI::get_web_app_hosts_request() { + qDebug().noquote() << QString("Requesting D-Bus service to list " + "all remote web app hosts"); + + // Make an asynchrous 'get_web_app_hosts' call + // Response will be sent to 'get_web_app_hosts_reply' + QDBusPendingCall async = _dbus_rwa->asyncCall("get_web_app_hosts"); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); + + QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(get_web_app_hosts_reply(QDBusPendingCallWatcher*))); +} + +/*! + * \brief This method requests the session service to add a RWAHost to its configuration files. + * + * \a host_url is the remote web app adress which will be used by the session service to coordinate + * sessions, connections, settings and such. + */ +void DBusAPI::add_web_app_host_request(QString host_url) { + qDebug().noquote() << QString("Requesting D-Bus service to register new " + "remote web app host with url '%0'").arg(host_url); + + // Make an asynchrous 'add_web_app_host' call + // Response will be sent to 'add_web_app_host_reply' + 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_reply(QDBusPendingCallWatcher*))); +} + +/*! + * \brief This method requests the session service to remove a RWAHost from its configuration files. + * + * \a host_uuid Unique identifier which all hosts have. + */ +void DBusAPI::remove_web_app_host_request(QString host_uuid) { + qDebug().noquote() << QString("Requesting D-Bus service to list " + "all remote web app hosts"); + + // Make an asynchrous 'remove_web_app_host' call + // Response will be sent to 'remove_web_app_host_reply' + QDBusPendingCall async = _dbus_rwa->asyncCall("remove_web_app_host", host_uuid); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); + + QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(remove_web_app_host_reply(QDBusPendingCallWatcher*))); +} + +/*! + * \brief Method gets called when a D-Bus response is ready. + * + * \a call contains the D-Bus response (session service or for example maybe just a error message). + * + * TODO: Example of json input + */ +void DBusAPI::get_web_app_hosts_reply(QDBusPendingCallWatcher *call){ + QString result = ""; + + QDBusPendingReply reply = *call; + if (reply.isError()) { + qDebug() << "D-Bus 'get_web_app_hosts' request failed, this was the reply:"; + qDebug() << reply.error(); + + emit serviceGetWebAppHostsResponse(nullptr); + return; + } else { + result = reply.argumentAt<0>(); + } + call->deleteLater(); + + // Get the QJsonObject + qDebug() << "Raw JSON from the remote web app host listing request:" << result.toUtf8().replace('"', ""); + QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8()); + + emit serviceGetWebAppHostsResponse(&doc); +} + +/*! + * \brief Method gets called when a D-Bus response is ready. + * + * \a call contains the D-Bus response (session service or for example maybe just a error message). + * + * TODO: Example of json input + */ +void DBusAPI::add_web_app_host_reply(QDBusPendingCallWatcher *call){ + QString result = ""; + + QDBusPendingReply reply = *call; + if (reply.isError()) { + qDebug() << "D-Bus 'add_web_app_host' request failed, this was the reply:"; + qDebug() << reply.error(); + + emit serviceAddWebAppHostResponse(nullptr); + return; + } else { + result = reply.argumentAt<0>(); + } + call->deleteLater(); + + // Get the QJsonObject + qDebug() << "Raw JSON from the remote web app host register request:" << result.toUtf8().replace('"', ""); + QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8()); + + emit serviceAddWebAppHostResponse(&doc); +} + +/*! + * \brief Method gets called when a D-Bus response is ready. + * + * \a call contains the D-Bus response (session service or for example maybe just a error message). + * + * TODO: Example of json input + */ +void DBusAPI::remove_web_app_host_reply(QDBusPendingCallWatcher *call){ + QString result = ""; + + QDBusPendingReply reply = *call; + if (reply.isError()) { + qDebug() << "D-Bus 'remove_web_app_host' request failed, this was the reply:"; + qDebug() << reply.error(); + + emit serviceRemoveWebAppHostResponse(nullptr); + return; + } else { + result = reply.argumentAt<0>(); + } + call->deleteLater(); + + // Get the QJsonObject + qDebug() << "Raw JSON from the remote web app host deletion request:" << result.toUtf8().replace('"', ""); + QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8()); + + emit serviceRemoveWebAppHostResponse(&doc); +} -- cgit v1.2.3 From 98049d1507a6f2ae232782fd79f4f753ad53eead Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Tue, 6 Jul 2021 20:02:31 +0200 Subject: Fix copyright headers --- qtquickcontrols2.conf | 4 ++-- src/DBusAPI.cpp | 25 +++++++++++++++++++++++++ src/DBusAPI.h | 25 +++++++++++++++++++++++++ src/ListItem.qml | 25 +++++++++++++++++++++++++ src/RWADBusAdaptor.cpp | 25 +++++++++++++++++++++++++ src/RWADBusAdaptor.h | 25 +++++++++++++++++++++++++ src/Toast.qml | 4 ++-- src/ToastManager.qml | 4 ++-- src/main.cpp | 4 ++-- src/main.qml | 4 ++-- src/main_qmladaptor.cpp | 4 ++-- src/main_qmladaptor.h | 4 ++-- src/session.cpp | 4 ++-- src/session.h | 4 ++-- 14 files changed, 143 insertions(+), 18 deletions(-) (limited to 'src/DBusAPI.cpp') diff --git a/qtquickcontrols2.conf b/qtquickcontrols2.conf index e646650..8bcc85b 100644 --- a/qtquickcontrols2.conf +++ b/qtquickcontrols2.conf @@ -1,7 +1,7 @@ # This file is part of Remote Support Desktop # https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp -# Copyright 2020-2021 Daniel Teichmann -# Copyright 2020-2021 Mike Gabriel +# Copyright 2020, 2021 Daniel Teichmann +# Copyright 2020, 2021 Mike Gabriel # SPDX-License-Identifier: GPL-2.0-or-later # # This program is free software; you can redistribute it and/or modify diff --git a/src/DBusAPI.cpp b/src/DBusAPI.cpp index 0809a51..c133910 100644 --- a/src/DBusAPI.cpp +++ b/src/DBusAPI.cpp @@ -1,3 +1,28 @@ +/* + * 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 "DBusAPI.h" /*! diff --git a/src/DBusAPI.h b/src/DBusAPI.h index 1564f57..632a90b 100644 --- a/src/DBusAPI.h +++ b/src/DBusAPI.h @@ -1,3 +1,28 @@ +/* + * 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 DBUSAPI_H #define DBUSAPI_H diff --git a/src/ListItem.qml b/src/ListItem.qml index c69af4b..fa83f4b 100644 --- a/src/ListItem.qml +++ b/src/ListItem.qml @@ -1,3 +1,28 @@ +/* + * 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 . + */ + import QtQuick 2.0 import QtQuick.Controls.Material 2.3 import QtQuick.Controls 2.2 diff --git a/src/RWADBusAdaptor.cpp b/src/RWADBusAdaptor.cpp index 381faca..6c1504e 100644 --- a/src/RWADBusAdaptor.cpp +++ b/src/RWADBusAdaptor.cpp @@ -1,3 +1,28 @@ +/* + * This file is part of Remote Support Desktop + * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp + * Copyright 2020, 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 . + */ + /* * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -i src/RWADBusAdaptor.h -p :src/RWADBusAdaptor.cpp rwa.xml diff --git a/src/RWADBusAdaptor.h b/src/RWADBusAdaptor.h index 741687f..77f4b6c 100644 --- a/src/RWADBusAdaptor.h +++ b/src/RWADBusAdaptor.h @@ -1,3 +1,28 @@ +/* + * This file is part of Remote Support Desktop + * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp + * Copyright 2020, 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 . + */ + /* * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -p src/RWADBusAdaptor.h: rwa.xml diff --git a/src/Toast.qml b/src/Toast.qml index eb65b20..a427d10 100644 --- a/src/Toast.qml +++ b/src/Toast.qml @@ -1,8 +1,8 @@ /* * This file is part of Remote Support Desktop * https://gitlab.das-netzwerkteam.de/RemoteWebApp/remote-support-desktop - * Copyright 2020-2021 Daniel Teichmann - * Copyright 2020-2021 Mike Gabriel + * Copyright 2020, 2021 Daniel Teichmann + * Copyright 2020, 2021 Mike Gabriel * SPDX-License-Identifier: GPL-2.0-or-later * * This program is free software; you can redistribute it and/or modify diff --git a/src/ToastManager.qml b/src/ToastManager.qml index b448905..1acf8d5 100644 --- a/src/ToastManager.qml +++ b/src/ToastManager.qml @@ -1,8 +1,8 @@ /* * This file is part of Remote Support Desktop * https://gitlab.das-netzwerkteam.de/RemoteWebApp/remote-support-desktop - * Copyright 2020-2021 Daniel Teichmann - * Copyright 2020-2021 Mike Gabriel + * Copyright 2020, 2021 Daniel Teichmann + * Copyright 2020, 2021 Mike Gabriel * SPDX-License-Identifier: GPL-2.0-or-later * * This program is free software; you can redistribute it and/or modify diff --git a/src/main.cpp b/src/main.cpp index f23e2c9..213a591 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,8 @@ /* * This file is part of Remote Support Desktop * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp - * Copyright 2020-2021 Daniel Teichmann - * Copyright 2020-2021 Mike Gabriel + * Copyright 2020, 2021 Daniel Teichmann + * Copyright 2020, 2021 Mike Gabriel * SPDX-License-Identifier: GPL-2.0-or-later * * This program is free software; you can redistribute it and/or modify diff --git a/src/main.qml b/src/main.qml index 1981f4f..a9bbed7 100644 --- a/src/main.qml +++ b/src/main.qml @@ -1,8 +1,8 @@ /* * This file is part of Remote Support Desktop * https://gitlab.das-netzwerkteam.de/RemoteWebApp/remote-support-desktop - * Copyright 2020-2021 Daniel Teichmann - * Copyright 2020-2021 Mike Gabriel + * Copyright 2020, 2021 Daniel Teichmann + * Copyright 2020, 2021 Mike Gabriel * SPDX-License-Identifier: GPL-2.0-or-later * * This program is free software; you can redistribute it and/or modify diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 8a54eb3..731efaf 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -1,8 +1,8 @@ /* * This file is part of Remote Support Desktop * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp - * Copyright 2020-2021 Daniel Teichmann - * Copyright 2020-2021 Mike Gabriel + * Copyright 2020, 2021 Daniel Teichmann + * Copyright 2020, 2021 Mike Gabriel * SPDX-License-Identifier: GPL-2.0-or-later * * This program is free software; you can redistribute it and/or modify diff --git a/src/main_qmladaptor.h b/src/main_qmladaptor.h index 4619968..3c6e75b 100644 --- a/src/main_qmladaptor.h +++ b/src/main_qmladaptor.h @@ -1,8 +1,8 @@ /* * This file is part of Remote Support Desktop * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp - * Copyright 2020-2021 Daniel Teichmann - * Copyright 2020-2021 Mike Gabriel + * Copyright 2020, 2021 Daniel Teichmann + * Copyright 2020, 2021 Mike Gabriel * SPDX-License-Identifier: GPL-2.0-or-later * * This program is free software; you can redistribute it and/or modify diff --git a/src/session.cpp b/src/session.cpp index 1ee4eef..4640786 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -1,8 +1,8 @@ /* * This file is part of Remote Support Desktop * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp - * Copyright 2020-2021 Daniel Teichmann - * Copyright 2020-2021 Mike Gabriel + * Copyright 2020, 2021 Daniel Teichmann + * Copyright 2020, 2021 Mike Gabriel * SPDX-License-Identifier: GPL-2.0-or-later * * This program is free software; you can redistribute it and/or modify diff --git a/src/session.h b/src/session.h index 2c534f4..5935919 100644 --- a/src/session.h +++ b/src/session.h @@ -1,8 +1,8 @@ /* * This file is part of Remote Support Desktop * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp - * Copyright 2020-2021 Daniel Teichmann - * Copyright 2020-2021 Mike Gabriel + * Copyright 2020, 2021 Daniel Teichmann + * Copyright 2020, 2021 Mike Gabriel * SPDX-License-Identifier: GPL-2.0-or-later * * This program is free software; you can redistribute it and/or modify -- cgit v1.2.3 From 3b2c865566aea43ab21afadcd34f58db0a5d5ab8 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Tue, 6 Jul 2021 20:25:45 +0200 Subject: DBusAPI: Change critical error to qCritical instead of qDebug. --- src/DBusAPI.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/DBusAPI.cpp') diff --git a/src/DBusAPI.cpp b/src/DBusAPI.cpp index c133910..7f14e4f 100644 --- a/src/DBusAPI.cpp +++ b/src/DBusAPI.cpp @@ -77,8 +77,8 @@ void DBusAPI::start_reply(QDBusPendingCallWatcher *call) { QString result = ""; QDBusPendingReply reply = *call; if (reply.isError()) { - qDebug() << "D-Bus 'start' request failed, this was the reply:"; - qDebug() << reply.error(); + qCritical() << "D-Bus 'start' request failed, this was the reply:"; + qCritical() << reply.error(); emit serviceStartResponse(nullptr); return; @@ -135,8 +135,8 @@ void DBusAPI::stop_reply(QDBusPendingCallWatcher *call) { QDBusPendingReply reply = *call; if (reply.isError()) { - qDebug() << "D-Bus 'stop' request failed, this was the reply:"; - qDebug() << reply.error(); + qCritical() << "D-Bus 'stop' request failed, this was the reply:"; + qCritical() << reply.error(); emit serviceStopResponse(nullptr); } else { @@ -218,8 +218,8 @@ void DBusAPI::status_reply(QDBusPendingCallWatcher *call){ QDBusPendingReply reply = *call; if (reply.isError()) { - qDebug() << "D-Bus '(refresh_)status' request failed, this was the reply:"; - qDebug() << reply.error(); + qCritical() << "D-Bus '(refresh_)status' request failed, this was the reply:"; + qCritical() << reply.error(); emit serviceStatusResponse(nullptr); return; @@ -300,8 +300,8 @@ void DBusAPI::get_web_app_hosts_reply(QDBusPendingCallWatcher *call){ QDBusPendingReply reply = *call; if (reply.isError()) { - qDebug() << "D-Bus 'get_web_app_hosts' request failed, this was the reply:"; - qDebug() << reply.error(); + qCritical() << "D-Bus 'get_web_app_hosts' request failed, this was the reply:"; + qCritical() << reply.error(); emit serviceGetWebAppHostsResponse(nullptr); return; @@ -329,8 +329,8 @@ void DBusAPI::add_web_app_host_reply(QDBusPendingCallWatcher *call){ QDBusPendingReply reply = *call; if (reply.isError()) { - qDebug() << "D-Bus 'add_web_app_host' request failed, this was the reply:"; - qDebug() << reply.error(); + qCritical() << "D-Bus 'add_web_app_host' request failed, this was the reply:"; + qCritical() << reply.error(); emit serviceAddWebAppHostResponse(nullptr); return; @@ -358,8 +358,8 @@ void DBusAPI::remove_web_app_host_reply(QDBusPendingCallWatcher *call){ QDBusPendingReply reply = *call; if (reply.isError()) { - qDebug() << "D-Bus 'remove_web_app_host' request failed, this was the reply:"; - qDebug() << reply.error(); + qCritical() << "D-Bus 'remove_web_app_host' request failed, this was the reply:"; + qCritical() << reply.error(); emit serviceRemoveWebAppHostResponse(nullptr); return; -- 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/DBusAPI.cpp | 22 ++++- src/DBusAPI.h | 2 +- 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 +- 5 files changed, 132 insertions(+), 47 deletions(-) (limited to 'src/DBusAPI.cpp') diff --git a/src/DBusAPI.cpp b/src/DBusAPI.cpp index 7f14e4f..18c5974 100644 --- a/src/DBusAPI.cpp +++ b/src/DBusAPI.cpp @@ -56,6 +56,8 @@ void DBusAPI::_initDBus() { * \a host RWAHost object which includes all necessary information about a RWA host. */ void DBusAPI::start_request(RWAHost *host) { + Q_ASSERT(host != nullptr); + qDebug() << "Requesting D-Bus service to start a new session on host:" << host->alias(); // Make an asynchrous 'start' call (Response will be sent to 'start_reply') @@ -101,6 +103,9 @@ void DBusAPI::start_reply(QDBusPendingCallWatcher *call) { * \a session_id Unique identifier for a session in a specific host. */ void DBusAPI::stop_request(RWAHost *host, QString session_id) { + Q_ASSERT(host != nullptr); + Q_ASSERT(session_id != ""); + bool ok; long long session_id_number = session_id.toLongLong(&ok); @@ -158,6 +163,9 @@ void DBusAPI::stop_reply(QDBusPendingCallWatcher *call) { * \a session_id Unique identifier for a session in a specific host. */ void DBusAPI::status_request(RWAHost *host, QString session_id) { + Q_ASSERT(host != nullptr); + Q_ASSERT(session_id != ""); + bool ok; long long session_id_number = session_id.toLongLong(&ok); @@ -186,6 +194,9 @@ void DBusAPI::status_request(RWAHost *host, QString session_id) { * \a session_id Unique identifier for a session in a specific host. */ void DBusAPI::refresh_status_request(RWAHost *host, QString session_id) { + Q_ASSERT(host != nullptr); + Q_ASSERT(session_id != ""); + bool ok; long long session_id_number = session_id.toLongLong(&ok); @@ -257,13 +268,16 @@ void DBusAPI::get_web_app_hosts_request() { * \a host_url is the remote web app adress which will be used by the session service to coordinate * sessions, connections, settings and such. */ -void DBusAPI::add_web_app_host_request(QString host_url) { +void DBusAPI::add_web_app_host_request(QString host_url, QString host_alias) { + Q_ASSERT(host_url != ""); + Q_ASSERT(host_alias != ""); + qDebug().noquote() << QString("Requesting D-Bus service to register new " - "remote web app host with url '%0'").arg(host_url); + "remote web app host '%0' with url '%1'").arg(host_alias).arg(host_url); // Make an asynchrous 'add_web_app_host' call // Response will be sent to 'add_web_app_host_reply' - QDBusPendingCall async = _dbus_rwa->asyncCall("add_web_app_host", host_url); + QDBusPendingCall async = _dbus_rwa->asyncCall("add_web_app_host", host_url, host_alias); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), @@ -276,6 +290,8 @@ void DBusAPI::add_web_app_host_request(QString host_url) { * \a host_uuid Unique identifier which all hosts have. */ void DBusAPI::remove_web_app_host_request(QString host_uuid) { + Q_ASSERT(host_uuid != ""); + qDebug().noquote() << QString("Requesting D-Bus service to list " "all remote web app hosts"); diff --git a/src/DBusAPI.h b/src/DBusAPI.h index 632a90b..a25fb64 100644 --- a/src/DBusAPI.h +++ b/src/DBusAPI.h @@ -73,7 +73,7 @@ public slots: void get_web_app_hosts_request(); // Add a specific remote web app host using a url to make sure its contactable - void add_web_app_host_request(QString host_url); + void add_web_app_host_request(QString host_url, QString host_alias); // Removes a specific remote web app host using the uuid of a host void remove_web_app_host_request(QString host_uuid); 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 6bea345ecf8a6cc451b2a7434b8294acacfbe0b4 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Thu, 8 Jul 2021 16:42:51 +0200 Subject: At QDBusError: Give the user a hint that the session service is not started. --- src/DBusAPI.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/DBusAPI.cpp') diff --git a/src/DBusAPI.cpp b/src/DBusAPI.cpp index 18c5974..760935b 100644 --- a/src/DBusAPI.cpp +++ b/src/DBusAPI.cpp @@ -82,7 +82,12 @@ void DBusAPI::start_reply(QDBusPendingCallWatcher *call) { qCritical() << "D-Bus 'start' request failed, this was the reply:"; qCritical() << reply.error(); + if (QDBusError::ServiceUnknown == reply.error().type()) { + qCritical() << "The session service was probably just not started!"; + } + emit serviceStartResponse(nullptr); + return; } else { result = reply.argumentAt<0>(); @@ -143,7 +148,13 @@ void DBusAPI::stop_reply(QDBusPendingCallWatcher *call) { qCritical() << "D-Bus 'stop' request failed, this was the reply:"; qCritical() << reply.error(); + if (QDBusError::ServiceUnknown == reply.error().type()) { + qCritical() << "The session service was probably just not started!"; + } + emit serviceStopResponse(nullptr); + + return; } else { result = reply.argumentAt<0>(); } @@ -232,7 +243,12 @@ void DBusAPI::status_reply(QDBusPendingCallWatcher *call){ qCritical() << "D-Bus '(refresh_)status' request failed, this was the reply:"; qCritical() << reply.error(); + if (QDBusError::ServiceUnknown == reply.error().type()) { + qCritical() << "The session service was probably just not started!"; + } + emit serviceStatusResponse(nullptr); + return; } else { result = reply.argumentAt<0>(); @@ -319,7 +335,12 @@ void DBusAPI::get_web_app_hosts_reply(QDBusPendingCallWatcher *call){ qCritical() << "D-Bus 'get_web_app_hosts' request failed, this was the reply:"; qCritical() << reply.error(); + if (QDBusError::ServiceUnknown == reply.error().type()) { + qCritical() << "The session service was probably just not started!"; + } + emit serviceGetWebAppHostsResponse(nullptr); + return; } else { result = reply.argumentAt<0>(); @@ -348,7 +369,12 @@ void DBusAPI::add_web_app_host_reply(QDBusPendingCallWatcher *call){ qCritical() << "D-Bus 'add_web_app_host' request failed, this was the reply:"; qCritical() << reply.error(); + if (QDBusError::ServiceUnknown == reply.error().type()) { + qCritical() << "The session service was probably just not started!"; + } + emit serviceAddWebAppHostResponse(nullptr); + return; } else { result = reply.argumentAt<0>(); @@ -377,7 +403,12 @@ void DBusAPI::remove_web_app_host_reply(QDBusPendingCallWatcher *call){ qCritical() << "D-Bus 'remove_web_app_host' request failed, this was the reply:"; qCritical() << reply.error(); + if (QDBusError::ServiceUnknown == reply.error().type()) { + qCritical() << "The session service was probably just not started!"; + } + emit serviceRemoveWebAppHostResponse(nullptr); + return; } else { result = reply.argumentAt<0>(); -- 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/DBusAPI.cpp | 18 +++++++++--------- src/DBusAPI.h | 3 +-- src/Toast.qml | 13 ++++++++----- src/main.cpp | 19 +++++++++---------- src/main.qml | 17 +++++++++++------ src/main_qmladaptor.cpp | 20 +++++++++++++------- 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 ++++++++++----- 11 files changed, 75 insertions(+), 46 deletions(-) (limited to 'src/DBusAPI.cpp') diff --git a/src/DBusAPI.cpp b/src/DBusAPI.cpp index 760935b..83f38cb 100644 --- a/src/DBusAPI.cpp +++ b/src/DBusAPI.cpp @@ -60,7 +60,7 @@ void DBusAPI::start_request(RWAHost *host) { qDebug() << "Requesting D-Bus service to start a new session on host:" << host->alias(); - // Make an asynchrous 'start' call (Response will be sent to 'start_reply') + // Make an asynchronous 'start' call (Response will be sent to 'start_reply') QDBusPendingCall async = _dbus_rwa->asyncCall("start", host->uuid()); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); @@ -125,7 +125,7 @@ void DBusAPI::stop_request(RWAHost *host, QString session_id) { .arg(session_id) .arg(host->alias()); - // Make an asynchrous 'start' call (Response will be sent to 'stop_reply') + // Make an asynchronous 'stop' call (Response will be sent to 'stop_reply') QDBusPendingCall async = _dbus_rwa->asyncCall("stop", host->uuid(), session_id_number); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); @@ -182,14 +182,14 @@ void DBusAPI::status_request(RWAHost *host, QString session_id) { // Sanity Check if(ok == false){ - qWarning() << QString("Unable to parse '%0' as long long!").arg(session_id); + qWarning().noquote() << QString("Unable to parse session_id '%0' as long long!").arg(session_id); return; } qDebug().noquote() << QString("Requesting D-Bus service for status of session " "#'%0' on host '%1'").arg(session_id).arg(host->alias()); - // Make an asynchrous 'start' call (Response will be sent to 'status_reply') + // Make an asynchronous 'start' call (Response will be sent to 'status_reply') QDBusPendingCall async = _dbus_rwa->asyncCall("status", host->uuid(), session_id_number); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); @@ -213,14 +213,14 @@ void DBusAPI::refresh_status_request(RWAHost *host, QString session_id) { // Sanity Check if(ok == false){ - qWarning() << QString("Unable to parse '%0' as long long!").arg(session_id); + qWarning().noquote() << QString("Unable to parse session_id '%0' as long long!").arg(session_id); return; } qDebug().noquote() << QString("Requesting D-Bus service for refresh_status of session " "#'%0' on host '%1'").arg(session_id).arg(host->alias()); - // Make an asynchrous 'start' call (Response will be sent to 'status_reply') + // Make an asynchronous 'start' call (Response will be sent to 'status_reply') QDBusPendingCall async = _dbus_rwa->asyncCall("refresh_status", host->uuid(), session_id_number); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); @@ -269,7 +269,7 @@ void DBusAPI::get_web_app_hosts_request() { qDebug().noquote() << QString("Requesting D-Bus service to list " "all remote web app hosts"); - // Make an asynchrous 'get_web_app_hosts' call + // Make an asynchronous 'get_web_app_hosts' call // Response will be sent to 'get_web_app_hosts_reply' QDBusPendingCall async = _dbus_rwa->asyncCall("get_web_app_hosts"); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); @@ -291,7 +291,7 @@ void DBusAPI::add_web_app_host_request(QString host_url, QString host_alias) { qDebug().noquote() << QString("Requesting D-Bus service to register new " "remote web app host '%0' with url '%1'").arg(host_alias).arg(host_url); - // Make an asynchrous 'add_web_app_host' call + // Make an asynchronous 'add_web_app_host' call // Response will be sent to 'add_web_app_host_reply' QDBusPendingCall async = _dbus_rwa->asyncCall("add_web_app_host", host_url, host_alias); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); @@ -311,7 +311,7 @@ void DBusAPI::remove_web_app_host_request(QString host_uuid) { qDebug().noquote() << QString("Requesting D-Bus service to list " "all remote web app hosts"); - // Make an asynchrous 'remove_web_app_host' call + // Make an asynchronous 'remove_web_app_host' call // Response will be sent to 'remove_web_app_host_reply' QDBusPendingCall async = _dbus_rwa->asyncCall("remove_web_app_host", host_uuid); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); diff --git a/src/DBusAPI.h b/src/DBusAPI.h index a25fb64..63dbe68 100644 --- a/src/DBusAPI.h +++ b/src/DBusAPI.h @@ -32,8 +32,7 @@ #include "RWAHost.h" #include "RWADBusAdaptor.h" -class DBusAPI : public QObject -{ +class DBusAPI : public QObject { Q_OBJECT public: explicit DBusAPI(); diff --git a/src/Toast.qml b/src/Toast.qml index 60e238c..0de53a9 100644 --- a/src/Toast.qml +++ b/src/Toast.qml @@ -36,7 +36,8 @@ import QtQuick.Controls.Material 2.3 */ /** - * @brief An Android-like timed message text in a box that self-destroys when finished if desired + * @brief An Android-like timed message text in + * a box that self-destroys when finished if desired */ Control { @@ -52,16 +53,18 @@ Control { */ function show(text, duration) { message.text = text; - if (typeof duration !== "undefined") { // checks if parameter was passed + + // checks if parameter was passed + if (typeof duration !== "undefined") { time = Math.max(duration, 2 * fadeTime); - } - else { + } else { time = defaultTime; } animation.start(); } - property bool selfDestroying: false // whether this Toast will self-destroy when it is finished + // whether this Toast will self-destroy when it is finished + property bool selfDestroying: false /** * Private diff --git a/src/main.cpp b/src/main.cpp index bb83d45..7139883 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,13 +40,12 @@ #include "RWADBusAdaptor.cpp" #include "session.h" #include "scenes/add_server_wizard/add_server_wizard.h" +#include "scenes/remote_control/remote_control_manager.h" #include "RWAHostModel.h" #include "RWAHost.h" -#define BUILD_TIME __DATE__ " " __TIME__ - int main(int argc, char *argv[]) { - qDebug() << "This app was built on: " << BUILD_TIME; + qDebug() << "This app was built on: " << __DATE__ << __TIME__; // We don't want users to have multiple instances of this app running QString tmpDirPath = QDir::tempPath() + "/rwa.support.desktopapp"; @@ -85,8 +84,11 @@ int main(int argc, char *argv[]) { QScopedPointer dbus_api (new DBusAPI()); - // Make mainqmladaptor available to QML - QScopedPointer main_gui (new MainQMLAdaptor(&app, &engine, dbus_api.data())); + // Make 'mainqmladaptor' available to QML + QScopedPointer main_gui ( + new MainQMLAdaptor(&app, &engine, dbus_api.data()) + ); + engine.rootContext()->setContextProperty("mainqmladaptor", main_gui.data()); QObject::connect(dbus_api.data(), @@ -100,10 +102,6 @@ int main(int argc, char *argv[]) { if (engine.rootObjects().isEmpty()) return -1; - //QScopedPointer rwa_host (new RWAHost("b9e09715-fe1d-4419-9b57-a0bd5b181ff0", "Lokaler Server", "http://localhost:8000")); - //QScopedPointer session (new Session(&app, main_gui.data(), rwa_host.data())); - //session.data()->start(); - QObject::connect(main_gui.data(), SIGNAL(minimizeWindow()), engine.rootObjects().takeFirst(), @@ -114,7 +112,8 @@ int main(int argc, char *argv[]) { engine.rootObjects().takeFirst(), SLOT(showWindow())); - QObject::connect(engine.rootObjects().takeFirst()->findChild("sidebar_drawer"), + QObject::connect(engine.rootObjects().takeFirst()-> + findChild("sidebar_drawer"), SIGNAL(rwaHostSelected(QString)), main_gui.data(), SLOT(onRwaHostSelected(QString))); diff --git a/src/main.qml b/src/main.qml index 102df11..03f9c5f 100644 --- a/src/main.qml +++ b/src/main.qml @@ -114,7 +114,7 @@ ApplicationWindow { Connections { target: mainqmladaptor - onShowMessageDialogChanged: { + function onShowMessageDialogChanged(show) { message_dialog.visible = show } } @@ -153,21 +153,21 @@ ApplicationWindow { Connections { target: mainqmladaptor - onMessageDialogTextChanged: { + function onMessageDialogTextChanged(text) { message_dialog.text = text } } Connections { target: mainqmladaptor - onMessageDialogTitleChanged: { + function onMessageDialogTitleChanged(title) { message_dialog.title = title } } Connections { target: mainqmladaptor - onMessageDialogIconChanged: { + function onMessageDialogIconChanged(iconindex) { message_dialog.icon = iconindex } } @@ -185,7 +185,9 @@ ApplicationWindow { objectName: "sidebar_drawer" y: top_menu_bar_frame.height - width: !inPortrait ? Math.min(300, Math.max(200, window.width * 0.333)) : (window.width * 0.5) + width: !inPortrait ? + Math.min(300, Math.max(200, window.width * 0.333)) : + (window.width * 0.5) height: window.height - top_menu_bar_frame.height modal: inPortrait @@ -286,7 +288,10 @@ ApplicationWindow { } // Disabled till a RWAHost object is selected. - enabled: sidebar_drawer.rwaHostIsSelected + //enabled: sidebar_drawer.rwaHostIsSelected + + // But remote view is not implemented yet + enabled: false } ListItem { text: " " + qsTr("Add RWA-Server") diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 6d3a60c..7e85157 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -129,8 +129,8 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { if (host_url == "" || host_uuid == "") { // This two values are required and can't be omitted. - QString reason = tr("A host object in the response of D-Bus " - "service lacks a necessary value. (host_url or host_uuid)"); + QString reason = tr("A host object in the response of D-Bus service lacks" + " a necessary value. (host_url or host_uuid)"); qCritical().noquote() << tr("An error occured while adding a new host:") << reason; @@ -162,7 +162,8 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { atLeastOneHostAvailable = true; if (!found) { - qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")).arg(rwa_host->alias()); + qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")) + .arg(rwa_host->alias()); addRWAHost(rwa_host); } } @@ -233,7 +234,8 @@ void MainQMLAdaptor::main_content_pop(QString scene) { QObject *window = _engine->rootObjects().takeFirst(); Q_ASSERT(window != nullptr); - QObject *main_content = _engine->rootObjects().takeFirst()->findChild("main_content"); + QObject *main_content = _engine->rootObjects().takeFirst()-> + findChild("main_content"); Q_ASSERT(main_content != nullptr); QVariant to_cast = main_content->property("currentItem"); @@ -252,17 +254,21 @@ void MainQMLAdaptor::main_content_replace(QString scene) { QObject *window = _engine->rootObjects().takeFirst(); Q_ASSERT(window != nullptr); - QObject *main_content = _engine->rootObjects().takeFirst()->findChild("main_content"); + QObject *main_content = _engine->rootObjects().takeFirst()-> + findChild("main_content"); Q_ASSERT(main_content != nullptr); QVariant to_cast = main_content->property("currentItem"); QObject *obj = qvariant_cast(to_cast); if (obj) { QString scene_add_server_wizard = "Scene_step_1"; - if (!(scene.contains(obj->objectName()) || scene_add_server_wizard.contains(obj->objectName()))) { + if (!(scene.contains(obj->objectName()) || + scene_add_server_wizard.contains(obj->objectName()))) { QVariant arg = QVariant::fromValue(scene); - if(!QMetaObject::invokeMethod(window, "main_content_replace", Q_ARG(QVariant, arg))) + if (!QMetaObject::invokeMethod(window, "main_content_replace", + Q_ARG(QVariant, arg))) { qDebug() << "Failed to invoke replace"; + } } } } 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 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/DBusAPI.cpp | 2 +- src/main.qml | 2 +- src/main_qmladaptor.cpp | 57 +----- src/main_qmladaptor.h | 7 +- src/scenes/Scene_remote_control.qml | 368 ------------------------------------ src/session.cpp | 34 +++- 6 files changed, 34 insertions(+), 436 deletions(-) delete mode 100644 src/scenes/Scene_remote_control.qml (limited to 'src/DBusAPI.cpp') diff --git a/src/DBusAPI.cpp b/src/DBusAPI.cpp index 83f38cb..9a0f8de 100644 --- a/src/DBusAPI.cpp +++ b/src/DBusAPI.cpp @@ -116,7 +116,7 @@ void DBusAPI::stop_request(RWAHost *host, QString session_id) { // Sanity Check if(ok == false){ - qWarning() << QString("Unable to parse '%0' as long long!").arg(session_id); + qWarning().noquote() << QString("Unable to parse session_id '%0' as long long!").arg(session_id); return; } diff --git a/src/main.qml b/src/main.qml index 03f9c5f..4782f4b 100644 --- a/src/main.qml +++ b/src/main.qml @@ -264,7 +264,7 @@ ApplicationWindow { ListItem { text: " " + qsTr("Remote Control") - scene_url: "scenes/Scene_remote_control.qml" + scene_url: "scenes/remote_control/Scene_remote_control.qml" onListItemClick: { header_text.text = qsTr("Allow remote control") if (inPortrait) sidebar_drawer.close() diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index 7e85157..5da0abb 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -81,16 +81,20 @@ QList MainQMLAdaptor::getRWAHostModel() { void MainQMLAdaptor::setRWAHostSelected(bool value) { // Find item via 'objectName' - QObject *sidebar_drawer = _engine->rootObjects().takeFirst()->findChild("sidebar_drawer"); + QObject *sidebar_drawer = _engine->rootObjects().takeFirst()-> + findChild("sidebar_drawer"); if (sidebar_drawer) { sidebar_drawer->setProperty("rwaHostIsSelected", value); } else { qWarning() << "Unable to find 'sidebar_drawer' Item!"; } - QObject *server_chooser = _engine->rootObjects().takeFirst()->findChild("server_chooser"); + QObject *server_chooser = _engine->rootObjects().takeFirst()-> + findChild("server_chooser"); if (server_chooser) { - server_chooser->setProperty("displayText", value ? server_chooser->property("currentText") : tr("No RWA host available!")); + server_chooser->setProperty("displayText", value ? + server_chooser->property("currentText") : + tr("No RWA host available!")); server_chooser->setProperty("enabled", value); } else { qWarning() << "Unable to find 'server_chooser' Item!"; @@ -273,53 +277,6 @@ void MainQMLAdaptor::main_content_replace(QString scene) { } } -bool MainQMLAdaptor::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 MainQMLAdaptor::setConnectButtonChecked(bool checked) { - // Find item via 'objectName' - QQuickItem *scene_remote_control = _engine->rootObjects().at(0)->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 MainQMLAdaptor::setStatus(QString status) { - // Find item via 'objectName' - QQuickItem *scene_remote_control = _engine->rootObjects().at(0)->findChild("Scene_remote_control"); - QQuickItem *item = scene_remote_control->findChild("dbus_api_status_text"); - if (item) { - item->setProperty("text", status); - } else { - qWarning() << "Unable to find 'dbus_api_status_text' Item!"; - return false; - } - - return true; -} - bool MainQMLAdaptor::openMessageDialog(QString title, QString text, QMessageBox::Icon icon) { _messageDialogText = text; _messageDialogTitle = title; diff --git a/src/main_qmladaptor.h b/src/main_qmladaptor.h index d7f1783..9a2f7c3 100644 --- a/src/main_qmladaptor.h +++ b/src/main_qmladaptor.h @@ -59,22 +59,17 @@ class MainQMLAdaptor : public QObject // this makes showMessageDialogIcon available as a QML property Q_PROPERTY(QMessageBox::Icon _messageDialogIcon READ getMessageDialogIcon NOTIFY messageDialogIconChanged) + public: explicit MainQMLAdaptor(QObject *parent, QQmlApplicationEngine *engine = nullptr, DBusAPI *dbus_api = nullptr); void setRWAHostModel(QList *rwa_hosts); - bool setConnectButtonEnabled(bool enabled); - bool setConnectButtonChecked(bool checked); - void main_content_push(QString); void main_content_pop(QString); void main_content_replace(QString); - bool setStatusIndicator(bool active, QColor color = QColor(255,255,255)); - bool setStatus(QString status); - bool openMessageDialog(QString title, QString text, QMessageBox::Icon); QString getMessageDialogTitle(); QString getMessageDialogText(); 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} -} - ##^##*/ diff --git a/src/session.cpp b/src/session.cpp index 32aca7d..a524afe 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -310,22 +310,36 @@ void Session::start_response(QJsonDocument *doc) { emit pinChanged(QString::number(pin)); emit urlChanged(url); emit sessionIDChanged(QString::number(session_id)); -} -void Session::stop() { - _dbus_api->stop_request(_host, this->getSessionID()); + started = true; - // Clear current variables - this->init_vars(); + // Ask status every 1000 millisecond - // Disable connect button to reduce spam. - // And don't enable it as long there is no status update. - // (Or something fails) - _main_gui->setConnectButtonEnabled(false); + QTimer *timer = new QTimer(this); + connect(timer, &QTimer::timeout, this, + QOverload<>::of(&Session::statusTimerEvent)); + timer->start(1000); + + qDebug() << "Successfully started a session."; + this->setStatus("start_session_success"); + + emit startSucceeded(); +} + +void Session::stop() { + if (started) + _dbus_api->stop_request(getHost(), getSessionID()); } void Session::stop_response(QJsonDocument *doc) { - Q_ASSERT(doc != nullptr); + // Q_ASSERT lets the program crash immediatly after method call + // when the session service is not started. + // Don't use Q_ASSERT(doc != nullptr); instead use: + if (doc == nullptr) { + emit stopFailed(tr("Can't connect to underlying session service! " + "Is the session service started?")); + return; + } QJsonObject jObject = doc->object(); QVariantMap mainMap = jObject.toVariantMap(); -- cgit v1.2.3