Skip to content

Commit

Permalink
custom props v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ksooo committed Sep 2, 2024
1 parent d0122da commit aea5fa3
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 67 deletions.
58 changes: 29 additions & 29 deletions src/Tvheadend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ struct TimerType : kodi::addon::PVRTimerType
unsigned int id,
unsigned int attributes,
const std::string& description,
const std::vector<kodi::addon::PVRIntSettingDefinition>& customIntSettingDefs,
const std::vector<kodi::addon::PVRSettingDefinition>& customSettingDefs,
const std::vector<kodi::addon::PVRTypeIntValue>& priorityValues,
const std::vector<kodi::addon::PVRTypeIntValue>& lifetimeValues,
const std::vector<kodi::addon::PVRTypeIntValue>& dupEpisodesValues =
Expand All @@ -901,7 +901,7 @@ struct TimerType : kodi::addon::PVRTimerType
SetId(id);
SetAttributes(attributes);
SetDescription(description);
SetCustomIntSettingDefinitions(customIntSettingDefs);
SetCustomSettingDefinitions(customSettingDefs);
SetPriorities(priorityValues, settings->GetDvrPriority());
SetLifetimes(lifetimeValues, LifetimeMapper::TvhToKodi(settings->GetDvrLifetime()));
SetPreventDuplicateEpisodes(dupEpisodesValues, settings->GetDvrDupdetect());
Expand Down Expand Up @@ -1004,8 +1004,8 @@ PVR_ERROR CTvheadend::GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& type

/* Timer types definition. */

/* Custom integer setting definitions */
const std::vector<kodi::addon::PVRIntSettingDefinition> customIntSettingDefs{
/* Custom setting definitions */
const std::vector<kodi::addon::PVRSettingDefinition> customSettingDefs{
m_customTimerProps.GetSettingDefinitions()};

/* One-shot manual (time and channel based) */
Expand All @@ -1018,8 +1018,8 @@ PVR_ERROR CTvheadend::GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& type
TIMER_ONCE_MANUAL_ATTRIBS,
/* Let Kodi generate the description. */
"",
/* Custom int settings definitions. */
customIntSettingDefs,
/* Custom settings definitions. */
customSettingDefs,
/* Values definitions for priorities. */
priorityValues,
/* Values definitions for lifetime. */
Expand All @@ -1035,8 +1035,8 @@ PVR_ERROR CTvheadend::GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& type
TIMER_ONCE_EPG_ATTRIBS,
/* Let Kodi generate the description. */
"",
/* Custom int settings definitions. */
customIntSettingDefs,
/* Custom settings definitions. */
customSettingDefs,
/* Values definitions for priorities. */
priorityValues,
/* Values definitions for lifetime. */
Expand All @@ -1052,8 +1052,8 @@ PVR_ERROR CTvheadend::GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& type
TIMER_ONCE_MANUAL_ATTRIBS | PVR_TIMER_TYPE_FORBIDS_NEW_INSTANCES,
/* Description. */
kodi::addon::GetLocalizedString(30350), // "One Time (Scheduled by timer rule)"
/* Custom int settings definitions. */
customIntSettingDefs,
/* Custom settings definitions. */
customSettingDefs,
/* Values definitions for priorities. */
priorityValues,
/* Values definitions for lifetime. */
Expand All @@ -1069,16 +1069,16 @@ PVR_ERROR CTvheadend::GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& type
TIMER_ONCE_EPG_ATTRIBS | PVR_TIMER_TYPE_FORBIDS_NEW_INSTANCES,
/* Description. */
kodi::addon::GetLocalizedString(30350), // "One Time (Scheduled by timer rule)"
/* Custom int settings definitions. */
customIntSettingDefs,
/* Custom settings definitions. */
customSettingDefs,
/* Values definitions for priorities. */
priorityValues,
/* Values definitions for lifetime. */
lifetimeValues));

/* Custom Timerec integer setting definitions */
const std::vector<kodi::addon::PVRIntSettingDefinition> customTimeRecIntSettingDefs{
m_timeRecordings.GetCustomIntSettingDefinitions()};
/* Custom Timerec setting definitions */
const std::vector<kodi::addon::PVRSettingDefinition> customTimeRecSettingDefs{
m_timeRecordings.GetCustomSettingDefinitions()};

/* Repeating manual (time and channel based) - timerec */
types.emplace_back(TimerType(
Expand All @@ -1094,16 +1094,16 @@ PVR_ERROR CTvheadend::GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& type
PVR_TIMER_TYPE_SUPPORTS_LIFETIME | PVR_TIMER_TYPE_SUPPORTS_RECORDING_FOLDERS,
/* Let Kodi generate the description. */
"",
/* Custom int settings definitions. */
customTimeRecIntSettingDefs,
/* Custom settings definitions. */
customTimeRecSettingDefs,
/* Values definitions for priorities. */
priorityValues,
/* Values definitions for lifetime. */
lifetimeValues));

/* Custom Autorec integer setting definitions */
const std::vector<kodi::addon::PVRIntSettingDefinition> customAutoRecIntSettingDefs{
m_autoRecordings.GetCustomIntSettingDefinitions()};
const std::vector<kodi::addon::PVRSettingDefinition> customAutoRecSettingDefs{
m_autoRecordings.GetCustomSettingDefinitions()};

if (m_conn->GetProtocol() >= 29)
{
Expand Down Expand Up @@ -1132,8 +1132,8 @@ PVR_ERROR CTvheadend::GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& type
TIMER_REPEATING_SERIESLINK_ATTRIBS,
/* Description. */
kodi::addon::GetLocalizedString(30369), // "Timer rule (series link)"
/* Custom int settings definitions. */
customAutoRecIntSettingDefs,
/* Custom settings definitions. */
customAutoRecSettingDefs,
/* Values definitions for priorities. */
priorityValues,
/* Values definitions for lifetime. */
Expand Down Expand Up @@ -1166,8 +1166,8 @@ PVR_ERROR CTvheadend::GetTimerTypes(std::vector<kodi::addon::PVRTimerType>& type
TIMER_REPEATING_EPG_ATTRIBS,
/* Let Kodi generate the description. */
"",
/* Custom int settings definitions. */
customAutoRecIntSettingDefs,
/* Custom settings definitions. */
customAutoRecSettingDefs,
/* Values definitions for priorities. */
priorityValues,
/* Values definitions for lifetime. */
Expand Down Expand Up @@ -1228,8 +1228,8 @@ bool CTvheadend::CreateTimer(const Recording& tvhTmr, kodi::addon::PVRTimer& tmr
? m_autoRecordings.GetTimerIntIdFromStringId(tvhTmr.GetAutorecId())
: 0);

/* Custom integer props */
tmr.SetCustomIntProperties(m_customTimerProps.GetProperties(tvhTmr));
/* Custom props */
tmr.SetCustomProperties(m_customTimerProps.GetProperties(tvhTmr));

return true;
}
Expand Down Expand Up @@ -1314,8 +1314,8 @@ PVR_ERROR CTvheadend::AddTimer(const kodi::addon::PVRTimer& timer)
LifetimeMapper::KodiToTvh(timer.GetLifetime())); // remove from disk
htsmsg_add_u32(m, "priority", timer.GetPriority());

/* Custom integer props. */
m_customTimerProps.AppendPropertiesToHTSPMessage(timer.GetCustomIntProperties(), m);
/* Custom props. */
m_customTimerProps.AppendPropertiesToHTSPMessage(timer.GetCustomProperties(), m);

/* Send and Wait */
{
Expand Down Expand Up @@ -1450,8 +1450,8 @@ PVR_ERROR CTvheadend::UpdateTimer(const kodi::addon::PVRTimer& timer)
LifetimeMapper::KodiToTvh(timer.GetLifetime())); // remove from disk
htsmsg_add_u32(m, "priority", timer.GetPriority());

/* Custom integer props. */
m_customTimerProps.AppendPropertiesToHTSPMessage(timer.GetCustomIntProperties(), m);
/* Custom props. */
m_customTimerProps.AppendPropertiesToHTSPMessage(timer.GetCustomProperties(), m);

return SendDvrUpdate(m);
}
Expand Down
12 changes: 6 additions & 6 deletions src/tvheadend/AutoRecordings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ void AutoRecordings::GetAutorecTimers(std::vector<kodi::addon::PVRTimer>& timers
tmr.SetFullTextEpgSearch(rec.second.GetFulltext());
tmr.SetParentClientIndex(0);

/* Custom integer props. */
tmr.SetCustomIntProperties(m_customTimerProps.GetProperties(rec.second));
/* Custom props. */
tmr.SetCustomProperties(m_customTimerProps.GetProperties(rec.second));

timers.emplace_back(std::move(tmr));
}
Expand Down Expand Up @@ -141,8 +141,8 @@ const std::string AutoRecordings::GetTimerStringIdFromIntId(unsigned int intId)
return "";
}

const std::vector<kodi::addon::PVRIntSettingDefinition> AutoRecordings::
GetCustomIntSettingDefinitions() const
const std::vector<kodi::addon::PVRSettingDefinition> AutoRecordings::GetCustomSettingDefinitions()
const
{
return m_customTimerProps.GetSettingDefinitions();
}
Expand Down Expand Up @@ -273,8 +273,8 @@ PVR_ERROR AutoRecordings::SendAutorecAddOrUpdate(const kodi::addon::PVRTimer& ti
if (timer.GetTimerType() == TIMER_REPEATING_SERIESLINK)
htsmsg_add_str(m, "serieslinkUri", timer.GetSeriesLink().c_str());

/* Custom integer props. */
m_customTimerProps.AppendPropertiesToHTSPMessage(timer.GetCustomIntProperties(), m);
/* Custom props. */
m_customTimerProps.AppendPropertiesToHTSPMessage(timer.GetCustomProperties(), m);

/* Send and Wait */
{
Expand Down
2 changes: 1 addition & 1 deletion src/tvheadend/AutoRecordings.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AutoRecordings
int GetAutorecTimerCount() const;
void GetAutorecTimers(std::vector<kodi::addon::PVRTimer>& timers);
const unsigned int GetTimerIntIdFromStringId(const std::string& strId) const;
const std::vector<kodi::addon::PVRIntSettingDefinition> GetCustomIntSettingDefinitions() const;
const std::vector<kodi::addon::PVRSettingDefinition> GetCustomSettingDefinitions() const;

/* client to server messages */
PVR_ERROR SendAutorecAdd(const kodi::addon::PVRTimer& timer);
Expand Down
36 changes: 20 additions & 16 deletions src/tvheadend/CustomTimerProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ CustomTimerProperties::CustomTimerProperties(const std::vector<unsigned int>& pr
{
}

std::vector<kodi::addon::PVRIntKeyValuePair> CustomTimerProperties::GetProperties(
std::vector<kodi::addon::PVRSettingKeyValuePair> CustomTimerProperties::GetProperties(
const tvheadend::entity::Recording& rec) const
{
std::vector<kodi::addon::PVRIntKeyValuePair> customProps;
std::vector<kodi::addon::PVRSettingKeyValuePair> customProps;
for (unsigned int propId : m_propIds)
{
switch (propId)
Expand All @@ -55,10 +55,10 @@ std::vector<kodi::addon::PVRIntKeyValuePair> CustomTimerProperties::GetPropertie
return customProps;
}

std::vector<kodi::addon::PVRIntKeyValuePair> CustomTimerProperties::GetProperties(
std::vector<kodi::addon::PVRSettingKeyValuePair> CustomTimerProperties::GetProperties(
const tvheadend::entity::AutoRecording& autorec) const
{
std::vector<kodi::addon::PVRIntKeyValuePair> customProps;
std::vector<kodi::addon::PVRSettingKeyValuePair> customProps;
for (unsigned int propId : m_propIds)
{
switch (propId)
Expand Down Expand Up @@ -90,10 +90,10 @@ std::vector<kodi::addon::PVRIntKeyValuePair> CustomTimerProperties::GetPropertie
return customProps;
}

std::vector<kodi::addon::PVRIntKeyValuePair> CustomTimerProperties::GetProperties(
std::vector<kodi::addon::PVRSettingKeyValuePair> CustomTimerProperties::GetProperties(
const tvheadend::entity::TimeRecording& timerec) const
{
std::vector<kodi::addon::PVRIntKeyValuePair> customProps;
std::vector<kodi::addon::PVRSettingKeyValuePair> customProps;
for (unsigned int propId : m_propIds)
{
switch (propId)
Expand All @@ -117,10 +117,10 @@ std::vector<kodi::addon::PVRIntKeyValuePair> CustomTimerProperties::GetPropertie
return customProps;
}

const std::vector<kodi::addon::PVRIntSettingDefinition> CustomTimerProperties::
GetSettingDefinitions() const
const std::vector<kodi::addon::PVRSettingDefinition> CustomTimerProperties::GetSettingDefinitions()
const
{
std::vector<kodi::addon::PVRIntSettingDefinition> ret;
std::vector<kodi::addon::PVRSettingDefinition> ret;

for (unsigned int propId : m_propIds)
{
Expand Down Expand Up @@ -221,7 +221,7 @@ const std::vector<kodi::addon::PVRTypeIntValue> CustomTimerProperties::GetPossib
}

void CustomTimerProperties::AppendPropertiesToHTSPMessage(
const std::vector<kodi::addon::PVRIntKeyValuePair>& props, htsmsg_t* msg) const
const std::vector<kodi::addon::PVRSettingKeyValuePair>& props, htsmsg_t* msg) const
{
for (const auto& prop : props)
{
Expand All @@ -230,15 +230,15 @@ void CustomTimerProperties::AppendPropertiesToHTSPMessage(
case CUSTOM_PROP_ID_AUTOREC_BROADCASTTYPE:
{
/* Broadcast type */
htsmsg_add_u32(msg, "broadcastType", prop.GetValue());
htsmsg_add_u32(msg, "broadcastType", prop.GetIntValue());
break;
}
case CUSTOM_PROP_ID_DVR_CONFIGURATION:
{
/* DVR configuration */
for (const auto& config : m_dvrConfigs)
{
if (config.GetId() == prop.GetValue())
if (config.GetId() == prop.GetIntValue())
{
htsmsg_add_str(msg, "configName", config.GetUuid().c_str());
break;
Expand Down Expand Up @@ -266,18 +266,22 @@ int CustomTimerProperties::GetDvrConfigurationId(const std::string& uuid) const
return -1;
}

kodi::addon::PVRIntSettingDefinition CustomTimerProperties::CreateSettingDefinition(
kodi::addon::PVRSettingDefinition CustomTimerProperties::CreateSettingDefinition(
unsigned int settingId,
int resourceId,
const std::vector<kodi::addon::PVRTypeIntValue>& values,
int defaultValue,
uint64_t readonlyConditions) const
{
kodi::addon::PVRIntSettingDefinition settingDef;
kodi::addon::PVRSettingDefinition settingDef;
settingDef.SetId(settingId);
settingDef.SetName(kodi::addon::GetLocalizedString(resourceId));
settingDef.SetValues(std::move(values));
settingDef.SetDefaultValue(defaultValue);
settingDef.SetReadonlyConditions(readonlyConditions);

kodi::addon::PVRIntSettingDefinition intSettingDef;
intSettingDef.SetValues(std::move(values));
intSettingDef.SetDefaultValue(defaultValue);

settingDef.SetIntDefinition(intSettingDef);
return settingDef;
}
16 changes: 8 additions & 8 deletions src/tvheadend/CustomTimerProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ extern "C"

namespace kodi::addon
{
class PVRIntKeyValuePair;
class PVRSettingDefinition;
class PVRSettingKeyValuePair;
class PVRTypeIntValue;
class PVRIntSettingDefinition;
} // namespace kodi::addon

namespace tvheadend
Expand All @@ -47,28 +47,28 @@ class CustomTimerProperties
virtual ~CustomTimerProperties() = default;

// Custom props for all one-shot timers
std::vector<kodi::addon::PVRIntKeyValuePair> GetProperties(
std::vector<kodi::addon::PVRSettingKeyValuePair> GetProperties(
const tvheadend::entity::Recording& rec) const;

// Custom props for Autorecs
std::vector<kodi::addon::PVRIntKeyValuePair> GetProperties(
std::vector<kodi::addon::PVRSettingKeyValuePair> GetProperties(
const tvheadend::entity::AutoRecording& autorec) const;

// Custom props for Timerecs
std::vector<kodi::addon::PVRIntKeyValuePair> GetProperties(
std::vector<kodi::addon::PVRSettingKeyValuePair> GetProperties(
const tvheadend::entity::TimeRecording& timerec) const;

// Setting definitions
const std::vector<kodi::addon::PVRIntSettingDefinition> GetSettingDefinitions() const;
const std::vector<kodi::addon::PVRSettingDefinition> GetSettingDefinitions() const;

// Append given props to given HTSP message
void AppendPropertiesToHTSPMessage(const std::vector<kodi::addon::PVRIntKeyValuePair>& props,
void AppendPropertiesToHTSPMessage(const std::vector<kodi::addon::PVRSettingKeyValuePair>& props,
htsmsg_t* msg) const;

private:
const std::vector<kodi::addon::PVRTypeIntValue> GetPossibleValues(unsigned int propId,
int& defaultValue) const;
kodi::addon::PVRIntSettingDefinition CreateSettingDefinition(
kodi::addon::PVRSettingDefinition CreateSettingDefinition(
unsigned int settingId,
int resourceId,
const std::vector<kodi::addon::PVRTypeIntValue>& values,
Expand Down
12 changes: 6 additions & 6 deletions src/tvheadend/TimeRecordings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void TimeRecordings::GetTimerecTimers(std::vector<kodi::addon::PVRTimer>& timers
tmr.SetFullTextEpgSearch(false); // n/a for manual timers
tmr.SetParentClientIndex(0);

/* Custom integer props. */
tmr.SetCustomIntProperties(m_customTimerProps.GetProperties(rec.second));
/* Custom props. */
tmr.SetCustomProperties(m_customTimerProps.GetProperties(rec.second));

timers.emplace_back(std::move(tmr));
}
Expand Down Expand Up @@ -114,8 +114,8 @@ const std::string TimeRecordings::GetTimerStringIdFromIntId(unsigned int intId)
return "";
}

const std::vector<kodi::addon::PVRIntSettingDefinition> TimeRecordings::
GetCustomIntSettingDefinitions() const
const std::vector<kodi::addon::PVRSettingDefinition> TimeRecordings::GetCustomSettingDefinitions()
const
{
return m_customTimerProps.GetSettingDefinitions();
}
Expand Down Expand Up @@ -175,8 +175,8 @@ PVR_ERROR TimeRecordings::SendTimerecAddOrUpdate(const kodi::addon::PVRTimer& ti
if (timer.GetDirectory() != "/")
htsmsg_add_str(m, "directory", timer.GetDirectory().c_str());

/* Custom integer props. */
m_customTimerProps.AppendPropertiesToHTSPMessage(timer.GetCustomIntProperties(), m);
/* Custom props. */
m_customTimerProps.AppendPropertiesToHTSPMessage(timer.GetCustomProperties(), m);

/* Send and Wait */
{
Expand Down
2 changes: 1 addition & 1 deletion src/tvheadend/TimeRecordings.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TimeRecordings
int GetTimerecTimerCount() const;
void GetTimerecTimers(std::vector<kodi::addon::PVRTimer>& timers);
const unsigned int GetTimerIntIdFromStringId(const std::string& strId) const;
const std::vector<kodi::addon::PVRIntSettingDefinition> GetCustomIntSettingDefinitions() const;
const std::vector<kodi::addon::PVRSettingDefinition> GetCustomSettingDefinitions() const;

/* client to server messages */
PVR_ERROR SendTimerecAdd(const kodi::addon::PVRTimer& timer);
Expand Down

0 comments on commit aea5fa3

Please sign in to comment.