Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PVR] Separate GUI from PVR core: remove CFileItem usage from core: step 1: directory listings. #16170

Merged
merged 1 commit into from May 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
109 changes: 11 additions & 98 deletions xbmc/filesystem/PVRDirectory.cpp
Expand Up @@ -6,19 +6,9 @@
* See LICENSES/README.md for more information.
*/

#include "FileItem.h"
#include "guilib/LocalizeStrings.h"
#include "PVRDirectory.h"
#include "ServiceBroker.h"
#include "URL.h"
#include "utils/log.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"

#include "pvr/PVRManager.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
#include "pvr/recordings/PVRRecordings.h"
#include "pvr/timers/PVRTimers.h"
#include "pvr/PVRGUIDirectory.h"

using namespace XFILE;
using namespace PVR;
Expand All @@ -29,115 +19,38 @@ CPVRDirectory::~CPVRDirectory() = default;

bool CPVRDirectory::Exists(const CURL& url)
{
if (!CServiceBroker::GetPVRManager().IsStarted())
return false;

return (url.IsProtocol("pvr") && StringUtils::StartsWith(url.GetFileName(), "recordings"));
const CPVRGUIDirectory dir(url);
return dir.Exists();
}

bool CPVRDirectory::GetDirectory(const CURL& url, CFileItemList &items)
{
std::string base(url.Get());
URIUtils::RemoveSlashAtEnd(base);

std::string fileName = url.GetFileName();
URIUtils::RemoveSlashAtEnd(fileName);
CLog::Log(LOGDEBUG, "CPVRDirectory::GetDirectory(%s)", base.c_str());
items.SetCacheToDisc(CFileItemList::CACHE_NEVER);

if (fileName == "")
{
if (CServiceBroker::GetPVRManager().IsStarted())
{
CFileItemPtr item;

item.reset(new CFileItem(base + "channels/", true));
item->SetLabel(g_localizeStrings.Get(19019));
item->SetLabelPreformatted(true);
items.Add(item);

item.reset(new CFileItem(base + "recordings/active/", true));
item->SetLabel(g_localizeStrings.Get(19017)); // TV Recordings
item->SetLabelPreformatted(true);
items.Add(item);

item.reset(new CFileItem(base + "recordings/deleted/", true));
item->SetLabel(g_localizeStrings.Get(19108)); // Deleted TV Recordings
item->SetLabelPreformatted(true);
items.Add(item);

// Sort by name only. Labels are preformatted.
items.AddSortMethod(SortByLabel, 551 /* Name */, LABEL_MASKS("%L", "", "%L", ""));
}
return true;
}
else if (StringUtils::StartsWith(fileName, "recordings"))
{
if (CServiceBroker::GetPVRManager().IsStarted())
{
const std::string pathToUrl(url.Get());
return CServiceBroker::GetPVRManager().Recordings()->GetDirectory(pathToUrl, items);
}
return true;
}
else if (StringUtils::StartsWith(fileName, "channels"))
{
if (CServiceBroker::GetPVRManager().ChannelGroups() && CServiceBroker::GetPVRManager().ChannelGroups()->Loaded())
{
const std::string pathToUrl(url.Get());
return CServiceBroker::GetPVRManager().ChannelGroups()->GetDirectory(pathToUrl, items);
}
return true;
}
else if (StringUtils::StartsWith(fileName, "timers"))
{
if (CServiceBroker::GetPVRManager().IsStarted())
{
const std::string pathToUrl(url.Get());
return CServiceBroker::GetPVRManager().Timers()->GetDirectory(pathToUrl, items);
}
return true;
}

return false;
const CPVRGUIDirectory dir(url);
return dir.GetDirectory(items);
}

bool CPVRDirectory::SupportsWriteFileOperations(const std::string& strPath)
{
CURL url(strPath);
std::string filename = url.GetFileName();

return URIUtils::IsPVRRecording(filename);
}

bool CPVRDirectory::IsLiveTV(const std::string& strPath)
{
CURL url(strPath);
std::string filename = url.GetFileName();

return URIUtils::IsLiveTV(filename);
const CPVRGUIDirectory dir(strPath);
return dir.SupportsWriteFileOperations();
}

bool CPVRDirectory::HasTVRecordings()
{
return CServiceBroker::GetPVRManager().IsStarted() ?
CServiceBroker::GetPVRManager().Recordings()->GetNumTVRecordings() > 0 : false;
return CPVRGUIDirectory::HasTVRecordings();
}

bool CPVRDirectory::HasDeletedTVRecordings()
{
return CServiceBroker::GetPVRManager().IsStarted() ?
CServiceBroker::GetPVRManager().Recordings()->HasDeletedTVRecordings() : false;
return CPVRGUIDirectory::HasDeletedTVRecordings();
}

bool CPVRDirectory::HasRadioRecordings()
{
return CServiceBroker::GetPVRManager().IsStarted() ?
CServiceBroker::GetPVRManager().Recordings()->GetNumRadioRecordings() > 0 : false;
return CPVRGUIDirectory::HasRadioRecordings();
}

bool CPVRDirectory::HasDeletedRadioRecordings()
{
return CServiceBroker::GetPVRManager().IsStarted() ?
CServiceBroker::GetPVRManager().Recordings()->HasDeletedRadioRecordings() : false;
return CPVRGUIDirectory::HasDeletedRadioRecordings();
}
4 changes: 1 addition & 3 deletions xbmc/filesystem/PVRDirectory.h
Expand Up @@ -10,8 +10,6 @@

#include "IDirectory.h"

class CPVRSession;

namespace XFILE {

class CPVRDirectory
Expand All @@ -27,7 +25,7 @@ class CPVRDirectory
bool Exists(const CURL& url) override;

static bool SupportsWriteFileOperations(const std::string& strPath);
static bool IsLiveTV(const std::string& strPath);

static bool HasTVRecordings();
static bool HasDeletedTVRecordings();
static bool HasRadioRecordings();
Expand Down
26 changes: 21 additions & 5 deletions xbmc/interfaces/json-rpc/PVROperations.cpp
Expand Up @@ -113,8 +113,11 @@ JSONRPC_STATUS CPVROperations::GetChannels(const std::string &method, ITransport
return InvalidParams;

CFileItemList channels;
if (channelGroup->GetMembers(channels) < 0)
return InvalidParams;
const std::vector<PVRChannelGroupMember> groupMembers = channelGroup->GetMembers(CPVRChannelGroup::Include::ONLY_VISIBLE);
for (const auto& groupMember : groupMembers)
{
channels.Add(std::make_shared<CFileItem>(groupMember.channel));
}

HandleFileItemList("channelid", false, "channels", channels, parameterObject, result, true);

Expand Down Expand Up @@ -280,7 +283,12 @@ void CPVROperations::FillChannelGroupDetails(const CPVRChannelGroupPtr &channelG
else
{
CFileItemList channels;
channelGroup->GetMembers(channels);
const std::vector<PVRChannelGroupMember> groupMembers = channelGroup->GetMembers(CPVRChannelGroup::Include::ONLY_VISIBLE);
for (const auto& groupMember : groupMembers)
{
channels.Add(std::make_shared<CFileItem>(groupMember.channel));
}

object["channels"] = CVariant(CVariant::VariantTypeArray);
HandleFileItemList("channelid", false, "channels", channels, parameterObject["channels"], object, false);

Expand All @@ -298,7 +306,11 @@ JSONRPC_STATUS CPVROperations::GetTimers(const std::string &method, ITransportLa
return FailedToExecute;

CFileItemList timerList;
timers->GetAll(timerList);
const std::vector<std::shared_ptr<CPVRTimerInfoTag>> tags = timers->GetAll();
for (const auto& timer : tags)
{
timerList.Add(std::make_shared<CFileItem>(timer));
}

HandleFileItemList("timerid", false, "timers", timerList, parameterObject, result, true);

Expand Down Expand Up @@ -413,7 +425,11 @@ JSONRPC_STATUS CPVROperations::GetRecordings(const std::string &method, ITranspo
return FailedToExecute;

CFileItemList recordingsList;
recordings->GetAll(recordingsList);
const std::vector<std::shared_ptr<CPVRRecording>> recs = recordings->GetAll();
for (const auto& recording : recs)
{
recordingsList.Add(std::make_shared<CFileItem>(recording));
}

HandleFileItemList("recordingid", true, "recordings", recordingsList, parameterObject, result, true);

Expand Down
2 changes: 2 additions & 0 deletions xbmc/pvr/CMakeLists.txt
Expand Up @@ -9,6 +9,7 @@ set(SOURCES PVRActionListener.cpp
PVRChannelNumberInputHandler.cpp
PVRJobs.cpp
PVRGUIChannelNavigator.cpp
PVRGUIDirectory.cpp
PVRGUIProgressHandler.cpp
PVRGUITimerInfo.cpp
PVRGUITimesInfo.cpp)
Expand All @@ -25,6 +26,7 @@ set(HEADERS PVRActionListener.h
PVRChannelNumberInputHandler.h
PVRJobs.h
PVRGUIChannelNavigator.h
PVRGUIDirectory.h
PVRGUIProgressHandler.h
PVRGUITimerInfo.h
PVRGUITimesInfo.h)
Expand Down