Add support for restarting nymea in the settings
This commit is contained in:
parent
26cda609c2
commit
24dddd6c4c
@ -76,14 +76,19 @@ bool SystemController::updateManagementAvailable() const
|
|||||||
return m_updateManagementAvailable;
|
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
|
bool SystemController::updateManagementBusy() const
|
||||||
@ -293,6 +298,27 @@ void SystemController::setTimeResponse(const QVariantMap ¶ms)
|
|||||||
qDebug() << "set time response" << params;
|
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)
|
void SystemController::notificationReceived(const QVariantMap &data)
|
||||||
{
|
{
|
||||||
QString notification = data.value("notification").toString();
|
QString notification = data.value("notification").toString();
|
||||||
|
|||||||
@ -64,8 +64,9 @@ public:
|
|||||||
QString nameSpace() const override;
|
QString nameSpace() const override;
|
||||||
|
|
||||||
bool powerManagementAvailable() const;
|
bool powerManagementAvailable() const;
|
||||||
Q_INVOKABLE void reboot();
|
Q_INVOKABLE int restart();
|
||||||
Q_INVOKABLE void shutdown();
|
Q_INVOKABLE int reboot();
|
||||||
|
Q_INVOKABLE int shutdown();
|
||||||
|
|
||||||
bool updateManagementAvailable() const;
|
bool updateManagementAvailable() const;
|
||||||
bool updateManagementBusy() const;
|
bool updateManagementBusy() const;
|
||||||
@ -99,6 +100,10 @@ signals:
|
|||||||
void automaticTimeAvailableChanged();
|
void automaticTimeAvailableChanged();
|
||||||
void automaticTimeChanged();
|
void automaticTimeChanged();
|
||||||
|
|
||||||
|
void restartReply(int id, bool success);
|
||||||
|
void rebootReply(int id, bool success);
|
||||||
|
void shutdownReply(int id, bool success);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void getCapabilitiesResponse(const QVariantMap &data);
|
void getCapabilitiesResponse(const QVariantMap &data);
|
||||||
void getUpdateStatusResponse(const QVariantMap &data);
|
void getUpdateStatusResponse(const QVariantMap &data);
|
||||||
@ -108,6 +113,9 @@ private slots:
|
|||||||
void enableRepositoryResponse(const QVariantMap ¶ms);
|
void enableRepositoryResponse(const QVariantMap ¶ms);
|
||||||
void getServerTimeResponse(const QVariantMap ¶ms);
|
void getServerTimeResponse(const QVariantMap ¶ms);
|
||||||
void setTimeResponse(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);
|
void notificationReceived(const QVariantMap &data);
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,30 @@ import "../components"
|
|||||||
SettingsPageBase {
|
SettingsPageBase {
|
||||||
id: root
|
id: root
|
||||||
title: qsTr("General settings")
|
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 {
|
SettingsPageSectionHeader {
|
||||||
text: qsTr("General")
|
text: qsTr("General")
|
||||||
@ -200,7 +223,30 @@ SettingsPageBase {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.leftMargin: app.margins
|
Layout.leftMargin: app.margins
|
||||||
Layout.rightMargin: 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
|
visible: engine.systemController.powerManagementAvailable
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var dialog = Qt.createComponent(Qt.resolvedUrl("../components/MeaDialog.qml"));
|
var dialog = Qt.createComponent(Qt.resolvedUrl("../components/MeaDialog.qml"));
|
||||||
@ -214,7 +260,7 @@ SettingsPageBase {
|
|||||||
});
|
});
|
||||||
popup.open();
|
popup.open();
|
||||||
popup.accepted.connect(function() {
|
popup.accepted.connect(function() {
|
||||||
engine.systemController.reboot()
|
d.pendingCommand = engine.systemController.reboot()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,7 +268,7 @@ SettingsPageBase {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.leftMargin: app.margins
|
Layout.leftMargin: app.margins
|
||||||
Layout.rightMargin: 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
|
visible: engine.systemController.powerManagementAvailable
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var dialog = Qt.createComponent(Qt.resolvedUrl("../components/MeaDialog.qml"));
|
var dialog = Qt.createComponent(Qt.resolvedUrl("../components/MeaDialog.qml"));
|
||||||
@ -236,7 +282,7 @@ SettingsPageBase {
|
|||||||
});
|
});
|
||||||
popup.open();
|
popup.open();
|
||||||
popup.accepted.connect(function() {
|
popup.accepted.connect(function() {
|
||||||
engine.systemController.shutdown()
|
d.pendingCommand = engine.systemController.shutdown()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user