[video] fix selection after changing video or extra art
[xbmc.git] / xbmc / pvr / guilib / PVRGUIActionsParentalControl.cpp
blobab4bfd55759a3dfda412dcf2a2e006acd8c6581f
1 /*
2 * Copyright (C) 2016-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "PVRGUIActionsParentalControl.h"
11 #include "ServiceBroker.h"
12 #include "dialogs/GUIDialogNumeric.h"
13 #include "guilib/LocalizeStrings.h"
14 #include "messaging/helpers/DialogOKHelper.h"
15 #include "pvr/PVRManager.h"
16 #include "pvr/channels/PVRChannel.h"
17 #include "settings/Settings.h"
18 #include "utils/Variant.h"
19 #include "utils/log.h"
21 #include <memory>
22 #include <string>
24 using namespace PVR;
25 using namespace KODI::MESSAGING;
27 CPVRGUIActionsParentalControl::CPVRGUIActionsParentalControl()
28 : m_settings({CSettings::SETTING_PVRPARENTAL_PIN, CSettings::SETTING_PVRPARENTAL_ENABLED})
32 ParentalCheckResult CPVRGUIActionsParentalControl::CheckParentalLock(
33 const std::shared_ptr<const CPVRChannel>& channel) const
35 if (!CServiceBroker::GetPVRManager().IsParentalLocked(channel))
36 return ParentalCheckResult::SUCCESS;
38 ParentalCheckResult ret = CheckParentalPIN();
40 if (ret == ParentalCheckResult::FAILED)
41 CLog::LogF(LOGERROR, "Parental lock verification failed for channel '{}': wrong PIN entered.",
42 channel->ChannelName());
44 return ret;
47 ParentalCheckResult CPVRGUIActionsParentalControl::CheckParentalPIN() const
49 if (!m_settings.GetBoolValue(CSettings::SETTING_PVRPARENTAL_ENABLED))
50 return ParentalCheckResult::SUCCESS;
52 std::string pinCode = m_settings.GetStringValue(CSettings::SETTING_PVRPARENTAL_PIN);
53 if (pinCode.empty())
54 return ParentalCheckResult::SUCCESS;
56 InputVerificationResult ret = CGUIDialogNumeric::ShowAndVerifyInput(
57 pinCode, g_localizeStrings.Get(19262), true); // "Parental control. Enter PIN:"
59 if (ret == InputVerificationResult::SUCCESS)
61 CServiceBroker::GetPVRManager().RestartParentalTimer();
62 return ParentalCheckResult::SUCCESS;
64 else if (ret == InputVerificationResult::FAILED)
66 HELPERS::ShowOKDialogText(CVariant{19264},
67 CVariant{19265}); // "Incorrect PIN", "The entered PIN was incorrect."
68 return ParentalCheckResult::FAILED;
70 else
72 return ParentalCheckResult::CANCELED;