diff options
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/dialogs/Select.h')
| -rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/dialogs/Select.h | 269 |
1 files changed, 0 insertions, 269 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/dialogs/Select.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/dialogs/Select.h deleted file mode 100644 index 39a98fe..0000000 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/dialogs/Select.h +++ /dev/null | |||
| @@ -1,269 +0,0 @@ | |||
| 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 "../definitions.h" | ||
| 12 | #include "../../AddonBase.h" | ||
| 13 | |||
| 14 | //============================================================================== | ||
| 15 | /// \defgroup cpp_kodi_vfs_Defs Definitions, structures and enumerators | ||
| 16 | /// \ingroup cpp_kodi_gui_dialogs_Select | ||
| 17 | /// @brief **Dialog Select definition values** | ||
| 18 | //------------------------------------------------------------------------------ | ||
| 19 | |||
| 20 | //============================================================================== | ||
| 21 | /// \ingroup cpp_kodi_vfs_Defs | ||
| 22 | /// @brief **Selection entry structure** | ||
| 23 | /// | ||
| 24 | typedef struct SSelectionEntry | ||
| 25 | { | ||
| 26 | //============================================================================ | ||
| 27 | /// Structure constructor | ||
| 28 | /// | ||
| 29 | /// There becomes selected always set to false. | ||
| 30 | /// | ||
| 31 | SSelectionEntry() = default; | ||
| 32 | //---------------------------------------------------------------------------- | ||
| 33 | |||
| 34 | /// Entry identfication string | ||
| 35 | std::string id; | ||
| 36 | |||
| 37 | /// Entry name to show on GUI dialog | ||
| 38 | std::string name; | ||
| 39 | |||
| 40 | /// Place where entry can be preselected and after return the from user | ||
| 41 | /// selected is set. | ||
| 42 | bool selected = false; | ||
| 43 | } SSelectionEntry; | ||
| 44 | //------------------------------------------------------------------------------ | ||
| 45 | |||
| 46 | namespace kodi | ||
| 47 | { | ||
| 48 | namespace gui | ||
| 49 | { | ||
| 50 | namespace dialogs | ||
| 51 | { | ||
| 52 | |||
| 53 | //============================================================================ | ||
| 54 | /// | ||
| 55 | /// \defgroup cpp_kodi_gui_dialogs_Select Dialog Select | ||
| 56 | /// \ingroup cpp_kodi_gui | ||
| 57 | /// @{ | ||
| 58 | /// @brief \cpp_namespace{ kodi::gui::dialogs::Select } | ||
| 59 | /// **Selection dialog** | ||
| 60 | /// | ||
| 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 | /// | ||
| 72 | /// \ingroup cpp_kodi_gui_dialogs_Select | ||
| 73 | /// @brief Show a selection dialog about given parts. | ||
| 74 | /// | ||
| 75 | /// @param[in] heading Dialog heading name | ||
| 76 | /// @param[in] entries String list about entries | ||
| 77 | /// @param[in] selected [opt] Predefined selection (default is | ||
| 78 | /// <tt>-1</tt> for the first) | ||
| 79 | /// @param[in] autoclose [opt] To close dialog automatic after the given | ||
| 80 | /// time in ms. As '0' it stays open. | ||
| 81 | /// @return The selected entry, if return <tt>-1</tt> was | ||
| 82 | /// nothing selected or canceled | ||
| 83 | /// | ||
| 84 | /// | ||
| 85 | ///------------------------------------------------------------------------- | ||
| 86 | /// | ||
| 87 | /// **Example:** | ||
| 88 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 89 | /// #include <kodi/gui/dialogs/Select.h> | ||
| 90 | /// | ||
| 91 | /// const std::vector<std::string> entries | ||
| 92 | /// { | ||
| 93 | /// "Test 1", | ||
| 94 | /// "Test 2", | ||
| 95 | /// "Test 3", | ||
| 96 | /// "Test 4", | ||
| 97 | /// "Test 5" | ||
| 98 | /// }; | ||
| 99 | /// | ||
| 100 | /// int selected = kodi::gui::dialogs::Select::Show("Test selection", entries, -1); | ||
| 101 | /// if (selected < 0) | ||
| 102 | /// fprintf(stderr, "Item selection canceled\n"); | ||
| 103 | /// else | ||
| 104 | /// fprintf(stderr, "Selected item is: %i\n", selected); | ||
| 105 | /// ~~~~~~~~~~~~~ | ||
| 106 | /// | ||
| 107 | inline int ATTRIBUTE_HIDDEN Show(const std::string& heading, | ||
| 108 | const std::vector<std::string>& entries, | ||
| 109 | int selected = -1, | ||
| 110 | unsigned int autoclose = 0) | ||
| 111 | { | ||
| 112 | using namespace ::kodi::addon; | ||
| 113 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 114 | const char** cEntries = (const char**)malloc(size * sizeof(const char**)); | ||
| 115 | for (unsigned int i = 0; i < size; ++i) | ||
| 116 | { | ||
| 117 | cEntries[i] = entries[i].c_str(); | ||
| 118 | } | ||
| 119 | int ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogSelect->open( | ||
| 120 | CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), cEntries, size, selected, | ||
| 121 | autoclose); | ||
| 122 | free(cEntries); | ||
| 123 | return ret; | ||
| 124 | } | ||
| 125 | //-------------------------------------------------------------------------- | ||
| 126 | |||
| 127 | //========================================================================== | ||
| 128 | /// | ||
| 129 | /// \ingroup cpp_kodi_gui_dialogs_Select | ||
| 130 | /// @brief Show a selection dialog about given parts. | ||
| 131 | /// | ||
| 132 | /// This function is mostly equal to the other, only becomes the string list | ||
| 133 | /// here done by a SSelectionEntry, where a ID string can be defined. | ||
| 134 | /// | ||
| 135 | /// @param[in] heading Dialog heading name | ||
| 136 | /// @param[in] entries SSelectionEntry list about entries | ||
| 137 | /// @param[in] selected [opt] Predefined selection (default is | ||
| 138 | /// <tt>-1</tt> for the first) | ||
| 139 | /// @param[in] autoclose [opt] To close dialog automatic after the given | ||
| 140 | /// time in ms. As '0' it stays open. | ||
| 141 | /// @return The selected entry, if return <tt>-1</tt> was | ||
| 142 | /// nothing selected or canceled | ||
| 143 | /// | ||
| 144 | /// | ||
| 145 | ///------------------------------------------------------------------------- | ||
| 146 | /// | ||
| 147 | /// **Example:** | ||
| 148 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 149 | /// #include <kodi/gui/dialogs/Select.h> | ||
| 150 | /// | ||
| 151 | /// std::vector<SSelectionEntry> entries | ||
| 152 | /// { | ||
| 153 | /// { "ID 1", "Test 1", false }, | ||
| 154 | /// { "ID 2", "Test 2", false }, | ||
| 155 | /// { "ID 3", "Test 3", false }, | ||
| 156 | /// { "ID 4", "Test 4", false }, | ||
| 157 | /// { "ID 5", "Test 5", false } | ||
| 158 | /// }; | ||
| 159 | /// | ||
| 160 | /// int selected = kodi::gui::dialogs::Select::Show("Test selection", entries, -1); | ||
| 161 | /// if (selected < 0) | ||
| 162 | /// fprintf(stderr, "Item selection canceled\n"); | ||
| 163 | /// else | ||
| 164 | /// fprintf(stderr, "Selected item is: %i\n", selected); | ||
| 165 | /// ~~~~~~~~~~~~~ | ||
| 166 | /// | ||
| 167 | inline int ATTRIBUTE_HIDDEN Show(const std::string& heading, | ||
| 168 | std::vector<SSelectionEntry>& entries, | ||
| 169 | int selected = -1, | ||
| 170 | unsigned int autoclose = 0) | ||
| 171 | { | ||
| 172 | using namespace ::kodi::addon; | ||
| 173 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 174 | const char** cEntries = static_cast<const char**>(malloc(size*sizeof(const char*))); | ||
| 175 | for (unsigned int i = 0; i < size; ++i) | ||
| 176 | { | ||
| 177 | cEntries[i] = entries[i].name.c_str(); | ||
| 178 | if (selected == -1 && entries[i].selected) | ||
| 179 | selected = i; | ||
| 180 | } | ||
| 181 | int ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogSelect->open(CAddonBase::m_interface->toKodi->kodiBase, heading.c_str(), | ||
| 182 | cEntries, size, selected, autoclose); | ||
| 183 | if (ret >= 0) | ||
| 184 | { | ||
| 185 | entries[ret].selected = true; | ||
| 186 | } | ||
| 187 | free(cEntries); | ||
| 188 | return ret; | ||
| 189 | } | ||
| 190 | //-------------------------------------------------------------------------- | ||
| 191 | |||
| 192 | //========================================================================== | ||
| 193 | /// | ||
| 194 | /// \ingroup cpp_kodi_gui_dialogs_Select | ||
| 195 | /// @brief Show a multiple selection dialog about given parts. | ||
| 196 | /// | ||
| 197 | /// @param[in] heading Dialog heading name | ||
| 198 | /// @param[in] entries SSelectionEntry list about entries | ||
| 199 | /// @param[in] autoclose [opt] To close dialog automatic after the given | ||
| 200 | /// time in ms. As '0' it stays open. | ||
| 201 | /// @return The selected entries, if return <tt>empty</tt> was | ||
| 202 | /// nothing selected or canceled | ||
| 203 | /// | ||
| 204 | /// With selected on SSelectionEntry can be a pre selection defined. | ||
| 205 | /// | ||
| 206 | ///------------------------------------------------------------------------- | ||
| 207 | /// | ||
| 208 | /// **Example:** | ||
| 209 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 210 | /// #include <kodi/gui/dialogs/Select.h> | ||
| 211 | /// | ||
| 212 | /// std::vector<SSelectionEntry> entries | ||
| 213 | /// { | ||
| 214 | /// { "ID 1", "Test 1", false }, | ||
| 215 | /// { "ID 2", "Test 2", false }, | ||
| 216 | /// { "ID 3", "Test 3", false }, | ||
| 217 | /// { "ID 4", "Test 4", false }, | ||
| 218 | /// { "ID 5", "Test 5", false } | ||
| 219 | /// }; | ||
| 220 | /// | ||
| 221 | /// bool ret = kodi::gui::dialogs::Select::ShowMultiSelect("Test selection", entries); | ||
| 222 | /// if (!ret) | ||
| 223 | /// fprintf(stderr, "Selection canceled\n"); | ||
| 224 | /// else | ||
| 225 | /// { | ||
| 226 | /// fprintf(stderr, "Selected items:\n"); | ||
| 227 | /// for (const auto& entry : entries) | ||
| 228 | /// { | ||
| 229 | /// if (entry.selected) | ||
| 230 | /// fprintf(stderr, " - %s\n", entry.selected.id.c_str()); | ||
| 231 | /// } | ||
| 232 | /// } | ||
| 233 | /// ~~~~~~~~~~~~~ | ||
| 234 | /// | ||
| 235 | inline bool ATTRIBUTE_HIDDEN ShowMultiSelect(const std::string& heading, | ||
| 236 | std::vector<SSelectionEntry>& entries, | ||
| 237 | int autoclose = 0) | ||
| 238 | { | ||
| 239 | using namespace ::kodi::addon; | ||
| 240 | unsigned int size = static_cast<unsigned int>(entries.size()); | ||
| 241 | const char** cEntryIDs = static_cast<const char**>(malloc(size*sizeof(const char*))); | ||
| 242 | const char** cEntryNames = static_cast<const char**>(malloc(size*sizeof(const char*))); | ||
| 243 | bool* cEntriesSelected = static_cast<bool*>(malloc(size*sizeof(bool))); | ||
| 244 | for (unsigned int i = 0; i < size; ++i) | ||
| 245 | { | ||
| 246 | cEntryIDs[i] = entries[i].id.c_str(); | ||
| 247 | cEntryNames[i] = entries[i].name.c_str(); | ||
| 248 | cEntriesSelected[i] = entries[i].selected; | ||
| 249 | } | ||
| 250 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogSelect->open_multi_select(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 251 | heading.c_str(), cEntryIDs, cEntryNames, | ||
| 252 | cEntriesSelected, size, autoclose); | ||
| 253 | if (ret) | ||
| 254 | { | ||
| 255 | for (unsigned int i = 0; i < size; ++i) | ||
| 256 | entries[i].selected = cEntriesSelected[i]; | ||
| 257 | } | ||
| 258 | free(cEntryNames); | ||
| 259 | free(cEntryIDs); | ||
| 260 | free(cEntriesSelected); | ||
| 261 | return ret; | ||
| 262 | } | ||
| 263 | //-------------------------------------------------------------------------- | ||
| 264 | }; | ||
| 265 | /// @} | ||
| 266 | |||
| 267 | } /* namespace dialogs */ | ||
| 268 | } /* namespace gui */ | ||
| 269 | } /* namespace kodi */ | ||
