diff options
author | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2021-08-01 02:19:15 +0200 |
---|---|---|
committer | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2021-08-01 02:19:50 +0200 |
commit | 766a90125df68f065495354c20412faf9e1df77a (patch) | |
tree | cdba9fef32fe0b29a74aa9305b38c362db5a1a4e /src | |
parent | d75db83442a01dcd003ea39a5ec61baad7d344a0 (diff) | |
download | RWA.Support.DesktopApp-766a90125df68f065495354c20412faf9e1df77a.tar.gz RWA.Support.DesktopApp-766a90125df68f065495354c20412faf9e1df77a.tar.bz2 RWA.Support.DesktopApp-766a90125df68f065495354c20412faf9e1df77a.zip |
move scenes/Scene_remote_control.qml into scenes/remote_control/Scene_remote_control.qml
Diffstat (limited to 'src')
-rw-r--r-- | src/DBusAPI.cpp | 2 | ||||
-rw-r--r-- | src/main.qml | 2 | ||||
-rw-r--r-- | src/main_qmladaptor.cpp | 57 | ||||
-rw-r--r-- | src/main_qmladaptor.h | 7 | ||||
-rw-r--r-- | src/scenes/Scene_remote_control.qml | 368 | ||||
-rw-r--r-- | src/session.cpp | 34 |
6 files changed, 34 insertions, 436 deletions
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<QObject*> MainQMLAdaptor::getRWAHostModel() { void MainQMLAdaptor::setRWAHostSelected(bool value) { // Find item via 'objectName' - QObject *sidebar_drawer = _engine->rootObjects().takeFirst()->findChild<QObject*>("sidebar_drawer"); + QObject *sidebar_drawer = _engine->rootObjects().takeFirst()-> + findChild<QObject*>("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<QObject*>("server_chooser"); + QObject *server_chooser = _engine->rootObjects().takeFirst()-> + findChild<QObject*>("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<QQuickItem*>("Scene_remote_control"); - QQuickItem *item = scene_remote_control->findChild<QQuickItem*>("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<QQuickItem*>("Scene_remote_control"); - QQuickItem *item = scene_remote_control->findChild<QQuickItem*>("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<QQuickItem*>("Scene_remote_control"); - QQuickItem *item = scene_remote_control->findChild<QQuickItem*>("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<QObject*> *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(); |