Skip to content

Commit

Permalink
Make timers created by autorec and timerec editable.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksooo committed Sep 6, 2024
1 parent 7b238c0 commit 5a028e3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
1 change: 1 addition & 0 deletions pvr.hts/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ v22.4.0
- Add support for Autorec property "Broadcast type" (HTSPv39+)
- Add support for DVR entry property "DVR configuration" (HTSPv40+)
- Add support for DVR entry property "Comment" (HTSPv42+)
- Make timers created by autorec and timerec editable

v22.3.0
- Add support for PVR Providers (HTSPv38+)
Expand Down
67 changes: 31 additions & 36 deletions src/Tvheadend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,14 +1043,14 @@ PVR_ERROR CTvheadend::GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& type
/* Values definitions for lifetime. */
lifetimeValues));

/* Read-only one-shot for timers generated by timerec */
/* One-shot for timers generated by timerec */
types.emplace_back(TimerType(
/* Settings */
m_settings,
/* Type id. */
TIMER_ONCE_CREATED_BY_TIMEREC,
/* Attributes. */
TIMER_ONCE_MANUAL_ATTRIBS | PVR_TIMER_TYPE_IS_READONLY | PVR_TIMER_TYPE_FORBIDS_NEW_INSTANCES,
TIMER_ONCE_MANUAL_ATTRIBS | PVR_TIMER_TYPE_FORBIDS_NEW_INSTANCES,
/* Description. */
kodi::addon::GetLocalizedString(30350), // "One Time (Scheduled by timer rule)"
/* Custom settings definitions. */
Expand All @@ -1060,14 +1060,14 @@ PVR_ERROR CTvheadend::GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& type
/* Values definitions for lifetime. */
lifetimeValues));

/* Read-only one-shot for timers generated by autorec */
/* One-shot for timers generated by autorec */
types.emplace_back(TimerType(
/* Settings */
m_settings,
/* Type id. */
TIMER_ONCE_CREATED_BY_AUTOREC,
/* Attributes. */
TIMER_ONCE_EPG_ATTRIBS | PVR_TIMER_TYPE_IS_READONLY | PVR_TIMER_TYPE_FORBIDS_NEW_INSTANCES,
TIMER_ONCE_EPG_ATTRIBS | PVR_TIMER_TYPE_FORBIDS_NEW_INSTANCES,
/* Description. */
kodi::addon::GetLocalizedString(30350), // "One Time (Scheduled by timer rule)"
/* Custom settings definitions. */
Expand Down Expand Up @@ -1373,7 +1373,9 @@ PVR_ERROR CTvheadend::DeleteTimer(const kodi::addon::PVRTimer& timer, bool)
}
}

if ((timer.GetTimerType() == TIMER_ONCE_MANUAL) || (timer.GetTimerType() == TIMER_ONCE_EPG))
if ((timer.GetTimerType() == TIMER_ONCE_MANUAL) || (timer.GetTimerType() == TIMER_ONCE_EPG) ||
(timer.GetTimerType() == TIMER_ONCE_CREATED_BY_TIMEREC) ||
(timer.GetTimerType() == TIMER_ONCE_CREATED_BY_AUTOREC))
{
/* one shot timer */
return SendDvrDelete(timer.GetClientIndex(), "cancelDvrEntry");
Expand All @@ -1389,13 +1391,6 @@ PVR_ERROR CTvheadend::DeleteTimer(const kodi::addon::PVRTimer& timer, bool)
/* EPG-query-based repeating timer */
return m_autoRecordings.SendAutorecDelete(timer);
}
else if ((timer.GetTimerType() == TIMER_ONCE_CREATED_BY_TIMEREC) ||
(timer.GetTimerType() == TIMER_ONCE_CREATED_BY_AUTOREC))
{
/* Read-only timer created by autorec or timerec */
Logger::Log(LogLevel::LEVEL_ERROR, "timer is read-only");
return PVR_ERROR_INVALID_PARAMETERS;
}
else
{
/* unknown timer */
Expand All @@ -1406,7 +1401,30 @@ PVR_ERROR CTvheadend::DeleteTimer(const kodi::addon::PVRTimer& timer, bool)

PVR_ERROR CTvheadend::UpdateTimer(const kodi::addon::PVRTimer& timer)
{
if ((timer.GetTimerType() == TIMER_ONCE_MANUAL) || (timer.GetTimerType() == TIMER_ONCE_EPG))
if ((timer.GetTimerType() == TIMER_ONCE_CREATED_BY_TIMEREC) ||
(timer.GetTimerType() == TIMER_ONCE_CREATED_BY_AUTOREC))
{
if (!m_asyncState.WaitForState(ASYNC_EPG))
return PVR_ERROR_FAILED;

/* Timer created by autorec or timerec */
std::lock_guard<std::recursive_mutex> lock(m_mutex);

const auto& it = m_recordings.find(timer.GetClientIndex());
if (it != m_recordings.end() &&
(it->second.IsEnabled() == (timer.GetState() == PVR_TIMER_STATE_DISABLED)))
{
/* This is actually a request to enable/disable a timer. */
htsmsg_t* m = htsmsg_create_map();
htsmsg_add_u32(m, "id", timer.GetClientIndex());
htsmsg_add_u32(m, "enabled", timer.GetState() == PVR_TIMER_STATE_DISABLED ? 0 : 1);
return SendDvrUpdate(m);
}
}

if ((timer.GetTimerType() == TIMER_ONCE_MANUAL) || (timer.GetTimerType() == TIMER_ONCE_EPG) ||
(timer.GetTimerType() == TIMER_ONCE_CREATED_BY_TIMEREC) ||
(timer.GetTimerType() == TIMER_ONCE_CREATED_BY_AUTOREC))
{
/* one shot timer */

Expand Down Expand Up @@ -1449,29 +1467,6 @@ PVR_ERROR CTvheadend::UpdateTimer(const kodi::addon::PVRTimer& timer)
/* EPG-query-based repeating timers */
return m_autoRecordings.SendAutorecUpdate(timer);
}
else if ((timer.GetTimerType() == TIMER_ONCE_CREATED_BY_TIMEREC) ||
(timer.GetTimerType() == TIMER_ONCE_CREATED_BY_AUTOREC))
{
if (!m_asyncState.WaitForState(ASYNC_EPG))
return PVR_ERROR_FAILED;

/* Read-only timer created by autorec or timerec */
std::lock_guard<std::recursive_mutex> lock(m_mutex);

const auto& it = m_recordings.find(timer.GetClientIndex());
if (it != m_recordings.end() &&
(it->second.IsEnabled() == (timer.GetState() == PVR_TIMER_STATE_DISABLED)))
{
/* This is actually a request to enable/disable a timer. */
htsmsg_t* m = htsmsg_create_map();
htsmsg_add_u32(m, "id", timer.GetClientIndex());
htsmsg_add_u32(m, "enabled", timer.GetState() == PVR_TIMER_STATE_DISABLED ? 0 : 1);
return SendDvrUpdate(m);
}

Logger::Log(LogLevel::LEVEL_ERROR, "timer is read-only");
return PVR_ERROR_INVALID_PARAMETERS;
}
else
{
/* unknown timer */
Expand Down

0 comments on commit 5a028e3

Please sign in to comment.