diff options
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/General.h')
| -rw-r--r-- | xbmc/addons/kodi-dev-kit/include/kodi/General.h | 834 |
1 files changed, 834 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/General.h b/xbmc/addons/kodi-dev-kit/include/kodi/General.h new file mode 100644 index 0000000..3fad5a0 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/General.h | |||
| @@ -0,0 +1,834 @@ | |||
| 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 | #include "tools/StringUtils.h" | ||
| 14 | |||
| 15 | #ifdef __cplusplus | ||
| 16 | |||
| 17 | //============================================================================== | ||
| 18 | /// \ingroup cpp_kodi_Defs | ||
| 19 | /// @brief For kodi::Version used structure | ||
| 20 | /// | ||
| 21 | typedef struct kodi_version_t | ||
| 22 | { | ||
| 23 | /// Application name, normally 'Kodi' | ||
| 24 | std::string compile_name; | ||
| 25 | /// Major code version of Kodi | ||
| 26 | int major; | ||
| 27 | /// Minor code version of Kodi | ||
| 28 | int minor; | ||
| 29 | /// The Revision contains a id and the build date, e.g. 20170706-c6b22fe217-dirty | ||
| 30 | std::string revision; | ||
| 31 | /// The version canditate e.g. alpha, beta or release | ||
| 32 | std::string tag; | ||
| 33 | /// The revision of tag before | ||
| 34 | std::string tag_revision; | ||
| 35 | } kodi_version_t; | ||
| 36 | //------------------------------------------------------------------------------ | ||
| 37 | |||
| 38 | namespace kodi | ||
| 39 | { | ||
| 40 | |||
| 41 | //============================================================================== | ||
| 42 | /// \ingroup cpp_kodi | ||
| 43 | /// @brief Returns the value of an addon property as a string | ||
| 44 | /// | ||
| 45 | /// @param[in] id id of the property that the module needs to access | ||
| 46 | /// | | Choices are | | | ||
| 47 | /// |:------------:|:------------:|:------------:| | ||
| 48 | /// | author | icon | stars | | ||
| 49 | /// | changelog | id | summary | | ||
| 50 | /// | description | name | type | | ||
| 51 | /// | disclaimer | path | version | | ||
| 52 | /// | fanart | profile | | | ||
| 53 | /// | ||
| 54 | /// @return AddOn property as a string | ||
| 55 | /// | ||
| 56 | /// | ||
| 57 | /// ------------------------------------------------------------------------ | ||
| 58 | /// | ||
| 59 | /// **Example:** | ||
| 60 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 61 | /// #include <kodi/General.h> | ||
| 62 | /// ... | ||
| 63 | /// std::string addonName = kodi::GetAddonInfo("name"); | ||
| 64 | /// ... | ||
| 65 | /// ~~~~~~~~~~~~~ | ||
| 66 | /// | ||
| 67 | inline std::string ATTRIBUTE_HIDDEN GetAddonInfo(const std::string& id) | ||
| 68 | { | ||
| 69 | using namespace kodi::addon; | ||
| 70 | |||
| 71 | AddonToKodiFuncTable_Addon* toKodi = CAddonBase::m_interface->toKodi; | ||
| 72 | |||
| 73 | std::string strReturn; | ||
| 74 | char* strMsg = toKodi->kodi->get_addon_info(toKodi->kodiBase, id.c_str()); | ||
| 75 | if (strMsg != nullptr) | ||
| 76 | { | ||
| 77 | if (std::strlen(strMsg)) | ||
| 78 | strReturn = strMsg; | ||
| 79 | toKodi->free_string(toKodi->kodiBase, strMsg); | ||
| 80 | } | ||
| 81 | return strReturn; | ||
| 82 | } | ||
| 83 | //------------------------------------------------------------------------------ | ||
| 84 | |||
| 85 | //============================================================================== | ||
| 86 | /// \ingroup cpp_kodi | ||
| 87 | /// @brief Opens this Add-Ons settings dialog. | ||
| 88 | /// | ||
| 89 | /// @return true if settings were changed and the dialog confirmed, false otherwise. | ||
| 90 | /// | ||
| 91 | /// | ||
| 92 | /// -------------------------------------------------------------------------- | ||
| 93 | /// | ||
| 94 | /// **Example:** | ||
| 95 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 96 | /// #include <kodi/General.h> | ||
| 97 | /// .. | ||
| 98 | /// kodi::OpenSettings(); | ||
| 99 | /// .. | ||
| 100 | /// ~~~~~~~~~~~~~ | ||
| 101 | /// | ||
| 102 | inline bool ATTRIBUTE_HIDDEN OpenSettings() | ||
| 103 | { | ||
| 104 | using namespace kodi::addon; | ||
| 105 | return CAddonBase::m_interface->toKodi->kodi->open_settings_dialog( | ||
| 106 | CAddonBase::m_interface->toKodi->kodiBase); | ||
| 107 | } | ||
| 108 | //------------------------------------------------------------------------------ | ||
| 109 | |||
| 110 | //============================================================================== | ||
| 111 | /// \ingroup cpp_kodi | ||
| 112 | /// @brief Returns an addon's localized 'unicode string'. | ||
| 113 | /// | ||
| 114 | /// @param[in] labelId string you want to localize | ||
| 115 | /// @param[in] defaultStr [opt] The default message, also helps to identify | ||
| 116 | /// the code that is used <em>(default is | ||
| 117 | /// <b><c>empty</c></b>)</em> | ||
| 118 | /// @return The localized message, or default if the add-on | ||
| 119 | /// helper fails to return a message | ||
| 120 | /// | ||
| 121 | /// @note Label id's \b 30000 to \b 30999 and \b 32000 to \b 32999 are related | ||
| 122 | /// to the add-on's own included strings from | ||
| 123 | /// <b>./resources/language/resource.language.??_??/strings.po</b> | ||
| 124 | /// All other strings are from Kodi core language files. | ||
| 125 | /// | ||
| 126 | /// | ||
| 127 | /// ------------------------------------------------------------------------ | ||
| 128 | /// | ||
| 129 | /// **Example:** | ||
| 130 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 131 | /// #include <kodi/General.h> | ||
| 132 | /// ... | ||
| 133 | /// std::string str = kodi::GetLocalizedString(30005, "Use me as default"); | ||
| 134 | /// ... | ||
| 135 | /// ~~~~~~~~~~~~~ | ||
| 136 | /// | ||
| 137 | inline std::string ATTRIBUTE_HIDDEN GetLocalizedString(uint32_t labelId, | ||
| 138 | const std::string& defaultStr = "") | ||
| 139 | { | ||
| 140 | using namespace kodi::addon; | ||
| 141 | |||
| 142 | std::string retString = defaultStr; | ||
| 143 | char* strMsg = CAddonBase::m_interface->toKodi->kodi->get_localized_string( | ||
| 144 | CAddonBase::m_interface->toKodi->kodiBase, labelId); | ||
| 145 | if (strMsg != nullptr) | ||
| 146 | { | ||
| 147 | if (std::strlen(strMsg)) | ||
| 148 | retString = strMsg; | ||
| 149 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, strMsg); | ||
| 150 | } | ||
| 151 | return retString; | ||
| 152 | } | ||
| 153 | //------------------------------------------------------------------------------ | ||
| 154 | |||
| 155 | //============================================================================== | ||
| 156 | /// \ingroup cpp_kodi | ||
| 157 | /// @brief Translate a string with an unknown encoding to UTF8. | ||
| 158 | /// | ||
| 159 | /// @param[in] stringSrc The string to translate. | ||
| 160 | /// @param[out] utf8StringDst The translated string. | ||
| 161 | /// @param[in] failOnBadChar [opt] returns failed if bad character is inside <em>(default is <b><c>false</c></b>)</em> | ||
| 162 | /// @return true if OK | ||
| 163 | /// | ||
| 164 | /// | ||
| 165 | /// ------------------------------------------------------------------------ | ||
| 166 | /// | ||
| 167 | /// **Example:** | ||
| 168 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 169 | /// #include <kodi/General.h> | ||
| 170 | /// ... | ||
| 171 | /// std::string ret; | ||
| 172 | /// if (!kodi::UnknownToUTF8("test string", ret, true)) | ||
| 173 | /// fprintf(stderr, "Translation to UTF8 failed!\n"); | ||
| 174 | /// ... | ||
| 175 | /// ~~~~~~~~~~~~~ | ||
| 176 | /// | ||
| 177 | inline bool ATTRIBUTE_HIDDEN UnknownToUTF8(const std::string& stringSrc, | ||
| 178 | std::string& utf8StringDst, | ||
| 179 | bool failOnBadChar = false) | ||
| 180 | { | ||
| 181 | using namespace kodi::addon; | ||
| 182 | |||
| 183 | bool ret = false; | ||
| 184 | char* retString = CAddonBase::m_interface->toKodi->kodi->unknown_to_utf8( | ||
| 185 | CAddonBase::m_interface->toKodi->kodiBase, stringSrc.c_str(), &ret, failOnBadChar); | ||
| 186 | if (retString != nullptr) | ||
| 187 | { | ||
| 188 | if (ret) | ||
| 189 | utf8StringDst = retString; | ||
| 190 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 191 | retString); | ||
| 192 | } | ||
| 193 | return ret; | ||
| 194 | } | ||
| 195 | //------------------------------------------------------------------------------ | ||
| 196 | |||
| 197 | //============================================================================== | ||
| 198 | /// \ingroup cpp_kodi | ||
| 199 | /// @brief Returns the active language as a string. | ||
| 200 | /// | ||
| 201 | /// @param[in] format Used format of the returned language string | ||
| 202 | /// | enum code: | Description: | | ||
| 203 | /// |----------------------:|------------------------------------------------------------| | ||
| 204 | /// | LANG_FMT_ENGLISH_NAME | full language name in English (Default) | | ||
| 205 | /// | LANG_FMT_ISO_639_1 | two letter code as defined in ISO 639-1 | | ||
| 206 | /// | LANG_FMT_ISO_639_2 | three letter code as defined in ISO 639-2/T or ISO 639-2/B | | ||
| 207 | /// @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> | ||
| 208 | /// @return active language | ||
| 209 | /// | ||
| 210 | /// | ||
| 211 | /// ------------------------------------------------------------------------ | ||
| 212 | /// | ||
| 213 | /// **Example:** | ||
| 214 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 215 | /// #include <kodi/General.h> | ||
| 216 | /// ... | ||
| 217 | /// std::string language = kodi::GetLanguage(LANG_FMT_ISO_639_1, false); | ||
| 218 | /// ... | ||
| 219 | /// ~~~~~~~~~~~~~ | ||
| 220 | /// | ||
| 221 | inline std::string ATTRIBUTE_HIDDEN GetLanguage(LangFormats format = LANG_FMT_ENGLISH_NAME, | ||
| 222 | bool region = false) | ||
| 223 | { | ||
| 224 | using namespace kodi::addon; | ||
| 225 | |||
| 226 | std::string language; | ||
| 227 | char* retString = CAddonBase::m_interface->toKodi->kodi->get_language( | ||
| 228 | CAddonBase::m_interface->toKodi->kodiBase, format, region); | ||
| 229 | if (retString != nullptr) | ||
| 230 | { | ||
| 231 | if (std::strlen(retString)) | ||
| 232 | language = retString; | ||
| 233 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 234 | retString); | ||
| 235 | } | ||
| 236 | return language; | ||
| 237 | } | ||
| 238 | //------------------------------------------------------------------------------ | ||
| 239 | |||
| 240 | //============================================================================== | ||
| 241 | /// \ingroup cpp_kodi | ||
| 242 | /// @brief Writes the C string pointed by format in the GUI. If format includes | ||
| 243 | /// format specifiers (subsequences beginning with %), the additional arguments | ||
| 244 | /// following format are formatted and inserted in the resulting string replacing | ||
| 245 | /// their respective specifiers. | ||
| 246 | /// | ||
| 247 | /// After the format parameter, the function expects at least as many additional | ||
| 248 | /// arguments as specified by format. | ||
| 249 | /// | ||
| 250 | /// @param[in] type The message type. | ||
| 251 | /// | enum code: | Description: | | ||
| 252 | /// |---------------:|-----------------------------------| | ||
| 253 | /// | QUEUE_INFO | Show info notification message | | ||
| 254 | /// | QUEUE_WARNING | Show warning notification message | | ||
| 255 | /// | QUEUE_ERROR | Show error notification message | | ||
| 256 | /// @param[in] format The format of the message to pass to display in Kodi. | ||
| 257 | /// C string that contains the text to be written to the stream. | ||
| 258 | /// It can optionally contain embedded format specifiers that are | ||
| 259 | /// replaced by the values specified in subsequent additional | ||
| 260 | /// arguments and formatted as requested. | ||
| 261 | /// | specifier | Output | Example | ||
| 262 | /// |------------|----------------------------------------------------|------------ | ||
| 263 | /// | d or i | Signed decimal integer | 392 | ||
| 264 | /// | u | Unsigned decimal integer | 7235 | ||
| 265 | /// | o | Unsigned octal | 610 | ||
| 266 | /// | x | Unsigned hexadecimal integer | 7fa | ||
| 267 | /// | X | Unsigned hexadecimal integer (uppercase) | 7FA | ||
| 268 | /// | f | Decimal floating point, lowercase | 392.65 | ||
| 269 | /// | F | Decimal floating point, uppercase | 392.65 | ||
| 270 | /// | e | Scientific notation (mantissa/exponent), lowercase | 3.9265e+2 | ||
| 271 | /// | E | Scientific notation (mantissa/exponent), uppercase | 3.9265E+2 | ||
| 272 | /// | g | Use the shortest representation: %e or %f | 392.65 | ||
| 273 | /// | G | Use the shortest representation: %E or %F | 392.65 | ||
| 274 | /// | a | Hexadecimal floating point, lowercase | -0xc.90fep-2 | ||
| 275 | /// | A | Hexadecimal floating point, uppercase | -0XC.90FEP-2 | ||
| 276 | /// | c | Character | a | ||
| 277 | /// | s | String of characters | sample | ||
| 278 | /// | p | Pointer address | b8000000 | ||
| 279 | /// | % | A % followed by another % character will write a single % to the stream. | % | ||
| 280 | /// | ||
| 281 | /// The length sub-specifier modifies the length of the data type. This is a chart | ||
| 282 | /// showing the types used to interpret the corresponding arguments with and without | ||
| 283 | /// length specifier (if a different type is used, the proper type promotion or | ||
| 284 | /// conversion is performed, if allowed): | ||
| 285 | /// | length| d i | u o x X | f F e E g G a A | c | s | p | n | | ||
| 286 | /// |-------|---------------|-----------------------|-----------------|-------|---------|---------|-----------------| | ||
| 287 | /// | (none)| int | unsigned int | double | int | char* | void* | int* | | ||
| 288 | /// | hh | signed char | unsigned char | | | | | signed char* | | ||
| 289 | /// | h | short int | unsigned short int | | | | | short int* | | ||
| 290 | /// | l | long int | unsigned long int | | wint_t| wchar_t*| | long int* | | ||
| 291 | /// | ll | long long int | unsigned long long int| | | | | long long int* | | ||
| 292 | /// | j | intmax_t | uintmax_t | | | | | intmax_t* | | ||
| 293 | /// | z | size_t | size_t | | | | | size_t* | | ||
| 294 | /// | t | ptrdiff_t | ptrdiff_t | | | | | ptrdiff_t* | | ||
| 295 | /// | L | | | long double | | | | | | ||
| 296 | /// <b>Note:</b> that the c specifier takes an int (or wint_t) as argument, but performs the proper conversion to a char value | ||
| 297 | /// (or a wchar_t) before formatting it for output. | ||
| 298 | /// @param[in] ... (additional arguments) Depending on the format string, the function | ||
| 299 | /// may expect a sequence of additional arguments, each containing a value | ||
| 300 | /// to be used to replace a format specifier in the format string (or a pointer | ||
| 301 | /// to a storage location, for n). | ||
| 302 | /// There should be at least as many of these arguments as the number of values specified | ||
| 303 | /// in the format specifiers. Additional arguments are ignored by the function. | ||
| 304 | /// | ||
| 305 | /// | ||
| 306 | /// ------------------------------------------------------------------------ | ||
| 307 | /// | ||
| 308 | /// **Example:** | ||
| 309 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 310 | /// #include <kodi/General.h> | ||
| 311 | /// ... | ||
| 312 | /// kodi::QueueFormattedNotification(QUEUE_WARNING, "I'm want to inform you, here with a test call to show '%s'", "this"); | ||
| 313 | /// ... | ||
| 314 | /// ~~~~~~~~~~~~~ | ||
| 315 | /// | ||
| 316 | inline void ATTRIBUTE_HIDDEN QueueFormattedNotification(QueueMsg type, const char* format, ...) | ||
| 317 | { | ||
| 318 | using namespace kodi::addon; | ||
| 319 | |||
| 320 | va_list args; | ||
| 321 | va_start(args, format); | ||
| 322 | const std::string str = kodi::tools::StringUtils::FormatV(format, args); | ||
| 323 | va_end(args); | ||
| 324 | CAddonBase::m_interface->toKodi->kodi->queue_notification( | ||
| 325 | CAddonBase::m_interface->toKodi->kodiBase, type, "", str.c_str(), "", 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 | /// | ||
| 374 | inline 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 | /// | ||
| 409 | inline 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 | /// | ||
| 433 | inline 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 | /// | ||
| 478 | inline 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 | /// | ||
| 519 | inline 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 | /// | ||
| 547 | inline 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 | /// | ||
| 577 | inline 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 | /// | ||
| 617 | inline 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 | /// | ||
| 675 | inline 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 | /// | ||
| 743 | inline 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 | /// | ||
| 815 | inline 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 */ | ||
