diff options
author | Alwin Esch <alwin.esch@web.de> | 2017-05-29 17:31:47 +0200 |
---|---|---|
committer | Alwin Esch <alwin.esch@web.de> | 2017-05-29 17:31:47 +0200 |
commit | 71d958d9d5316dffa70b5abb849c841c1fc52642 (patch) | |
tree | 237fd3986e0adab8f2a640dd5028f897d3932743 | |
parent | 40f9340f769dc93d790ff78693e8f95d73799443 (diff) |
[addons] add general addon callback functions to new style
This add the general function who used on several addons to the new addon
interface style.
In future all the basics like on Python addons can be added here.
-rw-r--r-- | addons/kodi.binary.global.general/addon.xml.in | 7 | ||||
-rw-r--r-- | system/addon-manifest.xml | 1 | ||||
-rw-r--r-- | xbmc/addons/AddonDll.cpp | 3 | ||||
-rw-r--r-- | xbmc/addons/interfaces/CMakeLists.txt | 6 | ||||
-rw-r--r-- | xbmc/addons/interfaces/General.cpp | 225 | ||||
-rw-r--r-- | xbmc/addons/interfaces/General.h | 63 | ||||
-rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/AddonBase.h | 2 | ||||
-rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h | 376 | ||||
-rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/versions.h | 18 |
9 files changed, 698 insertions, 3 deletions
diff --git a/addons/kodi.binary.global.general/addon.xml.in b/addons/kodi.binary.global.general/addon.xml.in new file mode 100644 index 0000000000..119c803363 --- /dev/null +++ b/addons/kodi.binary.global.general/addon.xml.in @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<addon id="kodi.binary.global.general" version="@ADDON_GLOBAL_VERSION_GENERAL@" provider-name="Team Kodi"> + <backwards-compatibility abi="@ADDON_GLOBAL_VERSION_GENERAL_MIN@"/> + <requires> + <import addon="xbmc.core" version="0.1.0"/> + </requires> +</addon> diff --git a/system/addon-manifest.xml b/system/addon-manifest.xml index 2ae2975eaf..0f034bd30d 100644 --- a/system/addon-manifest.xml +++ b/system/addon-manifest.xml @@ -4,6 +4,7 @@ <addon>game.controller.default</addon> <addon>kodi.binary.global.audioengine</addon> <addon>kodi.binary.global.main</addon> + <addon>kodi.binary.global.general</addon> <addon>kodi.binary.global.gui</addon> <addon>kodi.binary.instance.adsp</addon> <addon>kodi.binary.instance.audiodecoder</addon> diff --git a/xbmc/addons/AddonDll.cpp b/xbmc/addons/AddonDll.cpp index 00a147427c..1fd7f189fa 100644 --- a/xbmc/addons/AddonDll.cpp +++ b/xbmc/addons/AddonDll.cpp @@ -38,6 +38,7 @@ // Global addon callback handle classes #include "addons/interfaces/AudioEngine.h" +#include "addons/interfaces/General.h" namespace ADDON { @@ -563,6 +564,7 @@ bool CAddonDll::InitInterface(KODI_HANDLE firstKodiInstance) // Related parts becomes set from addon headers. m_interface.toAddon = (KodiToAddonFuncTable_Addon*) calloc(1, sizeof(KodiToAddonFuncTable_Addon)); + Interface_General::Init(&m_interface); Interface_AudioEngine::Init(&m_interface); return true; @@ -571,6 +573,7 @@ bool CAddonDll::InitInterface(KODI_HANDLE firstKodiInstance) void CAddonDll::DeInitInterface() { Interface_AudioEngine::DeInit(&m_interface); + Interface_General::DeInit(&m_interface); if (m_interface.libBasePath) free((char*)m_interface.libBasePath); diff --git a/xbmc/addons/interfaces/CMakeLists.txt b/xbmc/addons/interfaces/CMakeLists.txt index f662cf460b..53d149975e 100644 --- a/xbmc/addons/interfaces/CMakeLists.txt +++ b/xbmc/addons/interfaces/CMakeLists.txt @@ -1,7 +1,9 @@ set(SOURCES AddonInterfaces.cpp - AudioEngine.cpp) + AudioEngine.cpp + General.cpp) set(HEADERS AddonInterfaces.h - AudioEngine.h) + AudioEngine.h + General.h) core_add_library(addonsBinaryInterfaces) diff --git a/xbmc/addons/interfaces/General.cpp b/xbmc/addons/interfaces/General.cpp new file mode 100644 index 0000000000..0779732401 --- /dev/null +++ b/xbmc/addons/interfaces/General.cpp @@ -0,0 +1,225 @@ +/* + * Copyright (C) 2005-2017 Team Kodi + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KODI; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include "General.h" + +#include "addons/kodi-addon-dev-kit/include/kodi/General.h" + +#include "Application.h" +#include "addons/AddonDll.h" +#include "addons/GUIDialogAddonSettings.h" +#include "dialogs/GUIDialogKaiToast.h" +#include "utils/CharsetConverter.h" +#include "utils/log.h" +#include "utils/LangCodeExpander.h" +#include "utils/StringUtils.h" + +using namespace kodi; // addon-dev-kit namespace + +namespace ADDON +{ + +void Interface_General::Init(AddonGlobalInterface* addonInterface) +{ + addonInterface->toKodi->kodi = static_cast<AddonToKodiFuncTable_kodi*>(malloc(sizeof(AddonToKodiFuncTable_kodi))); + + addonInterface->toKodi->kodi->open_settings_dialog = open_settings_dialog; + addonInterface->toKodi->kodi->get_localized_string = get_localized_string; + addonInterface->toKodi->kodi->unknown_to_utf8 = unknown_to_utf8; + addonInterface->toKodi->kodi->get_language = get_language; + addonInterface->toKodi->kodi->queue_notification = queue_notification; +} + +void Interface_General::DeInit(AddonGlobalInterface* addonInterface) +{ + if (addonInterface->toKodi && /* <-- needed as long as the old addon way is used */ + addonInterface->toKodi->kodi) + { + free(addonInterface->toKodi->kodi); + addonInterface->toKodi->kodi = nullptr; + } +} + +bool Interface_General::open_settings_dialog(void* kodiBase) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (addon == nullptr) + { + CLog::Log(LOGERROR, "Interface_General::%s - invalid data (addon='%p')", __FUNCTION__, addon); + return false; + } + + // show settings dialog + AddonPtr addonInfo; + if (CAddonMgr::GetInstance().GetAddon(addon->ID(), addonInfo)) + { + CLog::Log(LOGERROR, "Interface_General::%s - Could not get addon information for '%s'", __FUNCTION__, addon->ID().c_str()); + return false; + } + + return CGUIDialogAddonSettings::ShowAndGetInput(addonInfo); +} + +char* Interface_General::get_localized_string(void* kodiBase, long dwCode) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_General::%s - invalid data (addon='%p')", __FUNCTION__, addon); + return nullptr; + } + + if (g_application.m_bStop) + return nullptr; + + std::string string; + if ((dwCode >= 30000 && dwCode <= 30999) || (dwCode >= 32000 && dwCode <= 32999)) + string = g_localizeStrings.GetAddonString(addon->ID(), dwCode).c_str(); + else + string = g_localizeStrings.Get(dwCode).c_str(); + + char* buffer = strdup(string.c_str()); + return buffer; +} + +char* Interface_General::unknown_to_utf8(void* kodiBase, const char* source, bool* ret, bool failOnBadChar) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon || !source || !ret) + { + CLog::Log(LOGERROR, "Interface_General::%s - invalid data (addon='%p', source='%p', ret='%p')", __FUNCTION__, addon, source, ret); + return nullptr; + } + + std::string string; + *ret = g_charsetConverter.unknownToUTF8(source, string, failOnBadChar); + char* buffer = strdup(string.c_str()); + return buffer; +} + +char* Interface_General::get_language(void* kodiBase, int format, bool region) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_General::%s - invalid data (addon='%p')", __FUNCTION__, addon); + return nullptr; + } + + std::string string = g_langInfo.GetEnglishLanguageName(); + switch (format) + { + case LANG_FMT_ISO_639_1: + { + std::string langCode; + g_LangCodeExpander.ConvertToISO6391(string, langCode); + string = langCode; + if (region) + { + std::string region2Code; + g_LangCodeExpander.ConvertToISO6391(g_langInfo.GetRegionLocale(), region2Code); + if (!region2Code.empty()) + string += "-" + region2Code; + } + break; + } + case LANG_FMT_ISO_639_2: + { + std::string langCode; + g_LangCodeExpander.ConvertToISO6392T(string, langCode); + string = langCode; + if (region) + { + std::string region3Code; + g_LangCodeExpander.ConvertToISO6392T(g_langInfo.GetRegionLocale(), region3Code); + if (!region3Code.empty()) + string += "-" + region3Code; + } + break; + } + case LANG_FMT_ENGLISH_NAME: + default: + { + if (region) + string += "-" + g_langInfo.GetCurrentRegion(); + break; + } + } + + char* buffer = strdup(string.c_str()); + return buffer; +} + +bool Interface_General::queue_notification(void* kodiBase, int type, const char* header, + const char* message, const char* imageFile, + unsigned int displayTime, bool withSound, + unsigned int messageTime) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (addon == nullptr || message == nullptr) + { + CLog::Log(LOGERROR, "Interface_General::%s - invalid data (addon='%p', message='%p')", __FUNCTION__, addon, message); + return false; + } + + std::string usedHeader; + if (header && strlen(header) > 0) + usedHeader = header; + else + usedHeader = addon->Name(); + + if (type != QUEUE_OWN_STYLE) + { + CGUIDialogKaiToast::eMessageType usedType; + switch (type) + { + case QUEUE_WARNING: + usedType = CGUIDialogKaiToast::Warning; + withSound = true; + CLog::Log(LOGDEBUG, "Interface_General::%s - %s - Warning Message: '%s'", __FUNCTION__, addon->Name().c_str(), message); + break; + case QUEUE_ERROR: + usedType = CGUIDialogKaiToast::Error; + withSound = true; + CLog::Log(LOGDEBUG, "Interface_General::%s - %s - Error Message : '%s'", __FUNCTION__, addon->Name().c_str(), message); + break; + case QUEUE_INFO: + default: + usedType = CGUIDialogKaiToast::Info; + withSound = false; + CLog::Log(LOGDEBUG, "Interface_General::%s - %s - Info Message : '%s'", __FUNCTION__, addon->Name().c_str(), message); + break; + } + + if (imageFile && strlen(imageFile) > 0) + { + CLog::Log(LOGERROR, "Interface_General::%s - To use given image file '%s' must be type value set to 'QUEUE_OWN_STYLE'", __FUNCTION__, imageFile); + } + + CGUIDialogKaiToast::QueueNotification(usedType, usedHeader, message, 3000, withSound); + } + else + { + CGUIDialogKaiToast::QueueNotification(imageFile, usedHeader, message, displayTime, withSound, messageTime); + } + return true; +} + +} /* namespace ADDON */ diff --git a/xbmc/addons/interfaces/General.h b/xbmc/addons/interfaces/General.h new file mode 100644 index 0000000000..b5b8f624b5 --- /dev/null +++ b/xbmc/addons/interfaces/General.h @@ -0,0 +1,63 @@ +#pragma once +/* + * Copyright (C) 2005-2017 Team Kodi + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KODI; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +extern "C" +{ + +struct AddonGlobalInterface; + +namespace ADDON +{ + + /*! + * @brief Global general Add-on to Kodi callback functions + * + * To hold general functions not related to a instance type and usable for + * every add-on type. + * + * Related add-on header is "./xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h" + */ + struct Interface_General + { + static void Init(AddonGlobalInterface* addonInterface); + static void DeInit(AddonGlobalInterface* addonInterface); + + /*! + * @brief callback functions from add-on to kodi + * + * @note To add a new function use the "_" style to directly identify an + * add-on callback function. Everything with CamelCase is only to be used + * in Kodi. + * + * The parameter `kodiBase` is used to become the pointer for a `CAddonDll` + * class. + */ + //@{ + static bool open_settings_dialog(void* kodiBase); + static char* get_localized_string(void* kodiBase, long dwCode); + static char* unknown_to_utf8(void* kodiBase, const char* source, bool* ret, bool failOnBadChar); + static char* get_language(void* kodiBase, int format, bool region); + static bool queue_notification(void* kodiBase, int type, const char* header, const char* message, const char* imageFile, unsigned int displayTime, bool withSound, unsigned int messageTime); + //@} + }; + +} /* namespace ADDON */ +} /* extern "C" */ diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/AddonBase.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/AddonBase.h index 6603b5635e..b8544cda6b 100644 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/AddonBase.h +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/AddonBase.h @@ -156,6 +156,7 @@ typedef ADDON_HANDLE_STRUCT *ADDON_HANDLE; * Callback function tables from addon to Kodi * Set complete from Kodi! */ +struct AddonToKodiFuncTable_kodi; struct AddonToKodiFuncTable_kodi_audioengine; typedef struct AddonToKodiFuncTable_Addon { @@ -171,6 +172,7 @@ typedef struct AddonToKodiFuncTable_Addon bool (*get_setting)(void* kodiBase, const char* settingName, void *settingValue); bool (*set_setting)(void* kodiBase, const char* settingName, const char* settingValue); + AddonToKodiFuncTable_kodi* kodi; AddonToKodiFuncTable_kodi_audioengine* kodi_audioengine; } AddonToKodiFuncTable_Addon; diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h new file mode 100644 index 0000000000..50718af8ab --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h @@ -0,0 +1,376 @@ +#pragma once +/* + * Copyright (C) 2005-2017 Team Kodi + * http://kodi.tv + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Kodi; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include "AddonBase.h" + +/* + * For interface between add-on and kodi. + * + * This structure defines the addresses of functions stored inside Kodi which + * are then available for the add-on to call + * + * All function pointers there are used by the C++ interface functions below. + * You find the set of them on xbmc/addons/interfaces/General.cpp + * + * Note: For add-on development itself this is not needed + */ +typedef struct AddonToKodiFuncTable_kodi +{ + bool (*open_settings_dialog)(void* kodiBase); + char* (*unknown_to_utf8)(void* kodiBase, const char* source, bool* ret, bool failOnBadChar); + char* (*get_localized_string)(void* kodiBase, long dwCode); + char* (*get_language)(void* kodiBase, int format, bool region); + bool (*queue_notification)(void* kodiBase, int type, const char* header, const char* message, const char* imageFile, unsigned int displayTime, bool withSound, unsigned int messageTime); +} AddonToKodiFuncTable_kodi; + +//============================================================================== +/// \ingroup cpp_kodi_Defs +/// @brief For kodi::QueueNotification() used message types +/// +typedef enum QueueMsg +{ + /// Show info notification message + QUEUE_INFO, + /// Show warning notification message + QUEUE_WARNING, + /// Show error notification message + QUEUE_ERROR, + /// Show with own given image and parts if set on values + QUEUE_OWN_STYLE +} QueueMsg; +//------------------------------------------------------------------------------ + +//============================================================================== +/// \ingroup cpp_kodi_Defs +/// @brief Format codes to get string from them. +/// +typedef enum LangFormats +{ + /// two letter code as defined in ISO 639-1 + LANG_FMT_ISO_639_1, + /// three letter code as defined in ISO 639-2/T or ISO 639-2/B + LANG_FMT_ISO_639_2, + /// full language name in English + LANG_FMT_ENGLISH_NAME +} LangFormats; +//------------------------------------------------------------------------------ + + +//============================================================================== +namespace kodi { +/// +/// \ingroup cpp_kodi +/// @brief Opens this Add-Ons settings dialog. +/// +/// @return true if settings were changed and the dialog confirmed, false otherwise. +/// +/// +/// -------------------------------------------------------------------------- +/// +/// **Example:** +/// ~~~~~~~~~~~~~{.cpp} +/// #include <kodi/General.h> +/// .. +/// kodi::OpenSettings(); +/// .. +/// ~~~~~~~~~~~~~ +/// +inline bool OpenSettings() +{ + return ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->open_settings_dialog(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase); +} +} /* namespace kodi */ +//------------------------------------------------------------------------------ + +//============================================================================== +namespace kodi { +/// +/// \ingroup cpp_kodi +/// @brief Returns an addon's localized 'unicode string'. +/// +/// @param[in] labelId string you want to localize +/// @param[in] defaultStr [opt] The default message, also helps to identify +/// the code that is used <em>(default is +/// <b><c>empty</c></b>)</em> +/// @return The localized message, or default if the add-on +/// helper fails to return a message +/// +/// @note Label id's \b 30000 to \b 30999 and \b 32000 to \b 32999 are related +/// to the add-on's own included strings from +/// <b>./resources/language/resource.language.??_??/strings.po</b> +/// All other strings are from Kodi core language files. +/// +/// +/// ------------------------------------------------------------------------ +/// +/// **Example:** +/// ~~~~~~~~~~~~~{.cpp} +/// #include <kodi/General.h> +/// ... +/// std::string str = kodi::GetLocalizedString(30005, "Use me as default"); +/// ... +/// ~~~~~~~~~~~~~ +/// +inline std::string GetLocalizedString(uint32_t labelId, const std::string& defaultStr = "") +{ + std::string retString = defaultStr; + char* strMsg = ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->get_localized_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, labelId); + if (strMsg != nullptr) + { + if (std::strlen(strMsg)) + retString = strMsg; + ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, strMsg); + } + return retString; +} +} /* namespace kodi */ +//------------------------------------------------------------------------------ + +//============================================================================== +namespace kodi { +/// +/// \ingroup cpp_kodi +/// @brief Translate a string with an unknown encoding to UTF8. +/// +/// @param[in] stringSrc The string to translate. +/// @param[out] utf8StringDst The translated string. +/// @param[in] failOnBadChar [opt] returns failed if bad character is inside <em>(default is <b><c>false</c></b>)</em> +/// @return true if OK +/// +/// +/// ------------------------------------------------------------------------ +/// +/// **Example:** +/// ~~~~~~~~~~~~~{.cpp} +/// #include <kodi/General.h> +/// ... +/// std::string ret; +/// if (!kodi::UnknownToUTF8("test string", ret, true)) +/// fprintf(stderr, "Translation to UTF8 failed!\n"); +/// ... +/// ~~~~~~~~~~~~~ +/// +inline bool UnknownToUTF8(const std::string& stringSrc, std::string& utf8StringDst, bool failOnBadChar = false) +{ + bool ret = false; + char* retString = ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->unknown_to_utf8(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, + stringSrc.c_str(), &ret, failOnBadChar); + if (retString != nullptr) + { + if (ret) + utf8StringDst = retString; + ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, retString); + } + return ret; +} +} /* namespace kodi */ +//------------------------------------------------------------------------------ + +//============================================================================== +namespace kodi { +/// +/// \ingroup cpp_kodi +/// @brief Returns the active language as a string. +/// +/// @param[in] format Used format of the returned language string +/// | enum code: | Description: | +/// |----------------------:|------------------------------------------------------------| +/// | LANG_FMT_ENGLISH_NAME | full language name in English (Default) | +/// | LANG_FMT_ISO_639_1 | two letter code as defined in ISO 639-1 | +/// | LANG_FMT_ISO_639_2 | three letter code as defined in ISO 639-2/T or ISO 639-2/B | +/// @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> +/// @return active language +/// +/// +/// ------------------------------------------------------------------------ +/// +/// **Example:** +/// ~~~~~~~~~~~~~{.cpp} +/// #include <kodi/General.h> +/// ... +/// std::string language = kodi::GetLanguage(LANG_FMT_ISO_639_1, false); +/// ... +/// ~~~~~~~~~~~~~ +/// +inline std::string GetLanguage(LangFormats format = LANG_FMT_ENGLISH_NAME, bool region = false) +{ + std::string language; + char* retString = ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->get_language(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, format, region); + if (retString != nullptr) + { + if (std::strlen(retString)) + language = retString; + ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, retString); + } + return language; +} +} /* namespace kodi */ +//------------------------------------------------------------------------------ + +//============================================================================== +namespace kodi { +/// +/// \ingroup cpp_kodi +/// @brief Writes the C string pointed by format in the GUI. If format includes +/// format specifiers (subsequences beginning with %), the additional arguments +/// following format are formatted and inserted in the resulting string replacing +/// their respective specifiers. +/// +/// After the format parameter, the function expects at least as many additional +/// arguments as specified by format. +/// +/// @param[in] type The message type. +/// | enum code: | Description: | +/// |---------------:|-----------------------------------| +/// | QUEUE_INFO | Show info notification message | +/// | QUEUE_WARNING | Show warning notification message | +/// | QUEUE_ERROR | Show error notification message | +/// @param[in] format The format of the message to pass to display in Kodi. +/// C string that contains the text to be written to the stream. +/// It can optionally contain embedded format specifiers that are +/// replaced by the values specified in subsequent additional +/// arguments and formatted as requested. +/// | specifier | Output | Example +/// |------------|----------------------------------------------------|------------ +/// | d or i | Signed decimal integer | 392 +/// | u | Unsigned decimal integer | 7235 +/// | o | Unsigned octal | 610 +/// | x | Unsigned hexadecimal integer | 7fa +/// | X | Unsigned hexadecimal integer (uppercase) | 7FA +/// | f | Decimal floating point, lowercase | 392.65 +/// | F | Decimal floating point, uppercase | 392.65 +/// | e | Scientific notation (mantissa/exponent), lowercase | 3.9265e+2 +/// | E | Scientific notation (mantissa/exponent), uppercase | 3.9265E+2 +/// | g | Use the shortest representation: %e or %f | 392.65 +/// | G | Use the shortest representation: %E or %F | 392.65 +/// | a | Hexadecimal floating point, lowercase | -0xc.90fep-2 +/// | A | Hexadecimal floating point, uppercase | -0XC.90FEP-2 +/// | c | Character | a +/// | s | String of characters | sample +/// | p | Pointer address | b8000000 +/// | % | A % followed by another % character will write a single % to the stream. | % +/// +/// The length sub-specifier modifies the length of the data type. This is a chart +/// showing the types used to interpret the corresponding arguments with and without +/// length specifier (if a different type is used, the proper type promotion or +/// conversion is performed, if allowed): +/// | length| d i | u o x X | f F e E g G a A | c | s | p | n | +/// |-------|---------------|-----------------------|-----------------|-------|---------|---------|-----------------| +/// | (none)| int | unsigned int | double | int | char* | void* | int* | +/// | hh | signed char | unsigned char | | | | | signed char* | +/// | h | short int | unsigned short int | | | | | short int* | +/// | l | long int | unsigned long int | | wint_t| wchar_t*| | long int* | +/// | ll | long long int | unsigned long long int| | | | | long long int* | +/// | j | intmax_t | uintmax_t | | | | | intmax_t* | +/// | z | size_t | size_t | | | | | size_t* | +/// | t | ptrdiff_t | ptrdiff_t | | | | | ptrdiff_t* | +/// | L | | | long double | | | | | +/// <b>Note:</b> that the c specifier takes an int (or wint_t) as argument, but performs the proper conversion to a char value +/// (or a wchar_t) before formatting it for output. +/// @param[in] ... (additional arguments) Depending on the format string, the function +/// may expect a sequence of additional arguments, each containing a value +/// to be used to replace a format specifier in the format string (or a pointer +/// to a storage location, for n). +/// There should be at least as many of these arguments as the number of values specified +/// in the format specifiers. Additional arguments are ignored by the function. +/// +/// +/// ------------------------------------------------------------------------ +/// +/// **Example:** +/// ~~~~~~~~~~~~~{.cpp} +/// #include <kodi/General.h> +/// ... +/// kodi::QueueFormattedNotification(QUEUE_WARNING, "I'm want to inform you, here with a test call to show '%s'", "this"); +/// ... +/// ~~~~~~~~~~~~~ +/// +inline void QueueFormattedNotification(QueueMsg type, const char* format, ... ) +{ + va_list args; + char buffer[16384]; + va_start(args, format); + vsprintf(buffer, format, args); + va_end(args); + ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->queue_notification(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, + type, "", buffer, "", 5000, false, 1000); +} +} /* namespace kodi */ +//------------------------------------------------------------------------------ + +//============================================================================== +namespace kodi { +/// +/// \ingroup cpp_kodi +/// @brief Queue a notification in the GUI. +/// +/// @param[in] type The message type. +/// | enum code: | Description: +/// |----------------------:|----------------------------------- +/// | QUEUE_INFO | Show info notification message +/// | QUEUE_WARNING | Show warning notification message +/// | QUEUE_ERROR | Show error notification message +/// | 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 +/// @param[in] header Header Name (if leaved empty becomes addon name used) +/// @param[in] message Message to display on Kodi +/// @param[in] imageFile [opt] The image file to show on message (to use must be type set to QUEUE_OWN_STYLE) +/// @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) +/// @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) +/// @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) +/// +/// +/// ------------------------------------------------------------------------ +/// +/// **Example:** +/// ~~~~~~~~~~~~~{.cpp} +/// #include <kodi/General.h> +/// ... +/// kodi::QueueNotification(QUEUE_OWN_STYLE, "I'm want to inform you", "Here with a test call", "", 3000, false, 1000); +/// ... +/// ~~~~~~~~~~~~~ +/// +/// **Example:** +/// ~~~~~~~~~~~~~{.cpp} +/// #include <kodi/General.h> +/// ... +/// kodi::QueueNotification(QUEUE_WARNING, "I'm want to inform you", "Here with a test call"); +/// ... +/// ~~~~~~~~~~~~~ +/// +/// **Example:** +/// ~~~~~~~~~~~~~{.cpp} +/// #include <kodi/General.h> +/// ... +/// kodi::QueueNotification(QUEUE_OWN_STYLE, "", "Here with a test call", "./myImage.png"); +/// ... +/// ~~~~~~~~~~~~~ +/// +inline void QueueNotification(QueueMsg type, const std::string& header, + const std::string& message, const std::string& imageFile = "", + unsigned int displayTime = 5000, bool withSound = true, + unsigned int messageTime = 1000) +{ + ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->queue_notification(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, + type, header.c_str(), message.c_str(), imageFile.c_str(), displayTime, + withSound, messageTime); +} +} /* namespace kodi */ +//------------------------------------------------------------------------------ diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/versions.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/versions.h index 3902a18dc3..80b673a576 100644 --- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/versions.h +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/versions.h @@ -41,7 +41,7 @@ * overview. */ -#define ADDON_GLOBAL_VERSION_MAIN "1.0.4" +#define ADDON_GLOBAL_VERSION_MAIN "1.0.5" #define ADDON_GLOBAL_VERSION_MAIN_MIN "1.0.2" #define ADDON_GLOBAL_VERSION_MAIN_XML_ID "kodi.binary.global.main" #define ADDON_GLOBAL_VERSION_MAIN_DEPENDS "AddonBase.h" \ @@ -50,6 +50,11 @@ "libXBMC_addon.h" \ "addon-instance/" +#define ADDON_GLOBAL_VERSION_GENERAL "1.0.0" +#define ADDON_GLOBAL_VERSION_GENERAL_MIN "1.0.0" +#define ADDON_GLOBAL_VERSION_GENERAL_XML_ID "kodi.binary.global.general" +#define ADDON_GLOBAL_VERSION_GENERAL_DEPENDS "General.h" + #define ADDON_GLOBAL_VERSION_GUI "5.11.0" #define ADDON_GLOBAL_VERSION_GUI_MIN "5.10.0" #define ADDON_GLOBAL_VERSION_GUI_XML_ID "kodi.binary.global.gui" @@ -147,6 +152,7 @@ typedef enum ADDON_TYPE ADDON_GLOBAL_MAIN = 0, ADDON_GLOBAL_GUI = 1, ADDON_GLOBAL_AUDIOENGINE = 2, + ADDON_GLOBAL_GENERAL = 3, ADDON_GLOBAL_MAX = 3, // Last used global id, used in loops to check versions. Need to change if new global type becomes added. /* addon type instances */ @@ -187,6 +193,10 @@ inline const char* GetTypeVersion(int type) /* addon global parts */ case ADDON_GLOBAL_MAIN: return ADDON_GLOBAL_VERSION_MAIN; +#if !defined(BUILD_KODI_ADDON) || defined(ADDON_GLOBAL_VERSION_GENERAL_USED) + case ADDON_GLOBAL_GENERAL: + return ADDON_GLOBAL_VERSION_GENERAL; +#endif #if !defined(BUILD_KODI_ADDON) || defined(ADDON_GLOBAL_VERSION_GUI_USED) case ADDON_GLOBAL_GUI: return ADDON_GLOBAL_VERSION_GUI; @@ -262,6 +272,8 @@ inline const char* GetTypeMinVersion(int type) return ADDON_GLOBAL_VERSION_MAIN_MIN; case ADDON_GLOBAL_GUI: return ADDON_GLOBAL_VERSION_GUI_MIN; + case ADDON_GLOBAL_GENERAL: + return ADDON_GLOBAL_VERSION_GENERAL_MIN; case ADDON_GLOBAL_AUDIOENGINE: return ADDON_GLOBAL_VERSION_AUDIOENGINE_MIN; @@ -308,6 +320,8 @@ inline const char* GetTypeName(int type) return "Addon"; case ADDON_GLOBAL_GUI: return "GUI"; + case ADDON_GLOBAL_GENERAL: + return "General"; case ADDON_GLOBAL_AUDIOENGINE: return "AudioEngine"; @@ -351,6 +365,8 @@ inline int GetTypeId(const char* name) { if (strcmp(name, "addon") == 0) return ADDON_GLOBAL_MAIN; + else if (strcmp(name, "general") == 0) + return ADDON_GLOBAL_GENERAL; else if (strcmp(name, "gui") == 0) return ADDON_GLOBAL_GUI; else if (strcmp(name, "audioengine") == 0) |