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

Add contextmenu option to remove resume points #12708

Merged
merged 2 commits into from
Sep 6, 2017
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
8 changes: 7 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -20656,7 +20656,13 @@ msgctxt "#38208"
msgid "If EXIF information exists (date, time, camera used, etc.), it will be displayed."
msgstr ""

#empty strings from id 38209 to 38999
#. Contextmenu entry to remove the resume point of the currently selected item
#: xbmc/video/ContextMenus.h
msgctxt "#38209"
msgid "Reset resume position"
msgstr ""

#empty strings from id 38210 to 38999

#: system/settings/settings.xml
msgctxt "#39000"
Expand Down
1 change: 1 addition & 0 deletions xbmc/ContextMenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void CContextMenuManager::Init()
std::make_shared<CONTEXTMENU::CSongInfo>(),
std::make_shared<CONTEXTMENU::CMarkWatched>(),
std::make_shared<CONTEXTMENU::CMarkUnWatched>(),
std::make_shared<CONTEXTMENU::CRemoveResumePoint>(),
std::make_shared<CONTEXTMENU::CEjectDisk>(),
std::make_shared<CONTEXTMENU::CEjectDrive>(),
std::make_shared<CONTEXTMENU::CRemoveFavourite>(),
Expand Down
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
15 changes: 15 additions & 0 deletions xbmc/video/ContextMenus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ bool CVideoInfo::Execute(const CFileItemPtr& item) const
return true;
}

bool CRemoveResumePoint::IsVisible(const CFileItem& itemIn) const
{
CFileItem item(itemIn.GetItemToPlay());
if (item.IsDeleted()) // e.g. trashed pvr recording
return false;

return CGUIWindowVideoBase::HasResumeItemOffset(&item);
}

bool CRemoveResumePoint::Execute(const CFileItemPtr& item) const
{
CVideoLibraryQueue::GetInstance().ResetResumePoint(item);
return true;
}

bool CMarkWatched::IsVisible(const CFileItem& item) const
{
if (item.IsDeleted()) // e.g. trashed pvr recording
Expand Down
7 changes: 7 additions & 0 deletions xbmc/video/ContextMenus.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ struct CMovieInfo : CVideoInfo
CMovieInfo() : CVideoInfo(MediaTypeMovie) {}
};

struct CRemoveResumePoint : CStaticContextMenuAction
{
CRemoveResumePoint() : CStaticContextMenuAction(38209) {}
bool IsVisible(const CFileItem& item) const override;
bool Execute(const CFileItemPtr& item) const override;
};

struct CMarkWatched : CStaticContextMenuAction
{
CMarkWatched() : CStaticContextMenuAction(16103) {}
Expand Down
32 changes: 29 additions & 3 deletions xbmc/video/VideoDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3066,23 +3066,49 @@ bool CVideoDatabase::GetResumeBookMark(const std::string& strFilenameAndPath, CB
return false;
}

void CVideoDatabase::DeleteResumeBookMark(const std::string &strFilenameAndPath)
void CVideoDatabase::DeleteResumeBookMark(const CFileItem& item)
{
if (!m_pDB.get() || !m_pDS.get())
return;

int fileID = GetFileId(strFilenameAndPath);
int fileID = item.GetVideoInfoTag()->m_iFileId;
if (fileID < -1)
return;

try
{
std::string sql = PrepareSQL("delete from bookmark where idFile=%i and type=%i", fileID, CBookmark::RESUME);
m_pDS->exec(sql);

VIDEODB_CONTENT_TYPE iType = static_cast<VIDEODB_CONTENT_TYPE>(item.GetVideoContentType());
std::string content;
switch (iType)
{
case VIDEODB_CONTENT_MOVIES:
content = MediaTypeMovie;
break;
case VIDEODB_CONTENT_EPISODES:
content = MediaTypeEpisode;
break;
case VIDEODB_CONTENT_TVSHOWS:
content = MediaTypeTvShow;
break;
case VIDEODB_CONTENT_MUSICVIDEOS:
content = MediaTypeMusicVideo;
break;
default:
break;
}

if (!content.empty())
{
AnnounceUpdate(content, item.GetVideoInfoTag()->m_iDbId);
}

}
catch(...)
{
CLog::Log(LOGERROR, "%s (%s) failed", __FUNCTION__, strFilenameAndPath.c_str());
CLog::Log(LOGERROR, "%s (%s) failed", __FUNCTION__, item.GetVideoInfoTag()->m_strFileNameAndPath.c_str());
}
}

Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/VideoDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ class CVideoDatabase : public CDatabase
void GetBookMarksForFile(const std::string& strFilenameAndPath, VECBOOKMARKS& bookmarks, CBookmark::EType type = CBookmark::STANDARD, bool bAppend=false, long partNumber=0);
void AddBookMarkToFile(const std::string& strFilenameAndPath, const CBookmark &bookmark, CBookmark::EType type = CBookmark::STANDARD);
bool GetResumeBookMark(const std::string& strFilenameAndPath, CBookmark &bookmark);
void DeleteResumeBookMark(const std::string &strFilenameAndPath);
void DeleteResumeBookMark(const CFileItem& item);
void ClearBookMarkOfFile(const std::string& strFilenameAndPath, CBookmark& bookmark, CBookmark::EType type = CBookmark::STANDARD);
void ClearBookMarksOfFile(const std::string& strFilenameAndPath, CBookmark::EType type = CBookmark::STANDARD);
void ClearBookMarksOfFile(int idFile, CBookmark::EType type = CBookmark::STANDARD);
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)
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;
}
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;
};