From 3c63eb25fbd4c3e98de697e7608890a644622d9c Mon Sep 17 00:00:00 2001 From: Mike Trahearn Date: Mon, 23 Dec 2024 17:56:09 +1000 Subject: [PATCH] Show Popup for "Detect generator at AC input" setting PageSettingsGenerator should correctly shows the existing toast by changing the enabled property to content.enabled so that the button may still be clickable. ListSwitch should be modified to emit its clicked() signal when the content.enabled is false. Fixes #1563 --- components/listitems/core/ListSwitch.qml | 6 +++++- pages/settings/PageSettingsGenerator.qml | 25 +++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/components/listitems/core/ListSwitch.qml b/components/listitems/core/ListSwitch.qml index 873c61b74..eed886f56 100644 --- a/components/listitems/core/ListSwitch.qml +++ b/components/listitems/core/ListSwitch.qml @@ -60,7 +60,11 @@ ListItem { anchors.fill: parent.backgroundRect radius: backgroundRect.radius - onClicked: root._setChecked(!switchItem.checked) + onClicked: if(content.enabled) { + root._setChecked(!switchItem.checked) + } else { + root.clicked() + } } VeQuickItem { diff --git a/pages/settings/PageSettingsGenerator.qml b/pages/settings/PageSettingsGenerator.qml index 4bcdc7119..10b6d0853 100644 --- a/pages/settings/PageSettingsGenerator.qml +++ b/pages/settings/PageSettingsGenerator.qml @@ -84,21 +84,33 @@ Page { } ListSwitch { + id: generatorACInputSwitch + property bool generatorIsSet: acIn1Source.value === 2 || acIn2Source.value === 2 + property ToastNotification toast: null //% "Detect generator at AC input" text: qsTrId("page_settings_generator_detect_generator_at_ac_input") dataItem.uid: settingsBindPrefix + "/Alarms/NoGeneratorAtAcIn" - enabled: dataItem.isValid && (generatorIsSet || checked) + content.enabled: dataItem.isValid && (generatorIsSet || checked) + + Connections { + target: generatorACInputSwitch.toast + function onDismissed() { + generatorACInputSwitch.toast = null + } + } + onClicked: { if (!checked) { + generatorACInputSwitch.toast?.close(true) if (!generatorIsSet) { //% "None of the AC inputs is set to generator. Go to the system setup page and set the correct AC input to generator in order to enable this functionality." - Global.showToastNotification(VenusOS.Notification_Info, qsTrId("page_settings_generator_detect_generator_not_set"), - Theme.animation_generator_detectGeneratorNotSet_toastNotification_autoClose_duration) + generatorACInputSwitch.toast = Global.showToastNotification(VenusOS.Notification_Info, qsTrId("page_settings_generator_detect_generator_not_set"), + Theme.animation_generator_detectGeneratorNotSet_toastNotification_autoClose_duration) } else { //% "An alarm will be triggered when no power from the generator is detected at the inverter AC input. Make sure that the correct AC input is set to generator on the system setup page." - Global.showToastNotification(VenusOS.Notification_Info, qsTrId("page_settings_generator_detect_generator_set"), - Theme.animation_generator_detectGeneratorSet_toastNotification_autoClose_duration) + generatorACInputSwitch.toast = Global.showToastNotification(VenusOS.Notification_Info, qsTrId("page_settings_generator_detect_generator_set"), + Theme.animation_generator_detectGeneratorSet_toastNotification_autoClose_duration) } } } @@ -124,7 +136,7 @@ Page { if (!checked) { //% "An alarm will be triggered when autostart function is left disabled for more than 10 minutes" Global.notificationLayer.showToastNotification(VenusOS.Notification_Info, - qsTrId("page_settings_generator_alarm_info"), 12000) + qsTrId("page_settings_generator_alarm_info"), 12000) } } } @@ -155,4 +167,3 @@ Page { } } } -