diff options
author | Kai Sommerfeld <kai.sommerfeld@gmx.com> | 2022-06-12 00:35:08 +0200 |
---|---|---|
committer | Kai Sommerfeld <kai.sommerfeld@gmx.com> | 2022-06-13 17:51:03 +0200 |
commit | 6c155cf36388059b4b283618bfed3af7fc1d10ce (patch) | |
tree | 5ff1c48289de0ecd4f46f00593a6979b23b2716f | |
parent | 740634258205036acc77bdafa57192e5de7dc4f9 (diff) |
[PVR] Sync channel groups with backend: Fix local removal of channel groups that were removed on backend.
-rw-r--r-- | xbmc/pvr/channels/PVRChannelGroup.cpp | 8 | ||||
-rw-r--r-- | xbmc/pvr/channels/PVRChannelGroup.h | 5 | ||||
-rw-r--r-- | xbmc/pvr/channels/PVRChannelGroups.cpp | 33 | ||||
-rw-r--r-- | xbmc/pvr/channels/PVRChannelGroups.h | 5 |
4 files changed, 38 insertions, 13 deletions
diff --git a/xbmc/pvr/channels/PVRChannelGroup.cpp b/xbmc/pvr/channels/PVRChannelGroup.cpp index 6452a4fde0..0aa5c8781c 100644 --- a/xbmc/pvr/channels/PVRChannelGroup.cpp +++ b/xbmc/pvr/channels/PVRChannelGroup.cpp @@ -610,9 +610,13 @@ bool CPVRChannelGroup::HasValidDataForClient(int iClientId) const m_failedClients.end(); } -bool CPVRChannelGroup::HasValidDataForAllClients() const +bool CPVRChannelGroup::HasValidDataForClients( + const std::vector<std::shared_ptr<CPVRClient>>& clients) const { - return m_failedClients.empty(); + return m_failedClients.empty() || std::none_of(clients.cbegin(), clients.cend(), + [this](const std::shared_ptr<CPVRClient>& client) { + return !HasValidDataForClient(client->GetID()); + }); } bool CPVRChannelGroup::UpdateChannelNumbersFromAllChannelsGroup() diff --git a/xbmc/pvr/channels/PVRChannelGroup.h b/xbmc/pvr/channels/PVRChannelGroup.h index d00adc999d..98edb220cc 100644 --- a/xbmc/pvr/channels/PVRChannelGroup.h +++ b/xbmc/pvr/channels/PVRChannelGroup.h @@ -416,11 +416,12 @@ namespace PVR bool HasValidDataForClient(int iClientId) const; /*! - * @brief Check, whether data for all active pvr clients are currently valid. For instance, data + * @brief Check, whether data for given pvr clients are currently valid. For instance, data * can be invalid because the client's backend was offline when data was last queried. + * @param clients The clients to check. Check all active clients if vector is empty. * @return True, if data is currently valid, false otherwise. */ - bool HasValidDataForAllClients() const; + bool HasValidDataForClients(const std::vector<std::shared_ptr<CPVRClient>>& clients) const; /*! * @brief Update the channel numbers according to the all channels group and publish event. diff --git a/xbmc/pvr/channels/PVRChannelGroups.cpp b/xbmc/pvr/channels/PVRChannelGroups.cpp index 4a4e1af674..c0aade603e 100644 --- a/xbmc/pvr/channels/PVRChannelGroups.cpp +++ b/xbmc/pvr/channels/PVRChannelGroups.cpp @@ -12,6 +12,7 @@ #include "pvr/PVRCachedImages.h" #include "pvr/PVRDatabase.h" #include "pvr/PVRManager.h" +#include "pvr/addons/PVRClient.h" #include "pvr/addons/PVRClients.h" #include "pvr/channels/PVRChannel.h" #include "pvr/channels/PVRChannelGroupInternal.h" @@ -185,9 +186,16 @@ std::shared_ptr<CPVRChannelGroup> CPVRChannelGroups::GetByName(const std::string return (it != m_groups.cend()) ? (*it) : std::shared_ptr<CPVRChannelGroup>(); } -bool CPVRChannelGroups::HasValidDataForAllClients() const +bool CPVRChannelGroups::HasValidDataForClients( + const std::vector<std::shared_ptr<CPVRClient>>& clients) const { - return m_failedClientsForChannelGroups.empty(); + return m_failedClientsForChannelGroups.empty() || + std::none_of(clients.cbegin(), clients.cend(), + [this](const std::shared_ptr<CPVRClient>& client) { + return std::find(m_failedClientsForChannelGroups.cbegin(), + m_failedClientsForChannelGroups.cend(), + client->GetID()) != m_failedClientsForChannelGroups.cend(); + }); } bool CPVRChannelGroups::UpdateFromClients(const std::vector<std::shared_ptr<CPVRClient>>& clients, @@ -233,16 +241,27 @@ bool CPVRChannelGroups::UpdateFromClients(const std::vector<std::shared_ptr<CPVR bReturn = false; } - if ((group->Size() - iMemberCount) > 0) + const int iChangedMembersCount = static_cast<int>(group->Size()) - iMemberCount; + if (iChangedMembersCount > 0) { - CLog::LogFC(LOGDEBUG, LOGPVR, "{} channel group members added from clients to group '{}'", - static_cast<int>(group->Size() - iMemberCount), group->GroupName()); + CLog::LogFC(LOGDEBUG, LOGPVR, "{} channel group members added to group '{}'", + iChangedMembersCount, group->GroupName()); + } + else if (iChangedMembersCount < 0) + { + CLog::LogFC(LOGDEBUG, LOGPVR, "{} channel group members removed from group '{}'", + -iChangedMembersCount, group->GroupName()); + } + else + { + // could still be changed if same amount of members was removed as was added, but too + // complicated to calculate just for debug logging } } // remove empty groups if sync with backend is enabled and we have valid data from all clients - if (bSyncWithBackends && !group->IsInternalGroup() && HasValidDataForAllClients() && - group->HasValidDataForAllClients() && group->Size() == 0) + if (bSyncWithBackends && group->Size() == 0 && !group->IsInternalGroup() && + HasValidDataForClients(clients) && group->HasValidDataForClients(clients)) { emptyGroups.emplace_back(group); } diff --git a/xbmc/pvr/channels/PVRChannelGroups.h b/xbmc/pvr/channels/PVRChannelGroups.h index 806cc12ea8..709dcfb114 100644 --- a/xbmc/pvr/channels/PVRChannelGroups.h +++ b/xbmc/pvr/channels/PVRChannelGroups.h @@ -229,11 +229,12 @@ namespace PVR void SortGroups(); /*! - * @brief Check, whether data for all active pvr clients are currently valid. For instance, data + * @brief Check, whether data for given pvr clients are currently valid. For instance, data * can be invalid because the client's backend was offline when data was last queried. + * @param clients The clients to check. Check all active clients if vector is empty. * @return True, if data is currently valid, false otherwise. */ - bool HasValidDataForAllClients() const; + bool HasValidDataForClients(const std::vector<std::shared_ptr<CPVRClient>>& clients) const; bool m_bRadio; /*!< true if this is a container for radio channels, false if it is for tv channels */ std::vector<std::shared_ptr<CPVRChannelGroup>> m_groups; /*!< the groups in this container */ |