MythTV  0.26-pre
recordingrule.cpp
Go to the documentation of this file.
00001 
00002 #include "recordingrule.h"
00003 
00004 // libmythbase
00005 #include "mythdb.h"
00006 
00007 // libmyth
00008 #include "mythcorecontext.h"
00009 
00010 // libmythtv
00011 #include "scheduledrecording.h" // For RescheduleMatch()
00012 #include "playgroup.h" // For GetInitialName()
00013 #include "recordingprofile.h" // For constants
00014 #include "mythmiscutil.h"
00015 
00016 static inline QString null_to_empty(const QString &str)
00017 {
00018     return str.isEmpty() ? "" : str;
00019 }
00020 
00021 // If the GetNumSetting() calls here are ever removed, update schema
00022 // upgrade 1302 in dbcheck.cpp to manually apply them to the Default
00023 // template.  Failing to do so will cause users upgrading from older
00024 // versions to lose those settings.
00025 
00026 RecordingRule::RecordingRule()
00027   : m_recordID(-1), m_parentRecID(0),
00028     m_isInactive(false),
00029     m_season(0),
00030     m_episode(0),
00031     m_starttime(QTime::currentTime()),
00032     m_startdate(QDate::currentDate()),
00033     m_endtime(QTime::currentTime()),
00034     m_enddate(QDate::currentDate()),
00035     m_inetref(), // String could be null when we trying to insert into DB
00036     m_channelid(0),
00037     m_findday(-1),
00038     m_findtime(QTime::fromString("00:00:00", Qt::ISODate)),
00039     m_findid(QDate(1970, 1, 1).daysTo(QDate::currentDate()) + 719528),
00040     m_type(kNotRecording),
00041     m_searchType(kNoSearch),
00042     m_recPriority(0),
00043     m_prefInput(0),
00044     m_startOffset(gCoreContext->GetNumSetting("DefaultStartOffset", 0)),
00045     m_endOffset(gCoreContext->GetNumSetting("DefaultEndOffset", 0)),
00046     m_dupMethod(static_cast<RecordingDupMethodType>(
00047                 gCoreContext->GetNumSetting("prefDupMethod", kDupCheckSubDesc))),
00048     m_dupIn(kDupsInAll),
00049     m_filter(GetDefaultFilter()),
00050     m_recProfile(QObject::tr("Default")),
00051     m_recGroup("Default"),
00052     m_storageGroup("Default"),
00053     m_playGroup("Default"),
00054     m_autoExpire(gCoreContext->GetNumSetting("AutoExpireDefault", 0)),
00055     m_maxEpisodes(0),
00056     m_maxNewest(false),
00057     m_autoCommFlag(gCoreContext->GetNumSetting("AutoCommercialFlag", 1)),
00058     m_autoTranscode(gCoreContext->GetNumSetting("AutoTranscode", 0)),
00059     m_transcoder(gCoreContext->GetNumSetting("DefaultTranscoder",
00060                 RecordingProfile::TranscoderAutodetect)),
00061     m_autoUserJob1(gCoreContext->GetNumSetting("AutoRunUserJob1", 0)),
00062     m_autoUserJob2(gCoreContext->GetNumSetting("AutoRunUserJob2", 0)),
00063     m_autoUserJob3(gCoreContext->GetNumSetting("AutoRunUserJob3", 0)),
00064     m_autoUserJob4(gCoreContext->GetNumSetting("AutoRunUserJob4", 0)),
00065     m_autoMetadataLookup(gCoreContext->GetNumSetting("AutoMetadataLookup", 1)),
00066     m_nextRecording(QDateTime::fromString("0000-00-00T00:00:00", Qt::ISODate)),
00067     m_lastRecorded(QDateTime::fromString("0000-00-00T00:00:00", Qt::ISODate)),
00068     m_lastDeleted(QDateTime::fromString("0000-00-00T00:00:00", Qt::ISODate)),
00069     m_averageDelay(100),
00070     m_recordTable("record"),
00071     m_tempID(0),
00072     m_isOverride(false),
00073     m_isTemplate(false),
00074     m_template(),
00075     m_progInfo(NULL),
00076     m_loaded(false)
00077 {
00078 }
00079 
00080 bool RecordingRule::Load(bool asTemplate)
00081 {
00082     if (m_recordID <= 0)
00083         return false;
00084 
00085     MSqlQuery query(MSqlQuery::InitCon());
00086     query.prepare("SELECT type, search, "
00087     "recpriority, prefinput, startoffset, endoffset, dupmethod, dupin, "
00088     "inactive, profile, recgroup, storagegroup, playgroup, autoexpire, "
00089     "maxepisodes, maxnewest, autocommflag, autotranscode, transcoder, "
00090     "autouserjob1, autouserjob2, autouserjob3, autouserjob4, "
00091     "autometadata, parentid, title, subtitle, description, season, episode, "
00092     "category, starttime, startdate, endtime, enddate, seriesid, programid, "
00093     "inetref, chanid, station, findday, findtime, findid, "
00094     "next_record, last_record, last_delete, avg_delay, filter "
00095     "FROM record WHERE recordid = :RECORDID ;");
00096 
00097     query.bindValue(":RECORDID", m_recordID);
00098 
00099     if (!query.exec())
00100     {
00101         MythDB::DBError("SELECT record", query);
00102         return false;
00103     }
00104 
00105     if (!query.next())
00106         return false;
00107 
00108     // Schedule
00109     if (!asTemplate)
00110     {
00111         m_type = static_cast<RecordingType>(query.value(0).toInt());
00112         m_searchType = static_cast<RecSearchType>(query.value(1).toInt());
00113     }
00114     m_recPriority = query.value(2).toInt();
00115     m_prefInput = query.value(3).toInt();
00116     m_startOffset = query.value(4).toInt();
00117     m_endOffset = query.value(5).toInt();
00118     m_dupMethod = static_cast<RecordingDupMethodType>
00119         (query.value(6).toInt());
00120     m_dupIn = static_cast<RecordingDupInType>(query.value(7).toInt());
00121     m_filter = query.value(47).toUInt();
00122     m_isInactive = query.value(8).toBool();
00123 
00124     // Storage
00125     m_recProfile = query.value(9).toString();
00126     m_recGroup = query.value(10).toString();
00127     m_storageGroup = query.value(11).toString();
00128     m_playGroup = query.value(12).toString();
00129     m_autoExpire = query.value(13).toBool();
00130     m_maxEpisodes = query.value(14).toInt();
00131     m_maxNewest = query.value(15).toBool();
00132 
00133     // Post Process
00134     m_autoCommFlag = query.value(16).toBool();
00135     m_autoTranscode = query.value(17).toBool();
00136     m_transcoder = query.value(18).toInt();
00137     m_autoUserJob1 = query.value(19).toBool();
00138     m_autoUserJob2 = query.value(20).toBool();
00139     m_autoUserJob3 = query.value(21).toBool();
00140     m_autoUserJob4 = query.value(22).toBool();
00141     m_autoMetadataLookup = query.value(23).toBool();
00142 
00143     // Original rule id for override rule
00144     if (!asTemplate)
00145         m_parentRecID = query.value(24).toInt();
00146 
00147     // Recording metadata
00148     if (!asTemplate)
00149     {
00150         m_title = query.value(25).toString();
00151         m_subtitle = query.value(26).toString();
00152         m_description = query.value(27).toString();
00153         m_season = query.value(28).toUInt();
00154         m_episode = query.value(29).toUInt();
00155         m_category = query.value(30).toString();
00156         m_starttime = query.value(31).toTime();
00157         m_startdate = query.value(32).toDate();
00158         m_endtime = query.value(33).toTime();
00159         m_enddate = query.value(34).toDate();
00160         m_seriesid = query.value(35).toString();
00161         m_programid = query.value(36).toString();
00162         m_inetref = query.value(37).toString();
00163     }
00164 
00165     // Associated data for rule types
00166     if (!asTemplate)
00167     {
00168         m_channelid = query.value(38).toInt();
00169         m_station = query.value(39).toString();
00170         m_findday = query.value(40).toInt();
00171         m_findtime = query.value(41).toTime();
00172         m_findid = query.value(42).toInt();
00173     }
00174 
00175     // Statistic fields - Used to generate statistics about particular rules
00176     // and influence watch list weighting
00177     if (!asTemplate)
00178     {
00179         m_nextRecording = query.value(43).toDateTime();
00180         m_lastRecorded = query.value(44).toDateTime();
00181         m_lastDeleted = query.value(45).toDateTime();
00182         m_averageDelay = query.value(46).toInt();
00183     }
00184 
00185     m_isOverride = (m_type == kOverrideRecord || m_type == kDontRecord);
00186     m_isTemplate = (m_type == kTemplateRecord);
00187     m_template = (asTemplate || m_isTemplate) ? 
00188         query.value(30).toString() : "";
00189 
00190     if (!asTemplate)
00191         m_loaded = true;
00192 
00193     return true;
00194 }
00195 
00196 bool RecordingRule::LoadByProgram(const ProgramInfo* proginfo)
00197 {
00198     if (!proginfo)
00199         return false;
00200 
00201     m_progInfo = proginfo;
00202 
00203     m_recordID = proginfo->GetRecordingRuleID();
00204     if (m_recordID)
00205         Load();
00206     else
00207         LoadTemplate(proginfo->GetCategory(), proginfo->GetCategoryType());
00208 
00209     if (m_type != kTemplateRecord &&
00210         (m_searchType == kNoSearch || m_searchType == kManualSearch))
00211     {
00212         AssignProgramInfo();
00213         if (!proginfo->GetRecordingRuleID())
00214             m_playGroup = PlayGroup::GetInitialName(proginfo);
00215     }
00216 
00217     m_loaded = true;
00218     return true;
00219 }
00220 
00221 bool RecordingRule::LoadBySearch(RecSearchType lsearch, QString textname,
00222                                  QString forwhat, QString from)
00223 {
00224     MSqlQuery query(MSqlQuery::InitCon());
00225 
00226     int rid = 0;
00227     query.prepare("SELECT recordid FROM record WHERE "
00228                   "search = :SEARCH AND description LIKE :FORWHAT");
00229     query.bindValue(":SEARCH", lsearch);
00230     query.bindValue(":FORWHAT", forwhat);
00231 
00232     if (query.exec())
00233     {
00234         if (query.next())
00235             rid = query.value(0).toInt();
00236         // else rid is zero, which is valid, we're looking at a new rule
00237     }
00238     else
00239     {
00240         MythDB::DBError("loadBySearch", query);
00241         return false;
00242     }
00243 
00244     if (rid)
00245     {
00246         m_recordID = rid;
00247         if (!Load())
00248             return false;
00249     }
00250     else
00251     {
00252         LoadTemplate("Default");
00253 
00254         QString searchType;
00255         m_searchType = lsearch;
00256         searchType = SearchTypeToString(m_searchType);
00257 
00258         QString ltitle = QString("%1 (%2)").arg(textname).arg(searchType);
00259         m_title = ltitle;
00260         m_subtitle = from;
00261         m_description = forwhat;
00262         m_findday = (m_startdate.dayOfWeek() + 1) % 7;
00263         QDate epoch(1970, 1, 1);
00264         m_findid = epoch.daysTo(m_startdate) + 719528;
00265     }
00266 
00267     m_loaded = true;
00268     return true;
00269 }
00270 
00271 bool RecordingRule::LoadTemplate(QString category, QString categoryType)
00272 {
00273     MSqlQuery query(MSqlQuery::InitCon());
00274     query.prepare("SELECT recordid, category, "
00275                   "       (category = :CAT1) AS catmatch, "
00276                   "       (category = :CATTYPE1) AS typematch "
00277                   "FROM record "
00278                   "WHERE type = :TEMPLATE AND "
00279                   "      (category = :CAT2 OR category = :CATTYPE2 "
00280                   "       OR category = 'Default') "
00281                   "ORDER BY catmatch DESC, typematch DESC"
00282                   );
00283     query.bindValue(":TEMPLATE", kTemplateRecord);
00284     query.bindValue(":CAT1", category);
00285     query.bindValue(":CAT2", category);
00286     query.bindValue(":CATTYPE1", categoryType);
00287     query.bindValue(":CATTYPE2", categoryType);
00288 
00289     if (!query.exec())
00290     {
00291         MythDB::DBError("LoadByTemplate", query);
00292         return false;
00293     }
00294 
00295     if (!query.next())
00296         return false;
00297 
00298     int savedRecordID = m_recordID;
00299     m_recordID = query.value(0).toInt();
00300     bool result = Load(true);
00301     m_recordID = savedRecordID;
00302 
00303     return result;
00304 }
00305 
00306 bool RecordingRule::MakeTemplate(QString category)
00307 {
00308     if (m_recordID > 0)
00309         return false;
00310 
00311     if (category.compare(QObject::tr("Default"), Qt::CaseInsensitive) == 0)
00312     {
00313         category = "Default";
00314         m_title = QObject::tr("Default (Template)");
00315     }
00316     else
00317     {
00318         m_title = category + QObject::tr(" (Template)");
00319     }
00320 
00321     LoadTemplate(category);
00322     m_recordID = 0;
00323     m_type = kNotRecording;
00324     m_category = category;
00325     m_loaded = true;
00326     m_isTemplate = true;
00327 
00328     return true;
00329 }
00330 
00331 bool RecordingRule::ModifyPowerSearchByID(int rid, QString textname,
00332                                           QString forwhat, QString from)
00333 {
00334     if (rid <= 0)
00335         return false;
00336 
00337     m_recordID = rid;
00338     if (!Load() || m_searchType != kPowerSearch)
00339         return false;
00340 
00341     QString ltitle = QString("%1 (%2)").arg(textname)
00342                                        .arg(QObject::tr("Power Search"));
00343     m_title = ltitle;
00344     m_subtitle = from;
00345     m_description = forwhat;
00346 
00347     m_loaded = true;
00348     return true;
00349 }
00350 
00351 bool RecordingRule::MakeOverride(void)
00352 {
00353     if (m_recordID <= 0)
00354         return false;
00355 
00356     if (m_type == kOverrideRecord || m_type == kDontRecord)
00357         return false;
00358 
00359     m_isOverride = true;
00360     m_parentRecID = m_recordID;
00361     m_recordID = 0;
00362     m_type = kNotRecording;
00363     m_isInactive = 0;
00364 
00365     if (m_searchType != kManualSearch)
00366         m_searchType = kNoSearch;
00367 
00368     AssignProgramInfo();
00369 
00370     return true;
00371 }
00372 
00373 bool RecordingRule::Save(bool sendSig)
00374 {
00375     QString sql =   "SET type = :TYPE, search = :SEARCHTYPE, "
00376                     "recpriority = :RECPRIORITY, prefinput = :INPUT, "
00377                     "startoffset = :STARTOFFSET, endoffset = :ENDOFFSET, "
00378                     "dupmethod = :DUPMETHOD, dupin = :DUPIN, "
00379                     "filter = :FILTER, "
00380                     "inactive = :INACTIVE, profile = :RECPROFILE, "
00381                     "recgroup = :RECGROUP, storagegroup = :STORAGEGROUP, "
00382                     "playgroup = :PLAYGROUP, autoexpire = :AUTOEXPIRE, "
00383                     "maxepisodes = :MAXEPISODES, maxnewest = :MAXNEWEST, "
00384                     "autocommflag = :AUTOCOMMFLAG, "
00385                     "autotranscode = :AUTOTRANSCODE, "
00386                     "transcoder = :TRANSCODER, autouserjob1 = :AUTOUSERJOB1, "
00387                     "autouserjob2 = :AUTOUSERJOB2, "
00388                     "autouserjob3 = :AUTOUSERJOB3, "
00389                     "autouserjob4 = :AUTOUSERJOB4, "
00390                     "autometadata = :AUTOMETADATA, "
00391                     "parentid = :PARENTID, title = :TITLE, "
00392                     "subtitle = :SUBTITLE, season = :SEASON, episode = :EPISODE, "
00393                     "description = :DESCRIPTION, category = :CATEGORY, "
00394                     "starttime = :STARTTIME, startdate = :STARTDATE, "
00395                     "endtime = :ENDTIME, enddate = :ENDDATE, seriesid = :SERIESID, "
00396                     "programid = :PROGRAMID, inetref = :INETREF, chanid = :CHANID, "
00397                     "station = :STATION, findday = :FINDDAY, "
00398                     "findtime = :FINDTIME, findid = :FINDID, "
00399                     "next_record = :NEXTREC, last_record = :LASTREC, "
00400                     "last_delete = :LASTDELETE, avg_delay = :AVGDELAY ";
00401 
00402     QString sqlquery;
00403     if (m_recordID > 0 || (m_recordTable != "record" && m_tempID > 0))
00404         sqlquery = QString("UPDATE %1 %2 WHERE recordid = :RECORDID;")
00405                                                         .arg(m_recordTable).arg(sql);
00406     else
00407         sqlquery = QString("INSERT INTO %1 %2;").arg(m_recordTable).arg(sql);
00408 
00409     MSqlQuery query(MSqlQuery::InitCon());
00410     query.prepare(sqlquery);
00411     query.bindValue(":TYPE", m_type);
00412     query.bindValue(":SEARCHTYPE", m_searchType);
00413     query.bindValue(":RECPRIORITY", m_recPriority);
00414     query.bindValue(":INPUT", m_prefInput);
00415     query.bindValue(":STARTOFFSET",  m_startOffset);
00416     query.bindValue(":ENDOFFSET", m_endOffset);
00417     query.bindValue(":DUPMETHOD", m_dupMethod);
00418     query.bindValue(":DUPIN", m_dupIn);
00419     query.bindValue(":FILTER", m_filter);
00420     query.bindValue(":INACTIVE", m_isInactive);
00421     query.bindValue(":RECPROFILE", null_to_empty(m_recProfile));
00422     query.bindValue(":RECGROUP", null_to_empty(m_recGroup));
00423     query.bindValue(":STORAGEGROUP", null_to_empty(m_storageGroup));
00424     query.bindValue(":PLAYGROUP", null_to_empty(m_playGroup));
00425     query.bindValue(":AUTOEXPIRE", m_autoExpire);
00426     query.bindValue(":MAXEPISODES", m_maxEpisodes);
00427     query.bindValue(":MAXNEWEST", m_maxNewest);
00428     query.bindValue(":AUTOCOMMFLAG", m_autoCommFlag);
00429     query.bindValue(":AUTOTRANSCODE", m_autoTranscode);
00430     query.bindValue(":TRANSCODER", m_transcoder);
00431     query.bindValue(":AUTOUSERJOB1", m_autoUserJob1);
00432     query.bindValue(":AUTOUSERJOB2", m_autoUserJob2);
00433     query.bindValue(":AUTOUSERJOB3", m_autoUserJob3);
00434     query.bindValue(":AUTOUSERJOB4", m_autoUserJob4);
00435     query.bindValue(":AUTOMETADATA", m_autoMetadataLookup);
00436     query.bindValue(":PARENTID", m_parentRecID);
00437     query.bindValue(":TITLE", m_title);
00438     query.bindValue(":SUBTITLE", null_to_empty(m_subtitle));
00439     query.bindValue(":DESCRIPTION", null_to_empty(m_description));
00440     query.bindValue(":SEASON", m_season);
00441     query.bindValue(":EPISODE", m_episode);
00442     query.bindValue(":CATEGORY", null_to_empty(m_category));
00443     query.bindValue(":STARTTIME", m_starttime);
00444     query.bindValue(":STARTDATE", m_startdate);
00445     query.bindValue(":ENDTIME", m_endtime);
00446     query.bindValue(":ENDDATE", m_enddate);
00447     query.bindValue(":SERIESID", null_to_empty(m_seriesid));
00448     query.bindValue(":PROGRAMID", null_to_empty(m_programid));
00449     query.bindValue(":INETREF", null_to_empty(m_inetref));
00450     query.bindValue(":CHANID", m_channelid);
00451     query.bindValue(":STATION", null_to_empty(m_station));
00452     query.bindValue(":FINDDAY", m_findday);
00453     query.bindValue(":FINDTIME", m_findtime);
00454     query.bindValue(":FINDID", m_findid);
00455     query.bindValue(":NEXTREC", m_nextRecording);
00456     query.bindValue(":LASTREC", m_lastRecorded);
00457     query.bindValue(":LASTDELETE", m_lastDeleted);
00458     query.bindValue(":AVGDELAY", m_averageDelay);
00459 
00460     if (m_recordTable != "record" && m_tempID > 0)
00461         query.bindValue(":RECORDID", m_tempID);
00462     else if (m_recordID > 0)
00463         query.bindValue(":RECORDID", m_recordID);
00464 
00465     if (!query.exec())
00466         MythDB::DBError("UPDATE/INSERT record", query);
00467     else if (m_recordTable != "record" && m_tempID <= 0)
00468         m_tempID = query.lastInsertId().toInt();
00469     else if (m_recordID <= 0)
00470         m_recordID = query.lastInsertId().toInt();
00471 
00472     if (sendSig)
00473         ScheduledRecording::RescheduleMatch(m_recordID, 0, 0, QDateTime(),
00474             QString("SaveRule %1").arg(m_title));
00475 
00476     return true;
00477 }
00478 
00479 bool RecordingRule::Delete(bool sendSig)
00480 {
00481     if (m_recordID < 0)
00482         return false;
00483 
00484     QString querystr;
00485     MSqlQuery query(MSqlQuery::InitCon());
00486     query.prepare("DELETE FROM record WHERE recordid = :RECORDID");
00487     query.bindValue(":RECORDID", m_recordID);
00488     if (!query.exec())
00489     {
00490         MythDB::DBError("ScheduledRecording::remove -- record", query);
00491         return false;
00492     }
00493 
00494     query.prepare("DELETE FROM oldfind WHERE recordid = :RECORDID");
00495     query.bindValue(":RECORDID", m_recordID);
00496     if (!query.exec())
00497     {
00498         MythDB::DBError("ScheduledRecording::remove -- oldfind", query);
00499     }
00500 
00501     if (sendSig)
00502         ScheduledRecording::RescheduleMatch(m_recordID, 0, 0, QDateTime(),
00503             QString("DeleteRule %1").arg(m_title));
00504 
00505     // Set m_recordID to zero, the rule is no longer in the database so it's
00506     // not valid. Should you want, this allows a rule to be removed from the
00507     // database and then re-inserted with Save()
00508     m_recordID = 0;
00509 
00510     return true;
00511 }
00512 
00513 void RecordingRule::ToMap(InfoMap &infoMap) const
00514 {
00515     if (m_title == "Default (Template)")
00516         infoMap["title"] = QObject::tr("Default (Template)");
00517     else
00518         infoMap["title"] = m_title;
00519     infoMap["subtitle"] = m_subtitle;
00520     infoMap["description"] = m_description;
00521     infoMap["season"] = QString::number(m_season);
00522     infoMap["episode"] = QString::number(m_episode);
00523 
00524     if (m_category == "Default")
00525         infoMap["category"] = QObject::tr("Default");
00526     else
00527         infoMap["category"] = m_category;
00528     infoMap["callsign"] = m_station;
00529 
00530     infoMap["starttime"] = MythTimeToString(m_starttime, kTime);
00531     infoMap["startdate"] = MythDateToString(m_startdate, kDateFull | kSimplify);
00532     infoMap["endtime"] = MythTimeToString(m_endtime, kTime);
00533     infoMap["enddate"] = MythDateToString(m_enddate, kDateFull | kSimplify);
00534 
00535     infoMap["inetref"] = m_inetref;
00536     infoMap["chanid"] = m_channelid;
00537     infoMap["channel"] = m_station;
00538 
00539     QDateTime startts(m_startdate, m_starttime);
00540     QDateTime endts(m_enddate, m_endtime);
00541 
00542     QString length;
00543     int hours, minutes, seconds;
00544     seconds = startts.secsTo(endts);
00545 
00546     minutes = seconds / 60;
00547     infoMap["lenmins"] = QObject::tr("%n minute(s)","",minutes);
00548     hours   = minutes / 60;
00549     minutes = minutes % 60;
00550 
00551     QString minstring = QObject::tr("%n minute(s)","",minutes);
00552 
00553     if (hours > 0)
00554     {
00555         infoMap["lentime"] = QString("%1 %2")
00556                                     .arg(QObject::tr("%n hour(s)","", hours))
00557                                     .arg(minstring);
00558     }
00559     else
00560         infoMap["lentime"] = minstring;
00561 
00562 
00563     infoMap["timedate"] = MythDateTimeToString(startts,
00564                                             kDateTimeFull | kSimplify) + " - " +
00565                           MythDateTimeToString(endts, kTime);
00566 
00567     infoMap["shorttimedate"] = MythDateTimeToString(startts,
00568                                             kDateTimeShort | kSimplify) + " - " +
00569                                MythDateTimeToString(endts, kTime);
00570 
00571     if (m_type == kFindDailyRecord || m_type == kFindWeeklyRecord)
00572     {
00573         QString findfrom = MythTimeToString(m_findtime, kTime);
00574         if (m_type == kFindWeeklyRecord)
00575         {
00576             int daynum = (m_findday + 5) % 7 + 1;
00577             findfrom = QString("%1, %2").arg(QDate::shortDayName(daynum))
00578                                         .arg(findfrom);
00579         }
00580         infoMap["subtitle"] = QObject::tr("(%1 or later) %3",
00581                                           "e.g. (Sunday or later) program "
00582                                           "subtitle").arg(findfrom)
00583                                           .arg(m_subtitle);
00584     }
00585 
00586     infoMap["searchtype"] = SearchTypeToString(m_searchType);
00587     if (m_searchType != kNoSearch)
00588         infoMap["searchforwhat"] = m_description;
00589 
00590 
00591     if (m_nextRecording.isValid())
00592         infoMap["nextrecording"] = MythDateTimeToString(m_nextRecording,
00593                                                         kDateFull | kAddYear);
00594     if (m_lastRecorded.isValid())
00595         infoMap["lastrecorded"] = MythDateTimeToString(m_lastRecorded,
00596                                                        kDateFull | kAddYear);
00597     if (m_lastDeleted.isValid())
00598         infoMap["lastdeleted"] = MythDateTimeToString(m_lastDeleted,
00599                                                       kDateFull | kAddYear);
00600 
00601     infoMap["ruletype"] = toString(m_type);
00602     infoMap["rectype"] = toString(m_type);
00603 
00604     if (m_template == "Default")
00605         infoMap["template"] = QObject::tr("Default");
00606     else
00607         infoMap["template"] = m_template;
00608 }
00609 
00610 void RecordingRule::UseTempTable(bool usetemp, QString table)
00611 {
00612     MSqlQuery query(MSqlQuery::SchedCon());
00613 
00614     if (usetemp)
00615     {
00616         m_recordTable = table;
00617 
00618         query.prepare("SELECT GET_LOCK(:LOCK, 2);");
00619         query.bindValue(":LOCK", "DiffSchedule");
00620         if (!query.exec())
00621         {
00622             MythDB::DBError("Obtaining lock in testRecording", query);
00623             return;
00624         }
00625 
00626         query.prepare(QString("DROP TABLE IF EXISTS %1;").arg(table));
00627         if (!query.exec())
00628         {
00629             MythDB::DBError("Deleting old table in testRecording", query);
00630             return;
00631         }
00632 
00633         query.prepare(QString("CREATE TABLE %1 SELECT * FROM record;")
00634                         .arg(table));
00635         if (!query.exec())
00636         {
00637             MythDB::DBError("Create new temp table", query);
00638             return;
00639         }
00640 
00641         query.prepare(QString("ALTER TABLE %1 MODIFY recordid int(10) "
00642                               "UNSIGNED NOT NULL AUTO_INCREMENT primary key;")
00643                               .arg(table));
00644         if (!query.exec())
00645         {
00646             MythDB::DBError("Modify recordid column to include "
00647                             "auto-increment", query);
00648             return;
00649         }
00650 
00651         if (m_recordID > 0)
00652             m_tempID = m_recordID;
00653 
00654         Save(false);
00655     }
00656     else
00657     {
00658         query.prepare("SELECT RELEASE_LOCK(:LOCK);");
00659         query.bindValue(":LOCK", "DiffSchedule");
00660         if (!query.exec())
00661         {
00662             MythDB::DBError("Free lock", query);
00663             return;
00664         }
00665         m_recordTable = "record";
00666         m_tempID = 0;
00667     }
00668 }
00669 
00670 void RecordingRule::AssignProgramInfo()
00671 {
00672     if (!m_progInfo)
00673         return;
00674 
00675     m_title       = m_progInfo->GetTitle();
00676     m_subtitle    = m_progInfo->GetSubtitle();
00677     m_description = m_progInfo->GetDescription();
00678     m_channelid   = m_progInfo->GetChanID();
00679     m_station     = m_progInfo->GetChannelSchedulingID();
00680     m_startdate   = m_progInfo->GetScheduledStartTime().date();
00681     m_starttime   = m_progInfo->GetScheduledStartTime().time();
00682     m_enddate     = m_progInfo->GetScheduledEndTime().date();
00683     m_endtime     = m_progInfo->GetScheduledEndTime().time();
00684     m_seriesid    = m_progInfo->GetSeriesID();
00685     m_programid   = m_progInfo->GetProgramID();
00686     if (m_findday < 0)
00687     {
00688         m_findday =
00689             (m_progInfo->GetScheduledStartTime().date().dayOfWeek() + 1) % 7;
00690         m_findtime = m_progInfo->GetScheduledStartTime().time();
00691 
00692         QDate epoch(1970, 1, 1);
00693         m_findid = epoch.daysTo(
00694             m_progInfo->GetScheduledStartTime().date()) + 719528;
00695     }
00696     else
00697     {
00698         if (m_findid > 0)
00699             m_findid = m_progInfo->GetFindID();
00700         else
00701         {
00702             QDate epoch(1970, 1, 1);
00703             m_findid = epoch.daysTo(
00704                 m_progInfo->GetScheduledStartTime().date()) + 719528;
00705         }
00706     }
00707     m_category = m_progInfo->GetCategory();
00708 
00709     if (m_inetref.isEmpty())
00710     {
00711         m_inetref = m_progInfo->GetInetRef();
00712         m_season  = m_progInfo->GetSeason();
00713         m_episode = m_progInfo->GetEpisode();
00714     }
00715 }
00716 
00717 unsigned RecordingRule::GetDefaultFilter(void)
00718 {
00719     MSqlQuery query(MSqlQuery::InitCon());
00720     query.prepare("SELECT SUM(1 << filterid) FROM recordfilter "
00721                   "WHERE filterid >= 0 AND filterid < :NUMFILTERS AND "
00722                   "      TRIM(clause) <> '' AND newruledefault <> 0");
00723     query.bindValue(":NUMFILTERS", RecordingRule::kNumFilters);
00724     if (!query.exec())
00725     {
00726         MythDB::DBError("GetDefaultFilter", query);
00727         return 0;
00728     }
00729 
00730     if (!query.next())
00731         return 0;
00732     
00733     return query.value(0).toUInt();
00734 }
00735 
00736 QString RecordingRule::SearchTypeToString(const RecSearchType searchType)
00737 {
00738     QString searchTypeString;
00739 
00740     switch (searchType)
00741     {
00742         case kNoSearch:
00743             searchTypeString = ""; // Allow themers to decide what to display
00744             break;
00745         case kPowerSearch:
00746             searchTypeString = QObject::tr("Power Search");
00747             break;
00748         case kTitleSearch:
00749             searchTypeString = QObject::tr("Title Search");
00750             break;
00751         case kKeywordSearch:
00752             searchTypeString = QObject::tr("Keyword Search");
00753             break;
00754         case kPeopleSearch:
00755             searchTypeString = QObject::tr("People Search");
00756             break;
00757         default:
00758             searchTypeString = QObject::tr("Unknown Search");
00759             break;
00760     }
00761 
00762     return searchTypeString;
00763 }
00764 
00765 QStringList RecordingRule::GetTemplateNames(void)
00766 {
00767     QStringList result;
00768 
00769     MSqlQuery query(MSqlQuery::InitCon());
00770     query.prepare("SELECT category "
00771                   "FROM record "
00772                   "WHERE type = :TEMPLATE "
00773                   "ORDER BY category = 'Default' DESC, category"
00774                   );
00775     query.bindValue(":TEMPLATE", kTemplateRecord);
00776 
00777     if (!query.exec())
00778     {
00779         MythDB::DBError("LoadByTemplate", query);
00780         return result;
00781     }
00782 
00783     while (query.next())
00784         result << query.value(0).toString();
00785 
00786     return result;
00787 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends