Skip to content

Commit

Permalink
Merge pull request #25356 from ksooo/pvr-channelgroups-cleanup
Browse files Browse the repository at this point in the history
[PVR] Channel groups cleanup
  • Loading branch information
ksooo committed Jun 23, 2024
2 parents 45a36c9 + b129126 commit 5069e47
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 124 deletions.
6 changes: 4 additions & 2 deletions xbmc/pvr/PVRDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "dbwrappers/dataset.h"
#include "pvr/addons/PVRClient.h"
#include "pvr/channels/PVRChannel.h"
#include "pvr/channels/PVRChannelGroupFactory.h"
#include "pvr/channels/PVRChannelGroupMember.h"
#include "pvr/channels/PVRChannelGroups.h"
#include "pvr/providers/PVRProvider.h"
Expand Down Expand Up @@ -721,10 +722,11 @@ int CPVRDatabase::GetGroups(CPVRChannelGroups& results, const std::string& query
{
while (!m_pDS->eof())
{
const std::shared_ptr<CPVRChannelGroup> group = results.CreateChannelGroup(
const std::shared_ptr<CPVRChannelGroup> group = results.GetGroupFactory()->CreateGroup(
m_pDS->fv("iGroupType").get_asInt(),
CPVRChannelsPath(m_pDS->fv("bIsRadio").get_asBool(), m_pDS->fv("sName").get_asString(),
m_pDS->fv("iClientId").get_asInt()));
m_pDS->fv("iClientId").get_asInt()),
results.GetGroupAll());

group->m_iGroupId = m_pDS->fv("idGroup").get_asInt();
group->m_iLastWatched = static_cast<time_t>(m_pDS->fv("iLastWatched").get_asInt());
Expand Down
5 changes: 2 additions & 3 deletions xbmc/pvr/addons/PVRClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
#include "pvr/addons/PVRClients.h"
#include "pvr/channels/PVRChannel.h"
#include "pvr/channels/PVRChannelGroup.h"
#include "pvr/channels/PVRChannelGroupAllChannels.h"
#include "pvr/channels/PVRChannelGroupFromClient.h"
#include "pvr/channels/PVRChannelGroupFactory.h"
#include "pvr/channels/PVRChannelGroupMember.h"
#include "pvr/channels/PVRChannelGroups.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
Expand Down Expand Up @@ -1709,7 +1708,7 @@ void CPVRClient::cb_transfer_channel_group(void* kodiInstance,

// transfer this entry to the groups container
CPVRChannelGroups* kodiGroups = static_cast<CPVRChannelGroups*>(handle->dataAddress);
const auto transferGroup = std::make_shared<CPVRChannelGroupFromClient>(
const auto transferGroup = kodiGroups->GetGroupFactory()->CreateClientGroup(
*group, client->GetID(), kodiGroups->GetGroupAll());
kodiGroups->UpdateFromClient(transferGroup);
});
Expand Down
3 changes: 2 additions & 1 deletion xbmc/pvr/channels/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set(SOURCES PVRChannel.cpp
PVRChannelGroup.cpp
PVRChannelGroupAllChannels.cpp
PVRChannelGroupFactory.cpp
PVRChannelGroupFromClient.cpp
PVRChannelGroupFromUser.cpp
PVRChannelGroupMember.cpp
PVRChannelGroupSettings.cpp
PVRChannelGroups.cpp
Expand All @@ -14,6 +14,7 @@ set(SOURCES PVRChannel.cpp
set(HEADERS PVRChannel.h
PVRChannelGroup.h
PVRChannelGroupAllChannels.h
PVRChannelGroupFactory.h
PVRChannelGroupFromClient.h
PVRChannelGroupFromUser.h
PVRChannelGroupMember.h
Expand Down
31 changes: 21 additions & 10 deletions xbmc/pvr/channels/PVRChannelGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ struct PVR_CHANNEL_GROUP;

namespace PVR
{
static constexpr int PVR_GROUP_TYPE_REMOTE = 0;
static constexpr int PVR_GROUP_TYPE_ALL_CHANNELS = 1;
static constexpr int PVR_GROUP_TYPE_LOCAL = 2;
static constexpr int PVR_GROUP_TYPE_CLIENT = 0;
static constexpr int PVR_GROUP_TYPE_SYSTEM_ALL_CHANNELS = 1;
static constexpr int PVR_GROUP_TYPE_USER = 2;

static constexpr int PVR_GROUP_CLIENT_ID_UNKNOWN = -2;
static constexpr int PVR_GROUP_CLIENT_ID_LOCAL = -1;
Expand All @@ -51,8 +51,7 @@ using GroupMemberPair =

class CPVRChannelGroup : public IChannelGroupSettingsCallback
{
friend class CPVRChannelGroups; // for GroupType()
friend class CPVRDatabase; // for GroupType()
friend class CPVRDatabase;

public:
static const int INVALID_GROUP_ID = -1;
Expand Down Expand Up @@ -459,6 +458,23 @@ class CPVRChannelGroup : public IChannelGroupSettingsCallback
*/
void UpdateClientPriorities();

enum class Origin
{
USER, // created and managed by the user
SYSTEM, // created and managed by Kodi
CLIENT, // created and managed by PVR client add-on
};
/*!
* @brief Get the group's origin.
* @return The origin.
*/
virtual Origin GetOrigin() const = 0;

/*!
* @brief Return the type of this group.
*/
virtual int GroupType() const = 0;

/*!
* @brief Check whether this group could be deleted by the user.
* @return True if the group could be deleted, false otherwise.
Expand Down Expand Up @@ -538,11 +554,6 @@ class CPVRChannelGroup : public IChannelGroupSettingsCallback
static std::weak_ptr<CPVRChannelGroupSettings> m_settingsSingleton;

private:
/*!
* @brief Return the type of this group.
*/
virtual int GroupType() const = 0;

/*!
* @brief Load the channel group members stored in the database.
* @param clients The PVR clients to load data for. Leave empty for all clients.
Expand Down
4 changes: 2 additions & 2 deletions xbmc/pvr/channels/PVRChannelGroupAllChannels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
using namespace PVR;

CPVRChannelGroupAllChannels::CPVRChannelGroupAllChannels(bool bRadio)
: CPVRChannelGroupFromUser(
: CPVRChannelGroup(
CPVRChannelsPath(bRadio, g_localizeStrings.Get(19287), PVR_GROUP_CLIENT_ID_LOCAL), nullptr)
{
}

CPVRChannelGroupAllChannels::CPVRChannelGroupAllChannels(const CPVRChannelsPath& path)
: CPVRChannelGroupFromUser(path, nullptr)
: CPVRChannelGroup(path, nullptr)
{
}

Expand Down
38 changes: 25 additions & 13 deletions xbmc/pvr/channels/PVRChannelGroupAllChannels.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@

#pragma once

#include "pvr/channels/PVRChannelGroupFromUser.h"

#include <memory>
#include <vector>
#include "pvr/channels/PVRChannelGroup.h"

namespace PVR
{
class CPVRChannel;
class CPVRChannelNumber;

class CPVRChannelGroupAllChannels : public CPVRChannelGroupFromUser
class CPVRChannelGroupAllChannels : public CPVRChannelGroup
{
public:
CPVRChannelGroupAllChannels() = delete;
Expand Down Expand Up @@ -58,12 +53,35 @@ class CPVRChannelGroupAllChannels : public CPVRChannelGroupFromUser
*/
void CheckGroupName();

/*!
* @brief Get the group's origin.
* @return The origin.
*/
Origin GetOrigin() const override { return Origin::SYSTEM; }

/*!
* @brief Return the type of this group.
*/
int GroupType() const override { return PVR_GROUP_TYPE_SYSTEM_ALL_CHANNELS; }

/*!
* @brief Check whether this group could be deleted by the user.
* @return True if the group could be deleted, false otherwise.
*/
bool SupportsDelete() const override { return false; }

/*!
* @brief Check whether members could be added to this group by the user.
* @return True if members could be added, false otherwise.
*/
bool SupportsMemberAdd() const override { return true; }

/*!
* @brief Check whether members could be removed from this group by the user.
* @return True if members could be removed, false otherwise.
*/
bool SupportsMemberRemove() const override { return true; }

/*!
* @brief Check whether this group is owner of the channel instances it contains.
* @return True if owner, false otherwise.
Expand All @@ -85,11 +103,5 @@ class CPVRChannelGroupAllChannels : public CPVRChannelGroupFromUser
* @return True on success, false otherwise.
*/
bool UpdateFromClients(const std::vector<std::shared_ptr<CPVRClient>>& clients) override;

private:
/*!
* @brief Return the type of this group.
*/
int GroupType() const override { return PVR_GROUP_TYPE_ALL_CHANNELS; }
};
} // namespace PVR
75 changes: 75 additions & 0 deletions xbmc/pvr/channels/PVRChannelGroupFactory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2024 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 "PVRChannelGroupFactory.h"

#include "pvr/channels/PVRChannelGroupAllChannels.h"
#include "pvr/channels/PVRChannelGroupFromClient.h"
#include "pvr/channels/PVRChannelGroupFromUser.h"
#include "pvr/channels/PVRChannelsPath.h"
#include "utils/log.h"

using namespace PVR;

std::shared_ptr<CPVRChannelGroup> CPVRChannelGroupFactory::CreateAllChannelsGroup(bool isRadio)
{
return std::make_shared<CPVRChannelGroupAllChannels>(isRadio);
}

std::shared_ptr<CPVRChannelGroup> CPVRChannelGroupFactory::CreateClientGroup(
const PVR_CHANNEL_GROUP& groupData,
int clientID,
const std::shared_ptr<const CPVRChannelGroup>& allChannels)
{
return std::make_shared<CPVRChannelGroupFromClient>(groupData, clientID, allChannels);
}

std::shared_ptr<CPVRChannelGroup> CPVRChannelGroupFactory::CreateUserGroup(
bool isRadio,
const std::string& name,
const std::shared_ptr<const CPVRChannelGroup>& allChannels)
{
return std::make_shared<CPVRChannelGroupFromUser>(
CPVRChannelsPath{isRadio, name, PVR_GROUP_CLIENT_ID_LOCAL}, allChannels);
}

std::shared_ptr<CPVRChannelGroup> CPVRChannelGroupFactory::CreateGroup(
int groupType,
const CPVRChannelsPath& groupPath,
const std::shared_ptr<const CPVRChannelGroup>& allChannels)
{
switch (groupType)
{
case PVR_GROUP_TYPE_SYSTEM_ALL_CHANNELS:
return std::make_shared<CPVRChannelGroupAllChannels>(groupPath);
case PVR_GROUP_TYPE_USER:
return std::make_shared<CPVRChannelGroupFromUser>(groupPath, allChannels);
case PVR_GROUP_TYPE_CLIENT:
return std::make_shared<CPVRChannelGroupFromClient>(groupPath, allChannels);
default:
CLog::LogFC(LOGERROR, LOGPVR, "Cannot create channel group '{}'. Unknown type {}.",
groupPath.GetGroupName(), groupType);
return {};
}
}

int CPVRChannelGroupFactory::GetGroupTypePriority(
const std::shared_ptr<const CPVRChannelGroup>& group) const
{
switch (group->GroupType())
{
case PVR_GROUP_TYPE_SYSTEM_ALL_CHANNELS:
return 0; // highest
case PVR_GROUP_TYPE_USER:
return 1;
case PVR_GROUP_TYPE_CLIENT:
return 2;
default:
return 3;
}
}
77 changes: 77 additions & 0 deletions xbmc/pvr/channels/PVRChannelGroupFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2024 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 <memory>

struct PVR_CHANNEL_GROUP;

namespace PVR
{

class CPVRChannelGroup;
class CPVRChannelsPath;

class CPVRChannelGroupFactory
{
public:
CPVRChannelGroupFactory() = default;
virtual ~CPVRChannelGroupFactory() = default;

/*!
* @brief Create an all channels group instance.
* @param isRadio Whether Radio or TV.
* @return The new group.
*/
std::shared_ptr<CPVRChannelGroup> CreateAllChannelsGroup(bool isRadio);

/*!
* @brief Create an instance for a group provided by a PVR client add-on.
* @param groupData The group data.
* @param clientID The id of the client that provided the group.
* @param allChannels The all channels group.
* @return The new group.
*/
std::shared_ptr<CPVRChannelGroup> CreateClientGroup(
const PVR_CHANNEL_GROUP& groupData,
int clientID,
const std::shared_ptr<const CPVRChannelGroup>& allChannels);

/*!
* @brief Create an instance for a group created by the user.
* @param isRadio Whether Radio or TV.
* @param name The name for the group.
* @param allChannels The all channels group.
* @return The new group.
*/
std::shared_ptr<CPVRChannelGroup> CreateUserGroup(
bool isRadio,
const std::string& name,
const std::shared_ptr<const CPVRChannelGroup>& allChannels);

/*!
* @brief Create a channel group matching the given type.
* @param groupType The type of the group.
* @param groupPath The path of the group.
* @param allChannels The all channels group.
* @return The new group.
*/
std::shared_ptr<CPVRChannelGroup> CreateGroup(
int groupType,
const CPVRChannelsPath& groupPath,
const std::shared_ptr<const CPVRChannelGroup>& allChannels);

/*!
* @brief Get the priority (e.g. for sorting groups) for the type of the given group. Lower number means higer priority.
* @param group The group.
* @return The group's type priority.
*/
int GetGroupTypePriority(const std::shared_ptr<const CPVRChannelGroup>& group) const;
};
} // namespace PVR
17 changes: 11 additions & 6 deletions xbmc/pvr/channels/PVRChannelGroupFromClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ class CPVRChannelGroupFromClient : public CPVRChannelGroup
int clientID,
const std::shared_ptr<const CPVRChannelGroup>& allChannelsGroup);

/*!
* @brief Get the group's origin.
* @return The origin.
*/
Origin GetOrigin() const override { return Origin::CLIENT; }

/*!
* @brief Return the type of this group.
*/
int GroupType() const override { return PVR_GROUP_TYPE_CLIENT; }

/*!
* @brief Check whether this group could be deleted by the user.
* @return True if the group could be deleted, false otherwise.
Expand Down Expand Up @@ -64,11 +75,5 @@ class CPVRChannelGroupFromClient : public CPVRChannelGroup
* @return True on success, false otherwise.
*/
bool UpdateFromClients(const std::vector<std::shared_ptr<CPVRClient>>& clients) override;

private:
/*!
* @brief Return the type of this group.
*/
int GroupType() const override { return PVR_GROUP_TYPE_REMOTE; }
};
} // namespace PVR
Loading

0 comments on commit 5069e47

Please sign in to comment.