diff --git a/libnymea-app/system/systemcontroller.cpp b/libnymea-app/system/systemcontroller.cpp index e52293dc..aeb7565b 100644 --- a/libnymea-app/system/systemcontroller.cpp +++ b/libnymea-app/system/systemcontroller.cpp @@ -76,14 +76,19 @@ bool SystemController::updateManagementAvailable() const return m_updateManagementAvailable; } -void SystemController::reboot() +int SystemController::restart() { - m_jsonRpcClient->sendCommand("System.Reboot"); + return m_jsonRpcClient->sendCommand("System.Restart", this, "restartResponse"); } -void SystemController::shutdown() +int SystemController::reboot() { - m_jsonRpcClient->sendCommand("System.Shutdown"); + return m_jsonRpcClient->sendCommand("System.Reboot", this, "rebootResponse"); +} + +int SystemController::shutdown() +{ + return m_jsonRpcClient->sendCommand("System.Shutdown", this, "shutdownResponse"); } bool SystemController::updateManagementBusy() const @@ -293,6 +298,27 @@ void SystemController::setTimeResponse(const QVariantMap ¶ms) qDebug() << "set time response" << params; } +void SystemController::restartResponse(const QVariantMap ¶ms) +{ + int id = params.value("id").toInt(); + bool success = params.value("params").toMap().value("success").toBool(); + emit restartReply(id, success); +} + +void SystemController::rebootResponse(const QVariantMap ¶ms) +{ + int id = params.value("id").toInt(); + bool success = params.value("params").toMap().value("success").toBool(); + emit rebootReply(id, success); +} + +void SystemController::shutdownResponse(const QVariantMap ¶ms) +{ + int id = params.value("id").toInt(); + bool success = params.value("params").toMap().value("success").toBool(); + emit shutdownReply(id, success); +} + void SystemController::notificationReceived(const QVariantMap &data) { QString notification = data.value("notification").toString(); diff --git a/libnymea-app/system/systemcontroller.h b/libnymea-app/system/systemcontroller.h index 013efe70..c264b7f7 100644 --- a/libnymea-app/system/systemcontroller.h +++ b/libnymea-app/system/systemcontroller.h @@ -64,8 +64,9 @@ public: QString nameSpace() const override; bool powerManagementAvailable() const; - Q_INVOKABLE void reboot(); - Q_INVOKABLE void shutdown(); + Q_INVOKABLE int restart(); + Q_INVOKABLE int reboot(); + Q_INVOKABLE int shutdown(); bool updateManagementAvailable() const; bool updateManagementBusy() const; @@ -99,6 +100,10 @@ signals: void automaticTimeAvailableChanged(); void automaticTimeChanged(); + void restartReply(int id, bool success); + void rebootReply(int id, bool success); + void shutdownReply(int id, bool success); + private slots: void getCapabilitiesResponse(const QVariantMap &data); void getUpdateStatusResponse(const QVariantMap &data); @@ -108,6 +113,9 @@ private slots: void enableRepositoryResponse(const QVariantMap ¶ms); void getServerTimeResponse(const QVariantMap ¶ms); void setTimeResponse(const QVariantMap ¶ms); + void restartResponse(const QVariantMap ¶ms); + void rebootResponse(const QVariantMap ¶ms); + void shutdownResponse(const QVariantMap ¶ms); void notificationReceived(const QVariantMap &data); diff --git a/nymea-app/ui/system/GeneralSettingsPage.qml b/nymea-app/ui/system/GeneralSettingsPage.qml index 7e95c81b..1373ede3 100644 --- a/nymea-app/ui/system/GeneralSettingsPage.qml +++ b/nymea-app/ui/system/GeneralSettingsPage.qml @@ -38,7 +38,30 @@ import "../components" SettingsPageBase { id: root title: qsTr("General settings") + busy: d.pendingCommand !== -1 + QtObject { + id: d + property int pendingCommand: -1 + } + + Connections { + target: engine.systemController + onRestartReply: handleReply(id, success) + onRebootReply: handleReply(id, success) + onShutdownReply: handleReply(id, success) + + function handleReply(id, success) { + if (id === d.pendingCommand) { + d.pendingCommand = -1 + if (!success) { + var component = Qt.createComponent(Qt.resolvedUrl("../components/ErrorDialog.qml")) + var popup = component.createObject(root); + popup.open() + } + } + } + } SettingsPageSectionHeader { text: qsTr("General") @@ -200,7 +223,30 @@ SettingsPageBase { Layout.fillWidth: true Layout.leftMargin: app.margins Layout.rightMargin: app.margins - text: qsTr("Reboot %1:core").arg(app.systemName) + text: qsTr("Restart %1:core").arg(app.systemName) + visible: engine.systemController.powerManagementAvailable && engine.jsonRpcClient.ensureServerVersion("5.1") + onClicked: { + var dialog = Qt.createComponent(Qt.resolvedUrl("../components/MeaDialog.qml")); + var text = qsTr("Are you sure you want to restart %1:core now?").arg(app.systemName) + var popup = dialog.createObject(app, + { + headerIcon: "../images/dialog-warning-symbolic.svg", + title: qsTr("Restart %1:core").arg(app.systemName), + text: text, + standardButtons: Dialog.Ok | Dialog.Cancel + }); + popup.open(); + popup.accepted.connect(function() { + d.pendingCommand = engine.systemController.restart() + }) + } + } + + Button { + Layout.fillWidth: true + Layout.leftMargin: app.margins + Layout.rightMargin: app.margins + text: qsTr("Reboot %1:core system").arg(app.systemName) visible: engine.systemController.powerManagementAvailable onClicked: { var dialog = Qt.createComponent(Qt.resolvedUrl("../components/MeaDialog.qml")); @@ -214,7 +260,7 @@ SettingsPageBase { }); popup.open(); popup.accepted.connect(function() { - engine.systemController.reboot() + d.pendingCommand = engine.systemController.reboot() }) } } @@ -222,7 +268,7 @@ SettingsPageBase { Layout.fillWidth: true Layout.leftMargin: app.margins Layout.rightMargin: app.margins - text: qsTr("Shutdown %1:core").arg(app.systemName) + text: qsTr("Shutdown %1:core system").arg(app.systemName) visible: engine.systemController.powerManagementAvailable onClicked: { var dialog = Qt.createComponent(Qt.resolvedUrl("../components/MeaDialog.qml")); @@ -236,7 +282,7 @@ SettingsPageBase { }); popup.open(); popup.accepted.connect(function() { - engine.systemController.shutdown() + d.pendingCommand = engine.systemController.shutdown() }) } }