Skip to content

Commit

Permalink
[PVR][video] Rework 'reset resume point' implementation; make it work…
Browse files Browse the repository at this point in the history
… also for PVR recordings.
  • Loading branch information
ksooo authored and razzeee committed Sep 6, 2017
1 parent d924076 commit 5e81a2d
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 10 deletions.
20 changes: 19 additions & 1 deletion xbmc/pvr/recordings/PVRRecordings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ bool CPVRRecordings::ChangeRecordingsPlayCount(const CFileItemPtr &item, int cou
items.Add(item);

CLog::Log(LOGDEBUG, "CPVRRecordings - %s - will set watched for %d items", __FUNCTION__, items.Size());
for (int i=0;i<items.Size();++i)
for (int i = 0; i < items.Size(); ++i)
{
CLog::Log(LOGDEBUG, "CPVRRecordings - %s - setting watched for item %d", __FUNCTION__, i);

Expand Down Expand Up @@ -576,3 +576,21 @@ bool CPVRRecordings::MarkWatched(const CFileItemPtr &item, bool bWatched)
else
return SetRecordingsPlayCount(item, 0);
}

bool CPVRRecordings::ResetResumePoint(const CFileItemPtr item)
{
bool bResult = false;

const CPVRRecordingPtr recording = item->GetPVRRecordingInfoTag();
if (recording && m_database.IsOpen())
{
bResult = true;

m_database.ClearBookMarksOfFile(item->GetPath(), CBookmark::RESUME);
recording->SetResumePoint(CBookmark());

CServiceBroker::GetPVRManager().PublishEvent(RecordingsInvalidated);
}

return bResult;
}
10 changes: 9 additions & 1 deletion xbmc/pvr/recordings/PVRRecordings.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,26 @@ namespace PVR
bool HasDeletedRadioRecordings() const;

/**
* Deletes the item in question, be it a directory or a file
* @brief Deletes the item in question, be it a directory or a file
* @param item the item to delete
* @return whether the item was deleted successfully
*/
bool Delete(const CFileItem &item);

bool Undelete(const CFileItem &item);
bool DeleteAllRecordingsFromTrash();
bool RenameRecording(CFileItem &item, std::string &strNewName);
bool SetRecordingsPlayCount(const CFileItemPtr &item, int count);
bool IncrementRecordingsPlayCount(const CFileItemPtr &item);
bool MarkWatched(const CFileItemPtr &item, bool bWatched);

/**
* @brief Resets a recording's resume point, if any
* @param item The item to process
* @return True, if the item's resume point was reset successfully, false otherwise
*/
bool ResetResumePoint(const CFileItemPtr item);

bool GetDirectory(const std::string& strPath, CFileItemList &items);
CFileItemPtr GetByPath(const std::string &path);
CPVRRecordingPtr GetById(int iClientId, const std::string &strRecordingId) const;
Expand Down
7 changes: 1 addition & 6 deletions xbmc/video/ContextMenus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ bool CRemoveResumePoint::IsVisible(const CFileItem& itemIn) const

bool CRemoveResumePoint::Execute(const CFileItemPtr& item) const
{
CVideoDatabase videoDatabase;
if (videoDatabase.Open())
{
videoDatabase.DeleteResumeBookMark(*item);
}

CVideoLibraryQueue::GetInstance().ResetResumePoint(item);
return true;
}

Expand Down
9 changes: 9 additions & 0 deletions xbmc/video/VideoLibraryQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "video/jobs/VideoLibraryJob.h"
#include "video/jobs/VideoLibraryMarkWatchedJob.h"
#include "video/jobs/VideoLibraryRefreshingJob.h"
#include "video/jobs/VideoLibraryResetResumePointJob.h"
#include "video/jobs/VideoLibraryScanningJob.h"

CVideoLibraryQueue::CVideoLibraryQueue()
Expand Down Expand Up @@ -153,6 +154,14 @@ void CVideoLibraryQueue::MarkAsWatched(const CFileItemPtr &item, bool watched)
AddJob(new CVideoLibraryMarkWatchedJob(item, watched));
}

void CVideoLibraryQueue::ResetResumePoint(const CFileItemPtr item)
{
if (item == nullptr)
return;

AddJob(new CVideoLibraryResetResumePointJob(item));
}

void CVideoLibraryQueue::AddJob(CVideoLibraryJob *job)
{
if (job == NULL)
Expand Down
7 changes: 7 additions & 0 deletions xbmc/video/VideoLibraryQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ class CVideoLibraryQueue : protected CJobQueue
*/
void MarkAsWatched(const CFileItemPtr &item, bool watched);

/*!
\brief Queue a reset resume point job.
\param[in] item Item to reset the resume point for
*/
void ResetResumePoint(const CFileItemPtr item);

/*!
\brief Adds the given job to the queue.
Expand Down
6 changes: 4 additions & 2 deletions xbmc/video/jobs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ set(SOURCES VideoLibraryCleaningJob.cpp
VideoLibraryMarkWatchedJob.cpp
VideoLibraryProgressJob.cpp
VideoLibraryRefreshingJob.cpp
VideoLibraryScanningJob.cpp)
VideoLibraryScanningJob.cpp
VideoLibraryResetResumePointJob.cpp)

set(HEADERS VideoLibraryCleaningJob.h
VideoLibraryJob.h
VideoLibraryMarkWatchedJob.h
VideoLibraryProgressJob.h
VideoLibraryRefreshingJob.h
VideoLibraryScanningJob.h)
VideoLibraryScanningJob.h
VideoLibraryResetResumePointJob.h)

core_add_library(video_jobs)
47 changes: 47 additions & 0 deletions xbmc/video/jobs/VideoLibraryResetResumePointJob.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once
/*
* Copyright (C) 2017 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "FileItem.h"
#include "video/jobs/VideoLibraryJob.h"

/*!
\brief Video library job implementation for resetting a resume point.
*/
class CVideoLibraryResetResumePointJob : public CVideoLibraryJob
{
public:
/*!
\brief Creates a new job for resetting a given item's resume point.
\param[in] item Item for that the resume point shall be reset.
*/
CVideoLibraryResetResumePointJob(const CFileItemPtr item);
~CVideoLibraryResetResumePointJob() override = default;

const char *GetType() const override { return "CVideoLibraryResetResumePointJob"; }
bool operator==(const CJob* job) const override;

protected:
bool Work(CVideoDatabase &db) override;

private:
CFileItemPtr m_item;
};
94 changes: 94 additions & 0 deletions xbmc/video/jobs/VideoLibraryResetResumepointJob.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (C) 2017 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "VideoLibraryResetResumePointJob.h"

#include <vector>

#include "FileItem.h"
#include "ServiceBroker.h"
#include "Util.h"
#include "filesystem/IDirectory.h"
#ifdef HAS_UPNP
#include "network/upnp/UPnP.h"
#endif
#include "profiles/ProfilesManager.h"
#include "pvr/PVRManager.h"
#include "pvr/recordings/PVRRecordings.h"
#include "utils/URIUtils.h"
#include "video/VideoDatabase.h"

CVideoLibraryResetResumePointJob::CVideoLibraryResetResumePointJob(const CFileItemPtr item)
: m_item(item)
{
}

bool CVideoLibraryResetResumePointJob::operator==(const CJob* job) const
{
if (strcmp(job->GetType(), GetType()) != 0)
return false;

const CVideoLibraryResetResumePointJob* resetJob = dynamic_cast<const CVideoLibraryResetResumePointJob*>(job);
if (!resetJob)
return false;

return m_item->IsSamePath(resetJob->m_item.get());
}

bool CVideoLibraryResetResumePointJob::Work(CVideoDatabase &db)
{
if (!CProfilesManager::GetInstance().GetCurrentProfile().canWriteDatabases())
return false;

CFileItemList items;
items.Add(std::make_shared<CFileItem>(*m_item));

if (m_item->m_bIsFolder)
CUtil::GetRecursiveListing(m_item->GetPath(), items, "", XFILE::DIR_FLAG_NO_FILE_INFO);

std::vector<CFileItemPtr> resetItems;
for (const auto& item : items)
{
#ifdef HAS_UPNP
if (URIUtils::IsUPnP(item->GetPath()) && UPNP::CUPnP::SaveFileState(*item, CBookmark(), false /* updatePlayCount */))
continue;
#endif

if (item->HasPVRRecordingInfoTag() && CServiceBroker::GetPVRManager().Recordings()->ResetResumePoint(item))
continue;

resetItems.emplace_back(item);
}

if (resetItems.empty())
return true;

db.BeginTransaction();

for (const auto& resetItem : resetItems)
{
db.DeleteResumeBookMark(*resetItem);
}

db.CommitTransaction();
db.Close();

return true;
}

0 comments on commit 5e81a2d

Please sign in to comment.