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/Keyboard.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/Keyboard.h')
| -rw-r--r-- | xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Keyboard.h | 404 |
1 files changed, 404 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Keyboard.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Keyboard.h new file mode 100644 index 0000000..710b7dd --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Keyboard.h | |||
| @@ -0,0 +1,404 @@ | |||
| 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/keyboard.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_Keyboard Dialog Keyboard | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 26 | /// @brief @cpp_namespace{ kodi::gui::dialogs::Keyboard } | ||
| 27 | /// **Keyboard dialogs**\n | ||
| 28 | /// The functions listed below have to be permitted by the user for the | ||
| 29 | /// representation of a keyboard around an input. | ||
| 30 | /// | ||
| 31 | /// The class supports several kinds, from an easy text choice up to the | ||
| 32 | /// passport Word production and their confirmation for add-on. | ||
| 33 | /// | ||
| 34 | /// It has the header @ref Keyboard.h "#include <kodi/gui/dialogs/Keyboard.h>" | ||
| 35 | /// be included to enjoy it. | ||
| 36 | /// | ||
| 37 | namespace Keyboard | ||
| 38 | { | ||
| 39 | //============================================================================== | ||
| 40 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 41 | /// @brief Show keyboard with initial value `text` and replace with result | ||
| 42 | /// string. | ||
| 43 | /// | ||
| 44 | /// @param[in,out] text Overwritten with user input if return=true. | ||
| 45 | /// @param[in] heading String shown on dialog title. | ||
| 46 | /// @param[in] allowEmptyResult Whether a blank password is valid or not. | ||
| 47 | /// @param[in] hiddenInput [opt] The inserted input is not shown as text. | ||
| 48 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 49 | /// milliseconds, default is 0 which keeps the dialog | ||
| 50 | /// open indefinitely. | ||
| 51 | /// @return true if successful display and user input. false if unsuccessful | ||
| 52 | /// display, no user input, or canceled editing. | ||
| 53 | /// | ||
| 54 | /// | ||
| 55 | ///------------------------------------------------------------------------- | ||
| 56 | /// | ||
| 57 | /// **Example:** | ||
| 58 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 59 | /// #include <kodi/gui/dialogs/Keyboard.h> | ||
| 60 | /// | ||
| 61 | /// // The example shows the display of keyboard call dialog at Kodi from the add-on. | ||
| 62 | /// // Below all values are set, however, can last two (hidden input = false and autoCloseMs = 0) | ||
| 63 | /// // to be released if not needed. | ||
| 64 | /// std::string text = "Please change me to them want you want"; // It can be leaved empty or a entry text added | ||
| 65 | /// bool bRet = ::kodi::gui::dialogs::Keyboard::ShowAndGetInput(text, | ||
| 66 | /// "Demonstration text entry", | ||
| 67 | /// true, | ||
| 68 | /// false, | ||
| 69 | /// 0); | ||
| 70 | /// fprintf(stderr, "Written keyboard input is : '%s' and was %s\n", | ||
| 71 | /// text.c_str(), bRet ? "OK" : "Canceled"); | ||
| 72 | /// ~~~~~~~~~~~~~ | ||
| 73 | /// | ||
| 74 | inline bool ATTRIBUTE_HIDDEN ShowAndGetInput(std::string& text, | ||
| 75 | const std::string& heading, | ||
| 76 | bool allowEmptyResult, | ||
| 77 | bool hiddenInput = false, | ||
| 78 | unsigned int autoCloseMs = 0) | ||
| 79 | { | ||
| 80 | using namespace ::kodi::addon; | ||
| 81 | char* retString = nullptr; | ||
| 82 | bool ret = | ||
| 83 | CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->show_and_get_input_with_head( | ||
| 84 | CAddonBase::m_interface->toKodi->kodiBase, text.c_str(), &retString, heading.c_str(), | ||
| 85 | allowEmptyResult, hiddenInput, autoCloseMs); | ||
| 86 | if (retString != nullptr) | ||
| 87 | { | ||
| 88 | text = retString; | ||
| 89 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 90 | retString); | ||
| 91 | } | ||
| 92 | return ret; | ||
| 93 | } | ||
| 94 | //------------------------------------------------------------------------------ | ||
| 95 | |||
| 96 | //============================================================================== | ||
| 97 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 98 | /// @brief The example shows the display of keyboard call dialog at Kodi | ||
| 99 | /// from the add-on. | ||
| 100 | /// | ||
| 101 | /// @param[out] text Overwritten with user input if return=true. | ||
| 102 | /// @param[in] allowEmptyResult If set to true keyboard can also exited without | ||
| 103 | /// entered text. | ||
| 104 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 105 | /// milliseconds, default is 0 which keeps the dialog | ||
| 106 | /// open indefinitely. | ||
| 107 | /// @return true if successful display and user input. false if unsuccessful | ||
| 108 | /// display, no user input, or canceled editing. | ||
| 109 | /// | ||
| 110 | inline bool ATTRIBUTE_HIDDEN ShowAndGetInput(std::string& text, | ||
| 111 | bool allowEmptyResult, | ||
| 112 | unsigned int autoCloseMs = 0) | ||
| 113 | { | ||
| 114 | using namespace ::kodi::addon; | ||
| 115 | char* retString = nullptr; | ||
| 116 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->show_and_get_input( | ||
| 117 | CAddonBase::m_interface->toKodi->kodiBase, text.c_str(), &retString, allowEmptyResult, | ||
| 118 | autoCloseMs); | ||
| 119 | if (retString != nullptr) | ||
| 120 | { | ||
| 121 | text = retString; | ||
| 122 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 123 | retString); | ||
| 124 | } | ||
| 125 | return ret; | ||
| 126 | } | ||
| 127 | //------------------------------------------------------------------------------ | ||
| 128 | |||
| 129 | //============================================================================== | ||
| 130 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 131 | /// @brief Shows keyboard and prompts for a password. Differs from | ||
| 132 | /// `ShowAndVerifyNewPassword()` in that no second verification. | ||
| 133 | /// | ||
| 134 | /// @param[in,out] newPassword Overwritten with user input if return=true. | ||
| 135 | /// @param[in] heading String shown on dialog title. | ||
| 136 | /// @param[in] allowEmptyResult Whether a blank password is valid or not. | ||
| 137 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 138 | /// milliseconds, default is 0 which keeps the dialog | ||
| 139 | /// open indefinitely. | ||
| 140 | /// @return true if successful display and user input. false if unsuccessful | ||
| 141 | /// display, no user input, or canceled editing. | ||
| 142 | /// | ||
| 143 | inline bool ATTRIBUTE_HIDDEN ShowAndGetNewPassword(std::string& newPassword, | ||
| 144 | const std::string& heading, | ||
| 145 | bool allowEmptyResult, | ||
| 146 | unsigned int autoCloseMs = 0) | ||
| 147 | { | ||
| 148 | using namespace ::kodi::addon; | ||
| 149 | char* retString = nullptr; | ||
| 150 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard | ||
| 151 | ->show_and_get_new_password_with_head( | ||
| 152 | CAddonBase::m_interface->toKodi->kodiBase, newPassword.c_str(), &retString, | ||
| 153 | heading.c_str(), allowEmptyResult, autoCloseMs); | ||
| 154 | if (retString != nullptr) | ||
| 155 | { | ||
| 156 | newPassword = retString; | ||
| 157 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 158 | retString); | ||
| 159 | } | ||
| 160 | return ret; | ||
| 161 | } | ||
| 162 | //------------------------------------------------------------------------------ | ||
| 163 | |||
| 164 | //============================================================================== | ||
| 165 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 166 | /// @brief Shows keyboard and prompts for a password. Differs from | ||
| 167 | /// `ShowAndVerifyNewPassword()` in that no second verification. | ||
| 168 | /// | ||
| 169 | /// @param[in,out] newPassword Overwritten with user input if return=true. | ||
| 170 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 171 | /// milliseconds, default is 0 which keeps the dialog | ||
| 172 | /// open indefinitely. | ||
| 173 | /// @return true if successful display and user input. false if unsuccessful | ||
| 174 | /// display, no user input, or canceled editing. | ||
| 175 | /// | ||
| 176 | inline bool ATTRIBUTE_HIDDEN ShowAndGetNewPassword(std::string& newPassword, | ||
| 177 | unsigned int autoCloseMs = 0) | ||
| 178 | { | ||
| 179 | using namespace ::kodi::addon; | ||
| 180 | char* retString = nullptr; | ||
| 181 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->show_and_get_new_password( | ||
| 182 | CAddonBase::m_interface->toKodi->kodiBase, newPassword.c_str(), &retString, autoCloseMs); | ||
| 183 | if (retString != nullptr) | ||
| 184 | { | ||
| 185 | newPassword = retString; | ||
| 186 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 187 | retString); | ||
| 188 | } | ||
| 189 | return ret; | ||
| 190 | } | ||
| 191 | //------------------------------------------------------------------------------ | ||
| 192 | |||
| 193 | //============================================================================== | ||
| 194 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 195 | /// @brief Show keyboard twice to get and confirm a user-entered password | ||
| 196 | /// string. | ||
| 197 | /// | ||
| 198 | /// @param[out] newPassword Overwritten with user input if return=true. | ||
| 199 | /// @param[in] heading String shown on dialog title. | ||
| 200 | /// @param[in] allowEmptyResult | ||
| 201 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 202 | /// milliseconds, default is 0 which keeps the dialog | ||
| 203 | /// open indefinitely. | ||
| 204 | /// @return true if successful display and user input. false if unsuccessful | ||
| 205 | /// display, no user input, or canceled editing. | ||
| 206 | /// | ||
| 207 | /// | ||
| 208 | ///------------------------------------------------------------------------- | ||
| 209 | /// | ||
| 210 | /// **Example:** | ||
| 211 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 212 | /// #include <kodi/General.h> | ||
| 213 | /// #include <kodi/gui/dialogs/Keyboard.h> | ||
| 214 | /// | ||
| 215 | /// // The example below shows the complete use of keyboard dialog for password | ||
| 216 | /// // check. If only one check from add-on needed can be function with retries | ||
| 217 | /// // set to '0' called alone. | ||
| 218 | /// // | ||
| 219 | /// // The use of MD5 translated password is always required for the check on Kodi! | ||
| 220 | /// | ||
| 221 | /// int maxretries = 3; | ||
| 222 | /// // Password names need to be send as md5 sum to kodi. | ||
| 223 | /// std::string password; | ||
| 224 | /// kodi::GetMD5("kodi", password); | ||
| 225 | /// | ||
| 226 | /// // To the loop about password checks. | ||
| 227 | /// int ret; | ||
| 228 | /// for (unsigned int i = 0; i < maxretries; i++) | ||
| 229 | /// { | ||
| 230 | /// // Ask the user about the password. | ||
| 231 | /// ret = ::kodi::gui::dialogs::Keyboard::ShowAndVerifyPassword(password, "Demo password call for PW 'kodi'", i, 0); | ||
| 232 | /// if (ret == 0) | ||
| 233 | /// { | ||
| 234 | /// fprintf(stderr, "Password successfull confirmed after '%i' tries\n", i+1); | ||
| 235 | /// break; | ||
| 236 | /// } | ||
| 237 | /// else if (ret < 0) | ||
| 238 | /// { | ||
| 239 | /// fprintf(stderr, "Canceled editing on try '%i'\n", i+1); | ||
| 240 | /// break; | ||
| 241 | /// } | ||
| 242 | /// else // if (ret > 0) | ||
| 243 | /// { | ||
| 244 | /// fprintf(stderr, "Wrong password entered on try '%i'\n", i+1); | ||
| 245 | /// } | ||
| 246 | /// } | ||
| 247 | /// ~~~~~~~~~~~~~ | ||
| 248 | /// | ||
| 249 | inline bool ATTRIBUTE_HIDDEN ShowAndVerifyNewPassword(std::string& newPassword, | ||
| 250 | const std::string& heading, | ||
| 251 | bool allowEmptyResult, | ||
| 252 | unsigned int autoCloseMs = 0) | ||
| 253 | { | ||
| 254 | using namespace ::kodi::addon; | ||
| 255 | char* retString = nullptr; | ||
| 256 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard | ||
| 257 | ->show_and_verify_new_password_with_head(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 258 | &retString, heading.c_str(), | ||
| 259 | allowEmptyResult, autoCloseMs); | ||
| 260 | if (retString != nullptr) | ||
| 261 | { | ||
| 262 | newPassword = retString; | ||
| 263 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 264 | retString); | ||
| 265 | } | ||
| 266 | return ret; | ||
| 267 | } | ||
| 268 | //------------------------------------------------------------------------------ | ||
| 269 | |||
| 270 | //============================================================================== | ||
| 271 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 272 | /// @brief Show keyboard twice to get and confirm a user-entered password | ||
| 273 | /// string. | ||
| 274 | /// | ||
| 275 | /// @param[out] newPassword Overwritten with user input if return=true. | ||
| 276 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 277 | /// milliseconds, default is 0 which keeps the dialog | ||
| 278 | /// open indefinitely. | ||
| 279 | /// @return true if successful display and user input. false if unsuccessful | ||
| 280 | /// display, no user input, or canceled editing. | ||
| 281 | /// | ||
| 282 | inline bool ATTRIBUTE_HIDDEN ShowAndVerifyNewPassword(std::string& newPassword, | ||
| 283 | unsigned int autoCloseMs = 0) | ||
| 284 | { | ||
| 285 | using namespace ::kodi::addon; | ||
| 286 | char* retString = nullptr; | ||
| 287 | bool ret = | ||
| 288 | CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->show_and_verify_new_password( | ||
| 289 | CAddonBase::m_interface->toKodi->kodiBase, &retString, autoCloseMs); | ||
| 290 | if (retString != nullptr) | ||
| 291 | { | ||
| 292 | newPassword = retString; | ||
| 293 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 294 | retString); | ||
| 295 | } | ||
| 296 | return ret; | ||
| 297 | } | ||
| 298 | //------------------------------------------------------------------------------ | ||
| 299 | |||
| 300 | //============================================================================== | ||
| 301 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 302 | /// @brief Show keyboard and verify user input against `password`. | ||
| 303 | /// | ||
| 304 | /// @param[in,out] password Value to compare against user input. | ||
| 305 | /// @param[in] heading String shown on dialog title. | ||
| 306 | /// @param[in] retries If greater than 0, shows "Incorrect password, %d retries | ||
| 307 | /// left" on dialog line 2, else line 2 is blank. | ||
| 308 | /// @param[in] autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 309 | /// milliseconds, default is 0 which keeps the dialog | ||
| 310 | /// open indefinitely. | ||
| 311 | /// @return 0 if successful display and user input. 1 if unsuccessful input. | ||
| 312 | /// -1 if no user input or canceled editing. | ||
| 313 | /// | ||
| 314 | inline int ATTRIBUTE_HIDDEN ShowAndVerifyPassword(std::string& password, | ||
| 315 | const std::string& heading, | ||
| 316 | int retries, | ||
| 317 | unsigned int autoCloseMs = 0) | ||
| 318 | { | ||
| 319 | using namespace ::kodi::addon; | ||
| 320 | char* retString = nullptr; | ||
| 321 | int ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->show_and_verify_password( | ||
| 322 | CAddonBase::m_interface->toKodi->kodiBase, password.c_str(), &retString, heading.c_str(), | ||
| 323 | retries, autoCloseMs); | ||
| 324 | if (retString != nullptr) | ||
| 325 | { | ||
| 326 | password = retString; | ||
| 327 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 328 | retString); | ||
| 329 | } | ||
| 330 | return ret; | ||
| 331 | } | ||
| 332 | //------------------------------------------------------------------------------ | ||
| 333 | |||
| 334 | //============================================================================== | ||
| 335 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 336 | /// @brief Shows a filter related keyboard. | ||
| 337 | /// | ||
| 338 | /// @param[in,out] text Overwritten with user input if return=true. | ||
| 339 | /// @param[in] searching Use dialog for search and send our search message in | ||
| 340 | /// safe way (only the active window needs it) | ||
| 341 | /// - header name if true is "Enter search string" | ||
| 342 | /// - header name if false is "Enter value" | ||
| 343 | /// @param autoCloseMs [opt] To close the dialog after a specified time, in | ||
| 344 | /// milliseconds, default is 0 which keeps the dialog open | ||
| 345 | /// indefinitely. | ||
| 346 | /// @return true if successful display and user input. false if unsuccessful | ||
| 347 | /// display, no user input, or canceled editing. | ||
| 348 | /// | ||
| 349 | inline bool ATTRIBUTE_HIDDEN ShowAndGetFilter(std::string& text, | ||
| 350 | bool searching, | ||
| 351 | unsigned int autoCloseMs = 0) | ||
| 352 | { | ||
| 353 | using namespace ::kodi::addon; | ||
| 354 | char* retString = nullptr; | ||
| 355 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->show_and_get_filter( | ||
| 356 | CAddonBase::m_interface->toKodi->kodiBase, text.c_str(), &retString, searching, autoCloseMs); | ||
| 357 | if (retString != nullptr) | ||
| 358 | { | ||
| 359 | text = retString; | ||
| 360 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 361 | retString); | ||
| 362 | } | ||
| 363 | return ret; | ||
| 364 | } | ||
| 365 | //------------------------------------------------------------------------------ | ||
| 366 | |||
| 367 | //============================================================================== | ||
| 368 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 369 | /// @brief Send a text to a visible keyboard. | ||
| 370 | /// | ||
| 371 | /// @param[in] text Overwritten with user input if return=true. | ||
| 372 | /// @param[in] closeKeyboard [opt] The open dialog is if also closed on 'true'. | ||
| 373 | /// @return true if successful done, false if unsuccessful or keyboard not | ||
| 374 | /// present. | ||
| 375 | /// | ||
| 376 | inline bool ATTRIBUTE_HIDDEN SendTextToActiveKeyboard(const std::string& text, | ||
| 377 | bool closeKeyboard = false) | ||
| 378 | { | ||
| 379 | using namespace ::kodi::addon; | ||
| 380 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->send_text_to_active_keyboard( | ||
| 381 | CAddonBase::m_interface->toKodi->kodiBase, text.c_str(), closeKeyboard); | ||
| 382 | } | ||
| 383 | //------------------------------------------------------------------------------ | ||
| 384 | |||
| 385 | //============================================================================== | ||
| 386 | /// @ingroup cpp_kodi_gui_dialogs_Keyboard | ||
| 387 | /// @brief Check for visible keyboard on GUI. | ||
| 388 | /// | ||
| 389 | /// @return true if keyboard present, false if not present | ||
| 390 | /// | ||
| 391 | inline bool ATTRIBUTE_HIDDEN IsKeyboardActivated() | ||
| 392 | { | ||
| 393 | using namespace ::kodi::addon; | ||
| 394 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogKeyboard->is_keyboard_activated( | ||
| 395 | CAddonBase::m_interface->toKodi->kodiBase); | ||
| 396 | } | ||
| 397 | //------------------------------------------------------------------------------ | ||
| 398 | }; // namespace Keyboard | ||
| 399 | |||
| 400 | } /* namespace dialogs */ | ||
| 401 | } /* namespace gui */ | ||
| 402 | } /* namespace kodi */ | ||
| 403 | |||
| 404 | #endif /* __cplusplus */ | ||
