From 274e4e14a7c9ff1bd9a0cbea278ad715f9212b28 Mon Sep 17 00:00:00 2001 From: ksooo <3226626+ksooo@users.noreply.github.com> Date: Fri, 12 Jul 2024 15:02:49 +0200 Subject: [FileItem][PVR] Remove duplicate code to calculate the title for an EPG tag, taking settings and parental controls into account. --- xbmc/FileItem.cpp | 26 ++++---------------------- xbmc/pvr/guilib/PVRGUIActionsEPG.cpp | 20 ++++++++++++++++++++ xbmc/pvr/guilib/PVRGUIActionsEPG.h | 15 +++++++++++++++ xbmc/pvr/guilib/guiinfo/PVRGUIInfo.cpp | 25 ++++++------------------- 4 files changed, 45 insertions(+), 41 deletions(-) diff --git a/xbmc/FileItem.cpp b/xbmc/FileItem.cpp index 2776627018..574f1ac4b2 100644 --- a/xbmc/FileItem.cpp +++ b/xbmc/FileItem.cpp @@ -43,6 +43,7 @@ #include "pvr/epg/EpgInfoTag.h" #include "pvr/epg/EpgSearchFilter.h" #include "pvr/guilib/PVRGUIActionsChannels.h" +#include "pvr/guilib/PVRGUIActionsEPG.h" #include "pvr/guilib/PVRGUIActionsUtils.h" #include "pvr/recordings/PVRRecording.h" #include "pvr/timers/PVRTimerInfoTag.h" @@ -124,37 +125,18 @@ CFileItem::CFileItem(const CVideoInfoTag& movie) SetFromVideoInfoTag(movie); } -namespace -{ -std::string GetEpgTagTitle(const std::shared_ptr& epgTag) -{ - if (CServiceBroker::GetPVRManager().IsParentalLocked(epgTag)) - return g_localizeStrings.Get(19266); // Parental locked - else if (epgTag->Title().empty() && - !CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool( - CSettings::SETTING_EPG_HIDENOINFOAVAILABLE)) - return g_localizeStrings.Get(19055); // no information available - else - return epgTag->Title(); -} -} // unnamed namespace - void CFileItem::FillMusicInfoTag(const std::shared_ptr& tag) { CMusicInfoTag* musictag = GetMusicInfoTag(); // create (!) the music tag. + musictag->SetTitle(CServiceBroker::GetPVRManager().Get().GetTitleForEpgTag(tag)); + if (tag) { - musictag->SetTitle(GetEpgTagTitle(tag)); musictag->SetGenre(tag->Genre()); musictag->SetDuration(tag->GetDuration()); musictag->SetURL(tag->Path()); } - else if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool( - CSettings::SETTING_EPG_HIDENOINFOAVAILABLE)) - { - musictag->SetTitle(g_localizeStrings.Get(19055)); // no information available - } musictag->SetLoaded(true); } @@ -167,7 +149,7 @@ CFileItem::CFileItem(const std::shared_ptr& tag) m_epgInfoTag = tag; m_strPath = tag->Path(); m_bCanQueue = false; - SetLabel(GetEpgTagTitle(tag)); + SetLabel(CServiceBroker::GetPVRManager().Get().GetTitleForEpgTag(tag)); m_dateTime = tag->StartAsLocalTime(); if (!tag->IconPath().empty()) diff --git a/xbmc/pvr/guilib/PVRGUIActionsEPG.cpp b/xbmc/pvr/guilib/PVRGUIActionsEPG.cpp index 15d3aedd08..8dcf7113eb 100644 --- a/xbmc/pvr/guilib/PVRGUIActionsEPG.cpp +++ b/xbmc/pvr/guilib/PVRGUIActionsEPG.cpp @@ -21,9 +21,12 @@ #include "pvr/dialogs/GUIDialogPVRChannelGuide.h" #include "pvr/dialogs/GUIDialogPVRGuideInfo.h" #include "pvr/epg/EpgContainer.h" +#include "pvr/epg/EpgInfoTag.h" #include "pvr/epg/EpgSearchFilter.h" #include "pvr/guilib/PVRGUIActionsParentalControl.h" #include "pvr/windows/GUIWindowPVRSearch.h" +#include "settings/Settings.h" +#include "settings/SettingsComponent.h" #include "utils/Variant.h" #include "utils/log.h" @@ -215,3 +218,20 @@ bool CPVRGUIActionsEPG::DeleteSavedSearch(const CFileItem& item) } return false; } + +std::string CPVRGUIActionsEPG::GetTitleForEpgTag(const std::shared_ptr& tag) +{ + if (tag) + { + if (CServiceBroker::GetPVRManager().IsParentalLocked(tag)) + return g_localizeStrings.Get(19266); // Parental locked + else if (!tag->Title().empty()) + return tag->Title(); + } + + if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool( + CSettings::SETTING_EPG_HIDENOINFOAVAILABLE)) + return g_localizeStrings.Get(19055); // no information available + + return {}; +} diff --git a/xbmc/pvr/guilib/PVRGUIActionsEPG.h b/xbmc/pvr/guilib/PVRGUIActionsEPG.h index e0a3edcf8c..c66740e985 100644 --- a/xbmc/pvr/guilib/PVRGUIActionsEPG.h +++ b/xbmc/pvr/guilib/PVRGUIActionsEPG.h @@ -10,10 +10,15 @@ #include "pvr/IPVRComponent.h" +#include +#include + class CFileItem; namespace PVR { +class CPVREpgInfoTag; + class CPVRGUIActionsEPG : public IPVRComponent { public: @@ -70,6 +75,16 @@ public: */ bool DeleteSavedSearch(const CFileItem& item); + /*! + * @brief Get the title for the given EPG tag, taking settings and parental controls into account. + * @param item The EPG tag. + * @return "Parental locked" in case the access to the information is restricted by parental + * controls, "No information avilable" if the real EPG event title is empty and + * SETTING_EPG_HIDENOINFOAVAILABLE is false or tag is nullptr, the real EPG event title as given + * by the EPG data provider otherwise. + */ + std::string GetTitleForEpgTag(const std::shared_ptr& tag); + private: CPVRGUIActionsEPG(const CPVRGUIActionsEPG&) = delete; CPVRGUIActionsEPG const& operator=(CPVRGUIActionsEPG const&) = delete; diff --git a/xbmc/pvr/guilib/guiinfo/PVRGUIInfo.cpp b/xbmc/pvr/guilib/guiinfo/PVRGUIInfo.cpp index c259759112..9df61c25a6 100644 --- a/xbmc/pvr/guilib/guiinfo/PVRGUIInfo.cpp +++ b/xbmc/pvr/guilib/guiinfo/PVRGUIInfo.cpp @@ -34,6 +34,7 @@ #include "pvr/epg/EpgInfoTag.h" #include "pvr/epg/EpgSearchFilter.h" #include "pvr/guilib/PVRGUIActionsChannels.h" +#include "pvr/guilib/PVRGUIActionsEPG.h" #include "pvr/providers/PVRProvider.h" #include "pvr/providers/PVRProviders.h" #include "pvr/recordings/PVRRecording.h" @@ -361,23 +362,6 @@ std::string GetAsLocalizedDateTimeString(const CDateTime& datetime) return datetime.IsValid() ? datetime.GetAsLocalizedDateTime(false, false) : ""; } -std::string GetEpgTagTitle(const std::shared_ptr& epgTag) -{ - if (epgTag) - { - if (CServiceBroker::GetPVRManager().IsParentalLocked(epgTag)) - return g_localizeStrings.Get(19266); // Parental locked - else if (!epgTag->Title().empty()) - return epgTag->Title(); - } - - if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool( - CSettings::SETTING_EPG_HIDENOINFOAVAILABLE)) - return g_localizeStrings.Get(19055); // no information available - - return {}; -} - } // unnamed namespace bool CPVRGUIInfo::GetListItemAndPlayerLabel(const CFileItem* item, @@ -683,7 +667,7 @@ bool CPVRGUIInfo::GetListItemAndPlayerLabel(const CFileItem* item, case LISTITEM_EPG_EVENT_TITLE: // Note: in difference to LISTITEM_TITLE, LISTITEM_EPG_EVENT_TITLE returns the title // associated with the epg event of a timer, if any, and not the title of the timer. - strValue = GetEpgTagTitle(epgTag); + strValue = CServiceBroker::GetPVRManager().Get().GetTitleForEpgTag(epgTag); return true; } } @@ -1303,8 +1287,11 @@ bool CPVRGUIInfo::GetFallbackLabel(std::string& value, ///////////////////////////////////////////////////////////////////////////////////////////// case VIDEOPLAYER_TITLE: case MUSICPLAYER_TITLE: - value = GetEpgTagTitle(CPVRItem(item).GetEpgInfoTag()); + { + const std::shared_ptr tag{CPVRItem(item).GetEpgInfoTag()}; + value = CServiceBroker::GetPVRManager().Get().GetTitleForEpgTag(tag); return !value.empty(); + } default: break; } -- cgit v1.2.3