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] Show resume indicator for recordings + some cleanups #1452

Merged
merged 3 commits into from Oct 1, 2012
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
18 changes: 18 additions & 0 deletions addons/skin.confluence/720p/ViewsPVR.xml
Expand Up @@ -678,6 +678,15 @@
<width>20</width>
<height>16</height>
<texture>$INFO[ListItem.Overlay]</texture>
<visible>!ListItem.IsResumable</visible>
</control>
<control type="image">
<posx>730</posx>
<posy>14</posy>
<width>16</width>
<height>16</height>
<texture>OverlayWatching.png</texture>
<visible>ListItem.IsResumable</visible>
</control>
</itemlayout>
<focusedlayout height="40" width="760">
Expand Down Expand Up @@ -744,6 +753,15 @@
<width>20</width>
<height>16</height>
<texture>$INFO[ListItem.Overlay]</texture>
<visible>!ListItem.IsResumable</visible>
</control>
<control type="image">
<posx>730</posx>
<posy>14</posy>
<width>16</width>
<height>16</height>
<texture>OverlayWatching.png</texture>
<visible>ListItem.IsResumable</visible>
</control>
</focusedlayout>
</control>
Expand Down
12 changes: 11 additions & 1 deletion xbmc/GUIInfoManager.cpp
Expand Up @@ -4154,6 +4154,8 @@ bool CGUIInfoManager::GetItemInt(int &value, const CGUIListItem *item, int info)
case LISTITEM_PERCENT_PLAYED:
if (item->IsFileItem() && ((const CFileItem *)item)->HasVideoInfoTag() && ((const CFileItem *)item)->GetVideoInfoTag()->m_resumePoint.IsPartWay())
value = (int)(100 * ((const CFileItem *)item)->GetVideoInfoTag()->m_resumePoint.timeInSeconds / ((const CFileItem *)item)->GetVideoInfoTag()->m_resumePoint.totalTimeInSeconds);
else if (item->IsFileItem() && ((const CFileItem *)item)->HasPVRRecordingInfoTag() && ((const CFileItem *)item)->GetPVRRecordingInfoTag()->m_resumePoint.IsPartWay())
value = (int)(100 * ((const CFileItem *)item)->GetPVRRecordingInfoTag()->m_resumePoint.timeInSeconds / ((const CFileItem *)item)->GetPVRRecordingInfoTag()->m_resumePoint.totalTimeInSeconds);
else
value = 0;
return true;
Expand Down Expand Up @@ -4886,7 +4888,15 @@ bool CGUIInfoManager::GetItemBool(const CGUIListItem *item, int condition) const
else if (condition == LISTITEM_IS_FOLDER)
return item->m_bIsFolder;
else if (condition == LISTITEM_IS_RESUMABLE)
return (item->IsFileItem() && ((const CFileItem *)item)->HasVideoInfoTag() && ((const CFileItem *)item)->GetVideoInfoTag()->m_resumePoint.timeInSeconds > 0);
{
if (item->IsFileItem())
{
if (((const CFileItem *)item)->HasVideoInfoTag())
return ((const CFileItem *)item)->GetVideoInfoTag()->m_resumePoint.timeInSeconds > 0;
else if (((const CFileItem *)item)->HasPVRRecordingInfoTag())
return ((const CFileItem *)item)->GetPVRRecordingInfoTag()->m_resumePoint.timeInSeconds > 0;
}
}
else if (item->IsFileItem())
{
const CFileItem *pItem = (const CFileItem *)item;
Expand Down
5 changes: 0 additions & 5 deletions xbmc/cores/dvdplayer/DVDPlayer.cpp
Expand Up @@ -1961,11 +1961,6 @@ void CDVDPlayer::OnExit()
}
m_pSubtitleDemuxer = NULL;

if (m_pInputStream->IsStreamType(DVDSTREAM_TYPE_PVRMANAGER) && g_PVRManager.IsPlayingRecording())
{
g_PVRManager.UpdateCurrentLastPlayedPosition(m_State.time / 1000);
}

// destroy the inputstream
if (m_pInputStream)
{
Expand Down
41 changes: 0 additions & 41 deletions xbmc/pvr/PVRManager.cpp
Expand Up @@ -887,47 +887,6 @@ bool CPVRManager::UpdateItem(CFileItem& item)
return false;
}


bool CPVRManager::UpdateCurrentLastPlayedPosition(int lastplayedposition)
{
// Only anything but recordings we fake success
if (!IsPlayingRecording())
return true;

bool rc = false;
CPVRRecording currentRecording;

if (m_addons)
{
PVR_ERROR error;
rc = m_addons->GetPlayingRecording(currentRecording) && m_addons->SetRecordingLastPlayedPosition(currentRecording, lastplayedposition, &error);
}
return rc;
}

bool CPVRManager::SetRecordingLastPlayedPosition(const CPVRRecording &recording, int lastplayedposition)
{
bool rc = false;

if (m_addons)
{
PVR_ERROR error;
rc = m_addons->SetRecordingLastPlayedPosition(recording, lastplayedposition, &error);
}
return rc;
}

int CPVRManager::GetRecordingLastPlayedPosition(const CPVRRecording &recording)
{
int rc = 0;

if (m_addons)
{
rc = m_addons->GetRecordingLastPlayedPosition(recording);
}
return rc;
}

bool CPVRManager::StartPlayback(const CPVRChannel *channel, bool bPreview /* = false */)
{
g_settings.m_bStartVideoWindowed = bPreview;
Expand Down
21 changes: 0 additions & 21 deletions xbmc/pvr/PVRManager.h
Expand Up @@ -447,27 +447,6 @@ namespace PVR
*/
bool SetWakeupCommand(void);

/*!
* @brief Update the last played position for the current playing file
* @param lastplayedposition channel The channel to start to play.
*/
bool UpdateCurrentLastPlayedPosition(int lastplayedposition);

/*!
* @brief Set the last watched position of a recording on the backend.
* @param recording The recording.
* @param position The last watched position in seconds
* @return True if the last played position was updated successfully, false otherwise
*/
bool SetRecordingLastPlayedPosition(const CPVRRecording &recording, int lastplayedposition);

/*!
* @brief Retrieve the last watched position of a recording on the backend.
* @param recording The recording.
* @return The last watched position in seconds
*/
int GetRecordingLastPlayedPosition(const CPVRRecording &recording);

protected:
/*!
* @brief PVR update and control thread.
Expand Down
30 changes: 30 additions & 0 deletions xbmc/pvr/recordings/PVRRecording.cpp
Expand Up @@ -131,6 +131,7 @@ bool CPVRRecording::Rename(const CStdString &strNewName)
bool CPVRRecording::SetPlayCount(int count)
{
PVR_ERROR error;
m_playCount = count;
m_iRecPlayCount = count;
if (g_PVRClients->SupportsRecordingPlayCount(m_iClientId) &&
!g_PVRClients->SetRecordingPlayCount(*this, count, &error))
Expand All @@ -142,6 +143,35 @@ bool CPVRRecording::SetPlayCount(int count)
return true;
}

bool CPVRRecording::IncrementPlayCount()
{
return SetPlayCount(m_iRecPlayCount + 1);
}

bool CPVRRecording::SetLastPlayedPosition(int lastplayedposition)
{
PVR_ERROR error;
if (g_PVRClients->SupportsRecordingPlayCount(m_iClientId) &&
!g_PVRClients->SetRecordingLastPlayedPosition(*this, lastplayedposition, &error))
{
DisplayError(error);
return false;
}
return true;
}

int CPVRRecording::GetLastPlayedPosition() const
{
int rc = 0;
if (g_PVRClients->SupportsRecordingPlayCount(m_iClientId))
{
rc = g_PVRClients->GetRecordingLastPlayedPosition(*this);
if (rc < 0)
DisplayError(PVR_ERROR_SERVER_ERROR);
}
return rc;
}

void CPVRRecording::DisplayError(PVR_ERROR err) const
{
if (err == PVR_ERROR_SERVER_ERROR)
Expand Down
19 changes: 19 additions & 0 deletions xbmc/pvr/recordings/PVRRecording.h
Expand Up @@ -92,6 +92,25 @@ namespace PVR
*/
bool SetPlayCount(int count);

/*!
* @brief Increment this recording's play count on the client (if supported).
* @return True if play count was set successfully, false otherwise.
*/
bool IncrementPlayCount();

/*!
* @brief Set the last watched position of a recording on the backend.
* @param position The last watched position in seconds
* @return True if the last played position was updated successfully, false otherwise
*/
bool SetLastPlayedPosition(int lastplayedposition);

/*!
* @brief Retrieve the last watched position of a recording on the backend.
* @return The last watched position in seconds
*/
int GetLastPlayedPosition() const;

/*!
* @brief Update this tag with the contents of the given tag.
* @param tag The new tag info.
Expand Down
25 changes: 25 additions & 0 deletions xbmc/pvr/recordings/PVRRecordings.cpp
Expand Up @@ -121,6 +121,28 @@ void CPVRRecordings::GetContents(const CStdString &strDirectory, CFileItemList *
}
pFileItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_UNWATCHED, pFileItem->GetPVRRecordingInfoTag()->m_playCount > 0);

// Set the resumePoint either directly from client (if supported) or from video db
int positionInSeconds = current->GetLastPlayedPosition();
if (positionInSeconds > 0)
{
// If the back-end does report a saved position then make sure there is a corresponding resume bookmark
CBookmark bookmark;
bookmark.timeInSeconds = positionInSeconds;
bookmark.totalTimeInSeconds = (double)current->GetDuration();
pFileItem->GetPVRRecordingInfoTag()->m_resumePoint = bookmark;
}
else if (positionInSeconds < 0)
{
CVideoDatabase db;
if (db.Open())
{
CBookmark bookmark;
if (db.GetResumeBookMark(current->m_strFileNameAndPath, bookmark))
pFileItem->GetPVRRecordingInfoTag()->m_resumePoint = bookmark;
db.Close();
}
}

results->Add(pFileItem);
}
}
Expand Down Expand Up @@ -391,7 +413,10 @@ bool CPVRRecordings::SetRecordingsPlayCount(const CFileItemPtr &item, int count)

// Clear resume bookmark
if (count > 0)
{
database.ClearBookMarksOfFile(pItem->GetPath(), CBookmark::RESUME);
pItem->GetPVRRecordingInfoTag()->SetLastPlayedPosition(0);
}

database.SetPlayCount(*pItem, count);
}
Expand Down
4 changes: 2 additions & 2 deletions xbmc/pvr/windows/GUIWindowPVRRecordings.cpp
Expand Up @@ -67,13 +67,13 @@ CStdString CGUIWindowPVRRecordings::GetResumeString(const CFileItem& item)
{

// First try to find the resume position on the back-end, if that fails use video database
CPVRRecording recording = *item.GetPVRRecordingInfoTag();
int positionInSeconds = g_PVRManager.GetRecordingLastPlayedPosition(recording);
int positionInSeconds = item.GetPVRRecordingInfoTag()->GetLastPlayedPosition();
// If the back-end does report a saved position then make sure there is a corresponding resume bookmark
if (positionInSeconds > 0)
{
CBookmark bookmark;
bookmark.timeInSeconds = positionInSeconds;
bookmark.totalTimeInSeconds = (double)item.GetPVRRecordingInfoTag()->GetDuration();
CVideoDatabase db;
if (db.Open())
{
Expand Down
16 changes: 16 additions & 0 deletions xbmc/utils/SaveFileStateJob.h
Expand Up @@ -4,6 +4,8 @@

#include "Job.h"
#include "FileItem.h"
#include "pvr/PVRManager.h"
#include "pvr/recordings/PVRRecordings.h"

class CSaveFileStateJob : public CJob
{
Expand Down Expand Up @@ -57,6 +59,11 @@ bool CSaveFileStateJob::DoWork()
// consider this item as played
videodatabase.IncrementPlayCount(m_item);
m_item.GetVideoInfoTag()->m_playCount++;

// PVR: Set recording's play count on the backend (if supported)
if (m_item.HasPVRRecordingInfoTag())
m_item.GetPVRRecordingInfoTag()->IncrementPlayCount();

m_item.SetOverlayImage(CGUIListItem::ICON_OVERLAY_UNWATCHED, true);
updateListing = true;
}
Expand All @@ -71,6 +78,15 @@ bool CSaveFileStateJob::DoWork()
videodatabase.AddBookMarkToFile(progressTrackingFile, m_bookmark, CBookmark::RESUME);
if (m_item.HasVideoInfoTag())
m_item.GetVideoInfoTag()->m_resumePoint = m_bookmark;

// PVR: Set/clear recording's resume bookmark on the backend (if supported)
if (m_item.HasPVRRecordingInfoTag())
{
PVR::CPVRRecording *recording = m_item.GetPVRRecordingInfoTag();
recording->SetLastPlayedPosition(m_bookmark.timeInSeconds <= 0.0f ? 0 : (int)m_bookmark.timeInSeconds);
recording->m_resumePoint = m_bookmark;
}

updateListing = true;
}
}
Expand Down
7 changes: 0 additions & 7 deletions xbmc/video/VideoDatabase.cpp
Expand Up @@ -51,8 +51,6 @@
#include "dbwrappers/dataset.h"
#include "utils/LabelFormatter.h"
#include "XBDateTime.h"
#include "pvr/PVRManager.h"
#include "pvr/recordings/PVRRecordings.h"
#include "URL.h"
#include "video/VideoDbUrl.h"
#include "playlists/SmartPlayList.h"
Expand All @@ -62,7 +60,6 @@ using namespace dbiplus;
using namespace XFILE;
using namespace VIDEO;
using namespace ADDON;
using namespace PVR;

//********************************************************************************************************************************
CVideoDatabase::CVideoDatabase(void)
Expand Down Expand Up @@ -4328,10 +4325,6 @@ void CVideoDatabase::SetPlayCount(const CFileItem &item, int count, const CDateT

m_pDS->exec(strSQL.c_str());

// PVR: Set recording's play count on the backend (if supported)
if (item.HasPVRRecordingInfoTag() && g_PVRManager.IsStarted())
g_PVRRecordings->SetPlayCount(item, count);

// We only need to announce changes to video items in the library
if (item.HasVideoInfoTag() && item.GetVideoInfoTag()->m_iDbId > 0)
{
Expand Down