Debian Codegraph @

xbmc/games/controllers/dialogs/GUIDialogButtonCapture.cpp

raw
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 "GUIDialogButtonCapture.h"
10
11 #include "ServiceBroker.h"
12 #include "games/controllers/ControllerIDs.h"
13 #include "input/actions/ActionIDs.h"
14 #include "input/joysticks/JoystickUtils.h"
15 #include "input/joysticks/interfaces/IButtonMap.h"
16 #include "input/keymaps/interfaces/IKeymap.h"
17 #include "messaging/helpers/DialogOKHelper.h"
18 #include "peripherals/Peripherals.h"
19 #include "utils/Variant.h"
20
21 #include <algorithm>
22 #include <iterator>
23
24 using namespace KODI;
25 using namespace GAME;
26
27 CGUIDialogButtonCapture::CGUIDialogButtonCapture() : CThread("ButtonCaptureDlg")
28 {
29 }
30
31 std::string CGUIDialogButtonCapture::ControllerID(void) const
32 {
33 return DEFAULT_CONTROLLER_ID;
34 }
35
36 void CGUIDialogButtonCapture::Show()
37 {
38 if (!IsRunning())
39 {
40 InstallHooks();
41
42 Create();
43
44 bool bAccepted = MESSAGING::HELPERS::ShowOKDialogText(CVariant{GetDialogHeader()},
45 CVariant{GetDialogText()});
46
47 StopThread(false);
48
49 m_captureEvent.Set();
50
51 OnClose(bAccepted);
52
53 RemoveHooks();
54 }
55 }
56
57 void CGUIDialogButtonCapture::Process()
58 {
59 while (!m_bStop)
60 {
61 m_captureEvent.Wait();
62
63 if (m_bStop)
64 break;
65
66 //! @todo Move to rendering thread when there is a rendering thread
67 MESSAGING::HELPERS::UpdateOKDialogText(CVariant{35013}, CVariant{GetDialogText()});
68 }
69 }
70
71 bool CGUIDialogButtonCapture::MapPrimitive(JOYSTICK::IButtonMap* buttonMap,
72 KEYMAP::IKeymap* keymap,
73 const JOYSTICK::CDriverPrimitive& primitive)
74 {
75 if (m_bStop)
76 return false;
77
78 // First check to see if driver primitive closes the dialog
79 if (keymap && keymap->ControllerID() == buttonMap->ControllerID())
80 {
81 std::string feature;
82 if (buttonMap->GetFeature(primitive, feature))
83 {
84 const auto& actions =
85 keymap->GetActions(JOYSTICK::CJoystickUtils::MakeKeyName(feature)).actions;
86 if (!actions.empty())
87 {
88 switch (actions.begin()->actionId)
89 {
90 case ACTION_SELECT_ITEM:
91 case ACTION_NAV_BACK:
92 case ACTION_PREVIOUS_MENU:
93 return false;
94 default:
95 break;
96 }
97 }
98 }
99 }
100
101 return MapPrimitiveInternal(buttonMap, keymap, primitive);
102 }
103
104 void CGUIDialogButtonCapture::InstallHooks(void)
105 {
106 CServiceBroker::GetPeripherals().RegisterJoystickButtonMapper(this);
107 CServiceBroker::GetPeripherals().RegisterObserver(this);
108 }
109
110 void CGUIDialogButtonCapture::RemoveHooks(void)
111 {
112 CServiceBroker::GetPeripherals().UnregisterObserver(this);
113 CServiceBroker::GetPeripherals().UnregisterJoystickButtonMapper(this);
114 }
115
116 void CGUIDialogButtonCapture::Notify(const Observable& obs, const ObservableMessage msg)
117 {
118 switch (msg)
119 {
120 case ObservableMessagePeripheralsChanged:
121 {
122 CServiceBroker::GetPeripherals().UnregisterJoystickButtonMapper(this);
123 CServiceBroker::GetPeripherals().RegisterJoystickButtonMapper(this);
124 break;
125 }
126 default:
127 break;
128 }
129 }