summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-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-addon-dev-kit/include/kodi/General.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h834
1 files changed, 0 insertions, 834 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h
deleted file mode 100644
index 878eaa4..0000000
--- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h
+++ /dev/null
@@ -1,834 +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 "AddonBase.h"
12#include "c-api/general.h"
13
14#ifdef __cplusplus
15
16//==============================================================================
17/// \ingroup cpp_kodi_Defs
18/// @brief For kodi::Version used structure
19///
20typedef struct kodi_version_t
21{
22 /// Application name, normally 'Kodi'
23 std::string compile_name;
24 /// Major code version of Kodi
25 int major;
26 /// Minor code version of Kodi
27 int minor;
28 /// The Revision contains a id and the build date, e.g. 20170706-c6b22fe217-dirty
29 std::string revision;
30 /// The version canditate e.g. alpha, beta or release
31 std::string tag;
32 /// The revision of tag before
33 std::string tag_revision;
34} kodi_version_t;
35//------------------------------------------------------------------------------
36
37namespace kodi
38{
39
40//==============================================================================
41/// \ingroup cpp_kodi
42/// @brief Returns the value of an addon property as a string
43///
44/// @param[in] id id of the property that the module needs to access
45/// | | Choices are | |
46/// |:------------:|:------------:|:------------:|
47/// | author | icon | stars |
48/// | changelog | id | summary |
49/// | description | name | type |
50/// | disclaimer | path | version |
51/// | fanart | profile | |
52///
53/// @return AddOn property as a string
54///
55///
56/// ------------------------------------------------------------------------
57///
58/// **Example:**
59/// ~~~~~~~~~~~~~{.cpp}
60/// #include <kodi/General.h>
61/// ...
62/// std::string addonName = kodi::GetAddonInfo("name");
63/// ...
64/// ~~~~~~~~~~~~~
65///
66inline std::string ATTRIBUTE_HIDDEN GetAddonInfo(const std::string& id)
67{
68 using namespace kodi::addon;
69
70 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
71
72 std::string strReturn;
73 char* strMsg = toKodi->kodi->get_addon_info(toKodi->kodiBase, id.c_str());
74 if (strMsg != nullptr)
75 {
76 if (std::strlen(strMsg))
77 strReturn = strMsg;
78 toKodi->free_string(toKodi->kodiBase, strMsg);
79 }
80 return strReturn;
81}
82//------------------------------------------------------------------------------
83
84//==============================================================================
85/// \ingroup cpp_kodi
86/// @brief Opens this Add-Ons settings dialog.
87///
88/// @return true if settings were changed and the dialog confirmed, false otherwise.
89///
90///
91/// --------------------------------------------------------------------------
92///
93/// **Example:**
94/// ~~~~~~~~~~~~~{.cpp}
95/// #include <kodi/General.h>
96/// ..
97/// kodi::OpenSettings();
98/// ..
99/// ~~~~~~~~~~~~~
100///
101inline bool ATTRIBUTE_HIDDEN OpenSettings()
102{
103 using namespace kodi::addon;
104 return CAddonBase::m_interface->toKodi->kodi->open_settings_dialog(
105 CAddonBase::m_interface->toKodi->kodiBase);
106}
107//------------------------------------------------------------------------------
108
109//==============================================================================
110/// \ingroup cpp_kodi
111/// @brief Returns an addon's localized 'unicode string'.
112///
113/// @param[in] labelId string you want to localize
114/// @param[in] defaultStr [opt] The default message, also helps to identify
115/// the code that is used <em>(default is
116/// <b><c>empty</c></b>)</em>
117/// @return The localized message, or default if the add-on
118/// helper fails to return a message
119///
120/// @note Label id's \b 30000 to \b 30999 and \b 32000 to \b 32999 are related
121/// to the add-on's own included strings from
122/// <b>./resources/language/resource.language.??_??/strings.po</b>
123/// All other strings are from Kodi core language files.
124///
125///
126/// ------------------------------------------------------------------------
127///
128/// **Example:**
129/// ~~~~~~~~~~~~~{.cpp}
130/// #include <kodi/General.h>
131/// ...
132/// std::string str = kodi::GetLocalizedString(30005, "Use me as default");
133/// ...
134/// ~~~~~~~~~~~~~
135///
136inline std::string ATTRIBUTE_HIDDEN GetLocalizedString(uint32_t labelId,
137 const std::string& defaultStr = "")
138{
139 using namespace kodi::addon;
140
141 std::string retString = defaultStr;
142 char* strMsg = CAddonBase::m_interface->toKodi->kodi->get_localized_string(
143 CAddonBase::m_interface->toKodi->kodiBase, labelId);
144 if (strMsg != nullptr)
145 {
146 if (std::strlen(strMsg))
147 retString = strMsg;
148 CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, strMsg);
149 }
150 return retString;
151}
152//------------------------------------------------------------------------------
153
154//==============================================================================
155/// \ingroup cpp_kodi
156/// @brief Translate a string with an unknown encoding to UTF8.
157///
158/// @param[in] stringSrc The string to translate.
159/// @param[out] utf8StringDst The translated string.
160/// @param[in] failOnBadChar [opt] returns failed if bad character is inside <em>(default is <b><c>false</c></b>)</em>
161/// @return true if OK
162///
163///
164/// ------------------------------------------------------------------------
165///
166/// **Example:**
167/// ~~~~~~~~~~~~~{.cpp}
168/// #include <kodi/General.h>
169/// ...
170/// std::string ret;
171/// if (!kodi::UnknownToUTF8("test string", ret, true))
172/// fprintf(stderr, "Translation to UTF8 failed!\n");
173/// ...
174/// ~~~~~~~~~~~~~
175///
176inline bool ATTRIBUTE_HIDDEN UnknownToUTF8(const std::string& stringSrc,
177 std::string& utf8StringDst,
178 bool failOnBadChar = false)
179{
180 using namespace kodi::addon;
181
182 bool ret = false;
183 char* retString = CAddonBase::m_interface->toKodi->kodi->unknown_to_utf8(
184 CAddonBase::m_interface->toKodi->kodiBase, stringSrc.c_str(), &ret, failOnBadChar);
185 if (retString != nullptr)
186 {
187 if (ret)
188 utf8StringDst = retString;
189 CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
190 retString);
191 }
192 return ret;
193}
194//------------------------------------------------------------------------------
195
196//==============================================================================
197/// \ingroup cpp_kodi
198/// @brief Returns the active language as a string.
199///
200/// @param[in] format Used format of the returned language string
201/// | enum code: | Description: |
202/// |----------------------:|------------------------------------------------------------|
203/// | LANG_FMT_ENGLISH_NAME | full language name in English (Default) |
204/// | LANG_FMT_ISO_639_1 | two letter code as defined in ISO 639-1 |
205/// | LANG_FMT_ISO_639_2 | three letter code as defined in ISO 639-2/T or ISO 639-2/B |
206/// @param[in] region [opt] append the region delimited by "-" of the language (setting) to the returned language string <em>(default is <b><c>false</c></b>)</em>
207/// @return active language
208///
209///
210/// ------------------------------------------------------------------------
211///
212/// **Example:**
213/// ~~~~~~~~~~~~~{.cpp}
214/// #include <kodi/General.h>
215/// ...
216/// std::string language = kodi::GetLanguage(LANG_FMT_ISO_639_1, false);
217/// ...
218/// ~~~~~~~~~~~~~
219///
220inline std::string ATTRIBUTE_HIDDEN GetLanguage(LangFormats format = LANG_FMT_ENGLISH_NAME,
221 bool region = false)
222{
223 using namespace kodi::addon;
224
225 std::string language;
226 char* retString = CAddonBase::m_interface->toKodi->kodi->get_language(
227 CAddonBase::m_interface->toKodi->kodiBase, format, region);
228 if (retString != nullptr)
229 {
230 if (std::strlen(retString))
231 language = retString;
232 CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
233 retString);
234 }
235 return language;
236}
237//------------------------------------------------------------------------------
238
239//==============================================================================
240/// \ingroup cpp_kodi
241/// @brief Writes the C string pointed by format in the GUI. If format includes
242/// format specifiers (subsequences beginning with %), the additional arguments
243/// following format are formatted and inserted in the resulting string replacing
244/// their respective specifiers.
245///
246/// After the format parameter, the function expects at least as many additional
247/// arguments as specified by format.
248///
249/// @param[in] type The message type.
250/// | enum code: | Description: |
251/// |---------------:|-----------------------------------|
252/// | QUEUE_INFO | Show info notification message |
253/// | QUEUE_WARNING | Show warning notification message |
254/// | QUEUE_ERROR | Show error notification message |
255/// @param[in] format The format of the message to pass to display in Kodi.
256/// C string that contains the text to be written to the stream.
257/// It can optionally contain embedded format specifiers that are
258/// replaced by the values specified in subsequent additional
259/// arguments and formatted as requested.
260/// | specifier | Output | Example
261/// |------------|----------------------------------------------------|------------
262/// | d or i | Signed decimal integer | 392
263/// | u | Unsigned decimal integer | 7235
264/// | o | Unsigned octal | 610
265/// | x | Unsigned hexadecimal integer | 7fa
266/// | X | Unsigned hexadecimal integer (uppercase) | 7FA
267/// | f | Decimal floating point, lowercase | 392.65
268/// | F | Decimal floating point, uppercase | 392.65
269/// | e | Scientific notation (mantissa/exponent), lowercase | 3.9265e+2
270/// | E | Scientific notation (mantissa/exponent), uppercase | 3.9265E+2
271/// | g | Use the shortest representation: %e or %f | 392.65
272/// | G | Use the shortest representation: %E or %F | 392.65
273/// | a | Hexadecimal floating point, lowercase | -0xc.90fep-2
274/// | A | Hexadecimal floating point, uppercase | -0XC.90FEP-2
275/// | c | Character | a
276/// | s | String of characters | sample
277/// | p | Pointer address | b8000000
278/// | % | A % followed by another % character will write a single % to the stream. | %
279///
280/// The length sub-specifier modifies the length of the data type. This is a chart
281/// showing the types used to interpret the corresponding arguments with and without
282/// length specifier (if a different type is used, the proper type promotion or
283/// conversion is performed, if allowed):
284/// | length| d i | u o x X | f F e E g G a A | c | s | p | n |
285/// |-------|---------------|-----------------------|-----------------|-------|---------|---------|-----------------|
286/// | (none)| int | unsigned int | double | int | char* | void* | int* |
287/// | hh | signed char | unsigned char | | | | | signed char* |
288/// | h | short int | unsigned short int | | | | | short int* |
289/// | l | long int | unsigned long int | | wint_t| wchar_t*| | long int* |
290/// | ll | long long int | unsigned long long int| | | | | long long int* |
291/// | j | intmax_t | uintmax_t | | | | | intmax_t* |
292/// | z | size_t | size_t | | | | | size_t* |
293/// | t | ptrdiff_t | ptrdiff_t | | | | | ptrdiff_t* |
294/// | L | | | long double | | | | |
295/// <b>Note:</b> that the c specifier takes an int (or wint_t) as argument, but performs the proper conversion to a char value
296/// (or a wchar_t) before formatting it for output.
297/// @param[in] ... (additional arguments) Depending on the format string, the function
298/// may expect a sequence of additional arguments, each containing a value
299/// to be used to replace a format specifier in the format string (or a pointer
300/// to a storage location, for n).
301/// There should be at least as many of these arguments as the number of values specified
302/// in the format specifiers. Additional arguments are ignored by the function.
303///
304///
305/// ------------------------------------------------------------------------
306///
307/// **Example:**
308/// ~~~~~~~~~~~~~{.cpp}
309/// #include <kodi/General.h>
310/// ...
311/// kodi::QueueFormattedNotification(QUEUE_WARNING, "I'm want to inform you, here with a test call to show '%s'", "this");
312/// ...
313/// ~~~~~~~~~~~~~
314///
315inline void ATTRIBUTE_HIDDEN QueueFormattedNotification(QueueMsg type, const char* format, ...)
316{
317 using namespace kodi::addon;
318
319 va_list args;
320 char buffer[16384];
321 va_start(args, format);
322 vsprintf(buffer, format, args);
323 va_end(args);
324 CAddonBase::m_interface->toKodi->kodi->queue_notification(
325 CAddonBase::m_interface->toKodi->kodiBase, type, "", buffer, "", 5000, false, 1000);
326}
327//------------------------------------------------------------------------------
328
329//==============================================================================
330/// \ingroup cpp_kodi
331/// @brief Queue a notification in the GUI.
332///
333/// @param[in] type The message type.
334/// | enum code: | Description:
335/// |----------------------:|-----------------------------------
336/// | QUEUE_INFO | Show info notification message
337/// | QUEUE_WARNING | Show warning notification message
338/// | QUEUE_ERROR | Show error notification message
339/// | QUEUE_OWN_STYLE | If used can be with imageFile the wanted image set or if leaved empty shown as info, also are the other optional values available then
340/// @param[in] header Header Name (if leaved empty becomes addon name used)
341/// @param[in] message Message to display on Kodi
342/// @param[in] imageFile [opt] The image file to show on message (to use must be type set to QUEUE_OWN_STYLE)
343/// @param[in] displayTime [opt] The time how long message is displayed <b>(default 5 sec)</b> (to use must be type set to QUEUE_OWN_STYLE)
344/// @param[in] withSound [opt] if true also warning sound becomes played <b>(default with sound)</b> (to use must be type set to QUEUE_OWN_STYLE)
345/// @param[in] messageTime [opt] how many milli seconds start show of notification <b>(default 1 sec)</b> (to use must be type set to QUEUE_OWN_STYLE)
346///
347///
348/// ------------------------------------------------------------------------
349///
350/// **Example:**
351/// ~~~~~~~~~~~~~{.cpp}
352/// #include <kodi/General.h>
353/// ...
354/// kodi::QueueNotification(QUEUE_OWN_STYLE, "I'm want to inform you", "Here with a test call", "", 3000, false, 1000);
355/// ...
356/// ~~~~~~~~~~~~~
357///
358/// **Example:**
359/// ~~~~~~~~~~~~~{.cpp}
360/// #include <kodi/General.h>
361/// ...
362/// kodi::QueueNotification(QUEUE_WARNING, "I'm want to inform you", "Here with a test call");
363/// ...
364/// ~~~~~~~~~~~~~
365///
366/// **Example:**
367/// ~~~~~~~~~~~~~{.cpp}
368/// #include <kodi/General.h>
369/// ...
370/// kodi::QueueNotification(QUEUE_OWN_STYLE, "", "Here with a test call", "./myImage.png");
371/// ...
372/// ~~~~~~~~~~~~~
373///
374inline void ATTRIBUTE_HIDDEN QueueNotification(QueueMsg type,
375 const std::string& header,
376 const std::string& message,
377 const std::string& imageFile = "",
378 unsigned int displayTime = 5000,
379 bool withSound = true,
380 unsigned int messageTime = 1000)
381{
382 using namespace kodi::addon;
383
384 CAddonBase::m_interface->toKodi->kodi->queue_notification(
385 CAddonBase::m_interface->toKodi->kodiBase, type, header.c_str(), message.c_str(),
386 imageFile.c_str(), displayTime, withSound, messageTime);
387}
388//------------------------------------------------------------------------------
389
390//============================================================================
391/// \ingroup cpp_kodi
392/// @brief Get the MD5 digest of the given text
393///
394/// @param[in] text text to compute the MD5 for
395/// @return Returned MD5 digest
396///
397///
398/// ------------------------------------------------------------------------
399///
400/// **Example:**
401/// ~~~~~~~~~~~~~{.cpp}
402/// #include <kodi/General.h>
403/// ...
404/// std::string md5 = kodi::GetMD5("Make me as md5");
405/// fprintf(stderr, "My md5 digest is: '%s'\n", md5.c_str());
406/// ...
407/// ~~~~~~~~~~~~~
408///
409inline std::string ATTRIBUTE_HIDDEN GetMD5(const std::string& text)
410{
411 using namespace kodi::addon;
412
413 char* md5ret = static_cast<char*>(malloc(40 * sizeof(char))); // md5 size normally 32 bytes
414 CAddonBase::m_interface->toKodi->kodi->get_md5(CAddonBase::m_interface->toKodi->kodiBase,
415 text.c_str(), md5ret);
416 std::string md5 = md5ret;
417 free(md5ret);
418 return md5;
419}
420//----------------------------------------------------------------------------
421
422//==============================================================================
423/// \ingroup cpp_kodi
424/// @brief To get a temporary path for the addon
425///
426/// This gives a temporary path which the addon can use individually for its things.
427///
428/// The content of this folder will be deleted when Kodi is finished!
429///
430/// @param[in] append A string to append to returned temporary path
431/// @return Individual path for the addon
432///
433inline std::string ATTRIBUTE_HIDDEN GetTempAddonPath(const std::string& append = "")
434{
435 using namespace kodi::addon;
436
437 char* str = CAddonBase::m_interface->toKodi->kodi->get_temp_path(
438 CAddonBase::m_interface->toKodi->kodiBase);
439 std::string ret = str;
440 CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, str);
441 if (!append.empty())
442 {
443 if (append.at(0) != '\\' && append.at(0) != '/')
444#ifdef TARGET_WINDOWS
445 ret.append("\\");
446#else
447 ret.append("/");
448#endif
449 ret.append(append);
450 }
451 return ret;
452}
453//------------------------------------------------------------------------------
454
455//==============================================================================
456/// \ingroup cpp_kodi
457/// @brief Returns your regions setting as a string for the specified id
458///
459/// @param[in] id id of setting to return
460/// | | Choices are | |
461/// |:------------:|:------------:|:------------:|
462/// | dateshort | time | tempunit |
463/// | datelong | meridiem | speedunit |
464///
465/// @return settings string
466///
467///
468/// ------------------------------------------------------------------------
469///
470/// **Example:**
471/// ~~~~~~~~~~~~~{.cpp}
472/// #include <kodi/General.h>
473/// ...
474/// std::string timeFormat = kodi::GetRegion("time");
475/// ...
476/// ~~~~~~~~~~~~~
477///
478inline std::string ATTRIBUTE_HIDDEN GetRegion(const std::string& id)
479{
480 using namespace kodi::addon;
481
482 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
483
484 std::string strReturn;
485 char* strMsg = toKodi->kodi->get_region(toKodi->kodiBase, id.c_str());
486 if (strMsg != nullptr)
487 {
488 if (std::strlen(strMsg))
489 strReturn = strMsg;
490 toKodi->free_string(toKodi->kodiBase, strMsg);
491 }
492 return strReturn;
493}
494//------------------------------------------------------------------------------
495
496//==============================================================================
497/// \ingroup cpp_kodi
498/// @brief Returns the amount of free memory in MByte (or as bytes) as an long
499/// integer
500///
501/// @param[out] free free memory
502/// @param[out] total total memory
503/// @param[in] asBytes [opt] if set to true becomes returned as bytes, otherwise
504/// as mega bytes
505///
506///
507/// ------------------------------------------------------------------------
508///
509/// **Example:**
510/// ~~~~~~~~~~~~~{.cpp}
511/// #include <kodi/General.h>
512/// ...
513/// long freeMem;
514/// long totalMem;
515/// kodi::GetFreeMem(freeMem, totalMem);
516/// ...
517/// ~~~~~~~~~~~~~
518///
519inline void ATTRIBUTE_HIDDEN GetFreeMem(long& free, long& total, bool asBytes = false)
520{
521 using namespace kodi::addon;
522
523 free = -1;
524 total = -1;
525 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
526 toKodi->kodi->get_free_mem(toKodi->kodiBase, &free, &total, asBytes);
527}
528//------------------------------------------------------------------------------
529
530//==============================================================================
531/// \ingroup cpp_kodi
532/// @brief Returns the elapsed idle time in seconds as an integer
533///
534/// @return idle time
535///
536///
537/// ------------------------------------------------------------------------
538///
539/// **Example:**
540/// ~~~~~~~~~~~~~{.cpp}
541/// #include <kodi/General.h>
542/// ...
543/// int time = kodi::GetGlobalIdleTime();
544/// ...
545/// ~~~~~~~~~~~~~
546///
547inline int ATTRIBUTE_HIDDEN GetGlobalIdleTime()
548{
549 using namespace kodi::addon;
550
551 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
552 return toKodi->kodi->get_global_idle_time(toKodi->kodiBase);
553}
554//------------------------------------------------------------------------------
555
556//==============================================================================
557/// \ingroup cpp_kodi
558/// @brief Get the currently used skin identification name from Kodi
559///
560/// @return The active skin id name as a string
561///
562///
563/// @note This is not the full path like 'special://home/addons/MediaCenter',
564/// but only 'MediaCenter'.
565///
566///
567/// ------------------------------------------------------------------------
568///
569/// **Example:**
570/// ~~~~~~~~~~~~~{.cpp}
571/// #include <kodi/General.h>
572/// ..
573/// std::string skinid = kodi::GetCurrentSkinId();
574/// ..
575/// ~~~~~~~~~~~~~
576///
577inline std::string ATTRIBUTE_HIDDEN GetCurrentSkinId()
578{
579 using namespace kodi::addon;
580
581 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
582
583 std::string strReturn;
584 char* strMsg = toKodi->kodi->get_current_skin_id(toKodi->kodiBase);
585 if (strMsg != nullptr)
586 {
587 if (std::strlen(strMsg))
588 strReturn = strMsg;
589 toKodi->free_string(toKodi->kodiBase, strMsg);
590 }
591 return strReturn;
592}
593//------------------------------------------------------------------------------
594
595//==============================================================================
596/// @brief To check another addon is available and usable inside Kodi.
597///
598/// @param[in] id The wanted addon identification string to check
599/// @param[out] version Version string of addon if **installed** inside Kodi
600/// @param[out] enabled Set to true <b>`true* </b> if addon is enabled
601/// @return Returns <b>`true* </b> if addon is installed
602///
603///
604/// ------------------------------------------------------------------------
605///
606/// **Example:**
607/// ~~~~~~~~~~~~~{.cpp}
608/// #include <kodi/General.h>
609///
610/// bool enabled = false;
611/// std::string version;
612/// bool ret = kodi::IsAddonAvailable("inputstream.adaptive", version, enabled);
613/// fprintf(stderr, "Available inputstream.adaptive version '%s' and enabled '%s'\n",
614/// ret ? version.c_str() : "not installed", enabled ? "yes" : "no");
615/// ~~~~~~~~~~~~~
616///
617inline bool ATTRIBUTE_HIDDEN IsAddonAvailable(const std::string& id,
618 std::string& version,
619 bool& enabled)
620{
621 using namespace kodi::addon;
622
623 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
624
625 char* cVersion = nullptr;
626 bool ret = toKodi->kodi->is_addon_avilable(toKodi->kodiBase, id.c_str(), &cVersion, &enabled);
627 if (cVersion)
628 {
629 version = cVersion;
630 toKodi->free_string(toKodi->kodiBase, cVersion);
631 }
632 return ret;
633}
634//------------------------------------------------------------------------------
635
636//==============================================================================
637/// \ingroup cpp_kodi
638/// @brief Get current Kodi informations and versions, returned data from the following
639/// <b><tt>kodi_version_t version; kodi::KodiVersion(version);</tt></b>
640/// is e.g.:
641/// ~~~~~~~~~~~~~{.cpp}
642/// version.compile_name = Kodi
643/// version.major = 18
644/// version.minor = 0
645/// version.revision = 20170706-c6b22fe217-di
646/// version.tag = alpha
647/// version.tag_revision = 1
648/// ~~~~~~~~~~~~~
649///
650/// @param[out] version structure to store data from kodi
651///
652///
653/// ------------------------------------------------------------------------
654///
655/// **Example:**
656/// ~~~~~~~~~~~~~{.cpp}
657/// #include <kodi/General.h>
658/// ...
659/// kodi_version_t version;
660/// kodi::KodiVersion(version);
661/// fprintf(stderr,
662/// "kodi_version_t version;\n"
663/// "kodi::KodiVersion(version);\n"
664/// " - version.compile_name = %s\n"
665/// " - version.major = %i\n"
666/// " - version.minor = %i\n"
667/// " - version.revision = %s\n"
668/// " - version.tag = %s\n"
669/// " - version.tag_revision = %s\n",
670/// version.compile_name.c_str(), version.major, version.minor,
671/// version.revision.c_str(), version.tag.c_str(), version.tag_revision.c_str());
672/// ...
673/// ~~~~~~~~~~~~~
674///
675inline void ATTRIBUTE_HIDDEN KodiVersion(kodi_version_t& version)
676{
677 using namespace kodi::addon;
678
679 char* compile_name = nullptr;
680 char* revision = nullptr;
681 char* tag = nullptr;
682 char* tag_revision = nullptr;
683
684 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
685 toKodi->kodi->kodi_version(toKodi->kodiBase, &compile_name, &version.major, &version.minor,
686 &revision, &tag, &tag_revision);
687 if (compile_name != nullptr)
688 {
689 version.compile_name = compile_name;
690 toKodi->free_string(toKodi->kodiBase, compile_name);
691 }
692 if (revision != nullptr)
693 {
694 version.revision = revision;
695 toKodi->free_string(toKodi->kodiBase, revision);
696 }
697 if (tag != nullptr)
698 {
699 version.tag = tag;
700 toKodi->free_string(toKodi->kodiBase, tag);
701 }
702 if (tag_revision != nullptr)
703 {
704 version.tag_revision = tag_revision;
705 toKodi->free_string(toKodi->kodiBase, tag_revision);
706 }
707}
708//------------------------------------------------------------------------------
709
710//==============================================================================
711/// \ingroup cpp_kodi
712/// @brief To get keyboard layout characters
713///
714/// This is used to get the keyboard layout currently used from Kodi by the
715/// there set language.
716///
717/// @param[in] modifierKey the key to define the needed layout (uppercase, symbols...)
718/// @param[out] layout_name name of used layout
719/// @param[out] layout list of selected keyboard layout
720/// @return true if request successed
721///
722///
723/// ------------------------------------------------------------------------
724///
725/// **Example:**
726/// ~~~~~~~~~~~~~{.cpp}
727/// #include <kodi/General.h>
728/// ...
729/// std::string layout_name;
730/// std::vector<std::vector<std::string>> layout;
731/// kodi::GetKeyboardLayout(STD_KB_MODIFIER_KEY_SHIFT | STD_KB_MODIFIER_KEY_SYMBOL, layout_name, layout);
732/// fprintf(stderr, "Layout: '%s'\n", layout_name.c_str());
733/// for (unsigned int row = 0; row < STD_KB_BUTTONS_MAX_ROWS; row++)
734/// {
735/// for (unsigned int column = 0; column < STD_KB_BUTTONS_PER_ROW; column++)
736/// {
737/// fprintf(stderr, " - Row: '%02i'; Column: '%02i'; Text: '%s'\n", row, column, layout[row][column].c_str());
738/// }
739/// }
740/// ...
741/// ~~~~~~~~~~~~~
742///
743inline bool ATTRIBUTE_HIDDEN GetKeyboardLayout(int modifierKey,
744 std::string& layout_name,
745 std::vector<std::vector<std::string>>& layout)
746{
747 using namespace kodi::addon;
748
749 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
750 AddonKeyboardKeyTable c_layout;
751 char* c_layout_name = nullptr;
752 bool ret =
753 toKodi->kodi->get_keyboard_layout(toKodi->kodiBase, &c_layout_name, modifierKey, &c_layout);
754 if (ret)
755 {
756 if (c_layout_name)
757 {
758 layout_name = c_layout_name;
759 toKodi->free_string(toKodi->kodiBase, c_layout_name);
760 }
761
762 layout.resize(STD_KB_BUTTONS_MAX_ROWS);
763 for (unsigned int row = 0; row < STD_KB_BUTTONS_MAX_ROWS; row++)
764 {
765 layout[row].resize(STD_KB_BUTTONS_PER_ROW);
766 for (unsigned int column = 0; column < STD_KB_BUTTONS_PER_ROW; column++)
767 {
768 char* button = c_layout.keys[row][column];
769 if (button)
770 {
771 layout[row][column] = button;
772 toKodi->free_string(toKodi->kodiBase, button);
773 }
774 }
775 }
776 }
777 return ret;
778}
779//------------------------------------------------------------------------------
780
781//==============================================================================
782/// \ingroup cpp_kodi
783/// @brief To change keyboard layout characters
784///
785/// This is used to change the keyboard layout currently used from Kodi
786///
787/// @param[out] layout_name new name of used layout (input string not used!)
788/// @return true if request successed
789///
790/// @note \ref GetKeyboardLayout must be called afterwards.
791///
792///
793/// ------------------------------------------------------------------------
794///
795/// **Example:**
796/// ~~~~~~~~~~~~~{.cpp}
797/// #include <kodi/General.h>
798/// ...
799/// std::string layout_name;
800/// kodi::ChangeKeyboardLayout(layout_name);
801///
802/// std::vector<std::vector<std::string>> layout;
803/// kodi::GetKeyboardLayout(STD_KB_MODIFIER_KEY_SHIFT | STD_KB_MODIFIER_KEY_SYMBOL, layout_name, layout);
804/// fprintf(stderr, "Layout: '%s'\n", layout_name.c_str());
805/// for (unsigned int row = 0; row < STD_KB_BUTTONS_MAX_ROWS; row++)
806/// {
807/// for (unsigned int column = 0; column < STD_KB_BUTTONS_PER_ROW; column++)
808/// {
809/// fprintf(stderr, " - Row: '%02i'; Column: '%02i'; Text: '%s'\n", row, column, layout[row][column].c_str());
810/// }
811/// }
812/// ...
813/// ~~~~~~~~~~~~~
814///
815inline bool ATTRIBUTE_HIDDEN ChangeKeyboardLayout(std::string& layout_name)
816{
817 using namespace kodi::addon;
818
819 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
820 char* c_layout_name = nullptr;
821 bool ret = toKodi->kodi->change_keyboard_layout(toKodi->kodiBase, &c_layout_name);
822 if (c_layout_name)
823 {
824 layout_name = c_layout_name;
825 toKodi->free_string(toKodi->kodiBase, c_layout_name);
826 }
827
828 return ret;
829}
830//------------------------------------------------------------------------------
831
832} /* namespace kodi */
833
834#endif /* __cplusplus */