Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
Select.h
1/*
2 * Copyright (C) 2005-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#pragma once
10
11#include "../../AddonBase.h"
12#include "../../c-api/gui/dialogs/select.h"
13
14#ifdef __cplusplus
15
16namespace kodi
17{
18namespace gui
19{
20namespace dialogs
21{
22
23//==============================================================================
29//------------------------------------------------------------------------------
30
31//==============================================================================
37typedef struct SSelectionEntry
38{
40 SSelectionEntry() = default;
44 std::string id;
45
47 std::string name;
48
51 bool selected = false;
53//------------------------------------------------------------------------------
54
55//==============================================================================
68namespace Select
69{
70//==============================================================================
106inline int ATTR_DLL_LOCAL Show(const std::string& heading,
107 const std::vector<std::string>& entries,
108 int selected = -1,
109 unsigned int autoclose = 0)
110{
111 using namespace ::kodi::addon;
112 unsigned int size = static_cast<unsigned int>(entries.size());
113 const char** cEntries = (const char**)malloc(size * sizeof(const char**));
114 for (unsigned int i = 0; i < size; ++i)
115 {
116 cEntries[i] = entries[i].c_str();
117 }
118 int ret = CPrivateBase::m_interface->toKodi->kodi_gui->dialogSelect->open(
119 CPrivateBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntries, size, selected,
120 autoclose);
121 free(cEntries);
122 return ret;
123}
124//------------------------------------------------------------------------------
125
126//==============================================================================
165inline int ATTR_DLL_LOCAL Show(const std::string& heading,
166 std::vector<kodi::gui::dialogs::SSelectionEntry>& entries,
167 int selected = -1,
168 unsigned int autoclose = 0)
169{
170 using namespace ::kodi::addon;
171 unsigned int size = static_cast<unsigned int>(entries.size());
172 const char** cEntries = static_cast<const char**>(malloc(size * sizeof(const char*)));
173 for (unsigned int i = 0; i < size; ++i)
174 {
175 cEntries[i] = entries[i].name.c_str();
176 if (selected == -1 && entries[i].selected)
177 selected = i;
178 }
179 int ret = CPrivateBase::m_interface->toKodi->kodi_gui->dialogSelect->open(
180 CPrivateBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntries, size, selected,
181 autoclose);
182 if (ret >= 0)
183 {
184 entries[ret].selected = true;
185 }
186 free(cEntries);
187 return ret;
188}
189//------------------------------------------------------------------------------
190
191//==============================================================================
233inline bool ATTR_DLL_LOCAL
234ShowMultiSelect(const std::string& heading,
235 std::vector<kodi::gui::dialogs::SSelectionEntry>& entries,
236 int autoclose = 0)
237{
238 using namespace ::kodi::addon;
239 unsigned int size = static_cast<unsigned int>(entries.size());
240 const char** cEntryIDs = static_cast<const char**>(malloc(size * sizeof(const char*)));
241 const char** cEntryNames = static_cast<const char**>(malloc(size * sizeof(const char*)));
242 bool* cEntriesSelected = static_cast<bool*>(malloc(size * sizeof(bool)));
243 for (unsigned int i = 0; i < size; ++i)
244 {
245 cEntryIDs[i] = entries[i].id.c_str();
246 cEntryNames[i] = entries[i].name.c_str();
247 cEntriesSelected[i] = entries[i].selected;
248 }
249 bool ret = CPrivateBase::m_interface->toKodi->kodi_gui->dialogSelect->open_multi_select(
250 CPrivateBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntryIDs, cEntryNames,
251 cEntriesSelected, size, autoclose);
252 if (ret)
253 {
254 for (unsigned int i = 0; i < size; ++i)
255 entries[i].selected = cEntriesSelected[i];
256 }
257 free(cEntryNames);
258 free(cEntryIDs);
259 free(cEntriesSelected);
260 return ret;
261}
262//------------------------------------------------------------------------------
263}; // namespace Select
265
266} /* namespace dialogs */
267} /* namespace gui */
268} /* namespace kodi */
269
270#endif /* __cplusplus */
std::string name
Entry name to show on GUI dialog.
Definition Select.h:47
std::string id
Entry identfication string.
Definition Select.h:44
Selection entry structure Used to provide the necessary data for the selection dialog and to declare ...
Definition Select.h:38
int ATTR_DLL_LOCAL Show(const std::string &heading, const std::vector< std::string > &entries, int selected=-1, unsigned int autoclose=0)
Show a selection dialog about given parts.
Definition Select.h:106
bool ATTR_DLL_LOCAL ShowMultiSelect(const std::string &heading, std::vector< kodi::gui::dialogs::SSelectionEntry > &entries, int autoclose=0)
Show a multiple selection dialog about given parts.
Definition Select.h:234