diff options
| author | manuel <manuel@mausz.at> | 2017-06-04 16:57:49 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2017-06-04 16:57:49 +0200 |
| commit | f44ecaa4f27e7538ddcad66d40e543bffa2d2d86 (patch) | |
| tree | d8de60fc7e17edeb6f0921726c038ee54b281445 /xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/DialogNumeric.h | |
| parent | ae08c8b7221bc965ac40d70e53fc8fcddb050c46 (diff) | |
| download | kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.tar.gz kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.tar.bz2 kodi-pvr-build-f44ecaa4f27e7538ddcad66d40e543bffa2d2d86.zip | |
sync with upstream
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/DialogNumeric.h')
| -rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/DialogNumeric.h | 366 |
1 files changed, 366 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/DialogNumeric.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/DialogNumeric.h new file mode 100644 index 0000000..8b5c592 --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/DialogNumeric.h | |||
| @@ -0,0 +1,366 @@ | |||
| 1 | #pragma once | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2005-2017 Team KODI | ||
| 4 | * http://kodi.tv | ||
| 5 | * | ||
| 6 | * This Program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2, or (at your option) | ||
| 9 | * any later version. | ||
| 10 | * | ||
| 11 | * This Program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with KODI; see the file COPYING. If not, see | ||
| 18 | * <http://www.gnu.org/licenses/>. | ||
| 19 | * | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "definitions.h" | ||
| 23 | #include "../AddonBase.h" | ||
| 24 | |||
| 25 | namespace kodi | ||
| 26 | { | ||
| 27 | namespace gui | ||
| 28 | { | ||
| 29 | |||
| 30 | //============================================================================ | ||
| 31 | /// | ||
| 32 | /// \defgroup cpp_kodi_gui_DialogNumeric Dialog Numeric | ||
| 33 | /// \ingroup cpp_kodi_gui | ||
| 34 | /// @{ | ||
| 35 | /// @brief \cpp_namespace{ kodi::gui::DialogNumeric } | ||
| 36 | /// **Numeric dialogs** | ||
| 37 | /// | ||
| 38 | /// The functions listed below have to be permitted by the user for the | ||
| 39 | /// representation of a numeric keyboard around an input. | ||
| 40 | /// | ||
| 41 | /// The class supports several kinds, from an easy number choice up to the | ||
| 42 | /// passport Word production and their confirmation for add-on. | ||
| 43 | /// | ||
| 44 | /// It has the header \ref DialogNumeric.h "#include <kodi/gui/DialogNumeric.h>" | ||
| 45 | /// be included to enjoy it. | ||
| 46 | /// | ||
| 47 | namespace DialogNumeric | ||
| 48 | { | ||
| 49 | //========================================================================== | ||
| 50 | /// | ||
| 51 | /// \ingroup cpp_kodi_gui_DialogNumeric | ||
| 52 | /// @brief Use dialog to get numeric new password | ||
| 53 | /// | ||
| 54 | /// @param[out] newPassword String to preload into the keyboard | ||
| 55 | /// accumulator. Overwritten with user input | ||
| 56 | /// if return=true. Returned in MD5 format. | ||
| 57 | /// @return true if successful display and user | ||
| 58 | /// input entry/re-entry. | ||
| 59 | /// false if unsuccessful display, no user | ||
| 60 | /// input, or canceled editing. | ||
| 61 | /// | ||
| 62 | inline bool ShowAndVerifyNewPassword(std::string& newPassword) | ||
| 63 | { | ||
| 64 | using namespace ::kodi::addon; | ||
| 65 | char* pw = nullptr; | ||
| 66 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_verify_new_password(CAddonBase::m_interface->toKodi->kodiBase, &pw); | ||
| 67 | if (pw != nullptr) | ||
| 68 | { | ||
| 69 | if (std::strlen(pw)) | ||
| 70 | newPassword = pw; | ||
| 71 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, pw); | ||
| 72 | } | ||
| 73 | return ret; | ||
| 74 | } | ||
| 75 | //-------------------------------------------------------------------------- | ||
| 76 | |||
| 77 | //========================================================================== | ||
| 78 | /// | ||
| 79 | /// \ingroup cpp_kodi_gui_DialogNumeric | ||
| 80 | /// @brief Use dialog to verify numeric password. | ||
| 81 | /// | ||
| 82 | /// @param[in] password Password to compare with user input, need | ||
| 83 | /// in MD5 format. | ||
| 84 | /// @param[in] heading Heading to display | ||
| 85 | /// @param[in] retries If greater than 0, shows "Incorrect | ||
| 86 | /// password, %d retries left" on dialog | ||
| 87 | /// line 2, else line 2 is blank. | ||
| 88 | /// @return Possible values: | ||
| 89 | /// - 0 if successful display and user input. | ||
| 90 | /// - 1 if unsuccessful input. | ||
| 91 | /// - -1 if no user input or canceled editing. | ||
| 92 | /// | ||
| 93 | /// | ||
| 94 | ///------------------------------------------------------------------------- | ||
| 95 | /// | ||
| 96 | /// **Example:** | ||
| 97 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 98 | /// #include <stdio.h> /* fprintf */ | ||
| 99 | /// #include <kodi/General.h> | ||
| 100 | /// #include <kodi/gui/DialogNumeric.h> | ||
| 101 | /// | ||
| 102 | /// /* | ||
| 103 | /// * The example below shows the complete use of keyboard dialog for password | ||
| 104 | /// * check. If only one check from add-on needed can be function with retries | ||
| 105 | /// * set to '0' called alone. | ||
| 106 | /// * | ||
| 107 | /// * The use of MD5 translated password is always required for the check on Kodi! | ||
| 108 | /// */ | ||
| 109 | /// | ||
| 110 | /// int maxretries = 3; | ||
| 111 | /// | ||
| 112 | /// /* | ||
| 113 | /// * Password names need to be send as md5 sum to kodi. | ||
| 114 | /// */ | ||
| 115 | /// std::string password = kodi::GetMD5("1234"); | ||
| 116 | /// | ||
| 117 | /// /* | ||
| 118 | /// * To the loop about password checks. | ||
| 119 | /// */ | ||
| 120 | /// int ret; | ||
| 121 | /// for (unsigned int i = 0; i < maxretries; i++) | ||
| 122 | /// { | ||
| 123 | /// /* | ||
| 124 | /// * Ask the user about the password. | ||
| 125 | /// */ | ||
| 126 | /// ret = kodi::gui::DialogNumeric::ShowAndVerifyPassword(password, "Demo numeric password call for PW '1234'", i); | ||
| 127 | /// if (ret == 0) | ||
| 128 | /// { | ||
| 129 | /// fprintf(stderr, "Numeric password successfull confirmed after '%i' tries\n", i+1); | ||
| 130 | /// break; | ||
| 131 | /// } | ||
| 132 | /// else if (ret < 0) | ||
| 133 | /// { | ||
| 134 | /// fprintf(stderr, "Canceled editing on try '%i'\n", i+1); | ||
| 135 | /// break; | ||
| 136 | /// } | ||
| 137 | /// else /* if (ret > 0) */ | ||
| 138 | /// { | ||
| 139 | /// fprintf(stderr, "Wrong numeric password entered on try '%i'\n", i+1); | ||
| 140 | /// } | ||
| 141 | /// } | ||
| 142 | /// ~~~~~~~~~~~~~ | ||
| 143 | /// | ||
| 144 | inline int ShowAndVerifyPassword(const std::string& password, const std::string& heading, int retries) | ||
| 145 | { | ||
| 146 | using namespace ::kodi::addon; | ||
| 147 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_verify_password(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 148 | password.c_str(), heading.c_str(), retries); | ||
| 149 | } | ||
| 150 | //-------------------------------------------------------------------------- | ||
| 151 | |||
| 152 | //========================================================================== | ||
| 153 | /// | ||
| 154 | /// \ingroup cpp_kodi_gui_DialogNumeric | ||
| 155 | /// @brief Use dialog to verify numeric password | ||
| 156 | /// | ||
| 157 | /// @param[in,out] toVerify Value to compare against user input. | ||
| 158 | /// @param[in] heading Heading to display | ||
| 159 | /// @param[in] verifyInput If set as true we verify the users input | ||
| 160 | /// versus toVerify. | ||
| 161 | /// @return true if successful display and user | ||
| 162 | /// input. false if unsuccessful display, no | ||
| 163 | /// user input, or canceled editing. | ||
| 164 | /// | ||
| 165 | inline bool ShowAndVerifyInput(std::string& toVerify, const std::string& heading, bool verifyInput) | ||
| 166 | { | ||
| 167 | using namespace ::kodi::addon; | ||
| 168 | char* retString = nullptr; | ||
| 169 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_verify_input(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 170 | toVerify.c_str(), &retString, heading.c_str(), verifyInput); | ||
| 171 | if (retString != nullptr) | ||
| 172 | { | ||
| 173 | if (std::strlen(retString)) | ||
| 174 | toVerify = retString; | ||
| 175 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, retString); | ||
| 176 | } | ||
| 177 | return ret; | ||
| 178 | } | ||
| 179 | //-------------------------------------------------------------------------- | ||
| 180 | |||
| 181 | //========================================================================== | ||
| 182 | /// | ||
| 183 | /// \ingroup cpp_kodi_gui_DialogNumeric | ||
| 184 | /// @brief Use dialog to get time value. | ||
| 185 | /// | ||
| 186 | /// @param[out] time Overwritten with user input if | ||
| 187 | /// return=true and time inserted. | ||
| 188 | /// @param[in] heading Heading to display. | ||
| 189 | /// @return true if successful display and user | ||
| 190 | /// input. false if unsuccessful display, no | ||
| 191 | /// user input, or canceled editing. | ||
| 192 | /// | ||
| 193 | /// | ||
| 194 | ///------------------------------------------------------------------------- | ||
| 195 | /// | ||
| 196 | /// **Example:** | ||
| 197 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 198 | /// #include <stdio.h> /* printf */ | ||
| 199 | /// #include <time.h> /* time_t, struct tm, time, localtime, strftime */ | ||
| 200 | /// #include <kodi/gui/DialogNumeric.h> | ||
| 201 | /// | ||
| 202 | /// time_t rawtime; | ||
| 203 | /// struct tm * timeinfo; | ||
| 204 | /// char buffer [10]; | ||
| 205 | /// | ||
| 206 | /// time (&rawtime); | ||
| 207 | /// timeinfo = localtime(&rawtime); | ||
| 208 | /// bool bRet = kodi::gui::DialogNumeric::ShowAndGetTime(*timeinfo, "Selected time test call"); | ||
| 209 | /// strftime(buffer, sizeof(buffer), "%H:%M.", timeinfo); | ||
| 210 | /// printf("Selected time it's %s and was on Dialog %s\n", buffer, bRet ? "OK" : "Canceled"); | ||
| 211 | /// ~~~~~~~~~~~~~ | ||
| 212 | /// | ||
| 213 | inline bool ShowAndGetTime(tm& time, const std::string& heading) | ||
| 214 | { | ||
| 215 | using namespace ::kodi::addon; | ||
| 216 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_time(CAddonBase::m_interface->toKodi->kodiBase, &time, heading.c_str()); | ||
| 217 | } | ||
| 218 | //-------------------------------------------------------------------------- | ||
| 219 | |||
| 220 | //========================================================================== | ||
| 221 | /// | ||
| 222 | /// \ingroup cpp_kodi_gui_DialogNumeric | ||
| 223 | /// @brief Use dialog to get date value. | ||
| 224 | /// | ||
| 225 | /// @param[in,out] date Overwritten with user input if | ||
| 226 | /// return=true and date inserted. | ||
| 227 | /// @param[in] heading Heading to display | ||
| 228 | /// @return true if successful display and user | ||
| 229 | /// input. false if unsuccessful display, no | ||
| 230 | /// user input, or canceled editing. | ||
| 231 | /// | ||
| 232 | /// | ||
| 233 | ///------------------------------------------------------------------------- | ||
| 234 | /// | ||
| 235 | /// **Example:** | ||
| 236 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 237 | /// #include <stdio.h> /* printf */ | ||
| 238 | /// #include <time.h> /* time_t, struct tm, time, localtime, strftime */ | ||
| 239 | /// #include <kodi/gui/DialogNumeric.h> | ||
| 240 | /// | ||
| 241 | /// time_t rawtime; | ||
| 242 | /// struct tm * timeinfo; | ||
| 243 | /// char buffer [20]; | ||
| 244 | /// | ||
| 245 | /// time (&rawtime); | ||
| 246 | /// timeinfo = localtime(&rawtime); | ||
| 247 | /// bool bRet = kodi::gui::DialogNumeric::ShowAndGetDate(*timeinfo, "Selected date test call"); | ||
| 248 | /// strftime(buffer, sizeof(buffer), "%Y-%m-%d", timeinfo); | ||
| 249 | /// printf("Selected date it's %s and was on Dialog %s\n", buffer, bRet ? "OK" : "Canceled"); | ||
| 250 | /// ~~~~~~~~~~~~~ | ||
| 251 | /// | ||
| 252 | inline bool ShowAndGetDate(tm& date, const std::string& heading) | ||
| 253 | { | ||
| 254 | using namespace ::kodi::addon; | ||
| 255 | return CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_date(CAddonBase::m_interface->toKodi->kodiBase, &date, heading.c_str()); | ||
| 256 | } | ||
| 257 | //-------------------------------------------------------------------------- | ||
| 258 | |||
| 259 | //========================================================================== | ||
| 260 | /// | ||
| 261 | /// \ingroup cpp_kodi_gui_DialogNumeric | ||
| 262 | /// @brief Use dialog to get a IP | ||
| 263 | /// | ||
| 264 | /// @param[in,out] ipAddress Overwritten with user input if | ||
| 265 | /// return=true and IP address inserted. | ||
| 266 | /// @param[in] heading Heading to display. | ||
| 267 | /// @return true if successful display and | ||
| 268 | /// user input. false if unsuccessful | ||
| 269 | /// display, no user input, or canceled | ||
| 270 | /// editing. | ||
| 271 | /// | ||
| 272 | inline bool ShowAndGetIPAddress(std::string& ipAddress, const std::string& heading) | ||
| 273 | { | ||
| 274 | using namespace ::kodi::addon; | ||
| 275 | char* retString = nullptr; | ||
| 276 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_ip_address(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 277 | ipAddress.c_str(), &retString, heading.c_str()); | ||
| 278 | if (retString != nullptr) | ||
| 279 | { | ||
| 280 | if (std::strlen(retString)) | ||
| 281 | ipAddress = retString; | ||
| 282 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, retString); | ||
| 283 | } | ||
| 284 | return ret; | ||
| 285 | } | ||
| 286 | //-------------------------------------------------------------------------- | ||
| 287 | |||
| 288 | //========================================================================== | ||
| 289 | /// | ||
| 290 | /// \ingroup cpp_kodi_gui_DialogNumeric | ||
| 291 | /// @brief Use dialog to get normal number. | ||
| 292 | /// | ||
| 293 | /// @param[in,out] input Overwritten with user input if | ||
| 294 | /// return=true and time in seconds inserted | ||
| 295 | /// @param[in] heading Heading to display | ||
| 296 | /// @param[in] autoCloseTimeoutMs To close the dialog after a specified | ||
| 297 | /// time, in milliseconds, default is 0 | ||
| 298 | /// which keeps the dialog open | ||
| 299 | /// indefinitely. | ||
| 300 | /// @return true if successful display and user | ||
| 301 | /// input. false if unsuccessful display, no | ||
| 302 | /// user input, or canceled editing. | ||
| 303 | /// | ||
| 304 | /// | ||
| 305 | ///------------------------------------------------------------------------- | ||
| 306 | /// | ||
| 307 | /// **Example:** | ||
| 308 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 309 | /// #include <stdio.h> /* printf */ | ||
| 310 | /// #include <stdlib.h> /* strtoull (C++11) */ | ||
| 311 | /// #include <kodi/gui/DialogNumeric.h> | ||
| 312 | /// | ||
| 313 | /// std::string number; | ||
| 314 | /// bool bRet = kodi::gui::DialogNumeric::ShowAndGetNumber(number, "Number test call"); | ||
| 315 | /// printf("Written number input is : %llu and was %s\n", | ||
| 316 | /// strtoull(number.c_str(), nullptr, 0), bRet ? "OK" : "Canceled"); | ||
| 317 | /// ~~~~~~~~~~~~~ | ||
| 318 | /// | ||
| 319 | inline bool ShowAndGetNumber(std::string& input, const std::string& heading, unsigned int autoCloseTimeoutMs = 0) | ||
| 320 | { | ||
| 321 | using namespace ::kodi::addon; | ||
| 322 | char* retString = nullptr; | ||
| 323 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_number(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 324 | input.c_str(), &retString, heading.c_str(), autoCloseTimeoutMs); | ||
| 325 | if (retString != nullptr) | ||
| 326 | { | ||
| 327 | if (std::strlen(retString)) | ||
| 328 | input = retString; | ||
| 329 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, retString); | ||
| 330 | } | ||
| 331 | return ret; | ||
| 332 | } | ||
| 333 | //-------------------------------------------------------------------------- | ||
| 334 | |||
| 335 | //========================================================================== | ||
| 336 | /// | ||
| 337 | /// \ingroup cpp_kodi_gui_DialogNumeric | ||
| 338 | /// @brief Show numeric keypad to get seconds. | ||
| 339 | /// | ||
| 340 | /// @param[in,out] time Overwritten with user input if return=true and | ||
| 341 | /// time in seconds inserted. | ||
| 342 | /// @param[in] heading Heading to display | ||
| 343 | /// @return true if successful display and user input. false | ||
| 344 | /// if unsuccessful display, no user input, or | ||
| 345 | /// canceled editing. | ||
| 346 | /// | ||
| 347 | inline bool ShowAndGetSeconds(std::string& time, const std::string& heading) | ||
| 348 | { | ||
| 349 | using namespace ::kodi::addon; | ||
| 350 | char* retString = nullptr; | ||
| 351 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogNumeric->show_and_get_seconds(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 352 | time.c_str(), &retString, heading.c_str()); | ||
| 353 | if (retString != nullptr) | ||
| 354 | { | ||
| 355 | if (std::strlen(retString)) | ||
| 356 | time = retString; | ||
| 357 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, retString); | ||
| 358 | } | ||
| 359 | return ret; | ||
| 360 | } | ||
| 361 | //-------------------------------------------------------------------------- | ||
| 362 | }; | ||
| 363 | /// @} | ||
| 364 | |||
| 365 | } /* namespace gui */ | ||
| 366 | } /* namespace kodi */ | ||
