diff options
| author | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
| commit | be933ef2241d79558f91796cc5b3a161f72ebf9c (patch) | |
| tree | fe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Select.h | |
| parent | 5f8335c1e49ce108ef3481863833c98efa00411b (diff) | |
| download | kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2 kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip | |
sync with upstream
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Select.h')
| -rw-r--r-- | xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Select.h | 269 |
1 files changed, 269 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Select.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Select.h new file mode 100644 index 0000000..9b1923e --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Select.h | |||
| @@ -0,0 +1,269 @@ | |||
| 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 | |||
| 16 | namespace kodi | ||
| 17 | { | ||
| 18 | namespace gui | ||
| 19 | { | ||
| 20 | namespace dialogs | ||
| 21 | { | ||
| 22 | |||
| 23 | //============================================================================== | ||
| 24 | /// @defgroup cpp_kodi_gui_dialogs_Select_Defs Definitions, structures and enumerators | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs_Select | ||
| 26 | /// @brief **Dialog Select definition values**\n | ||
| 27 | /// Data structures associated with this dialog. | ||
| 28 | /// | ||
| 29 | //------------------------------------------------------------------------------ | ||
| 30 | |||
| 31 | //============================================================================== | ||
| 32 | /// @ingroup cpp_kodi_gui_dialogs_Select_Defs | ||
| 33 | /// @brief **Selection entry structure**\n | ||
| 34 | /// Used to provide the necessary data for the selection dialog and to declare | ||
| 35 | /// the selected position in it. | ||
| 36 | /// | ||
| 37 | typedef struct SSelectionEntry | ||
| 38 | { | ||
| 39 | /*! \cond PRIVATE */ | ||
| 40 | SSelectionEntry() = default; | ||
| 41 | /*! \endcond */ | ||
| 42 | |||
| 43 | /// Entry identfication string | ||
| 44 | std::string id; | ||
| 45 | |||
| 46 | /// Entry name to show on GUI dialog | ||
| 47 | std::string name; | ||
| 48 | |||
| 49 | /// Place where entry can be preselected and after return the from user | ||
| 50 | /// selected is set. | ||
| 51 | bool selected = false; | ||
| 52 | } SSelectionEntry; | ||
| 53 | //------------------------------------------------------------------------------ | ||
| 54 | |||
| 55 | //============================================================================== | ||
| 56 | /// @defgroup cpp_kodi_gui_dialogs_Select Dialog Select | ||
| 57 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 58 | /// @{ | ||
| 59 | /// @brief @cpp_namespace{ kodi::gui::dialogs::Select } | ||
| 60 | /// **Selection dialog**\n | ||
| 61 | /// The function listed below permits the call of a dialogue to select of an | ||
| 62 | /// entry as a key | ||
| 63 | /// | ||
| 64 | /// It has the header @ref Select.h "#include <kodi/gui/dialogs/Select.h>" | ||
| 65 | /// be included to enjoy it. | ||
| 66 | /// | ||
| 67 | /// | ||
| 68 | namespace Select | ||
| 69 | { | ||
| 70 | //============================================================================== | ||
| 71 | /// @ingroup cpp_kodi_gui_dialogs_Select | ||
| 72 | /// @brief Show a selection dialog about given parts. | ||
| 73 | /// | ||
| 74 | /// @param[in] heading Dialog heading name | ||
| 75 | /// @param[in] entries String list about entries | ||
| 76 | /// @param[in] selected [opt] Predefined selection (default is <tt>-1</tt> for | ||
| 77 | /// the first) | ||
| 78 | /// @param[in] autoclose [opt] To close dialog automatic after the given time | ||
| 79 | /// in ms. As '0' it stays open. | ||
| 80 | /// @return The selected entry, if return <tt>-1</tt> was nothing selected or | ||
| 81 | /// canceled | ||
| 82 | /// | ||
| 83 | /// | ||
| 84 | ///------------------------------------------------------------------------- | ||
| 85 | /// | ||
| 86 | /// **Example:** | ||
| 87 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 88 | /// #include <kodi/gui/dialogs/Select.h> | ||
| 89 | /// | ||
| 90 | /// const std::vector<std::string> entries | ||
| 91 | /// { | ||
| 92 | /// "Test 1", | ||
| 93 | /// "Test 2", | ||
| 94 | /// "Test 3", | ||
| 95 | /// "Test 4", | ||
| 96 | /// "Test 5" | ||
| 97 | /// }; | ||
| 98 | /// | ||
| 99 | /// int selected = kodi::gui::dialogs::Select::Show("Test selection", entries, -1); | ||
| 100 | /// if (selected < 0) | ||
| 101 | /// fprintf(stderr, "Item selection canceled\n"); | ||
| 102 | /// else | ||
| 103 | /// fprintf(stderr, "Selected item is: %i\n", selected); | ||
| 104 | /// ~~~~~~~~~~~~~ | ||
| 105 | /// | ||
| 106 | inline int ATTRIBUTE_HIDDEN 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 = CAddonBase::m_interface->toKodi->kodi_gui->dialogSelect->open( | ||
| 119 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntries, size, selected, | ||
| 120 | autoclose); | ||
| 121 | free(cEntries); | ||
| 122 | return ret; | ||
| 123 | } | ||
| 124 | //------------------------------------------------------------------------------ | ||
| 125 | |||
| 126 | //============================================================================== | ||
| 127 | /// @ingroup cpp_kodi_gui_dialogs_Select | ||
| 128 | /// @brief Show a selection dialog about given parts. | ||
| 129 | /// | ||
| 130 | /// This function is mostly equal to the other, only becomes the string list | ||
| 131 | /// here done by a @ref SSelectionEntry, where a ID string can be defined. | ||
| 132 | /// | ||
| 133 | /// @param[in] heading Dialog heading name | ||
| 134 | /// @param[in] entries @ref SSelectionEntry list about entries | ||
| 135 | /// @param[in] selected [opt] Predefined selection (default is <tt>-1</tt> for | ||
| 136 | /// the first) | ||
| 137 | /// @param[in] autoclose [opt] To close dialog automatic after the given time | ||
| 138 | /// in ms. As '0' it stays open. | ||
| 139 | /// @return The selected entry, if return <tt>-1</tt> was nothing selected | ||
| 140 | /// or canceled | ||
| 141 | /// | ||
| 142 | /// | ||
| 143 | ///------------------------------------------------------------------------- | ||
| 144 | /// | ||
| 145 | /// **Example:** | ||
| 146 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 147 | /// #include <kodi/gui/dialogs/Select.h> | ||
| 148 | /// | ||
| 149 | /// std::vector<kodi::gui::dialogs::SSelectionEntry> entries | ||
| 150 | /// { | ||
| 151 | /// { "ID 1", "Test 1", false }, | ||
| 152 | /// { "ID 2", "Test 2", false }, | ||
| 153 | /// { "ID 3", "Test 3", false }, | ||
| 154 | /// { "ID 4", "Test 4", false }, | ||
| 155 | /// { "ID 5", "Test 5", false } | ||
| 156 | /// }; | ||
| 157 | /// | ||
| 158 | /// int selected = kodi::gui::dialogs::Select::Show("Test selection", entries, -1); | ||
| 159 | /// if (selected < 0) | ||
| 160 | /// fprintf(stderr, "Item selection canceled\n"); | ||
| 161 | /// else | ||
| 162 | /// fprintf(stderr, "Selected item is: %i\n", selected); | ||
| 163 | /// ~~~~~~~~~~~~~ | ||
| 164 | /// | ||
| 165 | inline int ATTRIBUTE_HIDDEN 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 = CAddonBase::m_interface->toKodi->kodi_gui->dialogSelect->open( | ||
| 180 | CAddonBase::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 | //============================================================================== | ||
| 192 | /// @ingroup cpp_kodi_gui_dialogs_Select | ||
| 193 | /// @brief Show a multiple selection dialog about given parts. | ||
| 194 | /// | ||
| 195 | /// @param[in] heading Dialog heading name | ||
| 196 | /// @param[in] entries @ref SSelectionEntry list about entries | ||
| 197 | /// @param[in] autoclose [opt] To close dialog automatic after the given time in | ||
| 198 | /// ms. As '0' it stays open. | ||
| 199 | /// @return The selected entries, if return <tt>empty</tt> was nothing selected | ||
| 200 | /// or canceled | ||
| 201 | /// | ||
| 202 | /// With selected on @ref SSelectionEntry can be a pre selection defined. | ||
| 203 | /// | ||
| 204 | ///------------------------------------------------------------------------- | ||
| 205 | /// | ||
| 206 | /// **Example:** | ||
| 207 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 208 | /// #include <kodi/gui/dialogs/Select.h> | ||
| 209 | /// | ||
| 210 | /// std::vector<kodi::gui::dialogs::SSelectionEntry> entries | ||
| 211 | /// { | ||
| 212 | /// { "ID 1", "Test 1", false }, | ||
| 213 | /// { "ID 2", "Test 2", false }, | ||
| 214 | /// { "ID 3", "Test 3", false }, | ||
| 215 | /// { "ID 4", "Test 4", false }, | ||
| 216 | /// { "ID 5", "Test 5", false } | ||
| 217 | /// }; | ||
| 218 | /// | ||
| 219 | /// bool ret = kodi::gui::dialogs::Select::ShowMultiSelect("Test selection", entries); | ||
| 220 | /// if (!ret) | ||
| 221 | /// fprintf(stderr, "Selection canceled\n"); | ||
| 222 | /// else | ||
| 223 | /// { | ||
| 224 | /// fprintf(stderr, "Selected items:\n"); | ||
| 225 | /// for (const auto& entry : entries) | ||
| 226 | /// { | ||
| 227 | /// if (entry.selected) | ||
| 228 | /// fprintf(stderr, " - %s\n", entry.selected.id.c_str()); | ||
| 229 | /// } | ||
| 230 | /// } | ||
| 231 | /// ~~~~~~~~~~~~~ | ||
| 232 | /// | ||
| 233 | inline bool ATTRIBUTE_HIDDEN ShowMultiSelect(const std::string& heading, | ||
| 234 | std::vector<kodi::gui::dialogs::SSelectionEntry>& entries, | ||
| 235 | int autoclose = 0) | ||
| 236 | { | ||
| 237 | using namespace ::kodi::addon; | ||
| 238 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 239 | const char** cEntryIDs = static_cast<const char**>(malloc(size * sizeof(const char*))); | ||
| 240 | const char** cEntryNames = static_cast<const char**>(malloc(size * sizeof(const char*))); | ||
| 241 | bool* cEntriesSelected = static_cast<bool*>(malloc(size * sizeof(bool))); | ||
| 242 | for (unsigned int i = 0; i < size; ++i) | ||
| 243 | { | ||
| 244 | cEntryIDs[i] = entries[i].id.c_str(); | ||
| 245 | cEntryNames[i] = entries[i].name.c_str(); | ||
| 246 | cEntriesSelected[i] = entries[i].selected; | ||
| 247 | } | ||
| 248 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogSelect->open_multi_select( | ||
| 249 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntryIDs, cEntryNames, | ||
| 250 | cEntriesSelected, size, autoclose); | ||
| 251 | if (ret) | ||
| 252 | { | ||
| 253 | for (unsigned int i = 0; i < size; ++i) | ||
| 254 | entries[i].selected = cEntriesSelected[i]; | ||
| 255 | } | ||
| 256 | free(cEntryNames); | ||
| 257 | free(cEntryIDs); | ||
| 258 | free(cEntriesSelected); | ||
| 259 | return ret; | ||
| 260 | } | ||
| 261 | //------------------------------------------------------------------------------ | ||
| 262 | }; // namespace Select | ||
| 263 | /// @} | ||
| 264 | |||
| 265 | } /* namespace dialogs */ | ||
| 266 | } /* namespace gui */ | ||
| 267 | } /* namespace kodi */ | ||
| 268 | |||
| 269 | #endif /* __cplusplus */ | ||
