Skip to content

Commit

Permalink
Add new component ListRebootButton
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Feb 6, 2025
1 parent ee27d05 commit b696f23
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 80 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ set (VENUS_QML_MODULE_SOURCES
components/listitems/ListMountStateButton.qml
components/listitems/ListPvInverterPositionRadioButtonGroup.qml
components/listitems/ListEvChargerPositionRadioButtonGroup.qml
components/listitems/ListRebootButton.qml
components/listitems/ListRelayState.qml
components/listitems/ListResetHistory.qml
components/listitems/ListTemperatureRelay.qml
Expand Down
52 changes: 52 additions & 0 deletions components/listitems/ListRebootButton.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
** Copyright (C) 2025 Victron Energy B.V.
** See LICENSE.txt for license information.
*/

import QtQuick
import QtQuick.Controls.impl as CP
import Victron.VenusOS
import QtQuick.Templates as T

ListButton {
id: root

text: CommonWords.reboot
//% "Reboot now"
button.text: qsTrId("settings_reboot_now")
writeAccessLevel: VenusOS.User_AccessType_User
onClicked: Global.dialogLayer.open(confirmRebootDialogComponent)

Component {
id: confirmRebootDialogComponent

ModalWarningDialog {
//% "Press 'OK' to reboot"
title: qsTrId("press_ok_to_reboot")
dialogDoneOptions: VenusOS.ModalDialog_DoneOptions_OkAndCancel
onClosed: {
if (result === T.Dialog.Accepted) {
Global.venusPlatform.reboot()
Qt.callLater(Global.dialogLayer.open, rebootingDialogComponent)
}
}
}
}

Component {
id: rebootingDialogComponent

ModalWarningDialog {
title: BackendConnection.type === BackendConnection.DBusSource
//% "Rebooting..."
? qsTrId("dialoglayer_rebooting")
//% "Device has been rebooted."
: qsTrId("dialoglayer_rebooted")

// On device, dialog cannot be dismissed; just wait until device is rebooted.
dialogDoneOptions: VenusOS.ModalDialog_DoneOptions_OkOnly
footer.enabled: BackendConnection.type !== BackendConnection.DBusSource
footer.opacity: footer.enabled ? 1 : 0
}
}
}
42 changes: 1 addition & 41 deletions pages/settings/PageSettingsGeneral.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import QtQuick
import Victron.VenusOS
import QtQuick.Templates as T

Page {
id: root
Expand Down Expand Up @@ -136,46 +135,7 @@ Page {

SettingsListHeader { }

ListButton {
text: CommonWords.reboot
//% "Reboot now"
button.text: qsTrId("settings_reboot_now")
writeAccessLevel: VenusOS.User_AccessType_User
onClicked: Global.dialogLayer.open(confirmRebootDialogComponent)

Component {
id: confirmRebootDialogComponent

ModalWarningDialog {
//% "Press 'OK' to reboot"
title: qsTrId("press_ok_to_reboot")
dialogDoneOptions: VenusOS.ModalDialog_DoneOptions_OkAndCancel
onClosed: {
if (result === T.Dialog.Accepted) {
Global.venusPlatform.reboot()
Qt.callLater(Global.dialogLayer.open, rebootingDialogComponent)
}
}
}
}

Component {
id: rebootingDialogComponent

ModalWarningDialog {
title: BackendConnection.type === BackendConnection.DBusSource
//% "Rebooting..."
? qsTrId("dialoglayer_rebooting")
//% "Device has been rebooted."
: qsTrId("dialoglayer_rebooted")

// On device, dialog cannot be dismissed; just wait until device is rebooted.
dialogDoneOptions: VenusOS.ModalDialog_DoneOptions_OkOnly
footer.enabled: BackendConnection.type !== BackendConnection.DBusSource
footer.opacity: footer.enabled ? 1 : 0
}
}
}
ListRebootButton { }

SettingsListHeader { }

Expand Down
44 changes: 5 additions & 39 deletions pages/settings/PageSettingsModificationChecks.qml
Original file line number Diff line number Diff line change
Expand Up @@ -334,47 +334,13 @@ Page {
}
}

ListButton {
ListRebootButton {
//% "Reboot now to apply changes"
text: qsTrId("pagesettingsmodificationchecks_reboot_now_to_apply_changes")
//% "Reboot now"
button.text: qsTrId("settings_reboot_now")
writeAccessLevel: VenusOS.User_AccessType_User
preferredVisible: systemHooksState >= 1 && systemHooksState <= 4
onClicked: Global.dialogLayer.open(confirmRebootDialogComponent)

Component {
id: confirmRebootDialogComponent

ModalWarningDialog {
//% "Press 'OK' to reboot"
title: qsTrId("press_ok_to_reboot")
dialogDoneOptions: VenusOS.ModalDialog_DoneOptions_OkAndCancel
onClosed: {
if (result === T.Dialog.Accepted) {
Global.venusPlatform.reboot()
Qt.callLater(Global.dialogLayer.open, rebootingDialogComponent)
}
}
}
}

Component {
id: rebootingDialogComponent

ModalWarningDialog {
title: BackendConnection.type === BackendConnection.DBusSource
//% "Rebooting..."
? qsTrId("dialoglayer_rebooting")
//% "Device has been rebooted."
: qsTrId("dialoglayer_rebooted")

// On device, dialog cannot be dismissed; just wait until device is rebooted.
dialogDoneOptions: VenusOS.ModalDialog_DoneOptions_OkOnly
footer.enabled: BackendConnection.type !== BackendConnection.DBusSource
footer.opacity: footer.enabled ? 1 : 0
}
}
// Show button if
// - Switch is enabled and custom-rc is not present, but rc.local or rcS.local are present
// - Switch is disabled and custom-rc is present
preferredVisible: (enableAllModifications.checked && !(systemHooksState & 16) && ((systemHooksState & 4) || (systemHooksState & 8))) || (!enableAllModifications.checked && (systemHooksState & 16))
}

SettingsListHeader {
Expand Down

0 comments on commit b696f23

Please sign in to comment.