From ec002d60587626080f593b8551bfef582d9308f5 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Wed, 29 Dec 2021 22:24:31 +0100 Subject: [PATCH] ChangeValueDisplays now have ConfirmInterface and ErrorHandlerInterface --- src/actions/setvalueaction.h | 19 ++++++++++++------- src/changevaluedisplay_bool.cpp | 4 ++-- src/changevaluedisplay_bool.h | 6 ++++-- src/changevaluedisplay_daylightsavingmode.cpp | 6 +++--- src/changevaluedisplay_daylightsavingmode.h | 6 ++++-- src/changevaluedisplay_sntp_sync_mode_t.cpp | 4 ++-- src/changevaluedisplay_sntp_sync_mode_t.h | 6 ++++-- src/changevaluedisplay_wifi_auth_mode_t.cpp | 18 +++++++++--------- src/changevaluedisplay_wifi_auth_mode_t.h | 6 ++++-- src/changevaluedisplay_wifi_mode_t.cpp | 8 ++++---- src/changevaluedisplay_wifi_mode_t.h | 6 ++++-- 11 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/actions/setvalueaction.h b/src/actions/setvalueaction.h index 23726b1..27ee39b 100644 --- a/src/actions/setvalueaction.h +++ b/src/actions/setvalueaction.h @@ -3,25 +3,29 @@ // local includes #include "actioninterface.h" #include "accessorinterface.h" +#include "confirminterface.h" +#include "errorhandlerinterface.h" namespace espgui { template class SetValueAction : public virtual ActionInterface { public: - SetValueAction(T value, AccessorInterface &accessorInterface, ActionInterface &actionInterface) : + SetValueAction(T value,AccessorInterface &accessorInterface, + ConfirmInterface &confirmInterface, ErrorHandlerInterface &errorHandlerInterface) : m_value{value}, m_accessorInterface{accessorInterface}, - m_actionInterface{actionInterface} + m_confirmInterface{confirmInterface}, + m_errorHandlerInterface{errorHandlerInterface} { } void triggered() override { - // TODO: implement error handling and show popup in case of error - m_accessorInterface.setValue(m_value); - - m_actionInterface.triggered(); + if (auto result = m_accessorInterface.setValue(m_value); result) + m_confirmInterface.confirm(); + else + m_errorHandlerInterface.errorOccured(std::move(result).error()); } T value() const { return m_value; } @@ -29,6 +33,7 @@ public: private: const T m_value; AccessorInterface &m_accessorInterface; - ActionInterface &m_actionInterface; + ConfirmInterface &m_confirmInterface; + ErrorHandlerInterface &m_errorHandlerInterface; }; } // namespace espgui diff --git a/src/changevaluedisplay_bool.cpp b/src/changevaluedisplay_bool.cpp index 7d28613..1203510 100644 --- a/src/changevaluedisplay_bool.cpp +++ b/src/changevaluedisplay_bool.cpp @@ -14,8 +14,8 @@ constexpr char TEXT_BACK[] = "Back"; ChangeValueDisplay::ChangeValueDisplay() { - constructMenuItem, StaticText>>(true, *this, *this); - constructMenuItem, StaticText>>(false, *this, *this); + constructMenuItem, StaticText>>(true, *this, *this, *this); + constructMenuItem, StaticText>>(false, *this, *this, *this); constructMenuItem, StaticMenuItemIcon<&icons::back>>>(*this); } diff --git a/src/changevaluedisplay_bool.h b/src/changevaluedisplay_bool.h index e626734..c10836a 100644 --- a/src/changevaluedisplay_bool.h +++ b/src/changevaluedisplay_bool.h @@ -3,7 +3,8 @@ // local includes #include "changevaluedisplay.h" #include "menudisplay.h" -#include "actioninterface.h" +#include "confirminterface.h" +#include "errorhandlerinterface.h" namespace espgui { @@ -11,7 +12,8 @@ template<> class ChangeValueDisplay : public MenuDisplay, public virtual AccessorInterface, - public virtual ActionInterface + public virtual ConfirmInterface, + public virtual ErrorHandlerInterface { using Base = MenuDisplay; diff --git a/src/changevaluedisplay_daylightsavingmode.cpp b/src/changevaluedisplay_daylightsavingmode.cpp index e5f52ca..9604caa 100644 --- a/src/changevaluedisplay_daylightsavingmode.cpp +++ b/src/changevaluedisplay_daylightsavingmode.cpp @@ -23,9 +23,9 @@ constexpr char TEXT_BACK[] = "Back"; ChangeValueDisplay::ChangeValueDisplay() { - constructMenuItem, StaticText>>(espchrono::DayLightSavingMode::None, *this, *this); - constructMenuItem, StaticText>>(espchrono::DayLightSavingMode::EuropeanSummerTime, *this, *this); - constructMenuItem, StaticText>>(espchrono::DayLightSavingMode::UsDaylightTime, *this, *this); + constructMenuItem, StaticText>>(espchrono::DayLightSavingMode::None, *this, *this, *this); + constructMenuItem, StaticText>>(espchrono::DayLightSavingMode::EuropeanSummerTime, *this, *this, *this); + constructMenuItem, StaticText>>(espchrono::DayLightSavingMode::UsDaylightTime, *this, *this, *this); constructMenuItem, StaticMenuItemIcon<&icons::back>>>(*this); } diff --git a/src/changevaluedisplay_daylightsavingmode.h b/src/changevaluedisplay_daylightsavingmode.h index e21a767..e6d95b8 100644 --- a/src/changevaluedisplay_daylightsavingmode.h +++ b/src/changevaluedisplay_daylightsavingmode.h @@ -6,7 +6,8 @@ // local includes #include "changevaluedisplay.h" #include "menudisplay.h" -#include "actioninterface.h" +#include "confirminterface.h" +#include "errorhandlerinterface.h" namespace espgui { @@ -14,7 +15,8 @@ template<> class ChangeValueDisplay : public MenuDisplay, public virtual AccessorInterface, - public virtual ActionInterface + public virtual ConfirmInterface, + public virtual ErrorHandlerInterface { using Base = MenuDisplay; diff --git a/src/changevaluedisplay_sntp_sync_mode_t.cpp b/src/changevaluedisplay_sntp_sync_mode_t.cpp index f64b1ff..cf87196 100644 --- a/src/changevaluedisplay_sntp_sync_mode_t.cpp +++ b/src/changevaluedisplay_sntp_sync_mode_t.cpp @@ -22,8 +22,8 @@ constexpr char TEXT_BACK[] = "Back"; ChangeValueDisplay::ChangeValueDisplay() { - constructMenuItem, StaticText>>(SNTP_SYNC_MODE_IMMED, *this, *this); - constructMenuItem, StaticText>>(SNTP_SYNC_MODE_SMOOTH, *this, *this); + constructMenuItem, StaticText>>(SNTP_SYNC_MODE_IMMED, *this, *this, *this); + constructMenuItem, StaticText>>(SNTP_SYNC_MODE_SMOOTH, *this, *this, *this); constructMenuItem, StaticMenuItemIcon<&icons::back>>>(*this); } diff --git a/src/changevaluedisplay_sntp_sync_mode_t.h b/src/changevaluedisplay_sntp_sync_mode_t.h index 54a2bef..3586fc0 100644 --- a/src/changevaluedisplay_sntp_sync_mode_t.h +++ b/src/changevaluedisplay_sntp_sync_mode_t.h @@ -6,7 +6,8 @@ // local includes #include "changevaluedisplay.h" #include "menudisplay.h" -#include "actioninterface.h" +#include "confirminterface.h" +#include "errorhandlerinterface.h" namespace espgui { @@ -14,7 +15,8 @@ template<> class ChangeValueDisplay : public MenuDisplay, public virtual AccessorInterface, - public virtual ActionInterface + public virtual ConfirmInterface, + public virtual ErrorHandlerInterface { using Base = MenuDisplay; diff --git a/src/changevaluedisplay_wifi_auth_mode_t.cpp b/src/changevaluedisplay_wifi_auth_mode_t.cpp index 9446d39..1e7adb0 100644 --- a/src/changevaluedisplay_wifi_auth_mode_t.cpp +++ b/src/changevaluedisplay_wifi_auth_mode_t.cpp @@ -29,15 +29,15 @@ constexpr char TEXT_BACK[] = "BACK"; ChangeValueDisplay::ChangeValueDisplay() { - constructMenuItem, StaticText>>(WIFI_AUTH_OPEN, *this, *this); - constructMenuItem, StaticText>>(WIFI_AUTH_WEP, *this, *this); - constructMenuItem, StaticText>>(WIFI_AUTH_WPA_PSK, *this, *this); - constructMenuItem, StaticText>>(WIFI_AUTH_WPA2_PSK, *this, *this); - constructMenuItem, StaticText>>(WIFI_AUTH_WPA_WPA2_PSK, *this, *this); - constructMenuItem, StaticText>>(WIFI_AUTH_WPA2_ENTERPRISE, *this, *this); - constructMenuItem, StaticText>>(WIFI_AUTH_WPA3_PSK, *this, *this); - constructMenuItem, StaticText>>(WIFI_AUTH_WPA2_WPA3_PSK, *this, *this); - constructMenuItem, StaticText>>(WIFI_AUTH_WAPI_PSK, *this, *this); + constructMenuItem, StaticText>>(WIFI_AUTH_OPEN, *this, *this, *this); + constructMenuItem, StaticText>>(WIFI_AUTH_WEP, *this, *this, *this); + constructMenuItem, StaticText>>(WIFI_AUTH_WPA_PSK, *this, *this, *this); + constructMenuItem, StaticText>>(WIFI_AUTH_WPA2_PSK, *this, *this, *this); + constructMenuItem, StaticText>>(WIFI_AUTH_WPA_WPA2_PSK, *this, *this, *this); + constructMenuItem, StaticText>>(WIFI_AUTH_WPA2_ENTERPRISE, *this, *this, *this); + constructMenuItem, StaticText>>(WIFI_AUTH_WPA3_PSK, *this, *this, *this); + constructMenuItem, StaticText>>(WIFI_AUTH_WPA2_WPA3_PSK, *this, *this, *this); + constructMenuItem, StaticText>>(WIFI_AUTH_WAPI_PSK, *this, *this, *this); constructMenuItem, StaticMenuItemIcon<&espgui::icons::back>>>(*this); } diff --git a/src/changevaluedisplay_wifi_auth_mode_t.h b/src/changevaluedisplay_wifi_auth_mode_t.h index 48613cf..8ad13c3 100644 --- a/src/changevaluedisplay_wifi_auth_mode_t.h +++ b/src/changevaluedisplay_wifi_auth_mode_t.h @@ -6,7 +6,8 @@ // local includes #include "changevaluedisplay.h" #include "menudisplay.h" -#include "actioninterface.h" +#include "confirminterface.h" +#include "errorhandlerinterface.h" namespace espgui { @@ -14,7 +15,8 @@ template<> class ChangeValueDisplay : public MenuDisplay, public virtual AccessorInterface, - public virtual ActionInterface + public virtual ConfirmInterface, + public virtual ErrorHandlerInterface { using Base = MenuDisplay; diff --git a/src/changevaluedisplay_wifi_mode_t.cpp b/src/changevaluedisplay_wifi_mode_t.cpp index 09682e7..63f6d54 100644 --- a/src/changevaluedisplay_wifi_mode_t.cpp +++ b/src/changevaluedisplay_wifi_mode_t.cpp @@ -24,10 +24,10 @@ constexpr char TEXT_BACK[] = "BACK"; ChangeValueDisplay::ChangeValueDisplay() { - constructMenuItem, StaticText>>(WIFI_MODE_NULL, *this, *this); - constructMenuItem, StaticText>>(WIFI_MODE_STA, *this, *this); - constructMenuItem, StaticText>>(WIFI_MODE_AP, *this, *this); - constructMenuItem, StaticText>>(WIFI_MODE_APSTA, *this, *this); + constructMenuItem, StaticText>>(WIFI_MODE_NULL, *this, *this, *this); + constructMenuItem, StaticText>>(WIFI_MODE_STA, *this, *this, *this); + constructMenuItem, StaticText>>(WIFI_MODE_AP, *this, *this, *this); + constructMenuItem, StaticText>>(WIFI_MODE_APSTA, *this, *this, *this); constructMenuItem, StaticMenuItemIcon<&espgui::icons::back>>>(*this); } diff --git a/src/changevaluedisplay_wifi_mode_t.h b/src/changevaluedisplay_wifi_mode_t.h index 6fb95c5..59fcf38 100644 --- a/src/changevaluedisplay_wifi_mode_t.h +++ b/src/changevaluedisplay_wifi_mode_t.h @@ -6,7 +6,8 @@ // local includes #include "changevaluedisplay.h" #include "menudisplay.h" -#include "actioninterface.h" +#include "confirminterface.h" +#include "errorhandlerinterface.h" namespace espgui { @@ -14,7 +15,8 @@ template<> class ChangeValueDisplay : public MenuDisplay, public virtual AccessorInterface, - public virtual ActionInterface + public virtual ConfirmInterface, + public virtual ErrorHandlerInterface { using Base = MenuDisplay;