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/messaging/helpers | |
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/messaging/helpers')
-rw-r--r-- | xbmc/messaging/helpers/CMakeLists.txt | 7 | ||||
-rw-r--r-- | xbmc/messaging/helpers/DialogHelper.cpp | 94 | ||||
-rw-r--r-- | xbmc/messaging/helpers/DialogHelper.h | 112 | ||||
-rw-r--r-- | xbmc/messaging/helpers/DialogOKHelper.cpp | 59 | ||||
-rw-r--r-- | xbmc/messaging/helpers/DialogOKHelper.h | 77 |
5 files changed, 349 insertions, 0 deletions
diff --git a/xbmc/messaging/helpers/CMakeLists.txt b/xbmc/messaging/helpers/CMakeLists.txt new file mode 100644 index 0000000..288ba7c --- /dev/null +++ b/xbmc/messaging/helpers/CMakeLists.txt @@ -0,0 +1,7 @@ +set(SOURCES DialogHelper.cpp + DialogOKHelper.cpp) + +set(HEADERS DialogHelper.h + DialogOKHelper.h) + +core_add_library(messagingHelpers) diff --git a/xbmc/messaging/helpers/DialogHelper.cpp b/xbmc/messaging/helpers/DialogHelper.cpp new file mode 100644 index 0000000..e269c09 --- /dev/null +++ b/xbmc/messaging/helpers/DialogHelper.cpp @@ -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. + */ + +#include "DialogHelper.h" + +#include "ServiceBroker.h" +#include "messaging/ApplicationMessenger.h" + +#include <cassert> +#include <utility> + +namespace KODI +{ +namespace MESSAGING +{ +namespace HELPERS +{ +DialogResponse ShowYesNoDialogText(CVariant heading, CVariant text, CVariant noLabel, CVariant yesLabel, uint32_t autoCloseTimeout) +{ + return ShowYesNoCustomDialog(std::move(heading), std::move(text), std::move(noLabel), + std::move(yesLabel), "", autoCloseTimeout); +} + +DialogResponse ShowYesNoCustomDialog(CVariant heading, CVariant text, CVariant noLabel, CVariant yesLabel, CVariant customLabel, uint32_t autoCloseTimeout) +{ + DialogYesNoMessage options; + options.heading = std::move(heading); + options.text = std::move(text); + options.noLabel = std::move(noLabel); + options.yesLabel = std::move(yesLabel); + options.customLabel = std::move(customLabel); + options.autoclose = autoCloseTimeout; + + switch (CServiceBroker::GetAppMessenger()->SendMsg(TMSG_GUI_DIALOG_YESNO, -1, -1, + static_cast<void*>(&options))) + { + case -1: + return DialogResponse::CHOICE_CANCELLED; + case 0: + return DialogResponse::CHOICE_NO; + case 1: + return DialogResponse::CHOICE_YES; + case 2: + return DialogResponse::CHOICE_CUSTOM; + default: + //If we get here someone changed the return values without updating this code + assert(false); + } + //This is unreachable code but we need to return something to suppress warnings about + //no return + return DialogResponse::CHOICE_CANCELLED; +} + +DialogResponse ShowYesNoDialogLines(CVariant heading, CVariant line0, CVariant line1, CVariant line2, + CVariant noLabel, CVariant yesLabel, uint32_t autoCloseTimeout) +{ + DialogYesNoMessage options; + options.heading = std::move(heading); + options.lines[0] = std::move(line0); + options.lines[1] = std::move(line1); + options.lines[2] = std::move(line2); + options.noLabel = std::move(noLabel); + options.yesLabel = std::move(yesLabel); + options.customLabel = ""; + options.autoclose = autoCloseTimeout; + + switch (CServiceBroker::GetAppMessenger()->SendMsg(TMSG_GUI_DIALOG_YESNO, -1, -1, + static_cast<void*>(&options))) + { + case -1: + return DialogResponse::CHOICE_CANCELLED; + case 0: + return DialogResponse::CHOICE_NO; + case 1: + return DialogResponse::CHOICE_YES; + case 2: + return DialogResponse::CHOICE_CUSTOM; + default: + //If we get here someone changed the return values without updating this code + assert(false); + } + //This is unreachable code but we need to return something to suppress warnings about + //no return + return DialogResponse::CHOICE_CANCELLED; +} + +} +} +} diff --git a/xbmc/messaging/helpers/DialogHelper.h b/xbmc/messaging/helpers/DialogHelper.h new file mode 100644 index 0000000..d36fad3 --- /dev/null +++ b/xbmc/messaging/helpers/DialogHelper.h @@ -0,0 +1,112 @@ +/* + * 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 "utils/Variant.h" + +#include <array> +#include <string> + +namespace KODI +{ +namespace MESSAGING +{ +namespace HELPERS +{ + +enum class DialogResponse : int +{ + CHOICE_CANCELLED, + CHOICE_YES, + CHOICE_NO, + CHOICE_CUSTOM, +}; + +/*! \struct DialogYesNoMessage DialogHelper.h "messaging/helpers/DialogHelper.h" + \brief Payload sent for message TMSG_GUI_DIALOG_YESNO + + \sa ShowDialogText + \sa ShowDialogLines +*/ +struct DialogYesNoMessage +{ + CVariant heading; //!< Heading to be displayed in the dialog box + CVariant text; //!< Body text to be displayed, this is mutually exclusive with lines below + std::array<CVariant, 3> lines; //!< Body text to be displayed, specified as three lines. This is mutually exclusive with the text above + CVariant yesLabel; //!< Text to show on the yes button + CVariant noLabel; //!< Text to show on the no button + CVariant customLabel; //!< Text to show on the 3rd custom button + uint32_t autoclose{0}; //!< Time in milliseconds before autoclosing the dialog, 0 means don't autoclose +}; + +/*! + \brief This is a helper method to send a threadmessage to open a Yes/No dialog box + + \param[in] heading The text to display as the dialog box header + \param[in] text The text to display in the dialog body + \param[in] noLabel The text to display on the No button + defaults to No + \param[in] yesLabel The text to display on the Yes button + defaults to Yes + \param[in] autoCloseTimeout The time before the dialog closes + defaults to 0 show indefinitely + \return -1 on cancelled, 0 on no and 1 on yes + \sa ShowYesNoDialogLines + \sa CGUIDialogYesNo::ShowAndGetInput + \sa DialogYesNoMessage +*/ +DialogResponse ShowYesNoDialogText(CVariant heading, CVariant text, CVariant noLabel = CVariant(), + CVariant yesLabel = CVariant(), uint32_t autoCloseTimeout = 0); + +/*! +\brief This is a helper method to send a threadmessage to open a Yes/No dialog box with a custom button + +\param[in] heading The text to display as the dialog box header +\param[in] text The text to display in the dialog body +\param[in] noLabel The text to display on the No button + defaults to No +\param[in] yesLabel The text to display on the Yes button + defaults to Yes +\param[in] customLabel The text to display on the optional 3rd custom button + defaults to empty and button not shown +\param[in] autoCloseTimeout The time before the dialog closes + defaults to 0 show indefinitely +\return -1 on cancelled, 0 on no, 1 on yes and 2 on 3rd custom response +\sa ShowYesNoDialogLines +\sa CGUIDialogYesNo::ShowAndGetInput +\sa DialogYesNoMessage +*/ +DialogResponse ShowYesNoCustomDialog(CVariant heading, CVariant text, CVariant noLabel = CVariant(), CVariant yesLabel = CVariant(), + CVariant customLabel = CVariant(), uint32_t autoCloseTimeout = 0); + +/*! + \brief This is a helper method to send a threadmessage to open a Yes/No dialog box + + \param[in] heading The text to display as the dialog box header + \param[in] line0 The text to display on the first line + \param[in] line1 The text to display on the second line + \param[in] line2 The text to display on the third line + \param[in] noLabel The text to display on the No button + defaults to No + \param[in] yesLabel The text to display on the Yes button + defaults to Yes + \param[in] autoCloseTimeout The time before the dialog closes + defaults to 0 show indefinitely + \return -1 on cancelled, 0 on no and 1 on yes + \sa ShowYesNoDialogText + \sa CGUIDialogYesNo::ShowAndGetInput + \sa DialogYesNoMessage +*/ +DialogResponse ShowYesNoDialogLines(CVariant heading, CVariant line0, CVariant line1 = CVariant(), + CVariant line2 = CVariant(), CVariant noLabel = CVariant(), + CVariant yesLabel = CVariant(), uint32_t autoCloseTimeout = 0); + +} +} +} diff --git a/xbmc/messaging/helpers/DialogOKHelper.cpp b/xbmc/messaging/helpers/DialogOKHelper.cpp new file mode 100644 index 0000000..71e8a79 --- /dev/null +++ b/xbmc/messaging/helpers/DialogOKHelper.cpp @@ -0,0 +1,59 @@ +/* + * 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 "DialogOKHelper.h" + +#include "ServiceBroker.h" +#include "messaging/ApplicationMessenger.h" + +namespace KODI +{ +namespace MESSAGING +{ +namespace HELPERS +{ +bool ShowOKDialogText(CVariant heading, CVariant text) +{ + DialogOKMessage options; + options.heading = std::move(heading); + options.text = std::move(text); + + if (CServiceBroker::GetAppMessenger()->SendMsg(TMSG_GUI_DIALOG_OK, -1, -1, + static_cast<void*>(&options)) > 0) + return true; + return false; +} + +void UpdateOKDialogText(CVariant heading, CVariant text) +{ + DialogOKMessage options; + options.heading = std::move(heading); + options.text = std::move(text); + options.show = false; + + CServiceBroker::GetAppMessenger()->SendMsg(TMSG_GUI_DIALOG_OK, -1, -1, + static_cast<void*>(&options)); +} + +bool ShowOKDialogLines(CVariant heading, CVariant line0, CVariant line1, CVariant line2) +{ + DialogOKMessage options; + options.heading = std::move(heading); + options.lines[0] = std::move(line0); + options.lines[1] = std::move(line1); + options.lines[2] = std::move(line2); + + if (CServiceBroker::GetAppMessenger()->SendMsg(TMSG_GUI_DIALOG_OK, -1, -1, + static_cast<void*>(&options)) > 0) + return true; + return false; +} + +} +} +} diff --git a/xbmc/messaging/helpers/DialogOKHelper.h b/xbmc/messaging/helpers/DialogOKHelper.h new file mode 100644 index 0000000..574bed6 --- /dev/null +++ b/xbmc/messaging/helpers/DialogOKHelper.h @@ -0,0 +1,77 @@ +/* + * 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 "utils/Variant.h" + +#include <array> +#include <string> + +namespace KODI +{ +namespace MESSAGING +{ +namespace HELPERS +{ + +/*! \struct DialogOkMessage DialogHelper.h "messaging/helpers/DialogHelper.h" + \brief Payload sent for message TMSG_GUI_DIALOG_OK + + \sa ShowOKDialogText + \sa ShowOKDialogLines +*/ +struct DialogOKMessage +{ + CVariant heading; //!< Heading to be displayed in the dialog box + CVariant text; //!< Body text to be displayed, this is mutually exclusive with lines below + std::array<CVariant, 3> lines; //!< Body text to be displayed, specified as three lines. This is mutually exclusive with the text above + bool show = true; //!< bool to see if the dialog needs to be shown +}; + +/*! + \brief This is a helper method to send a threadmessage to update a Ok dialog text + + \param[in] heading The text to display as the dialog box header + \param[in] text The text to display in the dialog body + \sa ShowOKDialogLines + \sa CGUIDialogOK::ShowAndGetInput + \sa DialogOKMessage +*/ +void UpdateOKDialogText(CVariant heading, CVariant text); + +/*! + \brief This is a helper method to send a threadmessage to open a Ok dialog box + + \param[in] heading The text to display as the dialog box header + \param[in] text The text to display in the dialog body + \return if it's confirmed + \sa UpdateOKDialogLines + \sa CGUIDialogOK::ShowAndGetInput + \sa DialogOKMessage +*/ +bool ShowOKDialogText(CVariant heading, CVariant text); + +/*! + \brief This is a helper method to send a threadmessage to open a OK dialog box + + \param[in] heading The text to display as the dialog box header + \param[in] line0 The text to display on the first line + \param[in] line1 The text to display on the second line + \param[in] line2 The text to display on the third line + \return if it's confirmed + \sa ShowOKDialogText + \sa CGUIDialogOK::ShowAndGetInput + \sa DialogOKMessage +*/ +bool ShowOKDialogLines(CVariant heading, CVariant line0, CVariant line1 = CVariant(), + CVariant line2 = CVariant()); + +} +} +} |