34 int chansep = channum.indexOf(QRegExp(
"\\D"));
38 major = channum.left(chansep).toInt();
39 minor = channum.right(channum.length() - (chansep + 1)).toInt();
48 "WHERE sourceid = :SOURCEID");
52 query.
value(0).toString() ==
"HDTV")
63 bool isEncoder, isUnscanable;
75 insert_channels = (isCableCard || isEncoder || isUnscanable) &&
79 return insert_channels;
84 ChannelInfoList::iterator chaninfo,
unsigned int chanid)
86 (*chaninfo).name =
getResponse(QObject::tr(
"Choose a channel name (any string, " 87 "long version) "),(*chaninfo).name);
88 (*chaninfo).callsign =
getResponse(QObject::tr(
"Choose a channel callsign (any string, " 89 "short version) "),(*chaninfo).callsign);
93 (*chaninfo).channum =
getResponse(QObject::tr(
"Choose a channel preset (0..999) "),
95 (*chaninfo).freqid =
getResponse(QObject::tr(
"Choose a frequency id "),
100 (*chaninfo).channum =
getResponse(QObject::tr(
"Choose a channel number "),
101 (*chaninfo).channum);
102 (*chaninfo).freqid = (*chaninfo).channum;
105 (*chaninfo).finetune =
getResponse(QObject::tr(
"Choose a channel fine tune offset "),
106 QString::number((*chaninfo).finetune)).toInt();
108 (*chaninfo).tvformat =
getResponse(QObject::tr(
"Choose a TV format " 109 "(PAL/SECAM/NTSC/ATSC/Default) "),
110 (*chaninfo).tvformat);
112 (*chaninfo).icon =
getResponse(QObject::tr(
"Choose a channel icon image " 113 "(relative path to icon storage group) "),
121 QString result = chanName;
124 result = result.toLower();
126 result = result.replace(
" ",
"");
141 ChannelInfoList::iterator it =
channelList.begin();
144 QString chanName = (*it).name;
146 retList.insert(key, *it);
155 ChannelList::iterator it;
156 for (it = existingChannels.begin(); it != existingChannels.end(); ++it)
158 if ((*it).xmltvid == chanInfo.
xmltvid)
163 ChannelInfo existChan = existingChannels.value(searchKey);
168 int chansep = chanInfo.
channum.indexOf(QRegExp(
"\\D"));
172 uint major = chanInfo.
channum.left(chansep).toInt();
174 (chanInfo.
channum.length() - (chansep + 1)).toInt();
176 for (it = existingChannels.begin();
177 it != existingChannels.end(); ++it)
179 if ((*it).atsc_major_chan == major &&
180 (*it).atsc_minor_chan ==
minor)
193 LOG(VB_GENERAL, LOG_NOTICE,
"Skipping Channel Updates");
200 QDir::setCurrent(fileprefix);
206 ChannelInfoList::iterator i = chanlist->begin();
207 for (; i != chanlist->end(); ++i)
209 if ((*i).xmltvid.isEmpty())
214 if (!(*i).icon.isEmpty())
216 QDir remotefile = QDir((*i).icon);
217 QString filename = remotefile.dirName();
219 localfile = fileprefix + filename;
220 QFile actualfile(localfile);
221 if (!actualfile.exists() &&
224 LOG(VB_GENERAL, LOG_ERR,
225 QString(
"Failed to fetch icon from '%1'")
229 localfile = filename;
234 if (!(*i).old_xmltvid.isEmpty())
239 "WHERE xmltvid = :XMLTVID");
240 query.
bindValue(
":XMLTVID", (*i).old_xmltvid);
246 else if (query.
next())
248 LOG(VB_GENERAL, LOG_INFO,
249 QString(
"Converting old xmltvid (%1) to new (%2)")
250 .arg((*i).old_xmltvid).arg((*i).xmltvid));
252 query.
prepare(
"UPDATE channel " 253 "SET xmltvid = :NEWXMLTVID" 254 "WHERE xmltvid = :OLDXMLTVID");
255 query.
bindValue(
":NEWXMLTVID", (*i).xmltvid);
256 query.
bindValue(
":OLDXMLTVID", (*i).old_xmltvid);
268 LOG(VB_XMLTV, LOG_NOTICE,
269 QString(
"Match found for xmltvid %1 to channel %2 (%3)")
270 .arg((*i).xmltvid).arg(dbChan.
name).arg(dbChan.
chanid));
274 cout <<
"### " << endl;
275 cout <<
"### Existing channel found" << endl;
276 cout <<
"### " << endl;
277 cout <<
"### xmltvid = " 278 << (*i).xmltvid.toLocal8Bit().constData() << endl;
279 cout <<
"### chanid = " 281 cout <<
"### name = " 282 << dbChan.
name.toLocal8Bit().constData() << endl;
283 cout <<
"### callsign = " 284 << dbChan.
callsign.toLocal8Bit().constData() << endl;
285 cout <<
"### channum = " 286 << dbChan.
channum.toLocal8Bit().constData() << endl;
289 cout <<
"### freqid = " 290 << dbChan.
freqid.toLocal8Bit().constData() << endl;
292 cout <<
"### finetune = " 294 cout <<
"### tvformat = " 295 << dbChan.
tvformat.toLocal8Bit().constData() << endl;
296 cout <<
"### icon = " 297 << dbChan.
icon.toLocal8Bit().constData() << endl;
298 cout <<
"### " << endl;
301 (*i).name = dbChan.
name;
305 (*i).freqid = dbChan.
freqid;
310 if ((*i).callsign.isEmpty())
311 (*i).callsign = dbChan.
name;
313 if (dbChan.
name != (*i).name ||
315 dbChan.
channum != (*i).channum ||
317 dbChan.
freqid != (*i).freqid ||
318 dbChan.
icon != localfile ||
322 subquery.
prepare(
"UPDATE channel SET chanid = :CHANID, " 323 "name = :NAME, callsign = :CALLSIGN, " 324 "channum = :CHANNUM, finetune = :FINE, " 325 "icon = :ICON, freqid = :FREQID, " 326 "tvformat = :TVFORMAT " 327 " WHERE xmltvid = :XMLTVID " 328 "AND sourceid = :SOURCEID;");
331 subquery.
bindValue(
":CALLSIGN", (*i).callsign);
332 subquery.
bindValue(
":CHANNUM", (*i).channum);
333 subquery.
bindValue(
":FINE", (*i).finetune);
335 subquery.
bindValue(
":FREQID", (*i).freqid);
336 subquery.
bindValue(
":TVFORMAT", (*i).tvformat);
337 subquery.
bindValue(
":XMLTVID", (*i).xmltvid);
340 if (!subquery.
exec())
346 cout <<
"### " << endl;
347 cout <<
"### Change performed" << endl;
348 cout <<
"### " << endl;
353 cout <<
"### " << endl;
354 cout <<
"### Nothing changed" << endl;
355 cout <<
"### " << endl;
358 else if ((dbChan.
icon != localfile) ||
359 (dbChan.
xmltvid != (*i).xmltvid))
361 LOG(VB_XMLTV, LOG_NOTICE, QString(
"Updating channel %1 (%2)")
364 if (localfile.isEmpty())
365 localfile = dbChan.
icon;
367 if (dbChan.
xmltvid != (*i).xmltvid)
371 subquery.
prepare(
"UPDATE channel SET icon = :ICON " 372 ", xmltvid:= :XMLTVID WHERE " 373 "chanid = :CHANID;");
375 subquery.
bindValue(
":XMLTVID", (*i).xmltvid);
378 if (!subquery.
exec())
384 subquery.
prepare(
"UPDATE channel SET icon = :ICON WHERE " 385 "chanid = :CHANID;");
389 if (!subquery.
exec())
397 int major,
minor = 0;
403 cout <<
"### " << endl;
404 cout <<
"### New channel found" << endl;
405 cout <<
"### " << endl;
406 cout <<
"### name = " 407 << (*i).name.toLocal8Bit().constData() << endl;
408 cout <<
"### callsign = " 409 << (*i).callsign.toLocal8Bit().constData() << endl;
410 cout <<
"### channum = " 411 << (*i).channum.toLocal8Bit().constData() << endl;
414 cout <<
"### freqid = " 415 << (*i).freqid.toLocal8Bit().constData() << endl;
417 cout <<
"### finetune = " 418 << (*i).finetune << endl;
419 cout <<
"### tvformat = " 420 << (*i).tvformat.toLocal8Bit().constData() << endl;
421 cout <<
"### icon = " 422 << localfile.toLocal8Bit().constData() << endl;
423 cout <<
"### " << endl;
427 if ((*i).callsign.isEmpty())
428 (*i).callsign = QString::number(chanid);
431 if ((chanid > 0) && (
minor > 0))
435 if (((mplexid > 0) || ((
minor == 0) && (chanid > 0))) &&
438 (*i).callsign, (*i).name, (*i).channum,
442 (*i).freqid, localfile, (*i).tvformat,
445 cout <<
"### " << endl;
446 cout <<
"### Channel inserted" << endl;
447 cout <<
"### " << endl;
451 cout <<
"### " << endl;
452 cout <<
"### Channel skipped" << endl;
453 cout <<
"### " << endl;
460 int mplexid = 0, chanid = 0;
464 id,
"atsc",
freq,
"8vsb");
467 if ((mplexid > 0) || (
minor == 0))
470 if ((*i).callsign.isEmpty())
472 QStringList words = (*i).name.simplified().toUpper()
474 QString callsign =
"";
475 QString w1 = words.size() > 0 ? words[0] : QString();
476 QString w2 = words.size() > 1 ? words[1] : QString();
478 callsign = QString::number(chanid);
479 else if (w2.isEmpty())
480 callsign = words[0].left(5);
483 callsign = w1.left(w2.length() == 1 ? 4:3);
484 callsign += w2.left(5 - callsign.length());
486 (*i).callsign = callsign;
491 QString cstr = (*i).channum;
493 cstr = QString::number(chanid % 1000);
511 cout <<
"Channel " << chanid <<
" creation failed" bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
static bool CreateChannel(uint db_mplexid, uint db_sourceid, uint new_channel_id, const QString &callsign, const QString &service_name, const QString &chan_num, uint service_id, uint atsc_major_channel, uint atsc_minor_channel, bool use_on_air_guide, bool hidden, bool hidden_in_guide, const QString &freqid, QString icon=QString(), QString format="Default", QString xmltvid=QString(), QString default_authority=QString())
void bindValue(const QString &placeholder, const QVariant &val)
static bool IsCableCardPresent(uint sourceid)
QSqlQuery wrapper that fetches a DB connection from the connection pool.
static bool IsUnscanable(const QString &rawtype)
static bool IsUnscanable(uint sourceid)
QString normalizeChannelKey(const QString &chanName) const
ChannelList channelList(int sourceId)
static bool IsEncoder(const QString &rawtype)
QVariant value(int i) const
QString SetupIconCacheDirectory(void)
unsigned int promptForChannelUpdates(ChannelInfoList::iterator chaninfo, unsigned int chanid)
bool isActive(void) const
MythDownloadManager * GetMythDownloadManager(void)
Gets the pointer to the MythDownloadManager singleton.
static MSqlQueryInfo DDCon()
Returns dedicated connection. (Required for using temporary SQL tables.)
bool download(const QString &url, const QString &dest, const bool reload=false)
Downloads a URL to a file in blocking mode.
static ChannelInfoList LoadChannels(uint startIndex, uint count, uint &totalAvailable, bool ignoreHidden=true, OrderBy orderBy=kChanOrderByChanNum, GroupBy groupBy=kChanGroupByChanid, uint sourceID=0, uint channelGroupID=0, bool liveTVOnly=false, QString callsign="", QString channum="")
Load channels from database into a list of ChannelInfo objects.
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
QString getResponse(const QString &query, const QString &def)
In an interactive shell, prompt the user to input a string.
static int CreateChanID(uint sourceid, const QString &chan_num)
Creates a unique channel ID for database use.
void handleChannels(int id, ChannelInfoList *chanlist)
static void get_atsc_stuff(QString channum, int sourceid, int freqid, int &major, int &minor, long long &freq)
ChannelInfo FindMatchingChannel(const ChannelInfo &chanInfo, ChannelList existingChannels) const
vector< ChannelInfo > ChannelInfoList
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
#define LOG(_MASK_, _LEVEL_, _STRING_)
bool insert_chan(uint sourceid)
static uint CreateMultiplex(int sourceid, QString sistandard, uint64_t frequency, QString modulation, int transport_id=-1, int network_id=-1)
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
static bool IsEncoder(uint sourceid, bool strict=false)
long long get_center_frequency(QString format, QString modulation, QString country, int freqid)
static void DBError(const QString &where, const MSqlQuery &query)
QList< ChannelListItem > ChannelList