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 | 376 |
1 files changed, 376 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 new file mode 100644 index 0000000..50718af --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/General.h | |||
| @@ -0,0 +1,376 @@ | |||
| 1 | #pragma once | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2005-2017 Team Kodi | ||
| 4 | * http://kodi.tv | ||
| 5 | * | ||
| 6 | * This Program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2, or (at your option) | ||
| 9 | * any later version. | ||
| 10 | * | ||
| 11 | * This Program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with Kodi; see the file COPYING. If not, see | ||
| 18 | * <http://www.gnu.org/licenses/>. | ||
| 19 | * | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "AddonBase.h" | ||
| 23 | |||
| 24 | /* | ||
| 25 | * For interface between add-on and kodi. | ||
| 26 | * | ||
| 27 | * This structure defines the addresses of functions stored inside Kodi which | ||
| 28 | * are then available for the add-on to call | ||
| 29 | * | ||
| 30 | * All function pointers there are used by the C++ interface functions below. | ||
| 31 | * You find the set of them on xbmc/addons/interfaces/General.cpp | ||
| 32 | * | ||
| 33 | * Note: For add-on development itself this is not needed | ||
| 34 | */ | ||
| 35 | typedef struct AddonToKodiFuncTable_kodi | ||
| 36 | { | ||
| 37 | bool (*open_settings_dialog)(void* kodiBase); | ||
| 38 | 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_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 | } AddonToKodiFuncTable_kodi; | ||
| 43 | |||
| 44 | //============================================================================== | ||
| 45 | /// \ingroup cpp_kodi_Defs | ||
| 46 | /// @brief For kodi::QueueNotification() used message types | ||
| 47 | /// | ||
| 48 | typedef enum QueueMsg | ||
| 49 | { | ||
| 50 | /// Show info notification message | ||
| 51 | QUEUE_INFO, | ||
| 52 | /// Show warning notification message | ||
| 53 | QUEUE_WARNING, | ||
| 54 | /// Show error notification message | ||
| 55 | QUEUE_ERROR, | ||
| 56 | /// Show with own given image and parts if set on values | ||
| 57 | QUEUE_OWN_STYLE | ||
| 58 | } QueueMsg; | ||
| 59 | //------------------------------------------------------------------------------ | ||
| 60 | |||
| 61 | //============================================================================== | ||
| 62 | /// \ingroup cpp_kodi_Defs | ||
| 63 | /// @brief Format codes to get string from them. | ||
| 64 | /// | ||
| 65 | typedef enum LangFormats | ||
| 66 | { | ||
| 67 | /// two letter code as defined in ISO 639-1 | ||
| 68 | LANG_FMT_ISO_639_1, | ||
| 69 | /// three letter code as defined in ISO 639-2/T or ISO 639-2/B | ||
| 70 | LANG_FMT_ISO_639_2, | ||
| 71 | /// full language name in English | ||
| 72 | LANG_FMT_ENGLISH_NAME | ||
| 73 | } LangFormats; | ||
| 74 | //------------------------------------------------------------------------------ | ||
| 75 | |||
| 76 | |||
| 77 | //============================================================================== | ||
| 78 | namespace kodi { | ||
| 79 | /// | ||
| 80 | /// \ingroup cpp_kodi | ||
| 81 | /// @brief Opens this Add-Ons settings dialog. | ||
| 82 | /// | ||
| 83 | /// @return true if settings were changed and the dialog confirmed, false otherwise. | ||
| 84 | /// | ||
| 85 | /// | ||
| 86 | /// -------------------------------------------------------------------------- | ||
| 87 | /// | ||
| 88 | /// **Example:** | ||
| 89 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 90 | /// #include <kodi/General.h> | ||
| 91 | /// .. | ||
| 92 | /// kodi::OpenSettings(); | ||
| 93 | /// .. | ||
| 94 | /// ~~~~~~~~~~~~~ | ||
| 95 | /// | ||
| 96 | inline bool OpenSettings() | ||
| 97 | { | ||
| 98 | return ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->open_settings_dialog(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase); | ||
| 99 | } | ||
| 100 | } /* namespace kodi */ | ||
| 101 | //------------------------------------------------------------------------------ | ||
| 102 | |||
| 103 | //============================================================================== | ||
| 104 | namespace kodi { | ||
| 105 | /// | ||
| 106 | /// \ingroup cpp_kodi | ||
| 107 | /// @brief Returns an addon's localized 'unicode string'. | ||
| 108 | /// | ||
| 109 | /// @param[in] labelId string you want to localize | ||
| 110 | /// @param[in] defaultStr [opt] The default message, also helps to identify | ||
| 111 | /// the code that is used <em>(default is | ||
| 112 | /// <b><c>empty</c></b>)</em> | ||
| 113 | /// @return The localized message, or default if the add-on | ||
| 114 | /// helper fails to return a message | ||
| 115 | /// | ||
| 116 | /// @note Label id's \b 30000 to \b 30999 and \b 32000 to \b 32999 are related | ||
| 117 | /// to the add-on's own included strings from | ||
| 118 | /// <b>./resources/language/resource.language.??_??/strings.po</b> | ||
| 119 | /// All other strings are from Kodi core language files. | ||
| 120 | /// | ||
| 121 | /// | ||
| 122 | /// ------------------------------------------------------------------------ | ||
| 123 | /// | ||
| 124 | /// **Example:** | ||
| 125 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 126 | /// #include <kodi/General.h> | ||
| 127 | /// ... | ||
| 128 | /// std::string str = kodi::GetLocalizedString(30005, "Use me as default"); | ||
| 129 | /// ... | ||
| 130 | /// ~~~~~~~~~~~~~ | ||
| 131 | /// | ||
| 132 | inline std::string GetLocalizedString(uint32_t labelId, const std::string& defaultStr = "") | ||
| 133 | { | ||
| 134 | std::string retString = defaultStr; | ||
| 135 | char* strMsg = ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->get_localized_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, labelId); | ||
| 136 | if (strMsg != nullptr) | ||
| 137 | { | ||
| 138 | if (std::strlen(strMsg)) | ||
| 139 | retString = strMsg; | ||
| 140 | ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, strMsg); | ||
| 141 | } | ||
| 142 | return retString; | ||
| 143 | } | ||
| 144 | } /* namespace kodi */ | ||
| 145 | //------------------------------------------------------------------------------ | ||
| 146 | |||
| 147 | //============================================================================== | ||
| 148 | namespace kodi { | ||
| 149 | /// | ||
| 150 | /// \ingroup cpp_kodi | ||
| 151 | /// @brief Translate a string with an unknown encoding to UTF8. | ||
| 152 | /// | ||
| 153 | /// @param[in] stringSrc The string to translate. | ||
| 154 | /// @param[out] utf8StringDst The translated string. | ||
| 155 | /// @param[in] failOnBadChar [opt] returns failed if bad character is inside <em>(default is <b><c>false</c></b>)</em> | ||
| 156 | /// @return true if OK | ||
| 157 | /// | ||
| 158 | /// | ||
| 159 | /// ------------------------------------------------------------------------ | ||
| 160 | /// | ||
| 161 | /// **Example:** | ||
| 162 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 163 | /// #include <kodi/General.h> | ||
| 164 | /// ... | ||
| 165 | /// std::string ret; | ||
| 166 | /// if (!kodi::UnknownToUTF8("test string", ret, true)) | ||
| 167 | /// fprintf(stderr, "Translation to UTF8 failed!\n"); | ||
| 168 | /// ... | ||
| 169 | /// ~~~~~~~~~~~~~ | ||
| 170 | /// | ||
| 171 | inline bool UnknownToUTF8(const std::string& stringSrc, std::string& utf8StringDst, bool failOnBadChar = false) | ||
| 172 | { | ||
| 173 | bool ret = false; | ||
| 174 | char* retString = ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->unknown_to_utf8(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, | ||
| 175 | stringSrc.c_str(), &ret, failOnBadChar); | ||
| 176 | if (retString != nullptr) | ||
| 177 | { | ||
| 178 | if (ret) | ||
| 179 | utf8StringDst = retString; | ||
| 180 | ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, retString); | ||
| 181 | } | ||
| 182 | return ret; | ||
| 183 | } | ||
| 184 | } /* namespace kodi */ | ||
| 185 | //------------------------------------------------------------------------------ | ||
| 186 | |||
| 187 | //============================================================================== | ||
| 188 | namespace kodi { | ||
| 189 | /// | ||
| 190 | /// \ingroup cpp_kodi | ||
| 191 | /// @brief Returns the active language as a string. | ||
| 192 | /// | ||
| 193 | /// @param[in] format Used format of the returned language string | ||
| 194 | /// | enum code: | Description: | | ||
| 195 | /// |----------------------:|------------------------------------------------------------| | ||
| 196 | /// | LANG_FMT_ENGLISH_NAME | full language name in English (Default) | | ||
| 197 | /// | LANG_FMT_ISO_639_1 | two letter code as defined in ISO 639-1 | | ||
| 198 | /// | LANG_FMT_ISO_639_2 | three letter code as defined in ISO 639-2/T or ISO 639-2/B | | ||
| 199 | /// @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> | ||
| 200 | /// @return active language | ||
| 201 | /// | ||
| 202 | /// | ||
| 203 | /// ------------------------------------------------------------------------ | ||
| 204 | /// | ||
| 205 | /// **Example:** | ||
| 206 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 207 | /// #include <kodi/General.h> | ||
| 208 | /// ... | ||
| 209 | /// std::string language = kodi::GetLanguage(LANG_FMT_ISO_639_1, false); | ||
| 210 | /// ... | ||
| 211 | /// ~~~~~~~~~~~~~ | ||
| 212 | /// | ||
| 213 | inline std::string GetLanguage(LangFormats format = LANG_FMT_ENGLISH_NAME, bool region = false) | ||
| 214 | { | ||
| 215 | std::string language; | ||
| 216 | char* retString = ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->get_language(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, format, region); | ||
| 217 | if (retString != nullptr) | ||
| 218 | { | ||
| 219 | if (std::strlen(retString)) | ||
| 220 | language = retString; | ||
| 221 | ::kodi::addon::CAddonBase::m_interface->toKodi->free_string(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, retString); | ||
| 222 | } | ||
| 223 | return language; | ||
| 224 | } | ||
| 225 | } /* namespace kodi */ | ||
| 226 | //------------------------------------------------------------------------------ | ||
| 227 | |||
| 228 | //============================================================================== | ||
| 229 | namespace kodi { | ||
| 230 | /// | ||
| 231 | /// \ingroup cpp_kodi | ||
| 232 | /// @brief Writes the C string pointed by format in the GUI. If format includes | ||
| 233 | /// format specifiers (subsequences beginning with %), the additional arguments | ||
| 234 | /// following format are formatted and inserted in the resulting string replacing | ||
| 235 | /// their respective specifiers. | ||
| 236 | /// | ||
| 237 | /// After the format parameter, the function expects at least as many additional | ||
| 238 | /// arguments as specified by format. | ||
| 239 | /// | ||
| 240 | /// @param[in] type The message type. | ||
| 241 | /// | enum code: | Description: | | ||
| 242 | /// |---------------:|-----------------------------------| | ||
| 243 | /// | QUEUE_INFO | Show info notification message | | ||
| 244 | /// | QUEUE_WARNING | Show warning notification message | | ||
| 245 | /// | QUEUE_ERROR | Show error notification message | | ||
| 246 | /// @param[in] format The format of the message to pass to display in Kodi. | ||
| 247 | /// C string that contains the text to be written to the stream. | ||
| 248 | /// It can optionally contain embedded format specifiers that are | ||
| 249 | /// replaced by the values specified in subsequent additional | ||
| 250 | /// arguments and formatted as requested. | ||
| 251 | /// | specifier | Output | Example | ||
| 252 | /// |------------|----------------------------------------------------|------------ | ||
| 253 | /// | d or i | Signed decimal integer | 392 | ||
| 254 | /// | u | Unsigned decimal integer | 7235 | ||
| 255 | /// | o | Unsigned octal | 610 | ||
| 256 | /// | x | Unsigned hexadecimal integer | 7fa | ||
| 257 | /// | X | Unsigned hexadecimal integer (uppercase) | 7FA | ||
| 258 | /// | f | Decimal floating point, lowercase | 392.65 | ||
| 259 | /// | F | Decimal floating point, uppercase | 392.65 | ||
| 260 | /// | e | Scientific notation (mantissa/exponent), lowercase | 3.9265e+2 | ||
| 261 | /// | E | Scientific notation (mantissa/exponent), uppercase | 3.9265E+2 | ||
| 262 | /// | g | Use the shortest representation: %e or %f | 392.65 | ||
| 263 | /// | G | Use the shortest representation: %E or %F | 392.65 | ||
| 264 | /// | a | Hexadecimal floating point, lowercase | -0xc.90fep-2 | ||
| 265 | /// | A | Hexadecimal floating point, uppercase | -0XC.90FEP-2 | ||
| 266 | /// | c | Character | a | ||
| 267 | /// | s | String of characters | sample | ||
| 268 | /// | p | Pointer address | b8000000 | ||
| 269 | /// | % | A % followed by another % character will write a single % to the stream. | % | ||
| 270 | /// | ||
| 271 | /// The length sub-specifier modifies the length of the data type. This is a chart | ||
| 272 | /// showing the types used to interpret the corresponding arguments with and without | ||
| 273 | /// length specifier (if a different type is used, the proper type promotion or | ||
| 274 | /// conversion is performed, if allowed): | ||
| 275 | /// | length| d i | u o x X | f F e E g G a A | c | s | p | n | | ||
| 276 | /// |-------|---------------|-----------------------|-----------------|-------|---------|---------|-----------------| | ||
| 277 | /// | (none)| int | unsigned int | double | int | char* | void* | int* | | ||
| 278 | /// | hh | signed char | unsigned char | | | | | signed char* | | ||
| 279 | /// | h | short int | unsigned short int | | | | | short int* | | ||
| 280 | /// | l | long int | unsigned long int | | wint_t| wchar_t*| | long int* | | ||
| 281 | /// | ll | long long int | unsigned long long int| | | | | long long int* | | ||
| 282 | /// | j | intmax_t | uintmax_t | | | | | intmax_t* | | ||
| 283 | /// | z | size_t | size_t | | | | | size_t* | | ||
| 284 | /// | t | ptrdiff_t | ptrdiff_t | | | | | ptrdiff_t* | | ||
| 285 | /// | L | | | long double | | | | | | ||
| 286 | /// <b>Note:</b> that the c specifier takes an int (or wint_t) as argument, but performs the proper conversion to a char value | ||
| 287 | /// (or a wchar_t) before formatting it for output. | ||
| 288 | /// @param[in] ... (additional arguments) Depending on the format string, the function | ||
| 289 | /// may expect a sequence of additional arguments, each containing a value | ||
| 290 | /// to be used to replace a format specifier in the format string (or a pointer | ||
| 291 | /// to a storage location, for n). | ||
| 292 | /// There should be at least as many of these arguments as the number of values specified | ||
| 293 | /// in the format specifiers. Additional arguments are ignored by the function. | ||
| 294 | /// | ||
| 295 | /// | ||
| 296 | /// ------------------------------------------------------------------------ | ||
| 297 | /// | ||
| 298 | /// **Example:** | ||
| 299 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 300 | /// #include <kodi/General.h> | ||
| 301 | /// ... | ||
| 302 | /// kodi::QueueFormattedNotification(QUEUE_WARNING, "I'm want to inform you, here with a test call to show '%s'", "this"); | ||
| 303 | /// ... | ||
| 304 | /// ~~~~~~~~~~~~~ | ||
| 305 | /// | ||
| 306 | inline void QueueFormattedNotification(QueueMsg type, const char* format, ... ) | ||
| 307 | { | ||
| 308 | va_list args; | ||
| 309 | char buffer[16384]; | ||
| 310 | va_start(args, format); | ||
| 311 | vsprintf(buffer, format, args); | ||
| 312 | va_end(args); | ||
| 313 | ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->queue_notification(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, | ||
| 314 | type, "", buffer, "", 5000, false, 1000); | ||
| 315 | } | ||
| 316 | } /* namespace kodi */ | ||
| 317 | //------------------------------------------------------------------------------ | ||
| 318 | |||
| 319 | //============================================================================== | ||
| 320 | namespace kodi { | ||
| 321 | /// | ||
| 322 | /// \ingroup cpp_kodi | ||
| 323 | /// @brief Queue a notification in the GUI. | ||
| 324 | /// | ||
| 325 | /// @param[in] type The message type. | ||
| 326 | /// | enum code: | Description: | ||
| 327 | /// |----------------------:|----------------------------------- | ||
| 328 | /// | QUEUE_INFO | Show info notification message | ||
| 329 | /// | QUEUE_WARNING | Show warning notification message | ||
| 330 | /// | QUEUE_ERROR | Show error notification message | ||
| 331 | /// | 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 | ||
| 332 | /// @param[in] header Header Name (if leaved empty becomes addon name used) | ||
| 333 | /// @param[in] message Message to display on Kodi | ||
| 334 | /// @param[in] imageFile [opt] The image file to show on message (to use must be type set to QUEUE_OWN_STYLE) | ||
| 335 | /// @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) | ||
| 336 | /// @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) | ||
| 337 | /// @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) | ||
| 338 | /// | ||
| 339 | /// | ||
| 340 | /// ------------------------------------------------------------------------ | ||
| 341 | /// | ||
| 342 | /// **Example:** | ||
| 343 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 344 | /// #include <kodi/General.h> | ||
| 345 | /// ... | ||
| 346 | /// kodi::QueueNotification(QUEUE_OWN_STYLE, "I'm want to inform you", "Here with a test call", "", 3000, false, 1000); | ||
| 347 | /// ... | ||
| 348 | /// ~~~~~~~~~~~~~ | ||
| 349 | /// | ||
| 350 | /// **Example:** | ||
| 351 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 352 | /// #include <kodi/General.h> | ||
| 353 | /// ... | ||
| 354 | /// kodi::QueueNotification(QUEUE_WARNING, "I'm want to inform you", "Here with a test call"); | ||
| 355 | /// ... | ||
| 356 | /// ~~~~~~~~~~~~~ | ||
| 357 | /// | ||
| 358 | /// **Example:** | ||
| 359 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 360 | /// #include <kodi/General.h> | ||
| 361 | /// ... | ||
| 362 | /// kodi::QueueNotification(QUEUE_OWN_STYLE, "", "Here with a test call", "./myImage.png"); | ||
| 363 | /// ... | ||
| 364 | /// ~~~~~~~~~~~~~ | ||
| 365 | /// | ||
| 366 | inline void QueueNotification(QueueMsg type, const std::string& header, | ||
| 367 | const std::string& message, const std::string& imageFile = "", | ||
| 368 | unsigned int displayTime = 5000, bool withSound = true, | ||
| 369 | unsigned int messageTime = 1000) | ||
| 370 | { | ||
| 371 | ::kodi::addon::CAddonBase::m_interface->toKodi->kodi->queue_notification(::kodi::addon::CAddonBase::m_interface->toKodi->kodiBase, | ||
| 372 | type, header.c_str(), message.c_str(), imageFile.c_str(), displayTime, | ||
| 373 | withSound, messageTime); | ||
| 374 | } | ||
| 375 | } /* namespace kodi */ | ||
| 376 | //------------------------------------------------------------------------------ | ||
