summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-07-02 23:09:26 +0200
committermanuel <manuel@mausz.at>2020-07-02 23:09:26 +0200
commit5f8335c1e49ce108ef3481863833c98efa00411b (patch)
treef02b5c1c9765bb6a14c8eb42bb4f81b9face0b55 /xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h
parente317daf081a1048904fdf0b548946fa3ba6593a7 (diff)
downloadkodi-pvr-build-master.tar.gz
kodi-pvr-build-master.tar.bz2
kodi-pvr-build-master.zip
sync with upstreamHEADmaster
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.h409
1 files changed, 257 insertions, 152 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
index 999ff6a..878eaa4 100644
--- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h
@@ -9,68 +9,9 @@
9#pragma once 9#pragma once
10 10
11#include "AddonBase.h" 11#include "AddonBase.h"
12#include "c-api/general.h"
12 13
13/* 14#ifdef __cplusplus
14 * For interface between add-on and kodi.
15 *
16 * This structure defines the addresses of functions stored inside Kodi which
17 * are then available for the add-on to call
18 *
19 * All function pointers there are used by the C++ interface functions below.
20 * You find the set of them on xbmc/addons/interfaces/General.cpp
21 *
22 * Note: For add-on development itself this is not needed
23 */
24typedef struct AddonToKodiFuncTable_kodi
25{
26 char* (*get_addon_info)(void* kodiBase, const char* id);
27 bool (*open_settings_dialog)(void* kodiBase);
28 char* (*unknown_to_utf8)(void* kodiBase, const char* source, bool* ret, bool failOnBadChar);
29 char* (*get_localized_string)(void* kodiBase, long label_id);
30 char* (*get_language)(void* kodiBase, int format, bool region);
31 bool (*queue_notification)(void* kodiBase, int type, const char* header, const char* message, const char* imageFile, unsigned int displayTime, bool withSound, unsigned int messageTime);
32 void (*get_md5)(void* kodiBase, const char* text, char* md5);
33 char* (*get_temp_path)(void* kodiBase);
34 char* (*get_region)(void* kodiBase, const char* id);
35 void (*get_free_mem)(void* kodiBase, long* free, long* total, bool as_bytes);
36 int (*get_global_idle_time)(void* kodiBase);
37 void (*kodi_version)(void* kodiBase, char** compile_name, int* major, int* minor, char** revision, char** tag, char** tagversion);
38 char* (*get_current_skin_id)(void* kodiBase);
39} AddonToKodiFuncTable_kodi;
40
41//==============================================================================
42/// \ingroup cpp_kodi_Defs
43/// @brief For kodi::QueueNotification() used message types
44///
45typedef enum QueueMsg
46{
47 /// Show info notification message
48 QUEUE_INFO,
49 /// Show warning notification message
50 QUEUE_WARNING,
51 /// Show error notification message
52 QUEUE_ERROR,
53 /// Show with own given image and parts if set on values
54 QUEUE_OWN_STYLE
55} QueueMsg;
56//------------------------------------------------------------------------------
57
58//==============================================================================
59/// \ingroup cpp_kodi_Defs
60/// @brief Format codes to get string from them.
61///
62/// Used on kodi::GetLanguage().
63///
64typedef enum LangFormats
65{
66 /// two letter code as defined in ISO 639-1
67 LANG_FMT_ISO_639_1,
68 /// three letter code as defined in ISO 639-2/T or ISO 639-2/B
69 LANG_FMT_ISO_639_2,
70 /// full language name in English
71 LANG_FMT_ENGLISH_NAME
72} LangFormats;
73//------------------------------------------------------------------------------
74 15
75//============================================================================== 16//==============================================================================
76/// \ingroup cpp_kodi_Defs 17/// \ingroup cpp_kodi_Defs
@@ -93,9 +34,10 @@ typedef struct kodi_version_t
93} kodi_version_t; 34} kodi_version_t;
94//------------------------------------------------------------------------------ 35//------------------------------------------------------------------------------
95 36
37namespace kodi
38{
39
96//============================================================================== 40//==============================================================================
97namespace kodi {
98///
99/// \ingroup cpp_kodi 41/// \ingroup cpp_kodi
100/// @brief Returns the value of an addon property as a string 42/// @brief Returns the value of an addon property as a string
101/// 43///
@@ -121,9 +63,11 @@ namespace kodi {
121/// ... 63/// ...
122/// ~~~~~~~~~~~~~ 64/// ~~~~~~~~~~~~~
123/// 65///
124inline std::string GetAddonInfo(const std::string& id) 66inline std::string ATTRIBUTE_HIDDEN GetAddonInfo(const std::string& id)
125{ 67{
126 AddonToKodiFuncTable_Addon* toKodi = ::kodi::addon::CAddonBase::m_interface->toKodi; 68 using namespace kodi::addon;
69
70 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
127 71
128 std::string strReturn; 72 std::string strReturn;
129 char* strMsg = toKodi->kodi->get_addon_info(toKodi->kodiBase, id.c_str()); 73 char* strMsg = toKodi->kodi->get_addon_info(toKodi->kodiBase, id.c_str());
@@ -135,12 +79,9 @@ inline std::string GetAddonInfo(const std::string& id)
135 } 79 }
136 return strReturn; 80 return strReturn;
137} 81}
138} /* namespace kodi */
139//------------------------------------------------------------------------------ 82//------------------------------------------------------------------------------
140 83
141//============================================================================== 84//==============================================================================
142namespace kodi {
143///
144/// \ingroup cpp_kodi 85/// \ingroup cpp_kodi
145/// @brief Opens this Add-Ons settings dialog. 86/// @brief Opens this Add-Ons settings dialog.
146/// 87///
@@ -157,16 +98,15 @@ namespace kodi {
157/// .. 98/// ..
158/// ~~~~~~~~~~~~~ 99/// ~~~~~~~~~~~~~
159/// 100///
160inline bool OpenSettings() 101inline bool ATTRIBUTE_HIDDEN OpenSettings()
161{ 102{
162 return ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->open_settings_dialog(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase); 103 using namespace kodi::addon;
104 return CAddonBase::m_interface->toKodi->kodi->open_settings_dialog(
105 CAddonBase::m_interface->toKodi->kodiBase);
163} 106}
164} /* namespace kodi */
165//------------------------------------------------------------------------------ 107//------------------------------------------------------------------------------
166 108
167//============================================================================== 109//==============================================================================
168namespace kodi {
169///
170/// \ingroup cpp_kodi 110/// \ingroup cpp_kodi
171/// @brief Returns an addon's localized 'unicode string'. 111/// @brief Returns an addon's localized 'unicode string'.
172/// 112///
@@ -193,24 +133,25 @@ namespace kodi {
193/// ... 133/// ...
194/// ~~~~~~~~~~~~~ 134/// ~~~~~~~~~~~~~
195/// 135///
196inline std::string GetLocalizedString(uint32_t labelId, const std::string& defaultStr = "") 136inline std::string ATTRIBUTE_HIDDEN GetLocalizedString(uint32_t labelId,
137 const std::string& defaultStr = "")
197{ 138{
139 using namespace kodi::addon;
140
198 std::string retString = defaultStr; 141 std::string retString = defaultStr;
199 char* strMsg = ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->get_localized_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, labelId); 142 char* strMsg = CAddonBase::m_interface->toKodi->kodi->get_localized_string(
143 CAddonBase::m_interface->toKodi->kodiBase, labelId);
200 if (strMsg != nullptr) 144 if (strMsg != nullptr)
201 { 145 {
202 if (std::strlen(strMsg)) 146 if (std::strlen(strMsg))
203 retString = strMsg; 147 retString = strMsg;
204 ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, strMsg); 148 CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, strMsg);
205 } 149 }
206 return retString; 150 return retString;
207} 151}
208} /* namespace kodi */
209//------------------------------------------------------------------------------ 152//------------------------------------------------------------------------------
210 153
211//============================================================================== 154//==============================================================================
212namespace kodi {
213///
214/// \ingroup cpp_kodi 155/// \ingroup cpp_kodi
215/// @brief Translate a string with an unknown encoding to UTF8. 156/// @brief Translate a string with an unknown encoding to UTF8.
216/// 157///
@@ -232,25 +173,27 @@ namespace kodi {
232/// ... 173/// ...
233/// ~~~~~~~~~~~~~ 174/// ~~~~~~~~~~~~~
234/// 175///
235inline bool UnknownToUTF8(const std::string& stringSrc, std::string& utf8StringDst, bool failOnBadChar = false) 176inline bool ATTRIBUTE_HIDDEN UnknownToUTF8(const std::string& stringSrc,
177 std::string& utf8StringDst,
178 bool failOnBadChar = false)
236{ 179{
180 using namespace kodi::addon;
181
237 bool ret = false; 182 bool ret = false;
238 char* retString = ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->unknown_to_utf8(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, 183 char* retString = CAddonBase::m_interface->toKodi->kodi->unknown_to_utf8(
239 stringSrc.c_str(), &ret, failOnBadChar); 184 CAddonBase::m_interface->toKodi->kodiBase, stringSrc.c_str(), &ret, failOnBadChar);
240 if (retString != nullptr) 185 if (retString != nullptr)
241 { 186 {
242 if (ret) 187 if (ret)
243 utf8StringDst = retString; 188 utf8StringDst = retString;
244 ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, retString); 189 CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
190 retString);
245 } 191 }
246 return ret; 192 return ret;
247} 193}
248} /* namespace kodi */
249//------------------------------------------------------------------------------ 194//------------------------------------------------------------------------------
250 195
251//============================================================================== 196//==============================================================================
252namespace kodi {
253///
254/// \ingroup cpp_kodi 197/// \ingroup cpp_kodi
255/// @brief Returns the active language as a string. 198/// @brief Returns the active language as a string.
256/// 199///
@@ -274,24 +217,26 @@ namespace kodi {
274/// ... 217/// ...
275/// ~~~~~~~~~~~~~ 218/// ~~~~~~~~~~~~~
276/// 219///
277inline std::string GetLanguage(LangFormats format = LANG_FMT_ENGLISH_NAME, bool region = false) 220inline std::string ATTRIBUTE_HIDDEN GetLanguage(LangFormats format = LANG_FMT_ENGLISH_NAME,
221 bool region = false)
278{ 222{
223 using namespace kodi::addon;
224
279 std::string language; 225 std::string language;
280 char* retString = ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->get_language(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, format, region); 226 char* retString = CAddonBase::m_interface->toKodi->kodi->get_language(
227 CAddonBase::m_interface->toKodi->kodiBase, format, region);
281 if (retString != nullptr) 228 if (retString != nullptr)
282 { 229 {
283 if (std::strlen(retString)) 230 if (std::strlen(retString))
284 language = retString; 231 language = retString;
285 ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, retString); 232 CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase,
233 retString);
286 } 234 }
287 return language; 235 return language;
288} 236}
289} /* namespace kodi */
290//------------------------------------------------------------------------------ 237//------------------------------------------------------------------------------
291 238
292//============================================================================== 239//==============================================================================
293namespace kodi {
294///
295/// \ingroup cpp_kodi 240/// \ingroup cpp_kodi
296/// @brief Writes the C string pointed by format in the GUI. If format includes 241/// @brief Writes the C string pointed by format in the GUI. If format includes
297/// format specifiers (subsequences beginning with %), the additional arguments 242/// format specifiers (subsequences beginning with %), the additional arguments
@@ -367,22 +312,21 @@ namespace kodi {
367/// ... 312/// ...
368/// ~~~~~~~~~~~~~ 313/// ~~~~~~~~~~~~~
369/// 314///
370inline void QueueFormattedNotification(QueueMsg type, const char* format, ... ) 315inline void ATTRIBUTE_HIDDEN QueueFormattedNotification(QueueMsg type, const char* format, ...)
371{ 316{
317 using namespace kodi::addon;
318
372 va_list args; 319 va_list args;
373 char buffer[16384]; 320 char buffer[16384];
374 va_start(args, format); 321 va_start(args, format);
375 vsprintf(buffer, format, args); 322 vsprintf(buffer, format, args);
376 va_end(args); 323 va_end(args);
377 ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->queue_notification(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, 324 CAddonBase::m_interface->toKodi->kodi->queue_notification(
378 type, "", buffer, "", 5000, false, 1000); 325 CAddonBase::m_interface->toKodi->kodiBase, type, "", buffer, "", 5000, false, 1000);
379} 326}
380} /* namespace kodi */
381//------------------------------------------------------------------------------ 327//------------------------------------------------------------------------------
382 328
383//============================================================================== 329//==============================================================================
384namespace kodi {
385///
386/// \ingroup cpp_kodi 330/// \ingroup cpp_kodi
387/// @brief Queue a notification in the GUI. 331/// @brief Queue a notification in the GUI.
388/// 332///
@@ -427,21 +371,23 @@ namespace kodi {
427/// ... 371/// ...
428/// ~~~~~~~~~~~~~ 372/// ~~~~~~~~~~~~~
429/// 373///
430inline void QueueNotification(QueueMsg type, const std::string& header, 374inline void ATTRIBUTE_HIDDEN QueueNotification(QueueMsg type,
431 const std::string& message, const std::string& imageFile = "", 375 const std::string& header,
432 unsigned int displayTime = 5000, bool withSound = true, 376 const std::string& message,
433 unsigned int messageTime = 1000) 377 const std::string& imageFile = "",
378 unsigned int displayTime = 5000,
379 bool withSound = true,
380 unsigned int messageTime = 1000)
434{ 381{
435 ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->queue_notification(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, 382 using namespace kodi::addon;
436 type, header.c_str(), message.c_str(), imageFile.c_str(), displayTime, 383
437 withSound, messageTime); 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);
438} 387}
439} /* namespace kodi */
440//------------------------------------------------------------------------------ 388//------------------------------------------------------------------------------
441 389
442//============================================================================ 390//============================================================================
443namespace kodi {
444///
445/// \ingroup cpp_kodi 391/// \ingroup cpp_kodi
446/// @brief Get the MD5 digest of the given text 392/// @brief Get the MD5 digest of the given text
447/// 393///
@@ -460,20 +406,20 @@ namespace kodi {
460/// ... 406/// ...
461/// ~~~~~~~~~~~~~ 407/// ~~~~~~~~~~~~~
462/// 408///
463inline std::string GetMD5(const std::string& text) 409inline std::string ATTRIBUTE_HIDDEN GetMD5(const std::string& text)
464{ 410{
465 char* md5ret = static_cast<char*>(malloc(40*sizeof(char))); // md5 size normally 32 bytes 411 using namespace kodi::addon;
466 ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->get_md5(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, text.c_str(), md5ret); 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);
467 std::string md5 = md5ret; 416 std::string md5 = md5ret;
468 free(md5ret); 417 free(md5ret);
469 return md5; 418 return md5;
470} 419}
471} /* namespace kodi */
472//---------------------------------------------------------------------------- 420//----------------------------------------------------------------------------
473 421
474//============================================================================== 422//==============================================================================
475namespace kodi {
476///
477/// \ingroup cpp_kodi 423/// \ingroup cpp_kodi
478/// @brief To get a temporary path for the addon 424/// @brief To get a temporary path for the addon
479/// 425///
@@ -484,15 +430,17 @@ namespace kodi {
484/// @param[in] append A string to append to returned temporary path 430/// @param[in] append A string to append to returned temporary path
485/// @return Individual path for the addon 431/// @return Individual path for the addon
486/// 432///
487inline std::string GetTempAddonPath(const std::string& append = "") 433inline std::string ATTRIBUTE_HIDDEN GetTempAddonPath(const std::string& append = "")
488{ 434{
489 char* str = ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->get_temp_path(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase); 435 using namespace kodi::addon;
436
437 char* str = CAddonBase::m_interface->toKodi->kodi->get_temp_path(
438 CAddonBase::m_interface->toKodi->kodiBase);
490 std::string ret = str; 439 std::string ret = str;
491 ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, str); 440 CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, str);
492 if (!append.empty()) 441 if (!append.empty())
493 { 442 {
494 if (append.at(0) != '\\' && 443 if (append.at(0) != '\\' && append.at(0) != '/')
495 append.at(0) != '/')
496#ifdef TARGET_WINDOWS 444#ifdef TARGET_WINDOWS
497 ret.append("\\"); 445 ret.append("\\");
498#else 446#else
@@ -502,12 +450,9 @@ inline std::string GetTempAddonPath(const std::string& append = "")
502 } 450 }
503 return ret; 451 return ret;
504} 452}
505} /* namespace kodi */
506//------------------------------------------------------------------------------ 453//------------------------------------------------------------------------------
507 454
508//============================================================================== 455//==============================================================================
509namespace kodi {
510///
511/// \ingroup cpp_kodi 456/// \ingroup cpp_kodi
512/// @brief Returns your regions setting as a string for the specified id 457/// @brief Returns your regions setting as a string for the specified id
513/// 458///
@@ -530,9 +475,11 @@ namespace kodi {
530/// ... 475/// ...
531/// ~~~~~~~~~~~~~ 476/// ~~~~~~~~~~~~~
532/// 477///
533inline std::string GetRegion(const std::string& id) 478inline std::string ATTRIBUTE_HIDDEN GetRegion(const std::string& id)
534{ 479{
535 AddonToKodiFuncTable_Addon* toKodi = ::kodi::addon::CAddonBase::m_interface->toKodi; 480 using namespace kodi::addon;
481
482 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
536 483
537 std::string strReturn; 484 std::string strReturn;
538 char* strMsg = toKodi->kodi->get_region(toKodi->kodiBase, id.c_str()); 485 char* strMsg = toKodi->kodi->get_region(toKodi->kodiBase, id.c_str());
@@ -544,12 +491,9 @@ inline std::string GetRegion(const std::string& id)
544 } 491 }
545 return strReturn; 492 return strReturn;
546} 493}
547} /* namespace kodi */
548//------------------------------------------------------------------------------ 494//------------------------------------------------------------------------------
549 495
550//============================================================================== 496//==============================================================================
551namespace kodi {
552///
553/// \ingroup cpp_kodi 497/// \ingroup cpp_kodi
554/// @brief Returns the amount of free memory in MByte (or as bytes) as an long 498/// @brief Returns the amount of free memory in MByte (or as bytes) as an long
555/// integer 499/// integer
@@ -572,19 +516,18 @@ namespace kodi {
572/// ... 516/// ...
573/// ~~~~~~~~~~~~~ 517/// ~~~~~~~~~~~~~
574/// 518///
575inline void GetFreeMem(long& free, long& total, bool asBytes = false) 519inline void ATTRIBUTE_HIDDEN GetFreeMem(long& free, long& total, bool asBytes = false)
576{ 520{
521 using namespace kodi::addon;
522
577 free = -1; 523 free = -1;
578 total = -1; 524 total = -1;
579 AddonToKodiFuncTable_Addon* toKodi = ::kodi::addon::CAddonBase::m_interface->toKodi; 525 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
580 toKodi->kodi->get_free_mem(toKodi->kodiBase, &free, &total, asBytes); 526 toKodi->kodi->get_free_mem(toKodi->kodiBase, &free, &total, asBytes);
581} 527}
582} /* namespace kodi */
583//------------------------------------------------------------------------------ 528//------------------------------------------------------------------------------
584 529
585//============================================================================== 530//==============================================================================
586namespace kodi {
587///
588/// \ingroup cpp_kodi 531/// \ingroup cpp_kodi
589/// @brief Returns the elapsed idle time in seconds as an integer 532/// @brief Returns the elapsed idle time in seconds as an integer
590/// 533///
@@ -601,20 +544,18 @@ namespace kodi {
601/// ... 544/// ...
602/// ~~~~~~~~~~~~~ 545/// ~~~~~~~~~~~~~
603/// 546///
604inline int GetGlobalIdleTime() 547inline int ATTRIBUTE_HIDDEN GetGlobalIdleTime()
605{ 548{
606 AddonToKodiFuncTable_Addon* toKodi = ::kodi::addon::CAddonBase::m_interface->toKodi; 549 using namespace kodi::addon;
550
551 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
607 return toKodi->kodi->get_global_idle_time(toKodi->kodiBase); 552 return toKodi->kodi->get_global_idle_time(toKodi->kodiBase);
608} 553}
609} /* namespace kodi */
610//------------------------------------------------------------------------------ 554//------------------------------------------------------------------------------
611 555
612//============================================================================== 556//==============================================================================
613namespace kodi {
614///
615/// \ingroup cpp_kodi 557/// \ingroup cpp_kodi
616/// @brief Get the currently used skin identification name from Kodi 558/// @brief Get the currently used skin identification name from Kodi
617///-----------------------------------------------------------------------
618/// 559///
619/// @return The active skin id name as a string 560/// @return The active skin id name as a string
620/// 561///
@@ -633,9 +574,11 @@ namespace kodi {
633/// .. 574/// ..
634/// ~~~~~~~~~~~~~ 575/// ~~~~~~~~~~~~~
635/// 576///
636inline std::string GetCurrentSkinId() 577inline std::string ATTRIBUTE_HIDDEN GetCurrentSkinId()
637{ 578{
638 AddonToKodiFuncTable_Addon* toKodi = ::kodi::addon::CAddonBase::m_interface->toKodi; 579 using namespace kodi::addon;
580
581 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
639 582
640 std::string strReturn; 583 std::string strReturn;
641 char* strMsg = toKodi->kodi->get_current_skin_id(toKodi->kodiBase); 584 char* strMsg = toKodi->kodi->get_current_skin_id(toKodi->kodiBase);
@@ -647,12 +590,50 @@ inline std::string GetCurrentSkinId()
647 } 590 }
648 return strReturn; 591 return strReturn;
649} 592}
650} /* namespace kodi */
651//------------------------------------------------------------------------------ 593//------------------------------------------------------------------------------
652 594
653//============================================================================== 595//==============================================================================
654namespace kodi { 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>
655/// 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//==============================================================================
656/// \ingroup cpp_kodi 637/// \ingroup cpp_kodi
657/// @brief Get current Kodi informations and versions, returned data from the following 638/// @brief Get current Kodi informations and versions, returned data from the following
658/// <b><tt>kodi_version_t version; kodi::KodiVersion(version);</tt></b> 639/// <b><tt>kodi_version_t version; kodi::KodiVersion(version);</tt></b>
@@ -691,23 +672,22 @@ namespace kodi {
691/// ... 672/// ...
692/// ~~~~~~~~~~~~~ 673/// ~~~~~~~~~~~~~
693/// 674///
694inline void KodiVersion(kodi_version_t& version) 675inline void ATTRIBUTE_HIDDEN KodiVersion(kodi_version_t& version)
695{ 676{
677 using namespace kodi::addon;
678
696 char* compile_name = nullptr; 679 char* compile_name = nullptr;
697 char* revision = nullptr; 680 char* revision = nullptr;
698 char* tag = nullptr; 681 char* tag = nullptr;
699 char* tag_revision = nullptr; 682 char* tag_revision = nullptr;
700 683
701 AddonToKodiFuncTable_Addon* toKodi = ::kodi::addon::CAddonBase::m_interface->toKodi; 684 AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi;
702 toKodi->kodi->kodi_version(toKodi->kodiBase, &compile_name, &version.major, &version.minor, &revision, &tag, &tag_revision); 685 toKodi->kodi->kodi_version(toKodi->kodiBase, &compile_name, &version.major, &version.minor,
686 &revision, &tag, &tag_revision);
703 if (compile_name != nullptr) 687 if (compile_name != nullptr)
704 { 688 {
705 version.compile_name = compile_name; 689 version.compile_name = compile_name;
706 toKodi->free_string 690 toKodi->free_string(toKodi->kodiBase, compile_name);
707 (
708 toKodi->kodiBase,
709 compile_name
710 );
711 } 691 }
712 if (revision != nullptr) 692 if (revision != nullptr)
713 { 693 {
@@ -725,5 +705,130 @@ inline void KodiVersion(kodi_version_t& version)
725 toKodi->free_string(toKodi->kodiBase, tag_revision); 705 toKodi->free_string(toKodi->kodiBase, tag_revision);
726 } 706 }
727} 707}
728} /* namespace kodi */
729//------------------------------------------------------------------------------ 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 */