Permalink
Browse files

Add groundwork for enhanced recording rule filters.

This change adds some of the capabilities of custom recording rules to
normal rules.  This is very convenient as the desire to use common
filters no longers requires having to create custom rules.  In
addition, the filter scheme is extensible so that new filters can be
easily added without code changes.

IMPORTANT NOTE: There is no UI support for the new filters in this
commit.  Someone else has graciously volunteered to help with that and
it will be added in a future commit.  Adding the core and database
changes now makes cooperating on the UI work easier.

IMPORTANT NOTE 2: The 6 filters included in this change are intended
for testing purposes only at this time.  The actual filters and
associated ids are subject to change before the final commit for this
feature.  IOW, don't use them for anything important unless you are
prepared to manually fix your recording rules later.
  • Loading branch information...
1 parent a2a32e6 commit e0122d89a08d8210d22d3368ebc4b0e7a128a2ae @gigem gigem committed Jun 5, 2011
Showing with 47 additions and 2 deletions.
  1. +29 −1 mythtv/libs/libmythtv/dbcheck.cpp
  2. +18 −1 mythtv/programs/mythbackend/scheduler.cpp
@@ -21,7 +21,7 @@ using namespace std;
mythtv/bindings/perl/MythTV.pm
*/
/// This is the DB schema version expected by the running MythTV instance.
-const QString currentDatabaseVersion = "1276";
+const QString currentDatabaseVersion = "1277";
static bool UpdateDBVersionNumber(const QString &newnumber, QString &dbver);
static bool performActualUpdate(
@@ -5717,6 +5717,34 @@ NULL
return false;
}
+ if (dbver == "1276")
+ {
+ const char *updates[] = {
+"ALTER TABLE record ADD COLUMN filter INT UNSIGNED NOT NULL DEFAULT 0;",
+"CREATE TABLE IF NOT EXISTS recordfilter ("
+" filterid INT UNSIGNED NOT NULL PRIMARY KEY,"
+" description VARCHAR(64) DEFAULT NULL,"
+" clause VARCHAR(256) DEFAULT NULL,"
+" newruledefault TINYINT(1) DEFAULT 0);",
+"INSERT INTO recordfilter (filterid, description, clause, newruledefault) "
+" VALUES (0, 'New episode', 'program.previouslyshown = 0', 0);",
+"INSERT INTO recordfilter (filterid, description, clause, newruledefault) "
+" VALUES (1, 'Identifiable episode', 'program.generic = 0', 0);",
+"INSERT INTO recordfilter (filterid, description, clause, newruledefault) "
+" VALUES (2, 'First showing', 'program.first > 0', 0);",
+"INSERT INTO recordfilter (filterid, description, clause, newruledefault) "
+" VALUES (3, 'Primetime', 'HOUR(program.starttime) >= 19 AND HOUR(program.starttime) < 23', 0);",
+"INSERT INTO recordfilter (filterid, description, clause, newruledefault) "
+" VALUES (4, 'Commercial free', 'channel.commmethod = -2', 0);",
+"INSERT INTO recordfilter (filterid, description, clause, newruledefault) "
+" VALUES (5, 'High definition', 'program.hdtv > 0', 0);",
+NULL
+};
+
+ if (!performActualUpdate(updates, "1277", dbver))
+ return false;
+ }
+
return true;
}
@@ -3224,6 +3224,21 @@ void Scheduler::UpdateMatches(int recordid) {
return;
}
+ QString filterClause;
+ query.prepare("SELECT filterid, clause FROM recordfilter "
+ "WHERE filterid >= 0 AND filterid < 12 AND "
+ " TRIM(clause) <> ''");
+ if (!query.exec())
+ {
+ MythDB::DBError("UpdateMatches", query);
+ return;
+ }
+ while (query.next())
+ {
+ filterClause += QString(" AND (((RECTABLE.filter & %1) = 0) OR (%2))")
+ .arg(1 << query.value(0).toInt()).arg(query.value(1).toString());
+ }
+
// Make sure all FindOne rules have a valid findid before scheduling.
query.prepare("SELECT NULL from record "
"WHERE type = :FINDONE AND findid <= 0;");
@@ -3275,7 +3290,9 @@ void Scheduler::UpdateMatches(int recordid) {
" AND (NOT ((RECTABLE.dupin & %3) AND (program.previouslyshown "
" OR program.first = 0))) ")
.arg(kDupsExRepeats).arg(kDupsExGeneric).arg(kDupsFirstNew) +
- QString(" AND channel.visible = 1 AND "
+ QString(" AND channel.visible = 1 ") +
+ filterClause + QString(" AND "
+
"((RECTABLE.type = %1 " // allrecord
"OR RECTABLE.type = %2 " // findonerecord
"OR RECTABLE.type = %3 " // finddailyrecord

0 comments on commit e0122d8

Please sign in to comment.