diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /xbmc/addons/interfaces/gui/dialogs | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/addons/interfaces/gui/dialogs')
21 files changed, 2837 insertions, 0 deletions
diff --git a/xbmc/addons/interfaces/gui/dialogs/CMakeLists.txt b/xbmc/addons/interfaces/gui/dialogs/CMakeLists.txt new file mode 100644 index 0000000..4dad4e9 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/CMakeLists.txt @@ -0,0 +1,23 @@ +set(SOURCES ContextMenu.cpp + ExtendedProgressBar.cpp + FileBrowser.cpp + Keyboard.cpp + Numeric.cpp + OK.cpp + Progress.cpp + Select.cpp + TextViewer.cpp + YesNo.cpp) + +set(HEADERS ContextMenu.h + ExtendedProgressBar.h + FileBrowser.h + Keyboard.h + Numeric.h + OK.h + Progress.h + Select.h + TextViewer.h + YesNo.h) + +core_add_library(addons_interfaces_gui_dialogs) diff --git a/xbmc/addons/interfaces/gui/dialogs/ContextMenu.cpp b/xbmc/addons/interfaces/gui/dialogs/ContextMenu.cpp new file mode 100644 index 0000000..e0e5684 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/ContextMenu.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "ContextMenu.h" + +#include "ServiceBroker.h" +#include "addons/binary-addons/AddonDll.h" +#include "addons/kodi-dev-kit/include/kodi/gui/dialogs/ContextMenu.h" +#include "dialogs/GUIDialogContextMenu.h" +#include "guilib/GUIComponent.h" +#include "guilib/GUIWindowManager.h" +#include "utils/log.h" + +namespace ADDON +{ + +void Interface_GUIDialogContextMenu::Init(AddonGlobalInterface* addonInterface) +{ + addonInterface->toKodi->kodi_gui->dialogContextMenu = + new AddonToKodiFuncTable_kodi_gui_dialogContextMenu(); + + addonInterface->toKodi->kodi_gui->dialogContextMenu->open = open; +} + +void Interface_GUIDialogContextMenu::DeInit(AddonGlobalInterface* addonInterface) +{ + delete addonInterface->toKodi->kodi_gui->dialogContextMenu; +} + +int Interface_GUIDialogContextMenu::open(KODI_HANDLE kodiBase, + const char* heading, + const char* entries[], + unsigned int size) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogContextMenu::{} - invalid data", __func__); + return -1; + } + + CGUIDialogContextMenu* dialog = + CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogContextMenu>( + WINDOW_DIALOG_CONTEXT_MENU); + if (!heading || !entries || !dialog) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogContextMenu::{} - invalid handler data (heading='{}', " + "entries='{}', dialog='{}') on addon '{}'", + __func__, static_cast<const void*>(heading), static_cast<const void*>(entries), + kodiBase, addon->ID()); + return -1; + } + + CContextButtons choices; + for (unsigned int i = 0; i < size; ++i) + choices.Add(i, entries[i]); + + return dialog->Show(choices); +} + +} /* namespace ADDON */ diff --git a/xbmc/addons/interfaces/gui/dialogs/ContextMenu.h b/xbmc/addons/interfaces/gui/dialogs/ContextMenu.h new file mode 100644 index 0000000..7b41a28 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/ContextMenu.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "addons/kodi-dev-kit/include/kodi/c-api/gui/dialogs/context_menu.h" + +extern "C" +{ + + struct AddonGlobalInterface; + + namespace ADDON + { + + /*! + * @brief Global gui Add-on to Kodi callback functions + * + * To hold functions not related to a instance type and usable for + * every add-on type. + * + * Related add-on header is "./xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ContextMenu.h" + */ + struct Interface_GUIDialogContextMenu + { + 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 int open(KODI_HANDLE kodiBase, + const char* heading, + const char* entries[], + unsigned int size); + //@} + }; + + } /* namespace ADDON */ +} /* extern "C" */ diff --git a/xbmc/addons/interfaces/gui/dialogs/ExtendedProgressBar.cpp b/xbmc/addons/interfaces/gui/dialogs/ExtendedProgressBar.cpp new file mode 100644 index 0000000..9e7f7a7 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/ExtendedProgressBar.cpp @@ -0,0 +1,305 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "ExtendedProgressBar.h" + +#include "ServiceBroker.h" +#include "addons/binary-addons/AddonDll.h" +#include "addons/kodi-dev-kit/include/kodi/gui/dialogs/ExtendedProgress.h" +#include "dialogs/GUIDialogExtendedProgressBar.h" +#include "guilib/GUIComponent.h" +#include "guilib/GUIWindowManager.h" +#include "utils/log.h" + +namespace ADDON +{ + +void Interface_GUIDialogExtendedProgress::Init(AddonGlobalInterface* addonInterface) +{ + addonInterface->toKodi->kodi_gui->dialogExtendedProgress = + new AddonToKodiFuncTable_kodi_gui_dialogExtendedProgress(); + + addonInterface->toKodi->kodi_gui->dialogExtendedProgress->new_dialog = new_dialog; + addonInterface->toKodi->kodi_gui->dialogExtendedProgress->delete_dialog = delete_dialog; + addonInterface->toKodi->kodi_gui->dialogExtendedProgress->get_title = get_title; + addonInterface->toKodi->kodi_gui->dialogExtendedProgress->set_title = set_title; + addonInterface->toKodi->kodi_gui->dialogExtendedProgress->get_text = get_text; + addonInterface->toKodi->kodi_gui->dialogExtendedProgress->set_text = set_text; + addonInterface->toKodi->kodi_gui->dialogExtendedProgress->is_finished = is_finished; + addonInterface->toKodi->kodi_gui->dialogExtendedProgress->mark_finished = mark_finished; + addonInterface->toKodi->kodi_gui->dialogExtendedProgress->get_percentage = get_percentage; + addonInterface->toKodi->kodi_gui->dialogExtendedProgress->set_percentage = set_percentage; + addonInterface->toKodi->kodi_gui->dialogExtendedProgress->set_progress = set_progress; +} + +void Interface_GUIDialogExtendedProgress::DeInit(AddonGlobalInterface* addonInterface) +{ + delete addonInterface->toKodi->kodi_gui->dialogExtendedProgress; +} + +KODI_GUI_HANDLE Interface_GUIDialogExtendedProgress::new_dialog(KODI_HANDLE kodiBase, + const char* title) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogExtendedProgress::{} - invalid kodi base data", + __func__); + return nullptr; + } + + // setup the progress dialog + CGUIDialogExtendedProgressBar* dialog = + CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogExtendedProgressBar>( + WINDOW_DIALOG_EXT_PROGRESS); + if (!title || !dialog) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogExtendedProgress::{} - invalid handler data (title='{}', " + "dialog='{}') on addon '{}'", + __func__, static_cast<const void*>(title), static_cast<void*>(dialog), addon->ID()); + return nullptr; + } + + CGUIDialogProgressBarHandle* dlgProgressHandle = dialog->GetHandle(title); + return dlgProgressHandle; +} + +void Interface_GUIDialogExtendedProgress::delete_dialog(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogExtendedProgress::{} - invalid kodi base data", + __func__); + return; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogExtendedProgress::{} - invalid handler data (handle='{}') on " + "addon '{}'", + __func__, handle, addon->ID()); + return; + } + + static_cast<CGUIDialogProgressBarHandle*>(handle)->MarkFinished(); +} + +char* Interface_GUIDialogExtendedProgress::get_title(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogExtendedProgress::{} - invalid kodi base data", + __func__); + return nullptr; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogExtendedProgress::{} - invalid handler data (handle='{}') on " + "addon '{}'", + __func__, handle, addon->ID()); + return nullptr; + } + + return strdup(static_cast<CGUIDialogProgressBarHandle*>(handle)->Title().c_str()); +} + +void Interface_GUIDialogExtendedProgress::set_title(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + const char* title) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogExtendedProgress::{} - invalid kodi base data", + __func__); + return; + } + + if (!handle || !title) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogExtendedProgress::{} - invalid handler data (handle='{}', " + "title='{}') on addon '{}'", + __func__, handle, static_cast<const void*>(title), addon->ID()); + return; + } + + static_cast<CGUIDialogProgressBarHandle*>(handle)->SetTitle(title); +} + +char* Interface_GUIDialogExtendedProgress::get_text(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogExtendedProgress::{} - invalid kodi base data", + __func__); + return nullptr; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogExtendedProgress::{} - invalid add-on data (handle='{}') on " + "addon '{}'", + __func__, handle, addon->ID()); + return nullptr; + } + + return strdup(static_cast<CGUIDialogProgressBarHandle*>(handle)->Text().c_str()); +} + +void Interface_GUIDialogExtendedProgress::set_text(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + const char* text) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogExtendedProgress::{} - invalid kodi base data", + __func__); + return; + } + + if (!handle || !text) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogExtendedProgress::{} - invalid handler data (handle='{}', " + "text='{}') on addon '{}'", + __func__, handle, static_cast<const void*>(text), addon->ID()); + return; + } + + static_cast<CGUIDialogProgressBarHandle*>(handle)->SetText(text); +} + +bool Interface_GUIDialogExtendedProgress::is_finished(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogExtendedProgress::{} - invalid kodi base data", + __func__); + return false; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogExtendedProgress::{} - invalid add-on data (handle='{}') on " + "addon '{}'", + __func__, handle, addon->ID()); + return false; + } + + return static_cast<CGUIDialogProgressBarHandle*>(handle)->IsFinished(); +} + +void Interface_GUIDialogExtendedProgress::mark_finished(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogExtendedProgress::{} - invalid kodi base data", + __func__); + return; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogExtendedProgress::{} - invalid add-on data (handle='{}') on " + "addon '{}'", + __func__, handle, addon->ID()); + return; + } + + static_cast<CGUIDialogProgressBarHandle*>(handle)->MarkFinished(); +} + +float Interface_GUIDialogExtendedProgress::get_percentage(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogExtendedProgress::{} - invalid kodi base data", + __func__); + return 0.0f; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogExtendedProgress::{} - invalid add-on data (handle='{}') on " + "addon '{}'", + __func__, handle, addon->ID()); + return 0.0f; + } + + return static_cast<CGUIDialogProgressBarHandle*>(handle)->Percentage(); +} + +void Interface_GUIDialogExtendedProgress::set_percentage(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + float percentage) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogExtendedProgress::{} - invalid kodi base data", + __func__); + return; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogExtendedProgress::{} - invalid add-on data (handle='{}') on " + "addon '{}'", + __func__, handle, addon->ID()); + return; + } + + static_cast<CGUIDialogProgressBarHandle*>(handle)->SetPercentage(percentage); +} + +void Interface_GUIDialogExtendedProgress::set_progress(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + int currentItem, + int itemCount) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogExtendedProgress::{} - invalid kodi base data", + __func__); + return; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogExtendedProgress::{} - invalid add-on data (handle='{}') on " + "addon '{}'", + __func__, handle, addon->ID()); + return; + } + + static_cast<CGUIDialogProgressBarHandle*>(handle)->SetProgress(currentItem, itemCount); +} + +} /* namespace ADDON */ diff --git a/xbmc/addons/interfaces/gui/dialogs/ExtendedProgressBar.h b/xbmc/addons/interfaces/gui/dialogs/ExtendedProgressBar.h new file mode 100644 index 0000000..66ccb49 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/ExtendedProgressBar.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "addons/kodi-dev-kit/include/kodi/c-api/gui/dialogs/extended_progress.h" + +extern "C" +{ + + struct AddonGlobalInterface; + + namespace ADDON + { + + /*! + * @brief Global gui Add-on to Kodi callback functions + * + * To hold functions not related to a instance type and usable for + * every add-on type. + * + * Related add-on header is "./xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/ExtendedProgress.h" + */ + struct Interface_GUIDialogExtendedProgress + { + 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 KODI_GUI_HANDLE new_dialog(KODI_HANDLE kodiBase, const char* title); + static void delete_dialog(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle); + static char* get_title(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle); + static void set_title(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle, const char* title); + static char* get_text(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle); + static void set_text(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle, const char* text); + static bool is_finished(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle); + static void mark_finished(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle); + static float get_percentage(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle); + static void set_percentage(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle, float percentage); + static void set_progress(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + int currentItem, + int itemCount); + //@} + }; + + } /* namespace ADDON */ +} /* extern "C" */ diff --git a/xbmc/addons/interfaces/gui/dialogs/FileBrowser.cpp b/xbmc/addons/interfaces/gui/dialogs/FileBrowser.cpp new file mode 100644 index 0000000..84d6443 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/FileBrowser.cpp @@ -0,0 +1,403 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "FileBrowser.h" + +#include "URL.h" +#include "addons/binary-addons/AddonDll.h" +#include "addons/kodi-dev-kit/include/kodi/gui/dialogs/FileBrowser.h" +#include "dialogs/GUIDialogFileBrowser.h" +#include "settings/MediaSourceSettings.h" +#include "storage/MediaManager.h" +#include "utils/URIUtils.h" +#include "utils/log.h" + +namespace ADDON +{ + +void Interface_GUIDialogFileBrowser::Init(AddonGlobalInterface* addonInterface) +{ + addonInterface->toKodi->kodi_gui->dialogFileBrowser = + new AddonToKodiFuncTable_kodi_gui_dialogFileBrowser(); + + addonInterface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_directory = + show_and_get_directory; + addonInterface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_file = show_and_get_file; + addonInterface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_file_from_dir = + show_and_get_file_from_dir; + addonInterface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_file_list = + show_and_get_file_list; + addonInterface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_source = show_and_get_source; + addonInterface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_image = show_and_get_image; + addonInterface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_image_list = + show_and_get_image_list; + addonInterface->toKodi->kodi_gui->dialogFileBrowser->clear_file_list = clear_file_list; +} + +void Interface_GUIDialogFileBrowser::DeInit(AddonGlobalInterface* addonInterface) +{ + delete addonInterface->toKodi->kodi_gui->dialogFileBrowser; +} + +bool Interface_GUIDialogFileBrowser::show_and_get_directory(KODI_HANDLE kodiBase, + const char* shares, + const char* heading, + const char* path_in, + char** path_out, + bool write_only) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogFileBrowser::{} - invalid data", __func__); + return false; + } + + if (!shares || !heading || !path_in || !path_out) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogFileBrowser::{} - invalid handler data (shares='{}', " + "heading='{}', path_in='{}', path_out='{}') on addon '{}'", + __func__, static_cast<const void*>(shares), static_cast<const void*>(heading), + static_cast<const void*>(path_in), static_cast<void*>(path_out), addon->ID()); + return false; + } + + std::string strPath = path_in; + + VECSOURCES vecShares; + GetVECShares(vecShares, shares, strPath); + bool bRet = CGUIDialogFileBrowser::ShowAndGetDirectory(vecShares, heading, strPath, write_only); + if (bRet) + *path_out = strdup(strPath.c_str()); + return bRet; +} + +bool Interface_GUIDialogFileBrowser::show_and_get_file(KODI_HANDLE kodiBase, + const char* shares, + const char* mask, + const char* heading, + const char* path_in, + char** path_out, + bool use_thumbs, + bool use_file_directories) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogFileBrowser::{} - invalid data", __func__); + return false; + } + + if (!shares || !mask || !heading || !path_in || !path_out) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogFileBrowser::{} - invalid handler data (shares='{}', mask='{}', " + "heading='{}', path_in='{}', path_out='{}') on addon '{}'", + __func__, static_cast<const void*>(shares), static_cast<const void*>(mask), + static_cast<const void*>(heading), static_cast<const void*>(path_in), + static_cast<void*>(path_out), addon->ID()); + return false; + } + + std::string strPath = path_in; + + VECSOURCES vecShares; + GetVECShares(vecShares, shares, strPath); + bool bRet = CGUIDialogFileBrowser::ShowAndGetFile(vecShares, mask, heading, strPath, use_thumbs, + use_file_directories); + if (bRet) + *path_out = strdup(strPath.c_str()); + return bRet; +} + +bool Interface_GUIDialogFileBrowser::show_and_get_file_from_dir(KODI_HANDLE kodiBase, + const char* directory, + const char* mask, + const char* heading, + const char* path_in, + char** path_out, + bool use_thumbs, + bool use_file_directories, + bool single_list) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogFileBrowser::{} - invalid data", __func__); + return false; + } + + if (!directory || !mask || !heading || !path_in || !path_out) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogFileBrowser::{} - invalid handler data (directory='{}', " + "mask='{}', heading='{}', path_in='{}', path_out='{}') on addon '{}'", + __func__, static_cast<const void*>(directory), static_cast<const void*>(mask), + static_cast<const void*>(heading), static_cast<const void*>(path_in), + static_cast<void*>(path_out), addon->ID()); + return false; + } + + std::string strPath = path_in; + bool bRet = CGUIDialogFileBrowser::ShowAndGetFile(directory, mask, heading, strPath, use_thumbs, + use_file_directories, single_list); + if (bRet) + *path_out = strdup(strPath.c_str()); + return bRet; +} + +bool Interface_GUIDialogFileBrowser::show_and_get_file_list(KODI_HANDLE kodiBase, + const char* shares, + const char* mask, + const char* heading, + char*** file_list, + unsigned int* entries, + bool use_thumbs, + bool use_file_directories) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogFileBrowser::{} - invalid data", __func__); + return false; + } + + if (!shares || !mask || !heading || !file_list || !entries) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogFileBrowser::{} - invalid handler data (shares='{}', mask='{}', " + "heading='{}', file_list='{}', entries='{}') on addon '{}'", + __func__, static_cast<const void*>(shares), static_cast<const void*>(mask), + static_cast<const void*>(heading), static_cast<void*>(file_list), + static_cast<void*>(entries), addon->ID()); + return false; + } + + VECSOURCES vecShares; + GetVECShares(vecShares, shares, ""); + + std::vector<std::string> pathsInt; + bool bRet = CGUIDialogFileBrowser::ShowAndGetFileList(vecShares, mask, heading, pathsInt, + use_thumbs, use_file_directories); + if (bRet) + { + *entries = pathsInt.size(); + *file_list = static_cast<char**>(malloc(*entries * sizeof(char*))); + for (unsigned int i = 0; i < *entries; ++i) + (*file_list)[i] = strdup(pathsInt[i].c_str()); + } + else + *entries = 0; + return bRet; +} + +bool Interface_GUIDialogFileBrowser::show_and_get_source(KODI_HANDLE kodiBase, + const char* path_in, + char** path_out, + bool allowNetworkShares, + const char* additionalShare, + const char* strType) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogFileBrowser::{} - invalid data", __func__); + return false; + } + + if (!strType || !additionalShare || !path_in || !path_out) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogFileBrowser::{} - invalid handler data (additionalShare='{}', " + "strType='{}', path_in='{}', path_out='{}') on addon '{}'", + __func__, static_cast<const void*>(additionalShare), + static_cast<const void*>(strType), static_cast<const void*>(path_in), + static_cast<void*>(path_out), addon->ID()); + return false; + } + + std::string strPath = path_in; + + VECSOURCES vecShares; + if (additionalShare) + GetVECShares(vecShares, additionalShare, strPath); + bool bRet = + CGUIDialogFileBrowser::ShowAndGetSource(strPath, allowNetworkShares, &vecShares, strType); + if (bRet) + *path_out = strdup(strPath.c_str()); + return bRet; +} + +bool Interface_GUIDialogFileBrowser::show_and_get_image(KODI_HANDLE kodiBase, + const char* shares, + const char* heading, + const char* path_in, + char** path_out) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogFileBrowser::{} - invalid data", __func__); + return false; + } + + if (!shares || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogFileBrowser::{} - invalid handler data (shares='{}', " + "heading='{}') on addon '{}'", + __func__, static_cast<const void*>(shares), static_cast<const void*>(heading), + addon->ID()); + return false; + } + + std::string strPath = path_in; + + VECSOURCES vecShares; + GetVECShares(vecShares, shares, strPath); + bool bRet = CGUIDialogFileBrowser::ShowAndGetImage(vecShares, heading, strPath); + if (bRet) + *path_out = strdup(strPath.c_str()); + return bRet; +} + +bool Interface_GUIDialogFileBrowser::show_and_get_image_list(KODI_HANDLE kodiBase, + const char* shares, + const char* heading, + char*** file_list, + unsigned int* entries) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogFileBrowser::{} - invalid data", __func__); + return false; + } + + if (!shares || !heading || !file_list || !entries) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogFileBrowser::{} - invalid handler data (shares='{}', " + "heading='{}', file_list='{}', entries='{}') on addon '{}'", + __func__, static_cast<const void*>(shares), static_cast<const void*>(heading), + static_cast<void*>(file_list), static_cast<void*>(entries), addon->ID()); + return false; + } + + VECSOURCES vecShares; + GetVECShares(vecShares, shares, ""); + + std::vector<std::string> pathsInt; + bool bRet = CGUIDialogFileBrowser::ShowAndGetImageList(vecShares, heading, pathsInt); + if (bRet) + { + *entries = pathsInt.size(); + *file_list = static_cast<char**>(malloc(*entries * sizeof(char*))); + for (unsigned int i = 0; i < *entries; ++i) + (*file_list)[i] = strdup(pathsInt[i].c_str()); + } + else + *entries = 0; + return bRet; +} + +void Interface_GUIDialogFileBrowser::clear_file_list(KODI_HANDLE kodiBase, + char*** file_list, + unsigned int entries) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogFileBrowser::{} - invalid data", __func__); + return; + } + + if (*file_list) + { + for (unsigned int i = 0; i < entries; ++i) + free((*file_list)[i]); + free(*file_list); + *file_list = nullptr; + } + else + { + + CLog::Log(LOGERROR, + "Interface_GUIDialogFileBrowser::{} - invalid handler data (file_list='{}') on " + "addon '{}'", + __func__, static_cast<void*>(file_list), addon->ID()); + } +} + +void Interface_GUIDialogFileBrowser::GetVECShares(VECSOURCES& vecShares, + const std::string& strShares, + const std::string& strPath) +{ + std::size_t found; + found = strShares.find("local"); + if (found != std::string::npos) + CServiceBroker::GetMediaManager().GetLocalDrives(vecShares); + found = strShares.find("network"); + if (found != std::string::npos) + CServiceBroker::GetMediaManager().GetNetworkLocations(vecShares); + found = strShares.find("removable"); + if (found != std::string::npos) + CServiceBroker::GetMediaManager().GetRemovableDrives(vecShares); + found = strShares.find("programs"); + if (found != std::string::npos) + { + VECSOURCES* sources = CMediaSourceSettings::GetInstance().GetSources("programs"); + if (sources != nullptr) + vecShares.insert(vecShares.end(), sources->begin(), sources->end()); + } + found = strShares.find("files"); + if (found != std::string::npos) + { + VECSOURCES* sources = CMediaSourceSettings::GetInstance().GetSources("files"); + if (sources != nullptr) + vecShares.insert(vecShares.end(), sources->begin(), sources->end()); + } + found = strShares.find("music"); + if (found != std::string::npos) + { + VECSOURCES* sources = CMediaSourceSettings::GetInstance().GetSources("music"); + if (sources != nullptr) + vecShares.insert(vecShares.end(), sources->begin(), sources->end()); + } + found = strShares.find("video"); + if (found != std::string::npos) + { + VECSOURCES* sources = CMediaSourceSettings::GetInstance().GetSources("video"); + if (sources != nullptr) + vecShares.insert(vecShares.end(), sources->begin(), sources->end()); + } + found = strShares.find("pictures"); + if (found != std::string::npos) + { + VECSOURCES* sources = CMediaSourceSettings::GetInstance().GetSources("pictures"); + if (sources != nullptr) + vecShares.insert(vecShares.end(), sources->begin(), sources->end()); + } + + if (vecShares.empty()) + { + CMediaSource share; + std::string basePath = strPath; + std::string tempPath; + while (URIUtils::GetParentPath(basePath, tempPath)) + basePath = tempPath; + share.strPath = basePath; + // don't include the user details in the share name + CURL url(share.strPath); + share.strName = url.GetWithoutUserDetails(); + vecShares.push_back(share); + } +} + +} /* namespace ADDON */ diff --git a/xbmc/addons/interfaces/gui/dialogs/FileBrowser.h b/xbmc/addons/interfaces/gui/dialogs/FileBrowser.h new file mode 100644 index 0000000..c2193f3 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/FileBrowser.h @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "addons/kodi-dev-kit/include/kodi/c-api/gui/dialogs/filebrowser.h" + +#include <string> +#include <vector> + +class CMediaSource; + +typedef std::vector<CMediaSource> VECSOURCES; + +extern "C" +{ + + struct AddonGlobalInterface; + + namespace ADDON + { + + /*! + * @brief Global gui Add-on to Kodi callback functions + * + * To hold functions not related to a instance type and usable for + * every add-on type. + * + * Related add-on header is "./xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/FileBrowser.h" + */ + struct Interface_GUIDialogFileBrowser + { + 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 show_and_get_directory(KODI_HANDLE kodiBase, + const char* shares, + const char* heading, + const char* path_in, + char** path_out, + bool write_only); + + static bool show_and_get_file(KODI_HANDLE kodiBase, + const char* shares, + const char* mask, + const char* heading, + const char* path_in, + char** path_out, + bool use_thumbs, + bool use_file_directories); + + static bool show_and_get_file_from_dir(KODI_HANDLE kodiBase, + const char* directory, + const char* mask, + const char* heading, + const char* path_in, + char** path_out, + bool use_thumbs, + bool use_file_directories, + bool singleList); + + static bool show_and_get_file_list(KODI_HANDLE kodiBase, + const char* shares, + const char* mask, + const char* heading, + char*** file_list, + unsigned int* entries, + bool use_thumbs, + bool use_file_directories); + + static bool show_and_get_source(KODI_HANDLE kodiBase, + const char* path_in, + char** path_out, + bool allow_network_shares, + const char* additional_share, + const char* type); + + static bool show_and_get_image(KODI_HANDLE kodiBase, + const char* shares, + const char* heading, + const char* path_in, + char** path_out); + + static bool show_and_get_image_list(KODI_HANDLE kodiBase, + const char* shares, + const char* heading, + char*** file_list, + unsigned int* entries); + + static void clear_file_list(KODI_HANDLE kodiBase, char*** file_list, unsigned int entries); + //@} + + private: + static void GetVECShares(VECSOURCES& vecShares, + const std::string& strShares, + const std::string& strPath); + }; + + } /* namespace ADDON */ +} /* extern "C" */ diff --git a/xbmc/addons/interfaces/gui/dialogs/Keyboard.cpp b/xbmc/addons/interfaces/gui/dialogs/Keyboard.cpp new file mode 100644 index 0000000..7ec56ab --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/Keyboard.cpp @@ -0,0 +1,319 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "Keyboard.h" + +#include "addons/binary-addons/AddonDll.h" +#include "addons/kodi-dev-kit/include/kodi/gui/dialogs/Keyboard.h" +#include "guilib/GUIKeyboardFactory.h" +#include "utils/Variant.h" +#include "utils/log.h" + +namespace ADDON +{ + +void Interface_GUIDialogKeyboard::Init(AddonGlobalInterface* addonInterface) +{ + addonInterface->toKodi->kodi_gui->dialogKeyboard = + new AddonToKodiFuncTable_kodi_gui_dialogKeyboard(); + + addonInterface->toKodi->kodi_gui->dialogKeyboard->show_and_get_input_with_head = + show_and_get_input_with_head; + addonInterface->toKodi->kodi_gui->dialogKeyboard->show_and_get_input = show_and_get_input; + addonInterface->toKodi->kodi_gui->dialogKeyboard->show_and_get_new_password_with_head = + show_and_get_new_password_with_head; + addonInterface->toKodi->kodi_gui->dialogKeyboard->show_and_get_new_password = + show_and_get_new_password; + addonInterface->toKodi->kodi_gui->dialogKeyboard->show_and_verify_new_password_with_head = + show_and_verify_new_password_with_head; + addonInterface->toKodi->kodi_gui->dialogKeyboard->show_and_verify_new_password = + show_and_verify_new_password; + addonInterface->toKodi->kodi_gui->dialogKeyboard->show_and_verify_password = + show_and_verify_password; + addonInterface->toKodi->kodi_gui->dialogKeyboard->show_and_get_filter = show_and_get_filter; + addonInterface->toKodi->kodi_gui->dialogKeyboard->send_text_to_active_keyboard = + send_text_to_active_keyboard; + addonInterface->toKodi->kodi_gui->dialogKeyboard->is_keyboard_activated = is_keyboard_activated; +} + +void Interface_GUIDialogKeyboard::DeInit(AddonGlobalInterface* addonInterface) +{ + delete addonInterface->toKodi->kodi_gui->dialogKeyboard; +} + +bool Interface_GUIDialogKeyboard::show_and_get_input_with_head(KODI_HANDLE kodiBase, + const char* text_in, + char** text_out, + const char* heading, + bool allow_empty_result, + bool hidden_input, + unsigned int auto_close_ms) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogKeyboard::{} - invalid data", __func__); + return false; + } + + if (!text_in || !text_out || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogKeyboard::{} - invalid handler data (text_in='{}', " + "text_out='{}', heading='{}') on addon '{}'", + __func__, static_cast<const void*>(text_in), static_cast<void*>(text_out), + static_cast<const void*>(heading), addon->ID()); + return false; + } + + std::string str = text_in; + bool bRet = CGUIKeyboardFactory::ShowAndGetInput(str, CVariant{heading}, allow_empty_result, + hidden_input, auto_close_ms); + if (bRet) + *text_out = strdup(str.c_str()); + return bRet; +} + +bool Interface_GUIDialogKeyboard::show_and_get_input(KODI_HANDLE kodiBase, + const char* text_in, + char** text_out, + bool allow_empty_result, + unsigned int auto_close_ms) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogKeyboard::{} - invalid data", __func__); + return false; + } + + if (!text_in || !text_out) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogKeyboard::{} - invalid handler data (text_in='{}', " + "text_out='{}') on addon '{}'", + __func__, static_cast<const void*>(text_in), static_cast<void*>(text_out), + addon->ID()); + return false; + } + + std::string str = text_in; + bool bRet = CGUIKeyboardFactory::ShowAndGetInput(str, allow_empty_result, auto_close_ms); + if (bRet) + *text_out = strdup(str.c_str()); + return bRet; +} + +bool Interface_GUIDialogKeyboard::show_and_get_new_password_with_head(KODI_HANDLE kodiBase, + const char* password_in, + char** password_out, + const char* heading, + bool allow_empty_result, + unsigned int auto_close_ms) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogKeyboard::{} - invalid data", __func__); + return false; + } + + if (!password_in || !password_out || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogKeyboard::{} - invalid handler data (password_in='{}', " + "password_out='{}', heading='{}') on addon '{}'", + __func__, static_cast<const void*>(password_in), static_cast<void*>(password_out), + static_cast<const void*>(heading), addon->ID()); + return false; + } + + std::string str = password_in; + bool bRet = + CGUIKeyboardFactory::ShowAndGetNewPassword(str, heading, allow_empty_result, auto_close_ms); + if (bRet) + *password_out = strdup(str.c_str()); + return bRet; +} + +bool Interface_GUIDialogKeyboard::show_and_get_new_password(KODI_HANDLE kodiBase, + const char* password_in, + char** password_out, + unsigned int auto_close_ms) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogKeyboard::{} - invalid data", __func__); + return false; + } + + if (!password_in || !password_out) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogKeyboard::{} - invalid handler data (password_in='{}', " + "password_out='{}') on addon '{}'", + __func__, static_cast<const void*>(password_in), static_cast<void*>(password_out), + addon->ID()); + return false; + } + + std::string str = password_in; + bool bRet = CGUIKeyboardFactory::ShowAndGetNewPassword(str, auto_close_ms); + if (bRet) + *password_out = strdup(str.c_str()); + return bRet; +} + +bool Interface_GUIDialogKeyboard::show_and_verify_new_password_with_head(KODI_HANDLE kodiBase, + char** password_out, + const char* heading, + bool allowEmpty, + unsigned int auto_close_ms) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogKeyboard::{} - invalid data", __func__); + return false; + } + + if (!password_out || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogKeyboard::{} - invalid handler data (password_out='{}', " + "heading='{}') on addon '{}'", + __func__, static_cast<void*>(password_out), static_cast<const void*>(heading), + addon->ID()); + return false; + } + + std::string str; + bool bRet = + CGUIKeyboardFactory::ShowAndVerifyNewPassword(str, heading, allowEmpty, auto_close_ms); + if (bRet) + *password_out = strdup(str.c_str()); + return bRet; +} + +bool Interface_GUIDialogKeyboard::show_and_verify_new_password(KODI_HANDLE kodiBase, + char** password_out, + unsigned int auto_close_ms) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogKeyboard::{} - invalid data", __func__); + return false; + } + + if (!password_out) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogKeyboard::{} - invalid handler data (password_out='{}') on " + "addon '{}'", + __func__, static_cast<void*>(password_out), addon->ID()); + return false; + } + + std::string str; + bool bRet = CGUIKeyboardFactory::ShowAndVerifyNewPassword(str, auto_close_ms); + if (bRet) + *password_out = strdup(str.c_str()); + return bRet; +} + +int Interface_GUIDialogKeyboard::show_and_verify_password(KODI_HANDLE kodiBase, + const char* password_in, + char** password_out, + const char* heading, + int retries, + unsigned int auto_close_ms) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogKeyboard::{} - invalid data", __func__); + return false; + } + + if (!password_in || !password_out || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogKeyboard::{} - invalid handler data (password_in='{}', " + "password_out='{}', heading='{}') on addon '{}'", + __func__, static_cast<const void*>(password_in), static_cast<void*>(password_out), + static_cast<const void*>(heading), addon->ID()); + return false; + } + + std::string str = password_in; + int iRet = CGUIKeyboardFactory::ShowAndVerifyPassword(str, heading, retries, auto_close_ms); + if (iRet) + *password_out = strdup(str.c_str()); + return iRet; +} + +bool Interface_GUIDialogKeyboard::show_and_get_filter(KODI_HANDLE kodiBase, + const char* text_in, + char** text_out, + bool searching, + unsigned int auto_close_ms) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogKeyboard::{} - invalid data", __func__); + return false; + } + + if (!text_in || !text_out) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogKeyboard::{} - invalid handler data (text_in='{}', " + "text_out='{}') on addon '{}'", + __func__, static_cast<const void*>(text_in), static_cast<void*>(text_out), + addon->ID()); + return false; + } + + + std::string str = text_in; + bool bRet = CGUIKeyboardFactory::ShowAndGetFilter(str, searching, auto_close_ms); + if (bRet) + *text_out = strdup(str.c_str()); + return bRet; +} + +bool Interface_GUIDialogKeyboard::send_text_to_active_keyboard(KODI_HANDLE kodiBase, + const char* text, + bool close_keyboard) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogKeyboard::{} - invalid data", __func__); + return false; + } + + return CGUIKeyboardFactory::SendTextToActiveKeyboard(text, close_keyboard); +} + +bool Interface_GUIDialogKeyboard::is_keyboard_activated(KODI_HANDLE kodiBase) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogKeyboard::{} - invalid data", __func__); + return false; + } + + return CGUIKeyboardFactory::isKeyboardActivated(); +} + +} /* namespace ADDON */ diff --git a/xbmc/addons/interfaces/gui/dialogs/Keyboard.h b/xbmc/addons/interfaces/gui/dialogs/Keyboard.h new file mode 100644 index 0000000..fb7d6b9 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/Keyboard.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "addons/kodi-dev-kit/include/kodi/c-api/gui/dialogs/keyboard.h" + +extern "C" +{ + + struct AddonGlobalInterface; + + namespace ADDON + { + + /*! + * @brief Global gui Add-on to Kodi callback functions + * + * To hold functions not related to a instance type and usable for + * every add-on type. + * + * Related add-on header is "./xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Keyboard.h" + */ + struct Interface_GUIDialogKeyboard + { + 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 show_and_get_input_with_head(KODI_HANDLE kodiBase, + const char* text_in, + char** text_out, + const char* heading, + bool allow_empty_result, + bool hidden_input, + unsigned int auto_close_ms); + static bool show_and_get_input(KODI_HANDLE kodiBase, + const char* text_in, + char** text_out, + bool allow_empty_result, + unsigned int auto_close_ms); + static bool show_and_get_new_password_with_head(KODI_HANDLE kodiBase, + const char* password_in, + char** password_out, + const char* heading, + bool allow_empty_result, + unsigned int auto_close_ms); + static bool show_and_get_new_password(KODI_HANDLE kodiBase, + const char* password_in, + char** password_out, + unsigned int auto_close_ms); + static bool show_and_verify_new_password_with_head(KODI_HANDLE kodiBase, + char** password_out, + const char* heading, + bool allowEmpty, + unsigned int auto_close_ms); + static bool show_and_verify_new_password(KODI_HANDLE kodiBase, + char** password_out, + unsigned int auto_close_ms); + static int show_and_verify_password(KODI_HANDLE kodiBase, + const char* password_in, + char** password_out, + const char* heading, + int retries, + unsigned int auto_close_ms); + static bool show_and_get_filter(KODI_HANDLE kodiBase, + const char* text_in, + char** text_out, + bool searching, + unsigned int auto_close_ms); + static bool send_text_to_active_keyboard(KODI_HANDLE kodiBase, + const char* text, + bool close_keyboard); + static bool is_keyboard_activated(KODI_HANDLE kodiBase); + //@} + }; + + } /* namespace ADDON */ +} /* extern "C" */ diff --git a/xbmc/addons/interfaces/gui/dialogs/Numeric.cpp b/xbmc/addons/interfaces/gui/dialogs/Numeric.cpp new file mode 100644 index 0000000..a78aa4a --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/Numeric.cpp @@ -0,0 +1,270 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "Numeric.h" + +#include "XBDateTime.h" +#include "addons/binary-addons/AddonDll.h" +#include "addons/kodi-dev-kit/include/kodi/gui/dialogs/Numeric.h" +#include "dialogs/GUIDialogNumeric.h" +#include "utils/log.h" + +namespace ADDON +{ + +void Interface_GUIDialogNumeric::Init(AddonGlobalInterface* addonInterface) +{ + addonInterface->toKodi->kodi_gui->dialogNumeric = + new AddonToKodiFuncTable_kodi_gui_dialogNumeric(); + + addonInterface->toKodi->kodi_gui->dialogNumeric->show_and_verify_new_password = + show_and_verify_new_password; + addonInterface->toKodi->kodi_gui->dialogNumeric->show_and_verify_password = + show_and_verify_password; + addonInterface->toKodi->kodi_gui->dialogNumeric->show_and_verify_input = show_and_verify_input; + addonInterface->toKodi->kodi_gui->dialogNumeric->show_and_get_time = show_and_get_time; + addonInterface->toKodi->kodi_gui->dialogNumeric->show_and_get_date = show_and_get_date; + addonInterface->toKodi->kodi_gui->dialogNumeric->show_and_get_ip_address = + show_and_get_ip_address; + addonInterface->toKodi->kodi_gui->dialogNumeric->show_and_get_number = show_and_get_number; + addonInterface->toKodi->kodi_gui->dialogNumeric->show_and_get_seconds = show_and_get_seconds; +} + +void Interface_GUIDialogNumeric::DeInit(AddonGlobalInterface* addonInterface) +{ + delete addonInterface->toKodi->kodi_gui->dialogNumeric; +} + +bool Interface_GUIDialogNumeric::show_and_verify_new_password(KODI_HANDLE kodiBase, char** password) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogNumeric::{} - invalid data", __func__); + return false; + } + + std::string str; + bool bRet = CGUIDialogNumeric::ShowAndVerifyNewPassword(str); + if (bRet) + *password = strdup(str.c_str()); + return bRet; +} + +int Interface_GUIDialogNumeric::show_and_verify_password(KODI_HANDLE kodiBase, + const char* password, + const char* heading, + int retries) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogNumeric::{} - invalid data", __func__); + return -1; + } + + if (!password || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogNumeric::{} - invalid handler data (password='{}', heading='{}') " + "on addon '{}'", + __func__, static_cast<const void*>(password), static_cast<const void*>(heading), + addon->ID()); + return -1; + } + + std::string pw(password); + return CGUIDialogNumeric::ShowAndVerifyPassword(pw, heading, retries); +} + +bool Interface_GUIDialogNumeric::show_and_verify_input(KODI_HANDLE kodiBase, + const char* verify_in, + char** verify_out, + const char* heading, + bool verify_input) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogNumeric::{} - invalid data", __func__); + return false; + } + + if (!verify_in || !verify_out || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogNumeric::{} - invalid handler data (verify_in='{}', " + "verify_out='{}', heading='{}') on addon '{}'", + __func__, static_cast<const void*>(verify_in), static_cast<void*>(verify_out), + static_cast<const void*>(heading), addon->ID()); + return false; + } + + std::string str = verify_in; + if (CGUIDialogNumeric::ShowAndVerifyInput(str, heading, verify_input) == + InputVerificationResult::SUCCESS) + { + *verify_out = strdup(str.c_str()); + return true; + } + return false; +} + +bool Interface_GUIDialogNumeric::show_and_get_time(KODI_HANDLE kodiBase, + tm* time, + const char* heading) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogNumeric::{} - invalid data", __func__); + return false; + } + + if (!time || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogNumeric::{} - invalid handler data (time='{}', heading='{}') on " + "addon '{}'", + __func__, static_cast<void*>(time), static_cast<const void*>(heading), addon->ID()); + return false; + } + + KODI::TIME::SystemTime systemTime; + CDateTime dateTime(*time); + dateTime.GetAsSystemTime(systemTime); + if (CGUIDialogNumeric::ShowAndGetTime(systemTime, heading)) + { + dateTime = systemTime; + dateTime.GetAsTm(*time); + return true; + } + return false; +} + +bool Interface_GUIDialogNumeric::show_and_get_date(KODI_HANDLE kodiBase, + tm* date, + const char* heading) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogNumeric::{} - invalid data", __func__); + return false; + } + + if (!date || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogNumeric::{} - invalid handler data (date='{}', heading='{}') on " + "addon '{}'", + __func__, static_cast<void*>(date), static_cast<const void*>(heading), addon->ID()); + return false; + } + + KODI::TIME::SystemTime systemTime; + CDateTime dateTime(*date); + dateTime.GetAsSystemTime(systemTime); + if (CGUIDialogNumeric::ShowAndGetDate(systemTime, heading)) + { + dateTime = systemTime; + dateTime.GetAsTm(*date); + return true; + } + return false; +} + +bool Interface_GUIDialogNumeric::show_and_get_ip_address(KODI_HANDLE kodiBase, + const char* ip_address_in, + char** ip_address_out, + const char* heading) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogNumeric::{} - invalid data", __func__); + return false; + } + + if (!ip_address_in || !ip_address_out || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogNumeric::{} - invalid handler data (ip_address_in='{}', " + "ip_address_out='{}', heading='{}') on addon '{}'", + __func__, static_cast<const void*>(ip_address_in), static_cast<void*>(ip_address_out), + static_cast<const void*>(heading), addon->ID()); + return false; + } + + std::string strIP = ip_address_in; + bool bRet = CGUIDialogNumeric::ShowAndGetIPAddress(strIP, heading); + if (bRet) + *ip_address_out = strdup(strIP.c_str()); + return bRet; +} + +bool Interface_GUIDialogNumeric::show_and_get_number(KODI_HANDLE kodiBase, + const char* number_in, + char** number_out, + const char* heading, + unsigned int auto_close_ms) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogNumeric::{} - invalid data", __func__); + return false; + } + + if (!number_in || !number_out || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogNumeric::{} - invalid handler data (number_in='{}', " + "number_out='{}', heading='{}') on addon '{}'", + __func__, static_cast<const void*>(number_in), static_cast<void*>(number_out), + static_cast<const void*>(heading), addon->ID()); + return false; + } + + std::string str = number_in; + bool bRet = CGUIDialogNumeric::ShowAndGetNumber(str, heading, auto_close_ms); + if (bRet) + *number_out = strdup(str.c_str()); + return bRet; +} + +bool Interface_GUIDialogNumeric::show_and_get_seconds(KODI_HANDLE kodiBase, + const char* time_in, + char** time_out, + const char* heading) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogNumeric::{} - invalid data", __func__); + return false; + } + + if (!time_in || !time_out || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogNumeric::{} - invalid handler data (time_in='{}', time_out='{}', " + "heading='{}') on addon '{}'", + __func__, static_cast<const void*>(time_in), static_cast<void*>(time_out), + static_cast<const void*>(heading), addon->ID()); + return false; + } + + std::string str = time_in; + bool bRet = CGUIDialogNumeric::ShowAndGetSeconds(str, heading); + if (bRet) + *time_out = strdup(str.c_str()); + return bRet; +} + +} /* namespace ADDON */ diff --git a/xbmc/addons/interfaces/gui/dialogs/Numeric.h b/xbmc/addons/interfaces/gui/dialogs/Numeric.h new file mode 100644 index 0000000..a54ad52 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/Numeric.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "addons/kodi-dev-kit/include/kodi/c-api/gui/dialogs/numeric.h" + +extern "C" +{ + + struct AddonGlobalInterface; + + namespace ADDON + { + + /*! + * @brief Global gui Add-on to Kodi callback functions + * + * To hold functions not related to a instance type and usable for + * every add-on type. + * + * Related add-on header is "./xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Numeric.h" + */ + struct Interface_GUIDialogNumeric + { + 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 show_and_verify_new_password(KODI_HANDLE kodiBase, char** password); + static int show_and_verify_password(KODI_HANDLE kodiBase, + const char* password, + const char* heading, + int retries); + static bool show_and_verify_input(KODI_HANDLE kodiBase, + const char* verify_in, + char** verify_out, + const char* heading, + bool verify_input); + static bool show_and_get_time(KODI_HANDLE kodiBase, tm* time, const char* heading); + static bool show_and_get_date(KODI_HANDLE kodiBase, tm* date, const char* heading); + static bool show_and_get_ip_address(KODI_HANDLE kodiBase, + const char* ip_address_in, + char** ip_address_out, + const char* heading); + static bool show_and_get_number(KODI_HANDLE kodiBase, + const char* number_in, + char** number_out, + const char* heading, + unsigned int auto_close_ms); + static bool show_and_get_seconds(KODI_HANDLE kodiBase, + const char* time_in, + char** time_out, + const char* heading); + //@} + }; + + } /* namespace ADDON */ +} /* extern "C" */ diff --git a/xbmc/addons/interfaces/gui/dialogs/OK.cpp b/xbmc/addons/interfaces/gui/dialogs/OK.cpp new file mode 100644 index 0000000..90e9d69 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/OK.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "OK.h" + +#include "addons/binary-addons/AddonDll.h" +#include "addons/kodi-dev-kit/include/kodi/gui/dialogs/OK.h" +#include "messaging/helpers/DialogOKHelper.h" +#include "utils/Variant.h" +#include "utils/log.h" + +using namespace KODI::MESSAGING; + +namespace ADDON +{ + +void Interface_GUIDialogOK::Init(AddonGlobalInterface* addonInterface) +{ + addonInterface->toKodi->kodi_gui->dialogOK = new AddonToKodiFuncTable_kodi_gui_dialogOK(); + + addonInterface->toKodi->kodi_gui->dialogOK->show_and_get_input_single_text = + show_and_get_input_single_text; + addonInterface->toKodi->kodi_gui->dialogOK->show_and_get_input_line_text = + show_and_get_input_line_text; +} + +void Interface_GUIDialogOK::DeInit(AddonGlobalInterface* addonInterface) +{ + delete addonInterface->toKodi->kodi_gui->dialogOK; +} + +void Interface_GUIDialogOK::show_and_get_input_single_text(KODI_HANDLE kodiBase, + const char* heading, + const char* text) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon || !heading || !text) + { + CLog::Log( + LOGERROR, "Interface_GUIDialogOK:{} - invalid data (addon='{}', heading='{}', text='{}')", + __func__, kodiBase, static_cast<const void*>(heading), static_cast<const void*>(text)); + return; + } + + HELPERS::ShowOKDialogText(CVariant{heading}, CVariant{text}); +} + +void Interface_GUIDialogOK::show_and_get_input_line_text(KODI_HANDLE kodiBase, + const char* heading, + const char* line0, + const char* line1, + const char* line2) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon || !heading || !line0 || !line1 || !line2) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogOK::{} - invalid data (addon='{}', heading='{}', line0='{}', " + "line1='{}', line2='{}')", + __func__, kodiBase, static_cast<const void*>(heading), + static_cast<const void*>(line0), static_cast<const void*>(line1), + static_cast<const void*>(line2)); + return; + } + HELPERS::ShowOKDialogLines(CVariant{heading}, CVariant{line0}, CVariant{line1}, CVariant{line2}); +} + +} /* namespace ADDON */ diff --git a/xbmc/addons/interfaces/gui/dialogs/OK.h b/xbmc/addons/interfaces/gui/dialogs/OK.h new file mode 100644 index 0000000..fd13719 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/OK.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "addons/kodi-dev-kit/include/kodi/c-api/gui/dialogs/ok.h" + +extern "C" +{ + + struct AddonGlobalInterface; + + namespace ADDON + { + + /*! + * @brief Global gui Add-on to Kodi callback functions + * + * To hold functions not related to a instance type and usable for + * every add-on type. + * + * Related add-on header is "./xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/OK.h" + */ + struct Interface_GUIDialogOK + { + static void Init(AddonGlobalInterface* addonInterface); + static void DeInit(AddonGlobalInterface* addonInterface); + + /*! + * @brief callback functions from add-on to kodi + * + * @note For add of new functions use the "_" style to identify direct a + * add-on callback function. Everything with CamelCase is only for the + * usage in Kodi only. + * + * The parameter `kodiBase` is used to become the pointer for a `CAddonDll` + * class. + */ + //@{ + static void show_and_get_input_single_text(KODI_HANDLE kodiBase, + const char* heading, + const char* text); + static void show_and_get_input_line_text(KODI_HANDLE kodiBase, + const char* heading, + const char* line0, + const char* line1, + const char* line2); + //@} + }; + + } /* namespace ADDON */ +} /* extern "C" */ diff --git a/xbmc/addons/interfaces/gui/dialogs/Progress.cpp b/xbmc/addons/interfaces/gui/dialogs/Progress.cpp new file mode 100644 index 0000000..ff6c742 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/Progress.cpp @@ -0,0 +1,328 @@ +/* + * Copyright (C) 2015-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "Progress.h" + +#include "ServiceBroker.h" +#include "addons/binary-addons/AddonDll.h" +#include "addons/kodi-dev-kit/include/kodi/gui/dialogs/Progress.h" +#include "dialogs/GUIDialogProgress.h" +#include "guilib/GUIComponent.h" +#include "guilib/GUIWindowManager.h" +#include "utils/Variant.h" +#include "utils/log.h" + +namespace ADDON +{ + +void Interface_GUIDialogProgress::Init(AddonGlobalInterface* addonInterface) +{ + addonInterface->toKodi->kodi_gui->dialogProgress = + new AddonToKodiFuncTable_kodi_gui_dialogProgress(); + + addonInterface->toKodi->kodi_gui->dialogProgress->new_dialog = new_dialog; + addonInterface->toKodi->kodi_gui->dialogProgress->delete_dialog = delete_dialog; + addonInterface->toKodi->kodi_gui->dialogProgress->open = open; + addonInterface->toKodi->kodi_gui->dialogProgress->set_heading = set_heading; + addonInterface->toKodi->kodi_gui->dialogProgress->set_line = set_line; + addonInterface->toKodi->kodi_gui->dialogProgress->set_can_cancel = set_can_cancel; + addonInterface->toKodi->kodi_gui->dialogProgress->is_canceled = is_canceled; + addonInterface->toKodi->kodi_gui->dialogProgress->set_percentage = set_percentage; + addonInterface->toKodi->kodi_gui->dialogProgress->get_percentage = get_percentage; + addonInterface->toKodi->kodi_gui->dialogProgress->show_progress_bar = show_progress_bar; + addonInterface->toKodi->kodi_gui->dialogProgress->set_progress_max = set_progress_max; + addonInterface->toKodi->kodi_gui->dialogProgress->set_progress_advance = set_progress_advance; + addonInterface->toKodi->kodi_gui->dialogProgress->abort = abort; +} + +void Interface_GUIDialogProgress::DeInit(AddonGlobalInterface* addonInterface) +{ + delete addonInterface->toKodi->kodi_gui->dialogProgress; +} + +KODI_GUI_HANDLE Interface_GUIDialogProgress::new_dialog(KODI_HANDLE kodiBase) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return nullptr; + } + + CGUIDialogProgress* dialog = + CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogProgress>( + WINDOW_DIALOG_PROGRESS); + if (!dialog) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (dialog='{}') on addon '{}'", + __func__, static_cast<void*>(dialog), addon->ID()); + return nullptr; + } + + return dialog; +} + +void Interface_GUIDialogProgress::delete_dialog(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (handle='{}') on addon '{}'", + __func__, handle, addon->ID()); + return; + } + + static_cast<CGUIDialogProgress*>(handle)->Close(); +} + +void Interface_GUIDialogProgress::open(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (handle='{}') on addon '{}'", + __func__, handle, addon->ID()); + return; + } + + static_cast<CGUIDialogProgress*>(handle)->Open(); +} + +void Interface_GUIDialogProgress::set_heading(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + const char* heading) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return; + } + + if (!handle || !heading) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (handle='{}', heading='{}') " + "on addon '{}'", + __func__, handle, static_cast<const void*>(heading), addon->ID()); + return; + } + + static_cast<CGUIDialogProgress*>(handle)->SetHeading(heading); +} + +void Interface_GUIDialogProgress::set_line(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + unsigned int line, + const char* text) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return; + } + + if (!handle || !text) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (handle='{}', text='{}') on " + "addon '{}'", + __func__, handle, static_cast<const void*>(text), addon->ID()); + return; + } + + static_cast<CGUIDialogProgress*>(handle)->SetLine(line, text); +} + +void Interface_GUIDialogProgress::set_can_cancel(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + bool canCancel) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (handle='{}') on addon '{}'", + __func__, handle, addon->ID()); + return; + } + + static_cast<CGUIDialogProgress*>(handle)->SetCanCancel(canCancel); +} + +bool Interface_GUIDialogProgress::is_canceled(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return false; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (handle='{}') on addon '{}'", + __func__, handle, addon->ID()); + return false; + } + + return static_cast<CGUIDialogProgress*>(handle)->IsCanceled(); +} + +void Interface_GUIDialogProgress::set_percentage(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + int percentage) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (handle='{}') on addon '{}'", + __func__, handle, addon->ID()); + return; + } + + static_cast<CGUIDialogProgress*>(handle)->SetPercentage(percentage); +} + +int Interface_GUIDialogProgress::get_percentage(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return 0; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (handle='{}') on addon '{}'", + __func__, handle, addon->ID()); + return 0; + } + + return static_cast<CGUIDialogProgress*>(handle)->GetPercentage(); +} + +void Interface_GUIDialogProgress::show_progress_bar(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + bool onOff) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (handle='{}') on addon '{}'", + __func__, handle, addon->ID()); + return; + } + + static_cast<CGUIDialogProgress*>(handle)->ShowProgressBar(onOff); +} + +void Interface_GUIDialogProgress::set_progress_max(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + int max) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (handle='{}') on addon '{}'", + __func__, handle, addon->ID()); + return; + } + + static_cast<CGUIDialogProgress*>(handle)->SetProgressMax(max); +} + +void Interface_GUIDialogProgress::set_progress_advance(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + int nSteps) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (handle='{}') on addon '{}'", + __func__, handle, addon->ID()); + return; + } + + static_cast<CGUIDialogProgress*>(handle)->SetProgressAdvance(nSteps); +} + +bool Interface_GUIDialogProgress::abort(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogProgress::{} - invalid data", __func__); + return false; + } + + if (!handle) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogProgress::{} - invalid handler data (handle='{}') on addon '{}'", + __func__, handle, addon->ID()); + return false; + } + + return static_cast<CGUIDialogProgress*>(handle)->Abort(); +} + +} /* namespace ADDON */ diff --git a/xbmc/addons/interfaces/gui/dialogs/Progress.h b/xbmc/addons/interfaces/gui/dialogs/Progress.h new file mode 100644 index 0000000..ba31f3c --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/Progress.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "addons/kodi-dev-kit/include/kodi/c-api/gui/dialogs/progress.h" + +extern "C" +{ + + struct AddonGlobalInterface; + + namespace ADDON + { + + /*! + * @brief Global gui Add-on to Kodi callback functions + * + * To hold functions not related to a instance type and usable for + * every add-on type. + * + * Related add-on header is "./xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Progress.h" + */ + struct Interface_GUIDialogProgress + { + 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 KODI_GUI_HANDLE new_dialog(KODI_HANDLE kodiBase); + static void delete_dialog(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle); + static void open(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle); + static void set_heading(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle, const char* heading); + static void set_line(KODI_HANDLE kodiBase, + KODI_GUI_HANDLE handle, + unsigned int line, + const char* text); + static void set_can_cancel(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle, bool canCancel); + static bool is_canceled(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle); + static void set_percentage(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle, int percentage); + static int get_percentage(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle); + static void show_progress_bar(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle, bool bOnOff); + static void set_progress_max(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle, int max); + static void set_progress_advance(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle, int nSteps); + static bool abort(KODI_HANDLE kodiBase, KODI_GUI_HANDLE handle); + //@} + }; + + } /* namespace ADDON */ +} /* extern "C" */ diff --git a/xbmc/addons/interfaces/gui/dialogs/Select.cpp b/xbmc/addons/interfaces/gui/dialogs/Select.cpp new file mode 100644 index 0000000..7ad6ed6 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/Select.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "Select.h" + +#include "ServiceBroker.h" +#include "addons/binary-addons/AddonDll.h" +#include "addons/kodi-dev-kit/include/kodi/gui/dialogs/Select.h" +#include "dialogs/GUIDialogSelect.h" +#include "guilib/GUIComponent.h" +#include "guilib/GUIWindowManager.h" +#include "utils/Variant.h" +#include "utils/log.h" + +namespace ADDON +{ + +void Interface_GUIDialogSelect::Init(AddonGlobalInterface* addonInterface) +{ + addonInterface->toKodi->kodi_gui->dialogSelect = new AddonToKodiFuncTable_kodi_gui_dialogSelect(); + + addonInterface->toKodi->kodi_gui->dialogSelect->open = open; + addonInterface->toKodi->kodi_gui->dialogSelect->open_multi_select = open_multi_select; +} + +void Interface_GUIDialogSelect::DeInit(AddonGlobalInterface* addonInterface) +{ + delete addonInterface->toKodi->kodi_gui->dialogSelect; +} + +int Interface_GUIDialogSelect::open(KODI_HANDLE kodiBase, + const char* heading, + const char* entries[], + unsigned int size, + int selected, + unsigned int autoclose) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogSelect::{} - invalid data", __func__); + return -1; + } + + CGUIDialogSelect* dialog = + CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>( + WINDOW_DIALOG_SELECT); + if (!heading || !entries || !dialog) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogSelect::{} - invalid handler data (heading='{}', entries='{}', " + "dialog='{}') on addon '{}'", + __func__, static_cast<const void*>(heading), static_cast<const void*>(entries), + static_cast<void*>(dialog), addon->ID()); + return -1; + } + + dialog->Reset(); + dialog->SetHeading(CVariant{heading}); + + for (unsigned int i = 0; i < size; ++i) + dialog->Add(entries[i]); + + if (selected > 0) + dialog->SetSelected(selected); + if (autoclose > 0) + dialog->SetAutoClose(autoclose); + + dialog->Open(); + return dialog->GetSelectedItem(); +} + + +bool Interface_GUIDialogSelect::open_multi_select(KODI_HANDLE kodiBase, + const char* heading, + const char* entryIDs[], + const char* entryNames[], + bool entriesSelected[], + unsigned int size, + unsigned int autoclose) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogMultiSelect::{} - invalid data", __func__); + return false; + } + + CGUIDialogSelect* dialog = + CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>( + WINDOW_DIALOG_SELECT); + if (!heading || !entryIDs || !entryNames || !entriesSelected || !dialog) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogMultiSelect::{} - invalid handler data (heading='{}', " + "entryIDs='{}', entryNames='{}', entriesSelected='{}', dialog='{}') on addon '{}'", + __func__, static_cast<const void*>(heading), static_cast<const void*>(entryIDs), + static_cast<const void*>(entryNames), static_cast<void*>(entriesSelected), + static_cast<void*>(dialog), addon->ID()); + return false; + } + + dialog->Reset(); + dialog->SetMultiSelection(true); + dialog->SetHeading(CVariant{heading}); + + std::vector<int> selectedIndexes; + + for (unsigned int i = 0; i < size; ++i) + { + dialog->Add(entryNames[i]); + if (entriesSelected[i]) + selectedIndexes.push_back(i); + } + + dialog->SetSelected(selectedIndexes); + if (autoclose > 0) + dialog->SetAutoClose(autoclose); + + dialog->Open(); + if (dialog->IsConfirmed()) + { + for (unsigned int i = 0; i < size; ++i) + entriesSelected[i] = false; + + selectedIndexes = dialog->GetSelectedItems(); + + for (unsigned int i = 0; i < selectedIndexes.size(); ++i) + { + if (selectedIndexes[i]) + entriesSelected[selectedIndexes[i]] = true; + } + } + + return true; +} + +} /* namespace ADDON */ diff --git a/xbmc/addons/interfaces/gui/dialogs/Select.h b/xbmc/addons/interfaces/gui/dialogs/Select.h new file mode 100644 index 0000000..5f2d0ef --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/Select.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "addons/kodi-dev-kit/include/kodi/c-api/gui/dialogs/select.h" + +extern "C" +{ + + struct AddonGlobalInterface; + + namespace ADDON + { + + /*! + * @brief Global gui Add-on to Kodi callback functions + * + * To hold functions not related to a instance type and usable for + * every add-on type. + * + * Related add-on header is "./xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/Select.h" + */ + struct Interface_GUIDialogSelect + { + 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 int open(KODI_HANDLE kodiBase, + const char* heading, + const char* entries[], + unsigned int size, + int selected, + unsigned int autoclose); + static bool open_multi_select(KODI_HANDLE kodiBase, + const char* heading, + const char* entryIDs[], + const char* entryNames[], + bool entriesSelected[], + unsigned int size, + unsigned int autoclose); + //@} + }; + + } /* namespace ADDON */ +} /* extern "C" */ diff --git a/xbmc/addons/interfaces/gui/dialogs/TextViewer.cpp b/xbmc/addons/interfaces/gui/dialogs/TextViewer.cpp new file mode 100644 index 0000000..637975a --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/TextViewer.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "TextViewer.h" + +#include "ServiceBroker.h" +#include "addons/binary-addons/AddonDll.h" +#include "addons/kodi-dev-kit/include/kodi/gui/dialogs/TextViewer.h" +#include "dialogs/GUIDialogTextViewer.h" +#include "guilib/GUIComponent.h" +#include "guilib/GUIWindowManager.h" +#include "utils/log.h" + +namespace ADDON +{ + +void Interface_GUIDialogTextViewer::Init(AddonGlobalInterface* addonInterface) +{ + addonInterface->toKodi->kodi_gui->dialogTextViewer = + new AddonToKodiFuncTable_kodi_gui_dialogTextViewer(); + + addonInterface->toKodi->kodi_gui->dialogTextViewer->open = open; +} + +void Interface_GUIDialogTextViewer::DeInit(AddonGlobalInterface* addonInterface) +{ + delete addonInterface->toKodi->kodi_gui->dialogTextViewer; +} + +void Interface_GUIDialogTextViewer::open(KODI_HANDLE kodiBase, + const char* heading, + const char* text) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogTextViewer::{} - invalid data", __func__); + return; + } + + CGUIDialogTextViewer* dialog = + CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogTextViewer>( + WINDOW_DIALOG_TEXT_VIEWER); + if (!heading || !text || !dialog) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogTextViewer::{} - invalid handler data (heading='{}', text='{}', " + "dialog='{}') on addon '{}'", + __func__, static_cast<const void*>(heading), static_cast<const void*>(text), + static_cast<void*>(dialog), addon->ID()); + return; + } + + dialog->SetHeading(heading); + dialog->SetText(text); + dialog->Open(); +} + +} /* namespace ADDON */ diff --git a/xbmc/addons/interfaces/gui/dialogs/TextViewer.h b/xbmc/addons/interfaces/gui/dialogs/TextViewer.h new file mode 100644 index 0000000..873dbbb --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/TextViewer.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "addons/kodi-dev-kit/include/kodi/c-api/gui/dialogs/text_viewer.h" + +extern "C" +{ + + struct AddonGlobalInterface; + + namespace ADDON + { + + /*! + * @brief Global gui Add-on to Kodi callback functions + * + * To hold functions not related to a instance type and usable for + * every add-on type. + * + * Related add-on header is "./xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/TextViewer.h" + */ + struct Interface_GUIDialogTextViewer + { + 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 void open(KODI_HANDLE kodiBase, const char* heading, const char* text); + //@} + }; + + } /* namespace ADDON */ +} /* extern "C" */ diff --git a/xbmc/addons/interfaces/gui/dialogs/YesNo.cpp b/xbmc/addons/interfaces/gui/dialogs/YesNo.cpp new file mode 100644 index 0000000..89dea58 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/YesNo.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "YesNo.h" + +#include "addons/binary-addons/AddonDll.h" +#include "addons/kodi-dev-kit/include/kodi/gui/dialogs/YesNo.h" +#include "dialogs/GUIDialogYesNo.h" +#include "messaging/helpers/DialogHelper.h" +#include "utils/log.h" + +using namespace KODI::MESSAGING; +using KODI::MESSAGING::HELPERS::DialogResponse; + +namespace ADDON +{ + +void Interface_GUIDialogYesNo::Init(AddonGlobalInterface* addonInterface) +{ + addonInterface->toKodi->kodi_gui->dialogYesNo = new AddonToKodiFuncTable_kodi_gui_dialogYesNo(); + + addonInterface->toKodi->kodi_gui->dialogYesNo->show_and_get_input_single_text = + show_and_get_input_single_text; + addonInterface->toKodi->kodi_gui->dialogYesNo->show_and_get_input_line_text = + show_and_get_input_line_text; + addonInterface->toKodi->kodi_gui->dialogYesNo->show_and_get_input_line_button_text = + show_and_get_input_line_button_text; +} + +void Interface_GUIDialogYesNo::DeInit(AddonGlobalInterface* addonInterface) +{ + delete addonInterface->toKodi->kodi_gui->dialogYesNo; +} + +bool Interface_GUIDialogYesNo::show_and_get_input_single_text(KODI_HANDLE kodiBase, + const char* heading, + const char* text, + bool* canceled, + const char* noLabel, + const char* yesLabel) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogYesNo::{} - invalid data", __func__); + return false; + } + + if (!heading || !text || !canceled || !noLabel || !yesLabel) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogYesNo::{} - invalid handler data (heading='{}', text='{}', " + "canceled='{}', noLabel='{}', yesLabel='{}') on addon '{}'", + __func__, static_cast<const void*>(heading), static_cast<const void*>(text), + static_cast<void*>(canceled), static_cast<const void*>(noLabel), + static_cast<const void*>(yesLabel), addon->ID()); + return false; + } + + DialogResponse result = HELPERS::ShowYesNoDialogText(heading, text, noLabel, yesLabel); + *canceled = (result == DialogResponse::CHOICE_CANCELLED); + return (result == DialogResponse::CHOICE_YES); +} + +bool Interface_GUIDialogYesNo::show_and_get_input_line_text(KODI_HANDLE kodiBase, + const char* heading, + const char* line0, + const char* line1, + const char* line2, + const char* noLabel, + const char* yesLabel) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogYesNo::{} - invalid data", __func__); + return false; + } + + if (!heading || !line0 || !line1 || !line2 || !noLabel || !yesLabel) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogYesNo::{} - invalid handler data (heading='{}', line0='{}', " + "line1='{}', line2='{}', " + "noLabel='{}', yesLabel='{}') on addon '{}'", + __func__, static_cast<const void*>(heading), static_cast<const void*>(line0), + static_cast<const void*>(line1), static_cast<const void*>(line2), + static_cast<const void*>(noLabel), static_cast<const void*>(yesLabel), addon->ID()); + return false; + } + + return HELPERS::ShowYesNoDialogLines(heading, line0, line1, line2, noLabel, yesLabel) == + DialogResponse::CHOICE_YES; +} + +bool Interface_GUIDialogYesNo::show_and_get_input_line_button_text(KODI_HANDLE kodiBase, + const char* heading, + const char* line0, + const char* line1, + const char* line2, + bool* canceled, + const char* noLabel, + const char* yesLabel) +{ + CAddonDll* addon = static_cast<CAddonDll*>(kodiBase); + if (!addon) + { + CLog::Log(LOGERROR, "Interface_GUIDialogYesNo::{} - invalid data", __func__); + return false; + } + + if (!heading || !line0 || !line1 || !line2 || !canceled || !noLabel || !yesLabel) + { + CLog::Log(LOGERROR, + "Interface_GUIDialogYesNo::{} - invalid handler data (heading='{}', line0='{}', " + "line1='{}', line2='{}', " + "canceled='{}', noLabel='{}', yesLabel='{}') on addon '{}'", + __func__, static_cast<const void*>(heading), static_cast<const void*>(line0), + static_cast<const void*>(line1), static_cast<const void*>(line2), + static_cast<const void*>(canceled), static_cast<const void*>(noLabel), + static_cast<const void*>(yesLabel), addon->ID()); + return false; + } + + DialogResponse result = + HELPERS::ShowYesNoDialogLines(heading, line0, line1, line2, noLabel, yesLabel); + *canceled = (result == DialogResponse::CHOICE_CANCELLED); + return (result == DialogResponse::CHOICE_YES); +} + +} /* namespace ADDON */ diff --git a/xbmc/addons/interfaces/gui/dialogs/YesNo.h b/xbmc/addons/interfaces/gui/dialogs/YesNo.h new file mode 100644 index 0000000..84e5d73 --- /dev/null +++ b/xbmc/addons/interfaces/gui/dialogs/YesNo.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "addons/kodi-dev-kit/include/kodi/c-api/gui/dialogs/yes_no.h" + +extern "C" +{ + + struct AddonGlobalInterface; + + namespace ADDON + { + + /*! + * @brief Global gui Add-on to Kodi callback functions + * + * To hold functions not related to a instance type and usable for + * every add-on type. + * + * Related add-on header is "./xbmc/addons/kodi-dev-kit/include/kodi/gui/dialogs/YesNo.h" + */ + struct Interface_GUIDialogYesNo + { + 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 show_and_get_input_single_text(KODI_HANDLE kodiBase, + const char* heading, + const char* text, + bool* canceled, + const char* noLabel, + const char* yesLabel); + + static bool show_and_get_input_line_text(KODI_HANDLE kodiBase, + const char* heading, + const char* line0, + const char* line1, + const char* line2, + const char* noLabel, + const char* yesLabel); + + static bool show_and_get_input_line_button_text(KODI_HANDLE kodiBase, + const char* heading, + const char* line0, + const char* line1, + const char* line2, + bool* canceled, + const char* noLabel, + const char* yesLabel); + //@} + }; + + } /* namespace ADDON */ +} /* extern "C" */ |