Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
General.h
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//==============================================================================
21typedef struct kodi_version_t
22{
24 std::string compile_name;
26 int major;
28 int minor;
30 std::string revision;
32 std::string tag;
34 std::string tag_revision;
36//------------------------------------------------------------------------------
37
38namespace kodi
39{
40
41//==============================================================================
63inline bool ATTR_DLL_LOCAL UnknownToUTF8(const std::string& stringSrc,
64 std::string& utf8StringDst,
65 bool failOnBadChar = false)
66{
67 using namespace kodi::addon;
68
69 bool ret = false;
70 char* retString = CPrivateBase::m_interface->toKodi->kodi->unknown_to_utf8(
71 CPrivateBase::m_interface->toKodi->kodiBase, stringSrc.c_str(), &ret, failOnBadChar);
72 if (retString != nullptr)
73 {
74 if (ret)
75 utf8StringDst = retString;
76 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
77 retString);
78 }
79 return ret;
80}
81//------------------------------------------------------------------------------
82
83//==============================================================================
107inline std::string ATTR_DLL_LOCAL GetLanguage(LangFormats format = LANG_FMT_ENGLISH_NAME,
108 bool region = false)
109{
110 using namespace kodi::addon;
111
112 std::string language;
113 char* retString = CPrivateBase::m_interface->toKodi->kodi->get_language(
114 CPrivateBase::m_interface->toKodi->kodiBase, format, region);
115 if (retString != nullptr)
116 {
117 if (std::strlen(retString))
118 language = retString;
119 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
120 retString);
121 }
122 return language;
123}
124//------------------------------------------------------------------------------
125
126//==============================================================================
202inline void ATTR_DLL_LOCAL QueueFormattedNotification(QueueMsg type, const char* format, ...)
203{
204 using namespace kodi::addon;
205
206 va_list args;
207 va_start(args, format);
208 const std::string str = kodi::tools::StringUtils::FormatV(format, args);
209 va_end(args);
210 CPrivateBase::m_interface->toKodi->kodi->queue_notification(
211 CPrivateBase::m_interface->toKodi->kodiBase, type, "", str.c_str(), "", 5000, false, 1000);
212}
213//------------------------------------------------------------------------------
214
215//==============================================================================
260inline void ATTR_DLL_LOCAL QueueNotification(QueueMsg type,
261 const std::string& header,
262 const std::string& message,
263 const std::string& imageFile = "",
264 unsigned int displayTime = 5000,
265 bool withSound = true,
266 unsigned int messageTime = 1000)
267{
268 using namespace kodi::addon;
269
270 CPrivateBase::m_interface->toKodi->kodi->queue_notification(
271 CPrivateBase::m_interface->toKodi->kodiBase, type, header.c_str(), message.c_str(),
272 imageFile.c_str(), displayTime, withSound, messageTime);
273}
274//------------------------------------------------------------------------------
275
276//============================================================================
295inline std::string ATTR_DLL_LOCAL GetMD5(const std::string& text)
296{
297 using namespace kodi::addon;
298
299 char* md5ret = static_cast<char*>(malloc(40 * sizeof(char))); // md5 size normally 32 bytes
300 CPrivateBase::m_interface->toKodi->kodi->get_md5(CPrivateBase::m_interface->toKodi->kodiBase,
301 text.c_str(), md5ret);
302 std::string md5 = md5ret;
303 free(md5ret);
304 return md5;
305}
306//----------------------------------------------------------------------------
307
308//==============================================================================
331inline std::string ATTR_DLL_LOCAL GetRegion(const std::string& id)
332{
333 using namespace kodi::addon;
334
335 AddonToKodiFuncTable_Addon* toKodi = CPrivateBase::m_interface->toKodi;
336
337 std::string strReturn;
338 char* strMsg = toKodi->kodi->get_region(toKodi->kodiBase, id.c_str());
339 if (strMsg != nullptr)
340 {
341 if (std::strlen(strMsg))
342 strReturn = strMsg;
343 toKodi->free_string(toKodi->kodiBase, strMsg);
344 }
345 return strReturn;
346}
347//------------------------------------------------------------------------------
348
349//==============================================================================
372inline void ATTR_DLL_LOCAL GetFreeMem(long& free, long& total, bool asBytes = false)
373{
374 using namespace kodi::addon;
375
376 free = -1;
377 total = -1;
378 AddonToKodiFuncTable_Addon* toKodi = CPrivateBase::m_interface->toKodi;
379 toKodi->kodi->get_free_mem(toKodi->kodiBase, &free, &total, asBytes);
380}
381//------------------------------------------------------------------------------
382
383//==============================================================================
400inline int ATTR_DLL_LOCAL GetGlobalIdleTime()
401{
402 using namespace kodi::addon;
403
404 AddonToKodiFuncTable_Addon* toKodi = CPrivateBase::m_interface->toKodi;
405 return toKodi->kodi->get_global_idle_time(toKodi->kodiBase);
406}
407//------------------------------------------------------------------------------
408
409//==============================================================================
430inline std::string ATTR_DLL_LOCAL GetCurrentSkinId()
431{
432 using namespace kodi::addon;
433
434 AddonToKodiFuncTable_Addon* toKodi = CPrivateBase::m_interface->toKodi;
435
436 std::string strReturn;
437 char* strMsg = toKodi->kodi->get_current_skin_id(toKodi->kodiBase);
438 if (strMsg != nullptr)
439 {
440 if (std::strlen(strMsg))
441 strReturn = strMsg;
442 toKodi->free_string(toKodi->kodiBase, strMsg);
443 }
444 return strReturn;
445}
446//------------------------------------------------------------------------------
447
448//==============================================================================
471inline bool ATTR_DLL_LOCAL IsAddonAvailable(const std::string& id,
472 std::string& version,
473 bool& enabled)
474{
475 using namespace kodi::addon;
476
477 AddonToKodiFuncTable_Addon* toKodi = CPrivateBase::m_interface->toKodi;
478
479 char* cVersion = nullptr;
480 bool ret = toKodi->kodi->is_addon_avilable(toKodi->kodiBase, id.c_str(), &cVersion, &enabled);
481 if (cVersion)
482 {
483 version = cVersion;
484 toKodi->free_string(toKodi->kodiBase, cVersion);
485 }
486 return ret;
487}
488//------------------------------------------------------------------------------
489
490//==============================================================================
529inline void ATTR_DLL_LOCAL KodiVersion(kodi_version_t& version)
530{
531 using namespace kodi::addon;
532
533 char* compile_name = nullptr;
534 char* revision = nullptr;
535 char* tag = nullptr;
536 char* tag_revision = nullptr;
537
538 AddonToKodiFuncTable_Addon* toKodi = CPrivateBase::m_interface->toKodi;
539 toKodi->kodi->kodi_version(toKodi->kodiBase, &compile_name, &version.major, &version.minor,
540 &revision, &tag, &tag_revision);
541 if (compile_name != nullptr)
542 {
543 version.compile_name = compile_name;
544 toKodi->free_string(toKodi->kodiBase, compile_name);
545 }
546 if (revision != nullptr)
547 {
548 version.revision = revision;
549 toKodi->free_string(toKodi->kodiBase, revision);
550 }
551 if (tag != nullptr)
552 {
553 version.tag = tag;
554 toKodi->free_string(toKodi->kodiBase, tag);
555 }
556 if (tag_revision != nullptr)
557 {
558 version.tag_revision = tag_revision;
559 toKodi->free_string(toKodi->kodiBase, tag_revision);
560 }
561}
562//------------------------------------------------------------------------------
563
564//==============================================================================
597inline bool ATTR_DLL_LOCAL GetKeyboardLayout(int modifierKey,
598 std::string& layout_name,
599 std::vector<std::vector<std::string>>& layout)
600{
601 using namespace kodi::addon;
602
603 AddonToKodiFuncTable_Addon* toKodi = CPrivateBase::m_interface->toKodi;
604 AddonKeyboardKeyTable c_layout;
605 char* c_layout_name = nullptr;
606 bool ret =
607 toKodi->kodi->get_keyboard_layout(toKodi->kodiBase, &c_layout_name, modifierKey, &c_layout);
608 if (ret)
609 {
610 if (c_layout_name)
611 {
612 layout_name = c_layout_name;
613 toKodi->free_string(toKodi->kodiBase, c_layout_name);
614 }
615
616 layout.resize(STD_KB_BUTTONS_MAX_ROWS);
617 for (unsigned int row = 0; row < STD_KB_BUTTONS_MAX_ROWS; row++)
618 {
619 layout[row].resize(STD_KB_BUTTONS_PER_ROW);
620 for (unsigned int column = 0; column < STD_KB_BUTTONS_PER_ROW; column++)
621 {
622 char* button = c_layout.keys[row][column];
623 if (button)
624 {
625 layout[row][column] = button;
626 toKodi->free_string(toKodi->kodiBase, button);
627 }
628 }
629 }
630 }
631 return ret;
632}
633//------------------------------------------------------------------------------
634
635//==============================================================================
669inline bool ATTR_DLL_LOCAL ChangeKeyboardLayout(std::string& layout_name)
670{
671 using namespace kodi::addon;
672
673 AddonToKodiFuncTable_Addon* toKodi = CPrivateBase::m_interface->toKodi;
674 char* c_layout_name = nullptr;
675 bool ret = toKodi->kodi->change_keyboard_layout(toKodi->kodiBase, &c_layout_name);
676 if (c_layout_name)
677 {
678 layout_name = c_layout_name;
679 toKodi->free_string(toKodi->kodiBase, c_layout_name);
680 }
681
682 return ret;
683}
684//------------------------------------------------------------------------------
685
686} /* namespace kodi */
687
688#endif /* __cplusplus */
std::string tag_revision
The revision of tag before.
Definition General.h:34
std::string revision
The Revision contains a id and the build date, e.g. 20170706-c6b22fe217-dirty.
Definition General.h:30
int major
Major code version of Kodi.
Definition General.h:26
std::string tag
The version candidate e.g. alpha, beta or release.
Definition General.h:32
int minor
Minor code version of Kodi.
Definition General.h:28
std::string compile_name
Application name, normally 'Kodi'.
Definition General.h:24
LangFormats
Format codes to get string from them.
Definition general.h:62
QueueMsg
For kodi::QueueNotification() used message types.
Definition general.h:43
@ LANG_FMT_ENGLISH_NAME
full language name in English
Definition general.h:68
@ STD_KB_BUTTONS_PER_ROW
The quantity of buttons per row on Kodi's standard keyboard.
Definition general.h:26
@ STD_KB_BUTTONS_MAX_ROWS
The quantity of rows on Kodi's standard keyboard.
Definition general.h:28
For kodi::Version used structure.
Definition General.h:22
static std::string FormatV(PRINTF_FORMAT_STRING const char *fmt, va_list args)
Returns the C++ string pointed by given format list.
Definition StringUtils.h:604
std::string ATTR_DLL_LOCAL GetMD5(const std::string &text)
Get the MD5 digest of the given text.
Definition General.h:295
bool ATTR_DLL_LOCAL UnknownToUTF8(const std::string &stringSrc, std::string &utf8StringDst, bool failOnBadChar=false)
Translate a string with an unknown encoding to UTF8.
Definition General.h:63
void ATTR_DLL_LOCAL KodiVersion(kodi_version_t &version)
Get current Kodi information and versions, returned data from the following kodi_version_t version; k...
Definition General.h:529
int ATTR_DLL_LOCAL GetGlobalIdleTime()
Returns the elapsed idle time in seconds as an integer.
Definition General.h:400
void ATTR_DLL_LOCAL 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)
Queue a notification in the GUI.
Definition General.h:260
bool ATTR_DLL_LOCAL GetKeyboardLayout(int modifierKey, std::string &layout_name, std::vector< std::vector< std::string > > &layout)
To get keyboard layout characters.
Definition General.h:597
std::string ATTR_DLL_LOCAL GetCurrentSkinId()
Get the currently used skin identification name from Kodi.
Definition General.h:430
void ATTR_DLL_LOCAL GetFreeMem(long &free, long &total, bool asBytes=false)
Returns the amount of free memory in MByte (or as bytes) as an long integer.
Definition General.h:372
bool ATTR_DLL_LOCAL ChangeKeyboardLayout(std::string &layout_name)
To change keyboard layout characters.
Definition General.h:669
std::string ATTR_DLL_LOCAL GetRegion(const std::string &id)
Returns your regions setting as a string for the specified id.
Definition General.h:331
std::string ATTR_DLL_LOCAL GetLanguage(LangFormats format=LANG_FMT_ENGLISH_NAME, bool region=false)
Returns the active language as a string.
Definition General.h:107
bool ATTR_DLL_LOCAL IsAddonAvailable(const std::string &id, std::string &version, bool &enabled)
To check another addon is available and usable inside Kodi.
Definition General.h:471
void ATTR_DLL_LOCAL QueueFormattedNotification(QueueMsg type, const char *format,...)
Writes the C string pointed by format in the GUI. If format includes format specifiers (subsequences ...
Definition General.h:202
Definition general.h:84
Callback function tables from addon to Kodi Set complete from Kodi!
Definition addon_base.h:326