diff options
author | Kai Sommerfeld <kai.sommerfeld@gmx.com> | 2022-09-22 23:01:02 +0200 |
---|---|---|
committer | Kai Sommerfeld <kai.sommerfeld@gmx.com> | 2022-09-27 13:17:23 +0200 |
commit | eba8585c4869953523f8cb7b14074fff4ce84414 (patch) | |
tree | 21de264329213a969a70697526ff1e87bbb77911 | |
parent | 30185a737b736945b8c783fe827f12a0b327a131 (diff) |
[PVR] Refactor CPVRGUIActions step 7: Move parental control related actions to own class.
-rw-r--r-- | xbmc/pvr/guilib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | xbmc/pvr/guilib/PVRGUIActions.cpp | 44 | ||||
-rw-r--r-- | xbmc/pvr/guilib/PVRGUIActions.h | 24 | ||||
-rw-r--r-- | xbmc/pvr/guilib/PVRGUIActionsParentalControl.cpp | 74 | ||||
-rw-r--r-- | xbmc/pvr/guilib/PVRGUIActionsParentalControl.h | 52 |
5 files changed, 131 insertions, 65 deletions
diff --git a/xbmc/pvr/guilib/CMakeLists.txt b/xbmc/pvr/guilib/CMakeLists.txt index e1ed26cb51..4f643b8e39 100644 --- a/xbmc/pvr/guilib/CMakeLists.txt +++ b/xbmc/pvr/guilib/CMakeLists.txt @@ -4,6 +4,7 @@ set(SOURCES GUIEPGGridContainer.cpp PVRGUIActions.cpp PVRGUIActionsChannels.cpp PVRGUIActionsEPG.cpp + PVRGUIActionsParentalControl.cpp PVRGUIActionsPlayback.cpp PVRGUIActionsPowerManagement.cpp PVRGUIActionsRecordings.cpp @@ -18,6 +19,7 @@ set(HEADERS GUIEPGGridContainer.h PVRGUIActions.h PVRGUIActionsChannels.h PVRGUIActionsEPG.h + PVRGUIActionsParentalControl.h PVRGUIActionsPlayback.h PVRGUIActionsPowerManagement.h PVRGUIActionsRecordings.h diff --git a/xbmc/pvr/guilib/PVRGUIActions.cpp b/xbmc/pvr/guilib/PVRGUIActions.cpp index 9819667e52..e4a5a8c163 100644 --- a/xbmc/pvr/guilib/PVRGUIActions.cpp +++ b/xbmc/pvr/guilib/PVRGUIActions.cpp @@ -53,8 +53,7 @@ using namespace KODI::MESSAGING; namespace PVR { CPVRGUIActions::CPVRGUIActions() - : m_settings({CSettings::SETTING_PVRMANAGER_PRESELECTPLAYINGCHANNEL, - CSettings::SETTING_PVRPARENTAL_PIN, CSettings::SETTING_PVRPARENTAL_ENABLED}) + : m_settings({CSettings::SETTING_PVRMANAGER_PRESELECTPLAYINGCHANNEL}) { } @@ -414,47 +413,6 @@ CPVRGUIActions::CPVRGUIActions() return true; } - ParentalCheckResult CPVRGUIActions::CheckParentalLock(const std::shared_ptr<CPVRChannel>& channel) const - { - if (!CServiceBroker::GetPVRManager().IsParentalLocked(channel)) - return ParentalCheckResult::SUCCESS; - - ParentalCheckResult ret = CheckParentalPIN(); - - if (ret == ParentalCheckResult::FAILED) - CLog::LogF(LOGERROR, "Parental lock verification failed for channel '{}': wrong PIN entered.", - channel->ChannelName()); - - return ret; - } - - ParentalCheckResult CPVRGUIActions::CheckParentalPIN() const - { - if (!m_settings.GetBoolValue(CSettings::SETTING_PVRPARENTAL_ENABLED)) - return ParentalCheckResult::SUCCESS; - - std::string pinCode = m_settings.GetStringValue(CSettings::SETTING_PVRPARENTAL_PIN); - if (pinCode.empty()) - return ParentalCheckResult::SUCCESS; - - InputVerificationResult ret = CGUIDialogNumeric::ShowAndVerifyInput(pinCode, g_localizeStrings.Get(19262), true); // "Parental control. Enter PIN:" - - if (ret == InputVerificationResult::SUCCESS) - { - CServiceBroker::GetPVRManager().RestartParentalTimer(); - return ParentalCheckResult::SUCCESS; - } - else if (ret == InputVerificationResult::FAILED) - { - HELPERS::ShowOKDialogText(CVariant{19264}, CVariant{19265}); // "Incorrect PIN", "The entered PIN was incorrect." - return ParentalCheckResult::FAILED; - } - else - { - return ParentalCheckResult::CANCELED; - } - } - void CPVRGUIActions::SetSelectedItemPath(bool bRadio, const std::string& path) { std::unique_lock<CCriticalSection> lock(m_critSection); diff --git a/xbmc/pvr/guilib/PVRGUIActions.h b/xbmc/pvr/guilib/PVRGUIActions.h index a1daa35ff4..bf7038afd7 100644 --- a/xbmc/pvr/guilib/PVRGUIActions.h +++ b/xbmc/pvr/guilib/PVRGUIActions.h @@ -10,6 +10,7 @@ #include "pvr/guilib/PVRGUIActionsChannels.h" #include "pvr/guilib/PVRGUIActionsEPG.h" +#include "pvr/guilib/PVRGUIActionsParentalControl.h" #include "pvr/guilib/PVRGUIActionsPlayback.h" #include "pvr/guilib/PVRGUIActionsPowerManagement.h" #include "pvr/guilib/PVRGUIActionsRecordings.h" @@ -24,17 +25,9 @@ class CFileItem; namespace PVR { -enum class ParentalCheckResult -{ - CANCELED, - FAILED, - SUCCESS -}; - -class CPVRChannel; - class CPVRGUIActions : public CPVRGUIActionsChannels, public CPVRGUIActionsEPG, + public CPVRGUIActionsParentalControl, public CPVRGUIActionsPlayback, public CPVRGUIActionsPowerManagement, public CPVRGUIActionsRecordings, @@ -58,19 +51,6 @@ public: bool ResetPVRDatabase(bool bResetEPGOnly); /*! - * @brief Check if channel is parental locked. Ask for PIN if necessary. - * @param channel The channel to do the check for. - * @return the result of the check (success, failed, or canceled by user). - */ - ParentalCheckResult CheckParentalLock(const std::shared_ptr<CPVRChannel>& channel) const; - - /*! - * @brief Open Numeric dialog to check for parental PIN. - * @return the result of the check (success, failed, or canceled by user). - */ - ParentalCheckResult CheckParentalPIN() const; - - /*! * @brief Get the currently selected item path; used across several windows/dialogs to share item selection. * @param bRadio True to query the selected path for PVR radio, false for Live TV. * @return the path. diff --git a/xbmc/pvr/guilib/PVRGUIActionsParentalControl.cpp b/xbmc/pvr/guilib/PVRGUIActionsParentalControl.cpp new file mode 100644 index 0000000000..96947c4381 --- /dev/null +++ b/xbmc/pvr/guilib/PVRGUIActionsParentalControl.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2016-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "PVRGUIActionsParentalControl.h" + +#include "ServiceBroker.h" +#include "dialogs/GUIDialogNumeric.h" +#include "guilib/LocalizeStrings.h" +#include "messaging/helpers/DialogOKHelper.h" +#include "pvr/PVRManager.h" +#include "pvr/channels/PVRChannel.h" +#include "settings/Settings.h" +#include "utils/Variant.h" +#include "utils/log.h" + +#include <memory> +#include <string> + +using namespace PVR; +using namespace KODI::MESSAGING; + +CPVRGUIActionsParentalControl::CPVRGUIActionsParentalControl() + : m_settings({CSettings::SETTING_PVRPARENTAL_PIN, CSettings::SETTING_PVRPARENTAL_ENABLED}) +{ +} + +ParentalCheckResult CPVRGUIActionsParentalControl::CheckParentalLock( + const std::shared_ptr<CPVRChannel>& channel) const +{ + if (!CServiceBroker::GetPVRManager().IsParentalLocked(channel)) + return ParentalCheckResult::SUCCESS; + + ParentalCheckResult ret = CheckParentalPIN(); + + if (ret == ParentalCheckResult::FAILED) + CLog::LogF(LOGERROR, "Parental lock verification failed for channel '{}': wrong PIN entered.", + channel->ChannelName()); + + return ret; +} + +ParentalCheckResult CPVRGUIActionsParentalControl::CheckParentalPIN() const +{ + if (!m_settings.GetBoolValue(CSettings::SETTING_PVRPARENTAL_ENABLED)) + return ParentalCheckResult::SUCCESS; + + std::string pinCode = m_settings.GetStringValue(CSettings::SETTING_PVRPARENTAL_PIN); + if (pinCode.empty()) + return ParentalCheckResult::SUCCESS; + + InputVerificationResult ret = CGUIDialogNumeric::ShowAndVerifyInput( + pinCode, g_localizeStrings.Get(19262), true); // "Parental control. Enter PIN:" + + if (ret == InputVerificationResult::SUCCESS) + { + CServiceBroker::GetPVRManager().RestartParentalTimer(); + return ParentalCheckResult::SUCCESS; + } + else if (ret == InputVerificationResult::FAILED) + { + HELPERS::ShowOKDialogText(CVariant{19264}, + CVariant{19265}); // "Incorrect PIN", "The entered PIN was incorrect." + return ParentalCheckResult::FAILED; + } + else + { + return ParentalCheckResult::CANCELED; + } +} diff --git a/xbmc/pvr/guilib/PVRGUIActionsParentalControl.h b/xbmc/pvr/guilib/PVRGUIActionsParentalControl.h new file mode 100644 index 0000000000..d0ce9f1ee0 --- /dev/null +++ b/xbmc/pvr/guilib/PVRGUIActionsParentalControl.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2016-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "pvr/settings/PVRSettings.h" + +#include <memory> + +namespace PVR +{ +enum class ParentalCheckResult +{ + CANCELED, + FAILED, + SUCCESS +}; + +class CPVRChannel; + +class CPVRGUIActionsParentalControl +{ +public: + CPVRGUIActionsParentalControl(); + virtual ~CPVRGUIActionsParentalControl() = default; + + /*! + * @brief Check if channel is parental locked. Ask for PIN if necessary. + * @param channel The channel to do the check for. + * @return the result of the check (success, failed, or canceled by user). + */ + ParentalCheckResult CheckParentalLock(const std::shared_ptr<CPVRChannel>& channel) const; + + /*! + * @brief Open Numeric dialog to check for parental PIN. + * @return the result of the check (success, failed, or canceled by user). + */ + ParentalCheckResult CheckParentalPIN() const; + +private: + CPVRGUIActionsParentalControl(const CPVRGUIActionsParentalControl&) = delete; + CPVRGUIActionsParentalControl const& operator=(CPVRGUIActionsParentalControl const&) = delete; + + CPVRSettings m_settings; +}; + +} // namespace PVR |