diff options
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.h | 322 |
1 files changed, 322 insertions, 0 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 50718af..f4295ea 100644 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h | |||
| @@ -34,11 +34,18 @@ | |||
| 34 | */ | 34 | */ |
| 35 | typedef struct AddonToKodiFuncTable_kodi | 35 | typedef struct AddonToKodiFuncTable_kodi |
| 36 | { | 36 | { |
| 37 | char* (*get_addon_info)(void* kodiBase, const char* id); | ||
| 37 | bool (*open_settings_dialog)(void* kodiBase); | 38 | bool (*open_settings_dialog)(void* kodiBase); |
| 38 | char* (*unknown_to_utf8)(void* kodiBase, const char* source, bool* ret, bool failOnBadChar); | 39 | char* (*unknown_to_utf8)(void* kodiBase, const char* source, bool* ret, bool failOnBadChar); |
| 39 | char* (*get_localized_string)(void* kodiBase, long dwCode); | 40 | char* (*get_localized_string)(void* kodiBase, long dwCode); |
| 40 | char* (*get_language)(void* kodiBase, int format, bool region); | 41 | char* (*get_language)(void* kodiBase, int format, bool region); |
| 41 | bool (*queue_notification)(void* kodiBase, int type, const char* header, const char* message, const char* imageFile, unsigned int displayTime, bool withSound, unsigned int messageTime); | 42 | bool (*queue_notification)(void* kodiBase, int type, const char* header, const char* message, const char* imageFile, unsigned int displayTime, bool withSound, unsigned int messageTime); |
| 43 | void (*get_md5)(void* kodiBase, const char* text, char* md5); | ||
| 44 | char* (*get_temp_path)(void* kodiBase); | ||
| 45 | char* (*get_region)(void* kodiBase, const char* id); | ||
| 46 | void (*get_free_mem)(void* kodiBase, long* free, long* total, bool as_bytes); | ||
| 47 | int (*get_global_idle_time)(void* kodiBase); | ||
| 48 | void (*kodi_version)(void* kodiBase, char** compile_name, int* major, int* minor, char** revision, char** tag, char** tagversion); | ||
| 42 | } AddonToKodiFuncTable_kodi; | 49 | } AddonToKodiFuncTable_kodi; |
| 43 | 50 | ||
| 44 | //============================================================================== | 51 | //============================================================================== |
| @@ -62,6 +69,8 @@ typedef enum QueueMsg | |||
| 62 | /// \ingroup cpp_kodi_Defs | 69 | /// \ingroup cpp_kodi_Defs |
| 63 | /// @brief Format codes to get string from them. | 70 | /// @brief Format codes to get string from them. |
| 64 | /// | 71 | /// |
| 72 | /// Used on kodi::GetLanguage(). | ||
| 73 | /// | ||
| 65 | typedef enum LangFormats | 74 | typedef enum LangFormats |
| 66 | { | 75 | { |
| 67 | /// two letter code as defined in ISO 639-1 | 76 | /// two letter code as defined in ISO 639-1 |
| @@ -73,6 +82,71 @@ typedef enum LangFormats | |||
| 73 | } LangFormats; | 82 | } LangFormats; |
| 74 | //------------------------------------------------------------------------------ | 83 | //------------------------------------------------------------------------------ |
| 75 | 84 | ||
| 85 | //============================================================================== | ||
| 86 | /// \ingroup cpp_kodi_Defs | ||
| 87 | /// @brief For kodi::Version used structure | ||
| 88 | /// | ||
| 89 | typedef struct kodi_version_t | ||
| 90 | { | ||
| 91 | /// Application name, normally 'Kodi' | ||
| 92 | std::string compile_name; | ||
| 93 | /// Major code version of Kodi | ||
| 94 | int major; | ||
| 95 | /// Minor code version of Kodi | ||
| 96 | int minor; | ||
| 97 | /// The Revision contains a id and the build date, e.g. 20170706-c6b22fe217-dirty | ||
| 98 | std::string revision; | ||
| 99 | /// The version canditate e.g. alpha, beta or release | ||
| 100 | std::string tag; | ||
| 101 | /// The revision of tag before | ||
| 102 | std::string tag_revision; | ||
| 103 | } kodi_version_t; | ||
| 104 | //------------------------------------------------------------------------------ | ||
| 105 | |||
| 106 | //============================================================================== | ||
| 107 | namespace kodi { | ||
| 108 | /// | ||
| 109 | /// \ingroup cpp_kodi | ||
| 110 | /// @brief Returns the value of an addon property as a string | ||
| 111 | /// | ||
| 112 | /// @param[in] id id of the property that the module needs to access | ||
| 113 | /// | | Choices are | | | ||
| 114 | /// |:------------:|:------------:|:------------:| | ||
| 115 | /// | author | icon | stars | | ||
| 116 | /// | changelog | id | summary | | ||
| 117 | /// | description | name | type | | ||
| 118 | /// | disclaimer | path | version | | ||
| 119 | /// | fanart | profile | | | ||
| 120 | /// | ||
| 121 | /// @return AddOn property as a string | ||
| 122 | /// | ||
| 123 | /// | ||
| 124 | /// ------------------------------------------------------------------------ | ||
| 125 | /// | ||
| 126 | /// **Example:** | ||
| 127 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 128 | /// #include <kodi/General.h> | ||
| 129 | /// ... | ||
| 130 | /// std::string addonName = kodi::GetAddonInfo("name"); | ||
| 131 | /// ... | ||
| 132 | /// ~~~~~~~~~~~~~ | ||
| 133 | /// | ||
| 134 | inline std::string GetAddonInfo(const std::string& id) | ||
| 135 | { | ||
| 136 | AddonToKodiFuncTable_Addon* toKodi = ::kodi::addon::CAddonBase::m_interface->toKodi; | ||
| 137 | |||
| 138 | std::string strReturn; | ||
| 139 | char* strMsg = toKodi->kodi->get_addon_info(toKodi->kodiBase, id.c_str()); | ||
| 140 | if (strMsg != nullptr) | ||
| 141 | { | ||
| 142 | if (std::strlen(strMsg)) | ||
| 143 | strReturn = strMsg; | ||
| 144 | toKodi->free_string(toKodi->kodiBase, strMsg); | ||
| 145 | } | ||
| 146 | return strReturn; | ||
| 147 | } | ||
| 148 | } /* namespace kodi */ | ||
| 149 | //------------------------------------------------------------------------------ | ||
| 76 | 150 | ||
| 77 | //============================================================================== | 151 | //============================================================================== |
| 78 | namespace kodi { | 152 | namespace kodi { |
| @@ -374,3 +448,251 @@ inline void QueueNotification(QueueMsg type, const std::string& header, | |||
| 374 | } | 448 | } |
| 375 | } /* namespace kodi */ | 449 | } /* namespace kodi */ |
| 376 | //------------------------------------------------------------------------------ | 450 | //------------------------------------------------------------------------------ |
| 451 | |||
| 452 | //============================================================================ | ||
| 453 | namespace kodi { | ||
| 454 | /// | ||
| 455 | /// \ingroup cpp_kodi | ||
| 456 | /// @brief Get the MD5 digest of the given text | ||
| 457 | /// | ||
| 458 | /// @param[in] text text to compute the MD5 for | ||
| 459 | /// @return Returned MD5 digest | ||
| 460 | /// | ||
| 461 | /// | ||
| 462 | /// ------------------------------------------------------------------------ | ||
| 463 | /// | ||
| 464 | /// **Example:** | ||
| 465 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 466 | /// #include <kodi/General.h> | ||
| 467 | /// ... | ||
| 468 | /// std::string md5 = kodi::GetMD5("Make me as md5"); | ||
| 469 | /// fprintf(stderr, "My md5 digest is: '%s'\n", md5.c_str()); | ||
| 470 | /// ... | ||
| 471 | /// ~~~~~~~~~~~~~ | ||
| 472 | /// | ||
| 473 | inline std::string GetMD5(const std::string& text) | ||
| 474 | { | ||
| 475 | char* md5ret = static_cast<char*>(malloc(40*sizeof(char))); // md5 size normally 32 bytes | ||
| 476 | ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->get_md5(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, text.c_str(), md5ret); | ||
| 477 | std::string md5 = md5ret; | ||
| 478 | free(md5ret); | ||
| 479 | return md5; | ||
| 480 | } | ||
| 481 | } /* namespace kodi */ | ||
| 482 | //---------------------------------------------------------------------------- | ||
| 483 | |||
| 484 | //============================================================================== | ||
| 485 | namespace kodi { | ||
| 486 | /// | ||
| 487 | /// \ingroup cpp_kodi | ||
| 488 | /// @brief To get a temporary path for the addon | ||
| 489 | /// | ||
| 490 | /// This gives a temporary path which the addon can use individually for its things. | ||
| 491 | /// | ||
| 492 | /// The content of this folder will be deleted when Kodi is finished! | ||
| 493 | /// | ||
| 494 | /// @param[in] append A string to append to returned temporary path | ||
| 495 | /// @return Individual path for the addon | ||
| 496 | /// | ||
| 497 | inline std::string GetTempAddonPath(const std::string& append = "") | ||
| 498 | { | ||
| 499 | char* str = ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->get_temp_path(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase); | ||
| 500 | std::string ret = str; | ||
| 501 | ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, str); | ||
| 502 | if (!append.empty()) | ||
| 503 | { | ||
| 504 | if (append.at(0) != '\\' && | ||
| 505 | append.at(0) != '/') | ||
| 506 | #ifdef TARGET_WINDOWS | ||
| 507 | ret.append("\\"); | ||
| 508 | #else | ||
| 509 | ret.append("/"); | ||
| 510 | #endif | ||
| 511 | ret.append(append); | ||
| 512 | } | ||
| 513 | return ret; | ||
| 514 | } | ||
| 515 | } /* namespace kodi */ | ||
| 516 | //------------------------------------------------------------------------------ | ||
| 517 | |||
| 518 | //============================================================================== | ||
| 519 | namespace kodi { | ||
| 520 | /// | ||
| 521 | /// \ingroup cpp_kodi | ||
| 522 | /// @brief Returns your regions setting as a string for the specified id | ||
| 523 | /// | ||
| 524 | /// @param[in] id id of setting to return | ||
| 525 | /// | | Choices are | | | ||
| 526 | /// |:------------:|:------------:|:------------:| | ||
| 527 | /// | dateshort | time | tempunit | | ||
| 528 | /// | datelong | meridiem | speedunit | | ||
| 529 | /// | ||
| 530 | /// @return settings string | ||
| 531 | /// | ||
| 532 | /// | ||
| 533 | /// ------------------------------------------------------------------------ | ||
| 534 | /// | ||
| 535 | /// **Example:** | ||
| 536 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 537 | /// #include <kodi/General.h> | ||
| 538 | /// ... | ||
| 539 | /// std::string timeFormat = kodi::GetRegion("time"); | ||
| 540 | /// ... | ||
| 541 | /// ~~~~~~~~~~~~~ | ||
| 542 | /// | ||
| 543 | inline std::string GetRegion(const std::string& id) | ||
| 544 | { | ||
| 545 | AddonToKodiFuncTable_Addon* toKodi = ::kodi::addon::CAddonBase::m_interface->toKodi; | ||
| 546 | |||
| 547 | std::string strReturn; | ||
| 548 | char* strMsg = toKodi->kodi->get_region(toKodi->kodiBase, id.c_str()); | ||
| 549 | if (strMsg != nullptr) | ||
| 550 | { | ||
| 551 | if (std::strlen(strMsg)) | ||
| 552 | strReturn = strMsg; | ||
| 553 | toKodi->free_string(toKodi->kodiBase, strMsg); | ||
| 554 | } | ||
| 555 | return strReturn; | ||
| 556 | } | ||
| 557 | } /* namespace kodi */ | ||
| 558 | //------------------------------------------------------------------------------ | ||
| 559 | |||
| 560 | //============================================================================== | ||
| 561 | namespace kodi { | ||
| 562 | /// | ||
| 563 | /// \ingroup cpp_kodi | ||
| 564 | /// @brief Returns the amount of free memory in MByte (or as bytes) as an long | ||
| 565 | /// integer | ||
| 566 | /// | ||
| 567 | /// @param[out] free free memory | ||
| 568 | /// @param[out] total total memory | ||
| 569 | /// @param[in] asBytes [opt] if set to true becomes returned as bytes, otherwise | ||
| 570 | /// as mega bytes | ||
| 571 | /// | ||
| 572 | /// | ||
| 573 | /// ------------------------------------------------------------------------ | ||
| 574 | /// | ||
| 575 | /// **Example:** | ||
| 576 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 577 | /// #include <kodi/General.h> | ||
| 578 | /// ... | ||
| 579 | /// long freeMem; | ||
| 580 | /// long totalMem; | ||
| 581 | /// kodi::GetFreeMem(freeMem, totalMem); | ||
| 582 | /// ... | ||
| 583 | /// ~~~~~~~~~~~~~ | ||
| 584 | /// | ||
| 585 | inline void GetFreeMem(long& free, long& total, bool asBytes = false) | ||
| 586 | { | ||
| 587 | free = -1; | ||
| 588 | total = -1; | ||
| 589 | AddonToKodiFuncTable_Addon* toKodi = ::kodi::addon::CAddonBase::m_interface->toKodi; | ||
| 590 | toKodi->kodi->get_free_mem(toKodi->kodiBase, &free, &total, asBytes); | ||
| 591 | } | ||
| 592 | } /* namespace kodi */ | ||
| 593 | //------------------------------------------------------------------------------ | ||
| 594 | |||
| 595 | //============================================================================== | ||
| 596 | namespace kodi { | ||
| 597 | /// | ||
| 598 | /// \ingroup cpp_kodi | ||
| 599 | /// @brief Returns the elapsed idle time in seconds as an integer | ||
| 600 | /// | ||
| 601 | /// @return idle time | ||
| 602 | /// | ||
| 603 | /// | ||
| 604 | /// ------------------------------------------------------------------------ | ||
| 605 | /// | ||
| 606 | /// **Example:** | ||
| 607 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 608 | /// #include <kodi/General.h> | ||
| 609 | /// ... | ||
| 610 | /// int time = kodi::GetGlobalIdleTime(); | ||
| 611 | /// ... | ||
| 612 | /// ~~~~~~~~~~~~~ | ||
| 613 | /// | ||
| 614 | inline int GetGlobalIdleTime() | ||
| 615 | { | ||
| 616 | AddonToKodiFuncTable_Addon* toKodi = ::kodi::addon::CAddonBase::m_interface->toKodi; | ||
| 617 | return toKodi->kodi->get_global_idle_time(toKodi->kodiBase); | ||
| 618 | } | ||
| 619 | } /* namespace kodi */ | ||
| 620 | //------------------------------------------------------------------------------ | ||
| 621 | |||
| 622 | //============================================================================== | ||
| 623 | namespace kodi { | ||
| 624 | /// | ||
| 625 | /// \ingroup cpp_kodi | ||
| 626 | /// @brief Get current Kodi informations and versions, returned data from the following | ||
| 627 | /// <b><tt>kodi_version_t version; kodi::KodiVersion(version);</tt></b> | ||
| 628 | /// is e.g.: | ||
| 629 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 630 | /// version.compile_name = Kodi | ||
| 631 | /// version.major = 18 | ||
| 632 | /// version.minor = 0 | ||
| 633 | /// version.revision = 20170706-c6b22fe217-di | ||
| 634 | /// version.tag = alpha | ||
| 635 | /// version.tag_revision = 1 | ||
| 636 | /// ~~~~~~~~~~~~~ | ||
| 637 | /// | ||
| 638 | /// @param[out] version structure to store data from kodi | ||
| 639 | /// | ||
| 640 | /// | ||
| 641 | /// ------------------------------------------------------------------------ | ||
| 642 | /// | ||
| 643 | /// **Example:** | ||
| 644 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 645 | /// #include <kodi/General.h> | ||
| 646 | /// ... | ||
| 647 | /// kodi_version_t version; | ||
| 648 | /// kodi::KodiVersion(version); | ||
| 649 | /// fprintf(stderr, | ||
| 650 | /// "kodi_version_t version;\n" | ||
| 651 | /// "kodi::KodiVersion(version);\n" | ||
| 652 | /// " - version.compile_name = %s\n" | ||
| 653 | /// " - version.major = %i\n" | ||
| 654 | /// " - version.minor = %i\n" | ||
| 655 | /// " - version.revision = %s\n" | ||
| 656 | /// " - version.tag = %s\n" | ||
| 657 | /// " - version.tag_revision = %s\n", | ||
| 658 | /// version.compile_name.c_str(), version.major, version.minor, | ||
| 659 | /// version.revision.c_str(), version.tag.c_str(), version.tag_revision.c_str()); | ||
| 660 | /// ... | ||
| 661 | /// ~~~~~~~~~~~~~ | ||
| 662 | /// | ||
| 663 | inline void KodiVersion(kodi_version_t& version) | ||
| 664 | { | ||
| 665 | char* compile_name = nullptr; | ||
| 666 | char* revision = nullptr; | ||
| 667 | char* tag = nullptr; | ||
| 668 | char* tag_revision = nullptr; | ||
| 669 | |||
| 670 | AddonToKodiFuncTable_Addon* toKodi = ::kodi::addon::CAddonBase::m_interface->toKodi; | ||
| 671 | toKodi->kodi->kodi_version(toKodi->kodiBase, &compile_name, &version.major, &version.minor, &revision, &tag, &tag_revision); | ||
| 672 | if (compile_name != nullptr) | ||
| 673 | { | ||
| 674 | version.compile_name = compile_name; | ||
| 675 | toKodi->free_string | ||
| 676 | ( | ||
| 677 | toKodi->kodiBase, | ||
| 678 | compile_name | ||
| 679 | ); | ||
| 680 | } | ||
| 681 | if (revision != nullptr) | ||
| 682 | { | ||
| 683 | version.revision = revision; | ||
| 684 | toKodi->free_string(toKodi->kodiBase, revision); | ||
| 685 | } | ||
| 686 | if (tag != nullptr) | ||
| 687 | { | ||
| 688 | version.tag = tag; | ||
| 689 | toKodi->free_string(toKodi->kodiBase, tag); | ||
| 690 | } | ||
| 691 | if (tag_revision != nullptr) | ||
| 692 | { | ||
| 693 | version.tag_revision = tag_revision; | ||
| 694 | toKodi->free_string(toKodi->kodiBase, tag_revision); | ||
| 695 | } | ||
| 696 | } | ||
| 697 | } /* namespace kodi */ | ||
| 698 | //------------------------------------------------------------------------------ | ||
