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/Numeric.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/Numeric.h')
| -rw-r--r-- | xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Numeric.h | 346 |
1 files changed, 346 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Numeric.h b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Numeric.h new file mode 100644 index 0000000..835a8d4 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Numeric.h | |||
| @@ -0,0 +1,346 @@ | |||
| 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/numeric.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_Numeric Dialog Numeric | ||
| 25 | /// @ingroup cpp_kodi_gui_dialogs | ||
| 26 | /// @{ | ||
| 27 | /// @brief @cpp_namespace{ kodi::gui::dialogs::Numeric } | ||
| 28 | /// **Numeric dialogs**\n | ||
| 29 | /// The functions listed below have to be permitted by the user for the | ||
| 30 | /// representation of a numeric keyboard around an input. | ||
| 31 | /// | ||
| 32 | /// The class supports several kinds, from an easy number choice up to the | ||
| 33 | /// passport Word production and their confirmation for add-on. | ||
| 34 | /// | ||
| 35 | /// It has the header @ref Numeric.h "#include <kodi/gui/dialogs/Numeric.h>" | ||
| 36 | /// be included to enjoy it. | ||
| 37 | /// | ||
| 38 | namespace Numeric | ||
| 39 | { | ||
| 40 | //============================================================================== | ||
| 41 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 42 | /// @brief Use dialog to get numeric new password | ||
| 43 | /// | ||
| 44 | /// @param[out] newPassword String to preload into the keyboard accumulator. | ||
| 45 | /// Overwritten with user input if return=true. | ||
| 46 | /// Returned in MD5 format. | ||
| 47 | /// @return true if successful display and user input entry/re-entry. false if | ||
| 48 | /// unsuccessful display, no user input, or canceled editing. | ||
| 49 | /// | ||
| 50 | inline bool ATTRIBUTE_HIDDEN ShowAndVerifyNewPassword(std::string& newPassword) | ||
| 51 | { | ||
| 52 | using namespace ::kodi::addon; | ||
| 53 | char* pw = nullptr; | ||
| 54 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_verify_new_password( | ||
| 55 | CAddonBase::m_interface->toKodi->kodiBase, &pw); | ||
| 56 | if (pw != nullptr) | ||
| 57 | { | ||
| 58 | newPassword = pw; | ||
| 59 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, pw); | ||
| 60 | } | ||
| 61 | return ret; | ||
| 62 | } | ||
| 63 | //------------------------------------------------------------------------------ | ||
| 64 | |||
| 65 | //============================================================================== | ||
| 66 | /// | ||
| 67 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 68 | /// @brief Use dialog to verify numeric password. | ||
| 69 | /// | ||
| 70 | /// @param[in] password Password to compare with user input, need | ||
| 71 | /// in MD5 format. | ||
| 72 | /// @param[in] heading Heading to display | ||
| 73 | /// @param[in] retries If greater than 0, shows "Incorrect | ||
| 74 | /// password, %d retries left" on dialog | ||
| 75 | /// line 2, else line 2 is blank. | ||
| 76 | /// @return Possible values: | ||
| 77 | /// - 0 if successful display and user input. | ||
| 78 | /// - 1 if unsuccessful input. | ||
| 79 | /// - -1 if no user input or canceled editing. | ||
| 80 | /// | ||
| 81 | /// | ||
| 82 | ///------------------------------------------------------------------------- | ||
| 83 | /// | ||
| 84 | /// **Example:** | ||
| 85 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 86 | /// #include <stdio.h> // fprintf | ||
| 87 | /// #include <kodi/General.h> | ||
| 88 | /// #include <kodi/gui/dialogs/Numeric.h> | ||
| 89 | /// | ||
| 90 | /// // The example below shows the complete use of keyboard dialog for password | ||
| 91 | /// // check. If only one check from add-on needed can be function with retries | ||
| 92 | /// // set to '0' called alone. | ||
| 93 | /// // | ||
| 94 | /// // The use of MD5 translated password is always required for the check on Kodi! | ||
| 95 | /// | ||
| 96 | /// int maxretries = 3; | ||
| 97 | /// | ||
| 98 | /// // Password names need to be send as md5 sum to kodi. | ||
| 99 | /// std::string password = kodi::GetMD5("1234"); | ||
| 100 | /// | ||
| 101 | /// // To the loop about password checks. | ||
| 102 | /// int ret; | ||
| 103 | /// for (unsigned int i = 0; i < maxretries; i++) | ||
| 104 | /// { | ||
| 105 | /// // Ask the user about the password. | ||
| 106 | /// ret = kodi::gui::dialogs::Numeric::ShowAndVerifyPassword(password, "Demo numeric password call for PW '1234'", i); | ||
| 107 | /// if (ret == 0) | ||
| 108 | /// { | ||
| 109 | /// fprintf(stderr, "Numeric password successfull confirmed after '%i' tries\n", i+1); | ||
| 110 | /// break; | ||
| 111 | /// } | ||
| 112 | /// else if (ret < 0) | ||
| 113 | /// { | ||
| 114 | /// fprintf(stderr, "Canceled editing on try '%i'\n", i+1); | ||
| 115 | /// break; | ||
| 116 | /// } | ||
| 117 | /// else // if (ret > 0) | ||
| 118 | /// { | ||
| 119 | /// fprintf(stderr, "Wrong numeric password entered on try '%i'\n", i+1); | ||
| 120 | /// } | ||
| 121 | /// } | ||
| 122 | /// ~~~~~~~~~~~~~ | ||
| 123 | /// | ||
| 124 | inline int ATTRIBUTE_HIDDEN ShowAndVerifyPassword(const std::string& password, | ||
| 125 | const std::string& heading, | ||
| 126 | int retries) | ||
| 127 | { | ||
| 128 | using namespace ::kodi::addon; | ||
| 129 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_verify_password( | ||
| 130 | CAddonBase::m_interface->toKodi->kodiBase, password.c_str(), heading.c_str(), retries); | ||
| 131 | } | ||
| 132 | //------------------------------------------------------------------------------ | ||
| 133 | |||
| 134 | //============================================================================== | ||
| 135 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 136 | /// @brief Use dialog to verify numeric password | ||
| 137 | /// | ||
| 138 | /// @param[in,out] toVerify Value to compare against user input. | ||
| 139 | /// @param[in] heading Heading to display | ||
| 140 | /// @param[in] verifyInput If set as true we verify the users input versus | ||
| 141 | /// toVerify. | ||
| 142 | /// @return true if successful display and user input. false if unsuccessful | ||
| 143 | /// display, no user input, or canceled editing. | ||
| 144 | /// | ||
| 145 | inline bool ATTRIBUTE_HIDDEN ShowAndVerifyInput(std::string& toVerify, | ||
| 146 | const std::string& heading, | ||
| 147 | bool verifyInput) | ||
| 148 | { | ||
| 149 | using namespace ::kodi::addon; | ||
| 150 | char* retString = nullptr; | ||
| 151 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_verify_input( | ||
| 152 | CAddonBase::m_interface->toKodi->kodiBase, toVerify.c_str(), &retString, heading.c_str(), | ||
| 153 | verifyInput); | ||
| 154 | if (retString != nullptr) | ||
| 155 | { | ||
| 156 | toVerify = 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_Numeric | ||
| 166 | /// @brief Use dialog to get time value. | ||
| 167 | /// | ||
| 168 | /// @param[out] time Overwritten with user input if return=true and time | ||
| 169 | /// inserted. | ||
| 170 | /// @param[in] heading Heading to display. | ||
| 171 | /// @return true if successful display and user input. false if unsuccessful | ||
| 172 | /// display, no user input, or canceled editing. | ||
| 173 | /// | ||
| 174 | /// | ||
| 175 | ///------------------------------------------------------------------------- | ||
| 176 | /// | ||
| 177 | /// **Example:** | ||
| 178 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 179 | /// #include <stdio.h> // printf | ||
| 180 | /// #include <time.h> // time_t, struct tm, time, localtime, strftime | ||
| 181 | /// #include <kodi/gui/dialogs/Numeric.h> | ||
| 182 | /// | ||
| 183 | /// time_t rawtime; | ||
| 184 | /// struct tm * timeinfo; | ||
| 185 | /// char buffer [10]; | ||
| 186 | /// | ||
| 187 | /// time (&rawtime); | ||
| 188 | /// timeinfo = localtime(&rawtime); | ||
| 189 | /// bool bRet = kodi::gui::dialogs::Numeric::ShowAndGetTime(*timeinfo, "Selected time test call"); | ||
| 190 | /// strftime(buffer, sizeof(buffer), "%H:%M.", timeinfo); | ||
| 191 | /// printf("Selected time it's %s and was on Dialog %s\n", buffer, bRet ? "OK" : "Canceled"); | ||
| 192 | /// ~~~~~~~~~~~~~ | ||
| 193 | /// | ||
| 194 | inline bool ATTRIBUTE_HIDDEN ShowAndGetTime(tm& time, const std::string& heading) | ||
| 195 | { | ||
| 196 | using namespace ::kodi::addon; | ||
| 197 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_time( | ||
| 198 | CAddonBase::m_interface->toKodi->kodiBase, &time, heading.c_str()); | ||
| 199 | } | ||
| 200 | //------------------------------------------------------------------------------ | ||
| 201 | |||
| 202 | //============================================================================== | ||
| 203 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 204 | /// @brief Use dialog to get date value. | ||
| 205 | /// | ||
| 206 | /// @param[in,out] date Overwritten with user input if return=true and date | ||
| 207 | /// inserted. | ||
| 208 | /// @param[in] heading Heading to display | ||
| 209 | /// @return true if successful display and user input. false if unsuccessful | ||
| 210 | /// display, no user input, or canceled editing. | ||
| 211 | /// | ||
| 212 | /// | ||
| 213 | ///------------------------------------------------------------------------- | ||
| 214 | /// | ||
| 215 | /// **Example:** | ||
| 216 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 217 | /// #include <stdio.h> // printf | ||
| 218 | /// #include <time.h> // time_t, struct tm, time, localtime, strftime | ||
| 219 | /// #include <kodi/gui/dialogs/Numeric.h> | ||
| 220 | /// | ||
| 221 | /// time_t rawtime; | ||
| 222 | /// struct tm * timeinfo; | ||
| 223 | /// char buffer [20]; | ||
| 224 | /// | ||
| 225 | /// time (&rawtime); | ||
| 226 | /// timeinfo = localtime(&rawtime); | ||
| 227 | /// bool bRet = kodi::gui::dialogs::Numeric::ShowAndGetDate(*timeinfo, "Selected date test call"); | ||
| 228 | /// strftime(buffer, sizeof(buffer), "%Y-%m-%d", timeinfo); | ||
| 229 | /// printf("Selected date it's %s and was on Dialog %s\n", buffer, bRet ? "OK" : "Canceled"); | ||
| 230 | /// ~~~~~~~~~~~~~ | ||
| 231 | /// | ||
| 232 | inline bool ATTRIBUTE_HIDDEN ShowAndGetDate(tm& date, const std::string& heading) | ||
| 233 | { | ||
| 234 | using namespace ::kodi::addon; | ||
| 235 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_date( | ||
| 236 | CAddonBase::m_interface->toKodi->kodiBase, &date, heading.c_str()); | ||
| 237 | } | ||
| 238 | //------------------------------------------------------------------------------ | ||
| 239 | |||
| 240 | //============================================================================== | ||
| 241 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 242 | /// @brief Use dialog to get a IP | ||
| 243 | /// | ||
| 244 | /// @param[in,out] ipAddress Overwritten with user input if return=true and | ||
| 245 | /// IP address inserted. | ||
| 246 | /// @param[in] heading Heading to display. | ||
| 247 | /// @return true if successful display and user input. false if unsuccessful | ||
| 248 | /// display, no user input, or canceled editing. | ||
| 249 | /// | ||
| 250 | inline bool ATTRIBUTE_HIDDEN ShowAndGetIPAddress(std::string& ipAddress, const std::string& heading) | ||
| 251 | { | ||
| 252 | using namespace ::kodi::addon; | ||
| 253 | char* retString = nullptr; | ||
| 254 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_ip_address( | ||
| 255 | CAddonBase::m_interface->toKodi->kodiBase, ipAddress.c_str(), &retString, heading.c_str()); | ||
| 256 | if (retString != nullptr) | ||
| 257 | { | ||
| 258 | ipAddress = retString; | ||
| 259 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 260 | retString); | ||
| 261 | } | ||
| 262 | return ret; | ||
| 263 | } | ||
| 264 | //------------------------------------------------------------------------------ | ||
| 265 | |||
| 266 | //============================================================================== | ||
| 267 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 268 | /// @brief Use dialog to get normal number. | ||
| 269 | /// | ||
| 270 | /// @param[in,out] input Overwritten with user input if return=true and time | ||
| 271 | /// in seconds inserted | ||
| 272 | /// @param[in] heading Heading to display | ||
| 273 | /// @param[in] autoCloseTimeoutMs [opt] To close the dialog after a specified | ||
| 274 | /// time, in milliseconds, default is 0 | ||
| 275 | /// which keeps the dialog open | ||
| 276 | /// indefinitely. | ||
| 277 | /// @return true if successful display and user input. false if unsuccessful | ||
| 278 | /// display, no user input, or canceled editing. | ||
| 279 | /// | ||
| 280 | /// | ||
| 281 | ///------------------------------------------------------------------------- | ||
| 282 | /// | ||
| 283 | /// **Example:** | ||
| 284 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 285 | /// #include <stdio.h> // printf | ||
| 286 | /// #include <stdlib.h> // strtoull (C++11) | ||
| 287 | /// #include <kodi/gui/dialogs/Numeric.h> | ||
| 288 | /// | ||
| 289 | /// std::string number; | ||
| 290 | /// bool bRet = kodi::gui::dialogs::Numeric::ShowAndGetNumber(number, "Number test call"); | ||
| 291 | /// printf("Written number input is : %llu and was %s\n", | ||
| 292 | /// strtoull(number.c_str(), nullptr, 0), bRet ? "OK" : "Canceled"); | ||
| 293 | /// ~~~~~~~~~~~~~ | ||
| 294 | /// | ||
| 295 | inline bool ATTRIBUTE_HIDDEN ShowAndGetNumber(std::string& input, | ||
| 296 | const std::string& heading, | ||
| 297 | unsigned int autoCloseTimeoutMs = 0) | ||
| 298 | { | ||
| 299 | using namespace ::kodi::addon; | ||
| 300 | char* retString = nullptr; | ||
| 301 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_number( | ||
| 302 | CAddonBase::m_interface->toKodi->kodiBase, input.c_str(), &retString, heading.c_str(), | ||
| 303 | autoCloseTimeoutMs); | ||
| 304 | if (retString != nullptr) | ||
| 305 | { | ||
| 306 | input = retString; | ||
| 307 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 308 | retString); | ||
| 309 | } | ||
| 310 | return ret; | ||
| 311 | } | ||
| 312 | //------------------------------------------------------------------------------ | ||
| 313 | |||
| 314 | //============================================================================== | ||
| 315 | /// @ingroup cpp_kodi_gui_dialogs_Numeric | ||
| 316 | /// @brief Show numeric keypad to get seconds. | ||
| 317 | /// | ||
| 318 | /// @param[in,out] time Overwritten with user input if return=true and time | ||
| 319 | /// in seconds inserted. | ||
| 320 | /// @param[in] heading Heading to display | ||
| 321 | /// @return true if successful display and user input. false if unsuccessful | ||
| 322 | /// display, no user input, or canceled editing. | ||
| 323 | /// | ||
| 324 | inline bool ATTRIBUTE_HIDDEN ShowAndGetSeconds(std::string& time, const std::string& heading) | ||
| 325 | { | ||
| 326 | using namespace ::kodi::addon; | ||
| 327 | char* retString = nullptr; | ||
| 328 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_seconds( | ||
| 329 | CAddonBase::m_interface->toKodi->kodiBase, time.c_str(), &retString, heading.c_str()); | ||
| 330 | if (retString != nullptr) | ||
| 331 | { | ||
| 332 | time = retString; | ||
| 333 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 334 | retString); | ||
| 335 | } | ||
| 336 | return ret; | ||
| 337 | } | ||
| 338 | //------------------------------------------------------------------------------ | ||
| 339 | }; // namespace Numeric | ||
| 340 | /// @} | ||
| 341 | |||
| 342 | } /* namespace dialogs */ | ||
| 343 | } /* namespace gui */ | ||
| 344 | } /* namespace kodi */ | ||
| 345 | |||
| 346 | #endif /* __cplusplus */ | ||
