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/events/BaseEvent.cpp | |
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/events/BaseEvent.cpp')
-rw-r--r-- | xbmc/events/BaseEvent.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/xbmc/events/BaseEvent.cpp b/xbmc/events/BaseEvent.cpp new file mode 100644 index 0000000..d90207d --- /dev/null +++ b/xbmc/events/BaseEvent.cpp @@ -0,0 +1,107 @@ +/* + * 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 "BaseEvent.h" + +#include "guilib/LocalizeStrings.h" +#include "utils/StringUtils.h" + +#include <chrono> +#include <inttypes.h> + +CBaseEvent::CBaseEvent(const std::string& identifier, const CVariant& label, const CVariant& description, EventLevel level /* = EventLevel::Information */) + : m_level(level), + m_identifier(identifier), + m_icon(), + m_label(label), + m_description(description), + m_details(), + m_executionLabel(), + m_timestamp(GetInternalTimestamp()), + m_dateTime(CDateTime::GetCurrentDateTime()) +{ } + +CBaseEvent::CBaseEvent(const std::string& identifier, const CVariant& label, const CVariant& description, const std::string& icon, EventLevel level /* = EventLevel::Information */) + : m_level(level), + m_identifier(identifier), + m_icon(icon), + m_label(label), + m_description(description), + m_details(), + m_executionLabel(), + m_timestamp(GetInternalTimestamp()), + m_dateTime(CDateTime::GetCurrentDateTime()) +{ } + +CBaseEvent::CBaseEvent(const std::string& identifier, const CVariant& label, const CVariant& description, const std::string& icon, const CVariant& details, EventLevel level /* = EventLevel::Information */) + : m_level(level), + m_identifier(identifier), + m_icon(icon), + m_label(label), + m_description(description), + m_details(details), + m_executionLabel(), + m_timestamp(GetInternalTimestamp()), + m_dateTime(CDateTime::GetCurrentDateTime()) +{ } + +CBaseEvent::CBaseEvent(const std::string& identifier, const CVariant& label, const CVariant& description, const std::string& icon, const CVariant& details, const CVariant& executionLabel, EventLevel level /* = EventLevel::Information */) + : m_level(level), + m_identifier(identifier), + m_icon(icon), + m_label(label), + m_description(description), + m_details(details), + m_executionLabel(executionLabel), + m_timestamp(GetInternalTimestamp()), + m_dateTime(CDateTime::GetCurrentDateTime()) +{ } + +uint64_t CBaseEvent::GetInternalTimestamp() +{ + return std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::steady_clock::now()).time_since_epoch().count(); +} + +std::string CBaseEvent::GetLabel() const +{ + return VariantToLocalizedString(m_label); +} + +std::string CBaseEvent::GetDescription() const +{ + return VariantToLocalizedString(m_description); +} + +std::string CBaseEvent::GetDetails() const +{ + return VariantToLocalizedString(m_details); +} + +std::string CBaseEvent::GetExecutionLabel() const +{ + return VariantToLocalizedString(m_executionLabel); +} + +std::string CBaseEvent::VariantToLocalizedString(const CVariant& variant) +{ + if (variant.isString()) + return variant.asString(); + + if (variant.isInteger() && variant.asInteger() > 0) + return g_localizeStrings.Get(static_cast<uint32_t>(variant.asInteger())); + if (variant.isUnsignedInteger() && variant.asUnsignedInteger() > 0) + return g_localizeStrings.Get(static_cast<uint32_t>(variant.asUnsignedInteger())); + + return ""; +} + +void CBaseEvent::ToSortable(SortItem& sortable, Field field) const +{ + if (field == FieldDate) + sortable[FieldDate] = StringUtils::Format("{:020}", m_timestamp); +} |