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