Go to the documentation of this file.
18 "SELECT mplexid, atsc_minor_chan, serviceid "
20 "WHERE deleted IS NULL AND "
21 " sourceid = :SOURCEID");
35 mplexid = (32767 == mplexid) ? 0 : mplexid;
37 if (mplexid && (
minor || prognum))
51 "WHERE sourceid = :SOURCEID");
64 return query.
value(0).toString();
74 "WHERE name = :NAME");
87 return query.
value(0).toUInt();
95 "WHERE deleted IS NULL AND "
96 " sourceid = :SOURCEID");
101 QMap<QString,uint> counts;
102 static const QRegularExpression kSeparatorRE { R
"((_|-|#|\.))" };
105 const QString channum = query.
value(0).toString();
106 const int where = channum.indexOf(kSeparatorRE);
107 if (channum.right(2).startsWith(
"0"))
110 counts[(where < 0) ?
"" : QString(channum.at(where))]++;
113 uint max = counts[
"_"];
114 static const std::array<const QString,5> s_spacers {
"",
"-",
"#",
".",
"0" };
115 for (
const auto & spacer : s_spacers)
117 if (counts[spacer] > max)
119 max = counts[spacer];
138 "WHERE deleted IS NULL AND "
139 " sourceid = :SOURCEID");
142 return query.
value(0).toUInt();
152 "FROM dtv_multiplex "
153 "WHERE sourceid = :SOURCEID");
156 std::vector<uint> list;
164 list.push_back(query.
value(0).toUInt());
170 QString &grabber, QString &userid,
171 QString &passwd, QString &lineupid)
175 "SELECT xmltvgrabber, userid, password, lineupid "
177 "WHERE sourceid = :SOURCEID");
189 grabber = query.
value(0).toString();
190 userid = query.
value(1).toString();
191 passwd = query.
value(2).toString();
192 lineupid = query.
value(3).toString();
203 "SELECT cardtype, inputname "
205 "WHERE capturecard.sourceid = :SOURCEID");
215 QString inputtype = query.
value(0).toString().toUpper();
216 QString inputname = query.
value(1).toString().toUpper();
217 inputtype = ((inputtype ==
"DVB") && (!inputname.startsWith(
"DVB"))) ?
236 QMap<QString,uint> counts;
237 for (
const auto &
type : qAsConst(
types))
245 counts[
"ANALOG_TUNING"]++;
247 counts[
"DIGITAL_TUNING"]++;
249 counts[
"VIRTUAL_TUNING"]++;
253 ((counts[
"ANALOG_TUNING"] != 0U) && (counts[
"DIGITAL_TUNING"] != 0U)) ||
254 ((counts[
"VIRTUAL_TUNING"] != 0U) && (counts[
"DIGITAL_TUNING"] != 0U));
255 bool enc_mismatch = (counts[
"ENCODER"] != 0U) && (counts[
"NOT_ENCODER"] != 0U);
256 bool scan_mismatch = (counts[
"SCAN"] != 0U) && (counts[
"NO_SCAN"] != 0U);
260 uint a = counts[
"ANALOG_TUNERS"];
261 uint d = counts[
"DIGITAL_TUNERS"];
262 uint v = counts[
"VIRTUAL_TUNERS"];
263 LOG(VB_GENERAL, LOG_NOTICE,
264 QString(
"SourceUtil::IsProperlyConnected(): ") +
265 QString(
"Connected to %1 analog, %2 digital and %3 virtual "
266 "tuners\n\t\t\t").arg(a).arg(
d).arg(v) +
267 QString(
"Can not mix digital with other tuning information."));
272 uint a = counts[
"ENCODER"];
273 uint d = counts[
"NOT_ENCODER"];
274 LOG(VB_GENERAL, LOG_NOTICE,
275 QString(
"SourceUtil::IsProperlyConnected(): ") +
276 QString(
"Source ID %1 ").arg(sourceid) +
277 QString(
"appears to be connected\n\t\t\tto %1 encoder%2, ")
278 .arg(a).arg((1 == a) ?
"":
"s") +
279 QString(
"and %1 non-encoder%2. ")
280 .arg(
d).arg((1 ==
d) ?
"":
"s") +
281 QString(
"This is probably a bad idea."));
286 uint a = counts[
"SCAN"];
287 uint d = counts[
"NO_SCAN"];
288 LOG(VB_GENERAL, LOG_NOTICE,
289 QString(
"SourceUtil::IsProperlyConnected(): ") +
290 QString(
"Source ID %1 ").arg(sourceid) +
291 QString(
"appears to be connected\n\t\t\t"
292 "to %1 scanable input%2, ")
293 .arg(a).arg((1 == a) ?
"":
"s") +
294 QString(
"and %1 non-scanable input%2. ")
295 .arg(
d).arg((1 ==
d) ?
"":
"s") +
296 QString(
"This may be a problem."));
300 return !tune_mismatch;
302 return !tune_mismatch && !enc_mismatch && !scan_mismatch;
309 bool encoder = std::all_of(
types.cbegin(),
types.cend(), isencoder);
318 "SELECT atsc_minor_chan, serviceid "
320 "WHERE deleted IS NULL AND "
321 " sourceid = :SOURCEID");
324 bool has_any_chan =
false;
331 encoder &= !query.
value(0).toBool() && !query.
value(1).toBool();
336 return (strict && !has_any_chan) ?
false: encoder;
345 return std::all_of(
types.cbegin(),
types.cend(), unscannable);
351 auto ccpresent = [](
uint input)
354 return std::any_of(inputs.cbegin(), inputs.cend(), ccpresent);
360 query.
prepare(
"SELECT sourceid FROM videosource");
381 "SELECT sourceid FROM videosource WHERE sourceid = :SOURCEID");
400 args.append(
"--only-update-channels");
404 args.append(QString(
"--sourceid"));
405 args.append(QString::number(sourceid));
407 if (!inputtype.isEmpty())
409 args.append(QString(
"--cardtype"));
410 args.append(inputtype);
420 "mythfilldatabase --only-update-channels";
422 cmd += QString(
" --sourceid %1").arg(sourceid);
423 if (!inputtype.isEmpty())
424 cmd += QString(
" --cardtype %1").arg(inputtype);
434 const QString& grabber,
const QString& userid,
435 const QString& freqtable,
const QString& lineupid,
436 const QString& password,
bool useeit,
437 const QString& configpath,
int nitid,
443 query.
prepare(
"UPDATE videosource SET name = :NAME, xmltvgrabber = :XMLTVGRABBER, "
444 "userid = :USERID, freqtable = :FREQTABLE, lineupid = :LINEUPID,"
445 "password = :PASSWORD, useeit = :USEEIT, configpath = :CONFIGPATH, "
446 "dvb_nit_id = :NITID, bouquet_id = :BOUQUETID, region_id = :REGIONID, "
447 "scanfrequency = :SCANFREQUENCY, lcnoffset = :LCNOFFSET "
448 "WHERE sourceid = :SOURCEID");
451 query.
bindValue(
":XMLTVGRABBER", grabber);
453 query.
bindValue(
":FREQTABLE", freqtable);
457 query.
bindValue(
":CONFIGPATH", configpath.isEmpty() ?
nullptr : configpath);
459 query.
bindValue(
":BOUQUETID", bouquetid);
462 query.
bindValue(
":SCANFREQUENCY", scanfrequency);
463 query.
bindValue(
":LCNOFFSET", lcnoffset);
475 const QString& grabber,
const QString& userid,
476 const QString& freqtable,
const QString& lineupid,
477 const QString& password,
bool useeit,
478 const QString& configpath,
int nitid,
484 query.
prepare(
"INSERT INTO videosource (name,xmltvgrabber,userid,freqtable,lineupid,"
485 "password,useeit,configpath,dvb_nit_id,bouquet_id,region_id, scanfrequency,"
487 "VALUES (:NAME, :XMLTVGRABBER, :USERID, :FREQTABLE, :LINEUPID, :PASSWORD, "
488 ":USEEIT, :CONFIGPATH, :NITID, :BOUQUETID, :REGIONID, :SCANFREQUENCY, "
492 query.
bindValue(
":XMLTVGRABBER", grabber);
494 query.
bindValue(
":FREQTABLE", freqtable);
498 query.
bindValue(
":CONFIGPATH", configpath.isEmpty() ?
nullptr : configpath);
500 query.
bindValue(
":BOUQUETID", bouquetid);
502 query.
bindValue(
":SCANFREQUENCY", scanfrequency);
503 query.
bindValue(
":LCNOFFSET", lcnoffset);
511 query.
prepare(
"SELECT MAX(sourceid) FROM videosource");
522 sourceid = query.
value(0).toInt();
532 query.
prepare(
"DELETE FROM dtv_multiplex "
533 "WHERE sourceid = :SOURCEID");
543 query.
prepare(
"UPDATE channel "
544 "SET deleted = NOW(), mplexid = 0, sourceid = 0 "
545 "WHERE deleted IS NULL AND sourceid = :SOURCEID");
555 query.
prepare(
"UPDATE capturecard "
557 "WHERE sourceid = :SOURCEID");
570 query.
prepare(
"DELETE FROM videosource "
571 "WHERE sourceid = :SOURCEID");
588 query.
prepare(
"UPDATE capturecard "
597 query.
prepare(
"UPDATE channel "
598 "SET deleted = NOW(), mplexid = 0, sourceid = 0 "
599 "WHERE deleted IS NULL");
607 return (query.
exec(
"TRUNCATE TABLE program") &&
608 query.
exec(
"TRUNCATE TABLE videosource") &&
609 query.
exec(
"TRUNCATE TABLE credits") &&
610 query.
exec(
"TRUNCATE TABLE programrating") &&
611 query.
exec(
"TRUNCATE TABLE programgenres") &&
612 query.
exec(
"TRUNCATE TABLE dtv_multiplex") &&
613 query.
exec(
"TRUNCATE TABLE diseqc_config") &&
614 query.
exec(
"TRUNCATE TABLE diseqc_tree") &&
615 query.
exec(
"TRUNCATE TABLE eit_cache") &&
616 query.
exec(
"TRUNCATE TABLE channelgroup") &&
617 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.