Skip to content

Commit

Permalink
Rework recording rule handling in services API.
Browse files Browse the repository at this point in the history
Thanks to tafy/dev-team%40tikinou.com providing the initial patch and
testing the end result.

The existing AddRecordSchedule() and new UpdateRecordSchedule() calls
essentially take complete, fully-specified rules and sanity check them
before saving.  AddRecordSchedule() is used to add new rules and
UpdateRecordSchedule() is used to update existing rules.

GetRecordSchedule() is changed to conveniently provide rules suitable
for later calls to AddRecordSchedule() and UpdateRecordSchedule().
When given a valid RecordId, GetRecordSchedule() returns that rule.
When given a Template name, GetRecordSchedule() returns an empty rule
initialized with that template.  When given a ChanId and StartTime,
GetRecordSchedule() returns the rule for that program or a new one if
no rule currently exists.  If the MakeOverride parameter is true, the
returned rule for the program will converted to an override rule if
needed.

Clients should always call GetRecordSchedule() with the appropriate
parameters before modifying the rule and then calling
AddRecordSchedule() or UpdateRecordSchedule().  In this way, clients
do not need to know all of the details on how to initialize rules or
update them for specific programs.

Fixes #11495
  • Loading branch information
gigem committed May 1, 2013
1 parent 7d9c51e commit 2865936
Show file tree
Hide file tree
Showing 8 changed files with 564 additions and 70 deletions.
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythversion.h
Expand Up @@ -12,7 +12,7 @@
/// Update this whenever the plug-in ABI changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods in exported headers.
#define MYTH_BINARY_VERSION "0.27.20130426-1"
#define MYTH_BINARY_VERSION "0.27.20130430-1"

/** \brief Increment this whenever the MythTV network protocol changes.
*
Expand Down
21 changes: 8 additions & 13 deletions mythtv/libs/libmythservicecontracts/datacontracts/recRule.h
Expand Up @@ -15,7 +15,7 @@ namespace DTC
class SERVICE_PUBLIC RecRule : public QObject
{
Q_OBJECT
Q_CLASSINFO( "version" , "1.10" );
Q_CLASSINFO( "version" , "1.11" );

Q_PROPERTY( int Id READ Id WRITE setId )
Q_PROPERTY( int ParentId READ ParentId WRITE setParentId )
Expand All @@ -36,10 +36,8 @@ class SERVICE_PUBLIC RecRule : public QObject

Q_PROPERTY( int ChanId READ ChanId WRITE setChanId )
Q_PROPERTY( QString CallSign READ CallSign WRITE setCallSign )
Q_PROPERTY( int Day READ Day WRITE setDay )
Q_PROPERTY( QTime Time READ Time WRITE setTime )
Q_PROPERTY( int FindId READ FindId WRITE setFindId )

Q_PROPERTY( int FindDay READ FindDay WRITE setFindDay )
Q_PROPERTY( QTime FindTime READ FindTime WRITE setFindTime )
Q_PROPERTY( QString Type READ Type WRITE setType )
Q_PROPERTY( QString SearchType READ SearchType WRITE setSearchType )
Q_PROPERTY( int RecPriority READ RecPriority WRITE setRecPriority )
Expand Down Expand Up @@ -89,9 +87,8 @@ class SERVICE_PUBLIC RecRule : public QObject
PROPERTYIMP ( QString , Inetref )
PROPERTYIMP ( int , ChanId )
PROPERTYIMP ( QString , CallSign )
PROPERTYIMP ( int , Day )
PROPERTYIMP ( QTime , Time )
PROPERTYIMP ( int , FindId )
PROPERTYIMP ( int , FindDay )
PROPERTYIMP ( QTime , FindTime )
PROPERTYIMP ( QString , Type )
PROPERTYIMP ( QString , SearchType )
PROPERTYIMP ( int , RecPriority )
Expand Down Expand Up @@ -135,8 +132,7 @@ class SERVICE_PUBLIC RecRule : public QObject
m_Season ( 0 ),
m_Episode ( 0 ),
m_ChanId ( 0 ),
m_Day ( 0 ),
m_FindId ( 0 ),
m_FindDay ( 0 ),
m_RecPriority ( 0 ),
m_PreferredInput( 0 ),
m_StartOffset ( 0 ),
Expand Down Expand Up @@ -180,9 +176,8 @@ class SERVICE_PUBLIC RecRule : public QObject
m_Inetref = src.m_Inetref ;
m_ChanId = src.m_ChanId ;
m_CallSign = src.m_CallSign ;
m_Day = src.m_Day ;
m_Time = src.m_Time ;
m_FindId = src.m_FindId ;
m_FindDay = src.m_FindDay ;
m_FindTime = src.m_FindTime ;
m_Type = src.m_Type ;
m_SearchType = src.m_SearchType ;
m_RecPriority = src.m_RecPriority ;
Expand Down
64 changes: 60 additions & 4 deletions mythtv/libs/libmythservicecontracts/services/dvrServices.h
Expand Up @@ -38,12 +38,13 @@
class SERVICE_PUBLIC DvrServices : public Service //, public QScriptable ???
{
Q_OBJECT
Q_CLASSINFO( "version" , "1.6" );
Q_CLASSINFO( "version" , "1.7" );
Q_CLASSINFO( "RemoveRecordedItem_Method", "POST" )
Q_CLASSINFO( "AddRecordSchedule_Method", "POST" )
Q_CLASSINFO( "RemoveRecordSchedule_Method", "POST" )
Q_CLASSINFO( "EnableRecordSchedule_Method", "POST" )
Q_CLASSINFO( "DisableRecordSchedule_Method", "POST" )
Q_CLASSINFO( "UpdateRecordSchedule_Method", "POST" )

public:

Expand Down Expand Up @@ -94,14 +95,65 @@ class SERVICE_PUBLIC DvrServices : public Service //, public QScriptable ???

// Recording Rules

virtual int AddRecordSchedule ( int ChanId,
virtual int AddRecordSchedule ( QString Title,
QString Subtitle,
QString Description,
QString Category,
QDateTime StartTime,
QDateTime EndTime,
QString SeriesId,
QString ProgramId,
int ChanId,
QString Station,
int FindDay,
QTime FindTime,
int ParentId,
bool Inactive,
uint Season,
uint Episode,
QString Inetref,
int FindId,
QString Type,
QString SearchType,
int RecPriority,
uint PreferredInput,
int StartOffset,
int EndOffset,
QString DupMethod,
QString DupIn,
uint Filter,
QString RecProfile,
QString RecGroup,
QString StorageGroup,
QString PlayGroup,
bool AutoExpire,
int MaxEpisodes,
bool MaxNewest,
bool AutoCommflag,
bool AutoTranscode,
bool AutoMetaLookup,
bool AutoUserJob1,
bool AutoUserJob2,
bool AutoUserJob3,
bool AutoUserJob4,
int Transcoder ) = 0;

virtual bool UpdateRecordSchedule ( int RecordId,
QString Title,
QString Subtitle,
QString Description,
QString Category,
QDateTime StartTime,
QDateTime EndTime,
QString SeriesId,
QString ProgramId,
int ChanId,
QString Station,
int FindDay,
QTime FindTime,
bool Inactive,
uint Season,
uint Episode,
QString Inetref,
QString Type,
QString SearchType,
int RecPriority,
Expand Down Expand Up @@ -132,7 +184,11 @@ class SERVICE_PUBLIC DvrServices : public Service //, public QScriptable ???
virtual DTC::RecRuleList* GetRecordScheduleList ( int StartIndex,
int Count ) = 0;

virtual DTC::RecRule* GetRecordSchedule ( uint RecordId ) = 0;
virtual DTC::RecRule* GetRecordSchedule ( uint RecordId,
QString Template,
int ChanId,
QDateTime StartTime,
bool MakeOverride ) = 0;

virtual bool EnableRecordSchedule ( uint RecordId ) = 0;

Expand Down
176 changes: 176 additions & 0 deletions mythtv/libs/libmythtv/recordingrule.cpp
Expand Up @@ -812,3 +812,179 @@ QStringList RecordingRule::GetTemplateNames(void)

return result;
}

bool RecordingRule::IsValid(QString &msg)
{
bool isOverride = false;
switch (m_type)
{
case kSingleRecord:
case kDailyRecord:
case kAllRecord:
case kWeeklyRecord:
case kOneRecord:
case kTemplateRecord:
break;
case kOverrideRecord:
case kDontRecord:
isOverride = true;
case kNotRecording:
default:
msg = QString("Invalid recording type.");
return false;
}

bool isNormal = false;
bool isSearch = false;
bool isManual = false;
switch (m_searchType)
{
case kNoSearch:
isNormal = true;
break;
case kPowerSearch:
case kTitleSearch:
case kKeywordSearch:
case kPeopleSearch:
isSearch = true;
break;
case kManualSearch:
isManual = true;
break;
default:
msg = QString("Invalid search type.");
return false;
}

if ((isNormal && (m_type == kDailyRecord || m_type == kWeeklyRecord)) ||
(isSearch && (m_type != kDailyRecord && m_type != kWeeklyRecord &&
m_type != kOneRecord && m_type != kAllRecord)) ||
(isManual && (m_type != kDailyRecord && m_type != kWeeklyRecord &&
m_type != kSingleRecord && m_type != kAllRecord)))
{
msg = QString("Invalid recording type/search type.");
return false;
}

if ((m_parentRecID && !isOverride) ||
(!m_parentRecID && isOverride))
{
msg = QString("Invalid parentID/override.");
return false;
}

if (m_title.isEmpty())
{
msg = QString("Invalid title.");
return false;
}

if (m_searchType == kPowerSearch)
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(QString("SELECT NULL FROM (program, channel) "
"%1 WHERE %2")
.arg(m_subtitle).arg(m_description));
if (m_description.contains(';') || !query.exec())
{
msg = QString("Invalid custom search values.");
return false;
}
}
else if (isSearch)
{
if (m_description.isEmpty())
{
msg = QString("Invalid search value.");
return false;
}
}

if (!isSearch)
{
if (!m_startdate.isValid() || !m_starttime.isValid() ||
!m_enddate.isValid() || !m_endtime.isValid())
{
msg = QString("Invalid start/end date/time.");
return false;
}
int secsto = QDateTime(m_startdate, m_starttime)
.secsTo(QDateTime(m_enddate, m_endtime));
if (secsto <= 0 || secsto > (8 * 3600))
{
msg = QString("Invalid duration.");
return false;
}

if (!m_channelid || m_station.isEmpty())
{
msg = QString("Invalid channel.");
return false;
}
}

if (m_findday < 0 || m_findday > 6 || !m_findtime.isValid())
{
msg = QString("Invalid find values.");
return false;
}

if (m_recPriority < -99 || m_recPriority > 99)
{
msg = QString("Invalid priority.");
return false;
}

if (m_startOffset < -480 || m_startOffset > 480 ||
m_endOffset < -480 || m_endOffset > 480)
{
msg = QString("Invalid start/end offset.");
return false;
}

if (m_prefInput < 0)
{
msg = QString("Invalid preferred input.");
return false;
}

if (m_filter & (~0 << kNumFilters))
{
msg = QString("Invalid filter value.");
return false;
}

if (m_recProfile.isEmpty() || m_recGroup.isEmpty() ||
m_storageGroup.isEmpty() || m_playGroup.isEmpty())
{
msg = QString("Invalid group value.");
return false;
}

if (m_maxEpisodes < 0)
{
msg = QString("Invalid max episodes value.");
return false;
}

if (m_dupIn & ~(kDupsInAll | kDupsNewEpi))
{
msg = QString("Invalid duplicate scope.");
return false;
}

if (m_dupMethod & ~(kDupCheckNone | kDupCheckSub |
kDupCheckDesc | kDupCheckSubThenDesc))
{
msg = QString("Invalid duplicate method.");
return false;
}

if (m_transcoder < 0)
{
msg = QString("Invalid transcoder value.");
return false;
}

return true;
}
2 changes: 2 additions & 0 deletions mythtv/libs/libmythtv/recordingrule.h
Expand Up @@ -59,6 +59,8 @@ class MTV_PUBLIC RecordingRule
AutoExpireType GetAutoExpire(void) const
{ return m_autoExpire ? kNormalAutoExpire : kDisableAutoExpire; }

bool IsValid(QString &text);

static QString SearchTypeToString(const RecSearchType searchType);
static QStringList GetTemplateNames(void);

Expand Down

0 comments on commit 2865936

Please sign in to comment.