From 5a028e37dcbca795f770a65810eda92f723213f9 Mon Sep 17 00:00:00 2001 From: ksooo <3226626+ksooo@users.noreply.github.com> Date: Sat, 31 Aug 2024 20:10:38 +0200 Subject: [PATCH] Make timers created by autorec and timerec editable. --- pvr.hts/changelog.txt | 1 + src/Tvheadend.cpp | 67 ++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/pvr.hts/changelog.txt b/pvr.hts/changelog.txt index 273b1d14..b71e3bf2 100644 --- a/pvr.hts/changelog.txt +++ b/pvr.hts/changelog.txt @@ -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+) diff --git a/src/Tvheadend.cpp b/src/Tvheadend.cpp index 9ecbd278..1af01fda 100644 --- a/src/Tvheadend.cpp +++ b/src/Tvheadend.cpp @@ -1043,14 +1043,14 @@ PVR_ERROR CTvheadend::GetTimerTypes(std::vector& 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. */ @@ -1060,14 +1060,14 @@ PVR_ERROR CTvheadend::GetTimerTypes(std::vector& 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. */ @@ -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"); @@ -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 */ @@ -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 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 */ @@ -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 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 */