| 1 |
/* |
| 2 |
* Copyright (C) 2016-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "GUIFeatureButton.h" |
| 10 |
|
| 11 |
#include "ServiceBroker.h" |
| 12 |
#include "games/controllers/windows/GUIControllerDefines.h" |
| 13 |
#include "guilib/GUIMessage.h" |
| 14 |
#include "guilib/WindowIDs.h" |
| 15 |
#include "messaging/ApplicationMessenger.h" |
| 16 |
#include "threads/Event.h" |
| 17 |
#include "utils/StringUtils.h" |
| 18 |
|
| 19 |
using namespace KODI; |
| 20 |
using namespace GAME; |
| 21 |
using namespace std::chrono_literals; |
| 22 |
|
| 23 |
CGUIFeatureButton::CGUIFeatureButton(const CGUIButtonControl& buttonTemplate, |
| 24 |
IConfigurationWizard* wizard, |
| 25 |
const CPhysicalFeature& feature, |
| 26 |
unsigned int index) |
| 27 |
: CGUIButtonControl(buttonTemplate), m_feature(feature), m_wizard(wizard) |
| 28 |
{ |
| 29 |
// Initialize CGUIButtonControl |
| 30 |
SetLabel(m_feature.Label()); |
| 31 |
SetID(CONTROL_FEATURE_BUTTONS_START + index); |
| 32 |
SetVisible(true); |
| 33 |
AllocResources(); |
| 34 |
} |
| 35 |
|
| 36 |
void CGUIFeatureButton::OnUnFocus(void) |
| 37 |
{ |
| 38 |
CGUIButtonControl::OnUnFocus(); |
| 39 |
m_wizard->OnUnfocus(this); |
| 40 |
} |
| 41 |
|
| 42 |
bool CGUIFeatureButton::DoPrompt(const std::string& strPrompt, |
| 43 |
const std::string& strWarn, |
| 44 |
const std::string& strFeature, |
| 45 |
CEvent& waitEvent) |
| 46 |
{ |
| 47 |
bool bInterrupted = false; |
| 48 |
|
| 49 |
if (!HasFocus()) |
| 50 |
{ |
| 51 |
CGUIMessage msgFocus(GUI_MSG_SETFOCUS, GetID(), GetID()); |
| 52 |
CServiceBroker::GetAppMessenger()->SendGUIMessage(msgFocus, WINDOW_INVALID, false); |
| 53 |
} |
| 54 |
|
| 55 |
CGUIMessage msgLabel(GUI_MSG_LABEL_SET, GetID(), GetID()); |
| 56 |
|
| 57 |
for (unsigned int i = 0; i < COUNTDOWN_DURATION_SEC; i++) |
| 58 |
{ |
| 59 |
const unsigned int secondsElapsed = i; |
| 60 |
const unsigned int secondsRemaining = COUNTDOWN_DURATION_SEC - i; |
| 61 |
|
| 62 |
const bool bWarn = secondsElapsed >= WAIT_TO_WARN_SEC; |
| 63 |
|
| 64 |
std::string strLabel; |
| 65 |
|
| 66 |
if (bWarn) |
| 67 |
strLabel = StringUtils::Format(strWarn, strFeature, secondsRemaining); |
| 68 |
else |
| 69 |
strLabel = StringUtils::Format(strPrompt, strFeature, secondsRemaining); |
| 70 |
|
| 71 |
msgLabel.SetLabel(strLabel); |
| 72 |
CServiceBroker::GetAppMessenger()->SendGUIMessage(msgLabel, WINDOW_INVALID, false); |
| 73 |
|
| 74 |
waitEvent.Reset(); |
| 75 |
bInterrupted = waitEvent.Wait(1000ms); // Wait 1 second |
| 76 |
|
| 77 |
if (bInterrupted) |
| 78 |
break; |
| 79 |
} |
| 80 |
|
| 81 |
// Reset label |
| 82 |
msgLabel.SetLabel(m_feature.Label()); |
| 83 |
CServiceBroker::GetAppMessenger()->SendGUIMessage(msgLabel, WINDOW_INVALID, false); |
| 84 |
|
| 85 |
return bInterrupted; |
| 86 |
} |