Go to the documentation of this file.
4 #include <QRegularExpression>
21 "SELECT mplexid, atsc_minor_chan, serviceid "
23 "WHERE deleted IS NULL AND "
24 " sourceid = :SOURCEID");
38 mplexid = (32767 == mplexid) ? 0 : mplexid;
40 if (mplexid && (
minor || prognum))
54 "WHERE sourceid = :SOURCEID");
67 return query.
value(0).toString();
77 "WHERE name = :NAME");
90 return query.
value(0).toUInt();
98 "WHERE deleted IS NULL AND "
99 " sourceid = :SOURCEID");
104 QMap<QString,uint> counts;
105 static const QRegularExpression kSeparatorRE { R
"((_|-|#|\.))" };
108 const QString channum = query.
value(0).toString();
109 const int where = channum.indexOf(kSeparatorRE);
110 if (channum.right(2).startsWith(
"0"))
113 counts[(where < 0) ?
"" : QString(channum.at(where))]++;
116 uint max = counts[
"_"];
117 static const std::array<const QString,5> s_spacers {
"",
"-",
"#",
".",
"0" };
118 for (
const auto & spacer : s_spacers)
120 if (counts[spacer] > max)
122 max = counts[spacer];
141 "WHERE deleted IS NULL AND "
142 " sourceid = :SOURCEID");
145 return query.
value(0).toUInt();
155 "FROM dtv_multiplex "
156 "WHERE sourceid = :SOURCEID");
159 std::vector<uint> list;
167 list.push_back(query.
value(0).toUInt());
173 QString &grabber, QString &userid,
174 QString &passwd, QString &lineupid)
178 "SELECT xmltvgrabber, userid, password, lineupid "
180 "WHERE sourceid = :SOURCEID");
192 grabber = query.
value(0).toString();
193 userid = query.
value(1).toString();
194 passwd = query.
value(2).toString();
195 lineupid = query.
value(3).toString();
206 "SELECT cardtype, inputname "
208 "WHERE capturecard.sourceid = :SOURCEID");
218 QString inputtype = query.
value(0).toString().toUpper();
219 QString inputname = query.
value(1).toString().toUpper();
220 inputtype = ((inputtype ==
"DVB") && (!inputname.startsWith(
"DVB"))) ?
239 QMap<QString,uint> counts;
240 for (
const auto &
type : std::as_const(
types))
248 counts[
"ANALOG_TUNING"]++;
250 counts[
"DIGITAL_TUNING"]++;
252 counts[
"VIRTUAL_TUNING"]++;
256 ((counts[
"ANALOG_TUNING"] != 0U) && (counts[
"DIGITAL_TUNING"] != 0U)) ||
257 ((counts[
"VIRTUAL_TUNING"] != 0U) && (counts[
"DIGITAL_TUNING"] != 0U));
258 bool enc_mismatch = (counts[
"ENCODER"] != 0U) && (counts[
"NOT_ENCODER"] != 0U);
259 bool scan_mismatch = (counts[
"SCAN"] != 0U) && (counts[
"NO_SCAN"] != 0U);
263 uint a = counts[
"ANALOG_TUNERS"];
264 uint d = counts[
"DIGITAL_TUNERS"];
265 uint v = counts[
"VIRTUAL_TUNERS"];
266 LOG(VB_GENERAL, LOG_NOTICE,
267 QString(
"SourceUtil::IsProperlyConnected(): ") +
268 QString(
"Connected to %1 analog, %2 digital and %3 virtual "
269 "tuners\n\t\t\t").arg(a).arg(
d).arg(v) +
270 QString(
"Can not mix digital with other tuning information."));
275 uint a = counts[
"ENCODER"];
276 uint d = counts[
"NOT_ENCODER"];
277 LOG(VB_GENERAL, LOG_NOTICE,
278 QString(
"SourceUtil::IsProperlyConnected(): ") +
279 QString(
"Source ID %1 ").arg(sourceid) +
280 QString(
"appears to be connected\n\t\t\tto %1 encoder%2, ")
281 .arg(a).arg((1 == a) ?
"":
"s") +
282 QString(
"and %1 non-encoder%2. ")
283 .arg(
d).arg((1 ==
d) ?
"":
"s") +
284 QString(
"This is probably a bad idea."));
289 uint a = counts[
"SCAN"];
290 uint d = counts[
"NO_SCAN"];
291 LOG(VB_GENERAL, LOG_NOTICE,
292 QString(
"SourceUtil::IsProperlyConnected(): ") +
293 QString(
"Source ID %1 ").arg(sourceid) +
294 QString(
"appears to be connected\n\t\t\t"
295 "to %1 scanable input%2, ")
296 .arg(a).arg((1 == a) ?
"":
"s") +
297 QString(
"and %1 non-scanable input%2. ")
298 .arg(
d).arg((1 ==
d) ?
"":
"s") +
299 QString(
"This may be a problem."));
303 return !tune_mismatch;
305 return !tune_mismatch && !enc_mismatch && !scan_mismatch;
312 bool encoder = std::all_of(
types.cbegin(),
types.cend(), isencoder);
321 "SELECT atsc_minor_chan, serviceid "
323 "WHERE deleted IS NULL AND "
324 " sourceid = :SOURCEID");
327 bool has_any_chan =
false;
334 encoder &= !query.
value(0).toBool() && !query.
value(1).toBool();
339 return (strict && !has_any_chan) ?
false: encoder;
348 return std::all_of(
types.cbegin(),
types.cend(), unscannable);
354 auto ccpresent = [](
uint input)
357 return std::any_of(inputs.cbegin(), inputs.cend(), ccpresent);
363 query.
prepare(
"SELECT sourceid FROM videosource");
384 "SELECT sourceid FROM videosource WHERE sourceid = :SOURCEID");
403 args.append(
"--only-update-channels");
407 args.append(QString(
"--sourceid"));
408 args.append(QString::number(sourceid));
410 if (!inputtype.isEmpty())
412 args.append(QString(
"--cardtype"));
413 args.append(inputtype);
423 "mythfilldatabase --only-update-channels";
425 cmd += QString(
" --sourceid %1").arg(sourceid);
426 if (!inputtype.isEmpty())
427 cmd += QString(
" --cardtype %1").arg(inputtype);
437 const QString& grabber,
const QString& userid,
438 const QString& freqtable,
const QString& lineupid,
439 const QString& password,
bool useeit,
440 const QString& configpath,
int nitid,
446 query.
prepare(
"UPDATE videosource SET name = :NAME, xmltvgrabber = :XMLTVGRABBER, "
447 "userid = :USERID, freqtable = :FREQTABLE, lineupid = :LINEUPID,"
448 "password = :PASSWORD, useeit = :USEEIT, configpath = :CONFIGPATH, "
449 "dvb_nit_id = :NITID, bouquet_id = :BOUQUETID, region_id = :REGIONID, "
450 "scanfrequency = :SCANFREQUENCY, lcnoffset = :LCNOFFSET "
451 "WHERE sourceid = :SOURCEID");
454 query.
bindValue(
":XMLTVGRABBER", grabber);
456 query.
bindValue(
":FREQTABLE", freqtable);
460 query.
bindValue(
":CONFIGPATH", configpath.isEmpty() ?
nullptr : configpath);
462 query.
bindValue(
":BOUQUETID", bouquetid);
465 query.
bindValue(
":SCANFREQUENCY", scanfrequency);
466 query.
bindValue(
":LCNOFFSET", lcnoffset);
478 const QString& grabber,
const QString& userid,
479 const QString& freqtable,
const QString& lineupid,
480 const QString& password,
bool useeit,
481 const QString& configpath,
int nitid,
487 query.
prepare(
"INSERT INTO videosource (name,xmltvgrabber,userid,freqtable,lineupid,"
488 "password,useeit,configpath,dvb_nit_id,bouquet_id,region_id, scanfrequency,"
490 "VALUES (:NAME, :XMLTVGRABBER, :USERID, :FREQTABLE, :LINEUPID, :PASSWORD, "
491 ":USEEIT, :CONFIGPATH, :NITID, :BOUQUETID, :REGIONID, :SCANFREQUENCY, "
495 query.
bindValue(
":XMLTVGRABBER", grabber);
497 query.
bindValue(
":FREQTABLE", freqtable);
501 query.
bindValue(
":CONFIGPATH", configpath.isEmpty() ?
nullptr : configpath);
503 query.
bindValue(
":BOUQUETID", bouquetid);
505 query.
bindValue(
":SCANFREQUENCY", scanfrequency);
506 query.
bindValue(
":LCNOFFSET", lcnoffset);
514 query.
prepare(
"SELECT MAX(sourceid) FROM videosource");
525 sourceid = query.
value(0).toInt();
535 query.
prepare(
"DELETE FROM dtv_multiplex "
536 "WHERE sourceid = :SOURCEID");
546 query.
prepare(
"UPDATE channel "
547 "SET deleted = NOW(), mplexid = 0, sourceid = 0 "
548 "WHERE deleted IS NULL AND sourceid = :SOURCEID");
558 query.
prepare(
"UPDATE capturecard "
560 "WHERE sourceid = :SOURCEID");
573 query.
prepare(
"DELETE FROM videosource "
574 "WHERE sourceid = :SOURCEID");
591 query.
prepare(
"UPDATE capturecard "
600 query.
prepare(
"UPDATE channel "
601 "SET deleted = NOW(), mplexid = 0, sourceid = 0 "
602 "WHERE deleted IS NULL");
610 return (query.
exec(
"TRUNCATE TABLE program") &&
611 query.
exec(
"TRUNCATE TABLE videosource") &&
612 query.
exec(
"TRUNCATE TABLE credits") &&
613 query.
exec(
"TRUNCATE TABLE programrating") &&
614 query.
exec(
"TRUNCATE TABLE programgenres") &&
615 query.
exec(
"TRUNCATE TABLE dtv_multiplex") &&
616 query.
exec(
"TRUNCATE TABLE diseqc_config") &&
617 query.
exec(
"TRUNCATE TABLE diseqc_tree") &&
618 query.
exec(
"TRUNCATE TABLE eit_cache") &&
619 query.
exec(
"TRUNCATE TABLE channelgroup") &&
620 query.
exec(
"TRUNCATE TABLE channelgroupnames"));
bool isActive(void) const
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
QSqlQuery wrapper that fetches a DB connection from the connection pool.
static std::vector< uint > GetInputIDs(const QString &videodevice=QString(), const QString &rawtype=QString(), const QString &inputname=QString(), QString hostname=QString())
Returns all inputids of inputs that uses the specified videodevice if specified, and optionally rawty...
static bool IsTuningVirtual(const QString &rawtype)
static bool DeleteSource(uint sourceid)
static QString GetSourceName(uint sourceid)
static bool IsCableCardPresent(uint sourceid)
static uint GetChannelCount(uint sourceid)
static bool IsProperlyConnected(uint sourceid, bool strict=false)
static std::vector< uint > GetMplexIDs(uint sourceid)
static bool UpdateSource(uint sourceid, const QString &sourcename, const QString &grabber, const QString &userid, const QString &freqtable, const QString &lineupid, const QString &password, bool useeit, const QString &configpath, int nitid, uint bouquetid, uint regionid, uint scanfrequency, uint lcnoffset)
QVariant value(int i) const
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
static QString GetChannelSeparator(uint sourceid)
static const struct wl_interface * types[]
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
static int CreateSource(const QString &sourcename, const QString &grabber, const QString &userid, const QString &freqtable, const QString &lineupid, const QString &password, bool useeit, const QString &configpath, int nitid, uint bouquetid, uint regionid, uint scanfrequency, uint lcnoffset)
static QString GetChannelFormat(uint sourceid)
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
static bool IsAnySourceScanable(void)
static bool IsSourceIDValid(uint sourceid)
static bool UpdateChannelsFromListings(uint sourceid, const QString &inputtype=QString(), bool wait=false)
static bool IsTuningDigital(const QString &rawtype)
static bool IsEncoder(const QString &rawtype)
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
static void DBError(const QString &where, const MSqlQuery &query)
uint Wait(std::chrono::seconds timeout=0s)
static bool IsUnscanable(uint sourceid)
static bool HasDigitalChannel(uint sourceid)
static void DeleteScansFromSource(uint sourceid)
@ kMSRunShell
run process through shell
@ kMSAutoCleanup
automatically delete if backgrounded
static QString GetRawInputType(uint inputid)
static bool IsCableCardPresent(uint inputid, const QString &inputType)
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
QString GetAppBinDir(void)
static bool DeleteAllSources(void)
static bool IsEncoder(uint sourceid, bool strict=false)
static bool GetListingsLoginData(uint sourceid, QString &grabber, QString &userid, QString &passwd, QString &lineupid)
void Run(std::chrono::seconds timeout=0s)
Runs a command inside the /bin/sh shell. Returns immediately.
static const iso6937table * d
static uint GetConnectionCount(uint sourceid)
static QStringList get_inputtypes(uint sourceid)
static bool IsTuningAnalog(const QString &rawtype)
static bool IsUnscanable(const QString &rawtype)
static uint GetSourceID(const QString &name)
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.